Rust constants
225 constants in daegun 2.0.0, as the compiler exports them, filed by area: the free ones, and those that hang off a type, such as each script and each name id. Each says what it means and where it goes.
Base
What everything else is built on: errors and their kinds, tags, glyph ids, boxes and orientation. These live at the root of the crate.
GlyphId::NOTDEFpub const NOTDEF: GlyphId = GlyphId(0);Glyph 0, the glyph a font draws for a character it has no glyph for.
OpenType keeps the "missing glyph" at index 0, where it goes by the name
.notdef. Most fonts draw it as an empty box.Use it as the fallback where a lookup such as
Font::glyph_idanswersNone. It is also the default ofShapeOptions::not_found_glyph, so a shaped run holds it wherever the font lacked a character, and it is the valueGlyphId::default()returns.use daegun::GlyphId; // Inter has no glyph for this character, so draw its missing glyph. let glyph = font.glyph_id('語').unwrap_or(GlyphId::NOTDEF); assert_eq!(glyph, GlyphId(0)); assert_eq!(GlyphId::NOTDEF, GlyphId::default());
Fonts
Opening a font and asking what it is: its names, its tables, its variation axes and the locations they make, and the caches that keep its work. Font, Location and their kin live at the root of the crate.
NameId::COMPATIBLE_FULL_NAMEpub const COMPATIBLE_FULL_NAME: NameId = NameId(18);Name ID 18: the compatible full name, for the Macintosh alone, where its font menu should show something other than name ID 4.
NameId::COPYRIGHT_NOTICEpub const COPYRIGHT_NOTICE: NameId = NameId(0);Name ID 0: the copyright notice.
NameId::DARK_BACKGROUND_PALETTEpub const DARK_BACKGROUND_PALETTE: NameId = NameId(24);Name ID 24: the name of a color font's palette that is meant for dark backgrounds.
NameId::DESCRIPTIONpub const DESCRIPTION: NameId = NameId(10);Name ID 10: a description of the typeface.
NameId::DESIGNERpub const DESIGNER: NameId = NameId(9);Name ID 9: the name of the typeface's designer.
NameId::DESIGNER_URLpub const DESIGNER_URL: NameId = NameId(12);Name ID 12: the URL of the typeface's designer.
NameId::FAMILY_NAMEpub const FAMILY_NAME: NameId = NameId(1);Name ID 1: the family name as older software groups fonts, with at most four styles to a family.
The four are regular, italic, bold and bold italic. A family with more styles is split into several families under this ID, one for its SemiBold for instance, and
NameId::TYPOGRAPHIC_FAMILY_NAMEnames it as a whole.Font::family_namereads that name first and this one second.NameId::FULL_NAMEpub const FULL_NAME: NameId = NameId(4);Name ID 4: the full name, family and style together, such as
Inter Variable Bold.NameId::LICENSE_DESCRIPTIONpub const LICENSE_DESCRIPTION: NameId = NameId(13);Name ID 13: the license description, which says in plain words how the font may be used.
NameId::LICENSE_URLpub const LICENSE_URL: NameId = NameId(14);Name ID 14: a URL where more about the font's license can be found.
NameId::LIGHT_BACKGROUND_PALETTEpub const LIGHT_BACKGROUND_PALETTE: NameId = NameId(23);Name ID 23: the name of a color font's palette that is meant for light backgrounds.
NameId::MANUFACTURERpub const MANUFACTURER: NameId = NameId(8);Name ID 8: the name of the foundry or company that made the font.
NameId::POSTSCRIPT_CID_FINDFONT_NAMEpub const POSTSCRIPT_CID_FINDFONT_NAME: NameId = NameId(20);Name ID 20: the PostScript CID findfont name, the name a CID-keyed font goes by with PostScript's
findfontoperator.NameId::POSTSCRIPT_NAMEpub const POSTSCRIPT_NAME: NameId = NameId(6);Name ID 6: the PostScript name, a short ASCII name without spaces, such as
InterVariable-Bold, that printing and PDF software know the font by.NameId::SAMPLE_TEXTpub const SAMPLE_TEXT: NameId = NameId(19);Name ID 19: sample text, the text the font's maker wants shown as a specimen of it.
NameId::SUBFAMILY_NAMEpub const SUBFAMILY_NAME: NameId = NameId(2);Name ID 2: the style within the family of name ID 1, by convention Regular, Italic, Bold or Bold Italic.
NameId::TRADEMARKpub const TRADEMARK: NameId = NameId(7);Name ID 7: the trademark notice.
NameId::TYPOGRAPHIC_FAMILY_NAMEpub const TYPOGRAPHIC_FAMILY_NAME: NameId = NameId(16);Name ID 16: the typographic family name, which groups every style of a family however many there are.
A font usually carries it only where it differs from
NameId::FAMILY_NAME, which stops at four styles.Font::family_namereturns this name where the font has it.NameId::TYPOGRAPHIC_SUBFAMILY_NAMEpub const TYPOGRAPHIC_SUBFAMILY_NAME: NameId = NameId(17);Name ID 17: the typographic subfamily name, the style within the typographic family, such as
SemiBold.NameId::UNIQUE_IDpub const UNIQUE_ID: NameId = NameId(3);Name ID 3: a string that identifies this font and no other, such as
4.001;git-9221beed3;RSMS;InterVariable-Regular.NameId::VARIATIONS_POSTSCRIPT_NAME_PREFIXpub const VARIATIONS_POSTSCRIPT_NAME_PREFIX: NameId = NameId(25);Name ID 25: the prefix that the PostScript names of a variable font's instances start with.
Inter Variable's is
InterVariable. Where an instance has no PostScript name of its own, daegun builds one from this prefix, or from the family name where the font has no prefix. The names at any location but the default leave this ID out, as one instance has no use for it.NameId::VENDOR_URLpub const VENDOR_URL: NameId = NameId(11);Name ID 11: the URL of the font's vendor.
NameId::VERSION_STRINGpub const VERSION_STRING: NameId = NameId(5);Name ID 5: the version string, by convention
Versionand a number, such asVersion 4.001.NameId::WWS_FAMILY_NAMEpub const WWS_FAMILY_NAME: NameId = NameId(21);Name ID 21: the WWS family name, for a family whose members differ only in weight, width and slope.
WWS stands for weight, width and slope. A typographic family that also varies in something else, such as optical size, names each group that varies in those three alone here, for software that sorts styles by them.
NameId::WWS_SUBFAMILY_NAMEpub const WWS_SUBFAMILY_NAME: NameId = NameId(22);Name ID 22: the WWS subfamily name, the style within the WWS family of name ID 21.
Metrics
A font's metrics in font units, y up: line spacing, the OS/2 and post tables, STAT, tracking and the flags a PDF writer needs. The calls are on Font, and their types are in daegun::metrics.
metrics::DEFAULT_POINT_SIZEpub const DEFAULT_POINT_SIZE: f64 = 12.0;The point size a font's tracking is read at when no usable size is given: 12 points.
Font::trackingreads thetraktable at this size when itspoint_sizeis not finite and above zero. Shaping does the same whenShapeOptions::point_sizeisNoneor such a size.use daegun::metrics::DEFAULT_POINT_SIZE; use daegun::Orientation; assert_eq!(DEFAULT_POINT_SIZE, 12.0); // A size that is no size is read as this one. For a font whose trak table gives 10 units at // 10 pt and -10 at 20 pt, both answers are 6. let fallback = font.tracking(f64::NAN, Orientation::Horizontal); assert_eq!(fallback, font.tracking(DEFAULT_POINT_SIZE, Orientation::Horizontal));metrics::PdfFlags::FIXED_PITCHpub const FIXED_PITCH: PdfFlags = PdfFlags(0x01);Every glyph has the same width, as in a typewriter face.
Font::pdf_flagssets it when theisFixedPitchfield of theposttable is not 0. It takes the font's word for it and measures no advances. A font without aposttable never has the flag.use daegun::metrics::PdfFlags; use daegun::Location; // Noto Color Emoji says that all of its glyphs are one width. assert!(font.pdf_flags(&Location::default()).contains(PdfFlags::FIXED_PITCH));metrics::PdfFlags::ITALICpub const ITALIC: PdfFlags = PdfFlags(0x40);The glyphs slant: the font states an italic angle other than 0.
Font::pdf_flagssets it whenFont::italic_angleis not 0. It goes by the angle inpost, not by the italic bit ofOS/2, so an oblique face that states an angle has it as well. At a location other than the default, on a variable font with aslntaxis, it is set where that axis is off 0.use daegun::metrics::PdfFlags; use daegun::{Font, Location}; assert!(!font.pdf_flags(&Location::default()).contains(PdfFlags::ITALIC)); // The italic of Irianis ADF states an angle of -13 degrees. let italic = Font::from_collection(&bytes("Irianisadfstd/IrianisadfstdItalic.ttc"), 0)?; assert!(italic.pdf_flags(&Location::default()).contains(PdfFlags::ITALIC));metrics::PdfFlags::NONSYMBOLICpub const NONSYMBOLIC: PdfFlags = PdfFlags(0x20);The font is not a symbol font, and every character it maps, control codes aside, is in the Adobe standard Latin set.
Font::pdf_flagssets it whenever it does not setPdfFlags::SYMBOLIC, so a font has one of the two and never both. A font with nocmaptable is nonsymbolic too.use daegun::metrics::PdfFlags; use daegun::Location; // An AAT test font that maps nothing beyond the standard Latin set. let flags = font.pdf_flags(&Location::default()); assert!(flags.contains(PdfFlags::NONSYMBOLIC)); assert!(!flags.contains(PdfFlags::SYMBOLIC));metrics::PdfFlags::SCRIPTpub const SCRIPT: PdfFlags = PdfFlags(0x08);The glyphs look handwritten, going by the family class of
OS/2.Font::pdf_flagssets it when the class inOs2::family_class, its high byte, is 10, the class for scripts. Nothing is read from the glyphs, so a handwriting font that leaves the class at 0 comes back without it.use daegun::metrics::PdfFlags; use daegun::Location; // Inter is not classed as a script face. assert!(!font.pdf_flags(&Location::default()).contains(PdfFlags::SCRIPT));metrics::PdfFlags::SERIFpub const SERIF: PdfFlags = PdfFlags(0x02);The glyphs have serifs, going by the family class of
OS/2.Font::pdf_flagssets it when the class inOs2::family_class, its high byte, is one of the serif classes: 1, 2, 3, 4, 5 or 7. Nothing is read from the glyphs, and a font may leave the class at 0. EB Garamond does, so it comes back without the flag for all its serifs.use daegun::metrics::PdfFlags; use daegun::Location; // STIX Two Math records family class 1, the first of the serif classes. let class = font.os2(&Location::default()).and_then(|os2| os2.family_class).map(|class| class >> 8); assert_eq!(class, Some(1)); assert!(font.pdf_flags(&Location::default()).contains(PdfFlags::SERIF));metrics::PdfFlags::SYMBOLICpub const SYMBOLIC: PdfFlags = PdfFlags(0x04);The font holds characters outside the Adobe standard Latin set, or is a symbol font.
Font::pdf_flagsfollows PDF's rule. The flag is set for a Windows symbol font, one whosecmaphas a symbol subtable and none keyed by Unicode. It is also set for any font that maps a character outside the Adobe standard Latin character set, the characters that PDF's built-in Latin encodings cover. Control codes do not count. One character is enough, so a font need not look like a symbol font to carry the flag: Inter has it, and its Greek letters alone would be enough.PdfFlags::NONSYMBOLICis set in every other case.use daegun::metrics::PdfFlags; use daegun::Location; // Inter maps the Greek letter lambda, which is outside the standard Latin set, so it is symbolic. assert!(font.glyph_id('λ').is_some()); assert!(font.pdf_flags(&Location::default()).contains(PdfFlags::SYMBOLIC));
Shaping
Text to glyphs placed in font units, one run or the runs of mixed-direction text, and the carets that hit testing reads off them. The calls are on Font, and their types are in daegun::shape.
shape::ShapeOptions::DEFAULTpub const DEFAULT: ShapeOptions<'static>;The default options as a constant, the same value
ShapeOptions::default()returns.Being a constant,
&ShapeOptions::DEFAULTborrows one static value where&ShapeOptions::default()builds a new one on the stack each call. Everywith_method is aconst fn, so options of your own can be constants too.use daegun::shape::{Direction, ShapeOptions}; use daegun::Location; const RTL: ShapeOptions = ShapeOptions::DEFAULT.with_direction(Direction::RightToLeft); let run = font.shape("Wave", &Location::default(), &RTL); assert_eq!(ShapeOptions::DEFAULT, ShapeOptions::default());
Unicode
Text analysis that needs no font: bidi, grapheme and word boundaries, line breaking, scripts and character properties. Free functions and types in daegun::unicode. Every position is a byte offset where a character starts.
unicode::Script::ADLAMpub const ADLAM: Script = Script(0);The Adlam script, ISO 15924
Adlm.unicode::Script::AHOMpub const AHOM: Script = Script(1);The Ahom script, ISO 15924
Ahom.unicode::Script::ANATOLIAN_HIEROGLYPHSpub const ANATOLIAN_HIEROGLYPHS: Script = Script(2);The Anatolian Hieroglyphs script, ISO 15924
Hluw.unicode::Script::ARABICpub const ARABIC: Script = Script(3);The Arabic script, ISO 15924
Arab.unicode::Script::ARMENIANpub const ARMENIAN: Script = Script(4);The Armenian script, ISO 15924
Armn.unicode::Script::AVESTANpub const AVESTAN: Script = Script(5);The Avestan script, ISO 15924
Avst.unicode::Script::BALINESEpub const BALINESE: Script = Script(6);The Balinese script, ISO 15924
Bali.unicode::Script::BAMUMpub const BAMUM: Script = Script(7);The Bamum script, ISO 15924
Bamu.unicode::Script::BASSA_VAHpub const BASSA_VAH: Script = Script(8);The Bassa Vah script, ISO 15924
Bass.unicode::Script::BATAKpub const BATAK: Script = Script(9);The Batak script, ISO 15924
Batk.unicode::Script::BENGALIpub const BENGALI: Script = Script(10);The Bengali script, ISO 15924
Beng.unicode::Script::BERIA_ERFEpub const BERIA_ERFE: Script = Script(11);The Beria Erfe script, ISO 15924
Berf.unicode::Script::BHAIKSUKIpub const BHAIKSUKI: Script = Script(12);The Bhaiksuki script, ISO 15924
Bhks.unicode::Script::BOPOMOFOpub const BOPOMOFO: Script = Script(13);The Bopomofo script, ISO 15924
Bopo.unicode::Script::BRAHMIpub const BRAHMI: Script = Script(14);The Brahmi script, ISO 15924
Brah.unicode::Script::BRAILLEpub const BRAILLE: Script = Script(15);The Braille script, ISO 15924
Brai.unicode::Script::BUGINESEpub const BUGINESE: Script = Script(16);The Buginese script, ISO 15924
Bugi.unicode::Script::BUHIDpub const BUHID: Script = Script(17);The Buhid script, ISO 15924
Buhd.unicode::Script::CANADIAN_ABORIGINALpub const CANADIAN_ABORIGINAL: Script = Script(18);The Canadian Aboriginal script, ISO 15924
Cans.unicode::Script::CARIANpub const CARIAN: Script = Script(19);The Carian script, ISO 15924
Cari.unicode::Script::CAUCASIAN_ALBANIANpub const CAUCASIAN_ALBANIAN: Script = Script(20);The Caucasian Albanian script, ISO 15924
Aghb.unicode::Script::CHAKMApub const CHAKMA: Script = Script(21);The Chakma script, ISO 15924
Cakm.unicode::Script::CHAMpub const CHAM: Script = Script(22);The Cham script, ISO 15924
Cham.unicode::Script::CHEROKEEpub const CHEROKEE: Script = Script(23);The Cherokee script, ISO 15924
Cher.unicode::Script::CHORASMIANpub const CHORASMIAN: Script = Script(24);The Chorasmian script, ISO 15924
Chrs.unicode::Script::COMMONpub const COMMON: Script = Script(25);The Common script, ISO 15924
Zyyy, which holds the characters many scripts share, such as digits, spaces and punctuation.unicode::Script::COPTICpub const COPTIC: Script = Script(26);The Coptic script, ISO 15924
Copt.unicode::Script::CUNEIFORMpub const CUNEIFORM: Script = Script(27);The Cuneiform script, ISO 15924
Xsux.unicode::Script::CYPRIOTpub const CYPRIOT: Script = Script(28);The Cypriot script, ISO 15924
Cprt.unicode::Script::CYPRO_MINOANpub const CYPRO_MINOAN: Script = Script(29);The Cypro Minoan script, ISO 15924
Cpmn.unicode::Script::CYRILLICpub const CYRILLIC: Script = Script(30);The Cyrillic script, ISO 15924
Cyrl.unicode::Script::DESERETpub const DESERET: Script = Script(31);The Deseret script, ISO 15924
Dsrt.unicode::Script::DEVANAGARIpub const DEVANAGARI: Script = Script(32);The Devanagari script, ISO 15924
Deva.unicode::Script::DIVES_AKURUpub const DIVES_AKURU: Script = Script(33);The Dives Akuru script, ISO 15924
Diak.unicode::Script::DOGRApub const DOGRA: Script = Script(34);The Dogra script, ISO 15924
Dogr.unicode::Script::DUPLOYANpub const DUPLOYAN: Script = Script(35);The Duployan script, ISO 15924
Dupl.unicode::Script::EGYPTIAN_HIEROGLYPHSpub const EGYPTIAN_HIEROGLYPHS: Script = Script(36);The Egyptian Hieroglyphs script, ISO 15924
Egyp.unicode::Script::ELBASANpub const ELBASAN: Script = Script(37);The Elbasan script, ISO 15924
Elba.unicode::Script::ELYMAICpub const ELYMAIC: Script = Script(38);The Elymaic script, ISO 15924
Elym.unicode::Script::ETHIOPICpub const ETHIOPIC: Script = Script(39);The Ethiopic script, ISO 15924
Ethi.unicode::Script::GARAYpub const GARAY: Script = Script(40);The Garay script, ISO 15924
Gara.unicode::Script::GEORGIANpub const GEORGIAN: Script = Script(41);The Georgian script, ISO 15924
Geor.unicode::Script::GLAGOLITICpub const GLAGOLITIC: Script = Script(42);The Glagolitic script, ISO 15924
Glag.unicode::Script::GOTHICpub const GOTHIC: Script = Script(43);The Gothic script, ISO 15924
Goth.unicode::Script::GRANTHApub const GRANTHA: Script = Script(44);The Grantha script, ISO 15924
Gran.unicode::Script::GREEKpub const GREEK: Script = Script(45);The Greek script, ISO 15924
Grek.unicode::Script::GUJARATIpub const GUJARATI: Script = Script(46);The Gujarati script, ISO 15924
Gujr.unicode::Script::GUNJALA_GONDIpub const GUNJALA_GONDI: Script = Script(47);The Gunjala Gondi script, ISO 15924
Gong.unicode::Script::GURMUKHIpub const GURMUKHI: Script = Script(48);The Gurmukhi script, ISO 15924
Guru.unicode::Script::GURUNG_KHEMApub const GURUNG_KHEMA: Script = Script(49);The Gurung Khema script, ISO 15924
Gukh.unicode::Script::HANpub const HAN: Script = Script(50);The Han script, ISO 15924
Hani.unicode::Script::HANGULpub const HANGUL: Script = Script(51);The Hangul script, ISO 15924
Hang.unicode::Script::HANIFI_ROHINGYApub const HANIFI_ROHINGYA: Script = Script(52);The Hanifi Rohingya script, ISO 15924
Rohg.unicode::Script::HANUNOOpub const HANUNOO: Script = Script(53);The Hanunoo script, ISO 15924
Hano.unicode::Script::HATRANpub const HATRAN: Script = Script(54);The Hatran script, ISO 15924
Hatr.unicode::Script::HEBREWpub const HEBREW: Script = Script(55);The Hebrew script, ISO 15924
Hebr.unicode::Script::HIRAGANApub const HIRAGANA: Script = Script(56);The Hiragana script, ISO 15924
Hira.unicode::Script::IMPERIAL_ARAMAICpub const IMPERIAL_ARAMAIC: Script = Script(57);The Imperial Aramaic script, ISO 15924
Armi.unicode::Script::INHERITEDpub const INHERITED: Script = Script(58);The Inherited script, ISO 15924
Zinh, which holds combining marks that take the script of the character they are attached to.unicode::Script::INSCRIPTIONAL_PAHLAVIpub const INSCRIPTIONAL_PAHLAVI: Script = Script(59);The Inscriptional Pahlavi script, ISO 15924
Phli.unicode::Script::INSCRIPTIONAL_PARTHIANpub const INSCRIPTIONAL_PARTHIAN: Script = Script(60);The Inscriptional Parthian script, ISO 15924
Prti.unicode::Script::JAVANESEpub const JAVANESE: Script = Script(61);The Javanese script, ISO 15924
Java.unicode::Script::JURCHENpub const JURCHEN: Script = Script(62);The Jurchen script, ISO 15924
Jurc.unicode::Script::KAITHIpub const KAITHI: Script = Script(63);The Kaithi script, ISO 15924
Kthi.unicode::Script::KANNADApub const KANNADA: Script = Script(64);The Kannada script, ISO 15924
Knda.unicode::Script::KATAKANApub const KATAKANA: Script = Script(65);The Katakana script, ISO 15924
Kana.unicode::Script::KAWIpub const KAWI: Script = Script(66);The Kawi script, ISO 15924
Kawi.unicode::Script::KAYAH_LIpub const KAYAH_LI: Script = Script(67);The Kayah Li script, ISO 15924
Kali.unicode::Script::KHAROSHTHIpub const KHAROSHTHI: Script = Script(68);The Kharoshthi script, ISO 15924
Khar.unicode::Script::KHITAN_SMALL_SCRIPTpub const KHITAN_SMALL_SCRIPT: Script = Script(69);The Khitan Small Script, ISO 15924
Kits.unicode::Script::KHMERpub const KHMER: Script = Script(70);The Khmer script, ISO 15924
Khmr.unicode::Script::KHOJKIpub const KHOJKI: Script = Script(71);The Khojki script, ISO 15924
Khoj.unicode::Script::KHUDAWADIpub const KHUDAWADI: Script = Script(72);The Khudawadi script, ISO 15924
Sind.unicode::Script::KIRAT_RAIpub const KIRAT_RAI: Script = Script(73);The Kirat Rai script, ISO 15924
Krai.unicode::Script::LAOpub const LAO: Script = Script(74);The Lao script, ISO 15924
Laoo.unicode::Script::LATINpub const LATIN: Script = Script(75);The Latin script, ISO 15924
Latn.unicode::Script::LEPCHApub const LEPCHA: Script = Script(76);The Lepcha script, ISO 15924
Lepc.unicode::Script::LIMBUpub const LIMBU: Script = Script(77);The Limbu script, ISO 15924
Limb.unicode::Script::LINEAR_Apub const LINEAR_A: Script = Script(78);The Linear A script, ISO 15924
Lina.unicode::Script::LINEAR_Bpub const LINEAR_B: Script = Script(79);The Linear B script, ISO 15924
Linb.unicode::Script::LISUpub const LISU: Script = Script(80);The Lisu script, ISO 15924
Lisu.unicode::Script::LYCIANpub const LYCIAN: Script = Script(81);The Lycian script, ISO 15924
Lyci.unicode::Script::LYDIANpub const LYDIAN: Script = Script(82);The Lydian script, ISO 15924
Lydi.unicode::Script::MAHAJANIpub const MAHAJANI: Script = Script(83);The Mahajani script, ISO 15924
Mahj.unicode::Script::MAKASARpub const MAKASAR: Script = Script(84);The Makasar script, ISO 15924
Maka.unicode::Script::MALAYALAMpub const MALAYALAM: Script = Script(85);The Malayalam script, ISO 15924
Mlym.unicode::Script::MANDAICpub const MANDAIC: Script = Script(86);The Mandaic script, ISO 15924
Mand.unicode::Script::MANICHAEANpub const MANICHAEAN: Script = Script(87);The Manichaean script, ISO 15924
Mani.unicode::Script::MARCHENpub const MARCHEN: Script = Script(88);The Marchen script, ISO 15924
Marc.unicode::Script::MASARAM_GONDIpub const MASARAM_GONDI: Script = Script(89);The Masaram Gondi script, ISO 15924
Gonm.unicode::Script::MEDEFAIDRINpub const MEDEFAIDRIN: Script = Script(90);The Medefaidrin script, ISO 15924
Medf.unicode::Script::MEETEI_MAYEKpub const MEETEI_MAYEK: Script = Script(91);The Meetei Mayek script, ISO 15924
Mtei.unicode::Script::MENDE_KIKAKUIpub const MENDE_KIKAKUI: Script = Script(92);The Mende Kikakui script, ISO 15924
Mend.unicode::Script::MEROITIC_CURSIVEpub const MEROITIC_CURSIVE: Script = Script(93);The Meroitic Cursive script, ISO 15924
Merc.unicode::Script::MEROITIC_HIEROGLYPHSpub const MEROITIC_HIEROGLYPHS: Script = Script(94);The Meroitic Hieroglyphs script, ISO 15924
Mero.unicode::Script::MIAOpub const MIAO: Script = Script(95);The Miao script, ISO 15924
Plrd.unicode::Script::MODIpub const MODI: Script = Script(96);The Modi script, ISO 15924
Modi.unicode::Script::MONGOLIANpub const MONGOLIAN: Script = Script(97);The Mongolian script, ISO 15924
Mong.unicode::Script::MROpub const MRO: Script = Script(98);The Mro script, ISO 15924
Mroo.unicode::Script::MULTANIpub const MULTANI: Script = Script(99);The Multani script, ISO 15924
Mult.unicode::Script::MYANMARpub const MYANMAR: Script = Script(100);The Myanmar script, ISO 15924
Mymr.unicode::Script::NABATAEANpub const NABATAEAN: Script = Script(101);The Nabataean script, ISO 15924
Nbat.unicode::Script::NAG_MUNDARIpub const NAG_MUNDARI: Script = Script(102);The Nag Mundari script, ISO 15924
Nagm.unicode::Script::NANDINAGARIpub const NANDINAGARI: Script = Script(103);The Nandinagari script, ISO 15924
Nand.unicode::Script::NEW_TAI_LUEpub const NEW_TAI_LUE: Script = Script(104);The New Tai Lue script, ISO 15924
Talu.unicode::Script::NEWApub const NEWA: Script = Script(105);The Newa script, ISO 15924
Newa.unicode::Script::NKOpub const NKO: Script = Script(106);The Nko script, ISO 15924
Nkoo.unicode::Script::NUSHUpub const NUSHU: Script = Script(107);The Nushu script, ISO 15924
Nshu.unicode::Script::NYIAKENG_PUACHUE_HMONGpub const NYIAKENG_PUACHUE_HMONG: Script = Script(108);The Nyiakeng Puachue Hmong script, ISO 15924
Hmnp.unicode::Script::OGHAMpub const OGHAM: Script = Script(109);The Ogham script, ISO 15924
Ogam.unicode::Script::OL_CHIKIpub const OL_CHIKI: Script = Script(110);The Ol Chiki script, ISO 15924
Olck.unicode::Script::OL_ONALpub const OL_ONAL: Script = Script(111);The Ol Onal script, ISO 15924
Onao.unicode::Script::OLD_HUNGARIANpub const OLD_HUNGARIAN: Script = Script(112);The Old Hungarian script, ISO 15924
Hung.unicode::Script::OLD_ITALICpub const OLD_ITALIC: Script = Script(113);The Old Italic script, ISO 15924
Ital.unicode::Script::OLD_NORTH_ARABIANpub const OLD_NORTH_ARABIAN: Script = Script(114);The Old North Arabian script, ISO 15924
Narb.unicode::Script::OLD_PERMICpub const OLD_PERMIC: Script = Script(115);The Old Permic script, ISO 15924
Perm.unicode::Script::OLD_PERSIANpub const OLD_PERSIAN: Script = Script(116);The Old Persian script, ISO 15924
Xpeo.unicode::Script::OLD_SOGDIANpub const OLD_SOGDIAN: Script = Script(117);The Old Sogdian script, ISO 15924
Sogo.unicode::Script::OLD_SOUTH_ARABIANpub const OLD_SOUTH_ARABIAN: Script = Script(118);The Old South Arabian script, ISO 15924
Sarb.unicode::Script::OLD_TURKICpub const OLD_TURKIC: Script = Script(119);The Old Turkic script, ISO 15924
Orkh.unicode::Script::OLD_UYGHURpub const OLD_UYGHUR: Script = Script(120);The Old Uyghur script, ISO 15924
Ougr.unicode::Script::ORIYApub const ORIYA: Script = Script(121);The Oriya script, ISO 15924
Orya.unicode::Script::OSAGEpub const OSAGE: Script = Script(122);The Osage script, ISO 15924
Osge.unicode::Script::OSMANYApub const OSMANYA: Script = Script(123);The Osmanya script, ISO 15924
Osma.unicode::Script::PAHAWH_HMONGpub const PAHAWH_HMONG: Script = Script(124);The Pahawh Hmong script, ISO 15924
Hmng.unicode::Script::PALMYRENEpub const PALMYRENE: Script = Script(125);The Palmyrene script, ISO 15924
Palm.unicode::Script::PAU_CIN_HAUpub const PAU_CIN_HAU: Script = Script(126);The Pau Cin Hau script, ISO 15924
Pauc.unicode::Script::PHAGS_PApub const PHAGS_PA: Script = Script(127);The Phags Pa script, ISO 15924
Phag.unicode::Script::PHOENICIANpub const PHOENICIAN: Script = Script(128);The Phoenician script, ISO 15924
Phnx.unicode::Script::PROTO_CUNEIFORMpub const PROTO_CUNEIFORM: Script = Script(129);The Proto Cuneiform script, ISO 15924
Pcun.unicode::Script::PSALTER_PAHLAVIpub const PSALTER_PAHLAVI: Script = Script(130);The Psalter Pahlavi script, ISO 15924
Phlp.unicode::Script::REJANGpub const REJANG: Script = Script(131);The Rejang script, ISO 15924
Rjng.unicode::Script::RUNICpub const RUNIC: Script = Script(132);The Runic script, ISO 15924
Runr.unicode::Script::SAMARITANpub const SAMARITAN: Script = Script(133);The Samaritan script, ISO 15924
Samr.unicode::Script::SAURASHTRApub const SAURASHTRA: Script = Script(134);The Saurashtra script, ISO 15924
Saur.unicode::Script::SEALpub const SEAL: Script = Script(135);The Seal script, ISO 15924
Seal.unicode::Script::SHARADApub const SHARADA: Script = Script(136);The Sharada script, ISO 15924
Shrd.unicode::Script::SHAVIANpub const SHAVIAN: Script = Script(137);The Shavian script, ISO 15924
Shaw.unicode::Script::SIDDHAMpub const SIDDHAM: Script = Script(138);The Siddham script, ISO 15924
Sidd.unicode::Script::SIDETICpub const SIDETIC: Script = Script(139);The Sidetic script, ISO 15924
Sidt.unicode::Script::SIGNWRITINGpub const SIGNWRITING: Script = Script(140);The SignWriting script, ISO 15924
Sgnw.unicode::Script::SINHALApub const SINHALA: Script = Script(141);The Sinhala script, ISO 15924
Sinh.unicode::Script::SOGDIANpub const SOGDIAN: Script = Script(142);The Sogdian script, ISO 15924
Sogd.unicode::Script::SORA_SOMPENGpub const SORA_SOMPENG: Script = Script(143);The Sora Sompeng script, ISO 15924
Sora.unicode::Script::SOYOMBOpub const SOYOMBO: Script = Script(144);The Soyombo script, ISO 15924
Soyo.unicode::Script::SUNDANESEpub const SUNDANESE: Script = Script(145);The Sundanese script, ISO 15924
Sund.unicode::Script::SUNUWARpub const SUNUWAR: Script = Script(146);The Sunuwar script, ISO 15924
Sunu.unicode::Script::SYLOTI_NAGRIpub const SYLOTI_NAGRI: Script = Script(147);The Syloti Nagri script, ISO 15924
Sylo.unicode::Script::SYRIACpub const SYRIAC: Script = Script(148);The Syriac script, ISO 15924
Syrc.unicode::Script::TAGALOGpub const TAGALOG: Script = Script(149);The Tagalog script, ISO 15924
Tglg.unicode::Script::TAGBANWApub const TAGBANWA: Script = Script(150);The Tagbanwa script, ISO 15924
Tagb.unicode::Script::TAI_LEpub const TAI_LE: Script = Script(151);The Tai Le script, ISO 15924
Tale.unicode::Script::TAI_THAMpub const TAI_THAM: Script = Script(152);The Tai Tham script, ISO 15924
Lana.unicode::Script::TAI_VIETpub const TAI_VIET: Script = Script(153);The Tai Viet script, ISO 15924
Tavt.unicode::Script::TAI_YOpub const TAI_YO: Script = Script(154);The Tai Yo script, ISO 15924
Tayo.unicode::Script::TAKRIpub const TAKRI: Script = Script(155);The Takri script, ISO 15924
Takr.unicode::Script::TAMILpub const TAMIL: Script = Script(156);The Tamil script, ISO 15924
Taml.unicode::Script::TANGSApub const TANGSA: Script = Script(157);The Tangsa script, ISO 15924
Tnsa.unicode::Script::TANGUTpub const TANGUT: Script = Script(158);The Tangut script, ISO 15924
Tang.unicode::Script::TELUGUpub const TELUGU: Script = Script(159);The Telugu script, ISO 15924
Telu.unicode::Script::THAANApub const THAANA: Script = Script(160);The Thaana script, ISO 15924
Thaa.unicode::Script::THAIpub const THAI: Script = Script(161);The Thai script, ISO 15924
Thai.unicode::Script::TIBETANpub const TIBETAN: Script = Script(162);The Tibetan script, ISO 15924
Tibt.unicode::Script::TIFINAGHpub const TIFINAGH: Script = Script(163);The Tifinagh script, ISO 15924
Tfng.unicode::Script::TIRHUTApub const TIRHUTA: Script = Script(164);The Tirhuta script, ISO 15924
Tirh.unicode::Script::TODHRIpub const TODHRI: Script = Script(165);The Todhri script, ISO 15924
Todr.unicode::Script::TOLONG_SIKIpub const TOLONG_SIKI: Script = Script(166);The Tolong Siki script, ISO 15924
Tols.unicode::Script::TOTOpub const TOTO: Script = Script(167);The Toto script, ISO 15924
Toto.unicode::Script::TULU_TIGALARIpub const TULU_TIGALARI: Script = Script(168);The Tulu Tigalari script, ISO 15924
Tutg.unicode::Script::UGARITICpub const UGARITIC: Script = Script(169);The Ugaritic script, ISO 15924
Ugar.unicode::Script::VAIpub const VAI: Script = Script(170);The Vai script, ISO 15924
Vaii.unicode::Script::VITHKUQIpub const VITHKUQI: Script = Script(171);The Vithkuqi script, ISO 15924
Vith.unicode::Script::WANCHOpub const WANCHO: Script = Script(172);The Wancho script, ISO 15924
Wcho.unicode::Script::WARANG_CITIpub const WARANG_CITI: Script = Script(173);The Warang Citi script, ISO 15924
Wara.unicode::Script::YEZIDIpub const YEZIDI: Script = Script(174);The Yezidi script, ISO 15924
Yezi.unicode::Script::YIpub const YI: Script = Script(175);The Yi script, ISO 15924
Yiii.unicode::Script::ZANABAZAR_SQUAREpub const ZANABAZAR_SQUARE: Script = Script(176);The Zanabazar Square script, ISO 15924
Zanb.
Layout
Paragraphs laid out in lines: wrapped, broken, aligned, in either writing mode, and one line justified by a font's JSTF table. Font::layout and the types in daegun::layout, all in font units.
layout::LayoutOptions::DEFAULTpub const DEFAULT: LayoutOptions<'static>;The default options as a constant, the same value
LayoutOptions::default()returns.They set text in horizontal lines that end only at hard breaks:
LayoutOptionslists the default of every field. Everywith_method is aconst fn, so options of your own can be constants built from this one.use daegun::layout::{Align, LayoutOptions}; use daegun::Location; const CENTERED: LayoutOptions = LayoutOptions::DEFAULT.with_align(Align::Center); let layout = font.layout("Title\nA longer subtitle", &Location::default(), &CENTERED); // With no measure, the short line is centered against the long one. let (title, subtitle) = (&layout.lines[0], &layout.lines[1]); assert_eq!(title.runs[0].offset.x, (subtitle.inline_size - title.inline_size) / 2.0); assert!(LayoutOptions::DEFAULT.max_inline_size.is_infinite());
Outlines
A glyph's shape: as the font stores it in font units, hinted in pixels, or prepared for a rasterizer of your own, with the paths, pens, strokes, curves and polygons around it. The calls are on Font, and the rest is in daegun::outline.
outline::MAX_FLATTEN_POINTSpub const MAX_FLATTEN_POINTS: usize = 1_048_576;The most points
Path::flattenreturns, and the mostPath::stroke_simplifiedholds: 1,048,576.Past it both calls fail with
ErrorKind::LimitExceeded.Path::flattenalso gives up once it has read more than twice as many points, which counts those of contours it would leave out. The limit keeps a hostile or broken outline from asking for memory without end: at the finest setting one curve alone can become 4,096 edges.Glyphs flattened for the screen come nowhere near it: Inter's o at 32 px is 80 points.
Path::strokehas no such limit, as it sends each point to the pen as it works it out.use daegun::outline::{OutlinePen, Path, MAX_FLATTEN_POINTS}; use daegun::ErrorKind; // 300 curves, which at the finest setting come to more points than the limit. let mut wave = Path::new(); wave.move_to(0.0, 0.0); for i in 0..300 { let x = i as f32 * 10.0; wave.curve_to(x + 3.0, 50.0, x + 6.0, -50.0, x + 10.0, 0.0); } let refused = wave.flatten(0.0).map_err(|e| e.kind()); assert_eq!(refused, Err(ErrorKind::LimitExceeded)); // With a max_area of 1 the same path is 3,601 points, far under the limit. let points: usize = wave.flatten(1.0)?.iter().map(Vec::len).sum(); assert_eq!(points, 3601); assert!(points < MAX_FLATTEN_POINTS);outline::OutlineOptions::DEFAULTpub const DEFAULT: OutlineOptions;The default options as a constant: the outline as the font draws it, scaled to the size and nothing more.
No hinting, no transform, no stroke, no embolden and no oblique. It is the value
OutlineOptions::default()returns. Everywith_method is aconst fn, so options of your own can be constants too.use daegun::outline::{HintMode, OutlineOptions}; const HINTED: OutlineOptions = OutlineOptions::DEFAULT.with_hinting(HintMode::Auto); assert_eq!(OutlineOptions::DEFAULT, OutlineOptions::default()); assert_eq!(OutlineOptions::DEFAULT.hinting, HintMode::None); assert_eq!(HINTED.hinting, HintMode::Auto);
Color
Color glyphs: bitmap strikes, COLR layers and palettes, paint graphs and the scenes made from them, and the color math to sample a gradient and composite a layer. The calls are on Font, and the rest is in daegun::color.
color::IDENTITYpub const IDENTITY: Matrix = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0];The matrix that leaves every point where it is.
Pass it wherever a call wants a
Matrixand you have no transform to apply: as thetransformofGradient::new, as theto_deviceofRamp::newwhen the gradient is already in pixels, or as thectmofcolor::lowerto keep a scene in font units.use daegun::color::{concat, IDENTITY}; let double = [2.0, 0.0, 0.0, 2.0, 0.0, 0.0]; // Chained with any matrix, on either side, it changes nothing. assert_eq!(concat(&double, &IDENTITY), double); assert_eq!(concat(&IDENTITY, &double), double);color::SceneOptions::DEFAULTpub const DEFAULT: SceneOptions = SceneOptions { palette: 0, foreground: Rgba { r: 0, g: 0, b: 0, a: 255 } };The default options as a constant: palette 0 and opaque black text, the value
SceneOptions::default()returns.Being a constant,
&SceneOptions::DEFAULTcan be passed straight toFont::color_scene, with no variable to hold it. Bothwith_methods areconst fn, so options of your own can be constants too.use daegun::color::{Rgba, SceneOptions}; const ON_DARK: SceneOptions = SceneOptions::DEFAULT.with_foreground(Rgba::opaque(255, 255, 255)); assert_eq!(SceneOptions::DEFAULT, SceneOptions::default()); assert_eq!(SceneOptions::DEFAULT.palette, 0); assert_eq!(SceneOptions::DEFAULT.foreground, Rgba::opaque(0, 0, 0)); assert_eq!(ON_DARK.palette, 0);
Raw tables
Font data at the byte level, for tools that read or write a table daegun has no call for: reads and writes that never panic, the structures several tables share, loca and glyf, and building a font file from its tables. In daegun::raw.
raw::format::class::DELETED_GLYPHpub const DELETED_GLYPH: u16 = 2;The class of glyph 0xFFFF, the mark an AAT table leaves where it has deleted a glyph: class 2 of every state table.
An AAT state table sorts glyphs into classes, and its machine reads an entry by the state it is in and the class of the glyph it meets. The first classes are the same in every table, ahead of the font's own, and daegun names two of them: this one and
END_OF_TEXT. Class 1 means out of bounds, a glyph the class table does not list, andStateTable::classanswers it as the plain number 1.A
morxsubtable deletes a glyph by turning it into glyph 0xFFFF, which stays in the run until the whole table has been applied, so later subtables still meet it and can act on its class.StateTable::classanswers this class for glyph 0xFFFF without reading the class table.use daegun::raw::bytes::read_u32_be; use daegun::raw::format::{class, state, StateTable}; use daegun::Tag; let morx = font.table(Tag::new(b"morx")).ok_or("no morx")?; // This test font's one morx subtable starts at byte 48, and its state table 12 bytes after that. let length = read_u32_be(morx, 48).ok_or("morx cut short")? as usize; let body = morx.get(60..48 + length).ok_or("morx cut short")?; let table = StateTable::parse(body, 2, font.glyph_count())?; // The deleted glyph has its own class, and the start state has an entry for it like any other class. assert_eq!(table.class(0xFFFF), class::DELETED_GLYPH); assert!(table.entry(state::START_OF_TEXT, class::DELETED_GLYPH).is_some()); // A glyph the class table does not list is out of bounds, class 1. assert_eq!(table.class(1000), 1);raw::format::class::END_OF_TEXTpub const END_OF_TEXT: u16 = 0;The class an AAT state machine is given once the text has run out: class 0 of every state table.
An AAT state table sorts glyphs into classes, and
StateTable::classgives the class of each glyph the machine meets. After the last glyph of a run the machine takes one more step, so a table can finish what it began. No glyph is left to take a class from, so that step reads the entry for this class: callStateTable::entrywith the state the machine is in andEND_OF_TEXT.use daegun::raw::bytes::read_u32_be; use daegun::raw::format::{class, state, StateTable}; use daegun::Tag; let morx = font.table(Tag::new(b"morx")).ok_or("no morx")?; // This test font's one morx subtable starts at byte 48, and its state table 12 bytes after that. let length = read_u32_be(morx, 48).ok_or("morx cut short")? as usize; let body = morx.get(60..48 + length).ok_or("morx cut short")?; let table = StateTable::parse(body, 2, font.glyph_count())?; // Walk the glyphs of "AB", then take the last step with the end-of-text class. let mut current = state::START_OF_TEXT; for c in ['A', 'B'] { let glyph = font.glyph_id(c).ok_or("no glyph")?; let entry = table.entry(current, table.class(glyph.0)).ok_or("no entry")?; // A driver acts on the entry here: its flags and extra words say what to do, and whether to // stay on this glyph. current = entry.new_state; } let last = table.entry(current, class::END_OF_TEXT).ok_or("no entry")?; assert_eq!((last.new_state, last.flags), (0, 0));raw::format::state::START_OF_TEXTpub const START_OF_TEXT: u16 = 0;The state an AAT state machine starts in: state 0 of every state table.
Pass it to
StateTable::entryfor the first glyph of a run, with the classStateTable::classgives that glyph. Each entry then names the state for the next glyph inEntry::new_state.use daegun::raw::bytes::read_u32_be; use daegun::raw::format::{state, StateTable}; use daegun::Tag; let morx = font.table(Tag::new(b"morx")).ok_or("no morx")?; // This test font's one morx subtable starts at byte 48, and its state table 12 bytes after that. let length = read_u32_be(morx, 48).ok_or("morx cut short")? as usize; let body = morx.get(60..48 + length).ok_or("morx cut short")?; let table = StateTable::parse(body, 2, font.glyph_count())?; // The first glyph of a run is met in the start state. let first = font.glyph_id('A').ok_or("no A")?; let entry = table.entry(state::START_OF_TEXT, table.class(first.0)).ok_or("no entry")?; // In this font an A leaves the machine in the start state. assert_eq!(entry.new_state, state::START_OF_TEXT);
Rasterizing
daegun's own rasterizer, which turns glyphs and paths into pixels, and what any rasterizer needs beyond outlines: subpixel layouts with their filters, and an atlas packer. In daegun::raster.
raster::MAX_DRAW_BYTESpub const MAX_DRAW_BYTES: usize = 1 << 28;The most bytes a draw that lends its image may hold in its buffers, the image among them: 2^28, which is 256 MiB.
Drawing takes working memory beside the image. Plain coverage keeps 9 bytes for each pixel while it works, next to the one byte of the image, so a glyph or a path reaches this limit at about 26 million pixels, long before both sides reach
MAX_SIDE. A subpixel layout, a distance field and above all a multi-channel one, and a color glyph with its layers each keep more for a pixel and reach it sooner.A draw that would pass the limit fails with
ErrorKind::LimitExceeded. The image and the working buffers are counted before they are allocated, so a refused draw never allocates them. It applies toRasterizer::glyph,Rasterizer::color_glyph,Rasterizer::distance_fieldandRasterizer::path. The calls that draw into aTargetwork a band of rows at a time within a small fixed size, and have no such limit.use daegun::raster::{RasterOptions, Rasterizer, MAX_DRAW_BYTES, MAX_SIDE}; use daegun::{ErrorKind, Location}; let mut rasterizer = Rasterizer::new(); let glyph = font.glyph_id('H').expect("the font maps H"); let (at, options) = (Location::default(), RasterOptions::DEFAULT); // At 9,000 px Inter's H is 5,107 by 6,548 pixels: within MAX_SIDE each way, but at 10 bytes a pixel // it would hold more than MAX_DRAW_BYTES. assert_eq!(MAX_DRAW_BYTES, 1 << 28); let lent = rasterizer.glyph(&font, glyph, &at, 9_000.0, &options); assert_eq!(lent.map(drop).map_err(|e| e.kind()), Err(ErrorKind::LimitExceeded));raster::MAX_OVERSAMPLEpub const MAX_OVERSAMPLE: u8 = 4;The most samples a layout takes for each pixel, in either direction.
SubpixelLayout::from_weightsrefuses anoversampleabove it, or one of 0, withErrorKind::InvalidArgument. The layouts daegun builds stay inside it: they take 3 one way and 1 the other.use daegun::raster::{SubpixelLayout, MAX_OVERSAMPLE}; use daegun::ErrorKind; let one = [1.0]; let weights: [&[f32]; 3] = [&one, &one, &one]; // Four samples across a pixel is the most a layout takes. let most = SubpixelLayout::from_weights((MAX_OVERSAMPLE, 1), (1, 1), (0, 0), weights)?; assert_eq!(most.oversample(), (4, 1)); let over = SubpixelLayout::from_weights((MAX_OVERSAMPLE + 1, 1), (1, 1), (0, 0), weights); assert_eq!(over.unwrap_err().kind(), ErrorKind::InvalidArgument);raster::MAX_SIDEpub const MAX_SIDE: u32 = 1 << 14;The most pixels an image a rasterizer lends may be across or down: 16,384.
A draw whose image would be wider or taller fails with
ErrorKind::LimitExceededbefore its pixels are allocated. That holds forRasterizer::glyph,Rasterizer::color_glyph,Rasterizer::distance_fieldandRasterizer::path. In practiceMAX_DRAW_BYTESstops a draw earlier, as an image this large on both sides would hold far more than that.The calls that draw into a
Targethave no such limit: the target is yours, of any size, and can cover any part of a drawing however large the whole would be.use daegun::raster::{RasterOptions, Rasterizer, Target, MAX_SIDE}; use daegun::{ErrorKind, Location}; let mut rasterizer = Rasterizer::new(); let glyph = font.glyph_id('H').expect("the font maps H"); let (at, options) = (Location::default(), RasterOptions::DEFAULT); // At 40,000 px Inter's H is 29,102 pixels tall, past MAX_SIDE, so it cannot be lent. assert_eq!(MAX_SIDE, 16_384); let lent = rasterizer.glyph(&font, glyph, &at, 40_000.0, &options); assert_eq!(lent.map(drop).map_err(|e| e.kind()), Err(ErrorKind::LimitExceeded)); // A target takes any part of it. These 64 by 16 pixels lie inside its left stem. let mut pixels = vec![0u8; 64 * 16]; let target = Target::new(4_000, 10_000, 64, 16, 64, &mut pixels); rasterizer.glyph_into(&font, glyph, &at, 40_000.0, &options, target)?; assert!(pixels.iter().all(|&coverage| coverage == 255));raster::MAX_TAPSpub const MAX_TAPS: usize = MAX_OVERSAMPLE as usize + 4;The most taps a layout's filter has, in either direction.
It bounds each number in the
tapsofSubpixelLayout::from_weights, which answersErrorKind::InvalidArgumentpast it. Its value isMAX_OVERSAMPLEplus 4: room for every sample of a pixel at the highest oversampling, and two more on each side.It is a
usize, where the taps themselves areu8.use daegun::raster::{SubpixelLayout, MAX_OVERSAMPLE, MAX_TAPS}; // The widest window: all four samples of a pixel, and two more on each side. let taps = u8::try_from(MAX_TAPS)?; let channel = vec![1.0 / f32::from(taps); MAX_TAPS]; let weights = [&channel[..], &channel[..], &channel[..]]; let wide = SubpixelLayout::from_weights((MAX_OVERSAMPLE, 1), (taps, 1), (-2, 0), weights)?; assert_eq!((wide.oversample(), wide.taps(), wide.pad()), ((4, 1), (8, 1), (1, 0))); // One tap more is refused. let channel = vec![0.0; MAX_TAPS + 1]; let weights = [&channel[..], &channel[..], &channel[..]]; assert!(SubpixelLayout::from_weights((MAX_OVERSAMPLE, 1), (taps + 1, 1), (-2, 0), weights).is_err());raster::MAX_WEIGHTSpub const MAX_WEIGHTS: usize = MAX_TAPS * MAX_TAPS;The most weights one channel of a filter has:
MAX_TAPSsquared.A channel has
taps.0 * taps.1weights, so this is the longest sliceSubpixelLayout::from_weightstakes for a channel and the longestSubpixelLayout::weightsreturns. A layout stores its weights inline, with room for this many in each of three channels, so building or copying one allocates nothing.use daegun::raster::{StripeOrder, SubpixelLayout, MAX_WEIGHTS}; // A fixed buffer that holds one channel of any layout. let mut buffer = [0.0f32; MAX_WEIGHTS]; let lcd = SubpixelLayout::horizontal(StripeOrder::Rgb); let red = lcd.weights(0).expect("a stripe layout has three channels"); buffer[..red.len()].copy_from_slice(red); assert_eq!(red.len(), 7);raster::RasterOptions::DEFAULTpub const DEFAULT: RasterOptions<'static>;The default options as a constant, the same value
RasterOptions::default()returns.Field by field:
outlineisOutlineOptions::DEFAULT, so no hinting, no transform, no stroke, no embolden and no oblique.offsetis[0.0, 0.0], the origin of the glyph on a pixel corner.layoutisSubpixelLayout::grayscale, one byte of coverage a pixel.darkenis false.gammaisGamma::Linear, coverage as it is.Being a constant,
&RasterOptions::DEFAULTborrows one static value, and since everywith_method is aconst fn, options of your own can be constants too.use daegun::outline::OutlineOptions; use daegun::raster::{Gamma, RasterOptions}; // A constant of your own: the defaults with stem darkening on. const SMALL_TEXT: RasterOptions = RasterOptions::DEFAULT.with_darken(true); assert!(SMALL_TEXT.darken); let defaults = RasterOptions::DEFAULT; assert_eq!(defaults.outline, OutlineOptions::DEFAULT); assert_eq!(defaults.offset, [0.0, 0.0]); assert!(defaults.layout.is_grayscale()); assert!(!defaults.darken); assert_eq!(defaults.gamma, Gamma::Linear); assert_eq!(defaults, RasterOptions::default());