summaryrefslogtreecommitdiff
path: root/chromium/third_party/WebKit/Source/platform/fonts/linux/FontRenderStyle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/platform/fonts/linux/FontRenderStyle.cpp')
-rw-r--r--chromium/third_party/WebKit/Source/platform/fonts/linux/FontRenderStyle.cpp65
1 files changed, 59 insertions, 6 deletions
diff --git a/chromium/third_party/WebKit/Source/platform/fonts/linux/FontRenderStyle.cpp b/chromium/third_party/WebKit/Source/platform/fonts/linux/FontRenderStyle.cpp
index 658bc846597..d9dbd283aaf 100644
--- a/chromium/third_party/WebKit/Source/platform/fonts/linux/FontRenderStyle.cpp
+++ b/chromium/third_party/WebKit/Source/platform/fonts/linux/FontRenderStyle.cpp
@@ -11,10 +11,43 @@
#include "public/platform/linux/WebFontRenderStyle.h"
#include "public/platform/linux/WebSandboxSupport.h"
+#include "ui/gfx/font_render_params.h"
+#include "ui/gfx/font.h"
+
namespace blink {
namespace {
+// These functions are also implemented in sandbox_ipc_linux.cc
+// Converts gfx::FontRenderParams::Hinting to WebFontRenderStyle::hintStyle.
+// Returns an int for serialization, but the underlying Blink type is a char.
+int ConvertHinting(gfx::FontRenderParams::Hinting hinting) {
+ switch (hinting) {
+ case gfx::FontRenderParams::HINTING_NONE: return 0;
+ case gfx::FontRenderParams::HINTING_SLIGHT: return 1;
+ case gfx::FontRenderParams::HINTING_MEDIUM: return 2;
+ case gfx::FontRenderParams::HINTING_FULL: return 3;
+ }
+ NOTREACHED() << "Unexpected hinting value " << hinting;
+ return 0;
+}
+
+// Converts gfx::FontRenderParams::SubpixelRendering to
+// WebFontRenderStyle::useSubpixelRendering. Returns an int for serialization,
+// but the underlying Blink type is a char.
+int ConvertSubpixelRendering(
+ gfx::FontRenderParams::SubpixelRendering rendering) {
+ switch (rendering) {
+ case gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE: return 0;
+ case gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB: return 1;
+ case gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR: return 1;
+ case gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB: return 1;
+ case gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR: return 1;
+ }
+ NOTREACHED() << "Unexpected subpixel rendering value " << rendering;
+ return 0;
+}
+
SkPaint::Hinting g_skia_hinting = SkPaint::kNormal_Hinting;
bool g_use_skia_auto_hint = true;
bool g_use_skia_bitmaps = true;
@@ -56,10 +89,30 @@ FontRenderStyle FontRenderStyle::QuerySystem(const CString& family,
#if defined(OS_ANDROID)
style.SetDefaults();
#else
- // If the font name is missing (i.e. probably a web font) or the sandbox is
- // disabled, use the system defaults.
- if (!family.length() || !Platform::Current()->GetSandboxSupport()) {
- style.SetDefaults();
+ // If the the sandbox is disabled, we can query font parameters directly.
+ if (!Platform::Current()->GetSandboxSupport()) {
+ gfx::FontRenderParamsQuery query;
+ if (family.length())
+ query.families.push_back(family.data());
+ query.pixel_size = text_size;
+ switch (font_style.slant()) {
+ case SkFontStyle::kUpright_Slant:
+ query.style = gfx::Font::NORMAL;
+ break;
+ case SkFontStyle::kItalic_Slant:
+ case SkFontStyle::kOblique_Slant:
+ query.style = gfx::Font::ITALIC;
+ break;
+ }
+ query.weight = (gfx::Font::Weight)font_style.weight();
+ const gfx::FontRenderParams params = gfx::GetFontRenderParams(query, NULL);
+ style.use_bitmaps = params.use_bitmaps;
+ style.use_auto_hint = params.autohinter;
+ style.use_hinting = params.hinting != gfx::FontRenderParams::HINTING_NONE;
+ style.hint_style = ConvertHinting(params.hinting);
+ style.use_anti_alias = params.antialiasing;
+ style.use_subpixel_rendering = ConvertSubpixelRendering(params.subpixel_rendering);
+ style.use_subpixel_positioning = params.subpixel_positioning;
} else {
bool is_bold = font_style.weight() >= SkFontStyle::kSemiBold_Weight;
bool is_italic = font_style.slant() != SkFontStyle::kUpright_Slant;
@@ -108,8 +161,8 @@ void FontRenderStyle::ApplyToPaint(SkPaint& paint,
if (use_anti_alias)
paint.setLCDRenderText(use_subpixel_rendering);
- // Do not enable subpixel text on low-dpi if full hinting is requested.
- bool use_subpixel_text = (paint.getHinting() != SkPaint::kFull_Hinting ||
+ // Do not enable subpixel text on low-dpi if normal or full hinting is requested.
+ bool use_subpixel_text = (paint.getHinting() < SkPaint::kNormal_Hinting ||
device_scale_factor > 1.0f);
// TestRunner specifically toggles the subpixel positioning flag.