fop_layout/layout/table/
types.rs1use crate::area::AreaId;
4use fop_types::Length;
5use std::fmt;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
13pub enum TableLayoutMode {
14 Auto,
17 #[default]
20 Fixed,
21}
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
29pub enum BorderCollapse {
30 #[default]
32 Separate,
33 Collapse,
35}
36
37impl fmt::Display for BorderCollapse {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 match self {
40 BorderCollapse::Separate => write!(f, "separate"),
41 BorderCollapse::Collapse => write!(f, "collapse"),
42 }
43 }
44}
45
46#[derive(Debug, Clone, PartialEq)]
48pub enum ColumnWidth {
49 Fixed(Length),
51
52 Proportional(f64),
54
55 Auto,
57}
58
59#[derive(Debug, Clone)]
63pub struct ColumnInfo {
64 pub width_spec: ColumnWidth,
66
67 pub computed_width: Length,
69
70 pub min_width: Length,
73
74 pub max_width: Length,
77}
78
79impl ColumnInfo {
80 pub fn new(width_spec: ColumnWidth) -> Self {
82 Self {
83 width_spec,
84 computed_width: Length::ZERO,
85 min_width: Length::ZERO,
86 max_width: Length::ZERO,
87 }
88 }
89
90 pub fn with_widths(width_spec: ColumnWidth, min_width: Length, max_width: Length) -> Self {
92 Self {
93 width_spec,
94 computed_width: Length::ZERO,
95 min_width,
96 max_width,
97 }
98 }
99}
100
101#[derive(Debug, Clone)]
103pub struct GridCell {
104 pub row: usize,
106
107 pub col: usize,
109
110 pub rowspan: usize,
112
113 pub colspan: usize,
115
116 pub content_id: Option<AreaId>,
118}
119
120#[derive(Debug, Clone, Copy)]
125pub struct CollapsedBorder {
126 pub width: Length,
128
129 pub color: fop_types::Color,
131
132 pub style: crate::area::BorderStyle,
134}
135
136impl CollapsedBorder {
137 pub fn new(width: Length, color: fop_types::Color, style: crate::area::BorderStyle) -> Self {
139 Self {
140 width,
141 color,
142 style,
143 }
144 }
145
146 pub fn none() -> Self {
148 Self {
149 width: Length::ZERO,
150 color: fop_types::Color::BLACK,
151 style: crate::area::BorderStyle::None,
152 }
153 }
154
155 pub fn is_visible(&self) -> bool {
157 self.width > Length::ZERO
158 && !matches!(
159 self.style,
160 crate::area::BorderStyle::None | crate::area::BorderStyle::Hidden
161 )
162 }
163}
164
165pub struct TableLayout {
167 pub(super) available_width: Length,
169
170 pub(super) border_spacing: Length,
172
173 pub(super) layout_mode: TableLayoutMode,
175
176 pub(super) border_collapse: BorderCollapse,
178}
179
180impl TableLayout {
181 pub fn new(available_width: Length) -> Self {
183 Self {
184 available_width,
185 border_spacing: Length::from_pt(2.0),
186 layout_mode: TableLayoutMode::Fixed,
187 border_collapse: BorderCollapse::Separate,
188 }
189 }
190
191 pub fn with_border_spacing(mut self, spacing: Length) -> Self {
193 self.border_spacing = spacing;
194 self
195 }
196
197 pub fn with_layout_mode(mut self, mode: TableLayoutMode) -> Self {
199 self.layout_mode = mode;
200 self
201 }
202
203 pub fn with_border_collapse(mut self, collapse: BorderCollapse) -> Self {
205 self.border_collapse = collapse;
206 self
207 }
208
209 pub fn layout_mode(&self) -> TableLayoutMode {
211 self.layout_mode
212 }
213
214 pub fn border_collapse(&self) -> BorderCollapse {
216 self.border_collapse
217 }
218}
219
220#[derive(Debug, Clone, Copy)]
224pub struct CellCollapsedBorders {
225 pub top: CollapsedBorder,
227 pub right: CollapsedBorder,
229 pub bottom: CollapsedBorder,
231 pub left: CollapsedBorder,
233}
234
235impl Default for CellCollapsedBorders {
236 fn default() -> Self {
237 Self {
238 top: CollapsedBorder::none(),
239 right: CollapsedBorder::none(),
240 bottom: CollapsedBorder::none(),
241 left: CollapsedBorder::none(),
242 }
243 }
244}