Aestivae's picture

Parts of some characters not rendering when using AntiAliasGridFit (with suggested fix)

Project:QuickFont - Text Printing and Font Generation Library
Version:1.0.2-final
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:open
Description

This is referring to the bug that james_lohr mentioned in an earlier project issue.

I'm not sure if this is still maintained, but since I spent quite some time banging my head against the wall (and finally found a solution, fortunately) I thought I should share.

The fonts that don't render properly with AntiAliasGridFit are due to the retargeting algorithm in Builder.cs. It scans through the bitmap to find the boundaries, then trims the glyph's bounding rectangle to minimize the texture space. The problem here is a simple (and yet incredibly elusive, as always) fencepost error in the scan for-loop.

When looking for the startY and endY, the loop ends prematurely due to an incorrect condition. The condition in lines 217 and 224 (identical lines of code) needs to be changed to i <= endX.

// Builder.cs
                for (startY = rect.Y; startY < bitmapData.Height; startY++)
                    for (int i = startX; i <= endX; i++)    // Line 217
                        if (!emptyPix(bitmapData, i, startY))
                            goto Done3;
 
                Done3:
 
                for (endY = rect.Y + rect.Height; endY >= 0; endY--)
                    for (int i = startX; i <= endX; i++)    // Line 224
                        if (!emptyPix(bitmapData, i, endY))
                            goto Done4;
                Done4:;