Cannot set font size for GanttChartView table

Hi, when i try to create new TextStyle it looks like font size is ignored, perhaps im doing it wrong?

Project project = new Project();

SaveOptions options = new PdfSaveOptions();

Aspose.Tasks.Task task = project.RootTask.Children.Add("Building House");
Aspose.Tasks.Task subtask1 = task.Children.Add("Laying foundation");
Aspose.Tasks.Task subtask2 = task.Children.Add("Roof works");
Aspose.Tasks.Task subtask3 = task.Children.Add("Insulation and Drywall");

task.Start = new DateTime(2024, 8, 20, 8, 0, 0, DateTimeKind.Utc);
task.Finish = new DateTime(2024, 8, 24, 17, 0, 0, DateTimeKind.Utc);

subtask1.Start = new DateTime(2024, 8, 20, 8, 0, 0, DateTimeKind.Utc);
subtask1.Finish = new DateTime(2024, 8, 20, 17, 0, 0, DateTimeKind.Utc);

subtask2.Start = new DateTime(2024, 8, 21, 8, 0, 0, DateTimeKind.Utc);
subtask2.Finish = new DateTime(2024, 8, 22, 17, 0, 0, DateTimeKind.Utc);

subtask3.Start = new DateTime(2024, 8, 23, 8, 0, 0, DateTimeKind.Utc);
subtask3.Finish = new DateTime(2024, 8, 24, 17, 0, 0, DateTimeKind.Utc);

var style = new TextStyle();
style.Color = Color.OrangeRed;
style.Font = new FontDescriptor("Calibri", 30F, FontStyles.Bold | FontStyles.Italic);
style.ItemType = TextItemType.SummaryTasks;
style.BackgroundColor = Color.Aqua;
style.BackgroundPattern = BackgroundPattern.DarkDither;

options.TextStyles = new List<TextStyle>
{
    style
};

project.Save("project_test.pdf", options);

@Herrington

It seems that you are having trouble setting the font size for the GanttChartView table in your Aspose.Tasks project. Based on the provided code, you are correctly creating a TextStyle and setting its properties, including the font size. However, it appears that the font size might not be applied as expected.

To ensure that the text styling is applied correctly, you should use the TableTextStyle class specifically designed for styling text in Gantt Chart views. Here’s an example of how to apply text styling to a Gantt Chart view:

using Aspose.Tasks;
using Aspose.Tasks.Saving;
using Aspose.Tasks.Visualization;
using System.Collections.Generic;
using System.Drawing;

class Program
{
    static void Main()
    {
        Project project = new Project();

        // Add tasks to the project
        Aspose.Tasks.Task task = project.RootTask.Children.Add("Building House");
        Aspose.Tasks.Task subtask1 = task.Children.Add("Laying foundation");
        Aspose.Tasks.Task subtask2 = task.Children.Add("Roof works");
        Aspose.Tasks.Task subtask3 = task.Children.Add("Insulation and Drywall");

        // Set task dates
        task.Start = new DateTime(2024, 8, 20);
        task.Finish = new DateTime(2024, 8, 24);
        subtask1.Start = new DateTime(2024, 8, 20);
        subtask1.Finish = new DateTime(2024, 8, 20);
        subtask2.Start = new DateTime(2024, 8, 21);
        subtask2.Finish = new DateTime(2024, 8, 22);
        subtask3.Start = new DateTime(2024, 8, 23);
        subtask3.Finish = new DateTime(2024, 8, 24);

        // Create a TableTextStyle for Gantt Chart
        TableTextStyle textStyle = new TableTextStyle
        {
            Color = Color.OrangeRed,
            Font = new FontDescriptor("Calibri", 30F, FontStyles.Bold | FontStyles.Italic),
            ItemType = TextItemType.SummaryTasks,
            BackgroundColor = Color.Aqua,
            BackgroundPattern = BackgroundPattern.DarkDither
        };

        // Set the text styles in the save options
        PdfSaveOptions options = new PdfSaveOptions
        {
            TextStyles = new List<TableTextStyle> { textStyle }
        };

        // Save the project to PDF
        project.Save("project_test.pdf", options);
    }
}

In this example, I used TableTextStyle instead of TextStyle to ensure that the font size and other properties are applied correctly to the Gantt Chart view. Make sure to adjust the ItemType according to the specific text items you want to style.

If you continue to experience issues, please check if there are any other settings or properties that might be overriding your text styles.

For more detailed information on working with views and text styling in Aspose.Tasks, you can refer to the official documentation here and here.

Sources:
[1]: Working with Views - Aspose Documentation
[2]: Project Views - Aspose Documentation

@Herrington

text style placed in PdfSaveOptions should override View`s text style, but font size is not applied. We will fix the behavior in a future release.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): TASKSNET-11270

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@Herrington ,
as a temporary workaround you can find text style for summary tasks in View.TextStyles collection and modify its properties:

Project project = new Project();

SaveOptions options = new PdfSaveOptions();

Aspose.Tasks.Task task = project.RootTask.Children.Add("Building House");
Aspose.Tasks.Task subtask1 = task.Children.Add("Laying foundation");
Aspose.Tasks.Task subtask2 = task.Children.Add("Roof works");
Aspose.Tasks.Task subtask3 = task.Children.Add("Insulation and Drywall");

task.Start = new DateTime(2024, 8, 20, 8, 0, 0, DateTimeKind.Utc);
task.Finish = new DateTime(2024, 8, 24, 17, 0, 0, DateTimeKind.Utc);

subtask1.Start = new DateTime(2024, 8, 20, 8, 0, 0, DateTimeKind.Utc);
subtask1.Finish = new DateTime(2024, 8, 20, 17, 0, 0, DateTimeKind.Utc);

subtask2.Start = new DateTime(2024, 8, 21, 8, 0, 0, DateTimeKind.Utc);
subtask2.Finish = new DateTime(2024, 8, 22, 17, 0, 0, DateTimeKind.Utc);

subtask3.Start = new DateTime(2024, 8, 23, 8, 0, 0, DateTimeKind.Utc);
subtask3.Finish = new DateTime(2024, 8, 24, 17, 0, 0, DateTimeKind.Utc);

var view = project.DefaultView as GanttChartView;

if (view == null)
{
    return;
}

options.ViewSettings = view;

var summaryStyle = view.TextStyles.First(ts => ts.ItemType == TextItemType.SummaryTasks);

summaryStyle.Color = Color.OrangeRed;
summaryStyle.Font = new FontDescriptor("Calibri", 30F, FontStyles.Bold | FontStyles.Italic);
summaryStyle.ItemType = TextItemType.SummaryTasks;
summaryStyle.BackgroundColor = Color.Aqua;
summaryStyle.BackgroundPattern = BackgroundPattern.DarkDither;
project.Save("project_test.pdf", options);

@vasiliy.sinitsyn
Thanks for the working solution!

The issues you have found earlier (filed as TASKSNET-11270) have been fixed in this update.
Download link