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
3 // found in the LICENSE file.
5 #include "content/renderer/render_view_impl.h"
7 #include "content/public/common/renderer_preferences.h"
8 #include "third_party/WebKit/public/web/linux/WebFontRendering.h"
9 #include "ui/gfx/font_render_params.h"
11 using blink::WebFontRendering
;
17 const int kMaxDefaultFontSize
= 999;
19 SkPaint::Hinting
RendererPreferencesToSkiaHinting(
20 const RendererPreferences
& prefs
) {
21 if (!prefs
.should_antialias_text
) {
22 // When anti-aliasing is off, GTK maps all non-zero hinting settings to
23 // 'Normal' hinting so we do the same. Otherwise, folks who have 'Slight'
24 // hinting selected will see readable text in everything expect Chromium.
25 switch (prefs
.hinting
) {
26 case gfx::FontRenderParams::HINTING_NONE
:
27 return SkPaint::kNo_Hinting
;
28 case gfx::FontRenderParams::HINTING_SLIGHT
:
29 case gfx::FontRenderParams::HINTING_MEDIUM
:
30 case gfx::FontRenderParams::HINTING_FULL
:
31 return SkPaint::kNormal_Hinting
;
34 return SkPaint::kNormal_Hinting
;
38 switch (prefs
.hinting
) {
39 case gfx::FontRenderParams::HINTING_NONE
: return SkPaint::kNo_Hinting
;
40 case gfx::FontRenderParams::HINTING_SLIGHT
: return SkPaint::kSlight_Hinting
;
41 case gfx::FontRenderParams::HINTING_MEDIUM
: return SkPaint::kNormal_Hinting
;
42 case gfx::FontRenderParams::HINTING_FULL
: return SkPaint::kFull_Hinting
;
45 return SkPaint::kNormal_Hinting
;
51 void RenderViewImpl::UpdateFontRenderingFromRendererPrefs() {
52 const RendererPreferences
& prefs
= renderer_preferences_
;
53 WebFontRendering::setHinting(RendererPreferencesToSkiaHinting(prefs
));
54 WebFontRendering::setAutoHint(prefs
.use_autohinter
);
55 WebFontRendering::setUseBitmaps(prefs
.use_bitmaps
);
56 WebFontRendering::setLCDOrder(
57 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrder(
58 prefs
.subpixel_rendering
));
59 WebFontRendering::setLCDOrientation(
60 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrientation(
61 prefs
.subpixel_rendering
));
62 WebFontRendering::setAntiAlias(prefs
.should_antialias_text
);
63 WebFontRendering::setSubpixelRendering(
64 prefs
.subpixel_rendering
!=
65 gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE
);
66 WebFontRendering::setSubpixelPositioning(prefs
.use_subpixel_positioning
);
67 if (prefs
.default_font_size
> 0 &&
68 prefs
.default_font_size
<= kMaxDefaultFontSize
) {
69 WebFontRendering::setDefaultFontSize(prefs
.default_font_size
);
73 } // namespace content