summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-24 02:32:32 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-24 02:32:32 +0000
commitce1f48ec9ba4c877a8144b9734c478d9e0d0d951 (patch)
tree540bc526eb033c37a90e55e5d3461ae973a9b040 /skia
parente684a31a3733e0a3047c56c818a9cd42742b0ba4 (diff)
downloadchromium_src-ce1f48ec9ba4c877a8144b9734c478d9e0d0d951.zip
chromium_src-ce1f48ec9ba4c877a8144b9734c478d9e0d0d951.tar.gz
chromium_src-ce1f48ec9ba4c877a8144b9734c478d9e0d0d951.tar.bz2
Linux: fix fake italics for fonts without italic variants.
Before this patch we assumed that the style which we got from fontconfig was the one that we asked for. Rather than do this we need to query the resulting style and plumb that back into WebKit. Once WebKit knows that there's a mismatch between the request and actual styles it can trigger faking. BUG=14810 http://codereview.chromium.org/147005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19095 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/ext/SkFontHost_fontconfig.cpp15
-rw-r--r--skia/ext/SkFontHost_fontconfig_direct.cpp35
-rw-r--r--skia/ext/SkFontHost_fontconfig_direct.h2
-rw-r--r--skia/ext/SkFontHost_fontconfig_impl.h8
-rw-r--r--skia/ext/SkFontHost_fontconfig_ipc.cpp20
-rw-r--r--skia/ext/SkFontHost_fontconfig_ipc.h2
6 files changed, 53 insertions, 29 deletions
diff --git a/skia/ext/SkFontHost_fontconfig.cpp b/skia/ext/SkFontHost_fontconfig.cpp
index 04ac5b9d..2ecbe6c 100644
--- a/skia/ext/SkFontHost_fontconfig.cpp
+++ b/skia/ext/SkFontHost_fontconfig.cpp
@@ -101,7 +101,7 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
const unsigned fileid = UniqueIdToFileId(familyFace->uniqueID());
if (!GetFcImpl()->Match(
&resolved_family_name, NULL, true /* fileid valid */, fileid, "",
- -1, -1)) {
+ NULL, NULL)) {
return NULL;
}
} else if (familyName) {
@@ -110,16 +110,19 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
return NULL;
}
- const bool bold = style & SkTypeface::kBold;
- const bool italic = style & SkTypeface::kItalic;
+ bool bold = style & SkTypeface::kBold;
+ bool italic = style & SkTypeface::kItalic;
unsigned fileid;
if (!GetFcImpl()->Match(NULL, &fileid, false, -1, /* no fileid */
- resolved_family_name, bold, italic)) {
+ resolved_family_name, &bold, &italic)) {
return NULL;
}
+ const SkTypeface::Style resulting_style = static_cast<SkTypeface::Style>(
+ (bold ? SkTypeface::kBold : 0) |
+ (italic ? SkTypeface::kItalic : 0));
- const unsigned id = FileIdAndStyleToUniqueId(fileid, style);
- SkTypeface* typeface = SkNEW_ARGS(FontConfigTypeface, (style, id));
+ const unsigned id = FileIdAndStyleToUniqueId(fileid, resulting_style);
+ SkTypeface* typeface = SkNEW_ARGS(FontConfigTypeface, (resulting_style, id));
{
SkAutoMutexAcquire ac(global_fc_map_lock);
diff --git a/skia/ext/SkFontHost_fontconfig_direct.cpp b/skia/ext/SkFontHost_fontconfig_direct.cpp
index 5d425c2..dc20aff 100644
--- a/skia/ext/SkFontHost_fontconfig_direct.cpp
+++ b/skia/ext/SkFontHost_fontconfig_direct.cpp
@@ -43,8 +43,8 @@ static bool IsFallbackFontAllowed(const std::string& family)
bool FontConfigDirect::Match(std::string* result_family,
unsigned* result_fileid,
bool fileid_valid, unsigned fileid,
- const std::string& family, int is_bold,
- int is_italic) {
+ const std::string& family, bool* is_bold,
+ bool* is_italic) {
SkAutoMutexAcquire ac(mutex_);
FcPattern* pattern = FcPatternCreate();
@@ -66,16 +66,14 @@ bool FontConfigDirect::Match(std::string* result_family,
fcvalue.u.s = (FcChar8*) family.c_str();
FcPatternAdd(pattern, FC_FAMILY, fcvalue, 0);
}
- if (is_bold > 0) {
- fcvalue.type = FcTypeInteger;
- fcvalue.u.i = is_bold ? FC_WEIGHT_BOLD : FC_WEIGHT_NORMAL;
- FcPatternAdd(pattern, FC_WEIGHT, fcvalue, 0);
- }
- if (is_italic > 0) {
- fcvalue.type = FcTypeInteger;
- fcvalue.u.i = is_italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN;
- FcPatternAdd(pattern, FC_SLANT, fcvalue, 0);
- }
+
+ fcvalue.type = FcTypeInteger;
+ fcvalue.u.i = is_bold && *is_bold ? FC_WEIGHT_BOLD : FC_WEIGHT_NORMAL;
+ FcPatternAdd(pattern, FC_WEIGHT, fcvalue, 0);
+
+ fcvalue.type = FcTypeInteger;
+ fcvalue.u.i = is_italic && *is_italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN;
+ FcPatternAdd(pattern, FC_SLANT, fcvalue, 0);
FcConfigSubstitute(0, pattern, FcMatchPattern);
FcDefaultSubstitute(pattern);
@@ -173,6 +171,19 @@ bool FontConfigDirect::Match(std::string* result_family,
return NULL;
}
+ int resulting_bold;
+ if (FcPatternGetInteger(match, FC_WEIGHT, 0, &resulting_bold))
+ resulting_bold = FC_WEIGHT_NORMAL;
+
+ int resulting_italic;
+ if (FcPatternGetInteger(match, FC_SLANT, 0, &resulting_italic))
+ resulting_italic = FC_SLANT_ROMAN;
+
+ if (is_bold)
+ *is_bold = resulting_bold >= FC_WEIGHT_BOLD;
+ if (is_italic)
+ *is_italic = resulting_italic == FC_SLANT_ITALIC;
+
if (result_family)
*result_family = (char *) c_family;
diff --git a/skia/ext/SkFontHost_fontconfig_direct.h b/skia/ext/SkFontHost_fontconfig_direct.h
index d9c934a..56bea34 100644
--- a/skia/ext/SkFontHost_fontconfig_direct.h
+++ b/skia/ext/SkFontHost_fontconfig_direct.h
@@ -31,7 +31,7 @@ class FontConfigDirect : public FontConfigInterface {
// FontConfigInterface implementation. Thread safe.
virtual bool Match(std::string* result_family, unsigned* result_fileid,
bool fileid_valid, unsigned fileid,
- const std::string& family, int is_bold, int is_italic);
+ const std::string& family, bool* is_bold, bool* is_italic);
virtual int Open(unsigned fileid);
private:
diff --git a/skia/ext/SkFontHost_fontconfig_impl.h b/skia/ext/SkFontHost_fontconfig_impl.h
index a593891..f3b4b41 100644
--- a/skia/ext/SkFontHost_fontconfig_impl.h
+++ b/skia/ext/SkFontHost_fontconfig_impl.h
@@ -39,8 +39,8 @@ class FontConfigInterface {
* trying to match.
* @param family (optional) the family of the font that we are trying to
* match.
- * @param is_bold (optional, set to -1 to ignore)
- * @param is_italic (optional, set to -1 to ignore)
+ * @param is_bold (optional, set to NULL to ignore, in/out)
+ * @param is_italic (optional, set to NULL to ignore, in/out)
* @return true iff successful.
*/
virtual bool Match(
@@ -49,8 +49,8 @@ class FontConfigInterface {
bool fileid_valid,
unsigned fileid,
const std::string& family,
- int is_bold,
- int is_italic) = 0;
+ bool* is_bold,
+ bool* is_italic) = 0;
/** Open a font file given the fileid as returned by Match
*/
diff --git a/skia/ext/SkFontHost_fontconfig_ipc.cpp b/skia/ext/SkFontHost_fontconfig_ipc.cpp
index e3868f4..ada7bc9 100644
--- a/skia/ext/SkFontHost_fontconfig_ipc.cpp
+++ b/skia/ext/SkFontHost_fontconfig_ipc.cpp
@@ -39,15 +39,17 @@ FontConfigIPC::~FontConfigIPC() {
bool FontConfigIPC::Match(std::string* result_family,
unsigned* result_fileid,
bool fileid_valid, unsigned fileid,
- const std::string& family, int is_bold,
- int is_italic) {
+ const std::string& family, bool* is_bold,
+ bool* is_italic) {
Pickle request;
request.WriteInt(METHOD_MATCH);
request.WriteBool(fileid_valid);
if (fileid_valid)
request.WriteUInt32(fileid);
- request.WriteBool(is_bold);
- request.WriteBool(is_italic);
+
+ request.WriteBool(is_bold && *is_bold);
+ request.WriteBool(is_bold && *is_italic);
+
request.WriteString(family);
uint8_t reply_buf[512];
@@ -66,8 +68,11 @@ bool FontConfigIPC::Match(std::string* result_family,
uint32_t reply_fileid;
std::string reply_family;
+ bool resulting_bold, resulting_italic;
if (!reply.ReadUInt32(&iter, &reply_fileid) ||
- !reply.ReadString(&iter, &reply_family)) {
+ !reply.ReadString(&iter, &reply_family) ||
+ !reply.ReadBool(&iter, &resulting_bold) ||
+ !reply.ReadBool(&iter, &resulting_italic)) {
return false;
}
@@ -75,6 +80,11 @@ bool FontConfigIPC::Match(std::string* result_family,
if (result_family)
*result_family = reply_family;
+ if (is_bold)
+ *is_bold = resulting_bold;
+ if (is_italic)
+ *is_italic = resulting_italic;
+
return true;
}
diff --git a/skia/ext/SkFontHost_fontconfig_ipc.h b/skia/ext/SkFontHost_fontconfig_ipc.h
index 9965cb6..30a32e1 100644
--- a/skia/ext/SkFontHost_fontconfig_ipc.h
+++ b/skia/ext/SkFontHost_fontconfig_ipc.h
@@ -33,7 +33,7 @@ class FontConfigIPC : public FontConfigInterface {
// FontConfigInterface implementation.
virtual bool Match(std::string* result_family, unsigned* result_fileid,
bool fileid_valid, unsigned fileid,
- const std::string& family, int is_bold, int is_italic);
+ const std::string& family, bool* is_bold, bool* is_italic);
virtual int Open(unsigned fileid);
enum Method {