Home | History | Annotate | Download | only in renderer
      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 static SkPaint::Hinting RendererPreferencesToSkiaHinting(
     15     const RendererPreferences& prefs) {
     16   if (!prefs.should_antialias_text) {
     17     // When anti-aliasing is off, GTK maps all non-zero hinting settings to
     18     // 'Normal' hinting so we do the same. Otherwise, folks who have 'Slight'
     19     // hinting selected will see readable text in everything expect Chromium.
     20     switch (prefs.hinting) {
     21       case RENDERER_PREFERENCES_HINTING_NONE:
     22         return SkPaint::kNo_Hinting;
     23       case RENDERER_PREFERENCES_HINTING_SYSTEM_DEFAULT:
     24       case RENDERER_PREFERENCES_HINTING_SLIGHT:
     25       case RENDERER_PREFERENCES_HINTING_MEDIUM:
     26       case RENDERER_PREFERENCES_HINTING_FULL:
     27         return SkPaint::kNormal_Hinting;
     28       default:
     29         NOTREACHED();
     30         return SkPaint::kNormal_Hinting;
     31     }
     32   }
     33 
     34   switch (prefs.hinting) {
     35   case RENDERER_PREFERENCES_HINTING_SYSTEM_DEFAULT:
     36     return SkPaint::kNormal_Hinting;
     37   case RENDERER_PREFERENCES_HINTING_NONE:
     38     return SkPaint::kNo_Hinting;
     39   case RENDERER_PREFERENCES_HINTING_SLIGHT:
     40     return SkPaint::kSlight_Hinting;
     41   case RENDERER_PREFERENCES_HINTING_MEDIUM:
     42     return SkPaint::kNormal_Hinting;
     43   case RENDERER_PREFERENCES_HINTING_FULL:
     44     return SkPaint::kFull_Hinting;
     45   default:
     46     NOTREACHED();
     47     return SkPaint::kNormal_Hinting;
     48   }
     49 }
     50 
     51 static SkFontHost::LCDOrder RendererPreferencesToSkiaLCDOrder(
     52     RendererPreferencesSubpixelRenderingEnum subpixel) {
     53   switch (subpixel) {
     54   case RENDERER_PREFERENCES_SUBPIXEL_RENDERING_SYSTEM_DEFAULT:
     55   case RENDERER_PREFERENCES_SUBPIXEL_RENDERING_NONE:
     56   case RENDERER_PREFERENCES_SUBPIXEL_RENDERING_RGB:
     57   case RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VRGB:
     58     return SkFontHost::kRGB_LCDOrder;
     59   case RENDERER_PREFERENCES_SUBPIXEL_RENDERING_BGR:
     60   case RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VBGR:
     61     return SkFontHost::kBGR_LCDOrder;
     62   default:
     63     NOTREACHED();
     64     return SkFontHost::kRGB_LCDOrder;
     65   }
     66 }
     67 
     68 static SkFontHost::LCDOrientation
     69     RendererPreferencesToSkiaLCDOrientation(
     70         RendererPreferencesSubpixelRenderingEnum subpixel) {
     71   switch (subpixel) {
     72   case RENDERER_PREFERENCES_SUBPIXEL_RENDERING_SYSTEM_DEFAULT:
     73   case RENDERER_PREFERENCES_SUBPIXEL_RENDERING_NONE:
     74   case RENDERER_PREFERENCES_SUBPIXEL_RENDERING_RGB:
     75   case RENDERER_PREFERENCES_SUBPIXEL_RENDERING_BGR:
     76     return SkFontHost::kHorizontal_LCDOrientation;
     77   case RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VRGB:
     78   case RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VBGR:
     79     return SkFontHost::kVertical_LCDOrientation;
     80   default:
     81     NOTREACHED();
     82     return SkFontHost::kHorizontal_LCDOrientation;
     83   }
     84 }
     85 
     86 static bool RendererPreferencesToAntiAliasFlag(
     87     const RendererPreferences& prefs) {
     88   return prefs.should_antialias_text;
     89 }
     90 
     91 static bool RendererPreferencesToSubpixelRenderingFlag(
     92     const RendererPreferences& prefs) {
     93   if (prefs.subpixel_rendering !=
     94         RENDERER_PREFERENCES_SUBPIXEL_RENDERING_SYSTEM_DEFAULT &&
     95       prefs.subpixel_rendering !=
     96         RENDERER_PREFERENCES_SUBPIXEL_RENDERING_NONE) {
     97     return true;
     98   }
     99   return false;
    100 }
    101 
    102 void RenderViewImpl::UpdateFontRenderingFromRendererPrefs() {
    103   const RendererPreferences& prefs = renderer_preferences_;
    104   WebFontRendering::setHinting(RendererPreferencesToSkiaHinting(prefs));
    105   WebFontRendering::setAutoHint(prefs.use_autohinter);
    106   WebFontRendering::setUseBitmaps(prefs.use_bitmaps);
    107   WebFontRendering::setLCDOrder(
    108       RendererPreferencesToSkiaLCDOrder(prefs.subpixel_rendering));
    109   WebFontRendering::setLCDOrientation(
    110       RendererPreferencesToSkiaLCDOrientation(prefs.subpixel_rendering));
    111   WebFontRendering::setAntiAlias(RendererPreferencesToAntiAliasFlag(prefs));
    112   WebFontRendering::setSubpixelRendering(
    113       RendererPreferencesToSubpixelRenderingFlag(prefs));
    114   WebFontRendering::setSubpixelPositioning(prefs.use_subpixel_positioning);
    115 }
    116 
    117 }  // namespace content
    118