use SkFontDescriptor on mac
Review URL: https://codereview.appspot.com/6247064 git-svn-id: http://skia.googlecode.com/svn/trunk@4117 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
5440f06331
commit
99840553cd
@ -21,6 +21,7 @@
|
|||||||
#include "SkCGUtils.h"
|
#include "SkCGUtils.h"
|
||||||
#include "SkDescriptor.h"
|
#include "SkDescriptor.h"
|
||||||
#include "SkEndian.h"
|
#include "SkEndian.h"
|
||||||
|
#include "SkFontDescriptor.h"
|
||||||
#include "SkFloatingPoint.h"
|
#include "SkFloatingPoint.h"
|
||||||
#include "SkPaint.h"
|
#include "SkPaint.h"
|
||||||
#include "SkString.h"
|
#include "SkString.h"
|
||||||
@ -378,6 +379,11 @@ public:
|
|||||||
CTFontRef fFontRef;
|
CTFontRef fFontRef;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static CTFontRef typeface_to_fontref(const SkTypeface* face) {
|
||||||
|
const SkTypeface_Mac* macface = reinterpret_cast<const SkTypeface_Mac*>(face);
|
||||||
|
return macface->fFontRef;
|
||||||
|
}
|
||||||
|
|
||||||
static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[]) {
|
static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[]) {
|
||||||
SkASSERT(fontRef);
|
SkASSERT(fontRef);
|
||||||
bool isMonospace;
|
bool isMonospace;
|
||||||
@ -1835,18 +1841,30 @@ size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
|
|||||||
|
|
||||||
#include "SkStream.h"
|
#include "SkStream.h"
|
||||||
|
|
||||||
|
// we take ownership of the ref
|
||||||
|
static const char* get_str(CFStringRef ref, SkString* str) {
|
||||||
|
CFStringToSkString(ref, str);
|
||||||
|
CFSafeRelease(ref);
|
||||||
|
return str->c_str();
|
||||||
|
}
|
||||||
|
|
||||||
void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) {
|
void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) {
|
||||||
// hack: need a real name or something from CG
|
CTFontRef ctFont = typeface_to_fontref(face);
|
||||||
uint32_t fontID = face->uniqueID();
|
SkFontDescriptor desc(face->style());
|
||||||
stream->write(&fontID, 4);
|
SkString tmpStr;
|
||||||
|
|
||||||
|
desc.setFamilyName(get_str(CTFontCopyFamilyName(ctFont), &tmpStr));
|
||||||
|
desc.setFullName(get_str(CTFontCopyFullName(ctFont), &tmpStr));
|
||||||
|
desc.setPostscriptName(get_str(CTFontCopyPostScriptName(ctFont), &tmpStr));
|
||||||
|
|
||||||
|
desc.serialize(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
|
SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
|
||||||
// hack: need a real name or something from CG
|
SkFontDescriptor desc(stream);
|
||||||
SkFontID fontID = stream->readU32();
|
|
||||||
SkTypeface* face = SkTypefaceCache::FindByID(fontID);
|
return SkFontHost::CreateTypeface(NULL, desc.getFamilyName(),
|
||||||
SkSafeRef(face);
|
desc.getStyle());
|
||||||
return face;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user