1 // Copyright 2014 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 #ifndef UI_GFX_FONT_RENDER_PARAMS_H_ 6 #define UI_GFX_FONT_RENDER_PARAMS_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "build/build_config.h" 12 #include "device/vr/buildflags/buildflags.h" 13 #include "third_party/skia/include/core/SkSurfaceProps.h" 14 #include "ui/gfx/font.h" 15 #include "ui/gfx/gfx_export.h" 16 17 namespace gfx { 18 19 // A collection of parameters describing how text should be rendered on Linux. 20 struct GFX_EXPORT FontRenderParams { 21 bool operator==(const FontRenderParams& other) const { 22 return antialiasing == other.antialiasing && 23 subpixel_positioning == other.subpixel_positioning && 24 autohinter == other.autohinter && use_bitmaps == other.use_bitmaps && 25 hinting == other.hinting && 26 subpixel_rendering == other.subpixel_rendering; 27 } 28 29 // Level of hinting to be applied. 30 enum Hinting { 31 HINTING_NONE = 0, 32 HINTING_SLIGHT, 33 HINTING_MEDIUM, 34 HINTING_FULL, 35 36 HINTING_MAX = HINTING_FULL, 37 }; 38 39 // Different subpixel orders to be used for subpixel rendering. 40 enum SubpixelRendering { 41 SUBPIXEL_RENDERING_NONE = 0, 42 SUBPIXEL_RENDERING_RGB, 43 SUBPIXEL_RENDERING_BGR, 44 SUBPIXEL_RENDERING_VRGB, 45 SUBPIXEL_RENDERING_VBGR, 46 47 SUBPIXEL_RENDERING_MAX = SUBPIXEL_RENDERING_VBGR, 48 }; 49 50 // Antialiasing (grayscale if |subpixel_rendering| is SUBPIXEL_RENDERING_NONE 51 // and RGBA otherwise). 52 bool antialiasing = true; 53 54 // Should subpixel positioning (i.e. fractional X positions for glyphs) be 55 // used? 56 // TODO(derat): Remove this; we don't set it in the browser and mostly ignore 57 // it in Blink: http://crbug.com/396659 58 bool subpixel_positioning = true; 59 60 // Should FreeType's autohinter be used (as opposed to Freetype's bytecode 61 // interpreter, which uses fonts' own hinting instructions)? 62 bool autohinter = false; 63 64 // Should embedded bitmaps in fonts should be used? 65 bool use_bitmaps = false; 66 67 // Hinting level. 68 Hinting hinting = HINTING_MEDIUM; 69 70 // Whether subpixel rendering should be used or not, and if so, the display's 71 // subpixel order. 72 SubpixelRendering subpixel_rendering = SUBPIXEL_RENDERING_NONE; 73 74 static SkPixelGeometry SubpixelRenderingToSkiaPixelGeometry( 75 SubpixelRendering subpixel_rendering); 76 }; 77 78 // A query used to determine the appropriate FontRenderParams. 79 struct GFX_EXPORT FontRenderParamsQuery { 80 FontRenderParamsQuery(); 81 FontRenderParamsQuery(const FontRenderParamsQuery& other); 82 ~FontRenderParamsQuery(); 83 is_emptyFontRenderParamsQuery84 bool is_empty() const { 85 return families.empty() && pixel_size <= 0 && point_size <= 0 && style < 0; 86 } 87 88 // Requested font families, or empty if unset. 89 std::vector<std::string> families; 90 91 // Font size in pixels or points, or 0 if unset. 92 int pixel_size; 93 int point_size; 94 95 // Font::FontStyle bit field, or -1 if unset. 96 int style; 97 98 // Weight of the font. Weight::NORMAL by default. 99 Font::Weight weight; 100 101 // The device scale factor of the display, or 0 if unset. 102 float device_scale_factor; 103 }; 104 105 // Returns the appropriate parameters for rendering the font described by 106 // |query|. If |family_out| is non-NULL, it will be updated to contain the 107 // recommended font family from |query.families|. 108 GFX_EXPORT FontRenderParams GetFontRenderParams( 109 const FontRenderParamsQuery& query, 110 std::string* family_out); 111 112 #if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_BSD) 113 // Clears GetFontRenderParams()'s cache. Intended to be called by tests that are 114 // changing Fontconfig's configuration. 115 GFX_EXPORT void ClearFontRenderParamsCacheForTest(); 116 #endif 117 118 // Gets the device scale factor to query the FontRenderParams. 119 GFX_EXPORT float GetFontRenderParamsDeviceScaleFactor(); 120 121 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_BSD) || \ 122 defined(OS_ANDROID) || defined(OS_FUCHSIA) 123 // Sets the device scale factor for FontRenderParams to decide 124 // if it should enable subpixel positioning. 125 GFX_EXPORT void SetFontRenderParamsDeviceScaleFactor( 126 float device_scale_factor); 127 #endif 128 129 } // namespace gfx 130 131 #endif // UI_GFX_FONT_RENDER_PARAMS_H_ 132