OLD | NEW |
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/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 18 matching lines...) Expand all Loading... |
29 // Marker for accelerators in the text. | 29 // Marker for accelerators in the text. |
30 const gunichar kAcceleratorChar = '&'; | 30 const gunichar kAcceleratorChar = '&'; |
31 | 31 |
32 // Multiply by the text height to determine how much text should be faded | 32 // Multiply by the text height to determine how much text should be faded |
33 // when elliding. | 33 // when elliding. |
34 const double kFadeWidthFactor = 1.5; | 34 const double kFadeWidthFactor = 1.5; |
35 | 35 |
36 // End state of the elliding fade. | 36 // End state of the elliding fade. |
37 const double kFadeFinalAlpha = 0.15; | 37 const double kFadeFinalAlpha = 0.15; |
38 | 38 |
39 // Return |cairo_font_options|. If needed, allocate and update it based on | 39 // Return |cairo_font_options|. If needed, allocate and update it. |
40 // GtkSettings. | |
41 cairo_font_options_t* GetCairoFontOptions() { | 40 cairo_font_options_t* GetCairoFontOptions() { |
42 // Font settings that we initialize once and then use when drawing text. | 41 // Font settings that we initialize once and then use when drawing text. |
43 static cairo_font_options_t* cairo_font_options = NULL; | 42 static cairo_font_options_t* cairo_font_options = NULL; |
44 | 43 |
45 if (cairo_font_options) | 44 if (cairo_font_options) |
46 return cairo_font_options; | 45 return cairo_font_options; |
47 | 46 |
48 cairo_font_options = cairo_font_options_create(); | 47 cairo_font_options = cairo_font_options_create(); |
49 | 48 |
| 49 #if defined(TOOLKIT_USES_GTK) |
50 gint antialias = 0; | 50 gint antialias = 0; |
51 gint hinting = 0; | 51 gint hinting = 0; |
52 gchar* hint_style = NULL; | 52 gchar* hint_style = NULL; |
53 gchar* rgba_style = NULL; | 53 gchar* rgba_style = NULL; |
54 | 54 |
55 #if !defined(USE_WAYLAND) && defined(TOOLKIT_USES_GTK) | |
56 // TODO(xji): still has gtk dependency. | |
57 GtkSettings* gtk_settings = gtk_settings_get_default(); | 55 GtkSettings* gtk_settings = gtk_settings_get_default(); |
58 g_object_get(gtk_settings, | 56 g_object_get(gtk_settings, |
59 "gtk-xft-antialias", &antialias, | 57 "gtk-xft-antialias", &antialias, |
60 "gtk-xft-hinting", &hinting, | 58 "gtk-xft-hinting", &hinting, |
61 "gtk-xft-hintstyle", &hint_style, | 59 "gtk-xft-hintstyle", &hint_style, |
62 "gtk-xft-rgba", &rgba_style, | 60 "gtk-xft-rgba", &rgba_style, |
63 NULL); | 61 NULL); |
64 #endif | |
65 | 62 |
66 // g_object_get() doesn't tell us whether the properties were present or not, | 63 // g_object_get() doesn't tell us whether the properties were present or not, |
67 // but if they aren't (because gnome-settings-daemon isn't running), we'll get | 64 // but if they aren't (because gnome-settings-daemon isn't running), we'll get |
68 // NULL values for the strings. | 65 // NULL values for the strings. |
69 if (hint_style && rgba_style) { | 66 if (hint_style && rgba_style) { |
70 if (!antialias) { | 67 if (!antialias) { |
71 cairo_font_options_set_antialias(cairo_font_options, | 68 cairo_font_options_set_antialias(cairo_font_options, |
72 CAIRO_ANTIALIAS_NONE); | 69 CAIRO_ANTIALIAS_NONE); |
73 } else if (strcmp(rgba_style, "none") == 0) { | 70 } else if (strcmp(rgba_style, "none") == 0) { |
74 cairo_font_options_set_antialias(cairo_font_options, | 71 cairo_font_options_set_antialias(cairo_font_options, |
(...skipping 26 matching lines...) Expand all Loading... |
101 } else if (strcmp(hint_style, "hintfull") == 0) { | 98 } else if (strcmp(hint_style, "hintfull") == 0) { |
102 cairo_hint_style = CAIRO_HINT_STYLE_FULL; | 99 cairo_hint_style = CAIRO_HINT_STYLE_FULL; |
103 } | 100 } |
104 cairo_font_options_set_hint_style(cairo_font_options, cairo_hint_style); | 101 cairo_font_options_set_hint_style(cairo_font_options, cairo_hint_style); |
105 } | 102 } |
106 | 103 |
107 if (hint_style) | 104 if (hint_style) |
108 g_free(hint_style); | 105 g_free(hint_style); |
109 if (rgba_style) | 106 if (rgba_style) |
110 g_free(rgba_style); | 107 g_free(rgba_style); |
| 108 #else |
| 109 // For non-GTK builds (read: Aura), use the same settings that were previously |
| 110 // used for GTK Chrome OS builds: RGB subpixel rendering with strong hinting. |
| 111 // Note: We should probably be getting per-font settings from FontConfig here, |
| 112 // but this path will be made obsolete by http://crbug.com/105550. |
| 113 cairo_font_options_set_antialias(cairo_font_options, |
| 114 CAIRO_ANTIALIAS_SUBPIXEL); |
| 115 cairo_font_options_set_subpixel_order(cairo_font_options, |
| 116 CAIRO_SUBPIXEL_ORDER_RGB); |
| 117 cairo_font_options_set_hint_style(cairo_font_options, CAIRO_HINT_STYLE_FULL); |
| 118 #endif |
111 | 119 |
112 return cairo_font_options; | 120 return cairo_font_options; |
113 } | 121 } |
114 | 122 |
115 // Returns the number of pixels in a point. | 123 // Returns the number of pixels in a point. |
116 // - multiply a point size by this to get pixels ("device units") | 124 // - multiply a point size by this to get pixels ("device units") |
117 // - divide a pixel size by this to get points | 125 // - divide a pixel size by this to get points |
118 float GetPixelsInPoint() { | 126 float GetPixelsInPoint() { |
119 static float pixels_in_point = 1.0; | 127 static float pixels_in_point = 1.0; |
120 static bool determined_value = false; | 128 static bool determined_value = false; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 // There are PANGO_SCALE Pango units in a device unit (pixel). | 385 // There are PANGO_SCALE Pango units in a device unit (pixel). |
378 size_in_pixels /= PANGO_SCALE; | 386 size_in_pixels /= PANGO_SCALE; |
379 } else { | 387 } else { |
380 // Otherwise, we need to convert from points. | 388 // Otherwise, we need to convert from points. |
381 size_in_pixels = size_in_pixels * GetPixelsInPoint() / PANGO_SCALE; | 389 size_in_pixels = size_in_pixels * GetPixelsInPoint() / PANGO_SCALE; |
382 } | 390 } |
383 return size_in_pixels; | 391 return size_in_pixels; |
384 } | 392 } |
385 | 393 |
386 } // namespace gfx | 394 } // namespace gfx |
OLD | NEW |