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

Unified Diff: ui/gfx/pango_util.cc

Issue 659883002: Enable hidpi on Linux, refactor a bit on Windows to share Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: constants Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« ui/gfx/gfx.gyp ('K') | « ui/gfx/gfx.gyp ('k') | ui/gfx/screen_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/pango_util.cc
diff --git a/ui/gfx/pango_util.cc b/ui/gfx/pango_util.cc
index a324b7b326c373323420c8a2cfeba7a9d11c1325..bdec8d49717cb6f08ce19e9b5c8866e2c067e7ec 100644
--- a/ui/gfx/pango_util.cc
+++ b/ui/gfx/pango_util.cc
@@ -28,6 +28,9 @@ namespace {
// Marker for accelerators in the text.
const gunichar kAcceleratorChar = '&';
+const double kStandardDPI = 96.0;
+const double kPointsPerInch = 72.0;
+
// Creates and returns a PangoContext. The caller owns the context.
PangoContext* GetPangoContext() {
PangoFontMap* font_map = pango_cairo_font_map_get_default();
@@ -85,27 +88,6 @@ cairo_font_options_t* CreateCairoFontOptions(const FontRenderParams& params) {
return cairo_font_options;
}
-// Returns the DPI that should be used by Pango.
-double GetPangoDPI() {
- static double dpi = -1.0;
- if (dpi < 0.0) {
- const gfx::LinuxFontDelegate* delegate = gfx::LinuxFontDelegate::instance();
- if (delegate)
- dpi = delegate->GetFontDPI();
- if (dpi <= 0.0)
- dpi = 96.0;
- }
- return dpi;
-}
-
-// 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
-double GetPixelsInPoint() {
- static double pixels_in_point = GetPangoDPI() / 72.0; // 72 points in an inch
- return pixels_in_point;
-}
-
} // namespace
void SetUpPangoLayout(
@@ -163,7 +145,7 @@ void SetUpPangoLayout(
// Set the layout's resolution to match the resolution used to convert from
// points to pixels.
pango_cairo_context_set_resolution(pango_layout_get_context(layout),
- GetPangoDPI());
+ kStandardDPI);
// Set text and accelerator character if needed.
if (flags & Canvas::SHOW_PREFIX) {
@@ -205,9 +187,10 @@ int GetPangoFontSizeInPixels(PangoFontDescription* pango_font) {
if (pango_font_description_get_size_is_absolute(pango_font))
return pango_font_description_get_size(pango_font) / PANGO_SCALE;
+ const double scale = kStandardDPI / kPointsPerInch;
// Otherwise, we need to convert from points.
- return static_cast<int>(GetPixelsInPoint() *
- pango_font_description_get_size(pango_font) / PANGO_SCALE + 0.5);
+ return static_cast<int>(
+ scale * pango_font_description_get_size(pango_font) / PANGO_SCALE + 0.5);
}
PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) {
« ui/gfx/gfx.gyp ('K') | « ui/gfx/gfx.gyp ('k') | ui/gfx/screen_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698