use super::*;
use crate::model::control::FormType;
use crate::model::shape::TextWrap;
use crate::renderer::composer::CharOverlapInfo;
use crate::renderer::equation::layout::{LayoutBox, LayoutKind};
use crate::renderer::render_tree::{
BoundingBox, EllipseNode, EquationNode, FieldMarkerType, FootnoteMarkerNode, FormObjectNode,
ImageNode, LineNode, PageBackgroundNode, PageNode, PathNode, PlaceholderNode, RawSvgNode,
RectangleNode, RenderLayerInfo, RenderNode, RenderNodeType, TableCellNode, TableNode,
TextLineNode, TextRunNode,
};
use crate::renderer::{LineStyle, PathCommand, ShapeStyle, TabLeaderInfo, TextStyle};
#[test]
fn builds_body_clip_layer() {
let mut tree = PageRenderTree::new(0, 800.0, 600.0);
tree.root.node_type = RenderNodeType::Page(PageNode {
page_index: 0,
width: 800.0,
height: 600.0,
section_index: 0,
});
let body = RenderNode::new(
1,
RenderNodeType::Body {
clip_rect: Some(BoundingBox::new(10.0, 20.0, 300.0, 400.0)),
},
BoundingBox::new(10.0, 20.0, 300.0, 400.0),
);
tree.root.children.push(body);
let mut builder = LayerBuilder::new(RenderProfile::Screen);
let layer_tree = builder.build(&tree);
assert_eq!(layer_tree.page_width, 800.0);
match &layer_tree.root.kind {
LayerNodeKind::Group { children, .. } => {
assert_eq!(children.len(), 1);
match &children[0].kind {
LayerNodeKind::ClipRect {
clip, clip_kind, ..
} => {
assert_eq!(clip.x, 10.0);
assert_eq!(*clip_kind, ClipKind::Body);
}
other => panic!("expected clip rect, got {other:?}"),
}
}
other => panic!("expected root group, got {other:?}"),
}
}
#[test]
fn normal_builder_export_keeps_text_fallback_and_font_native_sidecar_resources() {
let bbox = BoundingBox::new(10.0, 20.0, 16.0, 16.0);
let mut run = text_run("\u{E100}");
run.char_shape_id = Some(2);
run.style.font_size = 16.0;
run.baseline = 12.0;
let mut tree = PageRenderTree::new(0, 100.0, 100.0);
tree.root
.children
.push(RenderNode::new(1, RenderNodeType::TextRun(run), bbox));
let font = include_bytes!("../../../tests/fixtures/fonts/RHWPBitmapSvgGlyphSmoke.ttf");
let mut builder = LayerBuilder::new(RenderProfile::Screen);
let layer_tree = builder.build_with_embedded_fonts(
&tree,
&[EmbeddedFontFace {
char_shape_id: 2,
language_index: 0,
family: "RHWP Bitmap SVG Glyph Smoke",
alternate_family: None,
bytes: font,
face_index: 0,
}],
);
let LayerNodeKind::Group { children, .. } = &layer_tree.root.kind else {
panic!("expected root group");
};
let LayerNodeKind::Leaf { ops } = &children[0].kind else {
panic!("expected text leaf");
};
assert!(matches!(
ops.as_slice(),
[
PaintOp::TextRun { .. },
PaintOp::GlyphRun { .. },
PaintOp::GlyphOutline { .. }
]
));
assert_eq!(layer_tree.resources.image_count(), 1);
assert_eq!(layer_tree.resources.font_blob_count(), 1);
assert_eq!(layer_tree.resources.font_resources().blobs.len(), 1);
assert_eq!(layer_tree.resources.font_resources().faces.len(), 1);
}
#[test]
fn builder_keeps_oversized_compact_image_unresolved() {
let mut bmp = vec![0u8; 58];
bmp[..2].copy_from_slice(b"BM");
bmp[2..6].copy_from_slice(&58u32.to_le_bytes());
bmp[10..14].copy_from_slice(&54u32.to_le_bytes());
bmp[14..18].copy_from_slice(&40u32.to_le_bytes());
bmp[18..22].copy_from_slice(&8193i32.to_le_bytes());
bmp[22..26].copy_from_slice(&8193i32.to_le_bytes());
bmp[26..28].copy_from_slice(&1u16.to_le_bytes());
bmp[28..30].copy_from_slice(&8u16.to_le_bytes());
bmp[30..34].copy_from_slice(&1u32.to_le_bytes());
bmp[54..58].copy_from_slice(&[0, 1, 0, 1]);
let mut tree = PageRenderTree::new(0, 100.0, 100.0);
tree.root.children.push(RenderNode::new(
1,
RenderNodeType::Image(ImageNode::new(1, Some(bmp))),
BoundingBox::new(0.0, 0.0, 10.0, 10.0),
));
let layer_tree = LayerBuilder::new(RenderProfile::Screen).build(&tree);
let LayerNodeKind::Group { children, .. } = &layer_tree.root.kind else {
panic!("expected root group");
};
let LayerNodeKind::Leaf { ops } = &children[0].kind else {
panic!("expected image leaf");
};
assert!(matches!(
ops.as_slice(),
[PaintOp::Image { resolved: None, .. }]
));
}
#[test]
fn copies_render_layer_metadata_to_layer_node() {
let mut tree = PageRenderTree::new(0, 100.0, 100.0);
let layer = RenderLayerInfo::new(Some(TextWrap::BehindText), 7, 42);
let table = RenderNode::new(
1,
RenderNodeType::Table(TableNode {
row_count: 1,
col_count: 1,
border_fill_id: 0,
section_index: Some(0),
para_index: Some(0),
control_index: Some(0),
cell_context: None,
}),
BoundingBox::new(0.0, 0.0, 10.0, 10.0),
)
.with_layer(layer);
tree.root.children.push(table);
let mut builder = LayerBuilder::new(RenderProfile::Screen);
let layer_tree = builder.build(&tree);
let LayerNodeKind::Group { children, .. } = &layer_tree.root.kind else {
panic!("expected root group");
};
let copied = children[0].layer.expect("table layer copied");
assert_eq!(copied.text_wrap, Some(TextWrap::BehindText));
assert_eq!(copied.z_order, 7);
assert_eq!(copied.stable_index, 42);
}
#[test]
fn builds_textbox_clip_layer() {
let mut tree = PageRenderTree::new(0, 800.0, 600.0);
let mut textbox = RenderNode::new(
7,
RenderNodeType::TextBox,
BoundingBox::new(50.0, 80.0, 240.0, 120.0),
);
textbox.children.push(RenderNode::new(
8,
RenderNodeType::TextRun(text_run("글상자")),
BoundingBox::new(60.0, 90.0, 60.0, 20.0),
));
tree.root.children.push(textbox);
let mut builder = LayerBuilder::new(RenderProfile::Screen);
let layer_tree = builder.build(&tree);
let LayerNodeKind::Group { children, .. } = &layer_tree.root.kind else {
panic!("expected root group");
};
assert_eq!(children.len(), 1);
let LayerNodeKind::ClipRect {
clip,
clip_kind,
child,
} = &children[0].kind
else {
panic!("expected textbox clip");
};
assert_eq!(*clip_kind, ClipKind::TextBox);
assert_eq!(clip.x, 50.0);
assert_eq!(clip.y, 80.0);
assert_eq!(clip.width, 240.0);
assert_eq!(clip.height, 120.0);
let LayerNodeKind::Group {
group_kind,
children: textbox_children,
..
} = &child.kind
else {
panic!("expected clipped textbox group");
};
assert!(matches!(group_kind, GroupKind::TextBox));
assert!(matches!(
&textbox_children[0].kind,
LayerNodeKind::Leaf { .. }
));
}
#[test]
fn preserves_leaf_payloads() {
let mut tree = PageRenderTree::new(0, 800.0, 600.0);
tree.root.children.push(RenderNode::new(
1,
RenderNodeType::PageBackground(PageBackgroundNode {
background_color: Some(0x00FFFFFF),
border_color: None,
border_width: 0.0,
gradient: None,
image: None,
}),
BoundingBox::new(0.0, 0.0, 800.0, 600.0),
));
tree.root.children.push(RenderNode::new(
2,
RenderNodeType::TableCell(TableCellNode {
col: 0,
row: 0,
col_span: 1,
row_span: 1,
border_fill_id: 0,
text_direction: 0,
clip: true,
closed_reflow_frame: false,
page_fragment: false,
model_cell_index: None,
model_para_range: None,
}),
BoundingBox::new(100.0, 200.0, 150.0, 80.0),
));
let mut builder = LayerBuilder::new(RenderProfile::Screen);
let layer_tree = builder.build(&tree);
match &layer_tree.root.kind {
LayerNodeKind::Group { children, .. } => {
assert_eq!(children.len(), 2);
match &children[0].kind {
LayerNodeKind::Leaf { ops } => {
assert!(matches!(ops[0], PaintOp::PageBackground { .. }));
}
other => panic!("expected leaf, got {other:?}"),
}
match &children[1].kind {
LayerNodeKind::ClipRect { clip_kind, .. } => {
assert_eq!(*clip_kind, ClipKind::TableCell);
}
other => panic!("expected clip rect, got {other:?}"),
}
}
other => panic!("expected root group, got {other:?}"),
}
}
#[test]
fn lowers_all_leaf_variants_to_explicit_paint_ops() {
let cases: Vec<(RenderNodeType, fn(&PaintOp) -> bool, &'static str)> = vec![
(
RenderNodeType::PageBackground(PageBackgroundNode {
background_color: Some(0x00FFFFFF),
border_color: None,
border_width: 0.0,
gradient: None,
image: None,
}),
|op| matches!(op, PaintOp::PageBackground { .. }),
"PageBackground",
),
(
RenderNodeType::TextRun(text_run("leaf")),
|op| matches!(op, PaintOp::TextRun { .. }),
"TextRun",
),
(
RenderNodeType::FootnoteMarker(FootnoteMarkerNode {
number: 1,
text: "1)".to_string(),
base_font_size: 12.0,
baseline: 7.0,
font_family: "serif".to_string(),
color: 0x00000000,
section_index: 0,
para_index: 0,
control_index: 0,
}),
|op| matches!(op, PaintOp::FootnoteMarker { .. }),
"FootnoteMarker",
),
(
RenderNodeType::Line(LineNode::new(0.0, 0.0, 12.0, 0.0, LineStyle::default())),
|op| matches!(op, PaintOp::Line { .. }),
"Line",
),
(
RenderNodeType::Rectangle(RectangleNode::new(0.0, ShapeStyle::default(), None)),
|op| matches!(op, PaintOp::Rectangle { .. }),
"Rectangle",
),
(
RenderNodeType::Ellipse(EllipseNode::new(ShapeStyle::default(), None)),
|op| matches!(op, PaintOp::Ellipse { .. }),
"Ellipse",
),
(
RenderNodeType::Path(PathNode::new(
vec![PathCommand::MoveTo(0.0, 0.0), PathCommand::LineTo(8.0, 4.0)],
ShapeStyle::default(),
None,
)),
|op| matches!(op, PaintOp::Path { .. }),
"Path",
),
(
RenderNodeType::Image(ImageNode::new(1, Some(vec![0x89, b'P', b'N', b'G']))),
|op| matches!(op, PaintOp::Image { .. }),
"Image",
),
(
RenderNodeType::Equation(equation_node()),
|op| matches!(op, PaintOp::Equation { .. }),
"Equation",
),
(
RenderNodeType::FormObject(form_object_node()),
|op| matches!(op, PaintOp::FormObject { .. }),
"FormObject",
),
(
RenderNodeType::Placeholder(PlaceholderNode::new(
0x00F0F0F0,
0x00000000,
"OLE".to_string(),
)),
|op| matches!(op, PaintOp::Placeholder { .. }),
"Placeholder",
),
(
RenderNodeType::RawSvg(RawSvgNode::new("<g><path d=\"M0 0L1 1\"/></g>".to_string())),
|op| matches!(op, PaintOp::RawSvg { .. }),
"RawSvg",
),
];
for (idx, (node_type, is_expected_op, label)) in cases.into_iter().enumerate() {
let mut tree = PageRenderTree::new(0, 100.0, 100.0);
tree.root.children.push(RenderNode::new(
100 + idx as u32,
node_type,
BoundingBox::new(1.0, 2.0, 30.0, 20.0),
));
let mut builder = LayerBuilder::new(RenderProfile::Screen);
let layer_tree = builder.build(&tree);
let LayerNodeKind::Group { children, .. } = &layer_tree.root.kind else {
panic!("expected root group for {label}");
};
let LayerNodeKind::Leaf { ops } = &children[0].kind else {
panic!("expected leaf for {label}, got {:?}", children[0].kind);
};
assert_eq!(ops.len(), 1, "{label} should lower to one paint op");
assert!(is_expected_op(&ops[0]), "{label} lowered to {:?}", ops[0]);
}
}
#[test]
fn preserves_leaf_node_children_after_own_paint_op() {
let mut tree = PageRenderTree::new(0, 100.0, 100.0);
let mut form = RenderNode::new(
1,
RenderNodeType::FormObject(form_object_node()),
BoundingBox::new(10.0, 10.0, 60.0, 24.0),
);
form.children.push(RenderNode::new(
2,
RenderNodeType::TextRun(text_run("label")),
BoundingBox::new(14.0, 14.0, 40.0, 16.0),
));
tree.root.children.push(form);
let mut builder = LayerBuilder::new(RenderProfile::Screen);
let layer_tree = builder.build(&tree);
let LayerNodeKind::Group { children, .. } = &layer_tree.root.kind else {
panic!("expected root group");
};
let LayerNodeKind::Group {
children: form_children,
..
} = &children[0].kind
else {
panic!("expected form node with children to lower to a group");
};
assert_eq!(form_children.len(), 2);
let LayerNodeKind::Leaf { ops: form_ops } = &form_children[0].kind else {
panic!("expected own form paint op first");
};
assert!(matches!(form_ops[0], PaintOp::FormObject { .. }));
let LayerNodeKind::Leaf { ops: label_ops } = &form_children[1].kind else {
panic!("expected child text paint op second");
};
assert!(matches!(label_ops[0], PaintOp::TextRun { .. }));
}
#[test]
fn lowers_text_special_visuals_to_external_paint_ops() {
let mut run = text_run("special\ttext");
run.field_marker = FieldMarkerType::FieldBegin;
run.is_para_end = true;
run.style.tab_leaders.push(TabLeaderInfo {
start_x: 12.0,
end_x: 36.0,
fill_type: 3,
});
run.style.underline = UnderlineType::Bottom;
run.style.strikethrough = true;
run.style.emphasis_dot = 2;
let mut tree = PageRenderTree::new(0, 100.0, 100.0);
tree.root.children.push(RenderNode::new(
1,
RenderNodeType::TextRun(run),
BoundingBox::new(1.0, 2.0, 80.0, 20.0),
));
let mut builder =
LayerBuilder::new(RenderProfile::Screen).with_output_options(LayerOutputOptions {
show_paragraph_marks: true,
show_control_codes: true,
..Default::default()
});
let layer_tree = builder.build(&tree);
let LayerNodeKind::Group { children, .. } = &layer_tree.root.kind else {
panic!("expected root group");
};
let LayerNodeKind::Leaf { ops } = &children[0].kind else {
panic!("expected text leaf");
};
assert!(matches!(ops[0], PaintOp::TextRun { .. }));
assert!(!ops
.iter()
.any(|op| matches!(op, PaintOp::CharOverlap { .. })));
assert!(ops
.iter()
.any(|op| matches!(op, PaintOp::TextControlMark { .. })));
assert!(ops.iter().any(|op| matches!(op, PaintOp::TabLeader { .. })));
assert!(ops.iter().any(|op| matches!(
op,
PaintOp::TextDecoration {
kind: TextDecorationKind::Underline,
..
}
)));
assert!(ops.iter().any(|op| matches!(
op,
PaintOp::TextDecoration {
kind: TextDecorationKind::Strikethrough,
..
}
)));
assert!(ops.iter().any(|op| matches!(
op,
PaintOp::TextDecoration {
kind: TextDecorationKind::EmphasisDot,
..
}
)));
}
#[test]
fn lowers_space_and_tab_control_marks_without_an_end_marker() {
let run = text_run("space\tmark");
let mut tree = PageRenderTree::new(0, 100.0, 100.0);
tree.root.children.push(RenderNode::new(
1,
RenderNodeType::TextRun(run),
BoundingBox::new(1.0, 2.0, 80.0, 20.0),
));
let mut builder =
LayerBuilder::new(RenderProfile::Screen).with_output_options(LayerOutputOptions {
show_control_codes: true,
..Default::default()
});
let layer_tree = builder.build(&tree);
let LayerNodeKind::Group { children, .. } = &layer_tree.root.kind else {
panic!("expected root group");
};
let LayerNodeKind::Leaf { ops } = &children[0].kind else {
panic!("expected text leaf");
};
assert!(ops
.iter()
.any(|op| matches!(op, PaintOp::TextControlMark { .. })));
}
#[test]
fn either_view_option_preserves_legacy_text_mark_union_semantics() {
let mut paragraph_run = text_run("plain");
paragraph_run.is_para_end = true;
let paragraph_ops = text_run_ops(
BoundingBox::new(0.0, 0.0, 40.0, 10.0),
paragraph_run,
LayerOutputOptions {
show_control_codes: true,
..Default::default()
},
);
assert!(paragraph_ops
.iter()
.any(|op| matches!(op, PaintOp::TextControlMark { .. })));
let space_ops = text_run_ops(
BoundingBox::new(0.0, 0.0, 40.0, 10.0),
text_run("a b"),
LayerOutputOptions {
show_paragraph_marks: true,
..Default::default()
},
);
assert!(space_ops
.iter()
.any(|op| matches!(op, PaintOp::TextControlMark { .. })));
}
#[test]
fn overlap_runs_do_not_gain_normal_text_decorations_or_tab_leaders() {
let mut run = text_run("overlap");
run.char_overlap = Some(CharOverlapInfo {
border_type: 1,
inner_char_size: 90,
composition: None,
empty_ink: false,
});
run.style.tab_leaders.push(TabLeaderInfo {
start_x: 2.0,
end_x: 20.0,
fill_type: 1,
});
run.style.underline = UnderlineType::Bottom;
run.style.strikethrough = true;
run.style.emphasis_dot = 1;
let ops = text_run_ops(
BoundingBox::new(0.0, 0.0, 40.0, 10.0),
run,
LayerOutputOptions::default(),
);
assert!(ops
.iter()
.any(|op| matches!(op, PaintOp::CharOverlap { .. })));
assert!(!ops.iter().any(|op| matches!(op, PaintOp::TabLeader { .. })));
assert!(!ops
.iter()
.any(|op| matches!(op, PaintOp::TextDecoration { .. })));
}
#[test]
fn excludes_editor_only_nodes_from_print_profile() {
let editor_line = RenderNode::new(
1,
RenderNodeType::Line(crate::renderer::render_tree::LineNode::new(
0.0,
0.0,
20.0,
0.0,
crate::renderer::LineStyle::default(),
)),
BoundingBox::new(0.0, 0.0, 20.0, 1.0),
)
.with_editor_only();
let mut tree = PageRenderTree::new(0, 100.0, 100.0);
tree.root.children.push(editor_line);
let screen = LayerBuilder::new(RenderProfile::Screen).build(&tree);
let print = LayerBuilder::new(RenderProfile::Print).build(&tree);
let LayerNodeKind::Group {
children: screen_children,
..
} = &screen.root.kind
else {
panic!("expected screen root group");
};
let LayerNodeKind::Group {
children: print_children,
..
} = &print.root.kind
else {
panic!("expected print root group");
};
assert_eq!(screen_children.len(), 1);
assert!(print_children.is_empty());
}
#[test]
fn preserves_structural_groups_and_clips_for_backend_replay() {
let mut tree = PageRenderTree::new(0, 800.0, 600.0);
tree.root.node_type = RenderNodeType::Page(PageNode {
page_index: 0,
width: 800.0,
height: 600.0,
section_index: 0,
});
let mut header = RenderNode::new(
1,
RenderNodeType::Header,
BoundingBox::new(0.0, 0.0, 800.0, 80.0),
);
let mut header_line = RenderNode::new(
2,
RenderNodeType::TextLine(TextLineNode::with_para_vpos(20.0, 15.0, 0, 0, 0, 120)),
BoundingBox::new(40.0, 20.0, 200.0, 20.0),
);
header_line.children.push(RenderNode::new(
3,
RenderNodeType::TextRun(text_run("머리말")),
BoundingBox::new(40.0, 20.0, 60.0, 20.0),
));
header.children.push(header_line);
let footer = RenderNode::new(
4,
RenderNodeType::Footer,
BoundingBox::new(0.0, 540.0, 800.0, 60.0),
);
let body_clip = BoundingBox::new(40.0, 90.0, 720.0, 420.0);
let mut body = RenderNode::new(
5,
RenderNodeType::Body {
clip_rect: Some(body_clip),
},
body_clip,
);
let mut column = RenderNode::new(
6,
RenderNodeType::Column(1),
BoundingBox::new(40.0, 90.0, 340.0, 420.0),
);
let mut table = RenderNode::new(
7,
RenderNodeType::Table(TableNode {
row_count: 1,
col_count: 1,
border_fill_id: 2,
section_index: Some(0),
para_index: Some(2),
control_index: Some(0),
cell_context: None,
}),
BoundingBox::new(60.0, 110.0, 180.0, 80.0),
);
let mut clipped_cell = RenderNode::new(
8,
RenderNodeType::TableCell(TableCellNode {
col: 0,
row: 0,
col_span: 1,
row_span: 1,
border_fill_id: 3,
text_direction: 0,
clip: true,
closed_reflow_frame: false,
page_fragment: false,
model_cell_index: Some(4),
model_para_range: None,
}),
BoundingBox::new(60.0, 110.0, 180.0, 80.0),
);
let mut nested_table = RenderNode::new(
9,
RenderNodeType::Table(TableNode {
row_count: 1,
col_count: 1,
border_fill_id: 5,
section_index: Some(0),
para_index: Some(2),
control_index: Some(1),
cell_context: None,
}),
BoundingBox::new(70.0, 120.0, 80.0, 40.0),
);
nested_table.children.push(RenderNode::new(
10,
RenderNodeType::TableCell(TableCellNode {
col: 0,
row: 0,
col_span: 1,
row_span: 1,
border_fill_id: 6,
text_direction: 0,
clip: false,
closed_reflow_frame: false,
page_fragment: false,
model_cell_index: None,
model_para_range: None,
}),
BoundingBox::new(70.0, 120.0, 80.0, 40.0),
));
clipped_cell.children.push(nested_table);
table.children.push(clipped_cell);
column.children.push(table);
body.children.push(column);
tree.root.children.push(header);
tree.root.children.push(footer);
tree.root.children.push(body);
let mut builder = LayerBuilder::new(RenderProfile::Screen);
let layer_tree = builder.build(&tree);
let LayerNodeKind::Group { children, .. } = &layer_tree.root.kind else {
panic!("expected root group");
};
assert_eq!(children.len(), 3);
let LayerNodeKind::Group {
group_kind,
cache_hint,
children: header_children,
} = &children[0].kind
else {
panic!("expected header group");
};
assert!(matches!(group_kind, GroupKind::Header));
assert_eq!(*cache_hint, CacheHint::StaticSubtree);
let LayerNodeKind::Group {
group_kind,
children: line_children,
..
} = &header_children[0].kind
else {
panic!("expected text line group");
};
match group_kind {
GroupKind::TextLine(line) => {
assert_eq!(line.para_index, Some(0));
assert_eq!(line.vpos, Some(120));
}
other => panic!("expected text line group kind, got {other:?}"),
}
assert!(matches!(&line_children[0].kind, LayerNodeKind::Leaf { .. }));
let LayerNodeKind::Group {
group_kind,
cache_hint,
..
} = &children[1].kind
else {
panic!("expected footer group");
};
assert!(matches!(group_kind, GroupKind::Footer));
assert_eq!(*cache_hint, CacheHint::StaticSubtree);
let LayerNodeKind::ClipRect {
clip,
clip_kind,
child,
} = &children[2].kind
else {
panic!("expected body clip");
};
assert_eq!(clip.x, body_clip.x);
assert_eq!(clip.y, body_clip.y);
assert_eq!(clip.width, body_clip.width);
assert_eq!(clip.height, body_clip.height);
assert_eq!(*clip_kind, ClipKind::Body);
let LayerNodeKind::Group {
group_kind,
children: body_children,
..
} = &child.kind
else {
panic!("expected clipped body group");
};
assert!(matches!(group_kind, GroupKind::Body));
let LayerNodeKind::Group {
group_kind,
children: column_children,
..
} = &body_children[0].kind
else {
panic!("expected column group");
};
assert!(matches!(group_kind, GroupKind::Column(1)));
let LayerNodeKind::Group {
group_kind,
children: table_children,
..
} = &column_children[0].kind
else {
panic!("expected table group");
};
match group_kind {
GroupKind::Table(table) => {
assert_eq!(table.row_count, 1);
assert_eq!(table.col_count, 1);
assert_eq!(table.control_index, Some(0));
}
other => panic!("expected table group kind, got {other:?}"),
}
let LayerNodeKind::ClipRect {
clip_kind, child, ..
} = &table_children[0].kind
else {
panic!("expected table cell clip");
};
assert_eq!(*clip_kind, ClipKind::TableCell);
let LayerNodeKind::Group {
group_kind,
children: cell_children,
..
} = &child.kind
else {
panic!("expected clipped table cell group");
};
match group_kind {
GroupKind::TableCell(cell) => {
assert!(cell.clip);
assert_eq!(cell.model_cell_index, Some(4));
}
other => panic!("expected table cell group kind, got {other:?}"),
}
assert!(matches!(
&cell_children[0].kind,
LayerNodeKind::Group {
group_kind: GroupKind::Table(_),
..
}
));
}
fn text_run(text: &str) -> TextRunNode {
TextRunNode {
text: text.to_string(),
style: TextStyle::default(),
char_shape_id: None,
para_shape_id: None,
section_index: None,
para_index: None,
char_start: None,
cell_context: None,
is_para_end: false,
is_line_break_end: false,
rotation: 0.0,
is_vertical: false,
char_overlap: None,
border_fill_id: 0,
baseline: 12.0,
field_marker: Default::default(),
layout_positions: None,
display_text: None,
}
}
fn equation_node() -> EquationNode {
EquationNode {
svg_content: "<text>x</text>".to_string(),
layout_box: LayoutBox {
font_size: 12.0,
x: 0.0,
y: 0.0,
width: 8.0,
height: 12.0,
baseline: 10.0,
kind: LayoutKind::Text("x".to_string()),
},
color_str: "#000000".to_string(),
color: 0x00000000,
font_size: 12.0,
script: String::new(),
section_index: None,
para_index: None,
control_index: None,
cell_index: None,
cell_para_index: None,
note_ref: None,
}
}
fn form_object_node() -> FormObjectNode {
FormObjectNode {
form_type: FormType::PushButton,
caption: "OK".to_string(),
text: String::new(),
display_text: None,
appearance: Default::default(),
fore_color: "#000000".to_string(),
back_color: "#ffffff".to_string(),
value: 0,
enabled: true,
section_index: 0,
para_index: 0,
control_index: 0,
name: "button".to_string(),
cell_location: None,
}
}