Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions svgnative/src/SVGDocumentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ void SVGDocumentImpl::ParseChild(XMLNode* child)
auto hrefAttr = child->GetAttribute(kHrefAttr, kXlinkNS);
if (!hrefAttr.found || !hrefAttr.value || hrefAttr.value[0] != '#')
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fell that those newlines are useful for readability. Can we keep them?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i have kept those newlines in latest one. Mistakenly removed last time. @dirkschulze

const float x = ParseLengthFromAttr(child, kXAttr, LengthType::kHorizontal);
const float y = ParseLengthFromAttr(child, kYAttr, LengthType::kVertical);
if (!isCloseToZero(x) || !isCloseToZero(y))
Expand All @@ -330,7 +329,6 @@ void SVGDocumentImpl::ParseChild(XMLNode* child)
graphicStyle.transform = mRenderer->CreateTransform();
graphicStyle.transform->Concat(1, 0, 0, 1, x, y);
}

std::string href{(hrefAttr.value + 1)};
AddChildToCurrentGroup(std::make_shared<Reference>(graphicStyle, classNames, fillStyle, strokeStyle, std::move(href)), std::move(idString));
}
Expand Down Expand Up @@ -606,7 +604,6 @@ void SVGDocumentImpl::ParseFillProperties(FillStyleImpl& fillStyle, const Proper
else if (result == SVGDocumentImpl::Result::kSuccess)
fillStyle.hasFill = true;
}

prop = propertySet.find(kFillOpacityProp);
if (prop != iterEnd)
{
Expand Down Expand Up @@ -820,7 +817,6 @@ float SVGDocumentImpl::ParseColorStop(const XMLNode* node, std::vector<ColorStop
// Value is "currentColor". Simply set value to CSS color property.
paint = fillStyle.color;
}

graphicStyle.stopOpacity = std::max<float>(0.0, std::min<float>(1.0, graphicStyle.stopOpacity));

colorStops.push_back(std::make_tuple(offset, paint, graphicStyle.stopOpacity));
Expand Down Expand Up @@ -1063,13 +1059,18 @@ void SVGDocumentImpl::TraverseTree(const ColorMap& colorMap, const Element& elem
if (it != mVisitedElements.end())
break; // We found a cycle. Do not continue rendering.
auto insertResult = mVisitedElements.insert(&reference);

// Render referenced content.
auto refIt = mIdToElementMap.find(reference.href);
if (refIt != mIdToElementMap.end())
{
ApplyCSSStyle(reference.classNames, graphicStyle, fillStyle, strokeStyle);
auto saveRestore = SaveRestoreHelper{mRenderer, reference.graphicStyle};
if ((*(refIt->second)).Type() == ElementType::kGraphic)
{
Graphic& graphic = static_cast<Graphic&>(*(refIt->second));
// it will call assignment operator and pass fillStyle from reference to graphic
graphic = reference;
}
TraverseTree(colorMap, *(refIt->second));
}

Expand Down Expand Up @@ -1115,7 +1116,7 @@ void SVGDocumentImpl::TraverseTree(const ColorMap& colorMap, const Element& elem
}
}

#ifndef STYLE_SUPPORT
#ifndef STYLE_SUPPORTn

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typo?

@tjindal tjindal Nov 29, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes its typo! and i have fixed in latest one @dirkschulze

// Deprecated style support
void SVGDocumentImpl::ApplyCSSStyle(
const std::set<std::string>&, GraphicStyleImpl&, FillStyleImpl&, StrokeStyleImpl&) {}
Expand Down
32 changes: 19 additions & 13 deletions svgnative/src/SVGDocumentImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,40 +133,46 @@ class SVGDocumentImpl
ElementType Type() const override { return ElementType::kGroup; }
};

struct Graphic : public Element
struct Reference : public Element
Comment thread
dirkschulze marked this conversation as resolved.
{
Graphic(GraphicStyleImpl& aGraphicStyle, std::set<std::string>& aClasses, FillStyleImpl& aFillStyle, StrokeStyleImpl& aStrokeStyle,
std::shared_ptr<Path> aPath)
Reference(GraphicStyleImpl& aGraphicStyle, std::set<std::string>& aClasses, FillStyleImpl& aFillStyle, StrokeStyleImpl& aStrokeStyle,
std::string aHref)
: Element(aGraphicStyle, aClasses)
, fillStyle{aFillStyle}
, strokeStyle{aStrokeStyle}
, path{std::move(aPath)}
, href{std::move(aHref)}
{
}

FillStyleImpl fillStyle;
StrokeStyleImpl strokeStyle;
std::shared_ptr<Path> path;
std::string href;

ElementType Type() const override { return ElementType::kGraphic; }
ElementType Type() const override { return ElementType::kReference; }
};

struct Reference : public Element

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no trailing whitespaces.

struct Graphic : public Element
{
Reference(GraphicStyleImpl& aGraphicStyle, std::set<std::string>& aClasses, FillStyleImpl& aFillStyle, StrokeStyleImpl& aStrokeStyle,
std::string aHref)
Graphic(GraphicStyleImpl& aGraphicStyle, std::set<std::string>& aClasses, FillStyleImpl& aFillStyle, StrokeStyleImpl& aStrokeStyle,
std::shared_ptr<Path> aPath)
: Element(aGraphicStyle, aClasses)
, fillStyle{aFillStyle}
, strokeStyle{aStrokeStyle}
, href{std::move(aHref)}
, path{std::move(aPath)}
{
}

FillStyleImpl fillStyle;
StrokeStyleImpl strokeStyle;
std::string href;
std::shared_ptr<Path> path;

ElementType Type() const override { return ElementType::kReference; }
ElementType Type() const override { return ElementType::kGraphic; }
Graphic& operator= (const Reference& refObj)
{
this->fillStyle = refObj.fillStyle; //internal Paint is transferred
this->strokeStyle = refObj.strokeStyle;
return *this;
}
};

SVGDocumentImpl(std::shared_ptr<SVGRenderer> renderer);
Expand Down
1 change: 1 addition & 0 deletions svgnative/src/SVGStringParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,7 @@ SVGDocumentImpl::Result ParsePaint(const std::string& colorString, const std::ma
{
if (urlResult == SVGDocumentImpl::Result::kInvalid && result != SVGDocumentImpl::Result::kInvalid)
paint = altPaint;

return result;
}

Expand Down