Skip to content

Commit

Permalink
Internal: Rename SVGNode::parent to SVGNode::parentElement
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Jan 11, 2025
1 parent 3c203c4 commit 1247c54
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 27 deletions.
4 changes: 2 additions & 2 deletions source/lunasvg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ Element Node::toElement() const
Element Node::parentElement() const
{
if(m_node)
return m_node->parent();
return m_node->parentElement();
return Element();
}

Expand Down Expand Up @@ -376,7 +376,7 @@ Matrix Element::getGlobalMatrix() const
if(m_node == nullptr)
return Matrix();
auto transform = element(true)->localTransform();
for(auto parent = element()->parent(); parent; parent = parent->parent())
for(auto parent = element()->parentElement(); parent; parent = parent->parentElement())
transform.postMultiply(parent->localTransform());
return transform;
}
Expand Down
32 changes: 17 additions & 15 deletions source/svgelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ void SVGElement::parseAttribute(PropertyID id, const std::string& value)

SVGElement* SVGElement::previousElement() const
{
if(!parent())
auto parent = parentElement();
if(parent == nullptr)
return nullptr;
const auto& children = parent()->children();
const auto& children = parent->children();
auto it = children.begin();
auto end = children.end();
SVGElement* element = nullptr;
Expand All @@ -243,9 +244,10 @@ SVGElement* SVGElement::previousElement() const

SVGElement* SVGElement::nextElement() const
{
if(!parent())
auto parent = parentElement();
if(parent == nullptr)
return nullptr;
const auto& children = parent()->children();
const auto& children = parent->children();
auto it = children.rbegin();
auto end = children.rend();
SVGElement* element = nullptr;
Expand All @@ -263,7 +265,7 @@ SVGElement* SVGElement::nextElement() const

SVGNode* SVGElement::addChild(std::unique_ptr<SVGNode> child)
{
child->setParent(this);
child->setParentElement(this);
m_children.push_back(std::move(child));
return &*m_children.back();
}
Expand Down Expand Up @@ -372,17 +374,17 @@ SVGProperty* SVGElement::getProperty(PropertyID id) const

Size SVGElement::currentViewportSize() const
{
auto parentElement = parent();
if(parentElement == nullptr) {
auto parent = parentElement();
if(parent == nullptr) {
auto element = static_cast<const SVGSVGElement*>(this);
const auto& viewBox = element->viewBox();
if(viewBox.value().isValid())
return viewBox.value().size();
return Size(300, 150);
}

if(parentElement->id() == ElementID::Svg) {
auto element = static_cast<const SVGSVGElement*>(parentElement);
if(parent->id() == ElementID::Svg) {
auto element = static_cast<const SVGSVGElement*>(parent);
const auto& viewBox = element->viewBox();
if(viewBox.value().isValid())
return viewBox.value().size();
Expand All @@ -392,7 +394,7 @@ Size SVGElement::currentViewportSize() const
return Size(width, height);
}

return parentElement->currentViewportSize();
return parent->currentViewportSize();
}

void SVGElement::cloneChildren(SVGElement* parentElement) const
Expand Down Expand Up @@ -589,7 +591,7 @@ Transform SVGSVGElement::localTransform() const
lengthContext.valueForLength(m_height)
};

if(parent())
if(parentElement())
return SVGGraphicsElement::localTransform() * Transform::translated(viewportRect.x, viewportRect.y) * viewBoxToViewTransform(viewportRect.size());
return viewBoxToViewTransform(viewportRect.size());
}
Expand Down Expand Up @@ -763,12 +765,12 @@ std::unique_ptr<SVGElement> SVGUseElement::cloneTargetElement(SVGElement* target
if(targetElement == this || isDisallowedElement(targetElement))
return nullptr;
const auto& idAttr = targetElement->getAttribute(PropertyID::Id);
auto parentElement = parent();
while(parentElement) {
auto attribute = parentElement->findAttribute(PropertyID::Id);
auto parent = parentElement();
while(parent) {
auto attribute = parent->findAttribute(PropertyID::Id);
if(attribute && idAttr == attribute->value())
return nullptr;
parentElement = parentElement->parent();
parent = parent->parentElement();
}

auto tagId = targetElement->id();
Expand Down
6 changes: 3 additions & 3 deletions source/svgelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ class SVGNode {
Document* document() const { return m_document; }
SVGRootElement* rootElement() const { return m_document->rootElement(); }

SVGElement* parent() const { return m_parent; }
void setParent(SVGElement* parent) { m_parent = parent; }
SVGElement* parentElement() const { return m_parentElement; }
void setParentElement(SVGElement* parent) { m_parentElement = parent; }

virtual std::unique_ptr<SVGNode> clone(bool deep) const = 0;

private:
SVGNode(const SVGNode&) = delete;
SVGNode& operator=(const SVGNode&) = delete;
Document* m_document;
SVGElement* m_parent = nullptr;
SVGElement* m_parentElement = nullptr;
};

class SVGTextNode final : public SVGNode {
Expand Down
2 changes: 1 addition & 1 deletion source/svglayoutstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ SVGLayoutState::SVGLayoutState(const SVGLayoutState& parent, const SVGElement* e
, m_white_space(parent.white_space())
, m_direction(parent.direction())
, m_visibility(parent.visibility())
, m_overflow(element->parent() ? Overflow::Hidden : Overflow::Visible)
, m_overflow(element->parentElement() ? Overflow::Hidden : Overflow::Visible)
, m_marker_start(parent.marker_start())
, m_marker_mid(parent.marker_mid())
, m_marker_end(parent.marker_end())
Expand Down
6 changes: 3 additions & 3 deletions source/svgparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool RuleData::match(const SVGElement* element) const
switch(it->combinator) {
case SimpleSelector::Combinator::Child:
case SimpleSelector::Combinator::Descendant:
element = element->parent();
element = element->parentElement();
break;
case SimpleSelector::Combinator::DirectAdjacent:
case SimpleSelector::Combinator::InDirectAdjacent:
Expand Down Expand Up @@ -227,7 +227,7 @@ bool RuleData::matchPseudoClassSelector(const PseudoClassSelector& selector, con
if(selector.type == PseudoClassSelector::Type::Empty)
return element->children().empty();
if(selector.type == PseudoClassSelector::Type::Root)
return element->parent() == nullptr;
return element->parentElement() == nullptr;
if(selector.type == PseudoClassSelector::Type::Is) {
for(const auto& subSelector : selector.subSelectors) {
for(const auto& simpleSelector : subSelector) {
Expand Down Expand Up @@ -784,7 +784,7 @@ bool Document::parse(const char* data, size_t length)
auto id = elementid(buffer);
if(id != currentElement->id())
return false;
currentElement = currentElement->parent();
currentElement = currentElement->parentElement();
} else {
--ignoring;
}
Expand Down
8 changes: 5 additions & 3 deletions source/svgtextelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ static AlignmentBaseline resolveDominantBaseline(const SVGTextPositioningElement
static float calculateBaselineOffset(const SVGTextPositioningElement* element)
{
auto offset = element->baseline_offset();
for(auto parent = element->parent(); parent->isTextPositioningElement(); parent = parent->parent()) {
auto parent = element->parentElement();
while(parent->isTextPositioningElement()) {
offset += toSVGTextPositioningElement(parent)->baseline_offset();
parent = parent->parentElement();
}

auto baseline = element->alignment_baseline();
Expand Down Expand Up @@ -147,7 +149,7 @@ void SVGTextFragmentsBuilder::build(const SVGTextElement* textElement)
for(const auto& textPosition : m_textPositions) {
if(!textPosition.node->isTextNode())
continue;
auto element = toSVGTextPositioningElement(textPosition.node->parent());
auto element = toSVGTextPositioningElement(textPosition.node->parentElement());
SVGTextFragment fragment(element);
auto recordTextFragment = [&](auto startOffset, auto endOffset) {
auto text = wholeText.substr(startOffset, endOffset - startOffset);
Expand Down Expand Up @@ -239,7 +241,7 @@ void SVGTextFragmentsBuilder::handleText(const SVGTextNode* node)
const auto& text = node->data();
if(text.empty())
return;
auto element = toSVGTextPositioningElement(node->parent());
auto element = toSVGTextPositioningElement(node->parentElement());
const auto startOffset = m_text.length();
uint32_t lastCharacter = ' ';
if(!m_text.empty()) {
Expand Down

0 comments on commit 1247c54

Please sign in to comment.