On Thu, 2 Nov 2023, Mattias Gaertner via fpc-pascal wrote:
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.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal