font_kit/
hinting.rs

1// font-kit/src/hinting.rs
2//
3// Copyright © 2018 The Pathfinder Project Developers.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11//! Specifies how hinting (grid fitting) is to be performed (or not performed) for a glyph.
12//!
13//! This affects both outlines and rasterization.
14
15/// Specifies how hinting (grid fitting) is to be performed (or not performed) for a glyph.
16///
17/// This affects both outlines and rasterization.
18#[derive(Clone, Copy, Debug, PartialEq)]
19pub enum HintingOptions {
20    /// No hinting is performed unless absolutely necessary to assemble the glyph.
21    ///
22    /// This corresponds to what macOS and FreeType in its "no hinting" mode do.
23    None,
24
25    /// Hinting is performed only in the vertical direction. The specified point size is used for
26    /// grid fitting.
27    ///
28    /// This corresponds to what DirectWrite and FreeType in its light hinting mode do.
29    Vertical(f32),
30
31    /// Hinting is performed only in the vertical direction, and further tweaks are applied to make
32    /// subpixel antialiasing look better. The specified point size is used for grid fitting.
33    ///
34    /// This matches DirectWrite, GDI in its ClearType mode, and FreeType in its LCD hinting mode.
35    VerticalSubpixel(f32),
36
37    /// Hinting is performed in both horizontal and vertical directions. The specified point size
38    /// is used for grid fitting.
39    ///
40    /// This corresponds to what GDI in non-ClearType modes and FreeType in its normal hinting mode
41    /// do.
42    Full(f32),
43}
44
45impl HintingOptions {
46    /// Returns the point size that will be used for grid fitting, if any.
47    #[inline]
48    pub fn grid_fitting_size(&self) -> Option<f32> {
49        match *self {
50            HintingOptions::None => None,
51            HintingOptions::Vertical(size)
52            | HintingOptions::VerticalSubpixel(size)
53            | HintingOptions::Full(size) => Some(size),
54        }
55    }
56}