diff --git a/src/font.c b/src/font.c index 9702371..43993c1 100644 --- a/src/font.c +++ b/src/font.c @@ -451,7 +451,8 @@ TextLayout createTextLayoutEx(const char *text, int length) { } HeliGlyph *glyph = &blankGlyph; - int code2 = (code == 0 || code == 10 || code == 13) ? 32 : code; + int special = code == 0 || code == 10 || code == 13; + int code2 = special ? 32 : code; for(int i = 0; i < fontsCount && !glyph->fi; ++i) glyph = getGlyph(fonts[i], code2); for(int i = 0; i < fontsCount && !glyph->fi; ++i) @@ -481,15 +482,20 @@ TextLayout createTextLayoutEx(const char *text, int length) { line->width = cc->pos + cc->glyph->advance; } - if ( line->begin >= line->end - 1 - || ( cc->glyph->l + HELI_PRECISION < cc->glyph->r - && code != 10 - && code != 13 - && code != 0 )) - { + if (!special && cc->glyph->l + HELI_PRECISION < cc->glyph->r) { + // expand line for the visible glyph expand(&line->l, &line->r, cc->pos + cc->glyph->l); expand(&line->l, &line->r, cc->pos + cc->glyph->r); + } else + if (!special && isspace(code)) { + // expand line for the space char + expand(&line->l, &line->r, cc->pos + cc->glyph->advance); + } else + if (line->begin >= line->end - 1) { + // is glyph is not space and not visible then expand line only for the first char in the line + expand(&line->l, &line->r, cc->pos); } + expand(&line->t, &line->b, cc->glyph->t); expand(&line->t, &line->b, cc->glyph->b); expand(&line->t, &line->b, -glyph->fi->height);