FTFontMan Class Reference

A static class to allow access to fonts managed by FreeType. More...

#include <ftfonts.h>

Inheritance diagram for FTFontMan:

CCObject SimpleCCObject List of all members.

Public Member Functions

 FTFontMan ()
 Default constructor.

Static Public Member Functions

static BOOL GetAscentDescent (CharDescription &ChDesc, INT32 *pAscent, INT32 *pDescent)
 This function returns the ascent and descent of a given font scaled to DefaultHeight.
static BOOL GetCharWidth (CharDescription &ChDesc, TCHAR FirstChar, TCHAR LastChar, INT32 *pCharWidthsBuf)
 This function returns the widths of a range of characters scaled to DefaultHeight.
static INT32 GetCharsKerning (CharDescription &FontDesc, TCHAR LeftChar, TCHAR RightChar)
 This function returns the kerning between two glyphs scaled to DefaultHeight.
static void EnumAllFonts (OILEnumFonts *pClass)
 Gives the kernel a way of enumerating fonts itself.
static FontClass GetFontClass (String_64 &FaceName)
 Checks that the font is installed, is scalable and not a virtual font. Reports FC_TRUETYPE or FC_ATM. Reports FC_UNDEFINED if either of the above is not true or if the type could not be established.
static void AddFontToCache (ENUMLOGFONT &EnumLogFont)
 Add the given font to the font list cache.
static BOOL FontIsCached (ENUMLOGFONT &EnumLogFont)
 Check whether the given font is in the font list cache If it is, update its Referenced field as a side-effect.
static void UpdateCache ()
 Update the font list cache to reflect the wxWidgets font enumeration.

Static Private Member Functions

static BOOL IsOkToCall ()
 Determine whether we can make further calls to the TrueType Manager.
static BOOL CacheNamedFont (String_64 *pFont)
 This function attempts to cache a font supported by FreeType. It caches the font in the kernels font list, and hence can be accessed via FONTMANAGER-> calls.
static BOOL CacheCompatibleFont (String_64 *pFont)
 This function attempts to cache a compatible font.
static void ValidateCache ()
 This function will attempt to recache all FreeType fonts within the kernels font manager cache.
static void FindClosestFont ()
 Enumerates all the fonts reporting each to the Panose matcher in FontMan.
static FTFontCreateNewFont (String_64 *pFontName, FontClass Class)
 This function attempts to create a font instance and will be called by the font manager when new fonts are added.
static OUTLINETEXTMETRICGetOutlineTextMetric (LOGFONT *pLogFont)
 get the Panose structure for a font
static BOOL GetCharOutline (CharDescription &ChDesc, DocCoord **ppCoords, PathVerb **ppVerbs, UINT32 *pNumCoords, wxDC *pDC)
 Get the path associated with a given character.
static BOOL CacheFontCore (String_64 *pFont, BOOL compatible)
 This function attempts to cache a font supported by FreeType. It caches the font in the kernels font list, and hence can be accessed via FONTMANAGER-> calls.

Static Private Attributes

static FTFontCachem_cache = NULL

Friends

class OILFontMan

Detailed Description

A static class to allow access to fonts managed by FreeType.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
22/02/06

Definition at line 177 of file ftfonts.h.


Constructor & Destructor Documentation

FTFontMan::FTFontMan  ) 
 

Default constructor.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/09/95

Definition at line 214 of file ftfonts.cpp.

00215 {
00216 }


Member Function Documentation

void FTFontMan::AddFontToCache ENUMLOGFONT EnumLogFont  )  [static]
 

Add the given font to the font list cache.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
19/05/06
Parameters:
EnumLogFont - the face name wrapped in a LOGFONT/ENUMLOGFONT structure [INPUTS]

Definition at line 594 of file ftfonts.cpp.

00595 {
00596     FontClass OurFontClass = FTFontMan::GetFontClass(EnumLogFont.elfLogFont.FaceName);
00597     FTFontCacheEntry OurEntry(OurFontClass, TRUE);
00598     (*m_cache)[EnumLogFont] = OurEntry;
00599 }

BOOL FTFontMan::CacheCompatibleFont String_64 pFontName  )  [static, private]
 

This function attempts to cache a compatible font.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
06/03/06
Parameters:
pFontName = a pointer to a fontname to find and cache [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the font has been cached FALSE if not.

Definition at line 368 of file ftfonts.cpp.

00369 {
00370     return CacheFontCore(pFontName, TRUE);
00371 }

BOOL FTFontMan::CacheFontCore String_64 pFontName,
BOOL  compatible
[static, private]
 

This function attempts to cache a font supported by FreeType. It caches the font in the kernels font list, and hence can be accessed via FONTMANAGER-> calls.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
06/03/06
Parameters:
pFontName = a pointer to a fontname to find and cache [INPUTS] compatible = if TRUE, an inexact match can be tolerated, else we want an exact match
- [OUTPUTS]
Returns:
TRUE if the font has been cached FALSE if not.

Definition at line 260 of file ftfonts.cpp.

00261 {
00262     DumpString64User("wuerthne", _T("FTFontMan::CacheNamedFont"), pFontName);
00263     TRACEUSER("wuerthne", _T("compatible = %d"), compatible);
00264     
00265     PangoContext* pPangoContext = GetPangoContext();
00266     PangoFontMap* pFontMap = pango_context_get_font_map(pPangoContext);
00267     PangoFontDescription* pDescription = pango_font_description_new();
00268 
00269     char ASCIIName[64];   // TYPENOTE: Correct - Pango wants a plain char name
00270     if (!ToASCII((TCHAR*)*pFontName, ASCIIName, 64)) return FALSE;
00271 
00272     // we ask Pango for a font with the given name
00273     pango_font_description_set_family_static(pDescription, ASCIIName);
00274     pango_font_description_set_style(pDescription, PANGO_STYLE_NORMAL);
00275     pango_font_description_set_weight(pDescription, PANGO_WEIGHT_NORMAL);
00276     pango_font_description_set_size(pDescription, 12 * PANGO_SCALE);
00277 
00278     PangoFont* pFont = pango_font_map_load_font(pFontMap, pPangoContext,
00279                                                 pDescription);
00280     pango_font_description_free(pDescription);
00281 
00282     // Pango will always give us some font, no matter whether the font we asked
00283     // for is installed or not, so check what we really got
00284     PangoFontDescription *pRealDesc = pango_font_describe(pFont);
00285 
00286     wxString wxName(pango_font_description_get_family(pRealDesc), wxConvUTF8);
00287     String_64 OurFontName(wxName);
00288     DumpString64User("wuerthne", _T("Got font"), &OurFontName);
00289     TRACEUSER("wuerthne", _T("real font description has style = %d, weight = %d"),
00290               pango_font_description_get_style(pRealDesc), pango_font_description_get_weight(pRealDesc));
00291     pango_font_description_free(pRealDesc);
00292     
00293     // NB - Apart from the following "if" this routine only fails in case of a technical error
00294     //      not because the required font is not present. At the moment, we only check that we
00295     //      got the right font if compatible == FALSE, but we are always called with
00296     //      compatible == TRUE afterwards, so effectively, we always find a font, in the worst
00297     //      case some system default font. That means that the clever Panose matching code is
00298     //      never used because it is only called if both passes (first with compatible == FALSE
00299     //      then with compatible == TRUE) fail. Removing the "!compatible" check on the other
00300     //      hand means that we only allow an exact match and hence cannot make use of fontconfig's
00301     //      font substitution service, most notably using the user's own font substitution rules.
00302 
00303     // check whether the font name is the same as the one we asked for (case-insensitive)
00304     if (!compatible && !pFontName->IsEmpty() && OurFontName.CompareTo(*pFontName, FALSE) != 0) {
00305         // we wanted an exact match, but the names do not match, so do not cache the font
00306         TRACEUSER("wuerthne", _T("Name did not match, so fail"));
00307         return FALSE;
00308     }
00309 
00310     // register the font with the kernel
00311     TRACEUSER("wuerthne", _T("Register font"));
00312     Application* pApp = GetApplication();
00313     FontManager* pFontMan = pApp->GetFontManager();
00314     ENUMLOGFONT OurEnumLogFont;
00315     OurEnumLogFont.elfLogFont.FaceName = OurFontName;
00316     FontClass Class = GetFontClass(OurFontName);
00317     if (Class == FC_TRUETYPE || Class == FC_ATM)
00318     {
00319         pFontMan->SetTempFont(Class, &OurFontName, &OurEnumLogFont);  // kernel copies the ENUMLOGFONT structure
00320         return TRUE;
00321     }
00322     return FALSE;
00323 }

BOOL FTFontMan::CacheNamedFont String_64 pFontName  )  [static, private]
 

