summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ui/gfx/render_text.cc18
-rw-r--r--ui/gfx/render_text.h5
-rw-r--r--ui/gfx/render_text_harfbuzz.cc29
-rw-r--r--ui/gfx/render_text_harfbuzz.h1
4 files changed, 38 insertions, 15 deletions
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index e7144f8..19bb69b 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -213,12 +213,7 @@ void SkiaTextRenderer::SetDrawLooper(SkDrawLooper* draw_looper) {
void SkiaTextRenderer::SetFontRenderParams(const FontRenderParams& params,
bool background_is_transparent) {
- paint_.setAntiAlias(params.antialiasing);
- paint_.setLCDRenderText(!background_is_transparent &&
- params.subpixel_rendering != FontRenderParams::SUBPIXEL_RENDERING_NONE);
- paint_.setSubpixelText(params.subpixel_positioning);
- paint_.setAutohinted(params.autohinter);
- paint_.setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting));
+ ApplyRenderParams(params, background_is_transparent, &paint_);
}
void SkiaTextRenderer::SetTypeface(SkTypeface* typeface) {
@@ -416,6 +411,17 @@ skia::RefPtr<SkTypeface> CreateSkiaTypeface(const std::string& family,
return skia::AdoptRef(SkTypeface::CreateFromName(family.c_str(), skia_style));
}
+void ApplyRenderParams(const FontRenderParams& params,
+ bool background_is_transparent,
+ SkPaint* paint) {
+ paint->setAntiAlias(params.antialiasing);
+ paint->setLCDRenderText(!background_is_transparent &&
+ params.subpixel_rendering != FontRenderParams::SUBPIXEL_RENDERING_NONE);
+ paint->setSubpixelText(params.subpixel_positioning);
+ paint->setAutohinted(params.autohinter);
+ paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting));
+}
+
} // namespace internal
RenderText::~RenderText() {
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h
index 80055b0..6a79c4a 100644
--- a/ui/gfx/render_text.h
+++ b/ui/gfx/render_text.h
@@ -178,6 +178,11 @@ struct Line {
skia::RefPtr<SkTypeface> CreateSkiaTypeface(const std::string& family,
int style);
+// Applies the given FontRenderParams to a Skia |paint|.
+void ApplyRenderParams(const FontRenderParams& params,
+ bool background_is_transparent,
+ SkPaint* paint);
+
} // namespace internal
// RenderText represents an abstract model of styled text and its corresponding
diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc
index 01f75e3..a8f6f24 100644
--- a/ui/gfx/render_text_harfbuzz.cc
+++ b/ui/gfx/render_text_harfbuzz.cc
@@ -269,7 +269,10 @@ class HarfBuzzFace {
};
// Creates a HarfBuzz font from the given Skia face and text size.
-hb_font_t* CreateHarfBuzzFont(SkTypeface* skia_face, int text_size) {
+hb_font_t* CreateHarfBuzzFont(SkTypeface* skia_face,
+ int text_size,
+ const FontRenderParams& params,
+ bool background_is_transparent) {
typedef std::pair<HarfBuzzFace, GlyphCache> FaceCache;
// TODO(ckocagil): This shouldn't grow indefinitely. Maybe use base::MRUCache?
@@ -285,6 +288,9 @@ hb_font_t* CreateHarfBuzzFont(SkTypeface* skia_face, int text_size) {
FontData* hb_font_data = new FontData(&face_cache->second);
hb_font_data->paint_.setTypeface(skia_face);
hb_font_data->paint_.setTextSize(text_size);
+ // TODO(ckocagil): Do we need to update these params later?
+ internal::ApplyRenderParams(params, background_is_transparent,
+ &hb_font_data->paint_);
hb_font_set_funcs(harfbuzz_font, g_font_funcs.Get().get(), hb_font_data,
DeleteByType<FontData>);
hb_font_make_immutable(harfbuzz_font);
@@ -871,13 +877,6 @@ void RenderTextHarfBuzz::DrawVisualText(Canvas* canvas) {
internal::SkiaTextRenderer renderer(canvas);
ApplyFadeEffects(&renderer);
ApplyTextShadows(&renderer);
-
-#if defined(OS_WIN) || defined(OS_LINUX)
- renderer.SetFontRenderParams(
- font_list().GetPrimaryFont().GetFontRenderParams(),
- background_is_transparent());
-#endif
-
ApplyCompositionAndSelectionStyles();
int current_x = 0;
@@ -886,6 +885,10 @@ void RenderTextHarfBuzz::DrawVisualText(Canvas* canvas) {
const internal::TextRunHarfBuzz& run = *runs_[visual_to_logical_[i]];
renderer.SetTypeface(run.skia_face.get());
renderer.SetTextSize(run.font_size);
+#if defined(OS_WIN) || defined(OS_LINUX)
+ renderer.SetFontRenderParams(run.render_params,
+ background_is_transparent());
+#endif
Vector2d origin = line_offset + Vector2d(current_x, lines()[0].baseline);
scoped_ptr<SkPoint[]> positions(new SkPoint[run.glyph_count]);
@@ -1113,8 +1116,13 @@ bool RenderTextHarfBuzz::ShapeRunWithFont(internal::TextRunHarfBuzz* run,
if (skia_face == NULL)
return false;
run->skia_face = skia_face;
+ FontRenderParamsQuery query(false);
+ query.families.push_back(font_family);
+ query.pixel_size = run->font_size;
+ query.style = run->font_style;
+ run->render_params = GetFontRenderParams(query, NULL);
hb_font_t* harfbuzz_font = CreateHarfBuzzFont(run->skia_face.get(),
- run->font_size);
+ run->font_size, run->render_params, background_is_transparent());
// Create a HarfBuzz buffer and add the string to be shaped. The HarfBuzz
// buffer holds our text, run information to be used by the shaping engine,
@@ -1148,6 +1156,9 @@ bool RenderTextHarfBuzz::ShapeRunWithFont(internal::TextRunHarfBuzz* run,
const int y_offset = SkFixedToScalar(hb_positions[i].y_offset);
run->positions[i].set(run->width + x_offset, -y_offset);
run->width += SkFixedToScalar(hb_positions[i].x_advance);
+ // If subpixel positioning isn't enabled, round the glyph x coordinates.
+ if (!run->render_params.subpixel_positioning)
+ run->width = std::floor(run->width + 0.5f);
}
hb_buffer_destroy(buffer);
diff --git a/ui/gfx/render_text_harfbuzz.h b/ui/gfx/render_text_harfbuzz.h
index e84ca48..8936e53 100644
--- a/ui/gfx/render_text_harfbuzz.h
+++ b/ui/gfx/render_text_harfbuzz.h
@@ -61,6 +61,7 @@ struct GFX_EXPORT TextRunHarfBuzz {
size_t glyph_count;
skia::RefPtr<SkTypeface> skia_face;
+ FontRenderParams render_params;
int font_size;
int font_style;
bool strike;