Skip to content

Commit

Permalink
Use system's setting for font renderering, fixes #301.
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed May 14, 2014
1 parent cfeb00e commit afd927f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
53 changes: 53 additions & 0 deletions atom/browser/native_window_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -118,6 +157,7 @@ NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents,
}

SetWebKitColorStyle();
SetFontRenderering();
}

NativeWindowGtk::~NativeWindowGtk() {
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions atom/browser/native_window_gtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit afd927f

Please sign in to comment.