text example in linja pona font

This commit is contained in:
marceline-cramer 2022-07-16 14:06:06 -06:00
parent 50543d876a
commit d4591ddbb9
3 changed files with 15 additions and 17 deletions

BIN
src/linja-pona-4.9.otf Normal file

Binary file not shown.

View File

@ -0,0 +1,6 @@
The linja pona font for the sitelen pona toki pona writing system was created by
David A Roberts and is licensed under the CC-BY-4.0 license.
license link: https://creativecommons.org/licenses/by/4.0/
website: http://musilili.net/linja-pona/
github: https://github.com/davidar/linja-pona

View File

@ -12,7 +12,7 @@ use allsorts::tables::{FontTableProvider, SfntVersion};
use allsorts::{tag, Font};
use std::collections::HashMap;
const TEXT_SCALE: f32 = 0.00005;
const TEXT_SCALE: f32 = 0.0001;
pub struct GlyphCache {
glyphs: HashMap<u16, CachedGlyph>,
@ -75,24 +75,16 @@ pub struct DummyText {
impl Default for DummyText {
fn default() -> Self {
// if you're looking at this for whatever reason, forgive the mess,
// Arabic rendering is misbehaving
let script = tag::ARAB;
let buffer = include_bytes!("/usr/share/fonts/TTF/Hack-Regular.ttf");
let buffer = include_bytes!("/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc");
let buffer = include_bytes!("/usr/share/fonts/misc/ter-u16n.otb");
let buffer = include_bytes!("/usr/share/fonts/noto/NotoNastaliqUrdu-Regular.ttf");
// let buffer = include_bytes!("/usr/share/fonts/noto/NotoSansArabic-Regular.ttf");
// let buffer = include_bytes!("/usr/share/fonts/noto/NotoKufiArabic-Regular.ttf");
// let buffer = include_bytes!("/usr/share/fonts/noto/NotoNaskhArabic-Regular.ttf");
let script = tag::LATN;
let buffer = include_bytes!("linja-pona-4.9.otf");
let buffer = buffer.as_slice();
let scope = ReadScope::new(&buffer);
let font_file = scope.read::<FontData<'_>>().unwrap();
let provider = font_file.table_provider(0).unwrap();
let mut font = Font::new(provider).unwrap().unwrap();
let text = "نص حكيم له سر قاطع وذو شأن عظيم مكتوب على ثوب أخضر ومغلف بجلد أزرق";
let glyphs = font.map_glyphs(text, script, MatchingPresentation::NotRequired);
let text = "toki o! nimi mi li [_mun_alasa_sona]. toki+pona li pona.";
let glyphs = font.map_glyphs(&text, script, MatchingPresentation::Required);
let mut cache = GlyphCache::new();
@ -127,14 +119,14 @@ impl Default for DummyText {
panic!("no glyf or CFF table");
}
let lang_tag = Some(tag::URD);
let features = allsorts::gsub::Features::Mask(allsorts::gsub::FeatureMask::all());
let lang_tag = None;
let features = allsorts::gsub::Features::default();
let kerning = true;
let infos = font
.shape(glyphs, script, lang_tag, &features, kerning)
.unwrap();
let direction = TextDirection::RightToLeft;
let direction = TextDirection::LeftToRight;
let vertical = false;
let mut layout = GlyphLayout::new(&mut font, &infos, direction, vertical);
let positions = layout.glyph_positions().unwrap();
@ -161,7 +153,7 @@ impl Default for DummyText {
let yoff = (ypos as f32) * TEXT_SCALE;
for v in glyph.vertices.iter() {
let x = v.position.x + xoff + 0.5;
let x = v.position.x + xoff - 0.9;
let y = v.position.y + yoff + 0.5;
mesh.vertices.push(MeshVertex {
position: canary_types::Vec2 { x, y },