f-office-docx 0.2.2

DOCX model and Word's layout rules.
Documentation
//! Paragraph and run properties, as written in a part and after the style cascade.

mod border;
mod color;
mod frame;
mod paragraph;
mod place;
mod run;
#[cfg(test)]
mod tests;

/// Only the table tests build a border from its parts.
#[cfg(test)]
pub use border::BorderParts;
pub use border::{ArtStyle, Border, Borders, DashStyle, NamedSides};
pub(crate) use border::{
    BORDER_NAMES, Gap, LineStyle, Relief, read_border, read_border_as, read_line_style,
    read_table_border,
};
pub use color::{Color, WHITE};
pub(crate) use color::{parse_color, read_page_color, read_shading, shows_shading};
pub use frame::{FrameMark, FramePr, FrameWrap};
pub use paragraph::{
    Alignment, HtmlAutoSpacing, Kashidas, LineSpacing, ListLevel, ListRef, MarkChange, ParaProps,
    TabKind, TabStop, TextAlignment,
};
pub(crate) use place::{ANCHOR, X_ALIGN, XAlign, Y_ALIGN, YAlign};
pub use place::{Align, Anchor};
pub use run::{
    BidiLanguageClass, CodeFormat, EastAsianScript, FontRef, Limit, MathScript, MathStep,
    MathStyle, OutlineColor, RunProps, Strike, TextFill, TextGlow, TextOutline, TextReflection,
    TextShadow, Underline, VerticalAlign,
};
#[cfg(test)]
pub use run::{BidiScript, TextEffect, UnsupportedProperty};
pub(crate) use run::{SmallFractions, UNDERLINE};

/// The value of a property with the name of the part that sets it: the part of the layer of
/// the cascade where the reader read it, such as the main document for a paragraph's own
/// properties or the styles part for a style. The layout's warning of a feature that the
/// property shows names this part ([`crate::Feature`]).
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SetIn<T> {
    /// The value.
    pub value: T,
    /// The name of the part that sets it, as a warning keeps it, which the copies of the value
    /// share.
    pub part: std::rc::Rc<f_office_warnings::Name>,
}

impl<T> SetIn<T> {
    /// The value `value` that `reader` reads in its part.
    pub(crate) fn read(value: T, reader: &crate::reader::PartReader) -> Self {
        Self {
            value,
            part: std::rc::Rc::new(f_office_warnings::Name::new(reader.part())),
        }
    }
}

/// The value of a property that a layer of the cascade sets, if one sets it.
pub(crate) fn value_of<T: Copy>(set: Option<&SetIn<T>>) -> Option<T> {
    set.map(|set| set.value)
}

/// Overlays one property of a style or of direct formatting, `source`, on `target`: a property
/// that `source` sets wins, and one that it leaves unset keeps `target`.
pub(crate) fn overlay<T: Clone>(target: &mut Option<T>, source: Option<&T>) {
    if let Some(value) = source {
        *target = Some(value.clone());
    }
}