-
Notifications
You must be signed in to change notification settings - Fork 40
Resolution for issue Fill or stroke attributes on a use element #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
4a4bed1
3fd71c3
4fdfbaf
18ac44d
3cf6720
01c6b0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,42 +133,99 @@ class SVGDocumentImpl | |
| ElementType Type() const override { return ElementType::kGroup; } | ||
| }; | ||
|
|
||
| struct Graphic : public Element | ||
| struct Reference : public Element | ||
|
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 | ||
| 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; | ||
|
|
||
| ElementType Type() const override { return ElementType::kReference; } | ||
| }; | ||
| std::shared_ptr<Path> path; | ||
|
|
||
| ElementType Type() const override { return ElementType::kGraphic; } | ||
| Graphic& operator= (const Reference& refObj) | ||
| { | ||
| if (refObj.fillStyle.hasFill) | ||
| { | ||
| this->fillStyle.hasFill = refObj.fillStyle.hasFill; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No space aligning please.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in above example you mentioned , by doing recent changes output is showing 'green' which is desired one. As style object of reference object is taken into account by defining assignment operator , which pass on the fill and stroke properties if any from reference object to object that gets referenced. i have removed the space aligning.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in above example ,with the original code (not including any recent changes) the output is first rect is yellow and second is also yellow. even our expectation is that the first rect will be yellow and the second is black. when reference("use") element is pointing to any graphic element, simply it will look up into map "mIdToElementMap" and if graphic element is found, it will further draw graphic element. inheritance is broken there after lookup from above map, all styling attributes which are applied to reference object they are ignored. i have also debug the area you pointed in discussion it simple saves the graphic style , but fill and stroke properties are not stored anywhere which actually fills the rect.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dirkschulze can you pls share your thoughts on above comment ? |
||
| this->fillStyle.internalPaint = refObj.fillStyle.internalPaint; | ||
| } | ||
| if (refObj.fillStyle.fillRule != WindingRule::kNonZero) | ||
| this->fillStyle.fillRule = refObj.fillStyle.fillRule; | ||
|
|
||
| if (refObj.fillStyle.fillOpacity != 1.0f) | ||
| this->fillStyle.fillOpacity = refObj.fillStyle.fillOpacity; | ||
|
|
||
| Color paint = Color{{0, 0, 0, 1.0}}; | ||
| if (paint != boost::get<Color>(refObj.fillStyle.paint)) | ||
| this->fillStyle.paint = refObj.fillStyle.paint; | ||
|
|
||
| if (refObj.fillStyle.visibility != true) | ||
| this->fillStyle.visibility = refObj.fillStyle.visibility; | ||
|
|
||
| ColorImpl color = Color{{0.0f, 0.0f, 0.0f, 1.0f}}; | ||
| if (refObj.fillStyle.color != color) | ||
| this->fillStyle.color = refObj.fillStyle.color; | ||
|
|
||
| if (refObj.fillStyle.clipRule != WindingRule::kNonZero) | ||
| this->fillStyle.clipRule = refObj.fillStyle.clipRule; | ||
|
|
||
| if (refObj.strokeStyle.hasStroke) | ||
| { | ||
| this->strokeStyle.hasStroke = refObj.strokeStyle.hasStroke; | ||
| this->strokeStyle.internalPaint = refObj.strokeStyle.internalPaint; | ||
| } | ||
| if (refObj.strokeStyle.strokeOpacity != 1.0f) | ||
| this->strokeStyle.strokeOpacity = refObj.strokeStyle.strokeOpacity; | ||
|
|
||
| if (refObj.strokeStyle.lineWidth != 1.0f) | ||
| this->strokeStyle.lineWidth = refObj.strokeStyle.lineWidth; | ||
|
|
||
| if (refObj.strokeStyle.lineCap != LineCap::kButt) | ||
| this->strokeStyle.lineCap = refObj.strokeStyle.lineCap; | ||
|
|
||
| if (refObj.strokeStyle.lineJoin != LineJoin::kMiter) | ||
| this->strokeStyle.lineJoin = refObj.strokeStyle.lineJoin; | ||
|
|
||
| if (refObj.strokeStyle.dashArray.size() != 0) | ||
| this->strokeStyle.dashArray = refObj.strokeStyle.dashArray; | ||
|
|
||
| if (refObj.strokeStyle.miterLimit != 4.0f) | ||
| this->strokeStyle.miterLimit = refObj.strokeStyle.miterLimit; | ||
|
|
||
| if (refObj.strokeStyle.dashOffset != 4.0f) | ||
| this->strokeStyle.dashOffset = refObj.strokeStyle.dashOffset; | ||
|
|
||
| if (paint != boost::get<Color>(refObj.strokeStyle.paint)) | ||
| this->strokeStyle.paint = refObj.strokeStyle.paint; | ||
|
|
||
| return *this; | ||
| } | ||
| }; | ||
| SVGDocumentImpl(std::shared_ptr<SVGRenderer> renderer); | ||
| ~SVGDocumentImpl() {} | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This group handling will create another chain of issues. Especially with inherited properties that you don't handle. It also assumes that you just need to pass style information to the first child. However, there might be multiple nested groups and the styles need to get inherited through those groups as well.
In general, the
<use>element is like another group with shifting its content to position x/y. Actually, the shifting should be identical to a translation via transform. The referenced content gets "copied in" here. I am quoting because we do not want to actually copy.The intention was the following:
So the code should already work as is. See overall comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Dirk, i get your point of multiple nested groups if given, and i modified changes recently again to make code more generalised.