2022-10-03 16:25:42 +00:00
|
|
|
|
#include "styledelement.h"
|
|
|
|
|
#include "parser.h"
|
|
|
|
|
|
|
|
|
|
namespace lunasvg {
|
|
|
|
|
|
2022-10-03 18:53:48 +00:00
|
|
|
|
StyledElement::StyledElement(ElementID id)
|
2022-10-03 16:25:42 +00:00
|
|
|
|
: Element(id)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Paint StyledElement::fill() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Fill);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parsePaint(value, this, Color::Black);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Paint StyledElement::stroke() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Stroke);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parsePaint(value, this, Color::Transparent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Color StyledElement::color() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Color);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseColor(value, this, Color::Black);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Color StyledElement::stop_color() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Stop_Color);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseColor(value, this, Color::Black);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Color StyledElement::solid_color() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Solid_Color);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseColor(value, this, Color::Black);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double StyledElement::opacity() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = get(PropertyID::Opacity);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseNumberPercentage(value, 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double StyledElement::fill_opacity() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Fill_Opacity);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseNumberPercentage(value, 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double StyledElement::stroke_opacity() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Stroke_Opacity);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseNumberPercentage(value, 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double StyledElement::stop_opacity() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Stop_Opacity);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseNumberPercentage(value, 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double StyledElement::solid_opacity() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Solid_Opacity);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseNumberPercentage(value, 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double StyledElement::stroke_miterlimit() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Stroke_Miterlimit);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseNumber(value, 4.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Length StyledElement::stroke_width() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Stroke_Width);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseLength(value, ForbidNegativeLengths, Length::One);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Length StyledElement::stroke_dashoffset() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Stroke_Dashoffset);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseLength(value, AllowNegativeLengths, Length::Zero);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LengthList StyledElement::stroke_dasharray() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Stroke_Dasharray);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseLengthList(value, ForbidNegativeLengths);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WindRule StyledElement::fill_rule() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Fill_Rule);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseWindRule(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WindRule StyledElement::clip_rule() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Clip_Rule);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseWindRule(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LineCap StyledElement::stroke_linecap() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Stroke_Linecap);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseLineCap(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LineJoin StyledElement::stroke_linejoin() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Stroke_Linejoin);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseLineJoin(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Display StyledElement::display() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = get(PropertyID::Display);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseDisplay(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Visibility StyledElement::visibility() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Visibility);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseVisibility(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Overflow StyledElement::overflow() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = get(PropertyID::Overflow);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseOverflow(value, parent == nullptr ? Overflow::Visible : Overflow::Hidden);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string StyledElement::clip_path() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = get(PropertyID::Clip_Path);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseUrl(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string StyledElement::mask() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = get(PropertyID::Mask);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseUrl(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string StyledElement::marker_start() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Marker_Start);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseUrl(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string StyledElement::marker_mid() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Marker_Mid);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseUrl(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string StyledElement::marker_end() const
|
|
|
|
|
{
|
2022-10-03 18:53:48 +00:00
|
|
|
|
auto& value = find(PropertyID::Marker_End);
|
2022-10-03 16:25:42 +00:00
|
|
|
|
return Parser::parseUrl(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool StyledElement::isDisplayNone() const
|
|
|
|
|
{
|
|
|
|
|
return display() == Display::None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool StyledElement::isOverflowHidden() const
|
|
|
|
|
{
|
|
|
|
|
return overflow() == Overflow::Hidden;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace lunasvg
|