Paragraph

Struct Paragraph 

Source
pub struct Paragraph {
    pub runs: Vec<Run>,
    pub para_shape_id: ParaShapeIndex,
    pub column_break: bool,
    pub page_break: bool,
    pub heading_level: Option<u8>,
    pub style_id: Option<StyleIndex>,
}
Expand description

A paragraph: an ordered sequence of runs sharing a paragraph shape.

§Examples

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

let para = Paragraph::with_runs(
    vec![Run::text("Hello", CharShapeIndex::new(0))],
    ParaShapeIndex::new(0),
);
assert_eq!(para.run_count(), 1);
assert!(!para.is_empty());

Fields§

§runs: Vec<Run>

Ordered sequence of runs.

§para_shape_id: ParaShapeIndex

Index into the paragraph shape collection (Blueprint resolves this).

§column_break: bool

Whether this paragraph starts a new column (HWPX columnBreak="1").

§page_break: bool

Whether this paragraph starts a new page (HWPX pageBreak="1").

§heading_level: Option<u8>

Optional heading level (1-7) for TOC participation. Maps to 개요 1-7 styles. Paragraphs with a heading level will emit <hp:titleMark> in HWPX for auto-TOC support.

§style_id: Option<StyleIndex>

Optional reference to a named style (e.g. 개요 1, 본문). None means 바탕글 (style 0, the default).

Implementations§

Source§

impl Paragraph

Source

pub fn new(para_shape_id: ParaShapeIndex) -> Self

Creates an empty paragraph with the given shape reference.

§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_foundation::ParaShapeIndex;

let para = Paragraph::new(ParaShapeIndex::new(0));
assert!(para.is_empty());
Source

pub fn with_runs(runs: Vec<Run>, para_shape_id: ParaShapeIndex) -> Self

Creates a paragraph with pre-built runs.

§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_core::run::Run;
use hwpforge_foundation::{CharShapeIndex, ParaShapeIndex};

let para = Paragraph::with_runs(
    vec![Run::text("text", CharShapeIndex::new(0))],
    ParaShapeIndex::new(0),
);
assert_eq!(para.run_count(), 1);
Source

pub fn add_run(&mut self, run: Run)

Appends a run to this paragraph.

§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_core::run::Run;
use hwpforge_foundation::{CharShapeIndex, ParaShapeIndex};

let mut para = Paragraph::new(ParaShapeIndex::new(0));
para.add_run(Run::text("hello", CharShapeIndex::new(0)));
assert_eq!(para.run_count(), 1);
Source

pub fn with_heading_level(self, level: u8) -> Self

Sets the heading level for TOC participation (1-7).

Paragraphs with a heading level emit <hp:titleMark> in HWPX, enabling 한글 to auto-build a Table of Contents from document headings.

§Panics

Panics if level is 0 or greater than 7.

§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_foundation::ParaShapeIndex;

let para = Paragraph::new(ParaShapeIndex::new(0))
    .with_heading_level(1);
assert_eq!(para.heading_level, Some(1));
Source

pub fn with_style(self, style_id: StyleIndex) -> Self

Sets the style ID for this paragraph.

§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_foundation::{ParaShapeIndex, StyleIndex};

let para = Paragraph::new(ParaShapeIndex::new(0))
    .with_style(StyleIndex::new(2));
assert_eq!(para.style_id, Some(StyleIndex::new(2)));
Source

pub fn with_page_break(self) -> Self

Marks this paragraph as starting a new page (HWPX pageBreak="1").

§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_foundation::ParaShapeIndex;

let para = Paragraph::new(ParaShapeIndex::new(0)).with_page_break();
assert!(para.page_break);
Source

pub fn try_with_heading_level(self, level: u8) -> CoreResult<Self>

Sets the heading level for TOC participation (1-7), returning an error if the level is out of range.

This is the fallible alternative to with_heading_level, suitable for user-supplied input where panicking is undesirable.

§Errors

Returns CoreError::InvalidStructure if level is 0 or greater than 7.

§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_foundation::ParaShapeIndex;

let para = Paragraph::new(ParaShapeIndex::new(0))
    .try_with_heading_level(3)
    .unwrap();
assert_eq!(para.heading_level, Some(3));

let err = Paragraph::new(ParaShapeIndex::new(0))
    .try_with_heading_level(0);
assert!(err.is_err());
Source

pub fn text_content(&self) -> String

Concatenates all text runs into a single string.

Non-text runs (Table, Image, Control) are silently skipped. This is useful for full-text search and preview generation.

§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_core::run::Run;
use hwpforge_core::table::Table;
use hwpforge_foundation::{CharShapeIndex, ParaShapeIndex};

let para = Paragraph::with_runs(
    vec![
        Run::text("Hello ", CharShapeIndex::new(0)),
        Run::table(Table::new(vec![]), CharShapeIndex::new(0)),
        Run::text("world", CharShapeIndex::new(0)),
    ],
    ParaShapeIndex::new(0),
);
assert_eq!(para.text_content(), "Hello world");
Source

pub fn run_count(&self) -> usize

Returns the number of runs.

Source

pub fn is_empty(&self) -> bool

Returns true if this paragraph has no runs.

Trait Implementations§

Source§

impl Clone for Paragraph

Source§

fn clone(&self) -> Paragraph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Paragraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Paragraph

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Paragraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl JsonSchema for Paragraph

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for Paragraph

Source§

fn eq(&self, other: &Paragraph) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Paragraph

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Paragraph

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,