[Libreoffice-commits] core.git: vcl/coretext

Khaled Hosny khaledhosny at eglug.org
Mon Jul 1 06:50:46 PDT 2013


 vcl/coretext/ctfonts.cxx |   34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

New commits:
commit 8a2719b8fc65ab2f875f4d617c2202e573b7bc77
Author: Khaled Hosny <khaledhosny at eglug.org>
Date:   Mon Jul 1 15:47:43 2013 +0200

    Handle synthetic bold with Core Text
    
    And fix the previous commit for synthetic italic a bit.
    
    Change-Id: Ia5977d53739b7a6eaaccbf3aeb24adb820ca05c6

diff --git a/vcl/coretext/ctfonts.cxx b/vcl/coretext/ctfonts.cxx
index f5e1a98..d46d19d 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 );


More information about the Libreoffice-commits mailing list