Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Offset of the text when exporting by SvgExporter. (Read 1285 times)
Dducky
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 14
Joined: Oct 17th, 2022
Offset of the text when exporting by SvgExporter.
Jun 14th, 2023 at 5:56am
Print Post  
I already found an issue related with this. Please, let me know, do you have any progress on that?
Related topic: https://mindfusion.eu/Forum/YaBB.pl?num=1680524245

I have to duplicate it here.

Attachment 1:
The correct png, i expect that SVG will be the same after export.

Attachment 2:
Incorrect SVG, the text has been moved relative to the square.

Attachment 3: The solution.
  

attachment2.svg ( 1 KB | 39 Downloads )
SvgExportIssues_001_001.zip ( 1677 KB | 55 Downloads )
Attachment1.png ( 9 KB | 32 Downloads )
Attachment1.png
Back to top
 
IP Logged
 
Dducky
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 14
Joined: Oct 17th, 2022
Re: Offset of the text when exporting by SvgExporter.
Reply #1 - Jun 14th, 2023 at 5:57am
Print Post  
First attachment
  

Attachment1.png ( 9 KB | 32 Downloads )
Attachment1.png
Back to top
 
IP Logged
 
Dducky
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 14
Joined: Oct 17th, 2022
Re: Offset of the text when exporting by SvgExporter.
Reply #2 - Jun 14th, 2023 at 5:57am
Print Post  
Second attachment
  

attachment2.svg ( 1 KB | 39 Downloads )
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Offset of the text when exporting by SvgExporter.
Reply #3 - Jun 19th, 2023 at 11:47am
Print Post  
Try this build -
https://mindfusion.eu/_beta/wpfdiag394.zip

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Dducky
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 14
Joined: Oct 17th, 2022
Re: Offset of the text when exporting by SvgExporter.
Reply #4 - Jun 22nd, 2023 at 12:27pm
Print Post  
It isn't expected behavior with different font family.
The text always behave differently.
Watch the video and download new sample. Smiley
Video link: https://dropmefiles.com/f0v2e
  

SvgExportIssues_003.zip ( 1630 KB | 32 Downloads )
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Offset of the text when exporting by SvgExporter.
Reply #5 - Jun 29th, 2023 at 4:46pm
Print Post  
Code
Select All
var formattedText = new FormattedText("Text-*+*&$%",
    CultureInfo.InvariantCulture,
    FlowDirection.LeftToRight,
    new Typeface("Heebo"), // Heebo, roboto, arial (etc) always behave differently.
    100,
    new SolidColorBrush(Color.FromRgb(0, 0, 0)),
    VisualTreeHelper.GetDpi(this).PixelsPerDip); 



Heebo and roboto are not Windows fonts; do you actually have them installed on your system? In our test, the font family falls back to Segoe when SvgExporter gets to examine the GlyphRun generated by your TextNode. This might have different measures than the font browsers or SVG viewers fall back to when not finding actual font (or browsers might be downloading them if not installed with OS).

This build changes text alignments used, so it might depend less on font measures -
https://mindfusion.eu/_beta/wpfdiag394.zip

We find it working well enough for our advertised scenarios, and that will be all from us on the subject. If still not aligned as you expect it, only thing we can do is add some way to let you inject your own SVG <text> attributes for the custom-drawn text.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Dducky
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 14
Joined: Oct 17th, 2022
Re: Offset of the text when exporting by SvgExporter.
Reply #6 - Jul 3rd, 2023 at 8:31am
Print Post  
Yes, the font is installed. See attachment. It also can be detected by csharp code.

Pls explain why SvgExporter falls back typeface fontfamily to 'Segoe'? How we can control it? Could you provide any callback to access SvgGraphics instance during export (mb the behavior can be overriden by our code?)?

As i see you are making some transformations during drawing `GlyphRunDrawing` could this be a problem? Your related code from SvgExporter.cs:
Code
Select All
GlyphRunDrawing gdr = drawing as GlyphRunDrawing;
                    GlyphTypeface typeface = null;

                    string str = "";

                    Rect incBox = Rect.Empty;
                    Rect alignBox = Rect.Empty;
                    System.Drawing.Font textFont = null;
                    System.Drawing.Brush textBrush;
					System.Drawing.StringFormat textFormat = new System.Drawing.StringFormat();
                    System.Drawing.FontStyle fst = 0;

                    if (gdr.GlyphRun != null)
                    {
                        typeface = gdr.GlyphRun.GlyphTypeface;
						textFormat.Alignment = System.Drawing.StringAlignment.Center;
						textFormat.LineAlignment = System.Drawing.StringAlignment.Center;

                        if (typeface != null)
                        {
							if (parentClip != null)
							{
								GraphicsPath clipPath = WpfToGdi.PathMaker(parentClip, null)[0];
								svgGraphics.SetClip(clipPath);
							}

                            textBrush = WpfToGdi.BrushMaker(gdr.ForegroundBrush);

                            fst = System.Drawing.FontStyle.Regular;
                            fst |= ((typeface.StyleSimulations & StyleSimulations.BoldSimulation) != 0) ? System.Drawing.FontStyle.Bold : 0;
                            fst |= ((typeface.StyleSimulations & StyleSimulations.ItalicSimulation) != 0) ? System.Drawing.FontStyle.Italic : 0;
                            fst |= ((typeface.StyleSimulations & StyleSimulations.BoldItalicSimulation) != 0) ? System.Drawing.FontStyle.Italic | System.Drawing.FontStyle.Bold : 0;

                            fst |= (typeface.Weight.ToString().ToLower().IndexOf("bold") >= 0) ? System.Drawing.FontStyle.Bold : 0;
                            fst |= (typeface.Style.ToString().ToLower().IndexOf("italic") >= 0) ? System.Drawing.FontStyle.Italic : 0;
							string familyName = FontName(typeface);
							textFont = new System.Drawing.Font(
								familyName, (float)(gdr.GlyphRun.FontRenderingEmSize), fst);
							char[] chars = new char[gdr.GlyphRun.Characters.Count];
							gdr.GlyphRun.Characters.CopyTo(chars, 0);
							str = Encoding.Unicode.GetString(Encoding.Unicode.GetBytes(chars));

                            incBox = gdr.GlyphRun.ComputeInkBoundingBox();
                            alignBox = gdr.GlyphRun.ComputeAlignmentBox();

							textFormat = System.Drawing.StringFormat.GenericTypographic;
							textFormat.Alignment = System.Drawing.StringAlignment.Near;
							textFormat.LineAlignment = System.Drawing.StringAlignment.Near;
							textFormat.FormatFlags = System.Drawing.StringFormatFlags.NoWrap;
							textFormat.Trimming = System.Drawing.StringTrimming.None;

                            alignBox.Offset(gdr.GlyphRun.BaselineOrigin.X - gdr.GlyphRun.AdvanceWidths[0] / 2, gdr.GlyphRun.BaselineOrigin.Y);

                            using (System.Drawing.Drawing2D.Matrix newMatrix = WpfToGdi.MatrixMaker(pdfTransform))
                            {
								System.Drawing.Drawing2D.Matrix oldMatrix = svgGraphics.Transform;
								svgGraphics.Transform = newMatrix;
                                //replace unicode ellipsis character with 3 dots to avoid using of chinese fonts which are installed separately in adobe reader.
                                //TODO: make better detection of chinese, do not substitute fonts, embed fonts
                                str = str.Replace("\u2026", " ...");
								svgGraphics.DrawString(str, textFont, textBrush, WpfToGdi.PointFMaker(alignBox.Location), textFormat);
								svgGraphics.Transform = oldMatrix;
                            }

							if (parentClip != null)
								svgGraphics.ResetClip();
                        }
                    }
 


  

HeeboFont.png ( 89 KB | 31 Downloads )
HeeboFont.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Offset of the text when exporting by SvgExporter.
Reply #7 - Jul 3rd, 2023 at 9:39am
Print Post  
It's not SvgExporter falling back to Segoe, but WPF. This happens in our tests when Heebo / Roboto are not installed, but you could check on your end too with them installed (examine GlyphRun.GlyphTypeface.FamilyNames). Transformations are from diagram's measure unit to standard 72ppi point units and shouldn't lead to spacing differences between different fonts. You can find our code for last build on private messages page.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint