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

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

Issue 509093004: linux: Make RenderTextPango avoid clipping underlines. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « ui/gfx/platform_font_pango.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_pango.h" 5 #include "ui/gfx/render_text_pango.h"
6 6
7 #include <pango/pangocairo.h> 7 #include <pango/pangocairo.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 // Sets underline metrics on |renderer| according to Pango font |desc|. 50 // Sets underline metrics on |renderer| according to Pango font |desc|.
51 void SetPangoUnderlineMetrics(PangoFontDescription *desc, 51 void SetPangoUnderlineMetrics(PangoFontDescription *desc,
52 internal::SkiaTextRenderer* renderer) { 52 internal::SkiaTextRenderer* renderer) {
53 PangoFontMetrics* metrics = GetPangoFontMetrics(desc); 53 PangoFontMetrics* metrics = GetPangoFontMetrics(desc);
54 int thickness = pango_font_metrics_get_underline_thickness(metrics); 54 int thickness = pango_font_metrics_get_underline_thickness(metrics);
55 // Pango returns the position "above the baseline". Change its sign to convert 55 // Pango returns the position "above the baseline". Change its sign to convert
56 // it to a vertical offset from the baseline. 56 // it to a vertical offset from the baseline.
57 int position = -pango_font_metrics_get_underline_position(metrics); 57 int position = -pango_font_metrics_get_underline_position(metrics);
58 pango_quantize_line_geometry(&thickness, &position); 58
59 // Note: pango_quantize_line_geometry() guarantees pixel boundaries, so 59 // Note: pango_quantize_line_geometry() guarantees pixel boundaries, so
60 // PANGO_PIXELS() is safe to use. 60 // PANGO_PIXELS() is safe to use.
61 renderer->SetUnderlineMetrics(PANGO_PIXELS(thickness), 61 pango_quantize_line_geometry(&thickness, &position);
62 PANGO_PIXELS(position)); 62 int thickness_pixels = PANGO_PIXELS(thickness);
63 int position_pixels = PANGO_PIXELS(position);
64
65 // Ugly hack: make sure that underlines don't get clipped. See
66 // http://crbug.com/393117.
67 int descent_pixels = PANGO_PIXELS(pango_font_metrics_get_descent(metrics));
Daniel Erat 2014/08/28 20:37:23 it's also possible that this isn't the right fix a
msw 2014/08/29 00:41:55 I honestly don't know the Pango underline code tha
68 position_pixels = std::min(position_pixels,
69 descent_pixels - thickness_pixels);
70
71 renderer->SetUnderlineMetrics(thickness_pixels, position_pixels);
63 } 72 }
64 73
65 } // namespace 74 } // namespace
66 75
67 // TODO(xji): index saved in upper layer is utf16 index. Pango uses utf8 index. 76 // TODO(xji): index saved in upper layer is utf16 index. Pango uses utf8 index.
68 // Since caret_pos is used internally, we could save utf8 index for caret_pos 77 // Since caret_pos is used internally, we could save utf8 index for caret_pos
69 // to avoid conversion. 78 // to avoid conversion.
70 79
71 RenderTextPango::RenderTextPango() 80 RenderTextPango::RenderTextPango()
72 : layout_(NULL), 81 : layout_(NULL),
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 int glyph_index) const { 512 int glyph_index) const {
504 return LayoutIndexToTextIndex(run->item->offset + 513 return LayoutIndexToTextIndex(run->item->offset +
505 run->glyphs->log_clusters[glyph_index]); 514 run->glyphs->log_clusters[glyph_index]);
506 } 515 }
507 516
508 RenderText* RenderText::CreateNativeInstance() { 517 RenderText* RenderText::CreateNativeInstance() {
509 return new RenderTextPango; 518 return new RenderTextPango;
510 } 519 }
511 520
512 } // namespace gfx 521 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/platform_font_pango.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698