Git Product home page Git Product logo

Comments (5)

Moggel12 avatar Moggel12 commented on August 16, 2024 1

Alright, just spotted that the problem only occurs when elements are added to a group prior to being added to an SvgDocument. I edited the previous comment so that the problem actually occurs. Sorry!

from svg.

Moggel12 avatar Moggel12 commented on August 16, 2024 1

@Moggel12 Thanks for the illustration. Please, is this related to #946 ?

It may be an extension to it, but I don't believe it to be the same. In my case, no transformations have been added to the group. However, it does look like #946 adds elements to the group first and then adds the group to the document, so maybe the same root cause?

from svg.

paulushub avatar paulushub commented on August 16, 2024

@Moggel12 It will help a lot if you provide a sample.

from svg.

Moggel12 avatar Moggel12 commented on August 16, 2024

Sure, something like this? @paulushub

using Svg;

var document = new SvgDocument()
{
    Width = new SvgUnit(SvgUnitType.Inch, 10),
    Height = new SvgUnit(SvgUnitType.Inch, 10),
    FontSize = 15,
    FontFamily = "Sans-Serif",
};

var svgGroup = new SvgGroup();

float x = 100, y = 100;

var xLocation = new SvgUnitCollection();
var yLocation = new SvgUnitCollection();

xLocation.Add(x);
yLocation.Add(y);

var textBox = new SvgText
{
    X = xLocation,
    Y = yLocation
};

var lines = new List<string>()
{
    "This is",
    "a multiline",
    "test"
};

float offset = 0;

foreach (var line in lines)
{
    var unit = new SvgUnit(SvgUnitType.Em, offset);
    var yOffset = new SvgUnitCollection
    {
        unit
    };

    var textSpan = new SvgTextSpan
    {
        Text = line,
        Dy = yOffset,
        X = xLocation,
    };

    textBox.Children.Add(textSpan);
    offset += 1F;
}

textBox.AddStyle("fill", "black", 0);
textBox.AddStyle("font-size", "inherit", 0);

svgGroup.Children.Add(textBox);

var boundingBox = new SvgRectangle
{
    X = textBox.Bounds.X,
    Y = textBox.Bounds.Y,
    Width = textBox.Bounds.Width,
    Height = textBox.Bounds.Height
};

boundingBox.AddStyle("fill", "none", 0);
boundingBox.AddStyle("stroke", "black", 0);

svgGroup.Children.Add(boundingBox);

document.Children.Add(svgGroup);

var completePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "test.svg");

document.Write(completePath, false);

from svg.

paulushub avatar paulushub commented on August 16, 2024

@Moggel12 Thanks for the illustration. Please, is this related to #946 ?

from svg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.