FastReports / FastReport

Free Open Source Reporting tool for .NET6/.NET Core/.NET Framework that helps your application generate document-like reports

Home Page:https://www.fast-report.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect handling of alpha channel in HTMLExport colors

adrianlanzi opened this issue · comments

Issue Summary:

When using HTMLExport in FastReport, the alpha channel in colors is not respected. This seems to be due to the usage of ColorTranslator.ToHtml() from the System.Drawing.Color library. I found a potential solution by modifying the HTMLColorCode function in the ExportUtils class to consider the alpha channel.

Steps to Reproduce:

Use HTMLExport in FastReport.
Export a report containing colors with alpha channels.

Expected Behavior:

The exported HTML should respect the alpha channel in colors.

Actual Behavior:

The alpha channel is not taken into account, leading to incorrect color representation in the exported HTML.

Proposed Solution:

Modify (and start using) the HTMLColorCode function in the ExportUtils class to include the alpha channel.

internal static string HTMLColor(Color color)
{
    return HTMLColorCode(color);
}

internal static string HTMLColorCode(Color color)
{
    string alpha = (color.A < 255) ? (color.A / 255.0).ToString("0.00", CultureInfo.InvariantCulture) : string.Empty;
    string htmlColorCode = (string.IsNullOrEmpty(alpha))
        ? $"rgb({color.R}, {color.G}, {color.B})"
        : $"rgba({color.R}, {color.G}, {color.B}, {alpha})";

    return htmlColorCode;
}

This modification address the issue and ensure that the alpha channel is considered during HTML export. I can create a PR if you need so... Already tested in my code

Additional Information:

FastReport Version: all
Environment: Windows 11, C#, Visual Studio 2022

Thank you for your attention to this matter.

Thank you for pointing out the issue and submitting the code, we will examine it.