| 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/font_render_params_linux.h" | 5 #include "ui/gfx/font_render_params_linux.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "ui/gfx/display.h" | 9 #include "ui/gfx/display.h" |
| 10 #include "ui/gfx/switches.h" | 10 #include "ui/gfx/switches.h" |
| 11 | 11 |
| 12 #if defined(TOOLKIT_GTK) | |
| 13 #include <gtk/gtk.h> | |
| 14 #else | |
| 15 #include <fontconfig/fontconfig.h> | 12 #include <fontconfig/fontconfig.h> |
| 16 #endif | |
| 17 | 13 |
| 18 #if defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS) | 14 #if defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS) |
| 19 #include "ui/gfx/linux_font_delegate.h" | 15 #include "ui/gfx/linux_font_delegate.h" |
| 20 #endif | 16 #endif |
| 21 | 17 |
| 22 namespace gfx { | 18 namespace gfx { |
| 23 | 19 |
| 24 namespace { | 20 namespace { |
| 25 | 21 |
| 26 bool SubpixelPositioningRequested(bool renderer) { | 22 bool SubpixelPositioningRequested(bool renderer) { |
| 27 const CommandLine* cl = CommandLine::ForCurrentProcess(); | 23 const CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 28 if (renderer) { | 24 if (renderer) { |
| 29 // Text rendered by Blink in high-DPI mode is poorly-hinted unless subpixel | 25 // Text rendered by Blink in high-DPI mode is poorly-hinted unless subpixel |
| 30 // positioning is used (as opposed to each glyph being individually snapped | 26 // positioning is used (as opposed to each glyph being individually snapped |
| 31 // to the pixel grid). | 27 // to the pixel grid). |
| 32 return cl->HasSwitch(switches::kEnableWebkitTextSubpixelPositioning) || | 28 return cl->HasSwitch(switches::kEnableWebkitTextSubpixelPositioning) || |
| 33 (Display::HasForceDeviceScaleFactor() && | 29 (Display::HasForceDeviceScaleFactor() && |
| 34 Display::GetForcedDeviceScaleFactor() != 1.0); | 30 Display::GetForcedDeviceScaleFactor() != 1.0); |
| 35 } | 31 } |
| 36 return cl->HasSwitch(switches::kEnableBrowserTextSubpixelPositioning); | 32 return cl->HasSwitch(switches::kEnableBrowserTextSubpixelPositioning); |
| 37 } | 33 } |
| 38 | 34 |
| 39 // Initializes |params| with the system's default settings. |renderer| is true | 35 // Initializes |params| with the system's default settings. |renderer| is true |
| 40 // when setting WebKit renderer defaults. | 36 // when setting WebKit renderer defaults. |
| 41 void LoadDefaults(FontRenderParams* params, bool renderer) { | 37 void LoadDefaults(FontRenderParams* params, bool renderer) { |
| 42 #if defined(TOOLKIT_GTK) | |
| 43 params->antialiasing = true; | |
| 44 // TODO(wangxianzhu): autohinter is now true to keep original behavior | |
| 45 // of WebKit, but it might not be the best value. | |
| 46 params->autohinter = true; | |
| 47 params->use_bitmaps = true; | |
| 48 params->hinting = FontRenderParams::HINTING_SLIGHT; | |
| 49 params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE; | |
| 50 | |
| 51 GtkSettings* gtk_settings = gtk_settings_get_default(); | |
| 52 CHECK(gtk_settings); | |
| 53 gint gtk_antialias = 0; | |
| 54 gint gtk_hinting = 0; | |
| 55 gchar* gtk_hint_style = NULL; | |
| 56 gchar* gtk_rgba = NULL; | |
| 57 g_object_get(gtk_settings, | |
| 58 "gtk-xft-antialias", >k_antialias, | |
| 59 "gtk-xft-hinting", >k_hinting, | |
| 60 "gtk-xft-hintstyle", >k_hint_style, | |
| 61 "gtk-xft-rgba", >k_rgba, | |
| 62 NULL); | |
| 63 | |
| 64 // g_object_get() doesn't tell us whether the properties were present or not, | |
| 65 // but if they aren't (because gnome-settings-daemon isn't running), we'll get | |
| 66 // NULL values for the strings. | |
| 67 if (gtk_hint_style && gtk_rgba) { | |
| 68 params->antialiasing = gtk_antialias; | |
| 69 | |
| 70 if (gtk_hinting == 0 || strcmp(gtk_hint_style, "hintnone") == 0) | |
| 71 params->hinting = FontRenderParams::HINTING_NONE; | |
| 72 else if (strcmp(gtk_hint_style, "hintslight") == 0) | |
| 73 params->hinting = FontRenderParams::HINTING_SLIGHT; | |
| 74 else if (strcmp(gtk_hint_style, "hintmedium") == 0) | |
| 75 params->hinting = FontRenderParams::HINTING_MEDIUM; | |
| 76 else if (strcmp(gtk_hint_style, "hintfull") == 0) | |
| 77 params->hinting = FontRenderParams::HINTING_FULL; | |
| 78 | |
| 79 if (strcmp(gtk_rgba, "none") == 0) | |
| 80 params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE; | |
| 81 else if (strcmp(gtk_rgba, "rgb") == 0) | |
| 82 params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB; | |
| 83 else if (strcmp(gtk_rgba, "bgr") == 0) | |
| 84 params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_BGR; | |
| 85 else if (strcmp(gtk_rgba, "vrgb") == 0) | |
| 86 params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_VRGB; | |
| 87 else if (strcmp(gtk_rgba, "vbgr") == 0) | |
| 88 params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_VBGR; | |
| 89 } | |
| 90 | |
| 91 g_free(gtk_hint_style); | |
| 92 g_free(gtk_rgba); | |
| 93 #else | |
| 94 // For non-GTK builds (read: Aura), just use reasonable hardcoded values. | 38 // For non-GTK builds (read: Aura), just use reasonable hardcoded values. |
| 95 params->antialiasing = true; | 39 params->antialiasing = true; |
| 96 params->autohinter = true; | 40 params->autohinter = true; |
| 97 params->use_bitmaps = true; | 41 params->use_bitmaps = true; |
| 98 params->hinting = FontRenderParams::HINTING_SLIGHT; | 42 params->hinting = FontRenderParams::HINTING_SLIGHT; |
| 99 | 43 |
| 100 // Fetch default subpixel rendering settings from FontConfig. | 44 // Fetch default subpixel rendering settings from FontConfig. |
| 101 FcPattern* pattern = FcPatternCreate(); | 45 FcPattern* pattern = FcPatternCreate(); |
| 102 FcConfigSubstitute(NULL, pattern, FcMatchPattern); | 46 FcConfigSubstitute(NULL, pattern, FcMatchPattern); |
| 103 FcDefaultSubstitute(pattern); | 47 FcDefaultSubstitute(pattern); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 127 } | 71 } |
| 128 | 72 |
| 129 #if defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS) | 73 #if defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS) |
| 130 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); | 74 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); |
| 131 if (delegate) { | 75 if (delegate) { |
| 132 params->antialiasing = delegate->UseAntialiasing(); | 76 params->antialiasing = delegate->UseAntialiasing(); |
| 133 params->hinting = delegate->GetHintingStyle(); | 77 params->hinting = delegate->GetHintingStyle(); |
| 134 params->subpixel_rendering = delegate->GetSubpixelRenderingStyle(); | 78 params->subpixel_rendering = delegate->GetSubpixelRenderingStyle(); |
| 135 } | 79 } |
| 136 #endif | 80 #endif |
| 137 #endif | |
| 138 | 81 |
| 139 params->subpixel_positioning = SubpixelPositioningRequested(renderer); | 82 params->subpixel_positioning = SubpixelPositioningRequested(renderer); |
| 140 | 83 |
| 141 // To enable subpixel positioning, we need to disable hinting. | 84 // To enable subpixel positioning, we need to disable hinting. |
| 142 if (params->subpixel_positioning) | 85 if (params->subpixel_positioning) |
| 143 params->hinting = FontRenderParams::HINTING_NONE; | 86 params->hinting = FontRenderParams::HINTING_NONE; |
| 144 } | 87 } |
| 145 | 88 |
| 146 } // namespace | 89 } // namespace |
| 147 | 90 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 161 LoadDefaults(&default_params, /* renderer */ true); | 104 LoadDefaults(&default_params, /* renderer */ true); |
| 162 loaded_defaults = true; | 105 loaded_defaults = true; |
| 163 return default_params; | 106 return default_params; |
| 164 } | 107 } |
| 165 | 108 |
| 166 bool GetDefaultWebkitSubpixelPositioning() { | 109 bool GetDefaultWebkitSubpixelPositioning() { |
| 167 return SubpixelPositioningRequested(true); | 110 return SubpixelPositioningRequested(true); |
| 168 } | 111 } |
| 169 | 112 |
| 170 } // namespace gfx | 113 } // namespace gfx |
| OLD | NEW |