Skip to content

Commit

Permalink
Workaround new text renderer (#467)
Browse files Browse the repository at this point in the history
* add time markers

* workaround wip

* rename to render_data

* content into layout

* breakline as spanelement

* line number

* part one: compute shape by line

* update

* todo: fix clusters

* correct last line

* wip correction on clusters

* correction

* clustering support

* avoid compute total x since break_without_advance_or_alignment doesn't care

* correct line height calculation

* update lint
  • Loading branch information
raphamorim authored Mar 7, 2024
1 parent 3efc8e9 commit bb0c4c3
Show file tree
Hide file tree
Showing 11 changed files with 531 additions and 355 deletions.
15 changes: 8 additions & 7 deletions sugarloaf/src/components/rich_text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl RichTextBrush {

let dimensions = fetch_dimensions(
&mut self.comp,
&state.compositors.advanced.render_data_sugar,
&state.compositors.advanced.mocked_render_data,
state.compositors.advanced.font_library(),
);
if dimensions.0 > 0. && dimensions.1 > 0. {
Expand Down Expand Up @@ -704,15 +704,15 @@ impl RichTextBrush {
#[inline]
fn draw_layout(
comp: &mut compositor::Compositor,
layout: &crate::layout::Paragraph,
render_data: &crate::layout::RenderData,
x: f32,
y: f32,
font_library: &FontLibrary,
_rect: SugarDimensions,
) {
let depth = 0.0;
let mut glyphs = Vec::new();
for line in layout.lines() {
for line in render_data.lines() {
let mut px = x + line.offset();
for run in line.runs() {
let font = run.font();
Expand Down Expand Up @@ -763,20 +763,21 @@ fn draw_layout(
#[inline]
fn fetch_dimensions(
comp: &mut compositor::Compositor,
layout: &crate::layout::Paragraph,
render_data: &crate::layout::RenderData,
font_library: &FontLibrary,
) -> (f32, f32) {
let x = 0.;
let y = 0.;
let mut glyphs = Vec::with_capacity(3);
let mut sugarwidth = 0.0;
let mut sugarheight = 0.0;
for line in layout.lines() {
for line in render_data.lines() {
let mut px = x + line.offset();
for run in line.runs() {
let font = run.font();
let py = line.baseline() + y;
let run_x = px;
let line_height = line.ascent() + line.descent() + line.leading();
glyphs.clear();
for cluster in run.visual_clusters() {
for glyph in cluster.glyphs() {
Expand All @@ -797,13 +798,13 @@ fn fetch_dimensions(
background_color: None,
baseline: py,
topline: py - line.ascent(),
line_height: line.ascent() + line.descent(),
line_height,
advance: px - run_x,
underline: None,
};

sugarwidth = style.advance;
sugarheight = style.line_height;
sugarheight = line_height;
comp.draw_glyphs(
Rect::new(run_x, py, style.advance, 1.),
0.0,
Expand Down
Loading

0 comments on commit bb0c4c3

Please sign in to comment.