Chromium Code Reviews| Index: content/browser/renderer_host/pepper/pepper_truetype_font_linux.cc |
| diff --git a/content/renderer/pepper/pepper_truetype_font_linux.cc b/content/browser/renderer_host/pepper/pepper_truetype_font_linux.cc |
| similarity index 69% |
| rename from content/renderer/pepper/pepper_truetype_font_linux.cc |
| rename to content/browser/renderer_host/pepper/pepper_truetype_font_linux.cc |
| index c54a5148a1a7a32b0fad447d38620702ac8f0dc7..5f49a821fcf894398e0224b82d00a0f7d06aadbb 100644 |
| --- a/content/renderer/pepper/pepper_truetype_font_linux.cc |
| +++ b/content/browser/renderer_host/pepper/pepper_truetype_font_linux.cc |
| @@ -3,14 +3,15 @@ |
| // found in the LICENSE file. |
| #include "base/compiler_specific.h" |
| +#include "base/files/scoped_file.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/numerics/safe_conversions.h" |
| #include "base/sys_byteorder.h" |
| +#include "content/browser/renderer_host/font_utils_linux.h" |
| +#include "content/browser/renderer_host/pepper/pepper_truetype_font.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" |
| -#include "ppapi/c/trusted/ppb_browser_font_trusted.h" |
| namespace content { |
| @@ -18,14 +19,11 @@ namespace { |
| class PepperTrueTypeFontLinux : public PepperTrueTypeFont { |
| public: |
| - explicit PepperTrueTypeFontLinux( |
| - const ppapi::proxy::SerializedTrueTypeFontDesc& desc); |
| - virtual ~PepperTrueTypeFontLinux() OVERRIDE; |
| + PepperTrueTypeFontLinux(); |
| - // PepperTrueTypeFont overrides. |
| - virtual bool IsValid() OVERRIDE; |
| - virtual int32_t Describe(ppapi::proxy::SerializedTrueTypeFontDesc* desc) |
| - OVERRIDE; |
| + // PepperTrueTypeFont implementation. |
| + virtual int32_t Initialize( |
| + 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, |
| @@ -33,62 +31,60 @@ class PepperTrueTypeFontLinux : public PepperTrueTypeFont { |
| 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_; |
| + virtual ~PepperTrueTypeFontLinux() OVERRIDE; |
| + |
| + base::ScopedFD fd_; |
| DISALLOW_COPY_AND_ASSIGN(PepperTrueTypeFontLinux); |
| }; |
| -PepperTrueTypeFontLinux::PepperTrueTypeFontLinux( |
| - const ppapi::proxy::SerializedTrueTypeFontDesc& desc) |
| - : desc_(desc) { |
| +PepperTrueTypeFontLinux::PepperTrueTypeFontLinux() { |
| +} |
| + |
| +PepperTrueTypeFontLinux::~PepperTrueTypeFontLinux() { |
| +} |
| + |
| +int32_t PepperTrueTypeFontLinux::Initialize( |
| + ppapi::proxy::SerializedTrueTypeFontDesc* 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) { |
| + if (desc->family.empty()) { |
| + switch (desc->generic_family) { |
| case PP_TRUETYPEFONTFAMILY_SERIF: |
| - desc_.family = "serif"; |
| + desc->family = "serif"; |
| break; |
| case PP_TRUETYPEFONTFAMILY_SANSSERIF: |
| - desc_.family = "sans-serif"; |
| + desc->family = "sans-serif"; |
| break; |
| case PP_TRUETYPEFONTFAMILY_CURSIVE: |
| - desc_.family = "cursive"; |
| + desc->family = "cursive"; |
| break; |
| case PP_TRUETYPEFONTFAMILY_FANTASY: |
| - desc_.family = "fantasy"; |
| + desc->family = "fantasy"; |
| break; |
| case PP_TRUETYPEFONTFAMILY_MONOSPACE: |
| - desc_.family = "monospace"; |
| + desc->family = "monospace"; |
| break; |
| } |
| } |
| - fd_ = MatchFontWithFallback(desc_.family.c_str(), |
| - desc_.weight >= PP_TRUETYPEFONTWEIGHT_BOLD, |
| - desc_.style & PP_TRUETYPEFONTSTYLE_ITALIC, |
| - desc_.charset, |
| - PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT); |
| -} |
| - |
| -PepperTrueTypeFontLinux::~PepperTrueTypeFontLinux() {} |
| - |
| -bool PepperTrueTypeFontLinux::IsValid() { return fd_ != -1; } |
| - |
| -int32_t PepperTrueTypeFontLinux::Describe( |
| - ppapi::proxy::SerializedTrueTypeFontDesc* desc) { |
| - *desc = desc_; |
| - return PP_OK; |
| + fd_.reset( |
| + MatchFontFaceWithFallback(desc->family, |
| + desc->weight >= PP_TRUETYPEFONTWEIGHT_BOLD, |
| + desc->style & PP_TRUETYPEFONTSTYLE_ITALIC, |
| + desc->charset, |
| + PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT)); |
| + // TODO(bbudge) Modify content API to return results of font matching and |
| + // fallback, so we can update |desc| to reflect that. |
| + return fd_.is_valid() ? PP_OK : PP_ERROR_FAILED; |
| } |
| -int32_t PepperTrueTypeFontLinux::GetTableTags(std::vector<uint32_t>* tags) { |
| +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 (!GetFontTable(fd_, |
| + if (!GetFontTable(fd_.get(), |
|
piman
2014/06/23 18:21:12
So, the fd here could be invalid in case of a mali
bbudge
2014/06/23 18:34:10
I thought about using SequencedTaskRunner but it s
piman
2014/06/23 19:05:47
I'm not sure if there is a way, it doesn't seem ob
bbudge
2014/06/24 01:50:56
Switched to SequenceTaskRunner.
piman
2014/06/24 02:53:29
You still need a check on fd_ here (and GetTable,
bbudge
2014/06/24 12:21:11
Done for both Get* methods, here and for Win and M
|
| 0 /* tag */, |
| 4 /* offset */, |
| reinterpret_cast<uint8_t*>(&num_tables_buf), |
| @@ -104,7 +100,7 @@ int32_t PepperTrueTypeFontLinux::GetTableTags(std::vector<uint32_t>* tags) { |
| output_length = num_tables * kTableEntrySize; |
| scoped_ptr<uint8_t[]> table_entries(new uint8_t[output_length]); |
| // Get the table directory entries, which follow the font header. |
| - if (!GetFontTable(fd_, |
| + if (!GetFontTable(fd_.get(), |
| 0 /* tag */, |
| kFontHeaderSize /* offset */, |
| table_entries.get(), |
| @@ -133,12 +129,12 @@ int32_t PepperTrueTypeFontLinux::GetTable(uint32_t table_tag, |
| size_t table_size = 0; |
| // Tags are byte swapped on Linux. |
| table_tag = base::ByteSwap(table_tag); |
| - if (!GetFontTable(fd_, table_tag, offset, NULL, &table_size)) |
| + if (!GetFontTable(fd_.get(), 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 (!GetFontTable(fd_, |
| + if (!GetFontTable(fd_.get(), |
| table_tag, |
| offset, |
| reinterpret_cast<uint8_t*>(&(*data)[0]), |
| @@ -151,9 +147,8 @@ int32_t PepperTrueTypeFontLinux::GetTable(uint32_t table_tag, |
| } // namespace |
| // static |
| -PepperTrueTypeFont* PepperTrueTypeFont::Create( |
| - const ppapi::proxy::SerializedTrueTypeFontDesc& desc) { |
| - return new PepperTrueTypeFontLinux(desc); |
| +PepperTrueTypeFont* PepperTrueTypeFont::Create() { |
| + return new PepperTrueTypeFontLinux(); |
| } |
| } // namespace content |