diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2013-07-01 15:47:43 +0200 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2013-07-01 15:49:46 +0200 |
commit | 8a2719b8fc65ab2f875f4d617c2202e573b7bc77 (patch) | |
tree | aabcc94d8bcf9de0e7ad66d09ae234855cd71e0e | |
parent | 4dda042c354b4cfaf190bca35092bbd5f6dc2a1f (diff) |
Handle synthetic bold with Core Text
And fix the previous commit for synthetic italic a bit.
Change-Id: Ia5977d53739b7a6eaaccbf3aeb24adb820ca05c6
-rw-r--r-- | vcl/coretext/ctfonts.cxx | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/vcl/coretext/ctfonts.cxx b/vcl/coretext/ctfonts.cxx index f5e1a985212d..d46d19d31028 100644 --- a/vcl/coretext/ctfonts.cxx +++ b/vcl/coretext/ctfonts.cxx @@ -59,6 +59,11 @@ private: // ======================================================================= +inline double toRadian(int nDegree) +{ + return nDegree * (M_PI / 1800.0); +} + CTTextStyle::CTTextStyle( const FontSelectPattern& rFSD ) : ImplMacTextStyle( rFSD ) , mpStyleDict( NULL ) @@ -69,24 +74,18 @@ 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 - CGAffineTransform aMatrix = CGAffineTransformMakeScale(1.0, 1.0); if( (pReqFont->mnWidth != 0) && (pReqFont->mnWidth != pReqFont->mnHeight) ) { mfFontStretch = (float)pReqFont->mnWidth / pReqFont->mnHeight; aMatrix = CGAffineTransformConcat(aMatrix, CGAffineTransformMakeScale(mfFontStretch, 1.0F)); } - // fake bold - if ((pReqFont->GetWeight() >= WEIGHT_BOLD) && (mpFontData->GetWeight() < WEIGHT_SEMIBOLD)) - /* XXX */; - // 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, tanf(14 * acosf(0) / 90), 1, 0, 0)); - // create the style object for CoreText font attributes static const CFIndex nMaxDictSize = 16; // TODO: does this really suffice? mpStyleDict = CFDictionaryCreateMutable( NULL, nMaxDictSize, @@ -95,6 +94,21 @@ 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, &aMatrix ); CFDictionarySetValue( mpStyleDict, kCTFontAttributeName, pNewCTFont ); |