summaryrefslogtreecommitdiffstats
path: root/content/common/mac
diff options
context:
space:
mode:
Diffstat (limited to 'content/common/mac')
-rw-r--r--content/common/mac/font_loader.h31
-rw-r--r--content/common/mac/font_loader.mm49
2 files changed, 44 insertions, 36 deletions
diff --git a/content/common/mac/font_loader.h b/content/common/mac/font_loader.h
index 0b64417..f2ed4c6 100644
--- a/content/common/mac/font_loader.h
+++ b/content/common/mac/font_loader.h
@@ -17,6 +17,8 @@
class NSFont;
#endif
+struct FontDescriptor;
+
// Provides functionality to transmit fonts over IPC.
//
// Note about font formats: .dfont (datafork suitcase) fonts are currently not
@@ -25,20 +27,27 @@ class NSFont;
class FontLoader {
public:
- // Load a font specified by |font_to_encode| into a shared memory buffer
- // suitable for sending over IPC.
+ // This structure holds the result of LoadFont(). This structure is passed to
+ // LoadFont(), which should run on the file thread, then it is passed to a
+ // task which sends the result to the originating renderer.
+ struct Result {
+ uint32 font_data_size;
+ base::SharedMemory font_data;
+ uint32 font_id;
+ };
+ // Load a font specified by |font| into a shared memory buffer suitable for
+ // sending over IPC.
//
// On return:
- // returns true on success, false on failure.
- // |font_data| - shared memory buffer containing the raw data for the font
- // file.
- // |font_data_size| - size of data contained in |font_data|.
- // |font_id| - unique identifier for the on-disk file we load for the font.
+ // |result->font_data| - shared memory buffer containing the raw data for
+ // the font file. The buffer is only valid when both |result->font_data_size|
+ // and |result->font_id| are not zero.
+ // |result->font_data_size| - size of data contained in |result->font_data|.
+ // This value is zero on failure.
+ // |result->font_id| - unique identifier for the on-disk file we load for
+ // the font. This value is zero on failure.
CONTENT_EXPORT
- static bool LoadFontIntoBuffer(NSFont* font_to_encode,
- base::SharedMemory* font_data,
- uint32* font_data_size,
- uint32* font_id);
+ static void LoadFont(const FontDescriptor& font, FontLoader::Result* result);
// Given a shared memory buffer containing the raw data for a font file, load
// the font and return a CGFontRef.
diff --git a/content/common/mac/font_loader.mm b/content/common/mac/font_loader.mm
index a6bf6f0..1a0552b 100644
--- a/content/common/mac/font_loader.mm
+++ b/content/common/mac/font_loader.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -14,6 +14,8 @@
#include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/sys_string_conversions.h"
+#include "base/threading/thread_restrictions.h"
+#include "content/common/mac/font_descriptor.h"
extern "C" {
@@ -52,23 +54,21 @@ void _CTFontManagerUnregisterFontForData(NSUInteger, int) {
} // extern "C"
// static
-bool FontLoader::LoadFontIntoBuffer(NSFont* font_to_encode,
- base::SharedMemory* font_data,
- uint32* font_data_size,
- uint32* font_id) {
- DCHECK(font_data);
- DCHECK(font_data_size);
- DCHECK(font_id);
- *font_data_size = 0;
- *font_id = 0;
-
+void FontLoader::LoadFont(const FontDescriptor& font,
+ FontLoader::Result* result) {
+ base::ThreadRestrictions::AssertIOAllowed();
+ DCHECK(result);
+ result->font_data_size = 0;
+ result->font_id = 0;
+
+ NSFont* font_to_encode = font.ToNSFont();
// Used only for logging.
std::string font_name([[font_to_encode fontName] UTF8String]);
// Load appropriate NSFont.
if (!font_to_encode) {
DLOG(ERROR) << "Failed to load font " << font_name;
- return false;
+ return;
}
// NSFont -> ATSFontRef.
@@ -76,18 +76,18 @@ bool FontLoader::LoadFontIntoBuffer(NSFont* font_to_encode,
CTFontGetPlatformFont(reinterpret_cast<CTFontRef>(font_to_encode), NULL);
if (!ats_font) {
DLOG(ERROR) << "Conversion to ATSFontRef failed for " << font_name;
- return false;
+ return;
}
// Retrieve the ATSFontContainerRef corresponding to the font file we want to
// load. This is a unique identifier that allows the caller determine if the
// font file in question is already loaded.
- COMPILE_ASSERT(sizeof(ATSFontContainerRef) == sizeof(font_id),
+ COMPILE_ASSERT(sizeof(ATSFontContainerRef) == sizeof(&result->font_id),
uint32_cant_hold_fontcontainer_ref);
ATSFontContainerRef fontContainer = kATSFontContainerRefUnspecified;
if (ATSFontGetContainer(ats_font, 0, &fontContainer) != noErr) {
DLOG(ERROR) << "Failed to get font container ref for " << font_name;
- return false;
+ return;
}
// ATSFontRef -> File path.
@@ -101,7 +101,7 @@ bool FontLoader::LoadFontIntoBuffer(NSFont* font_to_encode,
FSRef font_fsref;
if (ATSFontGetFileReference(ats_font, &font_fsref) != noErr) {
DLOG(ERROR) << "Failed to find font file for " << font_name;
- return false;
+ return;
}
FilePath font_path = FilePath(base::mac::PathFromFSRef(font_fsref));
@@ -109,31 +109,30 @@ bool FontLoader::LoadFontIntoBuffer(NSFont* font_to_encode,
int64 font_file_size_64 = -1;
if (!file_util::GetFileSize(font_path, &font_file_size_64)) {
DLOG(ERROR) << "Couldn't get font file size for " << font_path.value();
- return false;
+ return;
}
if (font_file_size_64 <= 0 || font_file_size_64 >= kint32max) {
DLOG(ERROR) << "Bad size for font file " << font_path.value();
- return false;
+ return;
}
int32 font_file_size_32 = static_cast<int32>(font_file_size_64);
- if (!font_data->CreateAndMapAnonymous(font_file_size_32)) {
+ if (!result->font_data.CreateAndMapAnonymous(font_file_size_32)) {
DLOG(ERROR) << "Failed to create shmem area for " << font_name;
- return false;
+ return;
}
int32 amt_read = file_util::ReadFile(font_path,
- reinterpret_cast<char*>(font_data->memory()),
+ reinterpret_cast<char*>(result->font_data.memory()),
font_file_size_32);
if (amt_read != font_file_size_32) {
DLOG(ERROR) << "Failed to read font data for " << font_path.value();
- return false;
+ return;
}
- *font_data_size = font_file_size_32;
- *font_id = fontContainer;
- return true;
+ result->font_data_size = font_file_size_32;
+ result->font_id = fontContainer;
}
// static