question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem writing a changed DeepCopied document

See original GitHub issue

Hello! I have a problem writing a changed DeepCopied document.

Description

I have an original SVG file, that looks like that image I open it and make a deep copy of it:

var sampleDoc = SvgDocument.Open(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"../../../sample_closed.svg"));
var newDoc = (SvgDocument)sampleDoc.DeepCopy<SvgDocument>();
SvgPath newPath = (SvgPath)newDoc.Children[1].Children[1];

Then I make some changes to the path elements of the deep copied document. For example:

newPath.PathData[1] = new PointF(newPath.PathData[1].End.X - 1000, newPath.PathData[1].End.Y - 1000);

After that, I call Draw method to get changed png file as a result:

newDoc.Draw().Save(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"result.png"));

And it works fine: image

Then I try to save changed svg, calling Write method:

newDoc.Write(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"result.svg"));

But I get a svg file without any change as a result

Is it a bug or I do something wrong?

Used Versions

Target framework: .net 6.0

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mrbean-bremencommented, May 23, 2023

I had a look at this, and there seem to be two problems:

  • the writing is done based on the Nodes of the object, that are not created on adding an element to Children
  • DeepCopy does not check for equal references, so the same object referenced both as a child and as a node will end up as two different objects after the deep copy - updating the nodes will not have the expected effect

I think that at least the second one is a bug, and the first one is either a bug, or some missing convienence method, or at least documentation.

0reactions
mrbean-bremencommented, May 25, 2023

I would rather not have Nodes because they are complicating things.

Fair point.

However, only SvgTextBase is designed based on Nodes, and it is difficult to redesign it…

Well, the problem happens for other SvgElements too, in this case SvgPath, because Nodes are used for writing documents.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Comment format changing when copying from Word doc... - ...
Solved: Hi, I am using Adobe Acrobat Pro DC version 2019.012.20040 The comments I wanna add are in a different format in a...
Read more >
Shallow and deep copy operations
A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original. Two...
Read more >
How to override the copy/deepcopy operations for a Python ...
Its not clear from your problem why you need to override these methods, since you don't want to do any customization to the...
Read more >
copy in Python (Deep Copy and Shallow Copy)
It means that any changes made to a copy of the object do not reflect in the original object.
Read more >
Shallow vs Deep Copying of Python Objects
What's the difference between a shallow and a deep copy of a Python object? Learn how to clone arbitrary objects in Python, including...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found