[Libreoffice-commits] .: vcl/inc vcl/unx
Caolán McNamara
caolan at kemper.freedesktop.org
Fri Mar 18 09:22:41 PDT 2011
vcl/inc/vcl/impfont.hxx | 2 +-
vcl/unx/inc/salgdi.h | 19 ++++++++++++++++---
vcl/unx/source/fontmanager/fontconfig.cxx | 8 +++++++-
vcl/unx/source/gdi/salgdi3.cxx | 24 ++++++++++++++----------
4 files changed, 38 insertions(+), 15 deletions(-)
New commits:
commit 9e1e61b9cb4e5308437211433d65bc7bca41b263
Author: Caolán McNamara <caolanm at redhat.com>
Date: Fri Mar 18 16:20:38 2011 +0000
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.
diff --git a/vcl/inc/vcl/impfont.hxx b/vcl/inc/vcl/impfont.hxx
index faf264b..600a20f 100644
--- a/vcl/inc/vcl/impfont.hxx
+++ b/vcl/inc/vcl/impfont.hxx
@@ -166,7 +166,7 @@ public:
{ return meAntiAlias == ANTIALIAS_FALSE; }
bool DontUseHinting() const
{ return (meHinting == HINTING_FALSE) || (GetHintStyle() == HINT_NONE); }
- virtual void *GetPattern(void * /*pFace*/) const
+ virtual void *GetPattern(void * /*pFace*/, bool /*bEmbolden*/) const
{ return NULL; }
};
diff --git a/vcl/unx/inc/salgdi.h b/vcl/unx/inc/salgdi.h
index edead21..de32ac6 100644
--- a/vcl/unx/inc/salgdi.h
+++ b/vcl/unx/inc/salgdi.h
@@ -63,14 +63,27 @@ namespace basegfx {
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:
static int mnRefCount;
- typedef std::deque< std::pair<void *, void*> > LRUFonts;
+ typedef std::deque< std::pair<void *, CacheId> > LRUFonts;
static LRUFonts maLRUFonts;
public:
CairoFontsCache();
- static void CacheFont(void *pFont, void *pId);
- static void* FindCachedFont(void *pId);
+ static void CacheFont(void *pFont, const CacheId &rId);
+ static void* FindCachedFont(const CacheId &rId);
~CairoFontsCache();
};
diff --git a/vcl/unx/source/fontmanager/fontconfig.cxx b/vcl/unx/source/fontmanager/fontconfig.cxx
index fea0d9e..27c4079 100644
--- a/vcl/unx/source/fontmanager/fontconfig.cxx
+++ b/vcl/unx/source/fontmanager/fontconfig.cxx
@@ -59,6 +59,9 @@ using namespace psp;
#ifndef FC_FT_FACE
#define FC_FT_FACE "ftface"
#endif
+ #ifndef FC_EMBOLDEN
+ #define FC_EMBOLDEN "embolden"
+ #endif
#else
typedef void FcConfig;
typedef void FcObjectSet;
@@ -1165,11 +1168,14 @@ public:
if( rWrapper.isValid() )
rWrapper.FcPatternDestroy( mpPattern );
}
- virtual void *GetPattern(void * face) const
+ virtual void *GetPattern(void * face, bool bEmbolden) const
{
FontCfgWrapper& rWrapper = FontCfgWrapper::get();
if( rWrapper.isValid() )
+ {
rWrapper.FcPatternAddFTFace(mpPattern, FC_FT_FACE, static_cast<FT_Face>(face));
+ rWrapper.FcPatternAddBool(mpPattern, FC_EMBOLDEN, bEmbolden ? FcTrue : FcFalse);
+ }
return mpPattern;
}
FcPattern* mpPattern;
diff --git a/vcl/unx/source/gdi/salgdi3.cxx b/vcl/unx/source/gdi/salgdi3.cxx
index d9d5d70..20fd3cd 100644
--- a/vcl/unx/source/gdi/salgdi3.cxx
+++ b/vcl/unx/source/gdi/salgdi3.cxx
@@ -271,7 +271,7 @@ private:
void (*mp_set_font_options)(cairo_t *, const 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();
public:
@@ -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)
{
CairoWrapper &rCairo = CairoWrapper::get();
@@ -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();
for (LRUFonts::iterator aI = maLRUFonts.begin(); aI != aEnd; ++aI)
- if (aI->second == pId)
+ if (aI->second == rId)
return aI->first;
return NULL;
}
@@ -533,17 +533,21 @@ void X11SalGraphics::DrawCairoAAFontString( const ServerFontLayout& rLayout )
cairo_font_face_t* font_face = NULL;
- void *pId = rFont.GetFtFace();
- font_face = (cairo_font_face_t*)m_aCairoFontsCache.FindCachedFont(pId);
+ void* pFace = rFont.GetFtFace();
+ 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)
{
const ImplFontOptions *pOptions = rFont.GetFontOptions();
- void *pPattern = pOptions ? pOptions->GetPattern(pId) : NULL;
+ void *pPattern = pOptions ? pOptions->GetPattern(pFace, aId.mbEmbolden) : NULL;
if (pPattern)
font_face = rCairo.ft_font_face_create_for_pattern(pPattern);
if (!font_face)
- font_face = rCairo.ft_font_face_create_for_ft_face(pId, rFont.GetLoadFlags());
- m_aCairoFontsCache.CacheFont(font_face, pId);
+ font_face = rCairo.ft_font_face_create_for_ft_face(pFace, rFont.GetLoadFlags());
+ m_aCairoFontsCache.CacheFont(font_face, aId);
}
rCairo.set_font_face(cr, font_face);
More information about the Libreoffice-commits
mailing list