This function attempts to cache a font supported by FreeType. It caches the font in the kernels font list, and hence can be accessed via FONTMANAGER-> calls.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
06/03/06
Parameters:
pFontName = a pointer to a fontname to find and cache [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the font has been cached FALSE if not.

Definition at line 341 of file ftfonts.cpp.

00342 {
00343     TRACEUSER("wuerthne", _T("CacheNamedFont %08x"), pFontName);
00344     if (pFontName == NULL) {
00345         // we are called with a NULL pointer from the kernel, so pass an empty string instead,
00346         // which will probably prompt Pango to return its default font
00347         TRACEUSER("wuerthne", _T("CacheNamedFont called with NULL ptr, using emtpy string instead"));
00348         String_64 FontName(_T(""));
00349         return CacheFontCore(&FontName, FALSE);
00350     }
00351     else return CacheFontCore(pFontName, FALSE);
00352 }

FTFont * FTFontMan::CreateNewFont String_64 pFontName,
FontClass  Class
[static, private]
 

This function attempts to create a font instance and will be called by the font manager when new fonts are added.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
pFontName = a pointer to a fontname [INPUTS]
Returns:
NULL if no FreeType font structure has been created A pointer to a FreeType font structure if successfull.

Definition at line 701 of file ftfonts.cpp.

00702 {
00703     DumpString64User("wuerthne", _T("FTFontMan::CreateNewFont"), pFontName);
00704     FTFont* pFont = new FTFont(Class);
00705     if (pFont && !pFont->Initialise(pFontName))
00706     {
00707         delete pFont;
00708         return NULL;
00709     }
00710     return pFont;
00711 }

void FTFontMan::EnumAllFonts OILEnumFonts pOilEnumerator  )  [static]
 

Gives the kernel a way of enumerating fonts itself.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
06/03/06
Parameters:
pOilEnumerator = A pointer to an object to call back. [INPUTS]

Definition at line 665 of file ftfonts.cpp.

00666 {
00667     // use wxWidgets to enumerate all font families
00668     TRACEUSER("wuerthne", _T("FTFontMan::EnumAllFonts"));
00669 
00670     // we cache the results so we first check whether the cache can still be used
00671     UpdateCache();
00672 
00673     // now, simply return the information from the cache
00674     BOOL go_on = TRUE;
00675     for (FTFontCache::iterator it = m_cache->begin(); go_on && it != m_cache->end(); ++it)
00676     {
00677         FontClass OurFontClass = (*it).second.m_Class;
00678         if (OurFontClass == FC_TRUETYPE || OurFontClass == FC_ATM)
00679         {
00680             ENUMLOGFONT EnumLogFont = (*it).first;
00681             go_on = pOilEnumerator->NewFont(OurFontClass, &EnumLogFont);
00682         }
00683     }
00684     TRACEUSER("wuerthne", _T("FTFontMan::EnumAllFonts done"));
00685 }

void FTFontMan::FindClosestFont  )  [static, private]
 

Enumerates all the fonts reporting each to the Panose matcher in FontMan.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
19/04/06

Definition at line 489 of file ftfonts.cpp.

00490 {
00491     // use wxWidgets to enumerate all font families
00492     TRACEUSER("wuerthne", _T("FTFonMan::FindClosestFont"));
00493     ClosestFontEnumerator WxEnumerator;
00494     WxEnumerator.EnumerateFacenames();  
00495 }

BOOL FTFontMan::FontIsCached ENUMLOGFONT EnumLogFont  )  [static]
 

Check whether the given font is in the font list cache If it is, update its Referenced field as a side-effect.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
19/05/06
Parameters:
EnumLogFont - the face name wrapped in a LOGFONT/ENUMLOGFONT structure [INPUTS]
Returns:
TRUE if the font is in the cache

Definition at line 572 of file ftfonts.cpp.

00573 {
00574     FTFontCache::iterator it = m_cache->find(EnumLogFont);
00575     if (it != m_cache->end())
00576     {
00577         (*it).second.m_Referenced = TRUE;
00578         return TRUE;
00579     }
00580     return FALSE;
00581 }

BOOL FTFontMan::GetAscentDescent CharDescription ChDesc,
INT32 *  pAscent,
INT32 *  pDescent
[static]
 

This function returns the ascent and descent of a given font scaled to DefaultHeight.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
09/03/06
Parameters:
chDesc - a Kernel character description (to identify the font) [INPUTS]
font ascent and descent in pAscent and pDescent [OUTPUTS]
Returns:
TRUE if the values could be retrieved FALSE if not.

Definition at line 1349 of file ftfonts.cpp.

01350 {
01351     PangoFcFont* pPangoFcFont;
01352     FT_Face pFreeTypeFace;
01353     // TRACEUSER("wuerthne", _T("GetAscentDescent"));
01354     if (!GetPangoFcFontAndFreeTypeFaceForCharDesc(ChDesc, &pPangoFcFont, &pFreeTypeFace)) return FALSE;
01355 
01356     // get the design size
01357     INT32 DesignSize = pFreeTypeFace->units_per_EM;
01358     *pAscent = ScaleToDefaultHeight(pFreeTypeFace->ascender, DesignSize);
01359     *pDescent = ScaleToDefaultHeight(-pFreeTypeFace->descender, DesignSize);
01360     // TRACEUSER("wuerthne", _T("returning ascent = %d, descent = %d"), *pAscent, *pDescent);
01361     pango_fc_font_unlock_face(pPangoFcFont);
01362     return TRUE;
01363 }

BOOL FTFontMan::GetCharOutline CharDescription ChDesc,
DocCoord **  ppCoords,
PathVerb **  ppVerbs,
UINT32 pNumCoords,
wxDC *  pDC
[static, private]
 

Get the path associated with a given character.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
06/03/06
Parameters:
ChDesc = description of char [INPUTS] pDC = (possible) pointer to a DC (for optimisation) defaults to NULL
ppCoords = pointer to path coords buffer [OUTPUTS] ppVerbs = pointer to path verbs buffer pNumCoords = number of elements in path
Returns:
FALSE if unable to generate the character outline

Definition at line 1219 of file ftfonts.cpp.

01224 {
01225     // TRACEUSER("wuerthne", _T("FTFontMan::GetCharOutline %04x"), ChDesc.GetCharCode());
01226     // Check some input parameters
01227     ERROR2IF(ppCoords==NULL,FALSE,"FTFontMan::GetCharOutline ppCoords==NULL");
01228     ERROR2IF(ppVerbs==NULL,FALSE,"FTFontMan::GetCharOutline ppVerbs==NULL");
01229     ERROR2IF(pNumCoords==NULL,FALSE,"FTFontMan::GetCharOutline pNumCoords==NULL");
01230 
01231     PangoFcFont* pPangoFcFont;
01232     FT_Face pFreeTypeFace;
01233     if (!GetPangoFcFontAndFreeTypeFaceForCharDesc(ChDesc, &pPangoFcFont, &pFreeTypeFace)) return FALSE;
01234 
01235     // get the design size
01236     INT32 DesignSize = pFreeTypeFace->units_per_EM;
01237     // TRACEUSER("wuerthne", _T("DesignSize = %d"), DesignSize);
01238 
01239     // load the glyph data for our character into the font's glyph slot
01240     if (FT_Load_Char(pFreeTypeFace, ChDesc.GetCharCode(), FT_LOAD_NO_SCALE))
01241     {
01242         pango_fc_font_unlock_face(pPangoFcFont);
01243         ERROR2(FALSE, "FTFontMan::GetCharOutline - could not load glyph");
01244     }
01245 
01246     FT_GlyphSlotRec *pGlyph = pFreeTypeFace->glyph;
01247 
01248     // TRACEUSER("wuerthne", _T("found outline, %d contours, %d points"),
01249     //        pGlyph->outline.n_contours, pGlyph->outline.n_points);
01250     // finally, we have the glyph we want, so transfer it to the outlines cache
01251     OILFontMan::InitialiseOutlineCache();
01252 
01253     FT_Outline_Funcs funcs = { AddMoveTo, AddLineTo, AddConicTo, AddCubicTo, 0, 0 };
01254     DecompState state;
01255     state.DesignSize = DesignSize;
01256     state.IsFirstMove = TRUE;
01257 
01258     // TRACEUSER("wuerthne", _T("calling Outline_Decompose"));
01259     if (FT_Outline_Decompose(&pGlyph->outline, &funcs, &state))
01260     {
01261         OILFontMan::FinaliseOutlineCache();
01262         pango_fc_font_unlock_face(pPangoFcFont);
01263         return FALSE;
01264     }
01265     // TRACEUSER("wuerthne", _T("Outline_Decompose success"));
01266 
01267     // close the last contour if there was any output at all
01268     if (!state.IsFirstMove)
01269     {
01270         OILFontMan::ClosePath();
01271     }
01272     OILFontMan::FinaliseOutlineCache();
01273     pango_fc_font_unlock_face(pPangoFcFont);
01274     (*pNumCoords) = OILFontMan::GetOutlineCache(ppCoords,ppVerbs);
01275     // TRACEUSER("wuerthne", _T("FTFontMan::GetCharOutline Returning %d coords"), *pNumCoords);
01276     return TRUE;
01277 }

INT32 FTFontMan::GetCharsKerning CharDescription FontDesc,
TCHAR  LeftChar,
TCHAR  RightChar
[static]
 

This function returns the kerning between two glyphs scaled to DefaultHeight.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
19/04/06
Parameters:
FontDesc - a Kernel character description (to identify the font) [INPUTS] LeftChar, RightChar - left and right character
- [OUTPUTS]
Returns:
the kerning to be applied between LeftChar and RightChar

Definition at line 1424 of file ftfonts.cpp.

01425 {
01426     PangoFcFont* pPangoFcFont;
01427     FT_Face pFreeTypeFace;
01428 
01429     // TRACEUSER("wuerthne", _T("GetCharsKerning, %04x %04x"), LeftChar, RightChar);
01430     if (!GetPangoFcFontAndFreeTypeFaceForCharDesc(FontDesc, &pPangoFcFont, &pFreeTypeFace)) return 0;
01431 
01432     // get the design size
01433     INT32 DesignSize = pFreeTypeFace->units_per_EM;
01434 
01435     FT_ULong LeftIndex = FT_Get_Char_Index(pFreeTypeFace, LeftChar);
01436     FT_ULong RightIndex = FT_Get_Char_Index(pFreeTypeFace, RightChar);;
01437 
01438     FT_Vector kerning;
01439     FT_Error FreeTypeError;
01440     if ((FreeTypeError = FT_Get_Kerning(pFreeTypeFace, LeftIndex, RightIndex, FT_KERNING_UNSCALED, &kerning)) != 0)
01441     {
01442         TRACEUSER("wuerthne", _T("could not get kerning, error = %d"), FreeTypeError);
01443         return 0;
01444     }
01445 
01446     // TRACEUSER("wuerthne", _T("Got kerning: %d"), kerning.x);
01447     pango_fc_font_unlock_face(pPangoFcFont);
01448     return ScaleToDefaultHeight(kerning.x, DesignSize);
01449 }

BOOL FTFontMan::GetCharWidth CharDescription ChDesc,
TCHAR  FirstChar,
TCHAR  LastChar,
INT32 *  pCharWidthsBuf
[static]
 

This function returns the widths of a range of characters scaled to DefaultHeight.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
09/03/06
Parameters:
chDesc - a Kernel character description (to identify the font) [INPUTS] FirstChar - first character to get the width for LastChar - last character
character widths into pCharWidthsBuf [OUTPUTS]
Returns:
TRUE if the widths could be retrieved FALSE if not.

Definition at line 1383 of file ftfonts.cpp.

