Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Jan 13, 2025
1 parent 1247c54 commit 0b3f65b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
4 changes: 1 addition & 3 deletions source/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,7 @@ bool Path::isEmpty() const

bool Path::isUnique() const
{
if(m_data)
return plutovg_path_get_reference_count(m_data) == 1;
return false;
return plutovg_path_get_reference_count(m_data) == 1;
}

bool Path::parse(const char* data, size_t length)
Expand Down
6 changes: 3 additions & 3 deletions source/svgelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,9 @@ Transform SVGSVGElement::localTransform() const
lengthContext.valueForLength(m_height)
};

if(parentElement())
return SVGGraphicsElement::localTransform() * Transform::translated(viewportRect.x, viewportRect.y) * viewBoxToViewTransform(viewportRect.size());
return viewBoxToViewTransform(viewportRect.size());
if(isRootElement())
return viewBoxToViewTransform(viewportRect.size());
return SVGGraphicsElement::localTransform() * Transform::translated(viewportRect.x, viewportRect.y) * viewBoxToViewTransform(viewportRect.size());
}

void SVGSVGElement::render(SVGRenderState& state) const
Expand Down
3 changes: 3 additions & 0 deletions source/svgelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class SVGNode {
SVGElement* parentElement() const { return m_parentElement; }
void setParentElement(SVGElement* parent) { m_parentElement = parent; }

bool isRootElement() const { return m_parentElement == nullptr; }

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

private:
Expand Down Expand Up @@ -140,6 +142,7 @@ class SVGElement : public SVGNode {

SVGElement* previousElement() const;
SVGElement* nextElement() const;

SVGNode* addChild(std::unique_ptr<SVGNode> child);
SVGNode* firstChild() const;
SVGNode* lastChild() const;
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->parentElement() ? Overflow::Hidden : Overflow::Visible)
, m_overflow(element->isRootElement() ? Overflow::Visible : Overflow::Hidden)
, m_marker_start(parent.marker_start())
, m_marker_mid(parent.marker_mid())
, m_marker_end(parent.marker_end())
Expand Down
2 changes: 1 addition & 1 deletion source/svgparser.cpp
Original file line number Diff line number Diff line change
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->parentElement() == nullptr;
return element->isRootElement();
if(selector.type == PseudoClassSelector::Type::Is) {
for(const auto& subSelector : selector.subSelectors) {
for(const auto& simpleSelector : subSelector) {
Expand Down

0 comments on commit 0b3f65b

Please sign in to comment.