use std::rc::Rc;
use f_office_drawingml::color::on_white;
use f_office_drawingml::shape::{Geometry, ShapeLook, quarter_turns};
use f_office_fonts::FamilyName;
use f_office_paint::{Opacity, Rgb};
use f_office_units::scale::QUARTER_TURN;
use f_office_units::{Edges, Length};
use f_office_vml::css::{self, Style};
use f_office_vml::shape_type::{self, TextRect};
use f_office_xml::enumeration::{Values, another, own};
use f_office_xml::{Document, NodeId};
use crate::body::{Content, InlineDrawing, read_story};
use crate::enumerations::style_place;
use crate::floating::{
Floating, InsetEdge, PageArea, Position, Relative, TextFlow, TextPath, Wrap, WrapSides,
};
use crate::ns::{self, O, R, V, W, W10};
use crate::params::{VML_ARC_SIZE, VML_STROKE_WEIGHT, VML_TEXT_BOX_INSETS, VML_WRAP_DISTANCE};
use crate::picture::{Picture, VML_IMAGE, embedded_image, scale_to_original, turn};
use crate::props::Align;
use crate::reader::settings::{InlineVml, InlineVmlKind, VmlHolder};
use crate::reader::{PartReader, attribute};
use crate::warnings::{Drawing, Feature, ReadAs, Reason};
pub(crate) fn read(reader: &mut PartReader, node: NodeId) -> Option<Content> {
let doc = reader.doc;
skip_unread(reader, node);
let mut shapes = doc
.child_elements(node)
.filter(|child| SHAPES.iter().any(|name| doc.is(*child, V, name)));
let shape = shapes.next()?;
for later in shapes {
let drawing = if image_data(doc, later).is_some() {
Drawing::Picture
} else {
Drawing::Shape
};
reader.drawing_skipped(drawing, Reason::Unsupported);
}
let style = Style::new(doc.attribute(shape, None, "style").unwrap_or(""));
let holder = if doc.is(node, W, "object") && doc.child(node, O, "OLEObject").is_some() {
VmlHolder::EmbeddedObject {
original: original_size(reader, node),
}
} else {
VmlHolder::Picture
};
match reader.style_keyword(shape, &style, "position", POSITION) {
Some(CssPosition::Floating) => read_floating(reader, shape, &style)
.map(|floating| Content::Floating(Box::new(floating))),
Some(CssPosition::InLine) | None => read_inline(reader, shape, &style, holder)
.or_else(|| read_inline_shape(reader, shape, &style)),
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum CssPosition {
InLine,
Floating,
}
const POSITION: &Values<CssPosition> = &Values::new(&[
own("static", CssPosition::InLine),
own("absolute", CssPosition::Floating),
another("relative", CssPosition::InLine),
]);
fn read_inline(
reader: &mut PartReader,
shape: NodeId,
style: &Style,
holder: VmlHolder,
) -> Option<Content> {
let doc = reader.doc;
let data = image_data(doc, shape)?;
if !doc.is(shape, V, "shape") {
reader.drawing_skipped(Drawing::Picture, Reason::Unsupported);
return None;
}
let embed = embedded_image(reader, data, VML_IMAGE)?;
let (Some(width), Some(height)) = (size(style, "width"), size(style, "height")) else {
reader.drawing_skipped(Drawing::Picture, Reason::Unsupported);
return None;
};
if changes_colors(doc, data) {
reader.feature_not_supported(Feature::VmlPictureColors);
}
let text_box = doc.child(shape, V, "textbox");
if text_box.is_some_and(|text_box| ns::text_box_content(doc, text_box).is_some()) {
reader.feature_not_supported(Feature::VmlPictureTextBox);
}
let quarters = quarter_turns_of(reader, shape, style);
let mut picture = Picture {
drops: true,
turn: turn(quarters, [false; 2]),
scale_steps: reader.vml_sizes().picture_scale(holder),
..picture(reader, embed, data, width, height)
};
let (mut width, mut height) = (width, height);
if let (
VmlHolder::EmbeddedObject {
original: Some(original),
},
Some(steps),
) = (holder, reader.vml_sizes().preview_scale())
{
scale_to_original(&mut picture, (&mut width, &mut height), original, steps);
}
Some(Content::Object {
width,
height,
picture: Some(Box::new(picture)),
extent: None,
})
}
fn original_size(reader: &mut PartReader, node: NodeId) -> Option<(Length, Length)> {
Some((
reader.twips(node, "dxaOrig")?,
reader.twips(node, "dyaOrig")?,
))
}
fn image_data(doc: &Document, shape: NodeId) -> Option<NodeId> {
let (embed, (link_namespace, link)) = VML_IMAGE;
doc.child(shape, V, "imagedata").filter(|&data| {
doc.attribute(data, Some(R), embed).is_some()
|| doc.attribute(data, Some(link_namespace), link).is_some()
})
}
fn picture(
reader: &mut PartReader,
embed: &str,
data: NodeId,
width: Length,
height: Length,
) -> Picture {
Picture::new(embed, Edges::sized(width, height), crop(reader, data))
}
fn crop(reader: &mut PartReader, data: NodeId) -> Edges<i64> {
Edges::from(
["cropleft", "croptop", "cropright", "cropbottom"].map(|name| {
reader
.or_missing_in(data, (None, name), css::fraction)
.unwrap_or(0)
}),
)
}
fn size(style: &Style, name: &str) -> Option<Length> {
style
.get(name)
.and_then(css::length)
.filter(|length| length.units() >= 0)
}
const SHAPES: [&str; 5] = ["shape", "rect", "roundrect", "oval", "line"];
const STRAIGHT_CONNECTOR: &str = "_x0000_t32";
fn is_line(doc: &Document, shape: NodeId) -> bool {
doc.is(shape, V, "line")
|| doc
.attribute(shape, None, "type")
.map(|t| t.trim_start_matches('#'))
== Some(STRAIGHT_CONNECTOR)
}
fn read_inline_shape(reader: &mut PartReader, shape: NodeId, style: &Style) -> Option<Content> {
let doc = reader.doc;
if image_data(doc, shape).is_some() {
return None;
}
let (Some(width), Some(height)) = (size(style, "width"), size(style, "height")) else {
reader.drawing_skipped(Drawing::Shape, Reason::Unsupported);
return None;
};
let anchor_locked = doc.child(shape, W10, "anchorlock").is_some();
let rule = doc.attribute(shape, Some(O), "hr") == Some("t");
let kind = if rule {
InlineVmlKind::HorizontalRule
} else if outlined(doc, shape) {
InlineVmlKind::Outlined
} else {
InlineVmlKind::Plain
};
let InlineVml {
drawn: (drawn_width, drawn_height),
room: (width, height),
} = reader.vml_sizes().inline((width, height), kind);
let mut floating = Floating {
width: drawn_width,
height: drawn_height,
look: Some(look(reader, shape)),
..Floating::in_part(reader.part())
};
let quarters = quarter_turns_of(reader, shape, style);
turn_drawing(&mut floating, quarters);
text_box(reader, shape, &mut floating, quarters);
Some(Content::Drawing(Rc::new(InlineDrawing {
width,
height,
left: Length::ZERO,
top: Length::ZERO,
shape: floating,
drops: !rule,
anchor_locked,
extent: None,
})))
}
const LAYOUT_FLOW: &Values<TextFlow> = &Values::new(&[
own("horizontal", TextFlow::Across),
own("horizontal-ideographic", TextFlow::Across),
own("vertical", TextFlow::Turned),
own("vertical-ideographic", TextFlow::Turned),
]);
fn text_box(reader: &mut PartReader, shape: NodeId, floating: &mut Floating, quarters: i64) {
let doc = reader.doc;
if let Some(text_box) = doc.child(shape, V, "textbox") {
floating.insets = insets(reader, text_box);
floating.inset_edge = InsetEdge::Vml;
floating.text_rect = text_rect(reader, shape);
if let Some(content) = ns::text_box_content(doc, text_box) {
floating.blocks = read_story(reader, content);
let style = Style::new(doc.attribute(text_box, None, "style").unwrap_or(""));
let flow = reader.style_keyword(text_box, &style, "layout-flow", LAYOUT_FLOW);
if flow == Some(TextFlow::Turned) || quarters != 0 {
reader.feature_not_supported(Feature::TurnedTextBox);
}
}
}
}
fn text_rect(reader: &mut PartReader, shape: NodeId) -> Option<TextRect> {
let doc = reader.doc;
if !doc.is(shape, V, "shape") {
return None;
}
let id = doc
.attribute(shape, None, "type")?
.trim()
.trim_start_matches('#');
let kind = reader.shape_type(id)?;
let rect = path_attribute(doc, [shape, kind], "textboxrect")?;
let evaluated = evaluate_text_rect(doc, shape, kind, rect);
if evaluated.is_none() {
reader.feature_not_supported(Feature::VmlGeometry);
}
evaluated
}
fn path_attribute<'d>(doc: &'d Document, nodes: [NodeId; 2], name: &str) -> Option<&'d str> {
nodes.into_iter().find_map(|node| {
doc.child(node, V, "path")
.and_then(|path| doc.attribute(path, None, name))
})
}
fn pair(text: &str) -> Option<(i64, i64)> {
match shape_type::numbers(text)?.as_slice() {
[Some(across), Some(down)] => Some((*across, *down)),
_ => None,
}
}
fn adjust_values(doc: &Document, shape: NodeId, kind: NodeId) -> Option<Vec<i64>> {
let adjust_of = |node: NodeId| match doc.attribute(node, None, "adj") {
None => Some(Vec::new()),
Some(text) => shape_type::numbers(text),
};
let mut adjust: Vec<i64> = adjust_of(kind)?
.into_iter()
.map(Option::unwrap_or_default)
.collect();
for (index, value) in adjust_of(shape)?.into_iter().enumerate() {
if let Some(value) = value {
if adjust.len() <= index {
adjust.resize(index + 1, 0);
}
*adjust.get_mut(index)? = value;
}
}
Some(adjust)
}
fn equations(doc: &Document, nodes: [NodeId; 2]) -> Vec<&str> {
nodes
.into_iter()
.find_map(|node| doc.child(node, V, "formulas"))
.map_or_else(Vec::new, |formulas| {
doc.child_elements(formulas)
.filter(|f| doc.is(*f, V, "f"))
.filter_map(|f| doc.attribute(f, None, "eqn"))
.collect()
})
}
fn evaluate_text_rect(doc: &Document, shape: NodeId, kind: NodeId, rect: &str) -> Option<TextRect> {
let adjust = adjust_values(doc, shape, kind)?;
let size = match [shape, kind]
.into_iter()
.find_map(|node| doc.attribute(node, None, "coordsize"))
{
None => (shape_type::COORDINATES, shape_type::COORDINATES),
Some(text) => pair(text)?,
};
let values = shape_type::formulas(&equations(doc, [shape, kind]), &adjust, size)?;
let preset = doc
.attribute(kind, Some(O), "spt")
.and_then(|spt| spt.trim().parse().ok());
let edges = shape_type::text_rect(preset, rect, &values, &adjust, size)?;
let limo = match path_attribute(doc, [shape, kind], "limo") {
None => None,
Some(text) => Some(pair(text)?),
};
Some(TextRect { edges, size, limo })
}
const UNREAD: [(&str, Drawing); 5] = [
("group", Drawing::Shape),
("polyline", Drawing::Shape),
("arc", Drawing::Shape),
("curve", Drawing::Shape),
("image", Drawing::Picture),
];
fn skip_unread(reader: &mut PartReader, node: NodeId) {
let doc = reader.doc;
for child in doc.child_elements(node) {
if let Some((_, drawing)) = UNREAD.iter().find(|(name, _)| doc.is(child, V, name)) {
reader.drawing_skipped(*drawing, Reason::Unsupported);
}
}
}
fn turns(reader: &mut PartReader, shape: NodeId, style: &Style, floating: &Floating) -> i64 {
if floating.text_path.is_some() {
return 0;
}
quarter_turns_of(reader, shape, style)
}
fn drawn(
reader: &mut PartReader,
shape: NodeId,
style: &Style,
) -> (Option<ShapeLook>, Option<TextPath>) {
let path = if reader.vml_sizes().reads_text_paths() {
text_path(reader, shape, style)
} else {
None
};
match path {
Some(path) => (None, Some(path)),
None => (Some(look(reader, shape)), None),
}
}
fn text_path(reader: &mut PartReader, shape: NodeId, style: &Style) -> Option<TextPath> {
let doc = reader.doc;
let kind = doc.attribute(shape, None, "type")?.trim_start_matches('#');
if kind != "_x0000_t136" {
return None;
}
let path = doc.child(shape, V, "textpath")?;
let string = doc.attribute(path, None, "string")?;
let path_style = Style::new(doc.attribute(path, None, "style").unwrap_or(""));
let face = path_style
.get("font-family")?
.trim()
.trim_matches(['"', '\'']);
let color = reader
.or_missing_in(shape, (None, "fillcolor"), css::color)
.unwrap_or(Rgb::WHITE);
let opacity = doc
.child(shape, V, "fill")
.and_then(|fill| reader.or_missing_in(fill, (None, "opacity"), css::fraction))
.map_or(Opacity::FULL, Opacity::clamped);
let rotation = reader
.style_value(shape, style, "rotation", css::angle)
.unwrap_or(0);
Some(TextPath {
string: string.to_owned(),
face: FamilyName::new(face),
color: on_white(color, opacity),
rotation,
})
}
fn read_floating(reader: &mut PartReader, shape: NodeId, style: &Style) -> Option<Floating> {
let doc = reader.doc;
let embed = match image_data(doc, shape) {
None => None,
Some(data) if changes_colors(doc, data) => {
reader.drawing_skipped(Drawing::Picture, Reason::Unsupported);
return None;
}
Some(data) => Some((embedded_image(reader, data, VML_IMAGE)?, data)),
};
let (look, text_path) = embed
.as_ref()
.map_or_else(|| drawn(reader, shape, style), |_| (None, None));
let (width, height) = (size(style, "width"), size(style, "height"));
let (box_width, box_height) = (
width.unwrap_or(Length::ZERO),
height.unwrap_or(Length::ZERO),
);
let z_index = reader.style_value(shape, style, "z-index", css::number);
let mut floating = Floating {
h: across(reader, shape, style),
v: position(reader, shape, style, &DOWN),
width: box_width,
height: box_height,
behind: z_index.is_some_and(|z| z < 0),
stack: z_index.map_or(0, i64::unsigned_abs),
look,
picture: embed.map(|(embed, data)| picture(reader, embed, data, box_width, box_height)),
text_path,
..Floating::in_part(reader.part())
};
if doc.is(shape, V, "line") {
let point = |name| {
let text = doc.attribute(shape, None, name).unwrap_or("0,0");
let (x, y) = text.split_once(',').unwrap_or((text, "0"));
Some((css::length(x.trim())?, css::length(y.trim())?))
};
let ((x0, y0), (x1, y1)) = (point("from")?, point("to")?);
floating.h.offset = x0.min(x1);
floating.v.offset = y0.min(y1);
floating.width = x0.max(x1) - x0.min(x1);
floating.height = y0.max(y1) - y0.min(y1);
let flip = [x1 < x0, y1 < y0];
floating.look = floating.look.take().map(|look| look.flipped(flip));
} else if width.is_none() || height.is_none() {
let drawing = if floating.picture.is_some() {
Drawing::Picture
} else {
Drawing::Shape
};
reader.drawing_skipped(drawing, Reason::Unsupported);
return None;
} else if is_line(doc, shape) {
let flip = reader
.style_keyword(shape, style, "flip", FLIP)
.unwrap_or_default();
floating.look = floating.look.take().map(|look| look.flipped(flip));
}
let quarters = turns(reader, shape, style, &floating);
turn_drawing(&mut floating, quarters);
floating.wrap = wrap(reader, shape, style);
text_box(reader, shape, &mut floating, quarters);
Some(floating)
}
const FLIP: &Values<[bool; 2]> = &Values::new(&[
own("x", [true, false]),
own("y", [false, true]),
own("xy", [true, true]),
own("yx", [true, true]),
own("x y", [true, true]),
]);
fn quarter_turns_of(reader: &mut PartReader, shape: NodeId, style: &Style) -> i64 {
let rotation = reader
.style_value(shape, style, "rotation", css::angle)
.unwrap_or(0);
quarter_turns(rotation).unwrap_or_else(|| {
reader.feature_not_supported(Feature::VmlRotation);
0
})
}
fn turn_drawing(floating: &mut Floating, quarters: i64) {
floating.look = floating
.look
.take()
.map(|look| look.turned(quarters * QUARTER_TURN));
if let Some(picture) = &mut floating.picture {
picture.turn = turn(quarters, [false; 2]);
}
}
fn changes_colors(doc: &Document, data: NodeId) -> bool {
let on = |name| matches!(doc.attribute(data, None, name), Some("t" | "true" | "1"));
doc.attribute(data, None, "gain").is_some()
|| doc.attribute(data, None, "blacklevel").is_some()
|| on("grayscale")
|| on("bilevel")
}
struct Axis {
relative: (&'static str, &'static Values<Relative>),
text: Relative,
align: (&'static str, &'static Values<Option<Align>>),
offsets: [&'static str; 2],
}
const ACROSS: Axis = Axis {
relative: ("mso-position-horizontal-relative", RELATIVE_ACROSS),
text: TEXT_ACROSS,
align: ("mso-position-horizontal", ALIGN_ACROSS),
offsets: ["margin-left", "left"],
};
const DOWN: Axis = Axis {
relative: ("mso-position-vertical-relative", RELATIVE_DOWN),
text: TEXT_DOWN,
align: ("mso-position-vertical", ALIGN_DOWN),
offsets: ["margin-top", "top"],
};
const TEXT: &str = "text";
const TEXT_ACROSS: Relative = Relative::Column;
const TEXT_DOWN: Relative = Relative::Paragraph;
const RELATIVE_ACROSS: &Values<Relative> = &Values::new(&[
own("margin", Relative::Area(PageArea::Margin)),
own("page", Relative::Area(PageArea::Page)),
own(TEXT, TEXT_ACROSS),
another("char", Relative::Area(PageArea::Margin)),
own("left-margin-area", Relative::Area(PageArea::StartMargin)),
own("right-margin-area", Relative::Area(PageArea::EndMargin)),
another("inner-margin-area", Relative::Area(PageArea::StartMargin)),
another("outer-margin-area", Relative::Area(PageArea::EndMargin)),
]);
const RELATIVE_DOWN: &Values<Relative> = &Values::new(&[
own("margin", Relative::Area(PageArea::Margin)),
own("page", Relative::Area(PageArea::Page)),
own(TEXT, TEXT_DOWN),
another("line", Relative::Paragraph),
own("top-margin-area", Relative::Area(PageArea::StartMargin)),
own("bottom-margin-area", Relative::Area(PageArea::EndMargin)),
another("inner-margin-area", Relative::Area(PageArea::StartMargin)),
another("outer-margin-area", Relative::Area(PageArea::EndMargin)),
]);
const ALIGN_ACROSS: &Values<Option<Align>> = &Values::new(&[
own("absolute", None),
own("left", Some(Align::Start)),
own("center", Some(Align::Center)),
own("right", Some(Align::End)),
another("inside", Some(Align::Start)),
another("outside", Some(Align::End)),
]);
const ALIGN_DOWN: &Values<Option<Align>> = &Values::new(&[
own("absolute", None),
own("top", Some(Align::Start)),
own("center", Some(Align::Center)),
own("bottom", Some(Align::End)),
another("inside", Some(Align::Start)),
another("outside", Some(Align::End)),
]);
fn position(reader: &mut PartReader, shape: NodeId, style: &Style, axis: &Axis) -> Position {
let (property, table) = axis.relative;
let from = reader
.style_keyword(shape, style, property, table)
.unwrap_or(axis.text);
let (property, table) = axis.align;
let align = reader
.style_keyword(shape, style, property, table)
.flatten();
let offset = axis
.offsets
.iter()
.find_map(|name| reader.style_value(shape, style, name, css::length))
.unwrap_or(Length::ZERO);
Position {
from,
offset,
align,
share: None,
}
}
fn across(reader: &mut PartReader, shape: NodeId, style: &Style) -> Position {
let mut place = position(reader, shape, style, &ACROSS);
if place.from == TEXT_ACROSS {
place.from = Relative::Area(PageArea::Margin);
reader.note_text_column(shape);
}
place
}
pub(crate) fn warn_text_column(reader: &mut PartReader, shape: NodeId) {
reader.not_supported(shape, style_place(ACROSS.relative.0), TEXT);
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum WrapType {
Square,
Beside,
TopAndBottom,
Off,
}
const WRAP_TYPE: &Values<WrapType> = &Values::new(&[
own("topAndBottom", WrapType::TopAndBottom),
own("square", WrapType::Square),
own("none", WrapType::Off),
own("tight", WrapType::Beside),
own("through", WrapType::Beside),
]);
const WRAP_SIDE: &Values<WrapSides> = &Values::new(&[
own("both", WrapSides::Both),
own("left", WrapSides::Left),
own("right", WrapSides::Right),
own("largest", WrapSides::Largest),
]);
fn wrap(reader: &mut PartReader, shape: NodeId, style: &Style) -> Option<Wrap> {
let element = reader.doc.child(shape, W10, "wrap")?;
let distance = |reader: &mut PartReader, side: &str, default: Length| {
let property = format!("mso-wrap-distance-{side}");
reader
.style_value(shape, style, &property, css::length)
.unwrap_or(default)
};
let beside = |reader: &mut PartReader, sides, polygon| Wrap::Beside {
distances: Edges {
left: distance(reader, "left", VML_WRAP_DISTANCE),
top: distance(reader, "top", Length::ZERO),
right: distance(reader, "right", VML_WRAP_DISTANCE),
bottom: distance(reader, "bottom", Length::ZERO),
},
sides,
polygon,
};
match reader.enumeration_in(element, (None, "type"), WRAP_TYPE)? {
WrapType::Square => {
let sides = reader.enumeration_in(element, (None, "side"), WRAP_SIDE);
Some(beside(reader, Some(sides.unwrap_or_default()), None))
}
WrapType::Beside => Some(beside(reader, None, Some(Edges::default()))),
WrapType::TopAndBottom => Some(Wrap::TopAndBottom {
above: distance(reader, "top", Length::ZERO),
below: distance(reader, "bottom", Length::ZERO),
}),
WrapType::Off => None,
}
}
fn insets(reader: &mut PartReader, text_box: NodeId) -> Edges<Length> {
let (side, top) = VML_TEXT_BOX_INSETS;
let defaults = [side, top, side, top];
let text = reader.doc.attribute(text_box, None, "inset").unwrap_or("");
let mut values = text.split(',').map(str::trim);
Edges::from(defaults.map(|default| match values.next() {
None | Some("") => default,
Some(value) => css::length(value).unwrap_or_else(|| {
reader.invalid(text_box, attribute("inset"), ReadAs::Missing);
default
}),
}))
}
fn on_unless_off(value: Option<&str>) -> bool {
!matches!(value, Some("f" | "false" | "0"))
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum FillType {
Solid,
}
const FILL_TYPE: &Values<FillType> = &Values::new(&[
own("solid", FillType::Solid),
another("gradient", FillType::Solid),
another("gradientRadial", FillType::Solid),
another("tile", FillType::Solid),
another("pattern", FillType::Solid),
another("frame", FillType::Solid),
]);
fn look(reader: &mut PartReader, shape: NodeId) -> ShapeLook {
let doc = reader.doc;
let attribute = |name: &str| doc.attribute(shape, None, name);
let on = |name: &str| on_unless_off(attribute(name));
let geometry = if is_line(doc, shape) {
Geometry::Line
} else if doc.is(shape, V, "rect") {
Geometry::Rect
} else if doc.is(shape, V, "oval") {
Geometry::Ellipse
} else if doc.is(shape, V, "roundrect") {
let arc = reader
.or_missing_in(shape, (None, "arcsize"), css::fraction)
.unwrap_or(VML_ARC_SIZE);
Geometry::RoundRect(arc / 2)
} else {
let geometry = match attribute("type").map(|t| t.trim_start_matches('#')) {
None | Some("_x0000_t202" | "_x0000_t1") => Geometry::Rect,
Some(_) => Geometry::Other,
};
if matches!(geometry, Geometry::Other) || attribute("path").is_some() {
reader.feature_not_supported(Feature::VmlGeometry);
}
geometry
};
let fill = on("filled").then(|| {
let fill_type = doc
.child(shape, V, "fill")
.and_then(|fill| reader.enumeration_in(fill, (None, "type"), FILL_TYPE));
match fill_type {
Some(FillType::Solid) | None => reader
.or_missing_in(shape, (None, "fillcolor"), css::color)
.unwrap_or(Rgb::WHITE),
}
});
let stroke = doc.child(shape, V, "stroke");
let stroke_attribute = |name: &str| stroke.and_then(|s| doc.attribute(s, None, name));
let line = outlined(doc, shape).then(|| {
let color = stroke
.and_then(|stroke| reader.or_missing_in(stroke, (None, "color"), css::color))
.or_else(|| reader.or_missing_in(shape, (None, "strokecolor"), css::color))
.unwrap_or(Rgb::BLACK);
let width = stroke_attribute("weight")
.or_else(|| attribute("strokeweight"))
.and_then(css::length)
.unwrap_or(VML_STROKE_WEIGHT);
(color, width)
});
ShapeLook::plain(geometry, fill, line)
}
fn outlined(doc: &Document, shape: NodeId) -> bool {
let stroke_on = doc
.child(shape, V, "stroke")
.and_then(|stroke| doc.attribute(stroke, None, "on"));
on_unless_off(doc.attribute(shape, None, "stroked")) && on_unless_off(stroke_on)
}
#[cfg(test)]
mod tests;