Recent

Author Topic: TCustomFreeTypeFontCollection Enumerator  (Read 429 times)

ϻαϻɾΣɀО

  • Jr. Member
  • **
  • Posts: 54
  • MaMrEzO
TCustomFreeTypeFontCollection Enumerator
« on: June 01, 2019, 10:02:44 pm »
Hi Guys,
For the TCustomFreeTypeFontCollection there are two enumerators:
Code: Pascal  [Select]
  1.    
  2.     function FontFileEnumerator: IFreeTypeFontEnumerator; virtual; abstract;
  3.     function FamilyEnumerator: IFreeTypeFamilyEnumerator; virtual; abstract;
  4.  

But I cannot figure out how to use them!
Can someone help me?
Debio-Sql is a new brand of GUI Database tool for the Firebird RDBMS.
http://debio-sql.ariaian.com/

ϻαϻɾΣɀО

  • Jr. Member
  • **
  • Posts: 54
  • MaMrEzO
Re: TCustomFreeTypeFontCollection Enumerator
« Reply #1 on: June 01, 2019, 10:51:04 pm »
I found something like this and it works:
Code: Pascal  [Select]
  1. function GetFontFamilies: TStringList;
  2. var
  3.   enm: IFreeTypeFamilyEnumerator;
  4. begin
  5.     Result := TStringList.Create;
  6.     enm := FontCollection.FamilyEnumerator;
  7.     while enm.MoveNext do
  8.       Result.Add(enm.Current.FamilyName);
  9. end;
  10.  
any beter suggestion?
I mean something like
Code: Pascal  [Select]
  1.  for family in FontCollection do...
Debio-Sql is a new brand of GUI Database tool for the Firebird RDBMS.
http://debio-sql.ariaian.com/

jamie

  • Hero Member
  • *****
  • Posts: 2087
Re: TCustomFreeTypeFontCollection Enumerator
« Reply #2 on: June 02, 2019, 12:27:28 am »
Yes you fingered it out  :)

You can even write your enumerators in your classes that you make, all you need is the GetEnumerator function

That allows the loop counter using "IN" to function.


http://wiki.freepascal.org/for-in_loop
« Last Edit: June 02, 2019, 12:30:02 am by jamie »
Number 1 at blue screen app creations!

devEric69

  • Full Member
  • ***
  • Posts: 149
Re: TCustomFreeTypeFontCollection Enumerator
« Reply #3 on: June 02, 2019, 09:53:12 am »
Nice insight.
And just as a reminder, for those who are "paranoid" and want to free the memory by themselves, once the interface is used (without letting the interfaces's _refcount do its job as a "garbage collector"), you must assign the interface's variable with nil to free it, like:

Code: Pascal  [Select]
  1. GetFontFamilies function: TStringList;
  2. begin
  3.         .../...
  4.         enm:= nil;  //free the intrfc expressly
  5. end;
use: Ubuntu 18.04 + Laz. 1.8.5 + FPC 3.0.5 (64 bits).