summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/test/ppapi/ppapi_browsertest.cc3
-rw-r--r--content/renderer/pepper/pepper_truetype_font_linux.cc144
-rw-r--r--content/renderer/pepper/pepper_truetype_font_mac.mm393
-rw-r--r--content/renderer/pepper/pepper_truetype_font_win.cc193
-rw-r--r--ppapi/cpp/dev/truetype_font_dev.h32
-rw-r--r--ppapi/ppapi_sources.gypi2
-rw-r--r--ppapi/tests/test_truetype_font.cc363
-rw-r--r--ppapi/tests/test_truetype_font.h36
-rw-r--r--ppapi/tests/test_utils.h5
-rw-r--r--ppapi/thunk/enter.cc4
-rw-r--r--ppapi/thunk/ppb_truetype_font_thunk.cc3
11 files changed, 14 insertions, 1164 deletions
diff --git a/chrome/test/ppapi/ppapi_browsertest.cc b/chrome/test/ppapi/ppapi_browsertest.cc
index d0ed388..3f074876 100644
--- a/chrome/test/ppapi/ppapi_browsertest.cc
+++ b/chrome/test/ppapi/ppapi_browsertest.cc
@@ -1203,9 +1203,6 @@ TEST_PPAPI_IN_PROCESS(MouseCursor)
TEST_PPAPI_OUT_OF_PROCESS(MouseCursor)
TEST_PPAPI_NACL(MouseCursor)
-TEST_PPAPI_OUT_OF_PROCESS(TrueTypeFont)
-TEST_PPAPI_NACL(TrueTypeFont)
-
// PPB_Printing only implemented for out of process.
TEST_PPAPI_OUT_OF_PROCESS(Printing)
diff --git a/content/renderer/pepper/pepper_truetype_font_linux.cc b/content/renderer/pepper/pepper_truetype_font_linux.cc
index 4013211..f59df68 100644
--- a/content/renderer/pepper/pepper_truetype_font_linux.cc
+++ b/content/renderer/pepper/pepper_truetype_font_linux.cc
@@ -2,155 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/compiler_specific.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/safe_numerics.h"
-#include "content/public/common/child_process_sandbox_support_linux.h"
#include "content/renderer/pepper/pepper_truetype_font.h"
-#include "ppapi/c/dev/ppb_truetype_font_dev.h"
-#include "ppapi/c/pp_errors.h"
namespace content {
-namespace {
-
-class PepperTrueTypeFontLinux : public PepperTrueTypeFont {
- public:
- explicit PepperTrueTypeFontLinux(
- const ppapi::proxy::SerializedTrueTypeFontDesc& desc);
- virtual ~PepperTrueTypeFontLinux() OVERRIDE;
-
- // PepperTrueTypeFont overrides.
- virtual bool IsValid() OVERRIDE;
- virtual int32_t Describe(
- ppapi::proxy::SerializedTrueTypeFontDesc* desc) OVERRIDE;
- virtual int32_t GetTableTags(std::vector<uint32_t>* tags) OVERRIDE;
- virtual int32_t GetTable(uint32_t table_tag,
- int32_t offset,
- int32_t max_data_length,
- std::string* data) OVERRIDE;
- private:
- // Save creation parameters here and use these to implement Describe.
- // TODO(bbudge) Modify content API to return results of font matching and
- // fallback.
- ppapi::proxy::SerializedTrueTypeFontDesc desc_;
- int fd_;
-
- DISALLOW_COPY_AND_ASSIGN(PepperTrueTypeFontLinux);
-};
-
-PepperTrueTypeFontLinux::PepperTrueTypeFontLinux(
- const ppapi::proxy::SerializedTrueTypeFontDesc& desc) :
- desc_(desc) {
- // If no face is provided, convert family to the platform defaults. These
- // names should be mapped by FontConfig to an appropriate default font.
- if (desc_.family.empty()) {
- switch (desc_.generic_family) {
- case PP_TRUETYPEFONTFAMILY_SERIF:
- desc_.family = "serif";
- break;
- case PP_TRUETYPEFONTFAMILY_SANSSERIF:
- desc_.family = "sans-serif";
- break;
- case PP_TRUETYPEFONTFAMILY_CURSIVE:
- desc_.family = "cursive";
- break;
- case PP_TRUETYPEFONTFAMILY_FANTASY:
- desc_.family = "fantasy";
- break;
- case PP_TRUETYPEFONTFAMILY_MONOSPACE:
- desc_.family = "monospace";
- break;
- }
- }
-
- fd_ = content::MatchFontWithFallback(
- desc_.family.c_str(),
- desc_.weight >= PP_TRUETYPEFONTWEIGHT_BOLD,
- desc_.style & PP_TRUETYPEFONTSTYLE_ITALIC,
- desc_.charset);
-}
-
-PepperTrueTypeFontLinux::~PepperTrueTypeFontLinux() {
-}
-
-bool PepperTrueTypeFontLinux::IsValid() {
- return fd_ != -1;
-}
-
-int32_t PepperTrueTypeFontLinux::Describe(
- ppapi::proxy::SerializedTrueTypeFontDesc* desc) {
- *desc = desc_;
- return PP_OK;
-}
-
-int32_t PepperTrueTypeFontLinux::GetTableTags(std::vector<uint32_t>* tags) {
- // Get the 2 byte numTables field at an offset of 4 in the font.
- uint8_t num_tables_buf[2];
- size_t output_length = sizeof(num_tables_buf);
- if (!content::GetFontTable(fd_,
- 0 /* tag */,
- 4 /* offset */,
- reinterpret_cast<uint8_t*>(&num_tables_buf),
- &output_length))
- return PP_ERROR_FAILED;
- DCHECK(output_length == sizeof(num_tables_buf));
- // Font data is stored in big-endian order.
- uint16_t num_tables = (num_tables_buf[0] << 8) | num_tables_buf[1];
-
- // The font has a header, followed by n table entries in its directory.
- static const size_t kFontHeaderSize = 12;
- static const size_t kTableEntrySize = 16;
- output_length = num_tables * kTableEntrySize;
- scoped_array<uint8_t> table_entries(new uint8_t[output_length]);
- // Get the table directory entries, which follow the font header.
- if (!content::GetFontTable(fd_,
- 0 /* tag */,
- kFontHeaderSize /* offset */,
- table_entries.get(),
- &output_length))
- return PP_ERROR_FAILED;
- DCHECK(output_length == num_tables * kTableEntrySize);
-
- tags->resize(num_tables);
- for (uint16_t i = 0; i < num_tables; i++) {
- uint8_t* entry = table_entries.get() + i * kTableEntrySize;
- uint32_t tag = static_cast<uint32_t>(entry[0]) << 24 |
- static_cast<uint32_t>(entry[1]) << 16 |
- static_cast<uint32_t>(entry[2]) << 8 |
- static_cast<uint32_t>(entry[3]);
- (*tags)[i] = tag;
- }
-
- return num_tables;
-}
-
-int32_t PepperTrueTypeFontLinux::GetTable(uint32_t table_tag,
- int32_t offset,
- int32_t max_data_length,
- std::string* data) {
- // Get the size of the font data first.
- size_t table_size = 0;
- if (!content::GetFontTable(fd_, table_tag, offset, NULL, &table_size))
- return PP_ERROR_FAILED;
- // Only retrieve as much as the caller requested.
- table_size = std::min(table_size, static_cast<size_t>(max_data_length));
- data->resize(table_size);
- if (!content::GetFontTable(fd_, table_tag, offset,
- reinterpret_cast<uint8_t*>(&(*data)[0]),
- &table_size))
- return PP_ERROR_FAILED;
-
- return base::checked_numeric_cast<int32_t>(table_size);
-}
-
-} // namespace
-
// static
PepperTrueTypeFont* PepperTrueTypeFont::Create(
const ppapi::proxy::SerializedTrueTypeFontDesc& desc) {
- return new PepperTrueTypeFontLinux(desc);
+ NOTIMPLEMENTED();
+ return 0;
}
} // namespace content
-
diff --git a/content/renderer/pepper/pepper_truetype_font_mac.mm b/content/renderer/pepper/pepper_truetype_font_mac.mm
index b2fc84f..f59df68 100644
--- a/content/renderer/pepper/pepper_truetype_font_mac.mm
+++ b/content/renderer/pepper/pepper_truetype_font_mac.mm
@@ -4,402 +4,13 @@
#include "content/renderer/pepper/pepper_truetype_font.h"
-#import <ApplicationServices/ApplicationServices.h>
-
-#include <stdio.h>
-
-#include "base/compiler_specific.h"
-#include "base/mac/scoped_cftyperef.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
-#include "base/safe_numerics.h"
-#include "base/sys_byteorder.h"
-#include "base/sys_string_conversions.h"
-#include "ppapi/c/dev/ppb_truetype_font_dev.h"
-#include "ppapi/c/pp_errors.h"
-
namespace content {
-namespace {
-
-float GetMacWeight(PP_TrueTypeFontWeight_Dev weight) {
- // Map values from NORMAL (400) to HEAVY (900) to the range [0 .. 1], and
- // values below NORMAL to the range [-0.6 .. 0]. NORMAL should map to 0.
- float normal = PP_TRUETYPEFONTWEIGHT_NORMAL;
- float heavy = PP_TRUETYPEFONTWEIGHT_HEAVY;
- return (weight - normal) / (heavy - normal);
-}
-
-PP_TrueTypeFontWeight_Dev GetPepperWeight(float weight) {
- // Perform the inverse mapping of GetMacWeight.
- return static_cast<PP_TrueTypeFontWeight_Dev>(
- weight * (PP_TRUETYPEFONTWEIGHT_HEAVY - PP_TRUETYPEFONTWEIGHT_NORMAL) +
- PP_TRUETYPEFONTWEIGHT_NORMAL);
-}
-
-float GetMacWidth(PP_TrueTypeFontWidth_Dev width) {
- // Map values from NORMAL (4) to ULTRA_EXPANDED (8) to the range [0 .. 1],
- // and values below NORMAL to the range [-1 .. 0]. Normal should map to 0.
- float normal = PP_TRUETYPEFONTWIDTH_NORMAL;
- float ultra_expanded = PP_TRUETYPEFONTWIDTH_ULTRAEXPANDED;
- return (width - normal) / (ultra_expanded - normal);
-}
-
-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_NORMAL);
-}
-
-#define MAKE_TABLE_TAG(a, b, c, d) ((a) << 24) + ((b) << 16) + ((c) << 8) + (d)
-
-// TrueType font header and table entry structs. See
-// https://developer.apple.com/fonts/TTRefMan/RM06/Chap6.html
-struct FontHeader {
- int32_t font_type;
- uint16_t num_tables;
- uint16_t search_range;
- uint16_t entry_selector;
- uint16_t range_shift;
-};
-
-struct FontDirectoryEntry {
- uint32_t tag;
- uint32_t checksum;
- uint32_t offset;
- uint32_t logical_length;
-};
-
-uint32_t CalculateChecksum(char* table, int32_t table_length) {
- uint32_t sum = 0;
- uint32_t* current = reinterpret_cast<uint32_t*>(table);
- uint32_t length = (table_length + 3) / 4;
- // Raw font data is big-endian.
- while (length-- > 0)
- sum += base::NetToHost32(*current++);
- return sum;
-}
-
-class PepperTrueTypeFontMac : public PepperTrueTypeFont {
- public:
- explicit PepperTrueTypeFontMac(
- const ppapi::proxy::SerializedTrueTypeFontDesc& desc);
- virtual ~PepperTrueTypeFontMac() OVERRIDE;
-
- // PepperTrueTypeFont overrides.
- virtual bool IsValid() OVERRIDE;
- virtual int32_t Describe(
- ppapi::proxy::SerializedTrueTypeFontDesc* desc) OVERRIDE;
- virtual int32_t GetTableTags(std::vector<uint32_t>* tags) OVERRIDE;
- virtual int32_t GetTable(uint32_t table_tag,
- int32_t offset,
- int32_t max_data_length,
- std::string* data) OVERRIDE;
- private:
- virtual int32_t GetEntireFont(int32_t offset,
- int32_t max_data_length,
- std::string* data);
-
- base::mac::ScopedCFTypeRef<CTFontRef> font_ref_;
-
- DISALLOW_COPY_AND_ASSIGN(PepperTrueTypeFontMac);
-};
-
-PepperTrueTypeFontMac::PepperTrueTypeFontMac(
- const ppapi::proxy::SerializedTrueTypeFontDesc& desc) {
- // Create attributes and traits dictionaries.
- base::mac::ScopedCFTypeRef<CFMutableDictionaryRef> attributes_ref(
- CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
- &kCFTypeDictionaryKeyCallBacks,
- &kCFTypeDictionaryValueCallBacks));
-
- base::mac::ScopedCFTypeRef<CFMutableDictionaryRef> traits_ref(
- CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
- &kCFTypeDictionaryKeyCallBacks,
- &kCFTypeDictionaryValueCallBacks));
- if (!attributes_ref || !traits_ref)
- return;
-
- CFDictionaryAddValue(attributes_ref, kCTFontTraitsAttribute, traits_ref);
-
- // Use symbolic traits to specify traits when possible.
- CTFontSymbolicTraits symbolic_traits = 0;
- if (desc.style & PP_TRUETYPEFONTSTYLE_ITALIC)
- symbolic_traits |= kCTFontItalicTrait;
- if (desc.weight == PP_TRUETYPEFONTWEIGHT_BOLD)
- symbolic_traits |= kCTFontBoldTrait;
- if (desc.width == PP_TRUETYPEFONTWIDTH_CONDENSED)
- symbolic_traits |= kCTFontCondensedTrait;
- else if (desc.width == PP_TRUETYPEFONTWIDTH_EXPANDED)
- symbolic_traits |= kCTFontExpandedTrait;
-
- base::mac::ScopedCFTypeRef<CFNumberRef> symbolic_traits_ref(
- CFNumberCreate(kCFAllocatorDefault,
- kCFNumberSInt32Type,
- &symbolic_traits));
- if (!symbolic_traits_ref)
- return;
- CFDictionaryAddValue(traits_ref, kCTFontSymbolicTrait, symbolic_traits_ref);
-
- // Font family matching doesn't work using family classes in symbolic traits.
- // Instead, map generic_family to font families that are always available.
- std::string family(desc.family);
- if (family.empty()) {
- switch (desc.generic_family) {
- case PP_TRUETYPEFONTFAMILY_SERIF:
- family = "Times";
- break;
- case PP_TRUETYPEFONTFAMILY_SANSSERIF:
- family = "Helvetica";
- break;
- case PP_TRUETYPEFONTFAMILY_CURSIVE:
- family = "Apple Chancery";
- break;
- case PP_TRUETYPEFONTFAMILY_FANTASY:
- family = "Papyrus";
- break;
- case PP_TRUETYPEFONTFAMILY_MONOSPACE:
- family = "Courier";
- break;
- }
- }
-
- base::mac::ScopedCFTypeRef<CFStringRef> name_ref(
- CFStringCreateWithCString(NULL,
- family.c_str(),
- kCFStringEncodingUTF8));
- if (name_ref)
- CFDictionaryAddValue(attributes_ref, kCTFontFamilyNameAttribute, name_ref);
-
- if (desc.weight != PP_TRUETYPEFONTWEIGHT_NORMAL &&
- desc.weight != PP_TRUETYPEFONTWEIGHT_BOLD) {
- float weight = GetMacWeight(desc.weight);
- base::mac::ScopedCFTypeRef<CFNumberRef> weight_trait_ref(
- CFNumberCreate(kCFAllocatorDefault,
- kCFNumberFloat32Type,
- &weight));
- if (weight_trait_ref)
- CFDictionaryAddValue(traits_ref, kCTFontWeightTrait, weight_trait_ref);
- }
-
- if (desc.width != PP_TRUETYPEFONTWIDTH_NORMAL &&
- desc.width != PP_TRUETYPEFONTWIDTH_CONDENSED &&
- desc.width != PP_TRUETYPEFONTWIDTH_EXPANDED) {
- float width = GetMacWidth(desc.width);
- base::mac::ScopedCFTypeRef<CFNumberRef> width_trait_ref(
- CFNumberCreate(kCFAllocatorDefault,
- kCFNumberFloat32Type,
- &width));
- if (width_trait_ref)
- CFDictionaryAddValue(traits_ref, kCTFontWidthTrait, width_trait_ref);
- }
-
- base::mac::ScopedCFTypeRef<CTFontDescriptorRef> desc_ref(
- CTFontDescriptorCreateWithAttributes(attributes_ref));
-
- if (desc_ref)
- font_ref_.reset(CTFontCreateWithFontDescriptor(desc_ref, 0, NULL));
-}
-
-PepperTrueTypeFontMac::~PepperTrueTypeFontMac() {
-}
-
-bool PepperTrueTypeFontMac::IsValid() {
- return font_ref_.get() != NULL;
-}
-
-int32_t PepperTrueTypeFontMac::Describe(
- ppapi::proxy::SerializedTrueTypeFontDesc* desc) {
- if (!IsValid())
- return PP_ERROR_FAILED;
-
- base::mac::ScopedCFTypeRef<CTFontDescriptorRef> desc_ref(
- CTFontCopyFontDescriptor(font_ref_));
-
- base::mac::ScopedCFTypeRef<CFStringRef> family_name_ref(
- static_cast<CFStringRef>(CTFontDescriptorCopyAttribute(
- desc_ref, kCTFontFamilyNameAttribute)));
- desc->family = base::SysCFStringRefToUTF8(family_name_ref);
-
- base::mac::ScopedCFTypeRef<CFDictionaryRef> traits_ref(
- static_cast<CFDictionaryRef>(
- CTFontDescriptorCopyAttribute(desc_ref, kCTFontTraitsAttribute)));
-
- desc->style = PP_TRUETYPEFONTSTYLE_NORMAL;
- CTFontSymbolicTraits symbolic_traits(CTFontGetSymbolicTraits(font_ref_));
- if (symbolic_traits & kCTFontItalicTrait)
- desc->style = static_cast<PP_TrueTypeFontStyle_Dev>(
- desc->style | PP_TRUETYPEFONTSTYLE_ITALIC);
- if (symbolic_traits & kCTFontBoldTrait) {
- desc->weight = PP_TRUETYPEFONTWEIGHT_BOLD;
- } else {
- base::mac::ScopedCFTypeRef<CFNumberRef> weight_trait_ref(
- static_cast<CFNumberRef>(
- CFDictionaryGetValue(traits_ref, kCTFontWeightTrait)));
- if (weight_trait_ref) {
- float weight;
- if (CFNumberGetValue(weight_trait_ref, kCFNumberFloat32Type, &weight))
- desc->weight = GetPepperWeight(weight);
- }
- }
- if (symbolic_traits & kCTFontCondensedTrait) {
- desc->width = PP_TRUETYPEFONTWIDTH_CONDENSED;
- } else if (symbolic_traits & kCTFontExpandedTrait) {
- desc->width = PP_TRUETYPEFONTWIDTH_EXPANDED;
- } else {
- base::mac::ScopedCFTypeRef<CFNumberRef> width_trait_ref(
- static_cast<CFNumberRef>(
- CFDictionaryGetValue(traits_ref, kCTFontWidthTrait)));
- if (width_trait_ref) {
- float width;
- if (CFNumberGetValue(width_trait_ref, kCFNumberFloat32Type, &width))
- desc->width = GetPepperWidth(width);
- }
- }
-
- // Character set isn't supported on Mac.
- desc->charset = PP_TRUETYPEFONTCHARSET_DEFAULT;
- return PP_OK;
-}
-
-int32_t PepperTrueTypeFontMac::GetTableTags(std::vector<uint32_t>* tags) {
- base::mac::ScopedCFTypeRef<CFArrayRef> tag_array(
- CTFontCopyAvailableTables(font_ref_, kCTFontTableOptionNoOptions));
- if (!tag_array.get())
- return PP_ERROR_FAILED;
- CFIndex length = CFArrayGetCount(tag_array);
- tags->resize(length);
- CFArrayGetValues(tag_array, CFRangeMake(0, length),
- reinterpret_cast<const void**>(&(*tags)[0]));
- return length;
-}
-
-int32_t PepperTrueTypeFontMac::GetTable(uint32_t table_tag,
- int32_t offset,
- int32_t max_data_length,
- std::string* data) {
- if (!table_tag)
- return GetEntireFont(offset, max_data_length, data);
-
- base::mac::ScopedCFTypeRef<CFDataRef> table_ref(
- CTFontCopyTable(font_ref_, static_cast<CTFontTableTag>(table_tag),
- kCTFontTableOptionNoOptions));
- if (!table_ref.get())
- return PP_ERROR_FAILED;
-
- CFIndex table_size = CFDataGetLength(table_ref);
- CFIndex safe_offset =
- std::min(base::checked_numeric_cast<CFIndex>(offset), table_size);
- CFIndex safe_length =
- std::min(table_size - safe_offset,
- base::checked_numeric_cast<CFIndex>(max_data_length));
- data->resize(safe_length);
- CFDataGetBytes(table_ref, CFRangeMake(safe_offset, safe_length),
- reinterpret_cast<UInt8*>(&(*data)[0]));
-
- return safe_length;
-}
-
-int32_t PepperTrueTypeFontMac::GetEntireFont(int32_t offset,
- int32_t max_data_length,
- std::string* data) {
- // Reconstruct the font header, table directory, and tables.
- std::vector<uint32_t> table_tags;
- int32_t table_count = GetTableTags(&table_tags);
- if (table_count < 0)
- 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);
- // Map the OS X font type value to a TrueType scaler type.
- base::mac::ScopedCFTypeRef<CFNumberRef> font_type_ref(
- static_cast<CFNumberRef>(
- CTFontCopyAttribute(font_ref_, kCTFontFormatAttribute)));
- int32_t font_type;
- CFNumberGetValue(font_type_ref, kCFNumberSInt32Type, &font_type);
- switch (font_type) {
- case kCTFontFormatOpenTypePostScript:
- font_type = MAKE_TABLE_TAG('O', 'T', 'T', 'O');
- break;
- case kCTFontFormatTrueType:
- case kCTFontFormatBitmap:
- font_type = MAKE_TABLE_TAG('t', 'r', 'u', 'e');
- break;
- case kCTFontFormatPostScript:
- font_type = MAKE_TABLE_TAG('t', 'y', 'p', '1');
- break;
- case kCTFontFormatOpenTypeTrueType:
- case kCTFontFormatUnrecognized:
- default:
- font_type = MAKE_TABLE_TAG(0, 1, 0, 0);
- break;
- }
-
- // Calculate the rest of the header values.
- uint16_t num_tables = base::checked_numeric_cast<uint16_t>(table_count);
- uint16_t entry_selector = 0;
- uint16_t search_range = 1;
- while (search_range < num_tables >> 1) {
- entry_selector++;
- search_range <<= 1;
- }
- search_range <<= 4;
- uint16_t range_shift = (num_tables << 4) - search_range;
-
- // Write the header, with values in big-endian order.
- FontHeader* font_header = reinterpret_cast<FontHeader*>(&font[0]);
- font_header->font_type = base::HostToNet32(font_type);
- font_header->num_tables = base::HostToNet16(num_tables);
- font_header->search_range = base::HostToNet16(search_range);
- font_header->entry_selector = base::HostToNet16(entry_selector);
- font_header->range_shift = base::HostToNet16(range_shift);
-
- 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);
- if (table_size < 0)
- return table_size; // PPAPI error code.
-
- // Append it to the font data so far, and zero pad so tables stay aligned.
- size_t table_offset = font.size();
- font.append(table);
- size_t padding = font.size() & 0x3;
- font.append(padding, 0);
-
- // Fill in the directory entry for this table.
- 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->offset = base::HostToNet32(table_offset);
- entry->logical_length = base::HostToNet32(table_size);
- // TODO(bbudge) set the 'head' table checksumAdjustment.
- }
-
- // Extract a substring if the caller specified an offset or max data length.
- int32_t font_size = base::checked_numeric_cast<int32_t>(font.size());
- int32_t safe_offset = std::min(offset, font_size);
- int32_t safe_length = std::min(font_size - safe_offset, max_data_length);
- if (safe_offset || safe_length != font_size)
- font = font.substr(safe_offset, safe_length);
-
- data->clear();
- data->swap(font);
- return safe_length;
-}
-
-} // namespace
-
// static
PepperTrueTypeFont* PepperTrueTypeFont::Create(
const ppapi::proxy::SerializedTrueTypeFontDesc& desc) {
- return new PepperTrueTypeFontMac(desc);
+ NOTIMPLEMENTED();
+ return 0;
}
} // namespace content
diff --git a/content/renderer/pepper/pepper_truetype_font_win.cc b/content/renderer/pepper/pepper_truetype_font_win.cc
index 03017d4..f59df68 100644
--- a/content/renderer/pepper/pepper_truetype_font_win.cc
+++ b/content/renderer/pepper/pepper_truetype_font_win.cc
@@ -4,202 +4,13 @@
#include "content/renderer/pepper/pepper_truetype_font.h"
-#include <windows.h>
-#include <set>
-
-#include "base/compiler_specific.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/sys_byteorder.h"
-#include "base/utf_string_conversions.h"
-#include "base/win/scoped_hdc.h"
-#include "base/win/scoped_select_object.h"
-#include "ppapi/c/dev/ppb_truetype_font_dev.h"
-#include "ppapi/c/pp_errors.h"
-
namespace content {
-namespace {
-
-class PepperTrueTypeFontWin : public PepperTrueTypeFont {
- public:
- explicit PepperTrueTypeFontWin(
- const ppapi::proxy::SerializedTrueTypeFontDesc& desc);
- virtual ~PepperTrueTypeFontWin();
-
- // PepperTrueTypeFont overrides.
- virtual bool IsValid() OVERRIDE;
- virtual int32_t Describe(
- ppapi::proxy::SerializedTrueTypeFontDesc* desc) OVERRIDE;
- virtual int32_t GetTableTags(std::vector<uint32_t>* tags) OVERRIDE;
- virtual int32_t GetTable(uint32_t table_tag,
- int32_t offset,
- int32_t max_data_length,
- std::string* data) OVERRIDE;
- private:
- HFONT font_;
-
- DISALLOW_COPY_AND_ASSIGN(PepperTrueTypeFontWin);
-};
-
-PepperTrueTypeFontWin::PepperTrueTypeFontWin(
- const ppapi::proxy::SerializedTrueTypeFontDesc& desc) {
- DWORD pitch_and_family = DEFAULT_PITCH;
- switch (desc.generic_family) {
- case PP_TRUETYPEFONTFAMILY_SERIF:
- pitch_and_family |= FF_ROMAN;
- break;
- case PP_TRUETYPEFONTFAMILY_SANSSERIF:
- pitch_and_family |= FF_SWISS;
- break;
- case PP_TRUETYPEFONTFAMILY_CURSIVE:
- pitch_and_family |= FF_SCRIPT;
- break;
- case PP_TRUETYPEFONTFAMILY_FANTASY:
- pitch_and_family |= FF_DECORATIVE;
- break;
- case PP_TRUETYPEFONTFAMILY_MONOSPACE:
- pitch_and_family |= FF_MODERN;
- break;
- }
- // TODO weight, variant.
-
- font_ = CreateFont(0 /* height */,
- 0 /* width */,
- 0 /* escapement */,
- 0 /* orientation */,
- desc.weight, // our weight enum matches Windows.
- (desc.style & PP_TRUETYPEFONTSTYLE_ITALIC) ? 1 : 0,
- 0 /* underline */,
- 0 /* strikeout */,
- desc.charset, // our charset enum matches Windows.
- OUT_OUTLINE_PRECIS /* truetype and other outline fonts */,
- CLIP_DEFAULT_PRECIS,
- DEFAULT_QUALITY,
- pitch_and_family,
- UTF8ToUTF16(desc.family).c_str());
-}
-
-PepperTrueTypeFontWin::~PepperTrueTypeFontWin() {
-}
-
-bool PepperTrueTypeFontWin::IsValid() {
- return font_ != NULL;
-}
-
-int32_t PepperTrueTypeFontWin::Describe(
- ppapi::proxy::SerializedTrueTypeFontDesc* desc) {
- LOGFONT font_desc;
- if (!::GetObject(font_, sizeof(LOGFONT), &font_desc))
- return PP_ERROR_FAILED;
-
- switch (font_desc.lfPitchAndFamily & 0xF0) { // Top 4 bits are family.
- case FF_ROMAN:
- desc->generic_family = PP_TRUETYPEFONTFAMILY_SERIF;
- break;
- case FF_SWISS:
- desc->generic_family = PP_TRUETYPEFONTFAMILY_SANSSERIF;
- break;
- case FF_SCRIPT:
- desc->generic_family = PP_TRUETYPEFONTFAMILY_CURSIVE;
- break;
- case FF_DECORATIVE:
- desc->generic_family = PP_TRUETYPEFONTFAMILY_FANTASY;
- break;
- case FF_MODERN:
- desc->generic_family = PP_TRUETYPEFONTFAMILY_MONOSPACE;
- break;
- }
-
- desc->style = font_desc.lfItalic ? PP_TRUETYPEFONTSTYLE_ITALIC :
- PP_TRUETYPEFONTSTYLE_NORMAL;
- desc->weight = static_cast<PP_TrueTypeFontWeight_Dev>(font_desc.lfWeight);
- desc->width = PP_TRUETYPEFONTWIDTH_NORMAL;
- desc->charset =
- static_cast<PP_TrueTypeFontCharset_Dev>(font_desc.lfCharSet);
-
- // To get the face name, select the font and query for the name. GetObject
- // doesn't fill in the name field of the LOGFONT structure.
- base::win::ScopedCreateDC hdc(::CreateCompatibleDC(NULL));
- if (hdc) {
- base::win::ScopedSelectObject select_object(hdc, font_);
- WCHAR name[LF_FACESIZE];
- GetTextFace(hdc, LF_FACESIZE, name);
- desc->family = UTF16ToUTF8(name);
- }
- return PP_OK;
-}
-
-int32_t PepperTrueTypeFontWin::GetTableTags(std::vector<uint32_t>* tags) {
- base::win::ScopedCreateDC hdc(::CreateCompatibleDC(NULL));
- if (!hdc)
- return PP_ERROR_FAILED;
-
- base::win::ScopedSelectObject select_object(hdc, font_);
-
- // Get the 2 byte numTables field at an offset of 4 in the font. We need to
- // read at least 4 bytes or this fails.
- uint8_t num_tables_buf[4];
- if (::GetFontData(hdc, 0, 4, num_tables_buf, 4) != 4)
- return PP_ERROR_FAILED;
- // Font data is stored in big-endian order.
- DWORD num_tables = (num_tables_buf[0] << 8) | num_tables_buf[1];
-
- // The size in bytes of an entry in the table directory.
- static const DWORD kFontHeaderSize = 12;
- static const DWORD kTableEntrySize = 16;
- DWORD table_size = num_tables * kTableEntrySize;
- scoped_array<uint8_t> table_entries(new uint8_t[table_size]);
- // Get the table directory entries starting at an offset of 12 in the font.
- if (::GetFontData(hdc, 0 /* tag */, kFontHeaderSize,
- table_entries.get(),
- table_size) != table_size)
- return PP_ERROR_FAILED;
-
- tags->resize(num_tables);
- for (DWORD i = 0; i < num_tables; i++) {
- const uint8_t* entry = table_entries.get() + i * kTableEntrySize;
- uint32_t tag = static_cast<uint32_t>(entry[0]) << 24 |
- static_cast<uint32_t>(entry[1]) << 16 |
- static_cast<uint32_t>(entry[2]) << 8 |
- static_cast<uint32_t>(entry[3]);
- (*tags)[i] = tag;
- }
-
- return num_tables;
-}
-
-int32_t PepperTrueTypeFontWin::GetTable(uint32_t table_tag,
- int32_t offset,
- int32_t max_data_length,
- std::string* data) {
- base::win::ScopedCreateDC hdc(::CreateCompatibleDC(NULL));
- if (!hdc)
- return PP_ERROR_FAILED;
-
- base::win::ScopedSelectObject select_object(hdc, font_);
-
- // Tags are byte swapped on Windows.
- table_tag = base::ByteSwap(table_tag);
- // Get the size of the font table first.
- DWORD table_size = ::GetFontData(hdc, table_tag, 0, NULL, 0);
- if (table_size == GDI_ERROR)
- return PP_ERROR_FAILED;
-
- DWORD safe_offset = std::min(static_cast<DWORD>(offset), table_size);
- DWORD safe_length = std::min(table_size - safe_offset,
- static_cast<DWORD>(max_data_length));
- data->resize(safe_length);
- ::GetFontData(hdc, table_tag, safe_offset,
- reinterpret_cast<uint8_t*>(&(*data)[0]), safe_length);
- return static_cast<int32_t>(safe_length);
-}
-
-} // namespace
-
// static
PepperTrueTypeFont* PepperTrueTypeFont::Create(
const ppapi::proxy::SerializedTrueTypeFontDesc& desc) {
- return new PepperTrueTypeFontWin(desc);
+ NOTIMPLEMENTED();
+ return 0;
}
} // namespace content
diff --git a/ppapi/cpp/dev/truetype_font_dev.h b/ppapi/cpp/dev/truetype_font_dev.h
index 30c310b..124d3eb 100644
--- a/ppapi/cpp/dev/truetype_font_dev.h
+++ b/ppapi/cpp/dev/truetype_font_dev.h
@@ -174,43 +174,21 @@ class TrueTypeFont_Dev : public Resource {
namespace internal {
-// This is used by the CompletionCallbackFactory system to hold the output from
-// the async 'Describe' function call. When 'output' is called, this data is
-// wrapped and a reference is passed to the plugin's callback function.
-class TrueTypeFontAdapterWithStorage {
- public:
- TrueTypeFontAdapterWithStorage() {
- }
-
- PP_TrueTypeFontDesc_Dev* pp_output() { return &pp_desc_; }
-
- TrueTypeFontDesc_Dev& output() {
- desc_ = TrueTypeFontDesc_Dev(PASS_REF, pp_desc_);
- return desc_;
- }
-
- private:
- // |pp_desc_| will be written by the 'Describe' function. |desc_| will be
- // constructed and will manage the PP_Var in pp_desc_.
- PP_TrueTypeFontDesc_Dev pp_desc_;
- TrueTypeFontDesc_Dev desc_;
-};
-
// A specialization of CallbackOutputTraits to provide the callback system the
// information on how to handle pp::TrueTypeFontDesc_Dev. This converts
// PP_TrueTypeFontDesc_Dev to pp::TrueTypeFontDesc_Dev when passing to the
// plugin, and specifically manages the PP_Var embedded in the desc_ field.
template<>
-struct CallbackOutputTraits<TrueTypeFontDesc_Dev> {
+struct CallbackOutputTraits<pp::TrueTypeFontDesc_Dev> {
typedef PP_TrueTypeFontDesc_Dev* APIArgType;
- typedef TrueTypeFontAdapterWithStorage StorageType;
+ typedef PP_TrueTypeFontDesc_Dev StorageType;
static inline APIArgType StorageToAPIArg(StorageType& t) {
- return t.pp_output();
+ return &t;
}
- static inline TrueTypeFontDesc_Dev& StorageToPluginArg(StorageType& t) {
- return t.output();
+ static inline pp::TrueTypeFontDesc_Dev StorageToPluginArg(StorageType& t) {
+ return pp::TrueTypeFontDesc_Dev(PASS_REF, t);
}
};
diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi
index 7efc070..1d61391 100644
--- a/ppapi/ppapi_sources.gypi
+++ b/ppapi/ppapi_sources.gypi
@@ -426,8 +426,6 @@
'tests/test_tcp_server_socket_private.h',
'tests/test_tcp_socket_private.cc',
'tests/test_tcp_socket_private.h',
- 'tests/test_truetype_font.cc',
- 'tests/test_truetype_font.h',
'tests/test_udp_socket_private.cc',
'tests/test_udp_socket_private.h',
'tests/test_url_loader.cc',
diff --git a/ppapi/tests/test_truetype_font.cc b/ppapi/tests/test_truetype_font.cc
deleted file mode 100644
index 9c1456d..0000000
--- a/ppapi/tests/test_truetype_font.cc
+++ /dev/null
@@ -1,363 +0,0 @@
-// Copyright (c) 2013 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.
-//
-// Tests PPB_TrueTypeFont interface.
-
-#include "ppapi/tests/test_truetype_font.h"
-
-#include <string.h>
-#include <algorithm>
-#include <limits>
-
-#include "ppapi/c/dev/ppb_testing_dev.h"
-#include "ppapi/cpp/completion_callback.h"
-#include "ppapi/cpp/dev/truetype_font_dev.h"
-#include "ppapi/cpp/instance.h"
-#include "ppapi/cpp/var.h"
-#include "ppapi/tests/test_utils.h"
-#include "ppapi/tests/testing_instance.h"
-
-REGISTER_TEST_CASE(TrueTypeFont);
-
-#define MAKE_TABLE_TAG(a, b, c, d) ((a) << 24) + ((b) << 16) + ((c) << 8) + (d)
-
-namespace {
-
-const PP_Resource kInvalidResource = 0;
-const PP_Instance kInvalidInstance = 0;
-
-// TrueType font header and table entry structs. See
-// https://developer.apple.com/fonts/TTRefMan/RM06/Chap6.html
-struct FontHeader {
- int32_t font_type;
- uint16_t num_tables;
- uint16_t search_range;
- uint16_t entry_selector;
- uint16_t range_shift;
-};
-
-struct FontDirectoryEntry {
- uint32_t tag;
- uint32_t checksum;
- uint32_t offset;
- uint32_t logical_length;
-};
-
-uint32_t ReadBigEndian32(const void* ptr) {
- const uint8_t* data = reinterpret_cast<const uint8_t*>(ptr);
- return (data[3] << 0) | (data[2] << 8) | (data[1] << 16) | (data[0] << 24);
-}
-
-uint16_t ReadBigEndian16(const void* ptr) {
- const uint8_t* data = reinterpret_cast<const uint8_t*>(ptr);
- return (data[1] << 0) | (data[0] << 8);
-}
-
-}
-
-TestTrueTypeFont::TestTrueTypeFont(TestingInstance* instance)
- : TestCase(instance),
- ppb_truetype_font_interface_(NULL),
- ppb_core_interface_(NULL),
- ppb_var_interface_(NULL) {
-}
-
-bool TestTrueTypeFont::Init() {
- ppb_truetype_font_interface_ = static_cast<const PPB_TrueTypeFont_Dev*>(
- pp::Module::Get()->GetBrowserInterface(PPB_TRUETYPEFONT_DEV_INTERFACE));
- ppb_core_interface_ = static_cast<const PPB_Core*>(
- pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE));
- ppb_var_interface_ = static_cast<const PPB_Var*>(
- pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE));
- if (!ppb_truetype_font_interface_)
- instance_->AppendError("PPB_TrueTypeFont_Dev interface not available");
- if (!ppb_core_interface_)
- instance_->AppendError("PPB_Core interface not available");
- if (!ppb_var_interface_)
- instance_->AppendError("PPB_Var interface not available");
-
- return true;
-}
-
-TestTrueTypeFont::~TestTrueTypeFont() {
-}
-
-void TestTrueTypeFont::RunTests(const std::string& filter) {
- RUN_TEST(GetFontFamilies, filter);
- RUN_TEST(Create, filter);
- RUN_TEST(Describe, filter);
- RUN_TEST(GetTableTags, filter);
- RUN_TEST(GetTable, filter);
-}
-
-std::string TestTrueTypeFont::TestGetFontFamilies() {
- {
- // A valid instance should be able to enumerate fonts.
- TestCompletionCallbackWithOutput< std::vector<pp::Var> > cc(
- instance_->pp_instance(), false);
- cc.WaitForResult(pp::TrueTypeFont_Dev::GetFontFamilies(instance_, cc));
- const std::vector<pp::Var> font_families = cc.output();
- // We should get some font families on any platform.
- ASSERT_NE(0, font_families.size());
- ASSERT_EQ(static_cast<int32_t>(font_families.size()), cc.result());
- // Make sure at least one family is a non-empty string.
- ASSERT_NE(0, font_families[0].AsString().size());
- }
- {
- // Using an invalid instance should fail.
- TestCompletionCallbackWithOutput< std::vector<pp::Var> > cc(
- instance_->pp_instance(), false);
- cc.WaitForResult(
- ppb_truetype_font_interface_->GetFontFamilies(
- kInvalidInstance,
- cc.GetCallbackWithOutput().output(),
- cc.GetCallback().pp_completion_callback()));
- ASSERT_EQ(PP_ERROR_FAILED, cc.result());
- ASSERT_EQ(0, cc.output().size());
- }
-
- PASS();
-}
-
-std::string TestTrueTypeFont::TestCreate() {
- PP_Resource font;
- PP_TrueTypeFontDesc_Dev desc = {
- PP_MakeUndefined(),
- PP_TRUETYPEFONTFAMILY_SERIF,
- PP_TRUETYPEFONTSTYLE_NORMAL,
- PP_TRUETYPEFONTWEIGHT_NORMAL,
- PP_TRUETYPEFONTWIDTH_NORMAL,
- PP_TRUETYPEFONTCHARSET_DEFAULT
- };
- // Creating a font from an invalid instance returns an invalid resource.
- font = ppb_truetype_font_interface_->Create(kInvalidInstance, &desc);
- ASSERT_EQ(kInvalidResource, font);
- ASSERT_NE(PP_TRUE, ppb_truetype_font_interface_->IsFont(font));
-
- // Creating a font from a valid instance returns a font resource.
- font = ppb_truetype_font_interface_->Create(instance_->pp_instance(), &desc);
- ASSERT_NE(kInvalidResource, font);
- ASSERT_EQ(PP_TRUE, ppb_truetype_font_interface_->IsFont(font));
-
- ppb_core_interface_->ReleaseResource(font);
- // Once released, the resource shouldn't be a font.
- ASSERT_NE(PP_TRUE, ppb_truetype_font_interface_->IsFont(font));
-
- PASS();
-}
-
-std::string TestTrueTypeFont::TestDescribe() {
- pp::TrueTypeFontDesc_Dev create_desc;
- create_desc.set_generic_family(PP_TRUETYPEFONTFAMILY_SERIF);
- create_desc.set_style(PP_TRUETYPEFONTSTYLE_NORMAL);
- create_desc.set_weight(PP_TRUETYPEFONTWEIGHT_NORMAL);
- pp::TrueTypeFont_Dev font(instance_, create_desc);
- // Describe: See what font-matching did with a generic font. We should always
- // be able to Create a generic Serif font.
- TestCompletionCallbackWithOutput<pp::TrueTypeFontDesc_Dev> cc(
- instance_->pp_instance(), false);
- cc.WaitForResult(font.Describe(cc));
- pp::TrueTypeFontDesc_Dev& desc = cc.output();
- ASSERT_NE(0, desc.family().AsString().size());
- ASSERT_EQ(PP_TRUETYPEFONTFAMILY_SERIF, desc.generic_family());
- ASSERT_EQ(PP_TRUETYPEFONTSTYLE_NORMAL, desc.style());
- ASSERT_EQ(PP_TRUETYPEFONTWEIGHT_NORMAL, desc.weight());
-
- // Describe an invalid resource should fail.
- PP_TrueTypeFontDesc_Dev fail_desc;
- memset(&fail_desc, 0, sizeof(fail_desc));
- fail_desc.family = PP_MakeUndefined();
- // Create a shallow copy to check that no data is changed.
- PP_TrueTypeFontDesc_Dev fail_desc_copy;
- memcpy(&fail_desc_copy, &fail_desc, sizeof(fail_desc));
-
- cc.WaitForResult(
- ppb_truetype_font_interface_->Describe(
- kInvalidResource,
- &fail_desc,
- cc.GetCallback().pp_completion_callback()));
- ASSERT_EQ(PP_ERROR_BADRESOURCE, cc.result());
- ASSERT_EQ(PP_VARTYPE_UNDEFINED, fail_desc.family.type);
- ASSERT_EQ(0, memcmp(&fail_desc, &fail_desc_copy, sizeof(fail_desc)));
-
- PASS();
-}
-
-std::string TestTrueTypeFont::TestGetTableTags() {
- pp::TrueTypeFontDesc_Dev desc;
- pp::TrueTypeFont_Dev font(instance_, desc);
- {
- TestCompletionCallbackWithOutput< std::vector<uint32_t> > cc(
- instance_->pp_instance(), false);
- cc.WaitForResult(font.GetTableTags(cc));
- std::vector<uint32_t> tags = cc.output();
- ASSERT_NE(0, tags.size());
- ASSERT_EQ(static_cast<int32_t>(tags.size()), cc.result());
- // Tags will vary depending on the actual font that the host platform
- // chooses. Check that all required TrueType tags are present.
- const int required_tag_count = 9;
- uint32_t required_tags[required_tag_count] = {
- // Note: these must be sorted for std::includes below.
- MAKE_TABLE_TAG('c', 'm', 'a', 'p'),
- MAKE_TABLE_TAG('g', 'l', 'y', 'f'),
- MAKE_TABLE_TAG('h', 'e', 'a', 'd'),
- MAKE_TABLE_TAG('h', 'h', 'e', 'a'),
- MAKE_TABLE_TAG('h', 'm', 't', 'x'),
- MAKE_TABLE_TAG('l', 'o', 'c', 'a'),
- MAKE_TABLE_TAG('m', 'a', 'x', 'p'),
- MAKE_TABLE_TAG('n', 'a', 'm', 'e'),
- MAKE_TABLE_TAG('p', 'o', 's', 't')
- };
- std::sort(tags.begin(), tags.end());
- ASSERT_TRUE(std::includes(tags.begin(),
- tags.end(),
- required_tags,
- required_tags + required_tag_count));
- }
- {
- // Invalid resource should fail and write no data.
- TestCompletionCallbackWithOutput< std::vector<uint32_t> > cc(
- instance_->pp_instance(), false);
- cc.WaitForResult(
- ppb_truetype_font_interface_->GetTableTags(
- kInvalidResource,
- cc.GetCallbackWithOutput().output(),
- cc.GetCallback().pp_completion_callback()));
- ASSERT_EQ(PP_ERROR_BADRESOURCE, cc.result());
- ASSERT_EQ(0, cc.output().size());
- }
-
- PASS();
-}
-
-std::string TestTrueTypeFont::TestGetTable() {
- pp::TrueTypeFontDesc_Dev desc;
- pp::TrueTypeFont_Dev font(instance_, desc);
-
- {
- // Getting a required table from a valid font should succeed.
- TestCompletionCallbackWithOutput< std::vector<char> > cc(
- instance_->pp_instance(), false);
- cc.WaitForResult(font.GetTable(MAKE_TABLE_TAG('c', 'm', 'a', 'p'),
- 0, std::numeric_limits<int32_t>::max(),
- cc));
- const std::vector<char> data = cc.output();
- ASSERT_NE(0, data.size());
- ASSERT_EQ(static_cast<int32_t>(data.size()), cc.result());
-
- // Passing 0 for the table tag should return the entire font.
- TestCompletionCallbackWithOutput< std::vector<char> > cc2(
- instance_->pp_instance(), false);
- cc2.WaitForResult(font.GetTable(0 /* table_tag */,
- 0, std::numeric_limits<int32_t>::max(),
- cc2));
- const std::vector<char> entire_font = cc2.output();
- ASSERT_NE(0, entire_font.size());
- ASSERT_EQ(static_cast<int32_t>(entire_font.size()), cc2.result());
-
- // Verify that the CMAP table is in entire_font, and that it's identical
- // to the one we retrieved above. Note that since the font header and table
- // directory are in file (big-endian) order, we need to byte swap tags and
- // numbers.
- const size_t kHeaderSize = sizeof(FontHeader);
- const size_t kEntrySize = sizeof(FontDirectoryEntry);
- ASSERT_TRUE(kHeaderSize < entire_font.size());
- FontHeader header;
- memcpy(&header, &entire_font[0], kHeaderSize);
- uint16_t num_tables = ReadBigEndian16(&header.num_tables);
- std::vector<FontDirectoryEntry> directory(num_tables);
- size_t directory_size = kEntrySize * num_tables;
- ASSERT_TRUE(kHeaderSize + directory_size < entire_font.size());
- memcpy(&directory[0], &entire_font[kHeaderSize], directory_size);
- const FontDirectoryEntry* cmap_entry = NULL;
- for (uint16_t i = 0; i < num_tables; i++) {
- if (ReadBigEndian32(&directory[i].tag) ==
- MAKE_TABLE_TAG('c', 'm', 'a', 'p')) {
- cmap_entry = &directory[i];
- break;
- }
- }
- ASSERT_NE(NULL, cmap_entry);
-
- uint32_t logical_length = ReadBigEndian32(&cmap_entry->logical_length);
- uint32_t table_offset = ReadBigEndian32(&cmap_entry->offset);
- ASSERT_EQ(static_cast<size_t>(logical_length), data.size());
- ASSERT_TRUE(static_cast<size_t>(table_offset + logical_length) <
- entire_font.size());
- const char* cmap_table = &entire_font[0] + table_offset;
- ASSERT_EQ(0, memcmp(cmap_table, &data[0], data.size()));
-
- // Use offset and max_data_length to restrict the data.
- TestCompletionCallbackWithOutput< std::vector<char> > cc3(
- instance_->pp_instance(), false);
- const int32_t kOffset = 4;
- const int32_t kMaxDataSize = 1000;
- cc3.WaitForResult(font.GetTable(0 /* table_tag */,
- kOffset,
- kMaxDataSize,
- cc3));
- const std::vector<char> partial_font = cc3.output();
- ASSERT_EQ(partial_font.size(), static_cast<size_t>(cc3.result()));
- ASSERT_EQ(partial_font.size(), static_cast<size_t>(kMaxDataSize));
- ASSERT_EQ(0, memcmp(&entire_font[kOffset], &partial_font[0], kMaxDataSize));
- }
- {
- // Getting an invalid table should fail ('zzzz' should be safely invalid).
- TestCompletionCallbackWithOutput< std::vector<char> > cc(
- instance_->pp_instance(), false);
- cc.WaitForResult(font.GetTable(MAKE_TABLE_TAG('z', 'z', 'z', 'z'),
- 0, std::numeric_limits<int32_t>::max(),
- cc));
- ASSERT_EQ(0, cc.output().size());
- ASSERT_EQ(PP_ERROR_FAILED, cc.result());
- }
- {
- // GetTable on an invalid resource should fail with a bad resource error
- // and write no data.
- TestCompletionCallbackWithOutput< std::vector<char> > cc(
- instance_->pp_instance(), false);
- cc.WaitForResult(
- ppb_truetype_font_interface_->GetTable(
- kInvalidResource,
- MAKE_TABLE_TAG('c', 'm', 'a', 'p'),
- 0, std::numeric_limits<int32_t>::max(),
- cc.GetCallbackWithOutput().output(),
- cc.GetCallback().pp_completion_callback()));
- ASSERT_EQ(PP_ERROR_BADRESOURCE, cc.result());
- ASSERT_EQ(0, cc.output().size());
- }
- {
- // Negative offset should fail with a bad argument error and write no data.
- TestCompletionCallbackWithOutput< std::vector<char> > cc(
- instance_->pp_instance(), false);
- cc.WaitForResult(font.GetTable(MAKE_TABLE_TAG('c', 'm', 'a', 'p'),
- -100, 0,
- cc));
- ASSERT_EQ(PP_ERROR_BADARGUMENT, cc.result());
- ASSERT_EQ(0, cc.output().size());
- }
- {
- // Offset larger than file size succeeds but returns no data.
- TestCompletionCallbackWithOutput< std::vector<char> > cc(
- instance_->pp_instance(), false);
- cc.WaitForResult(font.GetTable(MAKE_TABLE_TAG('c', 'm', 'a', 'p'),
- 1 << 28, 0,
- cc));
- ASSERT_EQ(PP_OK, cc.result());
- ASSERT_EQ(0, cc.output().size());
- }
- {
- // Negative max_data_length should fail with a bad argument error and write
- // no data.
- TestCompletionCallbackWithOutput< std::vector<char> > cc(
- instance_->pp_instance(), false);
- cc.WaitForResult(font.GetTable(MAKE_TABLE_TAG('c', 'm', 'a', 'p'),
- 0, -100,
- cc));
- ASSERT_EQ(PP_ERROR_BADARGUMENT, cc.result());
- ASSERT_EQ(0, cc.output().size());
- }
-
- PASS();
-}
diff --git a/ppapi/tests/test_truetype_font.h b/ppapi/tests/test_truetype_font.h
deleted file mode 100644
index 90977c8..0000000
--- a/ppapi/tests/test_truetype_font.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (c) 2013 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.
-
-#ifndef PAPPI_TESTS_TEST_TRUETYPE_FONT_H_
-#define PAPPI_TESTS_TEST_TRUETYPE_FONT_H_
-
-#include <string>
-
-#include "ppapi/c/dev/ppb_truetype_font_dev.h"
-#include "ppapi/c/ppb_core.h"
-#include "ppapi/c/ppb_var.h"
-#include "ppapi/tests/test_case.h"
-
-class TestTrueTypeFont : public TestCase {
- public:
- explicit TestTrueTypeFont(TestingInstance* instance);
- virtual ~TestTrueTypeFont();
-
- private:
- // TestCase implementation.
- virtual bool Init();
- virtual void RunTests(const std::string& filter);
-
- std::string TestGetFontFamilies();
- std::string TestCreate();
- std::string TestDescribe();
- std::string TestGetTableTags();
- std::string TestGetTable();
-
- const PPB_TrueTypeFont_Dev* ppb_truetype_font_interface_;
- const PPB_Core* ppb_core_interface_;
- const PPB_Var* ppb_var_interface_;
-};
-
-#endif // PAPPI_TESTS_TEST_TRUETYPE_FONT_H_
diff --git a/ppapi/tests/test_utils.h b/ppapi/tests/test_utils.h
index 3a471d8..e61efbd 100644
--- a/ppapi/tests/test_utils.h
+++ b/ppapi/tests/test_utils.h
@@ -190,10 +190,7 @@ class TestCompletionCallbackWithOutput : public TestCompletionCallback {
return GetCallbackWithOutput();
}
- OutputT& output() {
- return pp::internal::CallbackOutputTraits<OutputT>::StorageToPluginArg(
- output_storage_);
- }
+ const OutputT& output() { return output_storage_.output(); }
typename pp::CompletionCallbackWithOutput<OutputT>::OutputStorageType
output_storage_;
diff --git a/ppapi/thunk/enter.cc b/ppapi/thunk/enter.cc
index 965e0f1..0248eba 100644
--- a/ppapi/thunk/enter.cc
+++ b/ppapi/thunk/enter.cc
@@ -63,9 +63,7 @@ EnterBase::EnterBase(PP_Instance instance, SingletonResourceID resource_id,
const PP_CompletionCallback& callback)
: resource_(GetSingletonResource(instance, resource_id)),
retval_(PP_OK) {
- DCHECK(resource_ || !instance);
- if (!resource_)
- retval_ = PP_ERROR_BADARGUMENT;
+ DCHECK(resource_);
callback_ = new TrackedCallback(resource_, callback);
}
diff --git a/ppapi/thunk/ppb_truetype_font_thunk.cc b/ppapi/thunk/ppb_truetype_font_thunk.cc
index 4b47afb..b941c84 100644
--- a/ppapi/thunk/ppb_truetype_font_thunk.cc
+++ b/ppapi/thunk/ppb_truetype_font_thunk.cc
@@ -24,8 +24,7 @@ int32_t GetFontFamilies(PP_Instance instance,
EnterInstanceAPI<PPB_TrueTypeFont_Singleton_API> enter(instance, callback);
if (enter.failed())
return PP_ERROR_FAILED;
- return enter.SetResult(
- enter.functions()->GetFontFamilies(instance, output, enter.callback()));
+ return enter.functions()->GetFontFamilies(instance, output, enter.callback());
}
PP_Resource Create(PP_Instance instance,