PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu May 02, 2024 9:40 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Jun 21, 2013 7:02 pm 
Offline

Joined: Fri Jun 21, 2013 6:34 pm
Posts: 2
Hello.
I am trying to generate pdf that includes some charts. I am using the "Hello MigraDoc" example (http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx) and modifying code that adds charts to the pdf.
I am having trouble with displaying non-english strings if they are rendered in chart (chart labels or legend). Instead of cyrillic symbols I am getting question marks("?"). Any text that is not rendered in chart is rendered correctly.

I am attaching a sample code that demonstrates the described behavior:

Code:
var chart = new Chart { Left = 0, Width = Unit.FromCentimeter(16), Height = Unit.FromCentimeter(12), Type = ChartType.Pie2D};

var series = chart.SeriesCollection.AddSeries();

var pieSeries = chartData.YSeries.First();

series.Add(10, 20, 30);
series.HasDataLabel = true;

var xseries = chart.XValues.AddXSeries();
xseries.Add("Текст 10", "Текст 20", "Текст 30");
           

var legend = chart.RightArea.AddLegend();
chart.DataLabel.Type = DataLabelType.Percent;
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;


I am attaching a screenshot that demonstrates question marks in legend. The chart on the screenshot is generated using the code above.


Attachments:
Screen Shot 2013-06-21 at 10.58.28 PM.png
Screen Shot 2013-06-21 at 10.58.28 PM.png [ 41.23 KiB | Viewed 6446 times ]
Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 24, 2013 12:08 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
Hi!

It seems the charts were never tested with Unicode.

I got it going with three small (and inofficial) changes.

In class "Converter" in method "internal static XFont ToXFont(Font font, XFont defaultFont)" make this change (bold part is new):
"xfont = new XFont(fontFamily, size, fontStyle, defaultFont.PdfOptions);"

In class "ChartRendererInfo" replace properties DefaultFont and DefaultDataLabelFont with this code:
Code:
/// <summary>
/// Gets the chart's default font for rendering.
/// </summary>
internal XFont DefaultFont
{
  get
  {
    if (defaultFont == null)
        defaultFont = Converter.ToXFont(this.chart.font, new XFont("Arial", 12, XFontStyle.Regular, new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always)));

    return defaultFont;
  }
}
XFont defaultFont;

/// <summary>
/// Gets the chart's default font for rendering data labels.
/// </summary>
internal XFont DefaultDataLabelFont
{
  get
  {
    if (defaultDataLabelFont == null)
      defaultDataLabelFont = Converter.ToXFont(this.chart.font, new XFont("Arial", 10, XFontStyle.Regular, new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always)));

    return defaultDataLabelFont;
  }
}
XFont defaultDataLabelFont;

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 24, 2013 2:39 pm 
Offline

Joined: Fri Jun 21, 2013 6:34 pm
Posts: 2
Thank you, your solution works great.

I have also observed the same behaviour in PDF bookmarks. Can this fix be adapter for them or is that problem something else entirely?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 24, 2013 3:35 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
Bookmarks are a different problem - and not my area of expertise.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 82 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group