doc_view#
shared document fonts, page painting, thumbnails and page coordinates -- crate root lib/doc_view/src/lib.rs
Shared document presentation: stable fonts, pagination measurement and page drawing.
Extracted from jfWord's existing page adapter; no legacy or WordCraft counterpart.
doc_view crate root#
/// Document viewport gutter reserved for the vertical scrollbar (DIP).
/// Exclude it from page centering; it does not change document dimensions or pagination.
SCROLL_GUTTER: i32 = 14
fn ribbon_sample(format: doc_core::ResolvedFormat, fonts: &Fonts) -> ui::RibbonSampleCompact style-gallery typography, preserving relative script size and displacement. The caller prepares this family in the text engine before requesting a sample.
doc_view/src/coords.rs#
Source: lib/doc_view/src/coords.rs
Shared page coordinate conversion. Rendering, pointer input and thumbnails use one scale.
struct PageTransformAn isotropic page transform from twips to an absolute pixel rectangle.
impl PageTransform
fn new(width_twips: u32, rect: [i32; 4]) -> Option<Self>Create a transform for a nonempty page and pixel rectangle.fn scale(&self, twips: i32) -> i32Scale a twip length to pixels, truncating as in the existing document renderer.fn unscale(&self, pixels: i32) -> i32Convert a pixel offset from the page edge to twips.fn to_pixels(&self, point: [i32; 2]) -> [i32; 2]Convert a page-relative twip point to an absolute pixel point.fn to_page(&self, point: [i32; 2]) -> [i32; 2]Convert an absolute pixel point to page-relative twips, including points outside it.fn font_size(&self, half_points: u16) -> i32Scale a half-point font size to 24.8 pixel units.fn zoom_width(width_twips: u32, percent: i32) -> i32Page width in DIP at a zoom percentage, clamped to the supported 10–500 percent range.fn page_height(width_twips: u32, height_twips: u32, width: i32) -> i32Preserve a page's aspect ratio when its width is changed; invalid page widths return zero.
doc_view/src/fonts.rs#
Source: lib/doc_view/src/fonts.rs
Document-owned fallback fonts. GUI themes and styles never select a document face.
The SGF1 assets are DejaVu Sans 2.37, byte-identical to jfWord's previous defaults.
enum FontErrorThe text registry could not register the fixed document faces or their italic forms.Registration-- The registry is full, or a bundled face is invalid.Italic-- A synthetic italic face could not be registered.
struct FontsHandles to document fonts registered in onetext::Textinstance.Construct once per text engine and retain across document changes. Clones share the family cache and registered faces; do not use them with a different text engine.
impl Fonts
fn new(text: &mut Text) -> Result<Self, FontError>Register the fixed DejaVu Sans fallback, independently of GUI fonts and theme. Failure rolls back every font registered during this call.fn get(&self, format: ResolvedFormat) -> u32Resolve the currently supported character attributes to a registered face.fn families(&self) -> Vec<String>Bundled families on every platform, plus installed native font families. Browser enumeration does not request access to the user's local fonts.fn prepare(&self, text: &mut Text, document: &Document)Register requested faces before measuring. Names survive substitutions unchanged. The bounded cache is shared by layout, page drawing and thumbnails.fn substituted(&self, family: FontFamily) -> boolTrue when the requested family is unavailable and a bundled substitute is used.fn ensure(&self, text: &mut Text, family: FontFamily)Prepare a family for an isolated style-gallery sample using the same resolver as pages.fn valid(&self, text: &Text) -> boolCheck that every cached face still belongs to the live text engine.
doc_view/src/measure.rs#
Source: lib/doc_view/src/measure.rs
Font measurement adapter between doc_layout's twips and the shared text engine.
Operation order matches the previous jfWord measurement to preserve pagination.
struct FontMeasure<'a>Measures document text in twips with a registered document font set.
impl<'a> FontMeasure<'a>
fn new(text: &'a mut Text, fonts: &'a Fonts) -> SelfBorrow the shared text engine for layout.paginatealso restores its current font.fn paginate( document: &Document, text: &mut Text, fonts: &Fonts, ) -> Result<Layout, doc_layout::Error>Paginate with document fonts and restore the text engine's previous UI font on return.fn apply_paginated(editor:&mut doc_core::Editor,edit:doc_core::Edit,text:&mut Text,fonts:&Fonts)->Result<doc_core::Id,doc_layout::Error>Commit only if the new document can be paginated with the actual document fonts. Model errors and layout errors preserve the editor's revision and undo history.fn replace_fragment_paginated(editor:&mut doc_core::Editor,paragraph:doc_core::Id,start:usize,end:usize,fragment:doc_core::DocumentFragment,text:&mut Text,fonts:&Fonts)->Result<(doc_core::Id,usize),doc_layout::Error>Paste a fragment only if it fits the page layout; return its surviving trailing caret.fn fit_table(document:&Document,id:doc_core::Id,mode:doc_layout::TableFit,text:&mut Text,fonts:&Fonts)->Result<alloc::vec::Vec<u32>,doc_layout::Error>Compute table widths while preserving the UI's current font and font size.
doc_view/src/page.rs#
Source: lib/doc_view/src/page.rs
Shared page paint adapter and bounded thumbnails. Colors belong to the document.
Extracted unchanged in operation order from jfWord's original preview renderer.
fn page_backdrop(ui: &mut ui::Ui, rect: [i32; 4])Paint the subtle page drop shadow before a page canvas, keeping hit geometry unchanged.enum PageErrorA page index, geometry or thumbnail size cannot be rendered.Page-- The requested page is not in the layout.Geometry-- The page has invalid physical dimensions.Limit-- A thumbnail exceeds the bounded allocation budget.Fonts-- The document faces are not registered in the supplied text engine.
struct PageDrawA retained page drawing usable inUi::canvas, thumbnails and agent render resources.
impl PageDraw
fn new(layout: Rc<Layout>, index: usize, fonts: Fonts) -> Result<Self, PageError>Retain one page and the document fonts used during pagination.fn without_frame(mut self) -> SelfOmit the page outline when a surrounding gallery card paints its own frame. Document text, colors, measurement and pagination are unchanged.fn thumbnail(&self, text: &mut Text, width: i32) -> Result<Surface, PageError>Render a thumbnail through exactly the page renderer used by the editor canvas. Width is limited to 2048 pixels and the resulting height to 4096 pixels.
doc_view/src/cell_border_editor.rs#
Source: lib/doc_view/src/cell_border_editor.rs
struct CellBorderEditor
impl CellBorderEditor
fn new(row:usize,column:usize,borders:CellBorders)->Selffn show(&mut self,ui:&mut Ui,id:u32)Reserves 16 controls: four rows with style, eighth-point width and RGB color.fn change(&self)->Result<TableChange,Error>
doc_view/src/table.rs#
Source: lib/doc_view/src/table.rs
fn table_cell_at(page: &Page, x: i32, y: i32) -> Option<&CellBox>fn text_line_bounds(d:&Document,page:&Page,line:&doc_layout::Line)->[i32;4]Horizontal text hit regions in twips, excluding floating tables and their text distances. The full paragraph width must not intercept clicks on a neighboring floating cell.struct TableController
impl TableController
fn active(&self) -> boolfn cancel(&mut self)fn update( &mut self, d: &Document, page: &Page, index: usize, input: &UiInput, revision: u64, ) -> Option<(Id, TableChange)>Returns one command on release. Escape and revision changes cancel a gesture.fn draw_guide(&self, ui: &mut ui::Ui, page: usize, rect: [i32; 4], page_width: u32)fn draw_handles(&self,ui:&mut ui::Ui,d:&Document,page:&Page,rect:[i32;4])Paint stable move handles in the same page coordinates used by hit testing.
doc_view/src/table_editor.rs#
Source: lib/doc_view/src/table_editor.rs
struct TableProperties
impl TableProperties
fn new(table: &Table, row: usize, column: usize) -> Option<Self>fn show(&mut self, ui: &mut Ui, id: u32)Reserves five consecutive IDs andid + 0x10000for the height rule, in points.fn change(&self) -> TableChange
doc_view/src/formula_editor.rs#
Source: lib/doc_view/src/formula_editor.rs
struct FormulaEditorCalculation draft with an explicit revision and stable field/caret target.revision:u64
impl FormulaEditor
fn new(d:&Document,revision:u64,paragraph:Id,inline:usize,offset:usize)->Option<Self>Start at a text caret or edit a calculation field. No source data is changed.fn show(&mut self,ui:&mut Ui,id:u32,d:&Document)Five widget IDs. Preview always uses the current containing table and shared arithmetic.fn edit(&self)->Result<Edit,FormulaError>A complete insert/update edit. The caller checksrevisionbefore applying it.fn paragraph(&self)->IdAnchor paragraph for focus restoration after committing.
doc_view/src/table_style_editor.rs#
Source: lib/doc_view/src/table_style_editor.rs
struct TableStyleEditorDraft preserves every unexposed text property and distinguishes inheritance from explicit values.
impl TableStyleEditor
fn new(style:TableStyle,document:&Document)->Selffn show(&mut self,ui:&mut Ui,id:u32)Reserves IDs id..id+23. First eight IDs retain their earlier meanings.fn definition(&self)->Result<TableStyle,Error>
doc_view/src/table_position_editor.rs#
Source: lib/doc_view/src/table_position_editor.rs
struct TablePositionEditor
impl TablePositionEditor
fn new(t:&Table)->Selffn show(&mut self,ui:&mut Ui,id:u32)Reserves ten controls. Position is relative to the selected page, margin or anchor.fn change(&self)->TableChange
doc_view/src/ruler.rs#
Source: lib/doc_view/src/ruler.rs
Physical page rulers shared by document editors. Geometry uses twips, never text pixels.
Independently implemented for jfguiLib; the caller supplies document and view state.
/// Space reserved for a document ruler, in device-independent pixels.
RULER_SIZE: i32 = 22
/// Space around and between pages, in device-independent pixels.
PAGE_GAP: i32 = 18
struct RulerPalettePresentation colors of a ruler; these never change stored document colors.background: u32-- The surrounding document workspace.body: u32-- The ruler's writable body area.margin: u32-- The ruler's margin area.tick: u32-- Tick marks, labels and indent outlines.
impl RulerPalette
fn light(background: u32) -> SelfNeutral document-ruler colors for a light workspace.fn dark(background: u32) -> SelfNeutral document-ruler colors for a dark workspace.enum RulerAxisWhich physical direction a ruler measures.Horizontal-- Inches along the page width, with paragraph indent markers.Vertical-- Inches along the page height, aligned with the page's scroll offset.
struct RulerDrawRetained ruler drawing, aligned to the same displayed page rectangle asPageDraw.paragraph_only: bool-- A constrained text area such as a table cell: show indents/tabs, lock its margins.page: PageSettings-- The physical page and margins.paragraph: ParagraphFormat-- The selected paragraph's indents; ignored by the vertical ruler.axis: RulerAxis-- The physical direction of the ruler.page_start: i32-- Page start in pixels, relative to this drawing's origin on the measured axis.page_width: i32-- Displayed page width in pixels, defining exactly the editor's scale.dpi: u32-- Device scale (96 is 100%).font: u32-- Registered UI face used for ruler numbers.palette: RulerPalette-- View colors, independent of document formatting.
impl RulerDraw
fn version(&self) -> u32Content fingerprint for retained UI drawing. A selection can change indent markers without changing the document revision or the drawing's allocation.
doc_view/src/ruler_input.rs#
Source: lib/doc_view/src/ruler_input.rs
enum RulerHandleFirstLineHangingLeftIndentRightIndentMarginStartMarginEndTab(i32)NewTab
enum RulerEditParagraph(ParagraphFormat)Page(PageSettings)
struct RulerControllerOne controller per ruler, reusable by any document application on every platform.
impl RulerDraw
fn pixel_at(&self, twips: i32) -> i32fn twips_at(&self, pixel: i32) -> i32fn handle_at(&self, x: i32, y: i32) -> Option<RulerHandle>Hit geometry shared with drawing, including DPI and the displayed page zoom.
impl RulerController
fn cancel(&mut self)fn dragging(&self) -> boolfn preview(&self, draw: &mut RulerDraw, alignment: TabAlignment)Ruler-only preview; the document and its undo stack are untouched during a drag.fn update(&mut self, draw: &RulerDraw, input: &UiInput, context: u64, alignment: TabAlignment) -> Option<RulerEdit>Alt bypasses the 1/16-inch snap. Escape cancels. Dragging a tab away removes it.contextmust change when the document revision or target selection changes.
doc_view/src/tab_editor.rs#
Source: lib/doc_view/src/tab_editor.rs
struct TabEditor
impl TabEditor
fn new() -> Selffn reset(&mut self)fn show(&mut self, ui: &mut Ui, id: u32, tabs: &mut TabStops, allow_clear: bool) -> boolReserve eight consecutive widget IDs. Clear markers are available to style editors; effective paragraph lists use only the five visible tab alignments.
ALIGNMENTS: [&str; 6] = ["Links", "Zentriert", "Rechts", "Dezimal", "Vertikale Li ...
fn tab_selector(ui: &mut Ui, id: u32, alignment: &mut i32)Font-independent selector for the five ruler tab markers, at the caller's next rect.