| Summary: | some TTF font rendering will be offset, without any warning of anything wrong detected | ||
|---|---|---|---|
| Product: | SDL_ttf | Reporter: | HAIHONG(Mr.LUO) <luohaihong> |
| Component: | misc | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | sezeroz, sylvain.becker |
| Version: | unspecified | ||
| Hardware: | All | ||
| OS: | All | ||
| Attachments: |
font file I met problem with, and the rendered capture/saved in picture
rendered surface captured as a PNG file patch patch patch patch patch patch for SDL-1.2 branch |
||
I have tried the fond and I am not sure to see your issue. You forgot to upload your screenshot Created attachment 3357 [details]
rendered surface captured as a PNG file
Pls see the attached.
Thanks, I see that also now, when the font size is big enough.
Looking at SDL_ttf, it hits this line:
if ((row + glyph->yoffset) < 0) {
continue;
}
so the first rows are not used.
// yoffset = font->ascent - cached->maxy;
// some values: skip row=0 glyph->yoffset=-2 font->ascent=96 glyph->maxy=98
Not sure how it should be handled ...
https://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html
But (assusming this criteria of comparison is correct without need to consider ascending/descending .etc) this should skip only two (pixel) rows? I might not be knowledgable enough to go to this deep yet. But a clue might help, if we use TTF library's utilities to open/draw with same font size, no issue, and I believe there should be quite some big space (maybe line space) above "8" rendered. Is there a way to just adopt TTF ways of criteria/formula? In my example it skips two pixels rows. But it can skip more or not depending on the size. I have checked and I also have a few glyph that get cropped. for instance upper case with accent (eg Å). If I try not to crop it, by making yoffset always positive. if (cached->yoffset < 0) ached->yoffset = 0; the glyph is fully drawn but, shift under the baseline. BTW, that was adding to fix a memory issue in bug 2749, https://hg.libsdl.org/SDL_ttf/rev/b9d515ee0aaf Created attachment 3360 [details]
patch
Here's a patch I've tested. It determines for each string a padding value to compensate negative yoffsets. Most of the time, it's zero, except with bad fonts.
With this padding added, no need to check overflows at the beginning.
(eg. "if ((row + glyph->yoffset) < 0) { continue".. )
Created attachment 3363 [details]
patch
Updated patch. Use a static global variable, we don't need a per TTF_font instance variable.
Created attachment 3364 [details]
patch
Add a new version so that underline and strike through still works.
@ HAIHONG(Mr.LUO) Did you have the chance to try the patch ? Please don't merge this patch. I have a local version that remove the static variable and fixes a few others issues. Most of app work I've done, as well as the test environment I am familiar to debug with, is SDL v1.2 series, which contains the SDL v2.0.11 for SDL-v1.2. Can I have the version (hopefully a targeted SDL v2.0.12) to work with SDL-v1.2 so that I can try it out? SDLv2 is just totally new and scary learning curve for me. Sorry, I can't make a version for SDL-1.2-branch as I don't use it anymore. But I guess SDL_ttf-2 should be directly compatible with SDL-1.2. Created attachment 3396 [details] patch Here's a new version of the patch, with more diffs. Fix bug 2749 by initializing properly 'xstart' Fix bug 4266 by adding an ystart 'value' Enable underline and strike-through styles for the 'Wrapped' functions. Remove three checks: Unneeded because xstart is now initialized so that it never gets negative: if ((xstart + glyph->minx) < 0) { xstart -= (xstart + glyph->minx); } Unneeded because an ystart offset has been added, so we never read at a negative position: if ((row + glyph->yoffset) < 0) { continue; } Unneeded because it's redundant with the bound checking "dst < dst_check": if ((row + glyph->yoffset) >= textbuf->h) { continue; } Clean up: - use SDL_min/max where it makes the code more readable - a few warnings fixed I have a long test-suite that uses many fonts and many languages, with valid and invalid inputs (only disable text shaping). I have seen no invalid read/write or uninitialized things. The fix for bug #2749 is already in (and packported to SDL-1.2 branch too.) Please re-diff your patch against current hg, and please do not include cleanup / warning fix parts: include _only_ the fix for this bug #4266, and post a different patch for the cleanups/warning fixes if necessary. Created attachment 3397 [details]
patch
Here's the new version with only the fix for this bug
Created attachment 3398 [details]
patch for SDL-1.2 branch
Here is backport of the patch for SDL-1.2 branch.
If no one objects, I can apply this weekend.
The patch for "Enable underline and strike-through styles for the 'Wrapped' functions." is in bug 4333 And the warning patch is in bug 4030 Patch added. SDL-2.0: http://hg.libsdl.org/SDL_ttf/rev/73ae6927d584 SDL-1.2: http://hg.libsdl.org/SDL_ttf/rev/2495a164b8a9 Closing. |
Created attachment 3308 [details] font file I met problem with, and the rendered capture/saved in picture called with, ... pFloorFont=TTF_OpenFont(".//ITCAvantGardeStd-Demi.ttf",297); ... , later further used for rendering: TTF_RenderUTF8_Blended(pFloorFont,"8", whiteColor); ... result is quite off/ascended.