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

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

Issue 8910004: Optimize setting the font when drawing in RenderTextLinux. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years 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
« no previous file with comments | « ui/gfx/pango_util.h ('k') | ui/gfx/platform_font_pango.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/pango_util.h" 5 #include "ui/gfx/pango_util.h"
6 6
7 #include <cairo/cairo.h> 7 #include <cairo/cairo.h>
8 #include <pango/pango.h> 8 #include <pango/pango.h>
9 #include <pango/pangocairo.h> 9 #include <pango/pangocairo.h>
10 10
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 if (hint_style) 107 if (hint_style)
108 g_free(hint_style); 108 g_free(hint_style);
109 if (rgba_style) 109 if (rgba_style)
110 g_free(rgba_style); 110 g_free(rgba_style);
111 111
112 return cairo_font_options; 112 return cairo_font_options;
113 } 113 }
114 114
115 // Returns the number of pixels in a point.
116 // - multiply a point size by this to get pixels ("device units")
117 // - divide a pixel size by this to get points
118 float GetPixelsInPoint() {
119 static float pixels_in_point = 1.0;
120 static bool determined_value = false;
121
122 if (!determined_value) {
123 // http://goo.gl/UIh5m: "This is a scale factor between points specified in
124 // a PangoFontDescription and Cairo units. The default value is 96, meaning
125 // that a 10 point font will be 13 units high. (10 * 96. / 72. = 13.3)."
126 double pango_dpi = gfx::GetPangoResolution();
127 if (pango_dpi <= 0)
128 pango_dpi = 96.0;
129 pixels_in_point = pango_dpi / 72.0; // 72 points in an inch
130 determined_value = true;
131 }
132
133 return pixels_in_point;
134 }
135
115 } // namespace 136 } // namespace
116 137
117 namespace gfx { 138 namespace gfx {
118 139
119 void DrawTextOntoCairoSurface(cairo_t* cr, 140 void DrawTextOntoCairoSurface(cairo_t* cr,
120 const string16& text, 141 const string16& text,
121 const gfx::Font& font, 142 const gfx::Font& font,
122 const gfx::Rect& bounds, 143 const gfx::Rect& bounds,
123 const gfx::Rect& clip, 144 const gfx::Rect& clip,
124 const SkColor& text_color, 145 const SkColor& text_color,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 cr, platform_font->underline_thickness() + 2 * extra_edge_width); 339 cr, platform_font->underline_thickness() + 2 * extra_edge_width);
319 cairo_move_to(cr, 340 cairo_move_to(cr,
320 text_rect.x() - extra_edge_width, 341 text_rect.x() - extra_edge_width,
321 underline_y); 342 underline_y);
322 cairo_line_to(cr, 343 cairo_line_to(cr,
323 text_rect.x() + text_rect.width() + extra_edge_width, 344 text_rect.x() + text_rect.width() + extra_edge_width,
324 underline_y); 345 underline_y);
325 cairo_stroke(cr); 346 cairo_stroke(cr);
326 } 347 }
327 348
349 size_t GetPangoFontSizeInPixels(PangoFontDescription* pango_font) {
350 size_t size_in_pixels = pango_font_description_get_size(pango_font);
351 if (pango_font_description_get_size_is_absolute(pango_font)) {
352 // If the size is absolute, then it's in Pango units rather than points.
353 // There are PANGO_SCALE Pango units in a device unit (pixel).
354 size_in_pixels /= PANGO_SCALE;
355 } else {
356 // Otherwise, we need to convert from points.
357 size_in_pixels = size_in_pixels * GetPixelsInPoint() / PANGO_SCALE;
358 }
359 return size_in_pixels;
360 }
361
328 } // namespace gfx 362 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/pango_util.h ('k') | ui/gfx/platform_font_pango.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698