Custom Fonts Duplicated

Stimulsoft Reports.JS discussion
Post Reply
yurilima
Posts: 12
Joined: Wed Oct 11, 2023 10:11 am

Custom Fonts Duplicated

Post by yurilima »

I have noticed that fonts is being added more than one.

I attached some code pic, would be good if you have any clue or where do i need to apply them.


Thank you
Attachments
Screenshot 2024-04-29 at 13.18.03.png
Screenshot 2024-04-29 at 13.18.03.png (23.93 KiB) Viewed 279 times
Screenshot 2024-04-29 at 13.08.48.png
Screenshot 2024-04-29 at 13.08.48.png (33.14 KiB) Viewed 282 times
Screenshot 2024-04-29 at 13.06.31.png
Screenshot 2024-04-29 at 13.06.31.png (182.13 KiB) Viewed 282 times
Screenshot 2024-04-29 at 13.06.04.png
Screenshot 2024-04-29 at 13.06.04.png (123.14 KiB) Viewed 282 times
Lech Kulikowski
Posts: 6349
Joined: Tue Mar 20, 2018 5:34 am

Re: Custom Fonts Duplicated

Post by Lech Kulikowski »

Hello,

If you load fonts through resources - yes, we have such a problem, font styles are not grouped there in any way.

The option is to load fonts through StiFontCollection, where you can specify the FontStyle parameter. i.e. you can load several files with the same name but with different styles.
For example:
Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(“Arial-Bold.ttf”, “Arial”, Stimulsoft.System.Drawing.FontStyle.Bold);

Thank you.
yurilima
Posts: 12
Joined: Wed Oct 11, 2023 10:11 am

Re: Custom Fonts Duplicated

Post by yurilima »

Ok, so if i use Stimulsoft.Base.StiFontCollection.addOpentypeFontFile, do you know if that would work also to include all the fonts necessery once i try to use the PDF A3 Compliance?

I mean the font would be embedded?
Last edited by yurilima on Tue Apr 30, 2024 9:18 am, edited 1 time in total.
Lech Kulikowski
Posts: 6349
Joined: Tue Mar 20, 2018 5:34 am

Re: Custom Fonts Duplicated

Post by Lech Kulikowski »

Hello,

It should work.

Thank you.
yurilima
Posts: 12
Joined: Wed Oct 11, 2023 10:11 am

Re: Custom Fonts Duplicated

Post by yurilima »

Hi,

I have attached a small videos, but just in case i cant open, let me try to describe my case.

You have recommended to add the fonts using the Sti Collection, i have done that which works, however, in relation to the PDF A3 Complience it doesnt work. It says there is not Font Embedded, as soon as i add the fonts to the resources, the pdf A3 Compliance works as normal.

My point is, how to avoid show the duplicated fonts in the dropdown? Or if you have a better way with a step by step how to Add fonts correctly where follow the A3 Compliance also, would be great.

I have added the same document as i was validating also in case you need.

Thank you so much for your support so far.

Let me know if you need something else, or we can make a video call in case you allowed and you are free, of course.


Here is the code i am trying to add with StiCollection

Code: Select all

