PDFsharp & MigraDoc Forum https://forum.pdfsharp.net/ |
|
[MigraDoc-GDI.1.32.4334.0] Unicode characters in charts https://forum.pdfsharp.net/viewtopic.php?f=2&t=2488 |
Page 1 of 1 |
Author: | Shurf [ Fri Jun 21, 2013 7:02 pm ] | ||
Post subject: | [MigraDoc-GDI.1.32.4334.0] Unicode characters in charts | ||
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.
|
Author: | Thomas Hoevel [ Mon Jun 24, 2013 12:08 pm ] |
Post subject: | Re: [MigraDoc-GDI.1.32.4334.0] Unicode characters in charts |
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; |
Author: | Shurf [ Mon Jun 24, 2013 2:39 pm ] |
Post subject: | Re: [MigraDoc-GDI.1.32.4334.0] Unicode characters in charts |
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? |
Author: | Thomas Hoevel [ Mon Jun 24, 2013 3:35 pm ] |
Post subject: | Re: [MigraDoc-GDI.1.32.4334.0] Unicode characters in charts |
Bookmarks are a different problem - and not my area of expertise. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |