Kaydet (Commit) e96c7d42 authored tarafından Caolán McNamara's avatar Caolán McNamara

We can embolden via cairo_ft_font_face_create_for_pattern

If we're able to build a font from a pattern, then we can smuggle
into cairo the info that we want this font to be artificially
emboldened.
üst 11792080
...@@ -166,7 +166,7 @@ public: ...@@ -166,7 +166,7 @@ public:
{ return meAntiAlias == ANTIALIAS_FALSE; } { return meAntiAlias == ANTIALIAS_FALSE; }
bool DontUseHinting() const bool DontUseHinting() const
{ return (meHinting == HINTING_FALSE) || (GetHintStyle() == HINT_NONE); } { return (meHinting == HINTING_FALSE) || (GetHintStyle() == HINT_NONE); }
virtual void *GetPattern(void * /*pFace*/) const virtual void *GetPattern(void * /*pFace*/, bool /*bEmbolden*/) const
{ return NULL; } { return NULL; }
}; };
......
...@@ -63,14 +63,27 @@ namespace basegfx { ...@@ -63,14 +63,27 @@ namespace basegfx {
class CairoFontsCache class CairoFontsCache
{ {
public:
struct CacheId
{
const void *mpFace;
const void *mpOptions;
bool mbEmbolden;
bool operator ==(const CacheId& rOther) const
{
return mpFace == rOther.mpFace &&
mpOptions == rOther.mpOptions &&
mbEmbolden == rOther.mbEmbolden;
}
};
private: private:
static int mnRefCount; static int mnRefCount;
typedef std::deque< std::pair<void *, void*> > LRUFonts; typedef std::deque< std::pair<void *, CacheId> > LRUFonts;
static LRUFonts maLRUFonts; static LRUFonts maLRUFonts;
public: public:
CairoFontsCache(); CairoFontsCache();
static void CacheFont(void *pFont, void *pId); static void CacheFont(void *pFont, const CacheId &rId);
static void* FindCachedFont(void *pId); static void* FindCachedFont(const CacheId &rId);
~CairoFontsCache(); ~CairoFontsCache();
}; };
......
...@@ -59,6 +59,9 @@ using namespace psp; ...@@ -59,6 +59,9 @@ using namespace psp;
#ifndef FC_FT_FACE #ifndef FC_FT_FACE
#define FC_FT_FACE "ftface" #define FC_FT_FACE "ftface"
#endif #endif
#ifndef FC_EMBOLDEN
#define FC_EMBOLDEN "embolden"
#endif
#else #else
typedef void FcConfig; typedef void FcConfig;
typedef void FcObjectSet; typedef void FcObjectSet;
...@@ -1165,11 +1168,14 @@ public: ...@@ -1165,11 +1168,14 @@ public:
if( rWrapper.isValid() ) if( rWrapper.isValid() )
rWrapper.FcPatternDestroy( mpPattern ); rWrapper.FcPatternDestroy( mpPattern );
} }
virtual void *GetPattern(void * face) const virtual void *GetPattern(void * face, bool bEmbolden) const
{ {
FontCfgWrapper& rWrapper = FontCfgWrapper::get(); FontCfgWrapper& rWrapper = FontCfgWrapper::get();
if( rWrapper.isValid() ) if( rWrapper.isValid() )
{
rWrapper.FcPatternAddFTFace(mpPattern, FC_FT_FACE, static_cast<FT_Face>(face)); rWrapper.FcPatternAddFTFace(mpPattern, FC_FT_FACE, static_cast<FT_Face>(face));
rWrapper.FcPatternAddBool(mpPattern, FC_EMBOLDEN, bEmbolden ? FcTrue : FcFalse);
}
return mpPattern; return mpPattern;
} }
FcPattern* mpPattern; FcPattern* mpPattern;
......
...@@ -271,7 +271,7 @@ private: ...@@ -271,7 +271,7 @@ private:
void (*mp_set_font_options)(cairo_t *, const void *); void (*mp_set_font_options)(cairo_t *, const void *);
void (*mp_ft_font_options_substitute)(const void*, void*); void (*mp_ft_font_options_substitute)(const void*, void*);
bool canEmbolden() const { return false; } bool canEmbolden() const { return mp_ft_font_face_create_for_pattern != NULL; }
CairoWrapper(); CairoWrapper();
public: public:
...@@ -447,9 +447,9 @@ CairoFontsCache::~CairoFontsCache() ...@@ -447,9 +447,9 @@ CairoFontsCache::~CairoFontsCache()
} }
} }
void CairoFontsCache::CacheFont(void *pFont, void* pId) void CairoFontsCache::CacheFont(void *pFont, const CairoFontsCache::CacheId &rId)
{ {
maLRUFonts.push_front( std::pair<void*, void *>(pFont, pId) ); maLRUFonts.push_front( std::pair<void*, CairoFontsCache::CacheId>(pFont, rId) );
if (maLRUFonts.size() > 8) if (maLRUFonts.size() > 8)
{ {
CairoWrapper &rCairo = CairoWrapper::get(); CairoWrapper &rCairo = CairoWrapper::get();
...@@ -458,11 +458,11 @@ void CairoFontsCache::CacheFont(void *pFont, void* pId) ...@@ -458,11 +458,11 @@ void CairoFontsCache::CacheFont(void *pFont, void* pId)
} }
} }
void* CairoFontsCache::FindCachedFont(void *pId) void* CairoFontsCache::FindCachedFont(const CairoFontsCache::CacheId &rId)
{ {
LRUFonts::iterator aEnd = maLRUFonts.end(); LRUFonts::iterator aEnd = maLRUFonts.end();
for (LRUFonts::iterator aI = maLRUFonts.begin(); aI != aEnd; ++aI) for (LRUFonts::iterator aI = maLRUFonts.begin(); aI != aEnd; ++aI)
if (aI->second == pId) if (aI->second == rId)
return aI->first; return aI->first;
return NULL; return NULL;
} }
...@@ -533,17 +533,21 @@ void X11SalGraphics::DrawCairoAAFontString( const ServerFontLayout& rLayout ) ...@@ -533,17 +533,21 @@ void X11SalGraphics::DrawCairoAAFontString( const ServerFontLayout& rLayout )
cairo_font_face_t* font_face = NULL; cairo_font_face_t* font_face = NULL;
void *pId = rFont.GetFtFace(); void* pFace = rFont.GetFtFace();
font_face = (cairo_font_face_t*)m_aCairoFontsCache.FindCachedFont(pId); CairoFontsCache::CacheId aId;
aId.mpFace = pFace;
aId.mpOptions = rFont.GetFontOptions();
aId.mbEmbolden = rFont.NeedsArtificialBold();
font_face = (cairo_font_face_t*)m_aCairoFontsCache.FindCachedFont(aId);
if (!font_face) if (!font_face)
{ {
const ImplFontOptions *pOptions = rFont.GetFontOptions(); const ImplFontOptions *pOptions = rFont.GetFontOptions();
void *pPattern = pOptions ? pOptions->GetPattern(pId) : NULL; void *pPattern = pOptions ? pOptions->GetPattern(pFace, aId.mbEmbolden) : NULL;
if (pPattern) if (pPattern)
font_face = rCairo.ft_font_face_create_for_pattern(pPattern); font_face = rCairo.ft_font_face_create_for_pattern(pPattern);
if (!font_face) if (!font_face)
font_face = rCairo.ft_font_face_create_for_ft_face(pId, rFont.GetLoadFlags()); font_face = rCairo.ft_font_face_create_for_ft_face(pFace, rFont.GetLoadFlags());
m_aCairoFontsCache.CacheFont(font_face, pId); m_aCairoFontsCache.CacheFont(font_face, aId);
} }
rCairo.set_font_face(cr, font_face); rCairo.set_font_face(cr, font_face);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment