Annotate fonts with ruby (pinyin/romaji) and produce modified TTF/WOFF2 outputs.
at main 44 lines 1.2 kB view raw
1#[cfg(feature = "pinyin")] 2pub mod pinyin; 3#[cfg(feature = "romaji")] 4pub mod romaji; 5 6pub mod utils; 7 8use std::ops::RangeInclusive; 9 10use anyhow::Result; 11use facet::Facet; 12use kurbo::BezPath; 13 14/// A pluggable renderer that can add "ruby" annotations. 15pub trait RubyRenderer: Send + Sync { 16 /// Given a base character `ch`, add annotation paths (if any) into `final_path`. 17 /// `orig_advance` is the glyph advance in font units; `main_upem` is the main font UPEM. 18 fn annotate( 19 &self, 20 ch: char, 21 final_path: &mut BezPath, 22 orig_advance: f64, 23 main_upem: f64, 24 ) -> Result<()>; 25 26 /// Returns the character ranges that this renderer can annotate. 27 fn ranges(&self) -> &[RangeInclusive<u32>]; 28} 29 30/// Positioning options for ruby annotations relative to the base glyph. 31#[derive(Facet, Clone, Copy, PartialEq, Eq)] 32#[repr(u8)] 33pub enum RubyPosition { 34 Top, 35 Bottom, 36 LeftDown, 37 LeftUp, 38 RightDown, 39 RightUp, 40} 41 42const CJK_RANGE: RangeInclusive<u32> = 0x4e00..=0x9fff; 43const HIRAGANA_RANGE: RangeInclusive<u32> = 0x3040..=0x309f; 44const KATAKANA_RANGE: RangeInclusive<u32> = 0x30a0..=0x30ff;