Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertical text scaling #100

Closed
terewenko opened this issue Aug 24, 2020 · 4 comments
Closed

Vertical text scaling #100

terewenko opened this issue Aug 24, 2020 · 4 comments

Comments

@terewenko
Copy link

Very great library! Thanks!

There is a problem with scaling vertical text. The fix might look something like

void AddTextVertical(ImDrawList *DrawList, const char *text, ImVec2 pos, ImU32 text_color) {
    pos.x = IM_ROUND(pos.x);
    pos.y = IM_ROUND(pos.y);
    ImFont* font = GImGui->Font;
    ImGuiContext& g = *GImGui;

    IM_ASSERT(font->FontSize > 0.0f);
    const float scale = g.FontSize / font->FontSize;
    const ImFontGlyph *glyph;
    for (char c = *text++; c; c = *text++) {
        glyph = font->FindGlyph(c);
        if (!glyph)
            continue;

        DrawList->PrimReserve(6, 4);
        DrawList->PrimQuadUV(
            pos + ImVec2(glyph->Y0, -glyph->X0) * scale, pos + ImVec2(glyph->Y0, -glyph->X1) * scale,
            pos + ImVec2(glyph->Y1, -glyph->X1) * scale, pos + ImVec2(glyph->Y1, -glyph->X0) * scale,
            ImVec2(glyph->U0, glyph->V0), ImVec2(glyph->U1, glyph->V0),
            ImVec2(glyph->U1, glyph->V1), ImVec2(glyph->U0, glyph->V1), text_color);
        pos.y -= glyph->AdvanceX * scale;
    }
}

Thanks.

@epezent
Copy link
Owner

epezent commented Aug 24, 2020

Can you post a picture of what is happening?

@terewenko
Copy link
Author

The vertical text does not respond to scaling changes.
image

@terewenko
Copy link
Author

image

@epezent
Copy link
Owner

epezent commented Aug 24, 2020

Thanks, I just pushed a fix for scaling and offset:

image

image

@epezent epezent closed this as completed Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants