Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic SVG / PDF Exporters problem while exporting templated ShapeNodes (Read 219 times)
MikeB
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 10
Joined: Apr 24th, 2024
SVG / PDF Exporters problem while exporting templated ShapeNodes
May 13th, 2024 at 11:01am
Print Post  
Hi,
When i try to export diagram that contains templated ShapeNodes
there is a problem with rendering a DataBinded properties.

Code
Select All
<Window x:Class="Diagraming.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Diagraming"
        xmlns:diagram="http://mindfusion.eu/diagramming/wpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Button Content="Export to PDF" Grid.Row="0" Click="ExportToPdf_Click"></Button>
        <diagram:DiagramView x:Name="diagram" Grid.Row="1">
            <diagram:DiagramView.Resources>
                <Style TargetType="{x:Type diagram:ShapeNode}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <DataTemplate>
                                <Label Background="Yellow" Content="{Binding Text, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}"></Label>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </diagram:DiagramView.Resources>
        </diagram:DiagramView>
    </Grid>
</Window>
 


Code (C++)
Select All
namespace Diagraming
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        [field: NonSerialized]
        public event PropertyChangedEventHandler PropertyChanged;

        public void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public Diagram diag { get; set; }

        private string text;
        public String Text
        {
            get
            {
                return text;
            }
            set
            {
                text = value;
                NotifyPropertyChanged("Text");
            }
        }
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;
            Text = "Test";

            diag = new Diagram();
            diag.Nodes.Add(new ShapeNode()
            {
                Shape = new Shape(new ElementTemplate[]
                        {
                            new LineTemplate(0, 0, 100, 0),
                            new LineTemplate(100, 0, 100, 100),
                            new LineTemplate(100, 100, 0, 100),
                        }, FillRule.EvenOdd),
            });

            diag.Nodes.Last().Move(50, 25);

            diagram.Diagram = diag;
        }


        private void ExportToPdf_Click(object sender, RoutedEventArgs e)
        {
            var exporter = new PdfExporter();

            //foreach (var diag in diagrams)
                exporter.Export(diag, @"D:\temp\diagram.pdf");
        }
    }
}
 

  

diagram_001.jpg ( 4 KB | 8 Downloads )
diagram_001.jpg
pdf.jpg ( 3 KB | 9 Downloads )
pdf.jpg
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3187
Joined: Oct 19th, 2005
Re: SVG / PDF Exporters problem while exporting templated ShapeNodes
Reply #1 - May 13th, 2024 at 12:36pm
Print Post  
Hi,

AncestorType=Window does not work because node presenters created by PdfExporter are not in the window's logical tree. We could add an option to export a DiagramView instead of a Diagram to reuse the view's logical tree, or maybe pass another UI object to set as logical parent. We'll have that in mind for next release.

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


I Love MindFusion!

Posts: 10
Joined: Apr 24th, 2024
Re: SVG / PDF Exporters problem while exporting templated ShapeNodes
Reply #2 - May 14th, 2024 at 8:07am
Print Post  
Hi,

Thanks for your reply.

I've found one more strange behaviour when using unicode characters in TextBlock used as DataTemplate. Two examples bellow.

This text causing exception when i try to make pdf export, but on diagram is rendered properly.
Code
Select All
                <Style TargetType="{x:Type diagram:ShapeNode}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <DataTemplate>
                                <TextBlock Text="&#x16C;&#x117;" Background="Yellow" FontFamily="Arial"/>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
 



Another example for different unicode characters shows difference between diagram visualization and exported pdf (extra space character and text offset).

Code
Select All
<TextBlock Text="&#x15B;&#x107;" Background="AliceBlue"  FontFamily="Arial"/>
 

  

diagram_002.jpg ( 2 KB | 9 Downloads )
diagram_002.jpg
pdf_001.jpg ( 3 KB | 9 Downloads )
pdf_001.jpg
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3187
Joined: Oct 19th, 2005
Re: SVG / PDF Exporters problem while exporting templated ShapeNodes
Reply #3 - May 14th, 2024 at 9:26am
Print Post  
Exporter's encoding detection seems to fail in that case. Try this to fix the exception:

Code
Select All
exporter.DefaultEncoding = Encoding.Unicode;
exporter.Export(...); 



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


I Love MindFusion!

Posts: 10
Joined: Apr 24th, 2024
Re: SVG / PDF Exporters problem while exporting templated ShapeNodes
Reply #4 - May 14th, 2024 at 9:51am
Print Post  
Thanks. That worked for the first example, but not for the second. Look for the attached screenshoots.
  

diagram_003.jpg ( 2 KB | 9 Downloads )
diagram_003.jpg
pdf_002.jpg ( 3 KB | 10 Downloads )
pdf_002.jpg
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3187
Joined: Oct 19th, 2005
Re: SVG / PDF Exporters problem while exporting templated ShapeNodes
Reply #5 - May 14th, 2024 at 10:13am
Print Post  
Actually you'll also need to disable AutoDetectEncoding for DefaultEncoding to be applied everywhere:

Code
Select All
exporter.AutoDetectEncoding = false;
exporter.DefaultEncoding = Encoding.Unicode;
exporter.Export(...); 



WPF appears to apply font fallback when the ttf file does not contain some glyphs, and unfortunately PdfExporter does not detect that. In this case Arial falls back to Arial Unicode MS. We'll see if we can detect that automatically for next release. At this time this seems to fix the sc string:

Code
Select All
<TextBlock Text="&#x15B;&#x107;" Background="Yellow" FontFamily="Arial Unicode MS"/> 



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


I Love MindFusion!

Posts: 10
Joined: Apr 24th, 2024
Re: SVG / PDF Exporters problem while exporting templated ShapeNodes
Reply #6 - May 14th, 2024 at 12:06pm
Print Post  
Thanks, now it works Cool
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint