summaryrefslogtreecommitdiffstats
path: root/content/common/font_loader_mac.mm
diff options
context:
space:
mode:
Diffstat (limited to 'content/common/font_loader_mac.mm')
-rw-r--r--content/common/font_loader_mac.mm32
1 files changed, 32 insertions, 0 deletions
diff --git a/content/common/font_loader_mac.mm b/content/common/font_loader_mac.mm
index b2ff8f4..867e1d3 100644
--- a/content/common/font_loader_mac.mm
+++ b/content/common/font_loader_mac.mm
@@ -10,7 +10,9 @@
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
+#include "base/mac/foundation_util.h"
#include "base/mac/mac_util.h"
+#include "base/mac/scoped_cftyperef.h"
#include "base/sys_string_conversions.h"
extern "C" {
@@ -135,6 +137,36 @@ bool FontLoader::LoadFontIntoBuffer(NSFont* font_to_encode,
}
// static
+bool FontLoader::CGFontRefFromBuffer(base::SharedMemoryHandle font_data,
+ uint32 font_data_size,
+ CGFontRef* out) {
+ *out = NULL;
+
+ using base::SharedMemory;
+ DCHECK(SharedMemory::IsHandleValid(font_data));
+ DCHECK_GT(font_data_size, 0U);
+
+ SharedMemory shm(font_data, /*read_only=*/true);
+ if (!shm.Map(font_data_size))
+ return false;
+
+ NSData* data = [NSData dataWithBytes:shm.memory()
+ length:font_data_size];
+ base::mac::ScopedCFTypeRef<CGDataProviderRef> provider(
+ CGDataProviderCreateWithCFData(base::mac::NSToCFCast(data)));
+ if (!provider)
+ return false;
+
+ *out = CGFontCreateWithDataProvider(provider.get());
+
+ if (*out == NULL)
+ return false;
+
+ return true;
+}
+
+// TODO(jeremy): Remove once http://webk.it/66935 lands.
+// static
bool FontLoader::ATSFontContainerFromBuffer(base::SharedMemoryHandle font_data,
uint32 font_data_size,
ATSFontContainerRef* font_container)