Skip to content
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

SVG AddPicture: Incorrectly renders text in SVG #681

Closed
jcoliz opened this issue May 13, 2024 · 2 comments · Fixed by #694
Closed

SVG AddPicture: Incorrectly renders text in SVG #681

jcoliz opened this issue May 13, 2024 · 2 comments · Fixed by #694

Comments

@jcoliz
Copy link
Contributor

jcoliz commented May 13, 2024

  1. Create an SVG with text
  2. Add that picture to a new presentation using ShapeCrawler
  3. Load the result into PowerPoint
  4. Notice that the beginning of the text is cut off

1x1
1x1-svg-wrong

using ShapeCrawler;

var pres = new Presentation();
var slide = pres.Slides[0];
var shapes = slide.Shapes;

var filename = "1x1.svg";
using var stream = File.OpenRead(filename);
shapes.AddPicture(stream);

pres.SaveAs($"out/{filename}.pptx");
jcoliz added a commit to jcoliz/ShapeCrawler that referenced this issue May 19, 2024
So I'll need to keep trying to find a problem image
@jcoliz
Copy link
Contributor Author

jcoliz commented May 20, 2024

One theory is that PowerPoint doesn't keep style attributes on tags within the SVG file.

Here is an example tag from the source file:

    <text
       xml:space="preserve"
       style="font-size:6.35px;font-family:'Segoe UI';-inkscape-font-specification:'Segoe UI';text-align:center;letter-spacing:0px;text-anchor:middle;fill:#ffffff;stroke:#ff0000;stroke-width:0"
       x="43.506058"
       y="40.64146"
       id="text1"><tspan
         sodipodi:role="line"
         id="tspan1"
         style="font-size:6.35px;fill:#ffffff;stroke-width:0"
         x="43.506058"
         y="40.64146">1x1</tspan></text>

When adding this to a presentation manually using the client app, the SVG is altered to this:

        <text id="text1" stroke="#FF0000" stroke-width="0" fill="#FFFFFF" font-family="Segoe UI"
            font-size="6.35" text-anchor="middle" xml:space="preserve" x="43.5061" y="40.6415">
            <tspan font-size="6.35" x="43.5061" y="40.6415">1x1</tspan>
        </text>

Thus, the relevant components of the style attribute are brought out into their own attributes.

SVG library has a FlushStyles method, which might be helpful.

In the meantime, just commit your text to paths before you add SVGs with text.

@jcoliz
Copy link
Contributor Author

jcoliz commented May 20, 2024

Ah, the problem is that there is a bug in the SVG library's Write() method. It incorrectly renders a text element thusly:

    <text x="43.50606" y="40.64146" letter-spacing="0px" id="text1" xml:space="preserve" stroke-width="0" text-anchor="middle" font-family="&quot;Segoe UI&quot;" font-size="6.35px" style="-inkscape-font-specification:&quot;Segoe UI&quot;;text-align:center;fill:white;stroke:red;">
      <tspan x="43.50606" y="40.64146" id="tspan1" stroke-width="0" font-size="6.35px" sodipodi:role="line">1x1</tspan>
    </text>

That's wrong because everything inside the tag should be rendered, INCLUDING the white space.

Solution is to not ask the Svg library to write the stream back out. Instead, use user-supplied stream.

jcoliz added a commit to jcoliz/ShapeCrawler that referenced this issue May 20, 2024
jcoliz added a commit to jcoliz/ShapeCrawler that referenced this issue May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant