Start work on emoji

WIP
This commit is contained in:
Raph Levien 2021-08-20 12:20:27 -07:00
parent 9cab8b8131
commit 02ee369428
3 changed files with 12 additions and 3 deletions

View file

@ -192,7 +192,7 @@ fn render_text_test(rc: &mut impl RenderContext) {
//rc.transform(Affine::new([0.2, 0.0, 0.0, -0.2, 200.0, 800.0]));
let layout = rc
.text()
.new_text_layout("hello piet-gpu text!")
.new_text_layout("\u{1f600}hello piet-gpu text!")
.default_attribute(TextAttribute::FontSize(100.0))
.build()
.unwrap();

View file

@ -492,7 +492,7 @@ impl PietGpuRenderContext {
pub(crate) fn append_path_encoder(&mut self, path: &PathEncoder) {
let elements = path.elements();
self.elements.extend(elements.iter().cloned());
self.pathseg_count += elements.len();
self.pathseg_count += path.n_segs();
}
pub(crate) fn fill_glyph(&mut self, rgba_color: u32) {

View file

@ -16,7 +16,7 @@ use crate::render_ctx::{self, FillMode};
use crate::PietGpuRenderContext;
// This is very much a hack to get things working.
const FONT_DATA: &[u8] = include_bytes!("../third-party/Roboto-Regular.ttf");
const FONT_DATA: &[u8] = include_bytes!("c:\\Windows\\Fonts\\seguiemj.ttf");
#[derive(Clone)]
pub struct Font {
@ -53,6 +53,9 @@ struct Glyph {
#[derive(Default)]
pub struct PathEncoder {
elements: Vec<Element>,
n_segs: usize,
// If this is zero, then it's a text glyph and should be followed by a fill
n_colr_layers: usize,
}
impl PietGpuText {
@ -128,6 +131,7 @@ impl Font {
let mut scale_context = ScaleContext::new();
let mut scaler = scale_context.builder(self.font_ref).size(2048.).build();
let mut encoder = PathEncoder::default();
println!("glyph {} has_color_outlines {}", glyph_id, scaler.has_color_outlines());
if let Some(outline) = scaler.scale_outline(glyph_id) {
let verbs = outline.verbs();
let points = outline.points();
@ -186,6 +190,7 @@ impl Font {
}
}
}
encoder.n_segs = encoder.elements.len();
encoder
}
}
@ -307,6 +312,10 @@ impl PathEncoder {
pub(crate) fn elements(&self) -> &[Element] {
&self.elements
}
pub(crate) fn n_segs(&self) -> usize {
self.n_segs
}
}
fn convert_swash_point(v: Vector) -> [f32; 2] {