summaryrefslogtreecommitdiffstats
path: root/ui/gfx
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-24 21:01:24 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-24 21:01:24 +0000
commitf3dc6fbc4d1ae9591fb59bdcba591fec5a2e7187 (patch)
tree0fd4a953e5329d5f2d057c6de4563a1bde403ee5 /ui/gfx
parent9862082a9b4cf2affde748b230b2c2e0b3248d38 (diff)
downloadchromium_src-f3dc6fbc4d1ae9591fb59bdcba591fec5a2e7187.zip
chromium_src-f3dc6fbc4d1ae9591fb59bdcba591fec5a2e7187.tar.gz
chromium_src-f3dc6fbc4d1ae9591fb59bdcba591fec5a2e7187.tar.bz2
Add a SkiaTextRenderer::SetFontFamilyWithStyle
RenderTextLinux::DrawVisualText use it to stick with one font familty and avoid bad glyph index problem; BUG=119680 TEST=Verify fix for 119680 and other text should look the same as before. Review URL: https://chromiumcodereview.appspot.com/9808098 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128774 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r--ui/gfx/render_text.cc18
-rw-r--r--ui/gfx/render_text.h2
-rw-r--r--ui/gfx/render_text_linux.cc10
3 files changed, 24 insertions, 6 deletions
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 727af4a..d6bbc16 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -198,6 +198,24 @@ void SkiaTextRenderer::SetTextSize(int size) {
paint_.setTextSize(size);
}
+void SkiaTextRenderer::SetFontFamilyWithStyle(const std::string& family,
+ int style) {
+ DCHECK(!family.empty());
+
+ SkTypeface::Style skia_style = ConvertFontStyleToSkiaTypefaceStyle(style);
+ SkAutoTUnref<SkTypeface> typeface(
+ SkTypeface::CreateFromName(family.c_str(), skia_style));
+ if (typeface.get()) {
+ // |paint_| adds its own ref. So don't |release()| it from the ref ptr here.
+ SetTypeface(typeface.get());
+
+ // Enable fake bold text if bold style is needed but new typeface does not
+ // have it.
+ paint_.setFakeBoldText((skia_style & SkTypeface::kBold) &&
+ !typeface.get()->isBold());
+ }
+}
+
void SkiaTextRenderer::SetFontStyle(int style) {
SkTypeface::Style skia_style = ConvertFontStyleToSkiaTypefaceStyle(style);
SkTypeface* current_typeface = paint_.getTypeface();
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h
index d5ae4dd..1118e80 100644
--- a/ui/gfx/render_text.h
+++ b/ui/gfx/render_text.h
@@ -7,6 +7,7 @@
#pragma once
#include <algorithm>
+#include <string>
#include <vector>
#include "base/gtest_prod_util.h"
@@ -41,6 +42,7 @@ class SkiaTextRenderer {
void SetTypeface(SkTypeface* typeface);
void SetTextSize(int size);
void SetFont(const gfx::Font& font);
+ void SetFontFamilyWithStyle(const std::string& family, int font_style);
void SetFontStyle(int font_style);
void SetForegroundColor(SkColor foreground);
void SetShader(SkShader* shader);
diff --git a/ui/gfx/render_text_linux.cc b/ui/gfx/render_text_linux.cc
index 16bf386..f5c3a9b 100644
--- a/ui/gfx/render_text_linux.cc
+++ b/ui/gfx/render_text_linux.cc
@@ -410,10 +410,8 @@ void RenderTextLinux::DrawVisualText(Canvas* canvas) {
PangoFontDescription* native_font =
pango_font_describe(run->item->analysis.font);
- const char* family_name = pango_font_description_get_family(native_font);
- SkAutoTUnref<SkTypeface> typeface(
- SkTypeface::CreateFromName(family_name, SkTypeface::kNormal));
- renderer.SetTypeface(typeface.get());
+ const std::string family_name =
+ pango_font_description_get_family(native_font);
renderer.SetTextSize(GetPangoFontSizeInPixels(native_font));
pango_font_description_free(native_font);
@@ -443,7 +441,7 @@ void RenderTextLinux::DrawVisualText(Canvas* canvas) {
// styles evenly over the glyph. We can do this too by
// clipping and drawing the glyph several times.
renderer.SetForegroundColor(styles[style].foreground);
- renderer.SetFontStyle(styles[style].font_style);
+ renderer.SetFontFamilyWithStyle(family_name, styles[style].font_style);
renderer.DrawPosText(&pos[start], &glyphs[start], i - start);
renderer.DrawDecorations(start_x, y, glyph_x - start_x, styles[style]);
@@ -459,7 +457,7 @@ void RenderTextLinux::DrawVisualText(Canvas* canvas) {
// Draw the remaining glyphs.
renderer.SetForegroundColor(styles[style].foreground);
- renderer.SetFontStyle(styles[style].font_style);
+ renderer.SetFontFamilyWithStyle(family_name, styles[style].font_style);
renderer.DrawPosText(&pos[start], &glyphs[start], glyph_count - start);
renderer.DrawDecorations(start_x, y, glyph_x - start_x, styles[style]);
x = glyph_x;