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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/pango_util.h ('k') | ui/gfx/platform_font_pango.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/pango_util.cc
===================================================================
--- ui/gfx/pango_util.cc (revision 114424)
+++ ui/gfx/pango_util.cc (working copy)
@@ -112,6 +112,27 @@
return cairo_font_options;
}
+// Returns the number of pixels in a point.
+// - multiply a point size by this to get pixels ("device units")
+// - divide a pixel size by this to get points
+float GetPixelsInPoint() {
+ static float pixels_in_point = 1.0;
+ static bool determined_value = false;
+
+ if (!determined_value) {
+ // http://goo.gl/UIh5m: "This is a scale factor between points specified in
+ // a PangoFontDescription and Cairo units. The default value is 96, meaning
+ // that a 10 point font will be 13 units high. (10 * 96. / 72. = 13.3)."
+ double pango_dpi = gfx::GetPangoResolution();
+ if (pango_dpi <= 0)
+ pango_dpi = 96.0;
+ pixels_in_point = pango_dpi / 72.0; // 72 points in an inch
+ determined_value = true;
+ }
+
+ return pixels_in_point;
+}
+
} // namespace
namespace gfx {
@@ -325,4 +346,17 @@
cairo_stroke(cr);
}
+size_t GetPangoFontSizeInPixels(PangoFontDescription* pango_font) {
+ size_t size_in_pixels = pango_font_description_get_size(pango_font);
+ if (pango_font_description_get_size_is_absolute(pango_font)) {
+ // If the size is absolute, then it's in Pango units rather than points.
+ // There are PANGO_SCALE Pango units in a device unit (pixel).
+ size_in_pixels /= PANGO_SCALE;
+ } else {
+ // Otherwise, we need to convert from points.
+ size_in_pixels = size_in_pixels * GetPixelsInPoint() / PANGO_SCALE;
+ }
+ return size_in_pixels;
+}
+
} // namespace gfx
« 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