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. 4 5 #include "content/renderer/render_view_impl.h" 6 7 #include "content/public/common/renderer_preferences.h" 8 #include "third_party/WebKit/public/web/linux/WebFontRendering.h" 9 10 using blink::WebFontRendering; 11 12 namespace content { 13 14 namespace { 15 RendererPreferencesToSkiaHinting(const RendererPreferences & prefs)16SkPaint::Hinting RendererPreferencesToSkiaHinting( 17 const RendererPreferences& prefs) { 18 if (!prefs.should_antialias_text) { 19 // When anti-aliasing is off, GTK maps all non-zero hinting settings to 20 // 'Normal' hinting so we do the same. Otherwise, folks who have 'Slight' 21 // hinting selected will see readable text in everything expect Chromium. 22 switch (prefs.hinting) { 23 case gfx::FontRenderParams::HINTING_NONE: 24 return SkPaint::kNo_Hinting; 25 case gfx::FontRenderParams::HINTING_SLIGHT: 26 case gfx::FontRenderParams::HINTING_MEDIUM: 27 case gfx::FontRenderParams::HINTING_FULL: 28 return SkPaint::kNormal_Hinting; 29 default: 30 NOTREACHED(); 31 return SkPaint::kNormal_Hinting; 32 } 33 } 34 35 switch (prefs.hinting) { 36 case gfx::FontRenderParams::HINTING_NONE: return SkPaint::kNo_Hinting; 37 case gfx::FontRenderParams::HINTING_SLIGHT: return SkPaint::kSlight_Hinting; 38 case gfx::FontRenderParams::HINTING_MEDIUM: return SkPaint::kNormal_Hinting; 39 case gfx::FontRenderParams::HINTING_FULL: return SkPaint::kFull_Hinting; 40 default: 41 NOTREACHED(); 42 return SkPaint::kNormal_Hinting; 43 } 44 } 45 RendererPreferencesToSkiaLCDOrder(const RendererPreferences & prefs)46SkFontHost::LCDOrder RendererPreferencesToSkiaLCDOrder( 47 const RendererPreferences& prefs) { 48 switch (prefs.subpixel_rendering) { 49 case gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE: 50 case gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB: 51 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB: 52 return SkFontHost::kRGB_LCDOrder; 53 case gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR: 54 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR: 55 return SkFontHost::kBGR_LCDOrder; 56 default: 57 NOTREACHED(); 58 return SkFontHost::kRGB_LCDOrder; 59 } 60 } 61 RendererPreferencesToSkiaLCDOrientation(const RendererPreferences & prefs)62SkFontHost::LCDOrientation RendererPreferencesToSkiaLCDOrientation( 63 const RendererPreferences& prefs) { 64 switch (prefs.subpixel_rendering) { 65 case gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE: 66 case gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB: 67 case gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR: 68 return SkFontHost::kHorizontal_LCDOrientation; 69 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB: 70 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR: 71 return SkFontHost::kVertical_LCDOrientation; 72 default: 73 NOTREACHED(); 74 return SkFontHost::kHorizontal_LCDOrientation; 75 } 76 } 77 78 } // namespace 79 UpdateFontRenderingFromRendererPrefs()80void RenderViewImpl::UpdateFontRenderingFromRendererPrefs() { 81 const RendererPreferences& prefs = renderer_preferences_; 82 WebFontRendering::setHinting(RendererPreferencesToSkiaHinting(prefs)); 83 WebFontRendering::setAutoHint(prefs.use_autohinter); 84 WebFontRendering::setUseBitmaps(prefs.use_bitmaps); 85 WebFontRendering::setLCDOrder(RendererPreferencesToSkiaLCDOrder(prefs)); 86 WebFontRendering::setLCDOrientation( 87 RendererPreferencesToSkiaLCDOrientation(prefs)); 88 WebFontRendering::setAntiAlias(prefs.should_antialias_text); 89 WebFontRendering::setSubpixelRendering( 90 prefs.subpixel_rendering != 91 gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE); 92 WebFontRendering::setSubpixelPositioning(prefs.use_subpixel_positioning); 93 } 94 95 } // namespace content 96