Kaydet (Commit) 8a2719b8 authored tarafından Khaled Hosny's avatar Khaled Hosny

Handle synthetic bold with Core Text

And fix the previous commit for synthetic italic a bit.

Change-Id: Ia5977d53739b7a6eaaccbf3aeb24adb820ca05c6
üst 4dda042c
......@@ -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 );
......
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