Crate hwpforge_core

Crate hwpforge_core 

Source
Expand description

HwpForge Core: format-independent Document Object Model.

This crate defines the universal document structure used across all HwpForge format conversions. It is the Anvil in the Forge metaphor – the surface on which all documents are shaped.

§Architecture

Core sits one layer above Foundation:

foundation (primitives: HwpUnit, Color, Index<T>)
    |
    v
core (this crate: Document, Section, Paragraph, Run)
    |
    v
blueprint (styles: CharShape, ParaShape, Template)
    |
    v
smithy-* (format codecs: HWPX, HWP5, Markdown)

Core has zero knowledge of XML, binary formats, or Markdown. It references style definitions by branded indices (Foundation’s CharShapeIndex, ParaShapeIndex) without depending on Blueprint.

§Document Lifecycle (Typestate)

Document<Draft>  --(validate)-->  Document<Validated>
   (mutable)                         (immutable)
  • Draft documents can be modified (add sections, set metadata).
  • Validated documents are structurally sound and ready for export.
  • Deserialization always produces Draft (must re-validate).

§DOM Hierarchy

Document
  +-- Metadata
  +-- Section[]
        +-- PageSettings
        +-- Paragraph[]
              +-- Run[]
                    +-- RunContent
                          +-- Text(String)
                          +-- Table(Box<Table>)
                          +-- Image(Image)
                          +-- Control(Box<Control>)

§Examples

use hwpforge_core::*;
use hwpforge_core::run::Run;
use hwpforge_core::section::Section;
use hwpforge_core::paragraph::Paragraph;
use hwpforge_foundation::{CharShapeIndex, ParaShapeIndex};

let mut doc = Document::new();
doc.add_section(Section::with_paragraphs(
    vec![Paragraph::with_runs(
        vec![Run::text("Hello, HwpForge!", CharShapeIndex::new(0))],
        ParaShapeIndex::new(0),
    )],
    PageSettings::a4(),
));

let validated = doc.validate().unwrap();
assert_eq!(validated.section_count(), 1);

Re-exports§

pub use caption::Caption;
pub use caption::CaptionSide;
pub use caption::DEFAULT_CAPTION_GAP;
pub use chart::ChartData;
pub use chart::ChartGrouping;
pub use chart::ChartSeries;
pub use chart::ChartType;
pub use chart::LegendPosition;
pub use chart::XySeries;
pub use column::ColumnDef;
pub use column::ColumnLayoutMode;
pub use column::ColumnSettings;
pub use column::ColumnType;
pub use control::ArrowStyle;
pub use control::Control;
pub use control::Fill;
pub use control::LineStyle;
pub use control::ShapePoint;
pub use control::ShapeStyle;
pub use document::Document;
pub use document::Draft;
pub use document::Validated;
pub use error::CoreError;
pub use error::CoreErrorCode;
pub use error::CoreResult;
pub use error::ValidationError;
pub use image::Image;
pub use image::ImageFormat;
pub use image::ImageStore;
pub use metadata::Metadata;
pub use numbering::NumberingDef;
pub use numbering::ParaHead;
pub use page::PageSettings;
pub use paragraph::Paragraph;
pub use run::Run;
pub use run::RunContent;
pub use section::BeginNum;
pub use section::HeaderFooter;
pub use section::LineNumberShape;
pub use section::MasterPage;
pub use section::PageBorderFillEntry;
pub use section::PageNumber;
pub use section::Section;
pub use section::Visibility;
pub use tab::TabDef;
pub use table::Table;
pub use table::TableCell;
pub use table::TableRow;

Modules§

caption
Caption types for shape objects (tables, images, textboxes, etc.).
chart
Chart types for OOXML-based chart support.
column
Multi-column layout settings for document sections.
control
Control elements: text boxes, hyperlinks, footnotes, endnotes, etc.
document
The Document type with typestate pattern.
error
Error types for the HwpForge Core crate.
image
Image types for embedded or referenced images.
metadata
Document metadata.
numbering
Numbering definitions for outline and list numbering.
page
Page settings for document sections.
paragraph
Paragraph: a sequence of runs with a paragraph shape reference.
run
Run and RunContent: the leaf nodes of the document tree.
section
Document sections.
tab
Tab property definitions.
table
Table types: Table, TableRow, TableCell.