Hi,
How to load a custom font from a stream instead of from a file?
Mattias

Mailing lists / fpc-pascal / 2023-11
9 messages · 3 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
How to load a custom font from a stream instead of from a file?
Mattias
Mattias Gaertner wroteHi, How to load a custom font from a stream instead of from a file?
Currently no way to my knowledge, but I am open for patches !
Michael.
> 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.
But fpparsettf.pp has this: TTFFileInfo = class(TObject) ... public // Load a TTF file…
Yes, but that is only one piece of the puzzle.
I will add the rest.
Mattias
Yes, but the font cache/manager in fpttf does not support this, and all font access…
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
s/SaveDocument/TPDFDictionary.WriteDictionary/
Yes. I added two functions and extended the example. To my surprise it turns out that a…
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.
Yes.
On second thought, maybe better share the TTFFileInfo?
Mattias