Chromium Code Reviews| Index: content/browser/renderer_host/pepper/pepper_truetype_font_mac.mm |
| diff --git a/content/renderer/pepper/pepper_truetype_font_mac.mm b/content/browser/renderer_host/pepper/pepper_truetype_font_mac.mm |
| similarity index 89% |
| rename from content/renderer/pepper/pepper_truetype_font_mac.mm |
| rename to content/browser/renderer_host/pepper/pepper_truetype_font_mac.mm |
| index 19e74749506d440c7aa85a7b7f4428d7c4527f5d..38aa5c94a9adf57fdd8485b870b2d8b2c5b985fd 100644 |
| --- a/content/renderer/pepper/pepper_truetype_font_mac.mm |
| +++ b/content/browser/renderer_host/pepper/pepper_truetype_font_mac.mm |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "content/renderer/pepper/pepper_truetype_font.h" |
| +#include "content/browser/renderer_host/pepper/pepper_truetype_font.h" |
| #import <ApplicationServices/ApplicationServices.h> |
| @@ -24,11 +24,10 @@ namespace { |
| static bool FindFloat(CFDictionaryRef dict, CFStringRef name, float* value) { |
| CFNumberRef num; |
| - return |
| - CFDictionaryGetValueIfPresent(dict, name, |
| - reinterpret_cast<const void**>(&num)) && |
| - CFNumberIsFloatType(num) && |
| - CFNumberGetValue(num, kCFNumberFloatType, value); |
| + return CFDictionaryGetValueIfPresent( |
| + dict, name, reinterpret_cast<const void**>(&num)) && |
| + CFNumberIsFloatType(num) && |
| + CFNumberGetValue(num, kCFNumberFloatType, value); |
| } |
| float GetMacWeight(PP_TrueTypeFontWeight_Dev weight) { |
| @@ -58,7 +57,7 @@ PP_TrueTypeFontWidth_Dev GetPepperWidth(float width) { |
| // Perform the inverse mapping of GetMacWeight. |
| return static_cast<PP_TrueTypeFontWidth_Dev>( |
| width * |
| - (PP_TRUETYPEFONTWIDTH_ULTRAEXPANDED - PP_TRUETYPEFONTWIDTH_NORMAL) + |
| + (PP_TRUETYPEFONTWIDTH_ULTRAEXPANDED - PP_TRUETYPEFONTWIDTH_NORMAL) + |
| PP_TRUETYPEFONTWIDTH_NORMAL); |
| } |
| @@ -98,21 +97,23 @@ class PepperTrueTypeFontMac : public PepperTrueTypeFont { |
| public: |
| explicit PepperTrueTypeFontMac( |
| const ppapi::proxy::SerializedTrueTypeFontDesc& desc); |
| - virtual ~PepperTrueTypeFontMac() OVERRIDE; |
| // PepperTrueTypeFont overrides. |
| - virtual bool IsValid() OVERRIDE; |
| + virtual bool IsValid() const OVERRIDE; |
| virtual int32_t Describe( |
| - ppapi::proxy::SerializedTrueTypeFontDesc* desc) OVERRIDE; |
| - virtual int32_t GetTableTags(std::vector<uint32_t>* tags) OVERRIDE; |
| + ppapi::proxy::SerializedTrueTypeFontDesc* desc) const OVERRIDE; |
| + virtual int32_t GetTableTags(std::vector<uint32_t>* tags) const OVERRIDE; |
| virtual int32_t GetTable(uint32_t table_tag, |
| int32_t offset, |
| int32_t max_data_length, |
| - std::string* data) OVERRIDE; |
| + std::string* data) const OVERRIDE; |
| + |
| private: |
| + virtual ~PepperTrueTypeFontMac() OVERRIDE; |
| + |
| virtual int32_t GetEntireFont(int32_t offset, |
| int32_t max_data_length, |
| - std::string* data); |
| + std::string* data) const; |
| base::ScopedCFTypeRef<CTFontRef> font_ref_; |
| @@ -212,12 +213,12 @@ PepperTrueTypeFontMac::PepperTrueTypeFontMac( |
| PepperTrueTypeFontMac::~PepperTrueTypeFontMac() { |
| } |
| -bool PepperTrueTypeFontMac::IsValid() { |
| +bool PepperTrueTypeFontMac::IsValid() const { |
| return font_ref_.get() != NULL; |
| } |
| int32_t PepperTrueTypeFontMac::Describe( |
| - ppapi::proxy::SerializedTrueTypeFontDesc* desc) { |
| + ppapi::proxy::SerializedTrueTypeFontDesc* desc) const { |
| if (!IsValid()) |
| return PP_ERROR_FAILED; |
| @@ -237,7 +238,7 @@ int32_t PepperTrueTypeFontMac::Describe( |
| CTFontSymbolicTraits symbolic_traits(CTFontGetSymbolicTraits(font_ref_)); |
| if (symbolic_traits & kCTFontItalicTrait) |
| desc->style = static_cast<PP_TrueTypeFontStyle_Dev>( |
| - desc->style | PP_TRUETYPEFONTSTYLE_ITALIC); |
| + desc->style | PP_TRUETYPEFONTSTYLE_ITALIC); |
| if (symbolic_traits & kCTFontBoldTrait) { |
| desc->weight = PP_TRUETYPEFONTWEIGHT_BOLD; |
| } else { |
| @@ -260,7 +261,7 @@ int32_t PepperTrueTypeFontMac::Describe( |
| return PP_OK; |
| } |
| -int32_t PepperTrueTypeFontMac::GetTableTags(std::vector<uint32_t>* tags) { |
| +int32_t PepperTrueTypeFontMac::GetTableTags(std::vector<uint32_t>* tags) const { |
| base::ScopedCFTypeRef<CFArrayRef> tag_array( |
| CTFontCopyAvailableTables(font_ref_, kCTFontTableOptionNoOptions)); |
| if (!tag_array) |
| @@ -280,7 +281,7 @@ int32_t PepperTrueTypeFontMac::GetTableTags(std::vector<uint32_t>* tags) { |
| int32_t PepperTrueTypeFontMac::GetTable(uint32_t table_tag, |
| int32_t offset, |
| int32_t max_data_length, |
| - std::string* data) { |
| + std::string* data) const { |
| if (!table_tag) |
| return GetEntireFont(offset, max_data_length, data); |
| @@ -294,11 +295,11 @@ int32_t PepperTrueTypeFontMac::GetTable(uint32_t table_tag, |
| CFIndex table_size = CFDataGetLength(table_ref); |
| CFIndex safe_offset = |
| std::min(base::checked_cast<CFIndex>(offset), table_size); |
| - CFIndex safe_length = |
| - std::min(table_size - safe_offset, |
| - base::checked_cast<CFIndex>(max_data_length)); |
| + CFIndex safe_length = std::min(table_size - safe_offset, |
| + base::checked_cast<CFIndex>(max_data_length)); |
| data->resize(safe_length); |
| - CFDataGetBytes(table_ref, CFRangeMake(safe_offset, safe_length), |
| + CFDataGetBytes(table_ref, |
| + CFRangeMake(safe_offset, safe_length), |
| reinterpret_cast<UInt8*>(&(*data)[0])); |
| return safe_length; |
| @@ -306,7 +307,7 @@ int32_t PepperTrueTypeFontMac::GetTable(uint32_t table_tag, |
| int32_t PepperTrueTypeFontMac::GetEntireFont(int32_t offset, |
| int32_t max_data_length, |
| - std::string* data) { |
| + std::string* data) const { |
| // Reconstruct the font header, table directory, and tables. |
| std::vector<uint32_t> table_tags; |
| int32_t table_count = GetTableTags(&table_tags); |
| @@ -314,8 +315,8 @@ int32_t PepperTrueTypeFontMac::GetEntireFont(int32_t offset, |
| return table_count; // PPAPI error code. |
| // Allocate enough room for the header and the table directory entries. |
| - std::string font(sizeof(FontHeader) + |
| - sizeof(FontDirectoryEntry) * table_count, 0); |
| + std::string font( |
| + sizeof(FontHeader) + sizeof(FontDirectoryEntry) * table_count, 0); |
| // Map the OS X font type value to a TrueType scalar type. |
| base::ScopedCFTypeRef<CFNumberRef> font_type_ref( |
| base::mac::CFCast<CFNumberRef>( |
| @@ -344,7 +345,7 @@ int32_t PepperTrueTypeFontMac::GetEntireFont(int32_t offset, |
| uint16_t num_tables = base::checked_cast<uint16_t>(table_count); |
| uint16_t entry_selector = 0; |
| uint16_t search_range = 1; |
| - while (search_range < num_tables >> 1) { |
| + while (search_range<num_tables>> 1) { |
|
piman
2014/06/19 20:03:42
nit: definitely more readable before.
bbudge
2014/06/21 14:12:50
clang format doesn't quite know what to do in here
piman
2014/06/23 18:21:12
worth filing a bug :)
|
| entry_selector++; |
| search_range <<= 1; |
| } |
| @@ -362,9 +363,8 @@ int32_t PepperTrueTypeFontMac::GetEntireFont(int32_t offset, |
| for (int32_t i = 0; i < table_count; i++) { |
| // Get the table data. |
| std::string table; |
| - int32_t table_size = GetTable(table_tags[i], |
| - 0, std::numeric_limits<int32_t>::max(), |
| - &table); |
| + int32_t table_size = |
| + GetTable(table_tags[i], 0, std::numeric_limits<int32_t>::max(), &table); |
| if (table_size < 0) |
| return table_size; // PPAPI error code. |
| @@ -378,8 +378,8 @@ int32_t PepperTrueTypeFontMac::GetEntireFont(int32_t offset, |
| FontDirectoryEntry* entry = reinterpret_cast<FontDirectoryEntry*>( |
| &font[0] + sizeof(FontHeader) + i * sizeof(FontDirectoryEntry)); |
| entry->tag = base::HostToNet32(table_tags[i]); |
| - entry->checksum = base::HostToNet32( |
| - CalculateChecksum(&font[table_offset], table_size)); |
| + entry->checksum = |
| + base::HostToNet32(CalculateChecksum(&font[table_offset], table_size)); |
| entry->offset = base::HostToNet32(table_offset); |
| entry->logical_length = base::HostToNet32(table_size); |
| // TODO(bbudge) set the 'head' table checksumAdjustment. |
| @@ -400,9 +400,12 @@ int32_t PepperTrueTypeFontMac::GetEntireFont(int32_t offset, |
| } // namespace |
| // static |
| -PepperTrueTypeFont* PepperTrueTypeFont::Create( |
| +scoped_refptr<PepperTrueTypeFont> PepperTrueTypeFont::Create( |
| const ppapi::proxy::SerializedTrueTypeFontDesc& desc) { |
| - return new PepperTrueTypeFontMac(desc); |
| + scoped_refptr<PepperTrueTypeFont> font = new PepperTrueTypeFontMac(desc); |
| + if (!font->IsValid()) |
| + font = NULL; |
| + return font; |
| } |
| } // namespace content |