ES-DE/source/useelement.cpp
Leon Styhre 3acd894f37 Squashed 'external/lunasvg/' changes from 7417baa0a..d13d8e521
d13d8e521 Refactoring
4925c87a8 Update
794c38591 Update
49eee9643 Update
914aee5ea Update
3bb00ecee Fix ParserString string-view iterator cast in windows
fabea2008 Fix string-view iterator cast in windows
bbcf0d34f Update
081df20f2 Update
fe3101f91 Refactoring
e9a41dc83 Refactoring
637121f89 Update lunasvg.cpp
d0abdccb1 Remove Document transformation methods
caa4b2410 Fix ft_stroke_border_export assertion
592533914 Fix SW_FT_Outline points overflow #55
0d40b061c Update

git-subtree-dir: external/lunasvg
git-subtree-split: d13d8e521c21f5f750ef0f6f92163f0131afdd3e
2022-10-03 20:53:48 +02:00

100 lines
2.5 KiB
C++

#include "useelement.h"
#include "parser.h"
#include "layoutcontext.h"
#include "gelement.h"
#include "svgelement.h"
namespace lunasvg {
UseElement::UseElement()
: GraphicsElement(ElementID::Use)
{
}
Length UseElement::x() const
{
auto& value = get(PropertyID::X);
return Parser::parseLength(value, AllowNegativeLengths, Length::Zero);
}
Length UseElement::y() const
{
auto& value = get(PropertyID::Y);
return Parser::parseLength(value, AllowNegativeLengths, Length::Zero);
}
Length UseElement::width() const
{
auto& value = get(PropertyID::Width);
return Parser::parseLength(value, ForbidNegativeLengths, Length::HundredPercent);
}
Length UseElement::height() const
{
auto& value = get(PropertyID::Height);
return Parser::parseLength(value, ForbidNegativeLengths, Length::HundredPercent);
}
std::string UseElement::href() const
{
auto& value = get(PropertyID::Href);
return Parser::parseHref(value);
}
void UseElement::transferWidthAndHeight(Element* element) const
{
auto& width = get(PropertyID::Width);
auto& height = get(PropertyID::Height);
element->set(PropertyID::Width, width, 0x0);
element->set(PropertyID::Height, height, 0x0);
}
void UseElement::layout(LayoutContext* context, LayoutContainer* current) const
{
if(isDisplayNone())
return;
auto ref = context->getElementById(href());
if(ref == nullptr || context->hasReference(ref) || (current->id == LayoutId::ClipPath && !ref->isGeometry()))
return;
LayoutBreaker layoutBreaker(context, ref);
auto group = std::make_unique<GElement>();
group->parent = parent;
group->properties = properties;
LengthContext lengthContext(this);
auto _x = lengthContext.valueForLength(x(), LengthMode::Width);
auto _y = lengthContext.valueForLength(y(), LengthMode::Height);
auto transform = get(PropertyID::Transform);
transform += "translate(";
transform += std::to_string(_x);
transform += ' ';
transform += std::to_string(_y);
transform += ')';
group->set(PropertyID::Transform, transform, 0x10);
if(ref->id == ElementID::Svg || ref->id == ElementID::Symbol)
{
auto element = ref->cloneElement<SVGElement>();
transferWidthAndHeight(element.get());
group->addChild(std::move(element));
}
else
{
group->addChild(ref->clone());
}
group->layout(context, current);
}
std::unique_ptr<Node> UseElement::clone() const
{
return cloneElement<UseElement>();
}
} // namespace lunasvg