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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/pepper/pepper_flash_font_file_host.cc
diff --git a/chrome/renderer/pepper/pepper_flash_font_file_host.cc b/chrome/renderer/pepper/pepper_flash_font_file_host.cc
index 69cd7e0f8c02db54de857fae57bbd485f9f8633e..aed27bf378c65f572f2bd213b5b8f52607c32cee 100644
--- a/chrome/renderer/pepper/pepper_flash_font_file_host.cc
+++ b/chrome/renderer/pepper/pepper_flash_font_file_host.cc
@@ -4,6 +4,7 @@
#include "chrome/renderer/pepper/pepper_flash_font_file_host.h"
+#include "base/sys_byteorder.h"
#include "build/build_config.h"
#include "content/public/renderer/renderer_ppapi_host.h"
#include "ppapi/c/pp_errors.h"
@@ -15,6 +16,8 @@
#if defined(OS_LINUX) || defined(OS_OPENBSD)
#include "content/public/common/child_process_sandbox_support_linux.h"
+#elif defined(OS_WIN)
+#include "third_party/skia/include/ports/SkFontMgr.h"
#endif
PepperFlashFontFileHost::PepperFlashFontFileHost(
@@ -31,6 +34,16 @@ PepperFlashFontFileHost::PepperFlashFontFileHost(
description.italic,
charset,
PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT));
+#elif defined(OS_WIN)
+ int weight = description.weight;
+ if (weight == FW_DONTCARE)
+ weight = SkFontStyle::kNormal_Weight;
+ SkFontStyle style(weight, SkFontStyle::kNormal_Width,
+ description.italic ? SkFontStyle::kItalic_Slant
+ : SkFontStyle::kUpright_Slant);
+ skia::RefPtr<SkFontMgr> font_mgr = skia::AdoptRef(SkFontMgr::RefDefault());
+ typeface_ = skia::AdoptRef(
+ font_mgr->matchFamilyStyle(description.face.c_str(), style));
#endif // defined(OS_LINUX) || defined(OS_OPENBSD)
}
@@ -46,29 +59,48 @@ int32_t PepperFlashFontFileHost::OnResourceMessageReceived(
return PP_ERROR_FAILED;
}
+bool PepperFlashFontFileHost::GetFontData(uint32_t table,
+ void* buffer,
+ size_t* length) {
+ bool result = false;
+#if defined(OS_LINUX) || defined(OS_OPENBSD)
+ int fd = fd_.get();
+ if (fd != -1)
+ result = content::GetFontTable(fd, table, 0 /* offset */,
Xing 2015/10/23 21:59:02 Fixed the typo of extra ')', and did the necessary
+ reinterpret_cast<uint8_t*>(buffer), length);
+#elif defined(OS_WIN)
+ if (typeface_) {
+ table = base::ByteSwap(table);
+ 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.
+ *length = typeface_->getTableSize(table);
+ if (*length > 0)
+ result = true;
+ } else {
+ size_t new_length = typeface_->getTableData(table, 0, *length, buffer);
+ if (new_length == *length)
+ result = true;
+ }
+ }
+#endif
+ return result;
+}
+
int32_t PepperFlashFontFileHost::OnGetFontTable(
ppapi::host::HostMessageContext* context,
uint32_t table) {
std::string contents;
int32_t result = PP_ERROR_FAILED;
-#if defined(OS_LINUX) || defined(OS_OPENBSD)
- int fd = fd_.get();
- if (fd != -1) {
- size_t length = 0;
- if (content::GetFontTable(fd, table, 0 /* offset */, NULL, &length)) {
- contents.resize(length);
- uint8_t* contents_ptr =
- reinterpret_cast<uint8_t*>(const_cast<char*>(contents.c_str()));
- if (content::GetFontTable(
- fd, table, 0 /* offset */, contents_ptr, &length)) {
- result = PP_OK;
- } else {
- contents.clear();
- }
+ size_t length = 0;
+ if (GetFontData(table, NULL, &length)) {
+ contents.resize(length);
+ uint8_t* contents_ptr =
+ reinterpret_cast<uint8_t*>(const_cast<char*>(contents.c_str()));
+ if (GetFontData(table, contents_ptr, &length)) {
+ result = PP_OK;
+ } else {
+ contents.clear();
}
}
-#endif // defined(OS_LINUX) || defined(OS_OPENBSD)
-
context->reply_msg = PpapiPluginMsg_FlashFontFile_GetFontTableReply(contents);
return result;
}
« 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