Use system's setting for font renderering, fixes #301.
authorCheng Zhao <zcbenz@gmail.com>
Wed, 14 May 2014 08:45:45 +0000 (16:45 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 14 May 2014 08:54:07 +0000 (16:54 +0800)
atom/browser/native_window_gtk.cc
atom/browser/native_window_gtk.h

index 1cb2429..67323c2 100644 (file)
@@ -21,6 +21,7 @@
 #include "ui/base/models/simple_menu_model.h"
 #include "ui/base/x/active_window_watcher_x.h"
 #include "ui/base/x/x11_util.h"
+#include "ui/gfx/font_render_params_linux.h"
 #include "ui/gfx/gtk_util.h"
 #include "ui/gfx/rect.h"
 #include "ui/gfx/skia_utils_gtk.h"
@@ -54,6 +55,44 @@ void SubstractBorderSize(int* width, int* height) {
   }
 }
 
+content::RendererPreferencesHintingEnum GetRendererPreferencesHintingEnum(
+    gfx::FontRenderParams::Hinting hinting) {
+  switch (hinting) {
+    case gfx::FontRenderParams::HINTING_NONE:
+      return content::RENDERER_PREFERENCES_HINTING_NONE;
+    case gfx::FontRenderParams::HINTING_SLIGHT:
+      return content::RENDERER_PREFERENCES_HINTING_SLIGHT;
+    case gfx::FontRenderParams::HINTING_MEDIUM:
+      return content::RENDERER_PREFERENCES_HINTING_MEDIUM;
+    case gfx::FontRenderParams::HINTING_FULL:
+      return content::RENDERER_PREFERENCES_HINTING_FULL;
+    default:
+      NOTREACHED() << "Unhandled hinting style " << hinting;
+      return content::RENDERER_PREFERENCES_HINTING_SYSTEM_DEFAULT;
+  }
+}
+
+content::RendererPreferencesSubpixelRenderingEnum
+GetRendererPreferencesSubpixelRenderingEnum(
+    gfx::FontRenderParams::SubpixelRendering subpixel_rendering) {
+  switch (subpixel_rendering) {
+    case gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE:
+      return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_NONE;
+    case gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB:
+      return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_RGB;
+    case gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR:
+      return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_BGR;
+    case gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB:
+      return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VRGB;
+    case gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR:
+      return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VBGR;
+    default:
+      NOTREACHED() << "Unhandled subpixel rendering style "
+                   << subpixel_rendering;
+      return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_SYSTEM_DEFAULT;
+  }
+}
+
 }  // namespace
 
 NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents,
@@ -118,6 +157,7 @@ NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents,
   }
 
   SetWebKitColorStyle();
+  SetFontRenderering();
 }
 
 NativeWindowGtk::~NativeWindowGtk() {
@@ -400,6 +440,19 @@ void NativeWindowGtk::SetWebKitColorStyle() {
       0;
 }
 
+void NativeWindowGtk::SetFontRenderering() {
+  content::RendererPreferences* prefs =
+      GetWebContents()->GetMutableRendererPrefs();
+  const gfx::FontRenderParams& params = gfx::GetDefaultWebKitFontRenderParams();
+  prefs->should_antialias_text = params.antialiasing;
+  prefs->use_subpixel_positioning = params.subpixel_positioning;
+  prefs->hinting = GetRendererPreferencesHintingEnum(params.hinting);
+  prefs->use_autohinter = params.autohinter;
+  prefs->use_bitmaps = params.use_bitmaps;
+  prefs->subpixel_rendering =
+  GetRendererPreferencesSubpixelRenderingEnum(params.subpixel_rendering);
+}
+
 bool NativeWindowGtk::IsMaximized() const {
   return state_ & GDK_WINDOW_STATE_MAXIMIZED;
 }
index 5f6411c..a01eefb 100644 (file)
@@ -86,6 +86,9 @@ class NativeWindowGtk : public NativeWindow,
   // Set WebKit's style from current theme.
   void SetWebKitColorStyle();
 
+  // Set how font is renderered.
+  void SetFontRenderering();
+
   // Whether window is maximized.
   bool IsMaximized() const;