Skip to content

Commit c336113

Browse files
committed
[TTF] Flip glyph coordinate system by ascent, not by em-square-units
1 parent 2b032a2 commit c336113

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

rust_programs/ttf_renderer/src/glyphs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::metrics::{GlyphRenderMetrics, LongHorMetric, VerticalMetrics};
1+
use crate::metrics::{FontGlobalLayoutMetrics, GlyphRenderMetrics, LongHorMetric, VerticalMetrics};
22
use crate::parse_utils::{BigEndianValue, FromFontBufInPlace, TransmuteFontBufInPlace};
33
use crate::parser::FontParser;
44
use crate::println;
@@ -401,7 +401,7 @@ pub(crate) fn parse_glyph(
401401
parser: &FontParser,
402402
glyph_index: usize,
403403
all_glyphs_bounding_box: &Rect,
404-
units_per_em: usize,
404+
font_layout_metrics: &FontGlobalLayoutMetrics,
405405
) -> GlyphRenderDescription {
406406
let glyph_header = parser.table_headers.get("glyf").unwrap();
407407
let (glyph_local_offset, glyph_data_length) = get_glyph_offset_and_length(parser, glyph_index);
@@ -469,7 +469,7 @@ pub(crate) fn parse_glyph(
469469
flag_count_to_parse -= 1;
470470
}
471471

472-
// Parse X coordinates
472+
// Parse coordinates
473473
let x_values =
474474
interpret_values_via_flags(parser, &mut cursor, &all_flags, CoordinateComponentType::X);
475475
let y_values =
@@ -478,7 +478,7 @@ pub(crate) fn parse_glyph(
478478
.iter()
479479
.zip(y_values.iter())
480480
// Flip the Y axis of every point to match our coordinate system
481-
.map(|(&x, &y)| PointF64::new(x as _, (units_per_em as isize - y) as _))
481+
.map(|(&x, &y)| PointF64::new(x as _, (font_layout_metrics.ascent - y) as _))
482482
.collect();
483483

484484
// Split the total collection of points into polygons, using the last-point-indexes that

rust_programs/ttf_renderer/src/lib.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(target_os = "axle", no_std)]
1+
#![cfg_attr(any(target_os = "axle", feature = "no_std"), no_std)]
22
#![feature(core_intrinsics)]
33
#![feature(slice_ptr_get)]
44
#![feature(format_args_nl)]
@@ -17,19 +17,22 @@ mod render_context;
1717

1818
pub use crate::glyphs::{GlyphRenderDescription, GlyphRenderInstructions};
1919
pub use crate::metrics::GlyphMetrics;
20-
pub use crate::render::{render_antialiased_glyph_onto, render_char_onto, render_glyph_onto};
20+
pub use crate::render::{
21+
render_antialiased_glyph_onto, render_char_onto, render_glyph_onto, rendered_string_size,
22+
};
2123
pub use crate::render_context::FontRenderContext;
22-
use agx_definitions::Rect;
24+
use agx_definitions::{Rect, Size};
2325
use alloc::collections::BTreeMap;
2426
use alloc::string::{String, ToString};
2527
use alloc::vec::Vec;
2628
use core::fmt::{Display, Formatter};
2729
use parser::FontParser;
2830

2931
use crate::hints::FunctionDefinition;
30-
#[cfg(target_os = "axle")]
32+
use crate::metrics::FontGlobalLayoutMetrics;
33+
#[cfg(any(target_os = "axle", feature = "no_std"))]
3134
pub(crate) use axle_rt::{print, println};
32-
#[cfg(not(target_os = "axle"))]
35+
#[cfg(not(any(target_os = "axle", feature = "no_std")))]
3336
pub(crate) use std::{print, println};
3437

3538
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]

rust_programs/ttf_renderer/src/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl<'a> FontParser<'a> {
354354
let mut all_glyphs = vec![];
355355
let mut codepoints_to_glyph_indexes = BTreeMap::new();
356356
for i in 0..max_profile.num_glyphs {
357-
let parsed_glyph = parse_glyph(self, i, &glyph_bounding_box, head.units_per_em as _);
357+
let parsed_glyph = parse_glyph(self, i, &glyph_bounding_box, &horizontal_glyph_metrics);
358358
all_glyphs.push(parsed_glyph);
359359

360360
match glyph_indexes_to_codepoints.get(&i) {

0 commit comments

Comments
 (0)