Recent

Author Topic: LazFreeType font types  (Read 16662 times)

MNeto

  • New Member
  • *
  • Posts: 18
LazFreeType font types
« on: June 26, 2016, 01:43:01 pm »
What are the types of fonts that can load LazFreeType? I tried to load an OpenType font and could not (I used the EasyLazFreeType).

I need to get the detailed metrics of the font characters arbitrarily chosen by the user of the software, especially the character advance position.

The LazFreeType uses FreeType 1 or FreeType 2 in the background?

Thanks in advance.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: LazFreeType font types
« Reply #1 on: June 26, 2016, 06:18:14 pm »
I can never remember, is LazFreeType the Pascal implementation of a very old FreeType?

Anyway, OTF and TTF are pretty much identical file structures. OTF simply has more structures for enhanced font features.

You can always use the fpttf.pp unit included with FPC Trunk. I've written it and tested it with TTF and OTF fonts to extract glyph metrics. The fpttf.pp unit can be used with FPC 2.6.4 too - in fact that is what I'm currently using it with.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

MNeto

  • New Member
  • *
  • Posts: 18
Re: LazFreeType font types
« Reply #2 on: June 27, 2016, 04:02:03 pm »
Hello.
Thanks for the answer.

I could only view information TTF fonts. When I try to load an otf font, the terminal generates an exception.

Here a small sample code I'm using.

Code: Pascal  [Select][+][-]
  1. program Programa;
  2.  
  3. {$mode ObjFPC}{$H+}
  4. {$codepage UTF8}
  5.  
  6. uses
  7.   {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF}
  8.   Classes, Crt, SysUtils, CLocale, CWString, Unix,
  9.  
  10.   fpTTF;
  11.  
  12. var
  13.   CacheList : TFPFontCacheList;
  14.   CacheItem : TFPFontCacheItem;
  15.  
  16. begin
  17.   try
  18.     CacheList := TFPFontCacheList.Create;
  19.     CacheList.SearchPath.Add(ExtractFilePath(ParamStr(0)) + 'fonts');
  20.     CacheList.BuildFontCache;
  21.     //CacheItem := CacheList.Find('FreeSerif'); //OK. TTF font
  22.     CacheItem := CacheList.Find('XITS'); //Problem: OTF font
  23.     WriteLn(IntToStr(CacheItem.FontData.CapHeight));
  24.  
  25.   except
  26.     WriteLn('An error occurred...');
  27.     CacheList.Free;
  28.   end;
  29.  
  30.   ReadKey;
  31. end.
  32.  

Thanks.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: LazFreeType font types
« Reply #3 on: June 27, 2016, 04:21:40 pm »
When I try to load an otf font, the terminal generates an exception.

It works here. See the code below. Does the CacheList.Find() call actually find the font you specified? Are you asking for the correct font name (postscript name)? I modified your example to first output all fonts added to the fontcache list. See highlighted lines. Then I used the correct postscript name to retrieve font glyph information.

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode ObjFPC}{$H+}
  4. {$codepage UTF8}
  5.  
  6. uses
  7.   Classes, CRT, SysUtils, CLocale, CWString,
  8.   fpTTF;
  9.  
  10. var
  11.   CacheList : TFPFontCacheList;
  12.   CacheItem : TFPFontCacheItem;
  13.   i: integer;
  14. begin
  15.   try
  16.     CacheList := TFPFontCacheList.Create;
  17.     CacheList.SearchPath.Add(ExtractFilePath(ParamStr(0)) + 'fonts');
  18.     CacheList.BuildFontCache;
  19.  
  20.     for i := 0 to CacheList.Count-1 do
  21.       writeln(CacheList.Items[i].PostScriptName);
  22.  
  23.     CacheItem := CacheList.Find('STIXGeneral');
  24.     WriteLn(IntToStr(CacheItem.FontData.CapHeight));
  25.   except
  26.     WriteLn('An error occurred...');
  27.     CacheList.Free;
  28.   end;
  29.  
  30.   ReadKey;
  31. end.
  32.  

The console output:

graemeg@wisadevel ~/devel/tests/otf_test $ ls -l fonts/*
-rw-r--r-- 1 graemeg graemeg 154180 Oct 31  2007 fonts/STIXGeneralBolIta.otf
-rw-r--r-- 1 graemeg graemeg 188836 Oct 31  2007 fonts/STIXGeneralBol.otf
-rw-r--r-- 1 graemeg graemeg 149946 Oct 31  2007 fonts/STIXGeneralItalic.otf
-rw-r--r-- 1 graemeg graemeg 273424 Oct 31  2007 fonts/STIXGeneral.otf
graemeg@wisadevel ~/devel/tests/otf_test $ ./project1
STIXGeneral
STIXGeneral-Bold
STIXGeneral-BoldItalic
STIXGeneral-Italic
662
« Last Edit: June 29, 2016, 02:21:29 pm by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

MNeto

  • New Member
  • *
  • Posts: 18
Re: LazFreeType font types
« Reply #4 on: June 27, 2016, 07:05:12 pm »
Thank you very much! It works now!

I did not know I should use the PostScript font name. I was using the names with which the font is recognized by the system.

The test I had done with FreeSerif font work because, in this case, the system name of the font matches the postscript name.

Thank you for this excellent work!

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: LazFreeType font types
« Reply #5 on: June 29, 2016, 02:29:42 pm »
I did not know I should use the PostScript font name. I was using the names with which the font is recognized by the system.
The reason we used the PostScript name in the FontCache lookup, is because the Family Name doesn't supply enough information to extract the exact TTF or OTF file you want. Note that you have one font file for each font attribute (Regular, Bold, Italic, Bold+Italic etc). So if we only used the Family Name, the FontCache would have had to return a list of TTF or OTF files. Not what we normally wanted.  That is also why the Find() method has the parameter name APostScriptName, to try and make it clearer to the developer.

For convenience, we also supplied some overloaded Find() methods. One of them takes the Family Name as an argument, but it requires two other parameters as well.

Anyway, glad it is working for you now. :)
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

MNeto

  • New Member
  • *
  • Posts: 18
Re: LazFreeType font types
« Reply #6 on: July 02, 2016, 06:57:52 pm »
Thank you!

One more question. I am having difficulty understanding the value returned by ItalicAngle property.

Code: Pascal  [Select][+][-]
  1. CacheItem: = CacheList.Find ('STIX-Italic');
  2.      WriteLn (IntToStr (CacheItem.FontData.ItalicAngle)); // Returns 4293897093

What is the interpretation of this number?
The ItalicAngle variable is of the type longword, which is an unsigned Integer. But FontForge warns that the italic angle to this font is -16.33.

The amount received by the variable is raw bytes? Some conversion is needed?

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: LazFreeType font types
« Reply #7 on: July 03, 2016, 06:52:56 pm »
One more question. I am having difficulty understanding the value returned by ItalicAngle property.

I got the info from here:
   https://www.microsoft.com/typography/otspec/post.htm

Look at than and the fpparsettf.pp unit, there is indeed a bug with ItalicAngle. We used a LongWord data type instead of a LongInt data type. I'll give this ASAP and get FPC Trunk update as soon as possible.

Quote
But FontForge warns that the italic angle to this font is -16.33.
I'm not 100% sure why FontForge is complaining. Maybe because it is using a floating point? Instead of -16. I've reviewed about 10 italic fonts and all use a LongInt range, not floating points. But then that's just 10 fonts I sampled out of hundreds of thousands of fonts out there. I'll look into ItalicAngle a bit more.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

MNeto

  • New Member
  • *
  • Posts: 18
Re: LazFreeType font types
« Reply #8 on: July 04, 2016, 03:46:52 am »
Thanks.

I already knew the site you indicated to me. On this page is informed that the italic angle is of type 'Fixed'.

In https://www.microsoft.com/typography/otspec/otff.htm page, is shown that the data type 'Single', in the "data type table" is:

Quote
Fixed --> 32-bit signed fixed-point number (16.16)

This may explain why the FontForge show that value ...

It would be interesting to replace the longword type for a single type (or Double)?
Why an integer type was used?

By the way, I'm not accustomed to thinking in fixed point ... just floating point.

What will be the type of Free Pascal data that most fits the definition of Fixed shown on the Microsoft website?
« Last Edit: July 04, 2016, 03:50:56 am by MNeto »

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: LazFreeType font types
« Reply #9 on: July 04, 2016, 10:45:32 am »
It would be interesting to replace the longword type for a single type (or Double)?
Why an integer type was used?
This has been fixed in FPC Trunk as commit r34060.

"Fixed Point" mathematics is sometime faster or more convenient than floating point mathematics. Also in was often used in the olden days (eg: The DOOM game from ID Software) where not all target CPU types  had FPU functionality (eg: Intel 386).

Wikipedia has a good explanation of Fixed Point mathematics.

Quote
What will be the type of Free Pascal data that most fits the definition of Fixed shown on the Microsoft website?
One also needs to take into account if the fixed point data type is signed or unsigned. The 'Fixed' data type used by TTF's ItalicAngle is a Signed Fixed Point 16.16, thus in Object Pascal you have to use a Int32 data type, and that is what I've done.

So the TPostScript.ItalicAngle uses a custom TF16Dot16 data type, which in turn is a Int32 (signed). So the TPostScript.ItalicAngle will return the exact fixed point value from the TTF file.

For convenience, I've also modified the TTFFileInfo.ItalicAngle() function which returns the ItalicAngle value as a Single data type. So this is probably what you would want to use.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

MNeto

  • New Member
  • *
  • Posts: 18
Re: LazFreeType font types
« Reply #10 on: July 04, 2016, 03:30:30 pm »
Quote
For convenience, I've also modified the TTFFileInfo.ItalicAngle() function which returns the ItalicAngle value as a Single data type. So this is probably what you would want to use.

Thank you!

 

TinyPortal © 2005-2018