Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: ui/gfx/render_text_linux.cc

Issue 10520017: Use pango underline metrics in RenderTextLinux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« ui/gfx/render_text.cc ('K') | « ui/gfx/render_text.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/render_text_linux.h" 5 #include "ui/gfx/render_text_linux.h"
6 6
7 #include <fontconfig/fontconfig.h> 7 #include <fontconfig/fontconfig.h>
8 #include <pango/pangocairo.h> 8 #include <pango/pangocairo.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 int fc_rgba = FC_RGBA_RGB; 63 int fc_rgba = FC_RGBA_RGB;
64 FcPatternGetInteger(match, FC_RGBA, 0, &fc_rgba); 64 FcPatternGetInteger(match, FC_RGBA, 0, &fc_rgba);
65 FcPatternDestroy(pattern); 65 FcPatternDestroy(pattern);
66 FcPatternDestroy(match); 66 FcPatternDestroy(match);
67 67
68 already_queried = true; 68 already_queried = true;
69 subpixel_enabled = (fc_rgba != FC_RGBA_NONE); 69 subpixel_enabled = (fc_rgba != FC_RGBA_NONE);
70 return subpixel_enabled; 70 return subpixel_enabled;
71 } 71 }
72 72
73 // Sets underline metrics on |renderer| according to Pango font |desc|.
74 void SetPangoUnderlineMetrics(PangoFontDescription *desc,
75 internal::SkiaTextRenderer* renderer) {
76 PangoFontMetrics* metrics = GetPangoFontMetrics(desc);
77 const int underline_thickness =
msw 2012/06/06 01:12:51 nit: nix "underline_" from the names to fit each o
Alexei Svitkine (slow) 2012/06/06 14:46:27 Done.
78 pango_font_metrics_get_underline_thickness(metrics);
79 const int underline_position =
80 pango_font_metrics_get_underline_position(metrics);
81 renderer->SetUnderlineMetrics(pango_units_to_double(underline_thickness),
82 pango_units_to_double(underline_position));
83 }
84
73 } // namespace 85 } // namespace
74 86
75 // TODO(xji): index saved in upper layer is utf16 index. Pango uses utf8 index. 87 // TODO(xji): index saved in upper layer is utf16 index. Pango uses utf8 index.
76 // Since caret_pos is used internally, we could save utf8 index for caret_pos 88 // Since caret_pos is used internally, we could save utf8 index for caret_pos
77 // to avoid conversion. 89 // to avoid conversion.
78 90
79 RenderTextLinux::RenderTextLinux() 91 RenderTextLinux::RenderTextLinux()
80 : layout_(NULL), 92 : layout_(NULL),
81 current_line_(NULL), 93 current_line_(NULL),
82 log_attrs_(NULL), 94 log_attrs_(NULL),
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 DCHECK_GE(style, 0); 450 DCHECK_GE(style, 0);
439 DCHECK_LT(style, static_cast<int>(styles.size())); 451 DCHECK_LT(style, static_cast<int>(styles.size()));
440 if (!IndexInRange(style_ranges_utf8[style], glyph_byte_index)) { 452 if (!IndexInRange(style_ranges_utf8[style], glyph_byte_index)) {
441 // TODO(asvitkine): For cases like "fi", where "fi" is a single glyph 453 // TODO(asvitkine): For cases like "fi", where "fi" is a single glyph
442 // but can span multiple styles, Pango splits the 454 // but can span multiple styles, Pango splits the
443 // styles evenly over the glyph. We can do this too by 455 // styles evenly over the glyph. We can do this too by
444 // clipping and drawing the glyph several times. 456 // clipping and drawing the glyph several times.
445 renderer.SetForegroundColor(styles[style].foreground); 457 renderer.SetForegroundColor(styles[style].foreground);
446 renderer.SetFontFamilyWithStyle(family_name, styles[style].font_style); 458 renderer.SetFontFamilyWithStyle(family_name, styles[style].font_style);
447 renderer.DrawPosText(&pos[start], &glyphs[start], i - start); 459 renderer.DrawPosText(&pos[start], &glyphs[start], i - start);
460 if (styles[style].underline)
461 SetPangoUnderlineMetrics(desc.get(), &renderer);
448 renderer.DrawDecorations(start_x, y, glyph_x - start_x, styles[style]); 462 renderer.DrawDecorations(start_x, y, glyph_x - start_x, styles[style]);
449 463
450 start = i; 464 start = i;
451 start_x = glyph_x; 465 start_x = glyph_x;
452 // Loop to find the next style, in case the glyph spans multiple styles. 466 // Loop to find the next style, in case the glyph spans multiple styles.
453 do { 467 do {
454 style += style_increment; 468 style += style_increment;
455 } while (style >= 0 && style < static_cast<int>(styles.size()) && 469 } while (style >= 0 && style < static_cast<int>(styles.size()) &&
456 !IndexInRange(style_ranges_utf8[style], glyph_byte_index)); 470 !IndexInRange(style_ranges_utf8[style], glyph_byte_index));
457 } 471 }
458 } 472 }
459 473
460 // Draw the remaining glyphs. 474 // Draw the remaining glyphs.
461 renderer.SetForegroundColor(styles[style].foreground); 475 renderer.SetForegroundColor(styles[style].foreground);
462 renderer.SetFontFamilyWithStyle(family_name, styles[style].font_style); 476 renderer.SetFontFamilyWithStyle(family_name, styles[style].font_style);
463 renderer.DrawPosText(&pos[start], &glyphs[start], glyph_count - start); 477 renderer.DrawPosText(&pos[start], &glyphs[start], glyph_count - start);
478 if (styles[style].underline)
479 SetPangoUnderlineMetrics(desc.get(), &renderer);
464 renderer.DrawDecorations(start_x, y, glyph_x - start_x, styles[style]); 480 renderer.DrawDecorations(start_x, y, glyph_x - start_x, styles[style]);
465 x = glyph_x; 481 x = glyph_x;
466 } 482 }
467 } 483 }
468 484
469 GSList* RenderTextLinux::GetRunContainingCaret( 485 GSList* RenderTextLinux::GetRunContainingCaret(
470 const SelectionModel& caret) const { 486 const SelectionModel& caret) const {
471 size_t position = TextIndexToLayoutIndex(caret.caret_pos()); 487 size_t position = TextIndexToLayoutIndex(caret.caret_pos());
472 LogicalCursorDirection affinity = caret.caret_affinity(); 488 LogicalCursorDirection affinity = caret.caret_affinity();
473 GSList* run = current_line_->runs; 489 GSList* run = current_line_->runs;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 return bounds; 557 return bounds;
542 } 558 }
543 559
544 std::vector<Rect> RenderTextLinux::GetSelectionBounds() { 560 std::vector<Rect> RenderTextLinux::GetSelectionBounds() {
545 if (selection_visual_bounds_.empty()) 561 if (selection_visual_bounds_.empty())
546 selection_visual_bounds_ = CalculateSubstringBounds(selection()); 562 selection_visual_bounds_ = CalculateSubstringBounds(selection());
547 return selection_visual_bounds_; 563 return selection_visual_bounds_;
548 } 564 }
549 565
550 } // namespace gfx 566 } // namespace gfx
OLDNEW
« ui/gfx/render_text.cc ('K') | « ui/gfx/render_text.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698