Merge pull request #7018 from HanaeKae/jpfont-in-flash
Japanese font rendering in flash.
This commit is contained in:
commit
572f58bc34
2 changed files with 55 additions and 17 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "chrome/renderer/pepper/pepper_flash_font_file_host.h"
|
#include "chrome/renderer/pepper/pepper_flash_font_file_host.h"
|
||||||
|
|
||||||
|
#include "base/sys_byteorder.h"
|
||||||
#include "build/build_config.h"
|
#include "build/build_config.h"
|
||||||
#include "content/public/renderer/renderer_ppapi_host.h"
|
#include "content/public/renderer/renderer_ppapi_host.h"
|
||||||
#include "ppapi/c/pp_errors.h"
|
#include "ppapi/c/pp_errors.h"
|
||||||
|
@ -15,6 +16,8 @@
|
||||||
|
|
||||||
#if defined(OS_LINUX) || defined(OS_OPENBSD)
|
#if defined(OS_LINUX) || defined(OS_OPENBSD)
|
||||||
#include "content/public/common/child_process_sandbox_support_linux.h"
|
#include "content/public/common/child_process_sandbox_support_linux.h"
|
||||||
|
#elif defined(OS_WIN)
|
||||||
|
#include "third_party/skia/include/ports/SkFontMgr.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PepperFlashFontFileHost::PepperFlashFontFileHost(
|
PepperFlashFontFileHost::PepperFlashFontFileHost(
|
||||||
|
@ -31,7 +34,17 @@ PepperFlashFontFileHost::PepperFlashFontFileHost(
|
||||||
description.italic,
|
description.italic,
|
||||||
charset,
|
charset,
|
||||||
PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT));
|
PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT));
|
||||||
#endif // defined(OS_LINUX) || defined(OS_OPENBSD)
|
#elif defined(OS_WIN) // defined(OS_LINUX) || defined(OS_OPENBSD)
|
||||||
|
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);
|
||||||
|
sk_sp<SkFontMgr> font_mgr(SkFontMgr::RefDefault());
|
||||||
|
typeface_ = sk_sp<SkTypeface>(
|
||||||
|
font_mgr->matchFamilyStyle(description.face.c_str(), style));
|
||||||
|
#endif // defined(OS_WIN)
|
||||||
}
|
}
|
||||||
|
|
||||||
PepperFlashFontFileHost::~PepperFlashFontFileHost() {}
|
PepperFlashFontFileHost::~PepperFlashFontFileHost() {}
|
||||||
|
@ -45,29 +58,48 @@ int32_t PepperFlashFontFileHost::OnResourceMessageReceived(
|
||||||
PPAPI_END_MESSAGE_MAP()
|
PPAPI_END_MESSAGE_MAP()
|
||||||
return PP_ERROR_FAILED;
|
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 */,
|
||||||
|
reinterpret_cast<uint8_t*>(buffer), length);
|
||||||
|
#elif defined(OS_WIN)
|
||||||
|
if (typeface_) {
|
||||||
|
table = base::ByteSwap(table);
|
||||||
|
if (buffer == NULL) {
|
||||||
|
*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(
|
int32_t PepperFlashFontFileHost::OnGetFontTable(
|
||||||
ppapi::host::HostMessageContext* context,
|
ppapi::host::HostMessageContext* context,
|
||||||
uint32_t table) {
|
uint32_t table) {
|
||||||
std::string contents;
|
std::string contents;
|
||||||
int32_t result = PP_ERROR_FAILED;
|
int32_t result = PP_ERROR_FAILED;
|
||||||
#if defined(OS_LINUX) || defined(OS_OPENBSD)
|
|
||||||
int fd = fd_.get();
|
|
||||||
if (fd != -1) {
|
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
if (content::GetFontTable(fd, table, 0 /* offset */, NULL, &length)) {
|
if (GetFontData(table, NULL, &length)) {
|
||||||
contents.resize(length);
|
contents.resize(length);
|
||||||
uint8_t* contents_ptr =
|
uint8_t* contents_ptr =
|
||||||
reinterpret_cast<uint8_t*>(const_cast<char*>(contents.c_str()));
|
reinterpret_cast<uint8_t*>(const_cast<char*>(contents.c_str()));
|
||||||
if (content::GetFontTable(
|
if (GetFontData(table, contents_ptr, &length)) {
|
||||||
fd, table, 0 /* offset */, contents_ptr, &length)) {
|
|
||||||
result = PP_OK;
|
result = PP_OK;
|
||||||
} else {
|
} else {
|
||||||
contents.clear();
|
contents.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif // defined(OS_LINUX) || defined(OS_OPENBSD)
|
|
||||||
|
|
||||||
context->reply_msg = PpapiPluginMsg_FlashFontFile_GetFontTableReply(contents);
|
context->reply_msg = PpapiPluginMsg_FlashFontFile_GetFontTableReply(contents);
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
|
|
||||||
#if defined(OS_LINUX) || defined(OS_OPENBSD)
|
#if defined(OS_LINUX) || defined(OS_OPENBSD)
|
||||||
#include "base/files/scoped_file.h"
|
#include "base/files/scoped_file.h"
|
||||||
|
#elif defined(OS_WIN)
|
||||||
|
#include "third_party/skia/include/core/SkRefCnt.h"
|
||||||
|
#include "third_party/skia/include/core/SkTypeface.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
|
@ -39,9 +42,12 @@ class PepperFlashFontFileHost : public ppapi::host::ResourceHost {
|
||||||
private:
|
private:
|
||||||
int32_t OnGetFontTable(ppapi::host::HostMessageContext* context,
|
int32_t OnGetFontTable(ppapi::host::HostMessageContext* context,
|
||||||
uint32_t table);
|
uint32_t table);
|
||||||
|
bool GetFontData(uint32_t table, void* buffer, size_t* length);
|
||||||
|
|
||||||
#if defined(OS_LINUX) || defined(OS_OPENBSD)
|
#if defined(OS_LINUX) || defined(OS_OPENBSD)
|
||||||
base::ScopedFD fd_;
|
base::ScopedFD fd_;
|
||||||
|
#elif defined(OS_WIN)
|
||||||
|
sk_sp<SkTypeface> typeface_;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(PepperFlashFontFileHost);
|
DISALLOW_COPY_AND_ASSIGN(PepperFlashFontFileHost);
|
||||||
|
|
Loading…
Reference in a new issue