[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]
[XaraXtreme-dev] Font rendering fix
- From: Martin Wuerthner <lists@xxxxxxxxxxxxxxx>
- Date: Mon, 03 Apr 2006 12:12:15 +0200
- Subject: [XaraXtreme-dev] Font rendering fix
Find attached a patch to fix the character widths of text in Type-1
fonts (obtained via FreeType).
fontbase.cpp:
Delegated scaling of character widths to DesignSize to font manager
ftfonts.cpp:
Scale widths to DesignSize rather than returning raw widths
Martin
Index: wxOil/fontbase.cpp
===================================================================
--- wxOil/fontbase.cpp (Revision 759)
+++ wxOil/fontbase.cpp (Arbeitskopie)
@@ -883,11 +883,16 @@
BOOL FontMetricsCacheEntry::CacheFontMetrics( wxDC* pDC, CharDescription FontDesc,
MILLIPOINT DefaultHeight, INT32 DesignSize )
{
- // get font metrics and convert from design size in pixels to default height in millipoints
INT32 Ascent;
INT32 Descent;
+ // these values are ignored - the DesignSize needs to be read from the font, so the
+ // scaling needs to be done by FTFontMan itself
+ IGNORE(DefaultHeight);
+ IGNORE(DesignSize);
+
#ifdef __WXGTK__
+ // TRACEUSER("wuerthne", _T("CacheFontMetrics DesignSize = %d"), DesignSize);
if (FTFontMan::GetAscentDescent(FontDesc, &Ascent, &Descent) == FALSE) return FALSE;
// scaling to DefaultHeight was done in GetAscentDescent already
SetFontAscent( Ascent );
@@ -897,8 +902,9 @@
static INT32 pTempCharWidthBuf[NUMCHARS];
if (FTFontMan::GetCharWidth(FontDesc, FIRSTCHAR, LASTCHAR, pTempCharWidthBuf)==FALSE)
return FALSE;
+ // scaling to DefaultHeight was done in GetCharWidth already
for (INT32 i=0; i<NUMCHARS; i++)
- pCharWidths[i] = MulDiv(pTempCharWidthBuf[i], DefaultHeight, DesignSize);
+ pCharWidths[i] = pTempCharWidthBuf[i];
// if 'em' char in cache, get it from the cache else calculate its width separately
if (CharInCacheRange(FONTEMCHAR))
@@ -909,7 +915,8 @@
INT32 TempCharWidth = 0;
if (FTFontMan::GetCharWidth(FontDesc, FONTEMCHAR, FONTEMCHAR, &TempCharWidth)==FALSE)
return FALSE;
- SetFontEmWidth( MulDiv(TempCharWidth, DefaultHeight, DesignSize) );
+ // scaling to DefaultHeight was done in GetCharWidth already
+ SetFontEmWidth( TempCharWidth );
}
// update cache tag
Index: wxOil/ftfonts.cpp
===================================================================
--- wxOil/ftfonts.cpp (Revision 759)
+++ wxOil/ftfonts.cpp (Arbeitskopie)
@@ -844,7 +844,7 @@
UINT32* pNumCoords,
wxDC* pDC)
{
- TRACEUSER("wuerthne", _T("FTFontMan::GetCharOutline"));
+ TRACEUSER("wuerthne", _T("FTFontMan::GetCharOutline %04x"), ChDesc.GetCharCode());
// Check some input parameters
ERROR2IF(ppCoords==NULL,FALSE,"FTFontMan::GetCharOutline ppCoords==NULL");
ERROR2IF(ppVerbs==NULL,FALSE,"FTFontMan::GetCharOutline ppVerbs==NULL");
@@ -942,7 +942,8 @@
Outputs: character widths into pCharWidthsBuf
Returns: TRUE if the widths could be retrieved
FALSE if not.
- Purpose: This function returns the raw widths of a range of characters
+ Purpose: This function returns the widths of a range of characters scaled
+ to DefaultHeight
********************************************************************************************/
@@ -956,8 +957,8 @@
if (!GetPangoFcFontAndFreeTypeFaceForCharDesc(ChDesc, &pPangoFcFont, &pFreeTypeFace)) return FALSE;
// get the design size
- // INT32 DesignSize = pFreeTypeFace->units_per_EM;
- // TRACEUSER("wuerthne", _T("DesignSize = %d"), DesignSize);
+ INT32 DesignSize = pFreeTypeFace->units_per_EM;
+ TRACEUSER("wuerthne", _T("GetCharWidth, DesignSize = %d"), DesignSize);
for (UINT32 i = 0; i < NumChars; i++) {
// load the glyph data for our character into the font's glyph slot
@@ -967,7 +968,7 @@
ERROR2(FALSE, "FTFontMan::GetCharWidth - could not load glyph");
}
FT_GlyphSlotRec *pGlyph = pFreeTypeFace->glyph;
- pCharWidthsBuf[i] = pGlyph->linearHoriAdvance;
+ pCharWidthsBuf[i] = ScaleToDefaultHeight(pGlyph->linearHoriAdvance, DesignSize);
}
pango_fc_font_unlock_face(pPangoFcFont);
return TRUE;