use crate::outline::{self, SmoothMode};
#[derive(Copy, Clone, PartialEq, Eq, Hash, Default, Debug)]
pub enum RasterTarget {
Mono,
#[default]
Normal,
Light,
Lcd,
VerticalLcd,
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum HintEngine {
TrueType,
PostScript,
Auto,
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub(super) enum EngineRequest {
Interpreter,
AutoFallback,
Auto,
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct HintOptions {
engine: EngineRequest,
target: RasterTarget,
classic_cleartype: bool,
symmetric_rendering: bool,
preserve_linear_metrics: bool,
pedantic: bool,
}
impl Default for HintOptions {
fn default() -> Self {
Self::auto_fallback()
}
}
impl HintOptions {
pub fn auto_fallback() -> Self {
Self::with_engine(EngineRequest::AutoFallback)
}
pub fn interpreter() -> Self {
Self::with_engine(EngineRequest::Interpreter)
}
pub fn auto() -> Self {
Self::with_engine(EngineRequest::Auto)
}
fn with_engine(engine: EngineRequest) -> Self {
Self {
engine,
target: RasterTarget::Normal,
classic_cleartype: false,
symmetric_rendering: true,
preserve_linear_metrics: false,
pedantic: false,
}
}
pub fn with_target(self, target: RasterTarget) -> Self {
Self { target, ..self }
}
pub fn with_classic_cleartype(self, classic_cleartype: bool) -> Self {
Self {
classic_cleartype,
..self
}
}
pub fn with_symmetric_rendering(self, symmetric_rendering: bool) -> Self {
Self {
symmetric_rendering,
..self
}
}
pub fn with_preserve_linear_metrics(self, preserve_linear_metrics: bool) -> Self {
Self {
preserve_linear_metrics,
..self
}
}
pub fn with_pedantic(self, pedantic: bool) -> Self {
Self { pedantic, ..self }
}
pub(super) fn engine(&self) -> EngineRequest {
self.engine
}
pub fn target(&self) -> RasterTarget {
self.target
}
pub fn classic_cleartype(&self) -> bool {
self.classic_cleartype
}
pub fn symmetric_rendering(&self) -> bool {
self.symmetric_rendering
}
pub fn preserve_linear_metrics(&self) -> bool {
self.preserve_linear_metrics
}
pub fn pedantic(&self) -> bool {
self.pedantic
}
pub(super) fn outline_target(&self) -> outline::Target {
let mode = match self.target {
RasterTarget::Mono => return outline::Target::Mono,
RasterTarget::Normal => SmoothMode::Normal,
RasterTarget::Light => SmoothMode::Light,
RasterTarget::Lcd => SmoothMode::Lcd,
RasterTarget::VerticalLcd => SmoothMode::VerticalLcd,
};
outline::Target::Smooth {
mode,
symmetric_rendering: self.symmetric_rendering,
preserve_linear_metrics: self.preserve_linear_metrics,
}
}
}