utsFreeType.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. unit utsFreeType;
  2. {$IFDEF FPC}
  3. {$mode delphi}{$H+}
  4. {$ENDIF}
  5. interface
  6. uses
  7. Classes, SysUtils, syncobjs, ctypes, {$IFDEF FPC}dynlibs,{$ELSE}windows,{$ENDIF}
  8. utsUtils;
  9. type
  10. // Simple Types
  11. FT_Error = cint;
  12. FT_Library = Pointer;
  13. FT_Short = csshort;
  14. FT_Byte = cuchar;
  15. FT_Char = AnsiChar;
  16. FT_UShort = cushort;
  17. FT_Int = csint;
  18. FT_Int32 = cint32;
  19. FT_UInt = cuint;
  20. FT_Long = cslong;
  21. FT_ULong = culong;
  22. FT_Fixed = cslong;
  23. FT_Pos = cslong;
  24. FT_F26Dot6 = cslong;
  25. FT_String = AnsiChar;
  26. // Enums
  27. FT_Encoding = csint;
  28. FT_Glyph_Format = csint;
  29. // Pointer
  30. FT_Face = ^FT_FaceRec;
  31. FT_GlyphSlot = ^FT_GlyphSlotRec;
  32. FT_Size = ^FT_SizeRec;
  33. FT_CharMap = ^FT_CharMapRec;
  34. PFT_Library = ^FT_Library;
  35. PFT_Face = ^FT_Face;
  36. PFT_String = ^FT_String;
  37. PFT_SfntName = ^FT_SfntName;
  38. PFT_Bitmap = ^FT_Bitmap;
  39. PTT_OS2 = ^TT_OS2;
  40. PTT_Postscript = ^TT_Postscript;
  41. PTT_HoriHeader = ^TT_HoriHeader;
  42. // unneeded
  43. FT_Driver = Pointer;
  44. FT_Memory = Pointer;
  45. FT_Stream = Pointer;
  46. FT_ListNode = Pointer;
  47. FT_Face_Internal = Pointer;
  48. FT_SubGlyph = Pointer;
  49. FT_Slot_Internal = Pointer;
  50. FT_Size_Internal = Pointer;
  51. FT_Generic_Finalizer = procedure(aObject: Pointer);
  52. FT_Generic = record
  53. data: Pointer;
  54. finalizer: FT_Generic_Finalizer;
  55. end;
  56. FT_BBox = record
  57. xMin, yMin, xMax, yMax: FT_Pos;
  58. end;
  59. FT_Vector = record
  60. x, y: FT_Pos;
  61. end;
  62. FT_ListRec = record
  63. head: FT_ListNode;
  64. tail: FT_ListNode;
  65. end;
  66. FT_CharMapRec = record
  67. face: FT_Face;
  68. encoding: FT_Encoding;
  69. platform_id: FT_UShort;
  70. encoding_id: FT_UShort;
  71. end;
  72. FT_Size_Metrics = record
  73. x_ppem: FT_UShort;
  74. y_ppem: FT_UShort;
  75. x_scale: FT_Fixed;
  76. y_scale: FT_Fixed;
  77. ascender: FT_Pos;
  78. descender: FT_Pos;
  79. height: FT_Pos;
  80. max_advance: FT_Pos;
  81. end;
  82. FT_SizeRec = record
  83. face: FT_Face;
  84. generic_: FT_Generic;
  85. metrics: FT_Size_Metrics;
  86. internal: FT_Size_Internal;
  87. end;
  88. FT_Glyph_Metrics = record
  89. width: FT_Pos;
  90. height: FT_Pos;
  91. horiBearingX: FT_Pos;
  92. horiBearingY: FT_Pos;
  93. horiAdvance: FT_Pos;
  94. vertBearingX: FT_Pos;
  95. vertBearingY: FT_Pos;
  96. vertAdvance: FT_Pos;
  97. end;
  98. FT_Bitmap_Size = record
  99. height: FT_Short;
  100. width: FT_Short;
  101. size: FT_Pos;
  102. x_ppem: FT_Pos;
  103. y_ppem: FT_Pos;
  104. end;
  105. FT_Bitmap = record
  106. rows: Integer;
  107. width: Integer;
  108. pitch: Integer;
  109. buffer: PByte;
  110. num_grays: ShortInt;
  111. pixel_mode: Byte;
  112. palette_mode: Byte;
  113. palette: Pointer;
  114. end;
  115. FT_Outline = record
  116. n_contours: ShortInt;
  117. n_points: ShortInt;
  118. points: ^FT_Vector;
  119. tags: PByte;
  120. contours: PShortInt;
  121. flags: Integer;
  122. end;
  123. FT_GlyphSlotRec = record
  124. library_: FT_Library;
  125. face: FT_Face;
  126. next: FT_GlyphSlot;
  127. reserved: FT_UInt;
  128. generic_: FT_Generic;
  129. metrics: FT_Glyph_Metrics;
  130. linearHoriAdvance: FT_Fixed;
  131. linearVertAdvance: FT_Fixed;
  132. advance: FT_Vector;
  133. format: FT_Glyph_Format;
  134. bitmap: FT_Bitmap;
  135. bitmap_left: FT_Int;
  136. bitmap_top: FT_Int;
  137. outline: FT_Outline;
  138. num_subglyphs: FT_UInt;
  139. subglyphs: FT_SubGlyph;
  140. control_data: Pointer;
  141. control_len: LongInt;
  142. lsb_delta: FT_Pos;
  143. rsb_delta: FT_Pos;
  144. other: Pointer;
  145. internal: FT_Slot_Internal;
  146. end;
  147. FT_FaceRec = record
  148. num_faces: FT_Long;
  149. face_index: FT_Long;
  150. face_flags: FT_Long;
  151. style_flags: FT_Long;
  152. num_glyphs: FT_Long;
  153. family_name: PFT_String;
  154. style_name: PFT_String;
  155. num_fixed_sizes: FT_Int;
  156. available_sizes: ^FT_Bitmap_Size;
  157. num_charmaps: FT_Int;
  158. charmaps: ^FT_CharMap;
  159. generic_: FT_Generic;
  160. bbox: FT_BBox;
  161. units_per_EM: FT_UShort;
  162. ascender: FT_Short;
  163. descender: FT_Short;
  164. height: FT_Short;
  165. max_advance_width: FT_Short;
  166. max_advance_height: FT_Short;
  167. underline_position: FT_Short;
  168. underline_thickness: FT_Short;
  169. glyph: FT_GlyphSlot;
  170. size: FT_Size;
  171. charmap: FT_CharMap;
  172. { private }
  173. driver: FT_Driver;
  174. memory: FT_Memory;
  175. stream: FT_Stream;
  176. sizes_list: FT_ListRec;
  177. autohint: FT_Generic;
  178. extensions: Pointer;
  179. internal: FT_Face_Internal;
  180. { private end }
  181. end;
  182. FT_SfntName = record
  183. platform_id: FT_UShort;
  184. encoding_id: FT_UShort;
  185. language_id: FT_UShort;
  186. name_id: FT_UShort;
  187. string_: PByte;
  188. string_len: FT_UInt;
  189. end;
  190. TT_OS2 = record
  191. version: FT_UShort;
  192. xAvgCharWidth: FT_Short;
  193. usWeightClass: FT_UShort;
  194. usWidthClass: FT_UShort;
  195. fsType: FT_Short;
  196. ySubscriptXSize: FT_Short;
  197. ySubscriptYSize: FT_Short;
  198. ySubscriptXOffset: FT_Short;
  199. ySubscriptYOffset: FT_Short;
  200. ySuperscriptXSize: FT_Short;
  201. ySuperscriptYSize: FT_Short;
  202. ySuperscriptXOffset: FT_Short;
  203. ySuperscriptYOffset: FT_Short;
  204. yStrikeoutSize: FT_Short;
  205. yStrikeoutPosition: FT_Short;
  206. sFamilyClass: FT_Short;
  207. panose: array[0..9] of FT_Byte;
  208. ulUnicodeRange1: FT_ULong;
  209. ulUnicodeRange3: FT_ULong;
  210. ulUnicodeRange2: FT_ULong;
  211. ulUnicodeRange4: FT_ULong;
  212. achVendID: array[0..3] of FT_Char;
  213. fsSelection: FT_UShort;
  214. usFirstCharIndex: FT_UShort;
  215. usLastCharIndex: FT_UShort;
  216. sTypoAscender: FT_Short;
  217. sTypoDescender: FT_Short;
  218. sTypoLineGap: FT_Short;
  219. usWinAscent: FT_UShort;
  220. usWinDescent: FT_UShort;
  221. ulCodePageRange1: FT_ULong;
  222. ulCodePageRange2: FT_ULong;
  223. { only version 2 and higher: }
  224. sxHeight: FT_Short;
  225. sCapHeight: FT_Short;
  226. usDefaultChar: FT_UShort;
  227. usBreakChar: FT_UShort;
  228. usMaxContext: FT_UShort;
  229. { only version 5 and higher: }
  230. usLowerOpticalPointSize: FT_UShort;
  231. usUpperOpticalPointSize: FT_UShort;
  232. end;
  233. TT_Postscript = record
  234. FormatType: FT_Fixed;
  235. italicAngle: FT_Fixed;
  236. underlinePosition: FT_Short;
  237. underlineThickness: FT_Short;
  238. isFixedPitch: FT_ULong;
  239. minMemType42: FT_ULong;
  240. maxMemType42: FT_ULong;
  241. minMemType1: FT_ULong;
  242. maxMemType1: FT_ULong;
  243. end;
  244. TT_HoriHeader = record
  245. Version: FT_Fixed;
  246. Ascender: FT_Short;
  247. Descender: FT_Short;
  248. Line_Gap: FT_Short;
  249. advance_Width_Max: FT_UShort;
  250. min_Left_Side_Bearin: FT_Short;
  251. min_Right_Side_Bearing: FT_Short;
  252. xMax_Extent: FT_Short;
  253. caret_Slope_Rise: FT_Short;
  254. caret_Slope_Run: FT_Short;
  255. caret_Offset: FT_Short;
  256. Reserved: array[0..3] of FT_Short;
  257. metric_Data_Format: FT_Short;
  258. number_Of_HMetrics: FT_UShort;
  259. long_metrics: Pointer;
  260. short_metrics: Pointer;
  261. end;
  262. TFT_Init_FreeType = function(aLibrary: PFT_Library): FT_Error;
  263. TFT_Done_FreeType = function(aLibrary: FT_Library): FT_Error;
  264. TFT_New_Face = function(aLibrary: FT_Library; const aFilename: PAnsiChar; aFaceIndex: FT_Long; aFace: PFT_Face): FT_Error;
  265. TFT_New_Memory_Face = function(aLibrary: FT_Library; aData: PByte; aSize: FT_Long; aFaceIndex: FT_Long; aFace: PFT_Face): FT_Error;
  266. TFT_Done_Face = function(aFace: FT_Face): FT_Error;
  267. TFT_Get_Sfnt_Name_Count = function(aFace: FT_Face): FT_UInt;
  268. TFT_Get_Sfnt_Name = function(aFace: FT_Face; aIndex: FT_UInt; aName: PFT_SfntName): FT_Error;
  269. TFT_Set_Char_Size = function(aFace: FT_Face; aCharWidth: FT_F26Dot6; aCharHeight: FT_F26Dot6; aHorzDPI: FT_UInt; aVertDPI: FT_UInt): FT_Error;
  270. TFT_Load_Char = function(aFace: FT_Face; aCharCode: FT_ULong; aLoadFlags: FT_Int32): FT_Error;
  271. TFT_Get_Sfnt_Table = function(aFace: FT_Face; aTag: Integer): Pointer;
  272. var
  273. FT_Init_FreeType: TFT_Init_FreeType;
  274. FT_Done_FreeType: TFT_Done_FreeType;
  275. FT_New_Face: TFT_New_Face;
  276. FT_New_Memory_Face: TFT_New_Memory_Face;
  277. FT_Done_Face: TFT_Done_Face;
  278. FT_Get_Sfnt_Name_Count: TFT_Get_Sfnt_Name_Count;
  279. FT_Get_Sfnt_Name: TFT_Get_Sfnt_Name;
  280. FT_Set_Char_Size: TFT_Set_Char_Size;
  281. FT_Load_Char: TFT_Load_Char;
  282. FT_Get_Sfnt_Table: TFT_Get_Sfnt_Table;
  283. const
  284. TT_NAME_ID_COPYRIGHT = 0;
  285. TT_NAME_ID_FONT_FAMILY = 1;
  286. TT_NAME_ID_FONT_SUBFAMILY = 2;
  287. TT_NAME_ID_UNIQUE_ID = 3;
  288. TT_NAME_ID_FULL_NAME = 4;
  289. TT_NAME_ID_VERSION_STRING = 5;
  290. TT_NAME_ID_PS_NAME = 6;
  291. TT_NAME_ID_TRADEMARK = 7;
  292. TT_PLATFORM_APPLE_UNICODE = 0;
  293. TT_PLATFORM_MACINTOSH = 1;
  294. TT_PLATFORM_ISO = 2; // deprecated
  295. TT_PLATFORM_MICROSOFT = 3;
  296. TT_PLATFORM_CUSTOM = 4;
  297. TT_PLATFORM_ADOBE = 7; // artificial
  298. TT_ISO_ID_7BIT_ASCII = 0;
  299. TT_ISO_ID_10646 = 1;
  300. TT_ISO_ID_8859_1 = 2;
  301. TT_APPLE_ID_DEFAULT = 0; // Unicode 1.0
  302. TT_APPLE_ID_UNICODE_1_1 = 1; // specify Hangul at U+34xx
  303. TT_APPLE_ID_ISO_10646 = 2; // deprecated
  304. TT_APPLE_ID_UNICODE_2_0 = 3; // or later
  305. TT_APPLE_ID_UNICODE_32 = 4; // 2.0 or later, full repertoire
  306. TT_MAC_ID_ROMAN = 0;
  307. TT_MAC_ID_JAPANESE = 1;
  308. TT_MAC_ID_TRADITIONAL_CHINESE = 2;
  309. TT_MAC_ID_KOREAN = 3;
  310. TT_MAC_ID_ARABIC = 4;
  311. TT_MAC_ID_HEBREW = 5;
  312. TT_MAC_ID_GREEK = 6;
  313. TT_MAC_ID_RUSSIAN = 7;
  314. TT_MAC_ID_RSYMBOL = 8;
  315. TT_MAC_ID_DEVANAGARI = 9;
  316. TT_MAC_ID_GURMUKHI = 10;
  317. TT_MAC_ID_GUJARATI = 11;
  318. TT_MAC_ID_ORIYA = 12;
  319. TT_MAC_ID_BENGALI = 13;
  320. TT_MAC_ID_TAMIL = 14;
  321. TT_MAC_ID_TELUGU = 15;
  322. TT_MAC_ID_KANNADA = 16;
  323. TT_MAC_ID_MALAYALAM = 17;
  324. TT_MAC_ID_SINHALESE = 18;
  325. TT_MAC_ID_BURMESE = 19;
  326. TT_MAC_ID_KHMER = 20;
  327. TT_MAC_ID_THAI = 21;
  328. TT_MAC_ID_LAOTIAN = 22;
  329. TT_MAC_ID_GEORGIAN = 23;
  330. TT_MAC_ID_ARMENIAN = 24;
  331. TT_MAC_ID_MALDIVIAN = 25;
  332. TT_MAC_ID_SIMPLIFIED_CHINESE = 25;
  333. TT_MAC_ID_TIBETAN = 26;
  334. TT_MAC_ID_MONGOLIAN = 27;
  335. TT_MAC_ID_GEEZ = 28;
  336. TT_MAC_ID_SLAVIC = 29;
  337. TT_MAC_ID_VIETNAMESE = 30;
  338. TT_MAC_ID_SINDHI = 31;
  339. TT_MAC_ID_UNINTERP = 32;
  340. FT_LOAD_DEFAULT = 0;
  341. FT_LOAD_NO_SCALE = ( 1 shl 0 );
  342. FT_LOAD_NO_HINTING = ( 1 shl 1 );
  343. FT_LOAD_RENDER = ( 1 shl 2 );
  344. FT_LOAD_NO_BITMAP = ( 1 shl 3 );
  345. FT_LOAD_VERTICAL_LAYOUT = ( 1 shl 4 );
  346. FT_LOAD_FORCE_AUTOHINT = ( 1 shl 5 );
  347. FT_LOAD_CROP_BITMAP = ( 1 shl 6 );
  348. FT_LOAD_PEDANTIC = ( 1 shl 7 );
  349. FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH = ( 1 shl 9 );
  350. FT_LOAD_NO_RECURSE = ( 1 shl 10 );
  351. FT_LOAD_IGNORE_TRANSFORM = ( 1 shl 11 );
  352. FT_LOAD_MONOCHROME = ( 1 shl 12 );
  353. FT_LOAD_LINEAR_DESIGN = ( 1 shl 13 );
  354. FT_LOAD_NO_AUTOHINT = ( 1 shl 15 );
  355. FT_LOAD_COLOR = ( 1 shl 20 );
  356. FT_GLYPH_FORMAT_NONE = 0;
  357. FT_GLYPH_FORMAT_COMPOSITE = (Ord('c') shl 24) or
  358. (Ord('o') shl 16) or
  359. (Ord('m') shl 8) or
  360. (Ord('p'));
  361. FT_GLYPH_FORMAT_BITMAP = (Ord('b') shl 24) or
  362. (Ord('i') shl 16) or
  363. (Ord('t') shl 8) or
  364. (Ord('s'));
  365. FT_GLYPH_FORMAT_OUTLINE = (Ord('o') shl 24) or
  366. (Ord('u') shl 16) or
  367. (Ord('t') shl 8) or
  368. (Ord('l'));
  369. FT_GLYPH_FORMAT_PLOTTER = (Ord('p') shl 24) or
  370. (Ord('l') shl 16) or
  371. (Ord('o') shl 8) or
  372. (Ord('t'));
  373. //FT_PIXEL_MODE_NONE = 0;
  374. FT_PIXEL_MODE_MONO = 0;
  375. FT_PIXEL_MODE_GRAY = 1;
  376. FT_PIXEL_MODE_GRAY2 = 2;
  377. FT_PIXEL_MODE_GRAY4 = 3;
  378. FT_PIXEL_MODE_LCD = 4;
  379. FT_PIXEL_MODE_LCD_V = 5;
  380. FT_PIXEL_MODE_BGRA = 6;
  381. FT_ERR_Ok = $00;
  382. FT_ERR_None = $00;
  383. FT_ERR_Cannot_Open_Resource = $01;
  384. FT_ERR_Unknown_File_Format = $02;
  385. FT_ERR_Invalid_File_Format = $03;
  386. FT_ERR_Invalid_Version = $04;
  387. FT_ERR_Lower_Module_Version = $05;
  388. FT_ERR_Invalid_Argument = $06;
  389. FT_ERR_Unimplemented_Feature = $07;
  390. FT_ERR_Invalid_Table = $08;
  391. FT_ERR_Invalid_Offset = $09;
  392. FT_ERR_Array_Too_Large = $0A;
  393. { glyph/character errors }
  394. FT_ERR_Invalid_Glyph_Index = $10;
  395. FT_ERR_Invalid_Character_Code = $11;
  396. FT_ERR_Invalid_Glyph_Format = $12;
  397. FT_ERR_Cannot_Render_Glyph = $13;
  398. FT_ERR_Invalid_Outline = $14;
  399. FT_ERR_Invalid_Composite = $15;
  400. FT_ERR_Too_Many_Hints = $16;
  401. FT_ERR_Invalid_Pixel_Size = $17;
  402. { handle errors }
  403. FT_ERR_Invalid_Handle = $20;
  404. FT_ERR_Invalid_Library_Handle = $21;
  405. FT_ERR_Invalid_Driver_Handle = $22;
  406. FT_ERR_Invalid_Face_Handle = $23;
  407. FT_ERR_Invalid_Size_Handle = $24;
  408. FT_ERR_Invalid_Slot_Handle = $25;
  409. FT_ERR_Invalid_CharMap_Handle = $26;
  410. FT_ERR_Invalid_Cache_Handle = $27;
  411. FT_ERR_Invalid_Stream_Handle = $28;
  412. { driver errors }
  413. FT_ERR_Too_Many_Drivers = $30;
  414. FT_ERR_Too_Many_Extensions = $31;
  415. { memory errors }
  416. FT_ERR_Out_Of_Memory = $40;
  417. FT_ERR_Unlisted_Object = $41;
  418. { stream errors }
  419. FT_ERR_Cannot_Open_Stream = $51;
  420. FT_ERR_Invalid_Stream_Seek = $52;
  421. FT_ERR_Invalid_Stream_Skip = $53;
  422. FT_ERR_Invalid_Stream_Read = $54;
  423. FT_ERR_Invalid_Stream_Operation = $55;
  424. FT_ERR_Invalid_Frame_Operation = $56;
  425. FT_ERR_Nested_Frame_Access = $57;
  426. FT_ERR_Invalid_Frame_Read = $58;
  427. { raster errors }
  428. FT_ERR_Raster_Uninitialized = $60;
  429. FT_ERR_Raster_Corrupted = $61;
  430. FT_ERR_Raster_Overflow = $62;
  431. FT_ERR_Raster_Negative_Height = $63;
  432. { cache errors }
  433. FT_ERR_Too_Many_Caches = $70;
  434. { TrueType and SFNT errors }
  435. FT_ERR_Invalid_Opcode = $80;
  436. FT_ERR_Too_Few_Arguments = $81;
  437. FT_ERR_Stack_Overflow = $82;
  438. FT_ERR_Code_Overflow = $83;
  439. FT_ERR_Bad_Argument = $84;
  440. FT_ERR_Divide_By_Zero = $85;
  441. FT_ERR_Invalid_Reference = $86;
  442. FT_ERR_Debug_OpCode = $87;
  443. FT_ERR_ENDF_In_Exec_Stream = $88;
  444. FT_ERR_Nested_DEFS = $89;
  445. FT_ERR_Invalid_CodeRange = $8A;
  446. FT_ERR_Execution_Too_Long = $8B;
  447. FT_ERR_Too_Many_Function_Defs = $8C;
  448. FT_ERR_Too_Many_Instruction_Defs = $8D;
  449. FT_ERR_Table_Missing = $8E;
  450. FT_ERR_Horiz_Header_Missing = $8F;
  451. FT_ERR_Locations_Missing = $90;
  452. FT_ERR_Name_Table_Missing = $91;
  453. FT_ERR_CMap_Table_Missing = $92;
  454. FT_ERR_Hmtx_Table_Missing = $93;
  455. FT_ERR_Post_Table_Missing = $94;
  456. FT_ERR_Invalid_Horiz_Metrics = $95;
  457. FT_ERR_Invalid_CharMap_Format = $96;
  458. FT_ERR_Invalid_PPem = $97;
  459. FT_ERR_Invalid_Vert_Metrics = $98;
  460. FT_ERR_Could_Not_Find_Context = $99;
  461. FT_ERR_Invalid_Post_Table_Format = $9A;
  462. FT_ERR_Invalid_Post_Table = $9B;
  463. { CFF CID and Type 1 errors }
  464. FT_ERR_Syntax_Error = $A0;
  465. FT_ERR_Stack_Underflow = $A1;
  466. FT_ERR_Ignore = $A2;
  467. { BDF errors }
  468. FT_ERR_Missing_Startfont_Field = $B0;
  469. FT_ERR_Missing_Font_Field = $B1;
  470. FT_ERR_Missing_Size_Field = $B2;
  471. FT_ERR_Missing_Chars_Field = $B3;
  472. FT_ERR_Missing_Startchar_Field = $B4;
  473. FT_ERR_Missing_Encoding_Field = $B5;
  474. FT_ERR_Missing_Bbx_Field = $B6;
  475. FT_ERR_Bbx_Too_Big = $B7;
  476. FT_ERR_Corrupted_Font_Header = $B8;
  477. FT_ERR_Corrupted_Font_Glyphs = $B9;
  478. FT_STYLE_FLAG_ITALIC = (1 shl 0);
  479. FT_STYLE_FLAG_BOLD = (1 shl 1);
  480. FT_RENDER_MODE_NORMAL = 0;
  481. FT_RENDER_MODE_LIGHT = 1;
  482. FT_RENDER_MODE_MONO = 2;
  483. FT_RENDER_MODE_LCD = 3;
  484. FT_RENDER_MODE_LCD_V = 4;
  485. FT_LOAD_TARGET_NORMAL = FT_RENDER_MODE_NORMAL shl 16;
  486. FT_LOAD_TARGET_LIGHT = FT_RENDER_MODE_LIGHT shl 16;
  487. FT_LOAD_TARGET_MONO = FT_RENDER_MODE_MONO shl 16;
  488. FT_LOAD_TARGET_LCD = FT_RENDER_MODE_LCD shl 16;
  489. FT_LOAD_TARGET_LCD_V = FT_RENDER_MODE_LCD_V shl 16;
  490. FT_SFNT_HEAD = 0;
  491. FT_SFNT_MAXP = 1;
  492. FT_SFNT_OS2 = 2;
  493. FT_SFNT_HHEA = 3;
  494. FT_SFNT_VHEA = 4;
  495. FT_SFNT_POST = 5;
  496. FT_SFNT_PCLT = 6;
  497. function InitFreeType: FT_Library;
  498. procedure QuitFreeType;
  499. implementation
  500. {$IFNDEF FPC}
  501. type
  502. TLibHandle = HMODULE;
  503. function GetLastOSError: Cardinal;
  504. begin
  505. result := GetLastError;
  506. end;
  507. {$ENDIF}
  508. {$IFDEF WINDOWS}
  509. {$IFDEF WIN32}
  510. {$DEFINE TS_FT_WIN32}
  511. {$ELSE}
  512. {$DEFINE TS_FT_WIN64}
  513. {$ENDIF}
  514. {$ELSE}
  515. {$DEFINE TS_FT_LINUX}
  516. {$ENDIF}
  517. const
  518. {$IF DEFINED(TS_FT_WIN32)}
  519. LIB_FREE_TYPE = 'freetype6-x86.dll';
  520. {$ELSEIF DEFINED(TS_FT_WIN64)}
  521. LIB_FREE_TYPE = 'freetype6-x64.dll';
  522. {$ELSEIF DEFINED(TS_FT_LINUX)}
  523. LIB_FREE_TYPE = 'libfreetype.so';
  524. {$ELSE}
  525. {$ERROR 'unknown/unsupported OS'}
  526. {$IFEND}
  527. var
  528. FreeTypeInitialized: Boolean;
  529. FreeTypeRefCount: Integer;
  530. FreeTypeCritSec: TCriticalSection;
  531. FreeTypeLibHandle: TLibHandle = 0;
  532. ftLibrary: FT_Library;
  533. function InitFreeType: FT_Library;
  534. function GetProcAddr(const aName: String): Pointer;
  535. begin
  536. result := GetProcAddress(FreeTypeLibHandle, PAnsiChar(aName));
  537. if not Assigned(result) then
  538. raise EtsException.Create('unable to load procedure from library: ' + aName);
  539. end;
  540. var
  541. err: FT_Error;
  542. begin
  543. result := nil;
  544. FreeTypeCritSec.Enter;
  545. try try
  546. inc(FreeTypeRefCount, 1);
  547. if FreeTypeInitialized then
  548. exit;
  549. if (FreeTypeLibHandle = 0) then begin
  550. FreeTypeLibHandle := LoadLibrary(LIB_FREE_TYPE);
  551. if (FreeTypeLibHandle = 0) then
  552. raise EtsException.Create('unable to load free type lib: ' + LIB_FREE_TYPE + ' error=' + IntToStr(GetLastOSError));
  553. end;
  554. FT_Init_FreeType := TFT_Init_FreeType( GetProcAddr('FT_Init_FreeType'));
  555. FT_Done_FreeType := TFT_Done_FreeType( GetProcAddr('FT_Done_FreeType'));
  556. FT_New_Face := TFT_New_Face( GetProcAddr('FT_New_Face'));
  557. FT_New_Memory_Face := TFT_New_Memory_Face(GetProcAddr('FT_New_Memory_Face'));
  558. FT_Done_Face := TFT_Done_Face( GetProcAddr('FT_Done_Face'));
  559. FT_Get_Sfnt_Name_Count := TFT_Get_Sfnt_Name_Count(GetProcAddr('FT_Get_Sfnt_Name_Count'));
  560. FT_Get_Sfnt_Name := TFT_Get_Sfnt_Name( GetProcAddr('FT_Get_Sfnt_Name'));
  561. FT_Set_Char_Size := TFT_Set_Char_Size( GetProcAddr('FT_Set_Char_Size'));
  562. FT_Load_Char := TFT_Load_Char( GetProcAddr('FT_Load_Char'));
  563. FT_Get_Sfnt_Table := TFT_Get_Sfnt_Table(GetProcAddr('FT_Get_Sfnt_Table'));
  564. err := FT_Init_FreeType(@ftLibrary);
  565. if (err <> 0) then
  566. raise EtsException.Create('unable to create free type library handle: ' + IntToStr(err));
  567. FreeTypeInitialized := true;
  568. result := ftLibrary;
  569. except
  570. FreeTypeInitialized := false;
  571. raise;
  572. end;
  573. finally
  574. FreeTypeCritSec.Leave;
  575. end;
  576. end;
  577. procedure QuitFreeType;
  578. begin
  579. FreeTypeCritSec.Enter;
  580. try
  581. dec(FreeTypeRefCount, 1);
  582. if (FreeTypeRefCount > 0) or not FreeTypeInitialized then
  583. exit;
  584. FT_Done_FreeType(ftLibrary);
  585. FT_Init_FreeType := nil;
  586. FT_Done_FreeType := nil;
  587. FT_New_Face := nil;
  588. FT_New_Memory_Face := nil;
  589. FT_Done_Face := nil;
  590. FT_Get_Sfnt_Name_Count := nil;
  591. FT_Get_Sfnt_Name := nil;
  592. FT_Set_Char_Size := nil;
  593. FT_Load_Char := nil;
  594. FT_Get_Sfnt_Table := nil;
  595. if (FreeTypeLibHandle <> 0) then begin
  596. FreeLibrary(FreeTypeLibHandle);
  597. FreeTypeLibHandle := 0;
  598. end;
  599. FreeTypeInitialized := false;
  600. finally
  601. FreeTypeCritSec.Leave;
  602. end;
  603. end;
  604. initialization
  605. FreeTypeRefCount := 0;
  606. FreeTypeInitialized := false;
  607. FreeTypeCritSec := TCriticalSection.Create;
  608. finalization
  609. if FreeTypeInitialized then
  610. QuitFreeType;
  611. FreeAndNil(FreeTypeCritSec);
  612. end.