01385 {
01386     // TRACEUSER("wuerthne", _T("FTFontMan::GetCharWidth first=%04x last=%04x"), FirstChar, LastChar);
01387     UINT32 NumChars = LastChar - FirstChar + 1;
01388     PangoFcFont* pPangoFcFont;
01389     FT_Face pFreeTypeFace;
01390     if (!GetPangoFcFontAndFreeTypeFaceForCharDesc(ChDesc, &pPangoFcFont, &pFreeTypeFace)) return FALSE;
01391 
01392     // get the design size
01393     INT32 DesignSize = pFreeTypeFace->units_per_EM;
01394     // TRACEUSER("wuerthne", _T("GetCharWidth, DesignSize = %d"), DesignSize);
01395 
01396     for (UINT32 i = 0; i < NumChars; i++) {
01397         // load the glyph data for our character into the font's glyph slot
01398         if (FT_Load_Char(pFreeTypeFace, FirstChar + i, FT_LOAD_NO_SCALE | FT_LOAD_LINEAR_DESIGN))
01399         {
01400             pango_fc_font_unlock_face(pPangoFcFont);
01401             ERROR2(FALSE, "FTFontMan::GetCharWidth - could not load glyph");
01402         }
01403         FT_GlyphSlotRec *pGlyph = pFreeTypeFace->glyph;
01404         pCharWidthsBuf[i] = ScaleToDefaultHeight(pGlyph->linearHoriAdvance, DesignSize);
01405     }
01406     pango_fc_font_unlock_face(pPangoFcFont);
01407     return TRUE;
01408 }

FontClass FTFontMan::GetFontClass String_64 FaceName  )  [static]
 

Checks that the font is installed, is scalable and not a virtual font. Reports FC_TRUETYPE or FC_ATM. Reports FC_UNDEFINED if either of the above is not true or if the type could not be established.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
18/05/06
Parameters:
FaceName - the name of the font we want to enquire about [INPUTS]

Definition at line 406 of file ftfonts.cpp.

00407 {
00408     FontClass fc = FC_UNDEFINED;
00409     PangoFcFont* pPangoFcFont;
00410     FT_Face pFreeTypeFace;
00411     if (GetPangoFcFontAndFreeTypeFaceForFaceName(&FaceName, &pPangoFcFont, &pFreeTypeFace))
00412     {
00413         // At this stage, we know that the font is scalable, otherwise the above call
00414         // would have returned an error already. Now, check whether this is a virtual
00415         // font (e.g., "Monospace") presented to us by fontconfig. We do that by reading
00416         // back the family name and comparing it to the one we passed.
00417         PangoFontDescription *pRealDesc = pango_font_describe((PangoFont*)pPangoFcFont);
00418         wxString wxName(pango_font_description_get_family(pRealDesc), wxConvUTF8);
00419         String_64 OurFontName(wxName);
00420         pango_font_description_free(pRealDesc);
00421         if (OurFontName.CompareTo(FaceName, FALSE) == 0)
00422         {
00423             PS_FontInfoRec PSRec;
00424             if (FT_Get_PS_Font_Info(pFreeTypeFace, &PSRec) != FT_Err_Invalid_Argument)
00425                 fc = FC_ATM;
00426             else
00427             {
00428                 if (FT_IS_SFNT(pFreeTypeFace)) fc = FC_TRUETYPE;
00429                 else
00430                 {
00431                     // scalable, but not PS-based and not SFNT-based, so not TrueType either
00432                     // ignore this for the time being, but we can probably support this type
00433                     // of font
00434                 }
00435             }
00436         }
00437         pango_fc_font_unlock_face(pPangoFcFont);
00438     }
00439     return fc;
00440 }

OUTLINETEXTMETRIC * FTFontMan::GetOutlineTextMetric LOGFONT pLogFont  )  [static, private]
 

get the Panose structure for a font

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
19/04/06
Parameters:
pLogFont = font descriptor [INPUTS]
Returns:
an OUTLINETEXTMETRIC structure or NULL if the information cannot be obtained (Panose information is only available for TrueType fonts, not for Type-1 fonts) The caller is responsible for freeing the structure

Definition at line 1297 of file ftfonts.cpp.

