mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-30 01:55:39 +00:00
0d52738239
e0f786c9b Fix parseStyle REVERT: d13d8e521 Refactoring REVERT: 4925c87a8 Update REVERT: 794c38591 Update REVERT: 49eee9643 Update REVERT: 914aee5ea Update REVERT: 3bb00ecee Fix ParserString string-view iterator cast in windows REVERT: fabea2008 Fix string-view iterator cast in windows REVERT: bbcf0d34f Update REVERT: 081df20f2 Update REVERT: fe3101f91 Refactoring REVERT: e9a41dc83 Refactoring git-subtree-dir: external/lunasvg git-subtree-split: e0f786c9be6fae1ffabddfe56fb1e0a1a7eb775d
100 lines
2.5 KiB
C++
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
|