mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Simplify
This commit is contained in:
@@ -9,7 +9,7 @@ use crate::{
|
|||||||
stroke::PathStroke,
|
stroke::PathStroke,
|
||||||
text::{
|
text::{
|
||||||
TAB_SIZE,
|
TAB_SIZE,
|
||||||
font::{StyledMetrics, is_cjk, is_cjk_break_allowed},
|
font::{StyledMetrics, UvRect, is_cjk, is_cjk_break_allowed},
|
||||||
fonts::FontFaceKey,
|
fonts::FontFaceKey,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -182,6 +182,31 @@ struct ShapingContext {
|
|||||||
prev_cluster: Option<u32>,
|
prev_cluster: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ShapingContext {
|
||||||
|
fn glyph(
|
||||||
|
&self,
|
||||||
|
chr: char,
|
||||||
|
physical_x: i32,
|
||||||
|
advance_width_px: f32,
|
||||||
|
face_metrics: &StyledMetrics,
|
||||||
|
uv_rect: UvRect,
|
||||||
|
) -> Glyph {
|
||||||
|
Glyph {
|
||||||
|
chr,
|
||||||
|
pos: pos2(physical_x as f32 / self.pixels_per_point, f32::NAN),
|
||||||
|
advance_width: advance_width_px / self.pixels_per_point,
|
||||||
|
line_height: self.line_height,
|
||||||
|
font_face_height: face_metrics.row_height,
|
||||||
|
font_face_ascent: face_metrics.ascent,
|
||||||
|
font_height: self.font_metrics.row_height,
|
||||||
|
font_ascent: self.font_metrics.ascent,
|
||||||
|
uv_rect,
|
||||||
|
section_index: self.section_index,
|
||||||
|
first_vertex: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Produced by [`Font::segment_into_runs`] for text shaping.
|
/// Produced by [`Font::segment_into_runs`] for text shaping.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct TextRun {
|
struct TextRun {
|
||||||
@@ -222,7 +247,7 @@ fn layout_shaped_run(
|
|||||||
let chr = run_text
|
let chr = run_text
|
||||||
.get(cluster as usize..)
|
.get(cluster as usize..)
|
||||||
.and_then(|s| s.chars().next())
|
.and_then(|s| s.chars().next())
|
||||||
.unwrap_or('\u{FFFD}');
|
.unwrap_or('\u{FFFD}'); // Unicode Replacement Character
|
||||||
|
|
||||||
// Tab is a layout concept, not a glyph — the shaper doesn't know about tab stops.
|
// Tab is a layout concept, not a glyph — the shaper doesn't know about tab stops.
|
||||||
// Override the advance width to TAB_SIZE × space width.
|
// Override the advance width to TAB_SIZE × space width.
|
||||||
@@ -243,7 +268,7 @@ fn layout_shaped_run(
|
|||||||
}
|
}
|
||||||
ctx.prev_cluster = Some(cluster);
|
ctx.prev_cluster = Some(cluster);
|
||||||
|
|
||||||
if glyph_id == skrifa::GlyphId::NOTDEF {
|
let glyph = if glyph_id == skrifa::GlyphId::NOTDEF {
|
||||||
// The shaper couldn't map this character. Drop combining marks
|
// The shaper couldn't map this character. Drop combining marks
|
||||||
// (Unicode category M) and duplicate NOTDEF glyphs within the same
|
// (Unicode category M) and duplicate NOTDEF glyphs within the same
|
||||||
// cluster — only the first base character gets a replacement glyph.
|
// cluster — only the first base character gets a replacement glyph.
|
||||||
@@ -277,20 +302,15 @@ fn layout_shaped_run(
|
|||||||
Default::default()
|
Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
paragraph.glyphs.push(Glyph {
|
|
||||||
chr,
|
|
||||||
pos: pos2(physical_x as f32 / ctx.pixels_per_point, f32::NAN),
|
|
||||||
advance_width: advance_width_px / ctx.pixels_per_point,
|
|
||||||
line_height: ctx.line_height,
|
|
||||||
font_face_height: fallback_metrics.row_height,
|
|
||||||
font_face_ascent: fallback_metrics.ascent,
|
|
||||||
font_height: ctx.font_metrics.row_height,
|
|
||||||
font_ascent: ctx.font_metrics.ascent,
|
|
||||||
uv_rect: glyph_alloc.uv_rect,
|
|
||||||
section_index: ctx.section_index,
|
|
||||||
first_vertex: 0,
|
|
||||||
});
|
|
||||||
paragraph.cursor_x_px += advance_width_px;
|
paragraph.cursor_x_px += advance_width_px;
|
||||||
|
|
||||||
|
ctx.glyph(
|
||||||
|
chr,
|
||||||
|
physical_x,
|
||||||
|
advance_width_px,
|
||||||
|
&fallback_metrics,
|
||||||
|
glyph_alloc.uv_rect,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
let (mut glyph_alloc, physical_x) =
|
let (mut glyph_alloc, physical_x) =
|
||||||
if let Some(ff) = font.fonts_by_id.get_mut(&run.font_key) {
|
if let Some(ff) = font.fonts_by_id.get_mut(&run.font_key) {
|
||||||
@@ -311,21 +331,17 @@ fn layout_shaped_run(
|
|||||||
// is not part of the cached ShapedGlyph / GlyphAllocation.
|
// is not part of the cached ShapedGlyph / GlyphAllocation.
|
||||||
glyph_alloc.uv_rect.offset.y += y_offset_px / ctx.pixels_per_point;
|
glyph_alloc.uv_rect.offset.y += y_offset_px / ctx.pixels_per_point;
|
||||||
|
|
||||||
paragraph.glyphs.push(Glyph {
|
|
||||||
chr,
|
|
||||||
pos: pos2(physical_x as f32 / ctx.pixels_per_point, f32::NAN),
|
|
||||||
advance_width: advance_width_px / ctx.pixels_per_point,
|
|
||||||
line_height: ctx.line_height,
|
|
||||||
font_face_height: face_metrics.row_height,
|
|
||||||
font_face_ascent: face_metrics.ascent,
|
|
||||||
font_height: ctx.font_metrics.row_height,
|
|
||||||
font_ascent: ctx.font_metrics.ascent,
|
|
||||||
uv_rect: glyph_alloc.uv_rect,
|
|
||||||
section_index: ctx.section_index,
|
|
||||||
first_vertex: 0,
|
|
||||||
});
|
|
||||||
paragraph.cursor_x_px += advance_width_px;
|
paragraph.cursor_x_px += advance_width_px;
|
||||||
}
|
|
||||||
|
ctx.glyph(
|
||||||
|
chr,
|
||||||
|
physical_x,
|
||||||
|
advance_width_px,
|
||||||
|
face_metrics,
|
||||||
|
glyph_alloc.uv_rect,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
paragraph.glyphs.push(glyph);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user