use super::layout::{
control_line_seg_index, estimate_text_width, estimate_text_width_unrounded,
hancom_regenerated_space_width, map_pua_bullet_char, resolved_to_text_style,
};
use super::style_resolver::{detect_lang_category, ResolvedStyleSet};
use super::{hwpunit_to_px, px_to_hwpunit, TextStyle};
use crate::model::control::Control;
use crate::model::document::Section;
pub use crate::model::paragraph::SpaceMetric;
use crate::model::paragraph::{CharShapeRef, LineSeg, Paragraph};
use crate::model::shape::{Caption, CaptionDirection, ShapeObject};
use crate::renderer::layout_frame::LayoutFrame;
pub use crate::renderer::layout_frame::ParagraphBox;
mod caption_paragraph;
mod object_host_tail;
pub(crate) use object_host_tail::{composed_object_tail, composed_tac_row};
mod frame_geometry;
pub(crate) use caption_paragraph::{
compose_caption_paragraph, compose_caption_paragraph_with_storage,
};
mod inline_table_frame;
mod nested_table_frames;
mod vertical_cell_lines;
pub(crate) use inline_table_frame::{
inline_table_needs_reflow_measurement, inline_table_needs_reflow_measurement_with_storage,
inline_table_width_cache_is_stale, inline_table_width_cache_is_stale_with_storage,
measured_reflow_inline_table, measured_reflow_inline_table_with_storage,
reflow_inline_table_heights, reflow_inline_table_heights_with_storage,
};
pub(crate) use nested_table_frames::{
recompose_cell_lines_with_nested_tables, recompose_cell_lines_with_nested_tables_with_storage,
table_cells_have_no_stored_lines,
};
pub(crate) use vertical_cell_lines::compose_vertical_cell_lines;
mod inline_frame_admission;
mod inline_picture_metrics;
mod resolved_fields;
pub(crate) mod stored_margin_context;
mod stored_marker_frames;
mod stored_tac_host_frame;
mod stored_word_tail;
pub(crate) use inline_picture_metrics::{
inline_picture_ascent_ratio, inline_picture_occupied_size_hu, inline_picture_size_hu,
};
pub(crate) use stored_tac_host_frame::stored_tac_host_frame;
pub(crate) use stored_word_tail::{
project_current_body_box_rows, project_current_body_box_rows_with_storage,
project_current_marker_geometry_rows, project_current_marker_geometry_rows_with_storage,
project_current_source_program_rows, project_current_source_program_rows_with_storage,
project_stored_soft_wraps, project_stored_soft_wraps_with_storage,
projects_current_marker_geometry,
};
mod note_line_slots;
mod punctuation_slots;
pub(crate) use note_line_slots::NoteLineSlots;
#[derive(Debug, Clone, PartialEq, serde::Serialize)]
pub struct CharOverlapInfo {
pub border_type: u8,
pub inner_char_size: i8,
#[serde(skip_serializing_if = "Option::is_none")]
pub composition: Option<Box<super::char_overlap::Composition>>,
#[serde(skip)]
pub empty_ink: bool,
}
crate::storage::clone_fields!(CharOverlapInfo, {border_type, inner_char_size, composition, empty_ink});
#[derive(Debug, Clone, Default)]
pub struct ComposedTextRun {
pub literal_soft_hyphen: bool,
pub literal_figure_space: bool,
pub text: String,
pub char_style_id: u32,
pub lang_index: usize,
pub neutral_space_origin: Option<usize>,
pub char_overlap: Option<CharOverlapInfo>,
pub footnote_marker: Option<u16>,
pub display_text: Option<String>,
pub supplemental_metrics_blocked: bool,
pub inserted_control_text: bool,
pub space_metric: SpaceMetric,
pub regenerated_font_metrics: bool,
}
crate::storage::clone_fields!(ComposedTextRun, {literal_soft_hyphen, literal_figure_space, text, char_style_id, lang_index, neutral_space_origin, char_overlap, footnote_marker, display_text, supplemental_metrics_blocked, inserted_control_text, space_metric, regenerated_font_metrics});
impl ComposedTextRun {
fn try_clone<S: crate::storage::Storage>(&self, storage: &S) -> Result<Self, S::Error> {
crate::storage::try_clone(self, storage)
}
pub(crate) fn source_scalar_count(&self) -> usize {
if self.inserted_control_text && self.char_overlap.is_none() {
0
} else {
self.text.chars().count()
}
}
pub(crate) fn text_style(&self, styles: &ResolvedStyleSet) -> TextStyle {
match self.try_text_style(styles, &crate::storage::Unbounded) {
Ok(value) => value,
Err(never) => match never {},
}
}
pub(crate) fn try_text_style<S: crate::storage::Storage>(
&self,
styles: &ResolvedStyleSet,
storage: &S,
) -> Result<TextStyle, S::Error> {
let mut style = super::layout::try_resolved_to_text_style(
styles,
self.char_style_id,
self.lang_index,
storage,
)?;
if let Some(origin) = self.neutral_space_origin {
punctuation_slots::apply_space_origin(&mut style, styles, self.char_style_id, origin);
}
if mapped_symbol_fonts::owns_mapped_symbol_font(self) {
let mut family = storage.string(mapped_symbol_fonts::MAPPED_SYMBOL_FONT)?;
storage.push_char(&mut family, ',')?;
storage.push_str(&mut family, &style.font_family)?;
style.font_family = family;
}
if self.supplemental_metrics_blocked {
style.supplemental_metrics = None;
}
conjoining_jamo::apply_font(self, &mut style);
self.space_metric.apply_to_style(&mut style);
style.regenerated_font_metrics = self.regenerated_font_metrics;
style.literal_figure_space = self.literal_figure_space;
style.literal_soft_hyphen = self.literal_soft_hyphen;
if self.footnote_marker.is_some() {
style.script_metrics = super::script_metrics::ScriptMetricsContract::NoteReference;
style.superscript = true;
style.subscript = false;
}
if self.literal_figure_space {
style.literal_figure_space_em =
styles.literal_figure_space_em(self.char_style_id, self.lang_index);
}
Ok(style)
}
pub(crate) fn line_box_font_size(&self, styles: &ResolvedStyleSet) -> f64 {
styles
.char_styles
.get(self.char_style_id as usize)
.map(|style| style.font_size)
.filter(|size| *size > 0.0)
.unwrap_or(12.0)
}
}
mod auto_number_projection;
mod conjoining_jamo;
pub(crate) use auto_number_projection::project_caption as project_caption_auto_numbers;
pub(crate) use conjoining_jamo::{
project_stored_rows_with_selected_program,
project_stored_rows_with_selected_program_with_storage,
};
mod equation_line_metrics;
mod mapped_symbol_fonts;
mod stored_row_fragments;
mod text_metric_origin;
pub(crate) use stored_row_fragments::crosses_physical_frame as stored_rows_cross_physical_frame;
pub(crate) use text_metric_origin::regenerated_row as line_metrics_regenerated;
pub(crate) mod stored_row_projection;
pub(crate) mod supplemental_clusters;
#[derive(Debug, Clone)]
pub struct ComposedLine {
pub runs: Vec<ComposedTextRun>,
pub line_height: i32,
pub baseline_distance: i32,
pub segment_width: i32,
pub column_start: i32,
pub line_spacing: i32,
pub has_line_break: bool,
pub char_start: usize,
}
crate::storage::clone_fields!(ComposedLine, {runs, line_height, baseline_distance, segment_width, column_start, line_spacing, has_line_break, char_start});
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum InlineControlType {
Table,
Shape,
Other,
}
crate::storage::clone_copy!(InlineControlType);
#[derive(Debug, Clone)]
pub struct InlineControl {
pub line_index: usize,
pub control_index: usize,
pub control_type: InlineControlType,
}
crate::storage::clone_fields!(InlineControl, {line_index, control_index, control_type});
#[derive(Debug, Clone)]
pub struct ComposedParagraph {
pub lines: Vec<ComposedLine>,
pub para_style_id: u16,
pub inline_controls: Vec<InlineControl>,
pub numbering_text: Option<(String, crate::model::paragraph::MarkerHead)>,
pub tac_controls: Vec<(usize, i32, usize)>,
pub footnote_positions: Vec<(usize, u16, usize)>,
pub tab_extended: Vec<[u16; 7]>,
pub(crate) frame_geometry: Option<std::sync::Arc<frame_geometry::FrameGeometry>>,
pub(crate) horizontal_shaping:
Option<std::sync::Arc<crate::renderer::shaping_paragraph::HorizontalShapingLineOutcome>>,
}
crate::storage::clone_fields!(ComposedParagraph, {lines, para_style_id, inline_controls, numbering_text, tac_controls, footnote_positions, tab_extended, frame_geometry, horizontal_shaping});
#[derive(Default)]
pub(crate) struct SingleLineOverflowCache {
section_tab_key: std::cell::Cell<u64>,
entries: std::cell::RefCell<std::collections::HashMap<(usize, u32), bool>>,
}
impl SingleLineOverflowCache {
fn use_section_tab_key(&self, key: u64) {
if self.section_tab_key.replace(key) != key {
self.clear();
}
}
#[inline]
fn get(&self, para: &Paragraph, width_key: u32) -> Option<bool> {
self.entries
.borrow()
.get(&(para as *const Paragraph as usize, width_key))
.copied()
}
#[inline]
fn insert(&self, para: &Paragraph, width_key: u32, overflowed: bool) {
match self.insert_with_storage(para, width_key, overflowed, &crate::storage::Unbounded) {
Ok(value) => value,
Err(never) => match never {},
}
}
pub(crate) fn insert_with_storage<S: crate::storage::Storage>(
&self,
para: &Paragraph,
width_key: u32,
overflowed: bool,
storage: &S,
) -> Result<(), S::Error> {
{
let mut entries = self.entries.borrow_mut();
let key = (para as *const Paragraph as usize, width_key);
if !entries.contains_key(&key) {
storage.reserve_map(&mut entries, 1)?;
}
entries.insert(key, overflowed);
};
Ok(())
}
pub(crate) fn clear(&self) {
self.entries.borrow_mut().clear();
}
}
include!("composer/composition.inc.rs");
include!("composer/stored_tac_display.inc.rs");
include!("composer/stored_lines_runs.inc.rs");
include!("composer/inline_control_projection.inc.rs");
include!("composer/reflow_helpers.inc.rs");
include!("composer/stored_cell_reflow.inc.rs");
include!("composer/cell_line_breaking.inc.rs");
include!("composer/pua_surface.inc.rs");
mod empty_line_metrics;
pub(crate) mod inline_box_rows;
mod line_breaking;
pub(crate) use line_breaking::try_reflow_line_segs;
pub(crate) use line_breaking::{condense_space_savings_px, overflowing_space_cut};
mod picture_anchor_projection;
pub(crate) use line_breaking::{
control_is_square_float_object, control_is_width_neutral_marker, frame_metrics_for_line,
paragraph_end_font_size_px, text_word_ranges, text_word_ranges_with_storage,
};
pub mod lineseg_compare;
pub(crate) use line_breaking::{
control_owns_body_band, is_line_end_forbidden, is_line_start_forbidden,
layout_container_picture_band, layout_paragraph_in_frame,
layout_paragraph_in_frame_with_storage, layout_picture_anchor_in_frame, layout_picture_band,
paragraph_flow_end, recalculate_section_vpos, reflow_line_segs,
reflow_line_segs_after_cell_split, reflow_line_segs_after_cell_text_edit,
reflow_line_segs_in_stored_section, restamp_indentation, row_is_carved_from_box,
supports_picture_band_frame_controls, tokenize_paragraph, BreakToken, StoredRowMissPolicy,
};
#[cfg(test)]
mod lineseg_compare_tests;
#[cfg(test)]
mod re_sample_gen;
#[cfg(test)]
mod tests;
pub(crate) fn uses_remeasured_equation_frame(para: &Paragraph) -> bool {
line_breaking::remeasured_equation_start_row(para).is_some()
&& line_breaking::supports_cached_body_frame_controls(para)
&& !para.stored_text_partition_is_dirty()
}