summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorKhaled Hosny <khaledhosny@eglug.org>2013-06-30 14:40:37 +0200
committerDavid Tardon <dtardon@redhat.com>2013-07-02 07:51:59 +0000
commit87daa3c948eaa928591d95c9528922471fde57c1 (patch)
treeac9669d1f8c3d5e4ee3e088997b57c2de5ebeb06 /vcl
parentdba2eef1b364c11a52d4bcec6c60e4c21ab26854 (diff)
Handle synthetic bold italic with Core Text
Core Text does not fake missing italic and bold (unlike ATSUI), so we have to do it on our own. Change-Id: Ia5977d53739b7a6eaaccbf3aeb24adb820ca05c6 Reviewed-on: https://gerrit.libreoffice.org/4658 Reviewed-by: David Tardon <dtardon@redhat.com> Tested-by: David Tardon <dtardon@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/coretext/ctfonts.cxx32
1 files changed, 26 insertions, 6 deletions
diff --git a/vcl/coretext/ctfonts.cxx b/vcl/coretext/ctfonts.cxx
index 5d8c0e74713e..a0cc98a7cd28 100644
--- a/vcl/coretext/ctfonts.cxx
+++ b/vcl/coretext/ctfonts.cxx
@@ -58,6 +58,11 @@ private:
// =======================================================================
+inline double toRadian(int nDegree)
+{
+ return nDegree * (M_PI / 1800.0);
+}
+
CTTextStyle::CTTextStyle( const FontSelectPattern& rFSD )
: ImplMacTextStyle( rFSD )
, mpStyleDict( NULL )
@@ -68,16 +73,16 @@ CTTextStyle::CTTextStyle( const FontSelectPattern& rFSD )
double fScaledFontHeight = pReqFont->mfExactHeight;
// convert font rotation to radian
- mfFontRotation = pReqFont->mnOrientation * (M_PI / 1800.0);
+ mfFontRotation = toRadian(pReqFont->mnOrientation);
+
+ // dummy matrix so we can use CGAffineTransformConcat() below
+ CGAffineTransform aMatrix = CGAffineTransformMakeTranslation(0, 0);
// handle font stretching if any
- const CGAffineTransform* pMatrix = NULL;
- CGAffineTransform aMatrix;
if( (pReqFont->mnWidth != 0) && (pReqFont->mnWidth != pReqFont->mnHeight) )
{
mfFontStretch = (float)pReqFont->mnWidth / pReqFont->mnHeight;
- aMatrix = CGAffineTransformMakeScale( mfFontStretch, 1.0F );
- pMatrix = &aMatrix;
+ aMatrix = CGAffineTransformConcat(aMatrix, CGAffineTransformMakeScale(mfFontStretch, 1.0F));
}
// create the style object for CoreText font attributes
@@ -88,8 +93,23 @@ CTTextStyle::CTTextStyle( const FontSelectPattern& rFSD )
CFBooleanRef pCFVertBool = pReqFont->mbVertical ? kCFBooleanTrue : kCFBooleanFalse;
CFDictionarySetValue( mpStyleDict, kCTVerticalFormsAttributeName, pCFVertBool );
+ // fake bold
+ if ((pReqFont->GetWeight() >= WEIGHT_BOLD) && (mpFontData->GetWeight() < WEIGHT_SEMIBOLD))
+ {
+ int nStroke = -10.0;
+ CFNumberRef rStroke = CFNumberCreate(NULL, kCFNumberSInt32Type, &nStroke);
+ CFDictionarySetValue(mpStyleDict, kCTStrokeWidthAttributeName, rStroke);
+ }
+
+ // fake italic
+ if (((pReqFont->GetSlant() == ITALIC_NORMAL) || (pReqFont->GetSlant() == ITALIC_OBLIQUE))
+ && !((mpFontData->GetSlant() == ITALIC_NORMAL) || (mpFontData->GetSlant() == ITALIC_OBLIQUE)))
+ {
+ aMatrix = CGAffineTransformConcat(aMatrix, CGAffineTransformMake(1, 0, toRadian(120), 1, 0, 0));
+ }
+
CTFontDescriptorRef pFontDesc = (CTFontDescriptorRef)mpFontData->GetFontId();
- CTFontRef pNewCTFont = CTFontCreateWithFontDescriptor( pFontDesc, fScaledFontHeight, pMatrix );
+ CTFontRef pNewCTFont = CTFontCreateWithFontDescriptor( pFontDesc, fScaledFontHeight, &aMatrix );
CFDictionarySetValue( mpStyleDict, kCTFontAttributeName, pNewCTFont );
CFRelease( pNewCTFont);