Forum > LazUtils

LazFreeType font types

(1/3) > >>

MNeto:
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:
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.

MNeto:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Programa; {$mode ObjFPC}{$H+}{$codepage UTF8} uses  {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF}  Classes, Crt, SysUtils, CLocale, CWString, Unix,   fpTTF; var  CacheList : TFPFontCacheList;  CacheItem : TFPFontCacheItem; begin  try    CacheList := TFPFontCacheList.Create;    CacheList.SearchPath.Add(ExtractFilePath(ParamStr(0)) + 'fonts');    CacheList.BuildFontCache;    //CacheItem := CacheList.Find('FreeSerif'); //OK. TTF font    CacheItem := CacheList.Find('XITS'); //Problem: OTF font    WriteLn(IntToStr(CacheItem.FontData.CapHeight));   except    WriteLn('An error occurred...');    CacheList.Free;  end;   ReadKey;end. 
Thanks.

Graeme:

--- Quote from: MNeto on June 27, 2016, 04:02:03 pm ---When I try to load an otf font, the terminal generates an exception.

--- End quote ---

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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project1; {$mode ObjFPC}{$H+}{$codepage UTF8} uses  Classes, CRT, SysUtils, CLocale, CWString,  fpTTF; var  CacheList : TFPFontCacheList;  CacheItem : TFPFontCacheItem;  i: integer;begin  try    CacheList := TFPFontCacheList.Create;    CacheList.SearchPath.Add(ExtractFilePath(ParamStr(0)) + 'fonts');    CacheList.BuildFontCache;     for i := 0 to CacheList.Count-1 do      writeln(CacheList.Items[i].PostScriptName);     CacheItem := CacheList.Find('STIXGeneral');    WriteLn(IntToStr(CacheItem.FontData.CapHeight));  except    WriteLn('An error occurred...');    CacheList.Free;  end;   ReadKey;end. 
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

MNeto:
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!

Navigation

[0] Message Index

[#] Next page

Go to full version