aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-01 16:19:32 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-01 16:19:32 +0000
commit99840553cda3184ec2e32fbb192d104741ceea86 (patch)
tree45a632f9db11055f7587a18d2dec60bda9f85f42 /src/ports
parent5440f06331b46d3f132a7247a4e414d9d4bc66e7 (diff)
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
Diffstat (limited to 'src/ports')
-rw-r--r--src/ports/SkFontHost_mac_coretext.cpp34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/ports/SkFontHost_mac_coretext.cpp b/src/ports/SkFontHost_mac_coretext.cpp
index c43d1a654b..f49185fb34 100644
--- a/src/ports/SkFontHost_mac_coretext.cpp
+++ b/src/ports/SkFontHost_mac_coretext.cpp
@@ -21,6 +21,7 @@
#include "SkCGUtils.h"
#include "SkDescriptor.h"
#include "SkEndian.h"
+#include "SkFontDescriptor.h"
#include "SkFloatingPoint.h"
#include "SkPaint.h"
#include "SkString.h"
@@ -378,6 +379,11 @@ public:
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[]) {
SkASSERT(fontRef);
bool isMonospace;
@@ -1835,18 +1841,30 @@ size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
#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) {
- // hack: need a real name or something from CG
- uint32_t fontID = face->uniqueID();
- stream->write(&fontID, 4);
+ CTFontRef ctFont = typeface_to_fontref(face);
+ SkFontDescriptor desc(face->style());
+ 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) {
- // hack: need a real name or something from CG
- SkFontID fontID = stream->readU32();
- SkTypeface* face = SkTypefaceCache::FindByID(fontID);
- SkSafeRef(face);
- return face;
+ SkFontDescriptor desc(stream);
+
+ return SkFontHost::CreateTypeface(NULL, desc.getFamilyName(),
+ desc.getStyle());
}
///////////////////////////////////////////////////////////////////////////////