01298 {
01299     String_64* pFaceName = &pLogFont->FaceName;
01300     PangoFcFont* pPangoFcFont;
01301     FT_Face pFreeTypeFace;
01302     // DumpString64User("wuerthne", _T("FTFontMan::GetOutlineTextMetric"), pFaceName);
01303 
01304     // first of all, retrieve the underlying font information
01305     if (!GetPangoFcFontAndFreeTypeFaceForFaceName(pFaceName, &pPangoFcFont, &pFreeTypeFace)) return NULL;
01306     // we have successfully retrieved the FreeType information (we need to release it below!)
01307 
01308     // ask FreeType for the Panose information - this is found in the OS/2 font table,
01309     // so check whether this font has a TrueType OS/2 font table
01310     TT_OS2* pOS2_Table;
01311     if ((pOS2_Table = (TT_OS2*)FT_Get_Sfnt_Table(pFreeTypeFace, ft_sfnt_os2)) == NULL   /* error loading */
01312         || pOS2_Table->version == 0xffff /* Mac font without OS/2 table */)
01313     {
01314         // we could not get the table with the Panose information, either because there
01315         // was an error when trying to load it or because the font is not a TrueType font,
01316         // or because it is an old Mac TrueType font without Panose information
01317         pango_fc_font_unlock_face(pPangoFcFont);
01318         return NULL;
01319     }
01320 
01321     // we have got the OS/2 table - it is owned by the face object so we need not free it,
01322     // it will disappear when we unlock the font face below
01323 
01324     // We need a permanent structure - the pointer may be cached. Otherwise, the kernel
01325     // will free the structure.
01326     OUTLINETEXTMETRIC* pMetric = new OUTLINETEXTMETRIC;
01327     pMetric->otmPanoseNumber = *((struct PANOSE*)&pOS2_Table->panose);
01328     // TRACEUSER("wuerthne", _T("returning valid OUTLINEFONTMETRIC structure"));
01329 
01330     pango_fc_font_unlock_face(pPangoFcFont);
01331     return pMetric;
01332 }

BOOL FTFontMan::IsOkToCall  )  [static, private]
 

Determine whether we can make further calls to the TrueType Manager.

static BOOL TTFontMan::IsOkToCall()

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
01/9/95
Returns:
TRUE if the FreeType manager is actually running and can be used on this OpSys

Definition at line 229 of file ftfonts.cpp.

00230 {
00231     // Currently its always true as this is the wxOil
00232     return TRUE;
00233 }

void FTFontMan::UpdateCache  )  [static]
 

Update the font list cache to reflect the wxWidgets font enumeration.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
19/05/06
Parameters:
- [INPUTS]

Definition at line 612 of file ftfonts.cpp.

00613 {
00614     MyFontEnumerator::CacheAction action;
00615     if (m_cache)
00616     {
00617         // we already have a cache, so just update it incrementally
00618         action = MyFontEnumerator::UpdateCache;
00619         // we want to purge entries that are no longer installed, so mark all entries as unreferenced
00620         // the cache update step will mark all the fonts it finds as Referenced
00621         for (FTFontCache::iterator it = m_cache->begin(); it != m_cache->end(); ++it)
00622             (*it).second.m_Referenced = FALSE;
00623     }
00624     else
00625     {
00626         // initial run
00627         m_cache = new FTFontCache;
00628         action = MyFontEnumerator::FillCache;
00629     }
00630     MyFontEnumerator FontEnumerator(action);
00631     FontEnumerator.EnumerateFacenames();
00632 
00633     if (action == MyFontEnumerator::UpdateCache) {
00634         // delete all fonts that have been deinstalled since we last checked
00635         for (FTFontCache::iterator it = m_cache->begin(); it != m_cache->end();)
00636         {
00637             if (!(*it).second.m_Referenced)
00638             {
00639                 TRACEUSER("wuerthne", _T("%s removed from font list cache"),
00640                           (const TCHAR*)((*it).first.elfLogFont.FaceName));
00641                 // NB - it++ first increments the iterator, then returns the iterator
00642                 //      to the current element, which is then deleted - this is safe,
00643                 //      as opposed to first deleting and then incrementing
00644                 m_cache->erase(it++);
00645             }
00646             else
00647             {
00648                 ++it;       
00649             }
00650         }
00651     }
00652 }

void FTFontMan::ValidateCache  )  [static, private]
 

This function will attempt to recache all FreeType fonts within the kernels font manager cache.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
06/03/06

Definition at line 384 of file ftfonts.cpp.

00385 {
00386     PORTNOTETRACE("text", "FTFontMan::ValidateCache - do nothing");
00387 }


Friends And Related Function Documentation

friend class OILFontMan [friend]
 

Definition at line 181 of file ftfonts.h.


Member Data Documentation

FTFontCache * FTFontMan::m_cache = NULL [static, private]
 

Definition at line 216 of file ftfonts.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:54:39 2007 for Camelot by  doxygen 1.4.4