Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug 4351 - Fixing corner case with underline / strike-through
Sylvain When applying small size and big outline and underline and strike through, it happens nasty corner cases. that would make the code crash if there were not boundary check. - we have already increased the limit for underline style set by something like this: font->height = SDL_max(font->height, bottom_row); I added the same update of font->height also for strike-through. (big outline makes the lines thickness be greater than height/2 and then bottom_row writes than surface height). - Then now, there is a circular dependency, because: TTF_strikethrough_top_row() returns (height/2) bottom_row = TTF_strikethrough_top_row() + thickness new height is SDL_max(font->height, bottom_row); when it renders, TTF_strikethrough_top_row() returns (new_height/2). which can write out of bounds. So I just move the strike/underline_to_row in the font structure. They are initialized when style changes. And not recomputed any more each time it renders. We just need to make sure the TTF_Size() is set correctly. Since the line can be of any thickness. it's inside a boundary box of miny=0 maxy=font->height at yoffset 0. We can virtually treat it as glyph by adding the same check: maxy = SDL_max(maxy, glyph->yoffset + glyph->maxy - glyph->miny); ie maxy = SDL_max(maxy, font->height); finally simply initializing maxy = font->height; and also the height surface *h = SDL_max(font->height, maxy - miny); as maxy >= font->height, and miny <=0, becames only: *h = (maxy - miny); In the modification: - create underline/strikethrough_top_row into TTF_FONT structure, and remove TTF_underline/strikethrough_top_row() private functions. - remove the boundary check of DrawLines - merge together TTF_drawLine_Solid() & TTF_drawLine_Shaded() as there are similar. (color 1, vers NUMGRAY - 1) - inline TTF_initLineMectrics just initializing two vars. - remove a duplicate "maxx = SDL_max(maxx, x + glyph->advance);"
- Loading branch information
Showing
1 changed file
with
43 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters