Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2023-11

fcl-pdf custom font from memstream

9 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alexey Torgashin
to Michael Van Canneyt
> How to load a custom font from a stream instead of from a file? Currently no way to my knowledge,

But fpparsettf.pp has this:

   TTFFileInfo = class(TObject)
   ...
   public
     // Load a TTF file from file or stream.
     Procedure LoadFromFile(const AFileName : String);
     Procedure LoadFromStream(AStream: TStream); virtual;

Reply by email

Michael Van Canneyt
to Alexey Torgashin
Alexey Torgashin wrote 13 lines
>> How to load a custom font from a stream instead of from a file? > > Currently no way to my knowledge, But fpparsettf.pp has this: TTFFileInfo = class(TObject) ... public // Load a TTF file from file or stream. Procedure LoadFromFile(const AFileName : String); Procedure LoadFromStream(AStream: TStream); virtual;

Yes, but the font cache/manager in fpttf does not support this, and all font access happens through the font cache. (at least that is how I understood Mattias' request)

Michael.

Reply by email

Mattias Gaertner
to Alexey Torgashin: But fpparsettf.pp has this: TTFFileInfo = class(TObject) ... public // Load a TTF file…
Alexey Torgashin wrote 13 lines
>> How to load a custom font from a stream instead of from a file? > > Currently no way to my knowledge, But fpparsettf.pp has this:   TTFFileInfo = class(TObject)   ...   public     // Load a TTF file from file or stream.     Procedure LoadFromFile(const AFileName : String);     Procedure LoadFromStream(AStream: TStream); virtual;

Yes, but that is only one piece of the puzzle.

I will add the rest.

Mattias

Reply by email

Mattias Gaertner
to Michael Van Canneyt: Yes, but the font cache/manager in fpttf does not support this, and all font access…
Michael Van Canneyt wrote 22 lines
On Thu, 2 Nov 2023, Alexey Torgashin via fpc-pascal wrote: > >>> How to load a custom font from a stream instead of from a file? >> >> Currently no way to my knowledge, > > But fpparsettf.pp has this: > >  TTFFileInfo = class(TObject) >  ... >  public >    // Load a TTF file from file or stream. >    Procedure LoadFromFile(const AFileName : String); >    Procedure LoadFromStream(AStream: TStream); virtual; Yes, but the font cache/manager in fpttf does not support this, and all font access happens through the font cache. (at least that is how I understood Mattias' request)

Yes. I added two functions and extended the example.

To my surprise it turns out that a ttf file is loaded up to 3 times: Once for AddFont, once for gTTFontCache and once in SaveDocument.

SaveDocument now uses the TPDFFont stream if available, so only 2 times.

Wouldn't it be better if TPDFDocument.Fonts and gTTFontCache share the stream?

Mattias

Reply by email

Mattias Gaertner
to Mattias Gaertner
Mattias Gaertner wrote 32 lines
On 02.11.23 14:00, Michael Van Canneyt via fpc-pascal wrote: > > > On Thu, 2 Nov 2023, Alexey Torgashin via fpc-pascal wrote: > >> >>>> How to load a custom font from a stream instead of from a file? >>> >>> Currently no way to my knowledge, >> >> But fpparsettf.pp has this: >> >>  TTFFileInfo = class(TObject) >>  ... >>  public >>    // Load a TTF file from file or stream. >>    Procedure LoadFromFile(const AFileName : String); >>    Procedure LoadFromStream(AStream: TStream); virtual; > > Yes, but the font cache/manager in fpttf does not support this, and > all font access happens > through the font cache. (at least that is how I understood Mattias' > request) Yes. I added two functions and extended the example. To my surprise it turns out that a ttf file is loaded up to 3 times: Once for AddFont, once for gTTFontCache and once in SaveDocument. SaveDocument now uses the TPDFFont stream if available, so only 2 times.

s/SaveDocument/TPDFDictionary.WriteDictionary/

Show quoted text 9 lines
Wouldn't it be better if TPDFDocument.Fonts and gTTFontCache share the stream? Mattias _______________________________________________ fpc-pascal maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Michael Van Canneyt
to Mattias Gaertner: Yes. I added two functions and extended the example. To my surprise it turns out that a…
Mattias Gaertner wrote 35 lines
On 02.11.23 14:00, Michael Van Canneyt via fpc-pascal wrote: > > > On Thu, 2 Nov 2023, Alexey Torgashin via fpc-pascal wrote: > >> >>>> How to load a custom font from a stream instead of from a file? >>> >>> Currently no way to my knowledge, >> >> But fpparsettf.pp has this: >> >>  TTFFileInfo = class(TObject) >>  ... >>  public >>    // Load a TTF file from file or stream. >>    Procedure LoadFromFile(const AFileName : String); >>    Procedure LoadFromStream(AStream: TStream); virtual; > > Yes, but the font cache/manager in fpttf does not support this, and all > font access happens > through the font cache. (at least that is how I understood Mattias' > request) Yes. I added two functions and extended the example. To my surprise it turns out that a ttf file is loaded up to 3 times: Once for AddFont, once for gTTFontCache and once in SaveDocument. SaveDocument now uses the TPDFFont stream if available, so only 2 times. Wouldn't it be better if TPDFDocument.Fonts and gTTFontCache share the stream?

Yes, absolutely.

But we may need a ref. counting mechanism then. Or at least we need to decide who 'owns' the streams;
At first sight it seems to me the gTTFontCache should own all font streams.

Michael.

Reply by email

Mattias Gaertner
to Michael Van Canneyt
Michael Van Canneyt wrote 6 lines
[...] Yes, absolutely. But we may need a ref. counting mechanism then. Or at least we need to decide who 'owns' the streams; At first sight it seems to me the gTTFontCache should own all font streams.

Yes.
On second thought, maybe better share the TTFFileInfo?

Mattias

Reply by email