summaryrefslogtreecommitdiffstats
path: root/ui/gfx/render_text_linux.cc
diff options
context:
space:
mode:
authorasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-09 23:05:30 +0000
committerasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-09 23:05:30 +0000
commitab96da42340f2828d7bce6ac2510b2ad5fa29ab2 (patch)
tree3e50e0eb02089b495e5715148d50405bd7ea1240 /ui/gfx/render_text_linux.cc
parent60b122deac5637b413268a9b67eb89e0cac1e135 (diff)
downloadchromium_src-ab96da42340f2828d7bce6ac2510b2ad5fa29ab2.zip
chromium_src-ab96da42340f2828d7bce6ac2510b2ad5fa29ab2.tar.gz
chromium_src-ab96da42340f2828d7bce6ac2510b2ad5fa29ab2.tar.bz2
Enable bold and italic text styles in RenderText*.
To do this, the following changes were made: Added functions GetStyle() and DeriveFontList(style) to FontList. Changed font list to use strings "Bold" and "Italic" instead of PANGO_STYLE_ITALIC and PANGO_WEIGHT_BOLD - where were actually compile constants for setting attributes and weren't recognized by Pango in a font string. (Whereas "Bold" and "Italic" are recognized). Add RenderText test that checks that the width of a bold string > the width of a non-bold string. Add FontList tests for the new functions. BUG=107893 TEST=Run views_examples_exe "Text Styles" examples and try bold and italic styles (this depends on an unreleased CL). Also, new tests in FontListTest and RenderTextTest. Review URL: http://codereview.chromium.org/8963027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116945 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/render_text_linux.cc')
-rw-r--r--ui/gfx/render_text_linux.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/ui/gfx/render_text_linux.cc b/ui/gfx/render_text_linux.cc
index 4ebac11..a51bbef 100644
--- a/ui/gfx/render_text_linux.cc
+++ b/ui/gfx/render_text_linux.cc
@@ -258,6 +258,7 @@ void RenderTextLinux::EnsureLayout() {
// TODO(xji): If RenderText will be used for displaying purpose, such as
// label, we will need to remove the single-line-mode setting.
pango_layout_set_single_paragraph_mode(layout_, true);
+ SetupPangoAttributes(layout_);
current_line_ = pango_layout_get_line_readonly(layout_, 0);
pango_layout_line_ref(current_line_);
@@ -269,6 +270,35 @@ void RenderTextLinux::EnsureLayout() {
}
}
+void RenderTextLinux::SetupPangoAttributes(PangoLayout* layout) {
+ PangoAttrList* attrs = pango_attr_list_new();
+
+ int default_font_style = font_list().GetStyle();
+ for (StyleRanges::const_iterator i = style_ranges().begin();
+ i < style_ranges().end(); ++i) {
+ // In Pango, different fonts means different runs, and it breaks Arabic
+ // shaping across run boundaries. So, set font only when it is different
+ // from the default font.
+ // TODO(xji): We'll eventually need to split up StyleRange into components
+ // (ColorRange, FontRange, etc.) so that we can combine adjacent ranges
+ // with the same Fonts (to avoid unnecessarily splitting up runs).
+ if (i->font_style != default_font_style) {
+ FontList derived_font_list = font_list().DeriveFontList(i->font_style);
+ PangoFontDescription* desc = pango_font_description_from_string(
+ derived_font_list.GetFontDescriptionString().c_str());
+
+ PangoAttribute* pango_attr = pango_attr_font_desc_new(desc);
+ pango_attr->start_index = Utf16IndexToUtf8Index(i->range.start());
+ pango_attr->end_index = Utf16IndexToUtf8Index(i->range.end());
+ pango_attr_list_insert(attrs, pango_attr);
+ pango_font_description_free(desc);
+ }
+ }
+
+ pango_layout_set_attributes(layout, attrs);
+ pango_attr_list_unref(attrs);
+}
+
void RenderTextLinux::DrawVisualText(Canvas* canvas) {
TRACE_EVENT0("gfx", "RenderTextLinux::DrawVisualText");
DCHECK(layout_);
@@ -353,6 +383,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.DrawPosText(&pos[start], &glyphs[start], i - start);
if (styles[style].underline || styles[style].strike) {
renderer.DrawDecorations(start_x, y, glyph_x - start_x,
@@ -372,6 +403,7 @@ void RenderTextLinux::DrawVisualText(Canvas* canvas) {
// Draw the remaining glyphs.
renderer.SetForegroundColor(styles[style].foreground);
+ renderer.SetFontStyle(styles[style].font_style);
renderer.DrawPosText(&pos[start], &glyphs[start], glyph_count - start);
if (styles[style].underline || styles[style].strike) {
renderer.DrawDecorations(start_x, y, glyph_x - start_x,