private async addFontsToReportWithStiFontCollection() {
        console.log("Count Resources: ", this.stiReport.dictionary.resources.count);
        // await this.addFontsToReportWithStiResource();

        let fontFolderPath = "assets/fonts/";
        let fontNames = [
            'Arial.ttf',
            'Arial-Bold.ttf',
            'Arial-Bold-Italic.ttf',
            'Roboto-Black.ttf',
            'Roboto-Black-Italic.ttf',
            'Roboto-Bold.ttf',
            'Roboto-Bold-Italic.ttf',
            'Roboto-Italic.ttf',
            'Roboto-Light.ttf',
            'Roboto-Light-Italic.ttf',
            'Roboto-Medium.ttf',
            'Roboto-Medium-Italic.ttf',
            'Roboto-Regular.ttf',
            'Roboto-Thin.ttf',
            'Roboto-Thin-Italic.ttf'
        ];

        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Arial.ttf`, `Arial`, Stimulsoft.System.Drawing.FontStyle.Regular, false);
        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Arial-Bold.ttf`, `Arial-Bold`, Stimulsoft.System.Drawing.FontStyle.Bold, false);
        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Roboto-Black.ttf`, `Roboto-Black`, Stimulsoft.System.Drawing.FontStyle.Bold, false);
        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Roboto-Black-Italic.ttf`, `Roboto-Black-Italic`, Stimulsoft.System.Drawing.FontStyle.Bold | Stimulsoft.System.Drawing.FontStyle.Italic, false);
        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Roboto-Bold.ttf`, `Roboto-Bold`, Stimulsoft.System.Drawing.FontStyle.Bold, false);
        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Roboto-Bold-Italic.ttf`, `Roboto-Bold-Italic`, Stimulsoft.System.Drawing.FontStyle.Bold | Stimulsoft.System.Drawing.FontStyle.Italic, false);
        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Roboto-Italic.ttf`, `Roboto-Italic`, Stimulsoft.System.Drawing.FontStyle.Italic, false);
        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Roboto-Light.ttf`, `Roboto-Light`, Stimulsoft.System.Drawing.FontStyle.Regular, false);
        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Roboto-Light-Italic.ttf`, `Roboto-Light-Italic`, Stimulsoft.System.Drawing.FontStyle.Regular | Stimulsoft.System.Drawing.FontStyle.Italic, false);
        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Roboto-Medium.ttf`, `Roboto-Medium`, Stimulsoft.System.Drawing.FontStyle.Regular, false);
        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Roboto-Medium-Italic.ttf`, `Roboto-Medium-Italic`, Stimulsoft.System.Drawing.FontStyle.Regular | Stimulsoft.System.Drawing.FontStyle.Italic, false);
        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Roboto-Regular.ttf`, `Roboto-Regular`, Stimulsoft.System.Drawing.FontStyle.Regular, false);
        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Roboto-Thin.ttf`, `Roboto-Thin`, Stimulsoft.System.Drawing.FontStyle.Regular, false);
        Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(`${fontFolderPath}Roboto-Thin-Italic.ttf`, `Roboto-Thin-Italic`, Stimulsoft.System.Drawing.FontStyle.Regular | Stimulsoft.System.Drawing.FontStyle.Italic, false);


        let fontAlias = `Arial.ttf`.split('.')[0];
        let fontNameWithoutdash = fontAlias.replace('-', ' ');
        let fileContent = Stimulsoft.System.IO.File.getFile(`${fontFolderPath}Arial.ttf`, true, 'application/octet-stream', [], true, false, true);
        let resource = new Stimulsoft.Report.Dictionary.StiResource(
            fontNameWithoutdash, null, false, Stimulsoft.Report.Dictionary.StiResourceType.FontTtf, fileContent, false);
        this.stiReport.dictionary.resources.add(resource);

    }

Attachments
10137-yuri.pdf
(38.79 KiB) Downloaded 40 times
Screen Recording 2024-04-30 at 11.39.16.mov
Exaplain what is happaing
(114.01 MiB) Downloaded 40 times
Lech Kulikowski
Posts: 6349
Joined: Tue Mar 20, 2018 5:34 am

Re: Custom Fonts Duplicated

Post by Lech Kulikowski »

Hello,

We require more time to investigate the issue thoroughly. Rest assured, we will keep you informed about the outcome as soon as possible.

Thank you.
yurilima
Posts: 12
Joined: Wed Oct 11, 2023 10:11 am

Re: Custom Fonts Duplicated

Post by yurilima »

Ok, again thank you man 🤝
Lech Kulikowski
Posts: 6349
Joined: Tue Mar 20, 2018 5:34 am

Re: Custom Fonts Duplicated

Post by Lech Kulikowski »

Hello,

> I have attached a small videos, but just in case i cant open, let me try to describe my case.
> You have recommended to add the fonts using the Sti Collection, i have done that which works, however, in relation to the PDF A3 Complience it doesnt work.
> It says there is not Font Embedded, as soon as i add the fonts to the resources, the pdf A3 Compliance works as normal.

Please send us a simple test project where the problem is reproduced for analysis.
You seem to be doing almost everything right, but it's very easy to miss nuances from screenshots and videos.

> My point is, how to avoid show the duplicated fonts in the dropdown? Or if you have a better way with a step by step how to Add fonts correctly where follow the A3 Compliance also, would be great.

I immediately see one problem in your code - you have misunderstood the principle.
For example, for Arial font you should specify the same Alias for all styles, but different styles:
Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(${fontFolderPath}Arial.ttf, Arial, Stimulsoft.System.Drawing.FontStyle.Regular);
Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(${fontFolderPath}Arial-Bold.ttf, Arial, Stimulsoft.System.Drawing.FontStyle.Bold);
Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(${fontFolderPath}Arial-Italic.ttf, Arial, Stimulsoft.System.Drawing.FontStyle.Italic);

Therefore, there will be no separate font styles in the list, only one font name will be displayed.

> I have added the same document as i was validating also in case you need.

Checked your file.
It has only one problem: "Width information for rendered glyphs is inconsistent".
This is a very common problem, because different graphics libraries calculate character widths differently and round them off. And according to the standard, rounding error is allowed to be about 0.1%, which is often unattainable.
Even MS-Word saves some files with this error.
We can't get rid of this problem completely automatically, but we can adjust the sizes for some fonts.
To analyze a specific report template and all the fonts used. The best way to analyze it is to have a sample project, as we wrote above.

Thank you.
Post Reply