use std::num::NonZeroUsize;
use f_office_units::scale::{FIFTIETHS_PER_PERCENT, PERCENT};
use f_office_units::{Edges, Length};
use f_office_xml::NodeId;
use f_office_xml::enumeration::{Drawn, Values, another, own};
use crate::body::{Block, holds_nothing, read_blocks, shown_branch};
use crate::ns::{MC, W};
use crate::numbers;
use crate::on_off;
use crate::params::{MAX_GRID_COLUMNS, TABLE_LOOK_BITS};
use crate::props::{
ANCHOR, Align, Anchor, Border, Color, SetIn, X_ALIGN, XAlign, Y_ALIGN, YAlign, overlay,
read_shading, read_table_border, shows_shading,
};
use crate::reader::{PartReader, val};
use crate::source_span::SourceSpan;
use crate::warnings::Limit;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Table {
pub props: TableProps,
pub grid: Vec<Length>,
pub rows: Vec<Row>,
pub part: std::rc::Rc<f_office_warnings::Name>,
pub source: SourceSpan,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Side {
Nil,
None,
Spaced(Length),
Line(Border),
}
impl Side {
#[must_use]
pub fn line(self) -> Option<Border> {
match self {
Self::Nil | Self::None | Self::Spaced(_) => None,
Self::Line(border) => Some(border),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct TableBorders {
pub top: Option<Side>,
pub left: Option<Side>,
pub bottom: Option<Side>,
pub right: Option<Side>,
pub inside_h: Option<Side>,
pub inside_v: Option<Side>,
}
impl TableBorders {
pub fn apply(&mut self, other: &Self) {
let Self {
top,
left,
bottom,
right,
inside_h,
inside_v,
} = other;
overlay(&mut self.top, top.as_ref());
overlay(&mut self.left, left.as_ref());
overlay(&mut self.bottom, bottom.as_ref());
overlay(&mut self.right, right.as_ref());
overlay(&mut self.inside_h, inside_h.as_ref());
overlay(&mut self.inside_v, inside_v.as_ref());
}
pub(crate) fn read(reader: &mut PartReader, node: NodeId) -> Self {
let doc = reader.doc;
let mut side = |names: &[&str]| {
names
.iter()
.find_map(|name| doc.child(node, W, name))
.map(|side| match read_table_border(reader, side) {
Some(border) => Side::Line(border),
None if empty_none(reader, side) => Side::None,
None => none_space(reader, side).map_or(Side::Nil, Side::Spaced),
})
};
Self {
top: side(&["top"]),
left: side(&["left", "start"]),
bottom: side(&["bottom"]),
right: side(&["right", "end"]),
inside_h: side(&["insideH"]),
inside_v: side(&["insideV"]),
}
}
}
fn empty_none(reader: &mut PartReader, side: NodeId) -> bool {
let doc = reader.doc;
doc.attribute(side, Some(W), "val") == Some("none")
&& reader.whole_number(side, "sz").unwrap_or(0) == 0
&& reader.whole_number(side, "space").unwrap_or(0) == 0
&& doc
.attribute(side, Some(W), "color")
.is_none_or(|color| color == "auto")
}
fn none_space(reader: &mut PartReader, side: NodeId) -> Option<Length> {
if reader.doc.attribute(side, Some(W), "val") != Some("none") {
return None;
}
let points = reader
.whole_number(side, "space")
.filter(|&points| points > 0)?;
Length::from_points(points)
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Margins {
pub top: Option<Length>,
pub left: Option<Length>,
pub bottom: Option<Length>,
pub right: Option<Length>,
}
impl Margins {
pub fn apply(&mut self, other: &Self) {
let Self {
top,
left,
bottom,
right,
} = other;
overlay(&mut self.top, top.as_ref());
overlay(&mut self.left, left.as_ref());
overlay(&mut self.bottom, bottom.as_ref());
overlay(&mut self.right, right.as_ref());
}
fn read(reader: &mut PartReader, node: NodeId) -> Self {
let doc = reader.doc;
let mut side = |names: &[&str]| {
names
.iter()
.find_map(|name| doc.child(node, W, name))
.and_then(|side| width(reader, side))
};
Self {
top: side(&["top"]),
left: side(&["left", "start"]),
bottom: side(&["bottom"]),
right: side(&["right", "end"]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct TablePlacement {
pub horizontal: Anchor,
pub vertical: Anchor,
pub x: Option<Length>,
pub y: Length,
pub x_align: Option<Align>,
pub y_align: Option<Align>,
pub distance: Edges<Length>,
}
impl TablePlacement {
fn read(reader: &mut PartReader, node: NodeId) -> Self {
let horizontal = reader.enumeration(node, "horzAnchor", ANCHOR);
let vertical = reader.enumeration(node, "vertAnchor", ANCHOR);
let x_align = reader.enumeration(node, "tblpXSpec", X_ALIGN);
let y_align = reader.enumeration(node, "tblpYSpec", Y_ALIGN);
let x = reader.twips(node, "tblpX");
let mut length = |name| reader.twips(node, name).unwrap_or(Length::ZERO);
Self {
horizontal: horizontal.unwrap_or_default(),
vertical: vertical.unwrap_or(Anchor::Margin),
x,
y: length("tblpY"),
x_align: x_align.map(XAlign::align),
y_align: y_align.and_then(YAlign::align),
distance: Edges::from(
[
"leftFromText",
"topFromText",
"rightFromText",
"bottomFromText",
]
.map(length),
),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TableAlignment {
Start,
Center,
End,
}
const TABLE_JC: &Values<TableAlignment> = &Values::new(&[
own("left", TableAlignment::Start),
own("start", TableAlignment::Start),
own("center", TableAlignment::Center),
own("right", TableAlignment::End),
own("end", TableAlignment::End),
own("both", TableAlignment::Start),
]);
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TableLayout {
Fixed,
Autofit,
}
const TABLE_LAYOUT: &Values<TableLayout> = &Values::new(&[
own("fixed", TableLayout::Fixed),
own("autofit", TableLayout::Autofit),
]);
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Region {
WholeTable,
Band1Vert,
Band2Vert,
Band1Horz,
Band2Horz,
FirstCol,
LastCol,
FirstRow,
LastRow,
NwCell,
NeCell,
SwCell,
SeCell,
}
pub(crate) const REGION: &Values<Region> = &Values::new(&[
own("wholeTable", Region::WholeTable),
own("band1Vert", Region::Band1Vert),
own("band2Vert", Region::Band2Vert),
own("band1Horz", Region::Band1Horz),
own("band2Horz", Region::Band2Horz),
own("firstCol", Region::FirstCol),
own("lastCol", Region::LastCol),
own("firstRow", Region::FirstRow),
own("lastRow", Region::LastRow),
own("nwCell", Region::NwCell),
own("neCell", Region::NeCell),
own("swCell", Region::SwCell),
own("seCell", Region::SeCell),
]);
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Look(u32);
impl Look {
pub const FIRST_ROW: u32 = TABLE_LOOK_BITS[0];
pub const LAST_ROW: u32 = TABLE_LOOK_BITS[1];
pub const FIRST_COLUMN: u32 = TABLE_LOOK_BITS[2];
pub const LAST_COLUMN: u32 = TABLE_LOOK_BITS[3];
pub const NO_ROW_BANDS: u32 = TABLE_LOOK_BITS[4];
pub const NO_COLUMN_BANDS: u32 = TABLE_LOOK_BITS[5];
#[must_use]
pub fn has(self, bit: u32) -> bool {
self.0 & bit != 0
}
fn read(reader: &mut PartReader, node: NodeId) -> Self {
let doc = reader.doc;
let mut bits = reader.hex(node, "val", numbers::SHORT_HEX).unwrap_or(0);
let names = [
("firstRow", Self::FIRST_ROW),
("lastRow", Self::LAST_ROW),
("firstColumn", Self::FIRST_COLUMN),
("lastColumn", Self::LAST_COLUMN),
("noHBand", Self::NO_ROW_BANDS),
("noVBand", Self::NO_COLUMN_BANDS),
];
for (name, bit) in names {
match doc.attribute(node, Some(W), name) {
Some(value) if on_off::read(value) == Some(true) => bits |= bit,
Some(_) => bits &= !bit,
None => {}
}
}
Self(bits)
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct TableProps {
pub style: Option<String>,
pub indent: Option<Length>,
pub alignment: Option<TableAlignment>,
pub borders: TableBorders,
pub margins: Margins,
pub look: Option<Look>,
pub row_band: Option<NonZeroUsize>,
pub column_band: Option<NonZeroUsize>,
pub placement: Option<TablePlacement>,
pub width: Option<PreferredWidth>,
pub layout: Option<TableLayout>,
pub cell_spacing: Option<Length>,
pub right_to_left: Option<bool>,
pub shading: Option<SetIn<bool>>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PreferredWidth {
Length(Length),
Percent(i64),
}
impl PreferredWidth {
#[must_use]
pub fn length(self) -> Option<Length> {
match self {
Self::Length(length) => Some(length),
Self::Percent(_) => None,
}
}
#[must_use]
pub fn of(self, whole: Length) -> Option<Length> {
match self {
Self::Length(length) => Some(length),
Self::Percent(share) => whole
.checked_mul(share)
.map(|part| part.div_toward_zero(FIFTIETHS_PER_PERCENT * PERCENT)),
}
}
}
impl TableProps {
pub fn apply(&mut self, other: &Self) {
let Self {
style,
indent,
alignment,
borders,
margins,
look,
row_band,
column_band,
placement,
width,
layout,
cell_spacing,
right_to_left,
shading,
} = other;
overlay(&mut self.placement, placement.as_ref());
overlay(&mut self.width, width.as_ref());
overlay(&mut self.layout, layout.as_ref());
overlay(&mut self.style, style.as_ref());
overlay(&mut self.indent, indent.as_ref());
overlay(&mut self.alignment, alignment.as_ref());
self.borders.apply(borders);
self.margins.apply(margins);
overlay(&mut self.look, look.as_ref());
overlay(&mut self.row_band, row_band.as_ref());
overlay(&mut self.column_band, column_band.as_ref());
overlay(&mut self.cell_spacing, cell_spacing.as_ref());
overlay(&mut self.right_to_left, right_to_left.as_ref());
overlay(&mut self.shading, shading.as_ref());
}
#[must_use]
pub fn lays_out_as(&self, other: &Self) -> bool {
if self.shading == other.shading {
return self == other;
}
let same_shading = Self {
shading: self.shading.clone(),
..other.clone()
};
*self == same_shading
}
pub(crate) fn read(reader: &mut PartReader, node: NodeId) -> Self {
let doc = reader.doc;
let mut props = Self::default();
for child in doc.child_elements(node) {
let Some(element) = doc.element(child) else {
continue;
};
match element.name.local {
"tblStyle" => props.style = val(doc, child).map(str::to_owned),
"tblInd" => props.indent = width(reader, child),
"tblW" => props.width = preferred(reader, child),
"tblLayout" => props.layout = reader.enumeration(child, "type", TABLE_LAYOUT),
"jc" => props.alignment = reader.enumeration(child, "val", TABLE_JC),
"tblBorders" => props.borders = TableBorders::read(reader, child),
"tblCellMar" => props.margins = Margins::read(reader, child),
"tblLook" => props.look = Some(Look::read(reader, child)),
"tblStyleRowBandSize" => props.row_band = band(reader, child),
"tblStyleColBandSize" => props.column_band = band(reader, child),
"tblpPr" => props.placement = Some(TablePlacement::read(reader, child)),
"bidiVisual" => props.right_to_left = Some(on_off::element(doc, child, W)),
"tblCellSpacing" => props.cell_spacing = cell_spacing(reader, child),
"shd" => props.shading = Some(SetIn::read(shows_shading(doc, child), reader)),
_ => {}
}
}
props
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum HeightRule {
AtLeast,
Exact,
Auto,
}
pub(crate) const HEIGHT_RULE: &Values<HeightRule> = &Values::new(&[
own("auto", HeightRule::Auto),
own("exact", HeightRule::Exact),
own("atLeast", HeightRule::AtLeast),
]);
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Row {
pub height: Option<(Length, HeightRule)>,
pub cant_split: bool,
pub header: bool,
pub hidden: bool,
pub grid_before: usize,
pub alignment: Option<TableAlignment>,
pub cell_spacing: Option<Length>,
pub exceptions: TableProps,
pub cells: Vec<Cell>,
pub source: SourceSpan,
}
impl Row {
fn read(reader: &mut PartReader, node: NodeId) -> Self {
let doc = reader.doc;
let mut row = Self {
source: SourceSpan::of(doc, node),
..Self::default()
};
if let Some(trpr) = doc.child(node, W, "trPr") {
row.read_props(reader, trpr);
}
if let Some(exceptions) = doc.child(node, W, "tblPrEx") {
row.exceptions = TableProps::read(reader, exceptions);
}
for cell in cell_nodes(reader, node) {
row.cells.push(Cell::read(reader, cell));
}
row
}
fn read_props(&mut self, reader: &mut PartReader, trpr: NodeId) {
let doc = reader.doc;
for child in doc.child_elements(trpr) {
let Some(element) = doc.element(child) else {
continue;
};
match element.name.local {
"trHeight" => self.height = read_height(reader, child),
"cantSplit" => self.cant_split = on_off::element(doc, child, W),
"tblHeader" => self.header = on_off::element(doc, child, W),
"hidden" => self.hidden = on_off::element(doc, child, W),
"gridBefore" => self.grid_before = grid_columns(reader, child).unwrap_or(0),
"jc" => self.alignment = reader.enumeration(child, "val", TABLE_JC),
"tblCellSpacing" => self.cell_spacing = cell_spacing(reader, child),
_ => {}
}
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Merge {
Restart,
Continue,
}
const MERGE: &Values<Merge> = &Values::new(&[
own("continue", Merge::Continue),
own("restart", Merge::Restart),
]);
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum VerticalAlign {
Top,
Center,
Bottom,
}
pub(crate) const CELL_V_ALIGN: &Values<VerticalAlign> = &Values::new(&[
own("top", VerticalAlign::Top),
own("center", VerticalAlign::Center),
own("bottom", VerticalAlign::Bottom),
another("both", VerticalAlign::Top),
]);
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum TextDirection {
#[default]
Upright,
BottomToTop,
TopToBottom,
}
pub(crate) const TEXT_DIRECTION: &Values<TextDirection> = &Values::new(&[
own("lrTb", TextDirection::Upright),
own("tb", TextDirection::Upright),
own("btLr", TextDirection::BottomToTop),
own("tbRl", TextDirection::TopToBottom),
another("lr", TextDirection::Upright),
another("rl", TextDirection::Upright),
another("lrTbV", TextDirection::Upright),
another("tbV", TextDirection::Upright),
another("tbRlV", TextDirection::Upright),
another("rlV", TextDirection::Upright),
another("tbLrV", TextDirection::Upright),
another("lrV", TextDirection::Upright),
]);
pub(crate) fn turns_text(name: &str) -> Option<bool> {
TEXT_DIRECTION.find(name).map(|(direction, _, drawn)| {
*direction != TextDirection::Upright || drawn == Drawn::AsAnother
})
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Cell {
pub width: Option<PreferredWidth>,
pub span: NonZeroUsize,
pub merge: Option<Merge>,
pub borders: TableBorders,
pub margins: Margins,
pub align: Option<VerticalAlign>,
pub direction: TextDirection,
pub shading: Option<Color>,
pub deletion: Option<CellDeletion>,
pub hide_mark: bool,
pub fit_text: bool,
pub blocks: Vec<Block>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct CellDeletion {
pub id: String,
pub author: String,
}
impl Cell {
#[must_use]
pub fn shown_blocks(&self) -> &[Block] {
match self.blocks.split_last() {
Some((Block::Paragraph(last), rest))
if holds_nothing(last)
&& (self.hide_mark || matches!(rest.last(), Some(Block::Table(_)))) =>
{
rest
}
_ => &self.blocks,
}
}
}
impl Default for Cell {
fn default() -> Self {
Self {
width: None,
span: NonZeroUsize::MIN,
merge: None,
borders: TableBorders::default(),
margins: Margins::default(),
align: None,
direction: TextDirection::Upright,
shading: None,
deletion: None,
hide_mark: false,
fit_text: false,
blocks: Vec::new(),
}
}
}
impl Cell {
fn read(reader: &mut PartReader, node: NodeId) -> Self {
let doc = reader.doc;
let mut cell = Self::default();
if let Some(tcpr) = doc.child(node, W, "tcPr") {
cell.read_props(reader, tcpr);
}
cell.blocks = read_blocks(reader, node);
cell
}
fn read_props(&mut self, reader: &mut PartReader, tcpr: NodeId) {
let doc = reader.doc;
for child in doc.child_elements(tcpr) {
let Some(element) = doc.element(child) else {
continue;
};
match element.name.local {
"tcW" => self.width = preferred(reader, child),
"gridSpan" => {
self.span = grid_columns(reader, child)
.and_then(NonZeroUsize::new)
.unwrap_or(NonZeroUsize::MIN);
}
"vMerge" => {
self.merge = Some(
reader
.enumeration(child, "val", MERGE)
.unwrap_or(Merge::Continue),
);
}
"tcBorders" => self.borders = TableBorders::read(reader, child),
"tcMar" => self.margins = Margins::read(reader, child),
"vAlign" => self.align = reader.enumeration(child, "val", CELL_V_ALIGN),
"textDirection" => {
self.direction = reader
.enumeration(child, "val", TEXT_DIRECTION)
.unwrap_or_default();
}
"shd" => self.shading = read_shading(reader, child),
"hideMark" => {
self.hide_mark = on_off::element(doc, child, W);
}
"tcFitText" => self.fit_text = on_off::element(doc, child, W),
"cellDel" => {
let attribute = |name| {
doc.attribute(child, Some(W), name)
.unwrap_or_default()
.to_owned()
};
self.deletion = Some(CellDeletion {
id: attribute("id"),
author: attribute("author"),
});
}
_ => {}
}
}
}
}
impl Table {
pub(crate) fn read(reader: &mut PartReader, node: NodeId) -> Self {
let doc = reader.doc;
let mut table = Self {
part: std::rc::Rc::new(f_office_warnings::Name::new(reader.part())),
source: SourceSpan::of(doc, node),
..Self::default()
};
for child in doc.child_elements(node) {
if doc.is(child, W, "tblPr") {
table.props = TableProps::read(reader, child);
} else if doc.is(child, W, "tblGrid") {
let mut columns = doc
.child_elements(child)
.filter(|col| doc.is(*col, W, "gridCol"));
table.grid = columns
.by_ref()
.take(MAX_GRID_COLUMNS)
.map(|col| reader.twips(col, "w").unwrap_or(Length::ZERO))
.collect();
if columns.next().is_some() {
reader.limit_reached(Limit::GridColumns);
}
} else {
collect_rows(reader, child, &mut table.rows);
}
}
table.grid = widened_grid(reader, &table.grid, &table.rows);
table
}
}
fn cell_starts(row: &Row) -> impl Iterator<Item = (usize, &Cell)> + '_ {
let mut column = row.grid_before;
row.cells.iter().map(move |cell| {
let start = column;
column = column.saturating_add(cell.span.get());
(start, cell)
})
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct RowCell {
pub(crate) node: NodeId,
pub(crate) start: usize,
pub(crate) merge: Option<Merge>,
}
pub(crate) fn row_cells(reader: &mut PartReader, row: NodeId) -> Vec<RowCell> {
let doc = reader.doc;
let mut start = doc
.child(row, W, "trPr")
.and_then(|trpr| doc.child(trpr, W, "gridBefore"))
.and_then(|node| grid_columns(reader, node))
.unwrap_or(0);
let mut places = Vec::new();
for cell in cell_nodes(reader, row) {
let tcpr = doc.child(cell, W, "tcPr");
let span = tcpr
.and_then(|tcpr| doc.child(tcpr, W, "gridSpan"))
.and_then(|node| grid_columns(reader, node))
.and_then(NonZeroUsize::new)
.unwrap_or(NonZeroUsize::MIN);
let merge = tcpr
.and_then(|tcpr| doc.child(tcpr, W, "vMerge"))
.map(|node| {
reader
.enumeration(node, "val", MERGE)
.unwrap_or(Merge::Continue)
});
places.push(RowCell {
node: cell,
start,
merge,
});
start = start.saturating_add(span.get());
}
places
}
fn grid_columns(reader: &mut PartReader, node: NodeId) -> Option<usize> {
let count = reader.number::<usize>(node, "val", numbers::NOT_NEGATIVE)?;
if count > MAX_GRID_COLUMNS {
reader.limit_reached(Limit::GridColumns);
}
Some(count.min(MAX_GRID_COLUMNS))
}
fn widened_grid(reader: &mut PartReader, grid: &[Length], rows: &[Row]) -> Vec<Length> {
let mut added: Vec<Option<Length>> = Vec::new();
for (start, cell) in rows.iter().flat_map(cell_starts) {
let span = cell.span.get();
let asked = start.saturating_add(span);
if asked > MAX_GRID_COLUMNS {
reader.limit_reached(Limit::GridColumns);
}
let end = asked.min(MAX_GRID_COLUMNS);
if let Some(count) = end.checked_sub(grid.len()).filter(|n| *n > added.len()) {
added.resize(count, None);
}
let width = cell.width.and_then(PreferredWidth::length);
let column = start.checked_sub(grid.len());
if let (Some(width), Some(slot), 1) = (width, column.and_then(|i| added.get_mut(i)), span) {
*slot = Some(slot.map_or(width, |widest| widest.max(width)));
}
}
let added = added.into_iter().map(|width| width.unwrap_or(Length::ZERO));
grid.iter().copied().chain(added).collect()
}
fn collect_rows(reader: &mut PartReader, node: NodeId, rows: &mut Vec<Row>) {
let doc = reader.doc;
if doc.is(node, W, "tr") {
rows.push(Row::read(reader, node));
} else if let Some(inner) = wrapped(reader, node) {
for child in doc.child_elements(inner) {
collect_rows(reader, child, rows);
}
}
}
fn cell_nodes(reader: &mut PartReader, row: NodeId) -> Vec<NodeId> {
let doc = reader.doc;
let mut cells = Vec::new();
let mut stack: Vec<NodeId> = doc.child_elements(row).collect();
stack.reverse();
while let Some(node) = stack.pop() {
if doc.is(node, W, "tc") {
cells.push(node);
} else if let Some(inner) = wrapped(reader, node) {
let mut children: Vec<NodeId> = doc.child_elements(inner).collect();
children.reverse();
stack.extend(children);
}
}
cells
}
fn wrapped(reader: &mut PartReader, node: NodeId) -> Option<NodeId> {
let doc = reader.doc;
if doc.is(node, MC, "AlternateContent") {
return shown_branch(reader, node);
}
["sdt", "sdtContent", "customXml"]
.iter()
.any(|name| doc.is(node, W, name))
.then_some(node)
}
fn read_height(reader: &mut PartReader, node: NodeId) -> Option<(Length, HeightRule)> {
let value = reader.twips(node, "val")?;
let rule = reader
.enumeration(node, "hRule", HEIGHT_RULE)
.unwrap_or(HeightRule::AtLeast);
Some((value, rule))
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum WidthType {
Twips,
Percent,
Auto,
}
const PREFERRED_TYPE: &Values<WidthType> = &Values::new(&[
own("dxa", WidthType::Twips),
own("pct", WidthType::Percent),
own("auto", WidthType::Auto),
another("nil", WidthType::Auto),
]);
const TWIPS_TYPE: &Values<WidthType> = &Values::new(&[
own("dxa", WidthType::Twips),
another("pct", WidthType::Auto),
another("auto", WidthType::Auto),
another("nil", WidthType::Auto),
]);
fn preferred(reader: &mut PartReader, node: NodeId) -> Option<PreferredWidth> {
let unit = reader.enumeration(node, "type", PREFERRED_TYPE);
match unit.unwrap_or(WidthType::Twips) {
WidthType::Twips => reader.twips(node, "w").map(PreferredWidth::Length),
WidthType::Percent => reader.fiftieths(node, "w").map(PreferredWidth::Percent),
WidthType::Auto => None,
}
}
fn width(reader: &mut PartReader, node: NodeId) -> Option<Length> {
match reader.enumeration(node, "type", TWIPS_TYPE) {
Some(WidthType::Twips) | None => reader.twips(node, "w"),
Some(WidthType::Percent | WidthType::Auto) => None,
}
}
fn cell_spacing(reader: &mut PartReader, node: NodeId) -> Option<Length> {
width(reader, node).filter(|s| s.units() >= 0)
}
fn band(reader: &mut PartReader, node: NodeId) -> Option<NonZeroUsize> {
reader
.number::<usize>(node, "val", 1..=i64::MAX)
.and_then(NonZeroUsize::new)
}
#[cfg(test)]
mod tests {
use super::{
Align, Anchor, HEIGHT_RULE, HeightRule, Look, Merge, REGION, Region, Side, Table,
TableAlignment, VerticalAlign,
};
use crate::body::Block;
use crate::ns::W;
use crate::params::MAX_GRID_COLUMNS;
use crate::props::{Color, DashStyle};
use crate::reader::PartReader;
use crate::warnings::Limit;
use f_office_units::Edges;
use f_office_units::Length;
use f_office_xml::{Document, Limits};
use std::num::NonZeroUsize;
fn table_and_limits(xml: &str) -> (Table, Vec<(Limit, u32)>) {
let doc = Document::parse(
format!(r#"<w:tbl xmlns:w="{W}">{xml}</w:tbl>"#).as_bytes(),
&Limits::default(),
)
.unwrap();
let mut reader = PartReader::new(&doc);
let table = Table::read(&mut reader, doc.root().unwrap());
(table, reader.limits_reached())
}
fn table(xml: &str) -> Table {
table_and_limits(xml).0
}
fn twips(t: i64) -> Option<Length> {
Length::from_twips(t)
}
#[test]
fn lays_out_tables_that_differ_only_in_their_whole_shading_alike() {
let shaded = table(
r#"<w:tblPr><w:jc w:val="center"/><w:shd w:val="clear" w:color="auto" w:fill="D9D9D9"/></w:tblPr>"#,
);
let plain = table(r#"<w:tblPr><w:jc w:val="center"/></w:tblPr>"#);
let right = table(r#"<w:tblPr><w:jc w:val="right"/></w:tblPr>"#);
assert_eq!(
shaded.props.shading.as_ref().map(|set| set.value),
Some(true)
);
assert_ne!(shaded.props, plain.props);
assert!(shaded.props.lays_out_as(&plain.props) && plain.props.lays_out_as(&shaded.props));
assert!(!right.props.lays_out_as(&shaded.props));
}
#[test]
fn reads_the_style_indent_and_borders() {
let t = table(
r#"<w:tblPr><w:tblStyle w:val="Grid"/><w:tblInd w:w="-108" w:type="dxa"/><w:jc w:val="center"/>
<w:tblBorders><w:top w:val="single" w:sz="8" w:color="FF0000"/><w:start w:val="nil"/><w:insideV w:val="none"/><w:end w:val="double" w:sz="4"/></w:tblBorders></w:tblPr>"#,
);
let p = &t.props;
assert_eq!(p.style.as_deref(), Some("Grid"));
assert_eq!(p.indent, twips(-108));
assert_eq!(p.alignment, Some(TableAlignment::Center));
let top = p.borders.top.and_then(Side::line).unwrap();
assert_eq!(
(Some(top.width), top.color),
(Length::from_eighth_points(8), Color::Rgb([255, 0, 0]))
);
assert_eq!(
(p.borders.left, p.borders.inside_v),
(Some(Side::Nil), Some(Side::None))
);
assert_eq!(
p.borders
.right
.and_then(Side::line)
.map(|b| (b.width, b.lines().len())),
Length::from_eighth_points(12).map(|width| (width, 2))
);
assert_eq!((p.borders.bottom, p.borders.inside_h), (None, None));
}
fn placement(attributes: &str) -> super::TablePlacement {
table(&format!(r"<w:tblPr><w:tblpPr {attributes}/></w:tblPr>"))
.props
.placement
.unwrap()
}
#[test]
fn reads_the_place_of_a_floating_table() {
let place = placement(
r#"w:leftFromText="180" w:topFromText="20" w:rightFromText="181" w:bottomFromText="40" w:vertAnchor="page" w:horzAnchor="margin" w:tblpX="-624" w:tblpY="2621""#,
);
assert_eq!(
(place.vertical, place.horizontal),
(Anchor::Page, Anchor::Margin)
);
assert_eq!((place.x, Some(place.y)), (twips(-624), twips(2621)));
assert_eq!(
place.distance.map(Some),
Edges::from([twips(180), twips(20), twips(181), twips(40)])
);
assert_eq!((place.x_align, place.y_align), (None, None));
assert_eq!(table("<w:tblPr/>").props.placement, None);
}
#[test]
fn reads_the_anchors_and_alignments_of_a_floating_table() {
let aligned = placement(r#"w:tblpXSpec="center" w:tblpYSpec="bottom""#);
assert_eq!(
(aligned.vertical, aligned.horizontal),
(Anchor::Margin, Anchor::Text)
);
assert_eq!(
(aligned.x_align, aligned.y_align),
(Some(Align::Center), Some(Align::End))
);
let left = placement(r#"w:tblpXSpec="left" w:tblpYSpec="inline""#);
assert_eq!((left.x_align, left.y_align), (Some(Align::Start), None));
assert_eq!((left.x, placement(r#"w:tblpX="0""#).x), (None, twips(0)));
}
#[test]
fn reads_an_alignment_only_of_its_own_axis() {
let crossed = placement(r#"w:tblpXSpec="top" w:tblpYSpec="right""#);
assert_eq!((crossed.x_align, crossed.y_align), (None, None));
let inside = placement(r#"w:tblpXSpec="outside" w:tblpYSpec="inside""#);
assert_eq!(
(inside.x_align, inside.y_align),
(Some(Align::Outside), Some(Align::Start))
);
}
#[test]
fn reads_the_preferred_width_of_the_table() {
use super::PreferredWidth;
let width = |xml: &str| table(&format!("<w:tblPr>{xml}</w:tblPr>")).props.width;
let pct = |w: &str| format!(r#"<w:tblW w:w="{w}" w:type="pct"/>"#);
assert_eq!(width(&pct("5000")), Some(PreferredWidth::Percent(5000)));
assert_eq!(width(&pct("50%")), Some(PreferredWidth::Percent(2500)));
let dxa = r#"<w:tblW w:w="720" w:type="dxa"/>"#;
assert_eq!(width(dxa), twips(720).map(PreferredWidth::Length));
assert_eq!(width(r#"<w:tblW w:w="0" w:type="auto"/>"#), None);
let units = Length::from_units;
let of = |width: PreferredWidth| width.of(units(400));
assert_eq!(of(PreferredWidth::Percent(1250)), Some(units(100)));
assert_eq!(of(PreferredWidth::Length(units(7))), Some(units(7)));
assert_eq!(of(PreferredWidth::Percent(i64::MAX)), None);
}
#[test]
fn reads_a_width_with_text_outside_its_type_in_twips() {
use super::PreferredWidth;
let props = |xml: &str| table(&format!("<w:tblPr>{xml}</w:tblPr>")).props;
let width = |unit: &str| props(&format!(r#"<w:tblW w:w="720" w:type="{unit}"/>"#)).width;
let read = ["Dxa", "", "twips", "nil"].map(width);
let length = twips(720).map(PreferredWidth::Length);
assert_eq!(read, [length, length, length, None]);
let indent =
|unit: &str| props(&format!(r#"<w:tblInd w:w="720" w:type="{unit}"/>"#)).indent;
assert_eq!(
["dxa", "Dxa", "pct", "auto"].map(indent),
[twips(720), twips(720), None, None]
);
}
#[test]
fn reads_cell_margins_bands_and_the_grid() {
let t = table(
r#"<w:tblPr><w:tblCellMar><w:top w:w="10" w:type="dxa"/><w:start w:w="70" w:type="dxa"/><w:bottom w:w="5" w:type="dxa"/><w:right w:w="2" w:type="pct"/></w:tblCellMar>
<w:tblStyleRowBandSize w:val="2"/><w:tblStyleColBandSize w:val="0"/></w:tblPr>
<w:tblGrid><w:gridCol w:w="100"/><w:gridCol/></w:tblGrid>"#,
);
let m = &t.props.margins;
assert_eq!(
(m.top, m.left, m.bottom, m.right),
(twips(10), twips(70), twips(5), None)
);
assert_eq!(
(t.props.row_band, t.props.column_band),
(NonZeroUsize::new(2), None)
);
assert_eq!(t.grid, vec![twips(100).unwrap(), Length::ZERO]);
}
#[test]
fn widens_the_grid_for_a_row_that_takes_more_columns() {
let cell = |w: u32| {
format!(r#"<w:tc><w:tcPr><w:tcW w:w="{w}" w:type="dxa"/></w:tcPr><w:p/></w:tc>"#)
};
let t = table(&format!(
r#"<w:tblGrid><w:gridCol w:w="100"/><w:gridCol w:w="100"/></w:tblGrid><w:tr><w:trPr><w:gridBefore w:val="1"/></w:trPr>{}{}</w:tr><w:tr>{}{}</w:tr>"#,
cell(100),
cell(300),
cell(100),
cell(100)
));
let widths: Vec<Option<Length>> = [100, 100, 300].map(twips).into();
assert_eq!(t.grid.into_iter().map(Some).collect::<Vec<_>>(), widths);
}
#[test]
fn widens_the_grid_up_to_the_limit_of_grid_columns() {
let (t, limits) = table_and_limits(
r#"<w:tblGrid><w:gridCol w:w="100"/></w:tblGrid>
<w:tr><w:tc><w:tcPr><w:gridSpan w:val="10000000"/></w:tcPr><w:p/></w:tc></w:tr>
<w:tr><w:trPr><w:gridBefore w:val="10000000"/></w:trPr><w:tc><w:p/></w:tc></w:tr>"#,
);
assert_eq!(t.grid.len(), MAX_GRID_COLUMNS);
assert_eq!(t.grid.first().copied(), twips(100));
let row = |i: usize| &t.rows[i];
assert_eq!(
(row(0).cells[0].span.get(), row(1).grid_before),
(MAX_GRID_COLUMNS, MAX_GRID_COLUMNS)
);
assert_eq!(limits, [(Limit::GridColumns, 3)]);
}
#[test]
fn reads_a_grid_up_to_the_limit_of_grid_columns() {
let largest = Length::FILE_LIMIT / Length::UNITS_PER_TWIP;
let column = format!(r#"<w:gridCol w:w="{largest}"/>"#);
let grid = |columns: usize| {
table_and_limits(&format!(
"<w:tblGrid>{}</w:tblGrid><w:tr><w:tc><w:p/></w:tc></w:tr>",
column.repeat(columns)
))
};
let (t, limits) = grid(MAX_GRID_COLUMNS + 1);
assert_eq!(t.grid.len(), MAX_GRID_COLUMNS);
assert!(t.grid.iter().all(|width| Some(*width) == twips(largest)));
assert_eq!(limits, [(Limit::GridColumns, 1)]);
let (t, limits) = grid(MAX_GRID_COLUMNS);
assert_eq!((t.grid.len(), limits), (MAX_GRID_COLUMNS, Vec::new()));
}
#[test]
fn reads_the_largest_spans_without_an_overflow() {
let span = format!(
r#"<w:tc><w:tcPr><w:gridSpan w:val="{}"/></w:tcPr><w:p/></w:tc>"#,
i64::MAX
);
let (t, limits) = table_and_limits(&format!("<w:tr>{span}{span}{span}</w:tr>"));
assert_eq!(t.grid.len(), MAX_GRID_COLUMNS);
assert_eq!(limits, [(Limit::GridColumns, 5)]);
assert!(
t.rows[0]
.cells
.iter()
.all(|c| c.span.get() == MAX_GRID_COLUMNS)
);
}
#[test]
fn reads_alignment_values() {
let jc = |v: &str| {
table(&format!(r#"<w:tblPr><w:jc w:val="{v}"/></w:tblPr>"#))
.props
.alignment
};
assert_eq!(jc("right"), Some(TableAlignment::End));
assert_eq!(jc("end"), Some(TableAlignment::End));
assert_eq!(jc("left"), Some(TableAlignment::Start));
assert_eq!(jc("start"), Some(TableAlignment::Start));
assert_eq!(jc("both"), Some(TableAlignment::Start));
}
#[test]
fn reads_text_outside_the_type_of_a_table_alignment_as_missing() {
let jc = |v: &str| {
table(&format!(r#"<w:tblPr><w:jc w:val="{v}"/></w:tblPr>"#))
.props
.alignment
};
let read = ["Right", " right ", "", "far", "distribute"].map(jc);
assert_eq!(read, [None; 5]);
}
#[test]
fn reads_the_look_from_bits_and_attributes() {
let look = |attrs: &str| {
table(&format!("<w:tblPr><w:tblLook {attrs}/></w:tblPr>"))
.props
.look
.unwrap()
};
let flags = |look: Look| {
[
Look::FIRST_ROW,
Look::LAST_ROW,
Look::FIRST_COLUMN,
Look::LAST_COLUMN,
Look::NO_ROW_BANDS,
Look::NO_COLUMN_BANDS,
]
.map(|bit| look.has(bit))
};
let bits = look(r#"w:val="04A0""#);
assert_eq!(flags(bits), [true, false, true, false, false, true]);
let named = look(
r#"w:val="04A0" w:firstRow="0" w:lastRow="1" w:lastColumn="true" w:noHBand="on" w:noVBand="0""#,
);
assert_eq!(flags(named), [false, true, true, true, true, false]);
assert_eq!(look(r#"w:val="zz""#), Look::default());
}
const ROWS: &str = r#"<w:tr><w:trPr><w:trHeight w:val="300" w:hRule="exact"/><w:cantSplit/><w:tblHeader/><w:gridBefore w:val="1"/></w:trPr>
<w:tc><w:tcPr><w:tcW w:w="2000" w:type="dxa"/><w:gridSpan w:val="2"/><w:vMerge w:val="restart"/><w:vAlign w:val="center"/>
<w:tcBorders><w:bottom w:val="single" w:sz="4"/></w:tcBorders><w:tcMar><w:left w:w="0" w:type="dxa"/></w:tcMar></w:tcPr>
<w:p/><w:tbl><w:tr><w:tc><w:p/></w:tc></w:tr></w:tbl></w:tc>
<w:sdt><w:sdtContent><w:tc><w:tcPr><w:tcW w:w="50" w:type="pct"/><w:gridSpan w:val="0"/><w:vMerge/><w:vAlign w:val="bottom"/></w:tcPr><w:p/></w:tc></w:sdtContent></w:sdt></w:tr>
<w:customXml><w:tr><w:trPr><w:trHeight w:val="200" w:hRule="auto"/><w:cantSplit w:val="0"/><w:gridBefore w:val="x"/></w:trPr><w:tc><w:tcPr><w:vAlign w:val="top"/></w:tcPr></w:tc></w:tr></w:customXml>
<w:tr><w:trPr><w:trHeight w:val="100"/></w:trPr></w:tr>"#;
#[test]
fn reads_rows() {
let t = table(ROWS);
let rows: Vec<_> = t
.rows
.iter()
.map(|r| (r.height, r.cant_split, r.header, r.grid_before))
.collect();
let height = |h, rule| twips(h).map(|h| (h, rule));
assert_eq!(
rows,
vec![
(height(300, HeightRule::Exact), true, true, 1),
(height(200, HeightRule::Auto), false, false, 0),
(height(100, HeightRule::AtLeast), false, false, 0),
]
);
}
#[test]
fn reads_cells() {
let t = table(ROWS);
let cells: Vec<_> = [
&t.rows[0].cells[0],
&t.rows[0].cells[1],
&t.rows[1].cells[0],
]
.iter()
.map(|c| (c.width, c.span.get(), c.merge, c.align, c.blocks.len()))
.collect();
assert_eq!(
cells,
vec![
(
twips(2000).map(super::PreferredWidth::Length),
2,
Some(Merge::Restart),
Some(VerticalAlign::Center),
2
),
(
Some(super::PreferredWidth::Percent(50)),
1,
Some(Merge::Continue),
Some(VerticalAlign::Bottom),
1
),
(None, 1, None, Some(VerticalAlign::Top), 0),
]
);
}
#[test]
fn reads_text_outside_the_type_of_a_cell_alignment_as_missing() {
let align = |v: &str| {
let t = table(&format!(
r#"<w:tr><w:tc><w:tcPr><w:vAlign w:val="{v}"/></w:tcPr><w:p/></w:tc></w:tr>"#
));
t.rows[0].cells[0].align
};
let read = ["both", "Center", " center ", "", "middle"].map(align);
assert_eq!(read, [Some(VerticalAlign::Top), None, None, None, None]);
}
#[test]
fn reads_a_cell_deletion_from_the_cell_s_own_properties() {
let t = table(
r#"<w:tr><w:tc><w:tcPr><w:cellDel w:id="7" w:author="Ann"/><w:tcPrChange><w:tcPr><w:cellDel w:id="8" w:author="Bob"/></w:tcPr></w:tcPrChange></w:tcPr><w:p/></w:tc><w:tc><w:tcPr><w:tcPrChange><w:tcPr><w:cellDel w:id="9" w:author="Bob"/></w:tcPr></w:tcPrChange></w:tcPr><w:p/></w:tc></w:tr>"#,
);
let deletions: Vec<_> = t.rows[0].cells.iter().map(|c| c.deletion.clone()).collect();
let ann = super::CellDeletion {
id: "7".to_owned(),
author: "Ann".to_owned(),
};
assert_eq!(deletions, [Some(ann), None]);
}
#[test]
fn skips_rows_and_cells_in_other_elements() {
let t = table(
"<w:unknown><w:tr/></w:unknown><w:tr><w:bookmarkStart/><w:unknown><w:tc/></w:unknown></w:tr>",
);
assert_eq!(t.rows.len(), 1);
assert_eq!(t.rows[0].cells, Vec::new());
}
#[test]
fn reads_the_dashes_of_the_style_of_a_side() {
let dash = |style: &str| {
let t = table(&format!(
r#"<w:tblPr><w:tblBorders><w:insideV w:val="{style}" w:sz="4"/></w:tblBorders></w:tblPr>"#
));
t.props
.borders
.inside_v
.and_then(Side::line)
.map(|b| b.dash)
};
assert_eq!(dash("dotted"), Some(Some(DashStyle::Dotted)));
assert_eq!(dash("dashed"), Some(Some(DashStyle::Dashed)));
assert_eq!(dash("dotDash"), Some(Some(DashStyle::DotDash)));
assert_eq!(dash("dotDotDash"), Some(Some(DashStyle::DotDotDash)));
assert_eq!(dash("single"), Some(None));
assert_eq!(dash("dashSmallGap"), Some(None));
assert_eq!(dash("none"), None);
}
#[test]
fn reads_cell_borders_margins_and_content() {
let t = table(ROWS);
let cell = &t.rows[0].cells[0];
assert!(cell.borders.bottom.and_then(Side::line).is_some());
assert_eq!(cell.margins.left, Some(Length::ZERO));
assert!(matches!(
cell.blocks.as_slice(),
[Block::Paragraph(_), Block::Table(_)]
));
}
fn overlaid() -> super::TableProps {
let base = table(
r#"<w:tblPr><w:tblStyle w:val="A"/><w:tblInd w:w="10" w:type="dxa"/><w:tblBorders><w:top w:val="single" w:sz="4"/><w:insideH w:val="single" w:sz="4"/></w:tblBorders><w:tblCellMar><w:left w:w="108" w:type="dxa"/></w:tblCellMar><w:tblLook w:val="0020"/></w:tblPr>"#,
);
let over = table(
r#"<w:tblPr><w:jc w:val="right"/><w:tblBorders><w:top w:val="nil"/><w:left w:val="single" w:sz="2"/><w:bottom w:val="single" w:sz="2"/><w:right w:val="single" w:sz="2"/><w:insideV w:val="single" w:sz="2"/></w:tblBorders><w:tblCellMar><w:top w:w="1" w:type="dxa"/><w:right w:w="2" w:type="dxa"/><w:bottom w:w="3" w:type="dxa"/></w:tblCellMar><w:tblStyleRowBandSize w:val="3"/><w:tblStyleColBandSize w:val="4"/></w:tblPr>"#,
);
let mut props = base.props;
props.apply(&over.props);
props
}
#[test]
fn reads_an_empty_none_apart_from_other_sides_without_a_line() {
let t = table(
r#"<w:tblPr><w:tblBorders><w:top w:val="none" w:sz="0" w:space="0" w:color="auto"/><w:left w:val="none" w:color="000000" w:sz="0"/><w:bottom w:val="none" w:sz="4"/><w:right w:val="none" w:space="1"/><w:insideH w:val="nil"/><w:insideV w:val="none"/></w:tblBorders></w:tblPr>"#,
);
let b = t.props.borders;
assert_eq!(
[b.top, b.left, b.bottom, b.right, b.inside_h, b.inside_v],
[
Side::None,
Side::Nil,
Side::Nil,
Side::Spaced(Length::from_points(1).unwrap()),
Side::Nil,
Side::None
]
.map(Some)
);
}
#[test]
fn later_table_properties_win() {
let props = overlaid();
assert_eq!(props.style.as_deref(), Some("A"));
assert_eq!(props.indent, twips(10));
assert_eq!(props.alignment, Some(TableAlignment::End));
assert_eq!(props.margins.left, twips(108));
assert_eq!(
(props.margins.top, props.margins.right, props.margins.bottom),
(twips(1), twips(2), twips(3))
);
assert!(props.look.unwrap().has(Look::FIRST_ROW));
assert_eq!(
(props.row_band, props.column_band),
(NonZeroUsize::new(3), NonZeroUsize::new(4))
);
}
#[test]
fn later_borders_win() {
let b = overlaid().borders;
let width = |side: Option<Side>| side.and_then(Side::line).map(|b| b.width);
let widths = [b.top, b.left, b.bottom, b.right, b.inside_h, b.inside_v].map(width);
let (half, quarter) = (Length::from_eighth_points(4), Length::from_eighth_points(2));
assert_eq!(widths, [None, quarter, quarter, quarter, half, quarter]);
assert_eq!(b.top, Some(Side::Nil));
}
#[test]
fn reads_each_region_of_a_table_style() {
let names = [
("wholeTable", Region::WholeTable),
("band1Vert", Region::Band1Vert),
("band2Vert", Region::Band2Vert),
("band1Horz", Region::Band1Horz),
("band2Horz", Region::Band2Horz),
("firstCol", Region::FirstCol),
("lastCol", Region::LastCol),
("firstRow", Region::FirstRow),
("lastRow", Region::LastRow),
("nwCell", Region::NwCell),
("neCell", Region::NeCell),
("swCell", Region::SwCell),
("seCell", Region::SeCell),
];
let read = |value: &str| {
let xml = format!(r#"<w:tblStylePr xmlns:w="{W}" w:type="{value}"/>"#);
let doc = Document::parse(xml.as_bytes(), &Limits::default()).unwrap();
let mut reader = PartReader::new(&doc);
let region = reader.enumeration(doc.root().unwrap(), "type", REGION);
(region, reader.invalid_values().len())
};
for (name, region) in names {
assert_eq!(read(name), (Some(region), 0));
}
assert_eq!(read("WholeTable"), (None, 1));
}
#[test]
fn each_enumeration_table_holds_each_name_of_its_type() {
crate::enumerations::assert_names(
REGION,
concat!(
"wholeTable firstRow lastRow firstCol lastCol band1Vert band2Vert band1Horz ",
"band2Horz neCell nwCell seCell swCell",
),
);
crate::enumerations::assert_names(super::TABLE_JC, "center end left right start both");
crate::enumerations::assert_names(super::TABLE_LAYOUT, "fixed autofit");
crate::enumerations::assert_names(super::CELL_V_ALIGN, "top center both bottom");
crate::enumerations::assert_names(super::PREFERRED_TYPE, "nil pct dxa auto");
crate::enumerations::assert_names(super::TWIPS_TYPE, "nil pct dxa auto");
crate::enumerations::assert_names(HEIGHT_RULE, "auto exact atLeast");
crate::enumerations::assert_names(super::MERGE, "continue restart");
crate::enumerations::assert_names(
super::TEXT_DIRECTION,
"tb rl lr tbV rlV lrV lrTb tbRl btLr lrTbV tbRlV tbLrV",
);
}
}