Styles And Numbering¶
featherdoc::Document exposes style and numbering APIs for inspection,
controlled mutation, refactoring, and default formatting. Use this page to find
the direct entry points for style and numbering work.
Typed Signature Guide¶
Style APIs address styles by style_id. Numbering levels are zero-based.
Methods returning std::optional<T> return an empty value when the style,
numbering definition, or generated plan cannot be resolved.
Run-font size setters accept only finite positive values representable as an
unsigned 32-bit half-point count (at most 2147483647.5 points). Invalid,
NaN, infinite, zero, negative, and overflowing values fail before the styles
DOM is changed. Numbering mutations similarly reserve every required
abstractNumId and numId before attaching package parts or changing
paragraph/style XML; exhaustion reports identifier_space_exhausted without
leaving a partial numbering definition.
import_numbering_catalog(...) is all-or-nothing. It builds every definition,
instance, and result-summary entry in an isolated checked clone, then attaches
the singleton metadata and publishes the numbering DOM only after all fallible
work succeeds. Pugixml or standard allocation failure returns zero imported
items and preserves an existing part or leaves a missing part unattached, so the
same Document can retry safely.
Signature |
Parameters |
Return semantics |
|---|---|---|
|
|
|
|
None. |
Current numbering catalog for governance or reuse. |
|
|
Import counts and conflicts. |
|
|
Definition id, or empty when it cannot be ensured. |
|
|
|
|
|
Summary, or empty when the style is missing. |
|
|
|
|
|
|
|
|
|
|
|
Audit report for all or one table style. |
Numbering¶
Method |
Returns |
Purpose |
|---|---|---|
|
|
Attach a generated list to a paragraph. |
|
|
Start a new list instance for a paragraph. |
|
|
Remove list metadata from a paragraph. |
|
|
Enumerate numbering definitions. |
|
|
Find one numbering definition. |
|
|
Export definitions for governance or reuse. |
|
|
Import a numbering catalog. |
|
|
Attach an existing numbering definition to a paragraph. |
Numbering Mutation Transactions¶
set_paragraph_numbering(...), set_paragraph_list(...), and
restart_paragraph_list(...) prepare the numbering DOM, document
relationships, Content Types, and a replacement direct w:pPr before
publishing any state. set_paragraph_style_numbering(...) and
ensure_style_linked_numbering(...) likewise prepare the styles DOM,
numbering DOM, document relationships, and Content Types as one transaction.
Validation, identifier planning, attachment, clone, or allocation failure
leaves every live DOM, part-presence flag, dirty flag, and existing handle
unchanged.
A Paragraph argument must be a live tracked handle owned by the receiving
Document and must belong to its body or a loaded header/footer story. A
foreign or stale handle is rejected with std::errc::invalid_argument before
either document is mutated.
Setting direct paragraph or paragraph-style numbering replaces duplicate direct
w:numPr children with one canonical element in CT_PPr schema order.
The clear methods remove all direct w:numPr duplicates, including those in
repeated direct w:pPr elements, and remove a resulting empty, attribute-free
w:pPr. Clearing a target that has no direct numbering is a successful pure
no-op. In particular, clearing the implicit Normal style when the package
has no styles part does not attach word/styles.xml, add a relationship or
Content Types Override, or mark package state dirty; another missing style is
still reported as an error with the same no-mutation guarantee.
Successful direct paragraph operations exchange only the paragraph’s direct
w:pPr inside the existing story DOM. They do not retire the document handle
generation, so already obtained handles for the target Paragraph and its
Run children remain valid after success. Failure preserves those handles
and all package state. This guarantee does not preserve a raw XML handle into
the replaced old w:pPr subtree.
Styles¶
Method |
Returns |
Purpose |
|---|---|---|
|
|
Enumerate styles. |
|
|
Find a style by id. |
|
|
Resolve inherited style properties. |
|
|
Inspect one style’s usage. |
|
|
Inspect usage across all styles. |
|
|
Rename a style id. |
|
|
Move usage from one style to another. |
|
|
Generate conservative merge suggestions. |
|
|
Plan or apply unused style cleanup. |
|
|
Set or clear the paragraph’s directly applied style. |
|
|
Set or clear the run’s directly applied character style. |
Direct applied-style APIs accept only live tracked handles owned by the
receiving Document. Foreign and stale Paragraph or Run handles fail
with std::errc::invalid_argument before either package changes. Setters
prepare a checked replacement w:pPr/w:rPr and any missing styles-part
metadata before publishing either one. Validation, clone, attachment, or
allocation failure therefore preserves the complete package state and the
existing handle, allowing a safe retry on that same handle.
A successful setter keeps one direct w:pStyle or w:rStyle as the first
child of its direct property container and removes duplicate style children in
that container. Clear removes all such duplicates and removes the property
container when it becomes empty and has no attributes. These direct mutations
do not retire the document handle generation.
rename_style(...) and merge_style(...) are atomic across styles, body,
loaded headers/footers, document relationships, and Content Types.
apply_style_refactor(...) applies a clean multi-operation plan as one
all-or-nothing transaction, and restore_style_refactor(...) publishes all
accepted restore entries together. Allocation failure returns
std::errc::not_enough_memory without changing the published DOM, dirty
state, or existing handles. A successful non-empty mutation retires the old DOM
generation, so reacquire XML-backed handles from Document.
Default Formatting¶
Method |
Returns |
Purpose |
|---|---|---|
|
|
Read the default run font family. |
|
|
Set the default run font family. |
|
|
Set the default run language. |
|
|
Set the default paragraph bidi flag. |
|
|
Clear the default run font family. |
Table Style Quality¶
Method |
Returns |
Purpose |
|---|---|---|
|
|
Inspect a table style definition. |
|
|
Audit table style region consistency. |
|
|
Audit table style inheritance. |
|
|
Inspect table look flags. |
|
|
Apply conservative table look repairs. |
|
|
Run table style quality checks. |
Example¶
featherdoc::Document doc{"styled.docx"};
doc.open();
auto styles = doc.list_styles();
auto usage = doc.list_style_usage();
auto suggestions = doc.suggest_style_merges();
auto ¶graph = doc.paragraphs();
doc.set_paragraph_list(paragraph, featherdoc::list_kind::bullet);
doc.set_default_run_language("en-US");