f-office-docx 0.1.0

DOCX model and Word's layout rules.
Documentation
//! Namespace URIs, and the elements that Word writes in two namespaces.

use f_office_xml::{Document, NodeId};

/// WordprocessingML main namespace.
pub const W: &str = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

/// WordprocessingML namespace of Word 2010, for text effects such as `w14:textOutline`.
pub const W14: &str = "http://schemas.microsoft.com/office/word/2010/wordml";

/// Office relationships namespace, used by attributes that name a relationship ID.
pub const R: &str = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";

/// WordprocessingML drawing namespace, for drawings in the text.
pub const WP: &str = "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";

/// Word 2010's additions to WordprocessingML drawings, such as sizes relative to the page
/// (`wp14:sizeRelH`).
pub const WP14: &str = "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing";

/// WordprocessingML shape namespace, for text boxes in drawings.
pub const WPS: &str = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";

/// Word's drawing groups (`wpg:wgp`), which hold shapes and pictures together.
pub const WPG: &str = "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup";

/// Markup compatibility namespace, for alternate content.
pub const MC: &str = "http://schemas.openxmlformats.org/markup-compatibility/2006";

/// DrawingML main namespace, used by the theme.
pub const A: &str = "http://schemas.openxmlformats.org/drawingml/2006/main";

/// DrawingML picture namespace, for pictures (`pic:pic`).
pub const PIC: &str = "http://schemas.openxmlformats.org/drawingml/2006/picture";

/// VML, the older drawing markup of ECMA-376 Part 4, which `w:pict` and `w:object` hold.
pub const V: &str = "urn:schemas-microsoft-com:vml";

/// Word's additions to VML, such as how text wraps around a shape (`w10:wrap`).
pub const W10: &str = "urn:schemas-microsoft-com:office:word";

/// Office's additions to VML, such as the mark of a horizontal rule (`o:hr`).
pub const O: &str = "urn:schemas-microsoft-com:office:office";

/// SmartArt (`dgm:relIds`).
pub const DGM: &str = "http://schemas.openxmlformats.org/drawingml/2006/diagram";

/// Word's saved drawings of SmartArt graphics (`dsp:drawing`).
pub const DSP: &str = "http://schemas.microsoft.com/office/drawing/2008/diagram";

/// Charts (`c:chart`, and the chart parts' `c:chartSpace`).
pub const C: &str = "http://schemas.openxmlformats.org/drawingml/2006/chart";

/// The charts of Office 2016 and later (`cx:chart`), such as a waterfall chart, which F-Office
/// does not read.
pub const CX: &str = "http://schemas.microsoft.com/office/drawing/2014/chartex";

/// Word's drawing canvas (`wpc:wpc`), which F-Office does not read.
pub const WPC: &str = "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas";

/// Word's symbol extension (`w16se:symEx`), a character in a font of its own, such as an emoji,
/// which F-Office does not read.
pub const W16SE: &str = "http://schemas.microsoft.com/office/word/2015/wordml/symex";

/// Office Math (`m:oMath`).
pub const M: &str = "http://schemas.openxmlformats.org/officeDocument/2006/math";

/// Custom document properties (`docProps/custom.xml`).
pub const CUSTOM_PROPERTIES: &str =
    "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties";

/// The value types of document properties (`vt:lpwstr`).
pub const VT: &str = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes";

/// The relationship type suffix of the custom properties part.
pub const REL_CUSTOM_PROPERTIES: &str = "/custom-properties";

/// The Strict namespaces of ECMA-376 and the Transitional namespaces that this crate reads
/// them as. Both spellings define the same elements and attributes.
pub const STRICT_ALIASES: &[(&str, &str)] = &[
    ("http://purl.oclc.org/ooxml/drawingml/diagram", DGM),
    ("http://purl.oclc.org/ooxml/drawingml/chart", C),
    ("http://purl.oclc.org/ooxml/wordprocessingml/main", W),
    ("http://purl.oclc.org/ooxml/drawingml/main", A),
    ("http://purl.oclc.org/ooxml/drawingml/picture", PIC),
    ("http://purl.oclc.org/ooxml/officeDocument/relationships", R),
    ("http://purl.oclc.org/ooxml/officeDocument/math", M),
    (
        "http://purl.oclc.org/ooxml/drawingml/wordprocessingDrawing",
        WP,
    ),
];

/// Relationship type of the styles part.
pub const REL_STYLES: &str = "/styles";

/// Relationship type of the theme part.
pub const REL_THEME: &str = "/theme";

/// Relationship type of the settings part.
pub const REL_SETTINGS: &str = "/settings";

/// Relationship type of the web settings part, which holds the HTML divs of a document that
/// was a web page.
pub const REL_WEB_SETTINGS: &str = "/webSettings";

/// Relationship type of the footnotes part.
pub const REL_FOOTNOTES: &str = "/footnotes";

/// Relationship type of the comments part.
pub const REL_COMMENTS: &str = "/comments";

/// Relationship type of the part that links replies to their comments.
pub const REL_COMMENTS_EXTENDED: &str = "/commentsExtended";

/// Word 2012 namespace, of the part that links replies to their comments.
pub const W15: &str = "http://schemas.microsoft.com/office/word/2012/wordml";

/// Word 2006 namespace, which holds the content of a text box of a Strict document
/// (`wne:txbxContent`).
pub const WNE: &str = "http://schemas.microsoft.com/office/word/2006/wordml";

/// Whether `node` is the content of a text box: `w:txbxContent`, or `wne:txbxContent`, which
/// Word writes in a Strict document.
pub fn is_text_box_content(doc: &Document, node: NodeId) -> bool {
    doc.is(node, W, "txbxContent") || doc.is(node, WNE, "txbxContent")
}

/// The content of the text box `text_box` (`wps:txbx`, `wp:txbx` or `v:textbox`): its child
/// `w:txbxContent` or `wne:txbxContent`.
pub fn text_box_content(doc: &Document, text_box: NodeId) -> Option<NodeId> {
    doc.child_elements(text_box)
        .find(|&child| is_text_box_content(doc, child))
}

/// Relationship type of the endnotes part.
pub const REL_ENDNOTES: &str = "/endnotes";

/// Relationship type of the numbering part.
pub const REL_NUMBERING: &str = "/numbering";

/// Relationship type of the font table part.
pub const REL_FONT_TABLE: &str = "/fontTable";

/// The namespace of the notes that F-Office leaves on a part's elements while it reads them,
/// such as the tracked change that held a run before the change was accepted. No part uses
/// it.
pub const NOTE: &str = "urn:f-office:note";