Re: [fpc-pascal] Creating capturers
> On Nov 2, 2023, at 1:44 PM, Sven Barth wrote: > > Now for nested as well as anonymous routines the compiler determines whether > a capturer is required at the point that the nested or anonymous routine is > assigned to a function reference (cause otherwise it can be handled as a > nested function or even a function or method pointer). This requirement is > detected during the parsing of the routine. On second thought I had some questions about this part. From what I see FPC always allocates the interface when reference pointers are used but what you write suggests maybe the compiler will demote the type to something more optimized (like a nested function). We talked about this at length before but I don't think anything was decided yet. for example: procedure DoThis; var proc: reference to procedure; begin proc := procedure begin end; proc(); end; doesn't need the heap allocated instance because the function reference never escapes the scope and it has no captured variables so it could be demoted to a global function even of nested. In fact Swift requires you to mark closures types as "@escaping" if they can escape the current scope so that the compiler can be optimize them. This is the feature I was thinking FPC needs. Can you clarify this? Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fcl-pdf custom font from memstream
On 02.11.23 16:42, 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. s/SaveDocument/TPDFDictionary.WriteDictionary/ Wouldn't it be better if TPDFDocument.Fonts and gTTFontCache share the stream? Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fcl-pdf custom font from memstream
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
Re: [fpc-pascal] fcl-pdf custom font from memstream
On 02.11.23 16:58, Michael Van Canneyt via fpc-pascal wrote: [...] 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 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fcl-pdf custom font from memstream
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? Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fcl-pdf custom font from memstream
On 02.11.23 13:38, 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 that is only one piece of the puzzle. I will add the rest. Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fcl-pdf custom font from memstream
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) Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Creating capturers
> On Nov 2, 2023, at 1:44 PM, Sven Barth wrote: > > The most important piece of knowledge is that in a routine with nested (or > anonymous) routines the nested (or anonymous) routines aren't compiled down > to machine code right away. The compiler first parses the whole hierarchy > until it's on the global/method level again and only *then* it compiles the > outermost routine followed by the nested ones. > > Now for nested as well as anonymous routines the compiler determines whether > a capturer is required at the point that the nested or anonymous routine is > assigned to a function reference (cause otherwise it can be handled as a > nested function or even a function or method pointer). This requirement is > detected during the parsing of the routine. > > If the routine requires a capturer then after the whole hierarchy has been > parsed, then all the captured variables will be moved from the local symtable > of the routine to the capturer or corresponding capture variables for > parameters will be introduced and then the whole nodetree will be walked to > adjust usages of the involved symbols. > > So, no, there is no copy involved (except for parameter values right at the > start of a routine where a parameter is captured) as the whole variables are > relocated into the capturer and they're only ever accessed from there. Ok that makes sense to move the symbols to another table before the function ends. Thanks for your detailed answer. Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fcl-pdf custom font from memstream
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; ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fcl-pdf custom font from memstream
On Thu, 2 Nov 2023, Mattias Gaertner via fpc-pascal wrote: Hi, 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. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] fcl-pdf custom font from memstream
Hi, How to load a custom font from a stream instead of from a file? Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal