Skip to content

Commit

Permalink
Fix zero-size text issue (RazrFalcon#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
paxbun committed Apr 22, 2024
1 parent 2b94970 commit 0e5502c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions crates/usvg/src/parser/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ pub(crate) fn convert(
cache: &mut converter::Cache,
parent: &mut Group,
) {
let pos_list = resolve_positions_list(text_node, state);
let mut pos_list = resolve_positions_list(text_node, state);
let rotate_list = resolve_rotate_list(text_node);
let writing_mode = convert_writing_mode(text_node);

let chunks = collect_text_chunks(text_node, &pos_list, state, cache);
let chunks = collect_text_chunks(text_node, &mut pos_list, state, cache);

let rendering_mode: TextRendering = text_node
.find_attribute(AId::TextRendering)
Expand Down Expand Up @@ -162,7 +162,7 @@ struct IterState {

fn collect_text_chunks(
text_node: SvgNode,
pos_list: &[CharacterPosition],
pos_list: &mut [CharacterPosition],
state: &converter::State,
cache: &mut converter::Cache,
) -> Vec<TextChunk> {
Expand All @@ -181,7 +181,7 @@ fn collect_text_chunks(

fn collect_text_chunks_impl(
parent: SvgNode,
pos_list: &[CharacterPosition],
pos_list: &mut [CharacterPosition],
state: &converter::State,
cache: &mut converter::Cache,
iter_state: &mut IterState,
Expand Down Expand Up @@ -236,7 +236,14 @@ fn collect_text_chunks_impl(
Some(n) => n,
None => {
// Skip this span.
let pos = pos_list.get(iter_state.chars_count).copied();
iter_state.chars_count += child.text().chars().count();
if iter_state.chars_count < pos_list.len() {
if let Some(pos) = pos {
pos_list[iter_state.chars_count] = pos;
}
}
// iter_state
continue;
}
};
Expand Down

0 comments on commit 0e5502c

Please sign in to comment.