store real fontstyle on mac fonts
git-svn-id: http://skia.googlecode.com/svn/trunk@8399 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
919e9c3477
commit
ce8b3de605
@ -40,6 +40,7 @@
|
|||||||
#include "SkTypeface_mac.h"
|
#include "SkTypeface_mac.h"
|
||||||
#include "SkUtils.h"
|
#include "SkUtils.h"
|
||||||
#include "SkTypefaceCache.h"
|
#include "SkTypefaceCache.h"
|
||||||
|
#include "SkFontMgr.h"
|
||||||
|
|
||||||
class SkScalerContext_Mac;
|
class SkScalerContext_Mac;
|
||||||
|
|
||||||
@ -394,6 +395,29 @@ static SkFontID CTFontRef_to_SkFontID(CTFontRef fontRef) {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SkFontStyle stylebits2fontstyle(SkTypeface::Style styleBits) {
|
||||||
|
return SkFontStyle((styleBits & SkTypeface::kBold)
|
||||||
|
? SkFontStyle::kBold_Weight
|
||||||
|
: SkFontStyle::kNormal_Weight,
|
||||||
|
SkFontStyle::kNormal_Width,
|
||||||
|
(styleBits & SkTypeface::kItalic)
|
||||||
|
? SkFontStyle::kItalic_Slant
|
||||||
|
: SkFontStyle::kUpright_Slant);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define WEIGHT_THRESHOLD ((SkFontStyle::kNormal_Weight + SkFontStyle::kBold_Weight)/2)
|
||||||
|
|
||||||
|
static SkTypeface::Style fontstyle2stylebits(const SkFontStyle& fs) {
|
||||||
|
unsigned style = 0;
|
||||||
|
if (fs.width() >= WEIGHT_THRESHOLD) {
|
||||||
|
style |= SkTypeface::kBold;
|
||||||
|
}
|
||||||
|
if (fs.isItalic()) {
|
||||||
|
style |= SkTypeface::kItalic;
|
||||||
|
}
|
||||||
|
return (SkTypeface::Style)style;
|
||||||
|
}
|
||||||
|
|
||||||
class SkTypeface_Mac : public SkTypeface {
|
class SkTypeface_Mac : public SkTypeface {
|
||||||
public:
|
public:
|
||||||
SkTypeface_Mac(SkTypeface::Style style, SkFontID fontID, bool isFixedPitch,
|
SkTypeface_Mac(SkTypeface::Style style, SkFontID fontID, bool isFixedPitch,
|
||||||
@ -401,12 +425,24 @@ public:
|
|||||||
: SkTypeface(style, fontID, isFixedPitch)
|
: SkTypeface(style, fontID, isFixedPitch)
|
||||||
, fName(name)
|
, fName(name)
|
||||||
, fFontRef(fontRef) // caller has already called CFRetain for us
|
, fFontRef(fontRef) // caller has already called CFRetain for us
|
||||||
|
, fFontStyle(stylebits2fontstyle(style))
|
||||||
|
{
|
||||||
|
SkASSERT(fontRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
SkTypeface_Mac(const SkFontStyle& fs, SkFontID fontID, bool isFixedPitch,
|
||||||
|
CTFontRef fontRef, const char name[])
|
||||||
|
: SkTypeface(fontstyle2stylebits(fs), fontID, isFixedPitch)
|
||||||
|
, fName(name)
|
||||||
|
, fFontRef(fontRef) // caller has already called CFRetain for us
|
||||||
|
, fFontStyle(fs)
|
||||||
{
|
{
|
||||||
SkASSERT(fontRef);
|
SkASSERT(fontRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkString fName;
|
SkString fName;
|
||||||
AutoCFRelease<CTFontRef> fFontRef;
|
AutoCFRelease<CTFontRef> fFontRef;
|
||||||
|
SkFontStyle fFontStyle;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class SkFontHost; // to access our protected members for deprecated methods
|
friend class SkFontHost; // to access our protected members for deprecated methods
|
||||||
@ -424,6 +460,7 @@ protected:
|
|||||||
const uint32_t*, uint32_t) const SK_OVERRIDE;
|
const uint32_t*, uint32_t) const SK_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
typedef SkTypeface INHERITED;
|
typedef SkTypeface INHERITED;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1841,16 +1878,6 @@ static bool find_dict_float(CFDictionaryRef dict, CFStringRef name, float* value
|
|||||||
&& CFNumberGetValue(num, kCFNumberFloatType, value);
|
&& CFNumberGetValue(num, kCFNumberFloatType, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkTypeface* createFromDesc(CFStringRef cfFamilyName,
|
|
||||||
CTFontDescriptorRef desc) {
|
|
||||||
AutoCFRelease<CTFontRef> ctNamed(CTFontCreateWithName(cfFamilyName, 1, NULL));
|
|
||||||
CTFontRef ctFont = CTFontCreateCopyWithAttributes(ctNamed, 1, NULL, desc);
|
|
||||||
|
|
||||||
SkString str;
|
|
||||||
CFStringToSkString(cfFamilyName, &str);
|
|
||||||
return ctFont ? NewFromFontRef(ctFont, str.c_str()) : NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "SkFontMgr.h"
|
#include "SkFontMgr.h"
|
||||||
|
|
||||||
static int unit_weight_to_fontstyle(float unit) {
|
static int unit_weight_to_fontstyle(float unit) {
|
||||||
@ -1898,6 +1925,25 @@ static SkFontStyle desc2fontstyle(CTFontDescriptorRef desc) {
|
|||||||
: SkFontStyle::kUpright_Slant);
|
: SkFontStyle::kUpright_Slant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SkTypeface* createFromDesc(CFStringRef cfFamilyName,
|
||||||
|
CTFontDescriptorRef desc) {
|
||||||
|
AutoCFRelease<CTFontRef> ctNamed(CTFontCreateWithName(cfFamilyName, 1, NULL));
|
||||||
|
CTFontRef ctFont = CTFontCreateCopyWithAttributes(ctNamed, 1, NULL, desc);
|
||||||
|
if (NULL == ctFont) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SkString str;
|
||||||
|
CFStringToSkString(cfFamilyName, &str);
|
||||||
|
|
||||||
|
bool isFixedPitch;
|
||||||
|
(void)computeStyleBits(ctFont, &isFixedPitch);
|
||||||
|
SkFontID fontID = CTFontRef_to_SkFontID(ctFont);
|
||||||
|
|
||||||
|
return new SkTypeface_Mac(desc2fontstyle(desc), fontID, isFixedPitch,
|
||||||
|
ctFont, str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
class SkFontStyleSet_Mac : public SkFontStyleSet {
|
class SkFontStyleSet_Mac : public SkFontStyleSet {
|
||||||
public:
|
public:
|
||||||
SkFontStyleSet_Mac(CFStringRef familyName, CTFontDescriptorRef desc)
|
SkFontStyleSet_Mac(CFStringRef familyName, CTFontDescriptorRef desc)
|
||||||
@ -1932,6 +1978,7 @@ public:
|
|||||||
virtual SkTypeface* createTypeface(int index) SK_OVERRIDE {
|
virtual SkTypeface* createTypeface(int index) SK_OVERRIDE {
|
||||||
SkASSERT((unsigned)index < (unsigned)CFArrayGetCount(fArray));
|
SkASSERT((unsigned)index < (unsigned)CFArrayGetCount(fArray));
|
||||||
CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fArray, index);
|
CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fArray, index);
|
||||||
|
|
||||||
return createFromDesc(fFamilyName, desc);
|
return createFromDesc(fFamilyName, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user