Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Mon Jun 04, 2018 6:22 pm

Hello

I working with Spire.Presentation package and I would like to know how can I get font from ChartLegend using C# code?
And can I switch it to another one?

I need to get font from this chart(Legend.jpg)

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Tue Jun 05, 2018 6:47 am

Hello,

Thanks for your post.
In regards to your needs, please refer to the following article.
https://www.e-iceblue.com/Tutorials/Spire.Presentation/Spire.Presentation-Program-Guide/Chart/Set-font-for-the-text-on-Chart-legend-and-Chart-Axis-in-C.html

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Jun 05, 2018 11:43 am

Hello
Thak you for your reply!

Now can you help me to get current font?
You said how I have to set font for Chart Legend, but I need to get it.
As you see on this picture it's null by default.


Jane.Bai wrote:Hello,

Thanks for your post.
In regards to your needs, please refer to the following article.
https://www.e-iceblue.com/Tutorials/Spire.Presentation/Spire.Presentation-Program-Guide/Chart/Set-font-for-the-text-on-Chart-legend-and-Chart-Axis-in-C.html

Sincerely,
Jane
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Wed Jun 06, 2018 1:55 am

Hello,

There's a mistake with your code, please modify it like below.
Code: Select all
var font=chart.ChartLegend.TextProperties.Paragraphs[0].DefaultCharacterProperties.LatinFont;


Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed Jun 06, 2018 7:42 am

Still don't get any value:


Jane.Bai wrote:Hello,

There's a mistake with your code, please modify it like below.
Code: Select all
var font=chart.ChartLegend.TextProperties.Paragraphs[0].DefaultCharacterProperties.LatinFont;


Sincerely,
Jane
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Wed Jun 06, 2018 9:39 am

Hello,

To help us look into it, please send your sample document to us.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Thu Jun 07, 2018 7:46 am

I'm afraid that you didn't get me, I need to get default font info for ChartLegend via code for calculating correct size of strings and generate adaptive ChartLegend.

Here is my template:


Jane.Bai wrote:Hello,

To help us look into it, please send your sample document to us.

Sincerely,
Jane
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Thu Jun 07, 2018 9:43 am

Dear rokaf,

Thanks for your file.
After the initial investigation, I found that the legend didn't have any font set, you could check the screenshot. So the code Jane provided got null. I have posted your requirement to our Dev team, they will check if it could get any default font. Once there is any update, we will let you know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Jun 08, 2018 8:17 am

Okay, thank you.

Betsy.jiang wrote:Dear rokaf,

Thanks for your file.
After the initial investigation, I found that the legend didn't have any font set, you could check the screenshot. So the code Jane provided got null. I have posted your requirement to our Dev team, they will check if it could get any default font. Once there is any update, we will let you know.

Sincerely,
Betsy
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Tue Jun 12, 2018 8:58 am

Hello
I looking forward to any updates.
It's urgent task, so let me know if you will have any useful refinements.

Betsy.jiang wrote:Dear rokaf,

Thanks for your file.
After the initial investigation, I found that the legend didn't have any font set, you could check the screenshot. So the code Jane provided got null. I have posted your requirement to our Dev team, they will check if it could get any default font. Once there is any update, we will let you know.

Sincerely,
Betsy
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Tue Jun 12, 2018 9:33 am

Dear rokaf,

After further investigation, I am afraid that it is very difficult to get accurate font information at present, since the legend don't set any font, that means there is no font data for the legend in the file. Considering this case, we suggest setting corresponding font for the legend in MS PowerPoint and then use the code Jane provided to get the font information.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Jun 18, 2018 9:52 am

Hello
I've tried to set default font via MS Point.
I received needed values in code.
But still get wrong result.


Betsy.jiang wrote:Dear rokaf,

After further investigation, I am afraid that it is very difficult to get accurate font information at present, since the legend don't set any font, that means there is no font data for the legend in the file. Considering this case, we suggest setting corresponding font for the legend in MS PowerPoint and then use the code Jane provided to get the font information.

Sincerely,
Betsy
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Mon Jun 18, 2018 9:58 am

Hello,

Thank you for your post.
Please share your sample document as well as the code snippet to help us look into the issue.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Jun 19, 2018 9:55 am

Here is my code:
Code: Select all
   
var textParagraph = Chart.ChartLegend.TextProperties.Paragraphs[0];

     public static Font GetFont(TextParagraph textParagraph)
        {
            return new Font(textParagraph.DefaultCharacterProperties.LatinFont.FontName, textParagraph.DefaultCharacterProperties.FontHeight, FontUtilities.GetFontStyle(textParagraph.DefaultCharacterProperties));
        }

 public static FontStyle GetFontStyle(TextCharacterProperties properties)
        {
            var enumResult = FontStyle.Regular;

            if (properties.IsBold == TriState.True)
            {
                enumResult |= FontStyle.Bold;
            }

            if (properties.IsItalic == TriState.True)
            {
                enumResult |= FontStyle.Italic;
            }

            if (properties.TextUnderlineType != TextUnderlineType.None &&
                properties.TextUnderlineType != TextUnderlineType.UnDefined)
            {
                enumResult |= FontStyle.Underline;
            }

            if (properties.TextStrikethroughType != TextStrikethroughType.None &&
                properties.TextStrikethroughType != TextStrikethroughType.UnDefined)
            {
                enumResult |= FontStyle.Strikeout;
            }

            return enumResult;
        }


In Documents.zip you can find template presentation and result presentation.
It says that in result we've got new font (which we set in template ), but in fact we haven't. It still Calibri.

Jane.Bai wrote:Hello,

Thank you for your post.
Please share your sample document as well as the code snippet to help us look into the issue.

Sincerely,
Jane
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Tue Jun 19, 2018 11:03 am

Hello,

Sorry that I'm not clear about your intention. I found that the font of the chart legend in "test.pptx" is "Blackadder ITC" rather than Calibri. And what indeed did you do? Get the font and font style and then reset the font? I tried that yet didn't encounter any issue. Please share the entire code and point out the issue.
Below is my testing code.
Code: Select all
Presentation ppt = new Presentation();
ppt.LoadFromFile(diag.FileName);
IChart Chart = null;
foreach (Shape shp in ppt.Slides[0].Shapes)
{
    if (shp is IChart)
    {
        Chart = shp as IChart;
    }
}
var textParagraph = Chart.ChartLegend.TextProperties.Paragraphs[0];
Font font = GetFont(textParagraph);
FontStyle fStyle = GetFontStyle(textParagraph.DefaultCharacterProperties);
textParagraph.DefaultCharacterProperties.LatinFont = new TextFont("Arial Unicode MS");
ppt.SaveToFile("123.pptx", FileFormat.Pptx2010);


Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.Presentation