Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(969)

Side by Side Diff: chrome/renderer/pepper/pepper_flash_font_file_host.cc

Issue 1416643002: Enable pp::flash::FontFile support on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Based generated thunk files Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/pepper/pepper_flash_font_file_host.h" 5 #include "chrome/renderer/pepper/pepper_flash_font_file_host.h"
6 6
7 #include "base/sys_byteorder.h"
7 #include "build/build_config.h" 8 #include "build/build_config.h"
8 #include "content/public/renderer/renderer_ppapi_host.h" 9 #include "content/public/renderer/renderer_ppapi_host.h"
9 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/host/dispatch_host_message.h" 11 #include "ppapi/host/dispatch_host_message.h"
11 #include "ppapi/host/host_message_context.h" 12 #include "ppapi/host/host_message_context.h"
12 #include "ppapi/host/ppapi_host.h" 13 #include "ppapi/host/ppapi_host.h"
13 #include "ppapi/proxy/ppapi_messages.h" 14 #include "ppapi/proxy/ppapi_messages.h"
14 #include "ppapi/proxy/serialized_structs.h" 15 #include "ppapi/proxy/serialized_structs.h"
15 16
16 #if defined(OS_LINUX) || defined(OS_OPENBSD) 17 #if defined(OS_LINUX) || defined(OS_OPENBSD)
17 #include "content/public/common/child_process_sandbox_support_linux.h" 18 #include "content/public/common/child_process_sandbox_support_linux.h"
19 #elif defined(OS_WIN)
20 #include "third_party/skia/include/ports/SkFontMgr.h"
18 #endif 21 #endif
19 22
20 PepperFlashFontFileHost::PepperFlashFontFileHost( 23 PepperFlashFontFileHost::PepperFlashFontFileHost(
21 content::RendererPpapiHost* host, 24 content::RendererPpapiHost* host,
22 PP_Instance instance, 25 PP_Instance instance,
23 PP_Resource resource, 26 PP_Resource resource,
24 const ppapi::proxy::SerializedFontDescription& description, 27 const ppapi::proxy::SerializedFontDescription& description,
25 PP_PrivateFontCharset charset) 28 PP_PrivateFontCharset charset)
26 : ResourceHost(host->GetPpapiHost(), instance, resource) { 29 : ResourceHost(host->GetPpapiHost(), instance, resource) {
27 #if defined(OS_LINUX) || defined(OS_OPENBSD) 30 #if defined(OS_LINUX) || defined(OS_OPENBSD)
28 fd_.reset(content::MatchFontWithFallback( 31 fd_.reset(content::MatchFontWithFallback(
29 description.face, 32 description.face,
30 description.weight >= PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD, 33 description.weight >= PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD,
31 description.italic, 34 description.italic,
32 charset, 35 charset,
33 PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT)); 36 PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT));
37 #elif defined(OS_WIN)
38 int weight = description.weight;
39 if (weight == FW_DONTCARE)
40 weight = SkFontStyle::kNormal_Weight;
41 SkFontStyle style(weight, SkFontStyle::kNormal_Width,
42 description.italic ? SkFontStyle::kItalic_Slant
43 : SkFontStyle::kUpright_Slant);
44 skia::RefPtr<SkFontMgr> font_mgr = skia::AdoptRef(SkFontMgr::RefDefault());
45 typeface_ = skia::AdoptRef(
46 font_mgr->matchFamilyStyle(description.face.c_str(), style));
34 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) 47 #endif // defined(OS_LINUX) || defined(OS_OPENBSD)
35 } 48 }
36 49
37 PepperFlashFontFileHost::~PepperFlashFontFileHost() {} 50 PepperFlashFontFileHost::~PepperFlashFontFileHost() {}
38 51
39 int32_t PepperFlashFontFileHost::OnResourceMessageReceived( 52 int32_t PepperFlashFontFileHost::OnResourceMessageReceived(
40 const IPC::Message& msg, 53 const IPC::Message& msg,
41 ppapi::host::HostMessageContext* context) { 54 ppapi::host::HostMessageContext* context) {
42 PPAPI_BEGIN_MESSAGE_MAP(PepperFlashFontFileHost, msg) 55 PPAPI_BEGIN_MESSAGE_MAP(PepperFlashFontFileHost, msg)
43 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FlashFontFile_GetFontTable, 56 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FlashFontFile_GetFontTable,
44 OnGetFontTable) 57 OnGetFontTable)
45 PPAPI_END_MESSAGE_MAP() 58 PPAPI_END_MESSAGE_MAP()
46 return PP_ERROR_FAILED; 59 return PP_ERROR_FAILED;
47 } 60 }
48 61
62 bool PepperFlashFontFileHost::GetFontData(uint32_t table,
63 void* buffer,
64 size_t* length) {
65 bool result = false;
66 #if defined(OS_LINUX) || defined(OS_OPENBSD)
67 int fd = fd_.get();
68 if (fd != -1)
69 result = content::GetFontTable(fd, table, 0 /* offset */,
Xing 2015/10/23 21:59:02 Fixed the typo of extra ')', and did the necessary
70 reinterpret_cast<uint8_t*>(buffer), length);
71 #elif defined(OS_WIN)
72 if (typeface_) {
73 table = base::ByteSwap(table);
74 if (buffer == NULL) {
bbudge 2015/10/28 00:06:33 Digging into skia a little bit, it seems like you'
Xing 2015/10/28 21:52:50 https://code.google.com/p/chromium/codesearch#chro
bbudge 2015/11/02 20:20:17 OK.
75 *length = typeface_->getTableSize(table);
76 if (*length > 0)
77 result = true;
78 } else {
79 size_t new_length = typeface_->getTableData(table, 0, *length, buffer);
80 if (new_length == *length)
81 result = true;
82 }
83 }
84 #endif
85 return result;
86 }
87
49 int32_t PepperFlashFontFileHost::OnGetFontTable( 88 int32_t PepperFlashFontFileHost::OnGetFontTable(
50 ppapi::host::HostMessageContext* context, 89 ppapi::host::HostMessageContext* context,
51 uint32_t table) { 90 uint32_t table) {
52 std::string contents; 91 std::string contents;
53 int32_t result = PP_ERROR_FAILED; 92 int32_t result = PP_ERROR_FAILED;
54 #if defined(OS_LINUX) || defined(OS_OPENBSD) 93 size_t length = 0;
55 int fd = fd_.get(); 94 if (GetFontData(table, NULL, &length)) {
56 if (fd != -1) { 95 contents.resize(length);
57 size_t length = 0; 96 uint8_t* contents_ptr =
58 if (content::GetFontTable(fd, table, 0 /* offset */, NULL, &length)) { 97 reinterpret_cast<uint8_t*>(const_cast<char*>(contents.c_str()));
59 contents.resize(length); 98 if (GetFontData(table, contents_ptr, &length)) {
60 uint8_t* contents_ptr = 99 result = PP_OK;
61 reinterpret_cast<uint8_t*>(const_cast<char*>(contents.c_str())); 100 } else {
62 if (content::GetFontTable( 101 contents.clear();
63 fd, table, 0 /* offset */, contents_ptr, &length)) {
64 result = PP_OK;
65 } else {
66 contents.clear();
67 }
68 } 102 }
69 } 103 }
70 #endif // defined(OS_LINUX) || defined(OS_OPENBSD)
71
72 context->reply_msg = PpapiPluginMsg_FlashFontFile_GetFontTableReply(contents); 104 context->reply_msg = PpapiPluginMsg_FlashFontFile_GetFontTableReply(contents);
73 return result; 105 return result;
74 } 106 }
OLDNEW
« no previous file with comments | « chrome/renderer/pepper/pepper_flash_font_file_host.h ('k') | ppapi/api/private/ppb_flash_font_file.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698