Commit 0f9067ba authored by bashi@chromium.org's avatar bashi@chromium.org

Use new getFontFamilyForCharacters() API.

Uses new getFontFamilyForCharacters() WebKit Chromium API so that
Chromium can pass bold and italic property. This will fix issue 32109.

No behavior change at this time. The CL will work after the fix of
WebKit side is completed.

The WebKit bug entry is https://bugs.webkit.org/show_bug.cgi?id=38701.

BUG=32109
TEST=compiled.


Review URL: http://codereview.chromium.org/8590028

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110871 0039d316-1c4b-4281-b951-d872f2087c98
parent d36352ca
......@@ -267,16 +267,20 @@ class SandboxIPCProcess {
if (!pickle.ReadString(&iter, &preferred_locale))
return;
WebCString family = WebFontInfo::familyForChars(chars.get(),
WebKit::WebFontFamily family;
WebFontInfo::familyForChars(chars.get(),
num_chars,
preferred_locale.c_str());
preferred_locale.c_str(),
&family);
Pickle reply;
if (family.data()) {
reply.WriteString(family.data());
if (family.name.data()) {
reply.WriteString(family.name.data());
} else {
reply.WriteString("");
}
reply.WriteBool(family.isBold);
reply.WriteBool(family.isItalic);
SendRendererReply(fds, reply, -1);
}
......
......@@ -13,6 +13,7 @@
#include "content/common/chrome_descriptors.h"
#include "content/common/sandbox_methods_linux.h"
#include "content/common/unix_domain_socket_posix.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebFontFamily.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebFontRenderStyle.h"
static int GetSandboxFD() {
......@@ -21,9 +22,10 @@ static int GetSandboxFD() {
namespace content {
std::string GetFontFamilyForCharacters(const uint16_t* utf16,
void GetFontFamilyForCharacters(const uint16_t* utf16,
size_t num_utf16,
const char* preferred_locale) {
const char* preferred_locale,
WebKit::WebFontFamily* family) {
Pickle request;
request.WriteInt(LinuxSandbox::METHOD_GET_FONT_FAMILY_FOR_CHARS);
request.WriteInt(num_utf16);
......@@ -36,13 +38,19 @@ std::string GetFontFamilyForCharacters(const uint16_t* utf16,
sizeof(buf), NULL, request);
std::string family_name;
bool isBold = false;
bool isItalic = false;
if (n != -1) {
Pickle reply(reinterpret_cast<char*>(buf), n);
void* pickle_iter = NULL;
reply.ReadString(&pickle_iter, &family_name);
if (reply.ReadString(&pickle_iter, &family_name) &&
reply.ReadBool(&pickle_iter, &isBold) &&
reply.ReadBool(&pickle_iter, &isItalic)) {
family->name = family_name;
family->isBold = isBold;
family->isItalic = isItalic;
}
}
return family_name;
}
void GetRenderStyleForStrike(const char* family, int sizeAndStyle,
......
......@@ -9,6 +9,7 @@
#include "content/public/common/child_process_sandbox_support_linux.h"
namespace WebKit {
struct WebFontFamily;
struct WebFontRenderStyle;
}
......@@ -20,11 +21,12 @@ namespace content {
// num_utf16: the number of 16-bit words in |utf16|
// preferred_locale: preferred locale identifier for the |utf16|
//
// Returns: the font family or an empty string if the request could not be
// satisfied.
std::string GetFontFamilyForCharacters(const uint16_t* utf16,
// Returns: a font family instance.
// The instance has an empty font name if the request could not be satisfied.
void GetFontFamilyForCharacters(const uint16_t* utf16,
size_t num_utf16,
const char* preferred_locale);
const char* preferred_locale,
WebKit::WebFontFamily* family);
void GetRenderStyleForStrike(const char* family, int sizeAndStyle,
WebKit::WebFontRenderStyle* out);
......
......@@ -22,6 +22,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebSandboxSupport.h"
#elif defined(OS_POSIX)
#include "content/common/child_process_sandbox_support_impl_linux.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebFontFamily.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebSandboxSupport.h"
#endif
......@@ -41,10 +42,11 @@ class PpapiWebKitPlatformSupportImpl::SandboxSupport : public WebSandboxSupport
virtual bool loadFont(
NSFont* srcFont, CGFontRef* out, uint32_t* fontID);
#elif defined(OS_POSIX)
virtual WebString getFontFamilyForCharacters(
virtual void getFontFamilyForCharacters(
const WebUChar* characters,
size_t numCharacters,
const char* preferred_locale);
const char* preferred_locale,
WebKit::WebFontFamily* family);
virtual void getRenderStyleForStrike(
const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out);
......@@ -54,7 +56,7 @@ class PpapiWebKitPlatformSupportImpl::SandboxSupport : public WebSandboxSupport
// here. The key in this map is an array of 16-bit UTF16 values from WebKit.
// The value is a string containing the correct font family.
base::Lock unicode_font_families_mutex_;
std::map<string16, std::string> unicode_font_families_;
std::map<string16, WebKit::WebFontFamily> unicode_font_families_;
#endif
};
......@@ -83,24 +85,29 @@ bool PpapiWebKitPlatformSupportImpl::SandboxSupport::loadFont(
#elif defined(OS_POSIX)
WebString
void
PpapiWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacters(
const WebUChar* characters,
size_t num_characters,
const char* preferred_locale) {
const char* preferred_locale,
WebKit::WebFontFamily* family) {
base::AutoLock lock(unicode_font_families_mutex_);
const string16 key(characters, num_characters);
const std::map<string16, std::string>::const_iterator iter =
const std::map<string16, WebKit::WebFontFamily>::const_iterator iter =
unicode_font_families_.find(key);
if (iter != unicode_font_families_.end())
return WebString::fromUTF8(iter->second);
const std::string family_name = content::GetFontFamilyForCharacters(
if (iter != unicode_font_families_.end()) {
family->name = iter->second.name;
family->isBold = iter->second.isBold;
family->isItalic = iter->second.isItalic;
return;
}
content::GetFontFamilyForCharacters(
characters,
num_characters,
preferred_locale);
unicode_font_families_.insert(make_pair(key, family_name));
return WebString::fromUTF8(family_name);
preferred_locale,
family);
unicode_font_families_.insert(make_pair(key, *family));
}
void PpapiWebKitPlatformSupportImpl::SandboxSupport::getRenderStyleForStrike(
......
......@@ -63,6 +63,7 @@
#include "base/synchronization/lock.h"
#include "content/common/child_process_sandbox_support_impl_linux.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebFontFamily.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebSandboxSupport.h"
#endif
......@@ -121,10 +122,11 @@ class RendererWebKitPlatformSupportImpl::SandboxSupport
CGFontRef* container,
uint32* font_id);
#elif defined(OS_POSIX)
virtual WebKit::WebString getFontFamilyForCharacters(
virtual void getFontFamilyForCharacters(
const WebKit::WebUChar* characters,
size_t numCharacters,
const char* preferred_locale);
const char* preferred_locale,
WebKit::WebFontFamily* family);
virtual void getRenderStyleForStrike(
const char* family, int sizeAndStyle, WebKit::WebFontRenderStyle* out);
......@@ -134,7 +136,7 @@ class RendererWebKitPlatformSupportImpl::SandboxSupport
// here. The key in this map is an array of 16-bit UTF16 values from WebKit.
// The value is a string containing the correct font family.
base::Lock unicode_font_families_mutex_;
std::map<string16, std::string> unicode_font_families_;
std::map<string16, WebKit::WebFontFamily> unicode_font_families_;
#endif
};
......@@ -481,24 +483,29 @@ bool RendererWebKitPlatformSupportImpl::SandboxSupport::loadFont(
#elif defined(OS_POSIX)
WebString
void
RendererWebKitPlatformSupportImpl::SandboxSupport::getFontFamilyForCharacters(
const WebKit::WebUChar* characters,
size_t num_characters,
const char* preferred_locale) {
const char* preferred_locale,
WebKit::WebFontFamily* family) {
base::AutoLock lock(unicode_font_families_mutex_);
const string16 key(characters, num_characters);
const std::map<string16, std::string>::const_iterator iter =
const std::map<string16, WebKit::WebFontFamily>::const_iterator iter =
unicode_font_families_.find(key);
if (iter != unicode_font_families_.end())
return WebString::fromUTF8(iter->second);
if (iter != unicode_font_families_.end()) {
family->name = iter->second.name;
family->isBold = iter->second.isBold;
family->isItalic = iter->second.isItalic;
return;
}
const std::string family_name = content::GetFontFamilyForCharacters(
content::GetFontFamilyForCharacters(
characters,
num_characters,
preferred_locale);
unicode_font_families_.insert(make_pair(key, family_name));
return WebString::fromUTF8(family_name);
preferred_locale,
family);
unicode_font_families_.insert(make_pair(key, *family));
}
void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment