freetypeh.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2003 by the Free Pascal development team
  4. Basic canvas definitions.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$mode objfpc}
  12. unit freetypeh;
  13. { Note that these are not all the availlable calls from the dll yet.
  14. This unit is used by TStringBitMaps and FTFont }
  15. interface
  16. const
  17. {$packrecords c}
  18. // Windows
  19. {$ifdef windows}
  20. freetypedll = 'freetype-6.dll'; // version 2.1.4
  21. {$define ft_found_platform}
  22. {$endif}
  23. // Mac OS X
  24. {$ifdef darwin}
  25. freetypedll = 'libfreetype'; // Doesn't seam to matter much.
  26. {$linklib freetype} // This one is the important part,
  27. // but you also need to pass to fpc
  28. // the following command:
  29. // -k-L/usr/X11/lib
  30. // or another place where it can find
  31. // libfreetype.dylib
  32. {$define ft_found_platform}
  33. {$endif}
  34. // LINUX
  35. {$if defined(UNIX) and not defined(darwin)}
  36. freetypedll = 'freetype';
  37. {$define ft_found_platform}
  38. {$endif}
  39. // Other platforms
  40. {$ifndef ft_found_platform}
  41. freetypedll = 'freetype';
  42. {$endif}
  43. type
  44. FT_Encoding = array[0..3] of char;
  45. const
  46. FT_FACE_FLAG_SCALABLE = 1 shl 0;
  47. FT_FACE_FLAG_FIXED_SIZES = 1 shl 1;
  48. FT_FACE_FLAG_FIXED_WIDTH = 1 shl 2;
  49. FT_FACE_FLAG_SFNT = 1 shl 3;
  50. FT_FACE_FLAG_HORIZONTAL = 1 shl 4;
  51. FT_FACE_FLAG_VERTICAL = 1 shl 5;
  52. FT_FACE_FLAG_KERNING = 1 shl 6;
  53. FT_FACE_FLAG_FAST_GLYPHS = 1 shl 7;
  54. FT_FACE_FLAG_MULTIPLE_MASTERS = 1 shl 8;
  55. FT_FACE_FLAG_GLYPH_NAMES = 1 shl 9;
  56. FT_FACE_FLAG_EXTERNAL_STREAM = 1 shl 10;
  57. FT_STYLE_FLAG_ITALIC = 1 shl 0;
  58. FT_STYLE_FLAG_BOLD = 1 shl 1;
  59. FT_LOAD_DEFAULT = $0000;
  60. FT_LOAD_NO_SCALE = $0001;
  61. FT_LOAD_NO_HINTING = $0002;
  62. FT_LOAD_RENDER = $0004;
  63. FT_LOAD_NO_BITMAP = $0008;
  64. FT_LOAD_VERTICAL_LAYOUT = $0010;
  65. FT_LOAD_FORCE_AUTOHINT = $0020;
  66. FT_LOAD_CROP_BITMAP = $0040;
  67. FT_LOAD_PEDANTIC = $0080;
  68. FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH = $0200;
  69. FT_LOAD_NO_RECURSE = $0400;
  70. FT_LOAD_IGNORE_TRANSFORM = $0800;
  71. FT_LOAD_MONOCHROME = $1000;
  72. FT_LOAD_LINEAR_DESIGN = $2000;
  73. ft_glyph_format_none = $00000000;
  74. ft_glyph_format_composite = $636F6D70; //comp 099 111 109 112
  75. ft_glyph_format_bitmap = $62697473; //bits 098 105 116 115
  76. ft_glyph_format_outline = $6F75746C; //outl 111 117 116 108
  77. ft_glyph_format_plotter = $706C6F74; //plot 112 108 111 116
  78. FT_ENCODING_MS_SYMBOL : FT_Encoding = 'symb';
  79. FT_ENCODING_UNICODE : FT_Encoding = 'unic';
  80. FT_ENCODING_MS_SJIS : FT_Encoding = 'sjis';
  81. FT_ENCODING_MS_GB2312 : FT_Encoding = 'gb ';
  82. FT_ENCODING_MS_BIG5 : FT_Encoding = 'big5';
  83. FT_ENCODING_MS_WANSUNG : FT_Encoding = 'wans';
  84. FT_ENCODING_MS_JOHAB : FT_Encoding = 'joha';
  85. FT_ENCODING_ADOBE_STANDARD : FT_Encoding = 'ADOB';
  86. FT_ENCODING_ADOBE_EXPERT : FT_Encoding = 'ADBE';
  87. FT_ENCODING_ADOBE_CUSTOM : FT_Encoding = 'ADBC';
  88. FT_ENCODING_ADOBE_LATIN_1 : FT_Encoding = 'lat1';
  89. FT_ENCODING_OLD_LATIN_2 : FT_Encoding = 'lat2';
  90. FT_ENCODING_APPLE_ROMAN : FT_Encoding = 'armn';
  91. ft_glyph_bbox_unscaled = 0; //* return unscaled font units */
  92. ft_glyph_bbox_subpixels = 0; //* return unfitted 26.6 coordinates */
  93. ft_glyph_bbox_gridfit = 1; //* return grid-fitted 26.6 coordinates */
  94. ft_glyph_bbox_truncate = 2; //* return coordinates in integer pixels */
  95. ft_glyph_bbox_pixels = 3; //* return grid-fitted pixel coordinates */
  96. FT_KERNING_DEFAULT = 0;
  97. FT_KERNING_UNFITTED = 1;
  98. FT_KERNING_UNSCALED = 2;
  99. type
  100. FT_Bool = boolean;
  101. FT_FWord = smallint;
  102. FT_UFWord = word;
  103. FT_Char = char;
  104. FT_Byte = byte;
  105. FT_String = char;
  106. FT_Short = smallint;
  107. FT_UShort = word;
  108. FT_Int = longint;
  109. FT_UInt = longword;
  110. {$if defined(cpu64) and not(defined(win64) and defined(cpux86_64))}
  111. FT_Long = int64;
  112. FT_ULong = qword;
  113. FT_Pos = int64;
  114. {$ELSE}
  115. FT_Long = longint;
  116. FT_ULong = longword;
  117. FT_Pos = longint;
  118. {$ENDIF}
  119. FT_F2Dot14 = smallint;
  120. FT_F26Dot6 = longint;
  121. FT_Fixed = longint;
  122. FT_Error = longint;
  123. FT_Pointer = pointer;
  124. //FT_Offset = size_t;
  125. //FT_PtrDist = size_t;
  126. FT_Render_Mode = (FT_RENDER_MODE_NORMAL, FT_RENDER_MODE_LIGHT,
  127. FT_RENDER_MODE_MONO, FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V,
  128. FT_RENDER_MODE_MAX);
  129. FT_UnitVector_ = record
  130. x : FT_F2Dot14;
  131. y : FT_F2Dot14;
  132. end;
  133. FT_UnitVector = FT_UnitVector_;
  134. FT_Matrix = record
  135. xx : FT_Fixed;
  136. xy : FT_Fixed;
  137. yx : FT_Fixed;
  138. yy : FT_Fixed;
  139. end;
  140. PFT_Matrix = ^FT_Matrix;
  141. FT_Data = record
  142. pointer : ^FT_Byte;
  143. length : FT_Int;
  144. end;
  145. FT_Generic_Finalizer = procedure (AnObject:pointer);cdecl;
  146. FT_Generic = record
  147. data : pointer;
  148. finalizer : FT_Generic_Finalizer;
  149. end;
  150. FT_Glyph_Metrics = record
  151. width : FT_Pos;
  152. height : FT_Pos;
  153. horiBearingX : FT_Pos;
  154. horiBearingY : FT_Pos;
  155. horiAdvance : FT_Pos;
  156. vertBearingX : FT_Pos;
  157. vertBearingY : FT_Pos;
  158. vertAdvance : FT_Pos;
  159. end;
  160. FT_Bitmap_Size = record
  161. height : FT_Short;
  162. width : FT_Short;
  163. end;
  164. AFT_Bitmap_Size = array [0..1023] of FT_Bitmap_Size;
  165. PFT_Bitmap_Size = ^AFT_Bitmap_Size;
  166. FT_Vector = record
  167. x : FT_Pos;
  168. y : FT_Pos;
  169. end;
  170. PFT_Vector = ^FT_Vector;
  171. FT_BBox = record
  172. xMin, yMin : FT_Pos;
  173. xMax, yMax : FT_Pos;
  174. end;
  175. PFT_BBox = ^FT_BBox;
  176. FT_Bitmap = record
  177. rows : integer;
  178. width : integer;
  179. pitch : integer;
  180. buffer : pointer;
  181. num_grays : shortint;
  182. pixel_mode : char;
  183. palette_mode : char;
  184. palette : pointer;
  185. end;
  186. FT_Outline = record
  187. n_contours,
  188. n_points : smallint;
  189. points : PFT_Vector;
  190. tags : pchar;
  191. contours : ^smallint;
  192. flags : integer;
  193. end;
  194. PFT_Outline = ^FT_Outline;
  195. FT_Outline_MoveToFunc = function(const to_: PFT_Vector; user: Pointer): integer;
  196. FT_Outline_LineToFunc = function(const to_: PFT_Vector; user: Pointer): integer;
  197. FT_Outline_ConicToFunc = function(const control, to_: PFT_Vector; user: Pointer): integer;
  198. FT_Outline_CubicToFunc = function(const control1, control2, to_: PFT_Vector; user: Pointer): integer;
  199. FT_Outline_Funcs = record
  200. move_to: FT_Outline_MoveToFunc;
  201. line_to: FT_Outline_LineToFunc;
  202. conic_to: FT_Outline_ConicToFunc;
  203. cubic_to: FT_Outline_CubicToFunc;
  204. shift: integer;
  205. delta: FT_Pos;
  206. end;
  207. PFT_Outline_Funcs = ^FT_Outline_Funcs;
  208. FT_Size_Metrics = record
  209. x_ppem : FT_UShort;
  210. y_ppem : FT_UShort;
  211. x_scale : FT_Fixed;
  212. y_scale : FT_Fixed;
  213. ascender : FT_Pos;
  214. descender : FT_Pos;
  215. height : FT_Pos;
  216. max_advance : FT_Pos;
  217. end;
  218. PFT_Library = ^TFT_Library;
  219. //PPFT_Library = ^PFT_Library;
  220. PFT_Face = ^TFT_Face;
  221. //PPFT_Face = ^PFT_Face;
  222. PFT_Charmap = ^TFT_Charmap;
  223. PPFT_Charmap = ^PFT_Charmap;
  224. PFT_GlyphSlot = ^TFT_GlyphSlot;
  225. PFT_Subglyph = ^TFT_Subglyph;
  226. PFT_Size = ^TFT_Size;
  227. PFT_Glyph = ^TFT_Glyph;
  228. //PPFT_Glyph = ^PFT_Glyph;
  229. PFT_BitmapGlyph = ^TFT_BitmapGlyph;
  230. PFT_OutlineGlyph = ^TFT_OutlineGlyph;
  231. TFT_Library = record
  232. end;
  233. TFT_Charmap = record
  234. face : PFT_Face;
  235. encoding : FT_Encoding;
  236. platform_id, encoding_id : FT_UShort;
  237. end;
  238. TFT_Size = record
  239. face : PFT_Face;
  240. generic : FT_Generic;
  241. metrics : FT_Size_Metrics;
  242. //internal : FT_Size_Internal;
  243. end;
  244. TFT_Subglyph = record // TODO
  245. end;
  246. TFT_GlyphSlot = record
  247. alibrary : PFT_Library;
  248. face : PFT_Face;
  249. next : PFT_GlyphSlot;
  250. flags : FT_UInt;
  251. generic : FT_Generic;
  252. metrics : FT_Glyph_Metrics;
  253. linearHoriAdvance : FT_Fixed;
  254. linearVertAdvance : FT_Fixed;
  255. advance : FT_Vector;
  256. format : longword;
  257. bitmap : FT_Bitmap;
  258. bitmap_left : FT_Int;
  259. bitmap_top : FT_Int;
  260. outline : FT_Outline;
  261. num_subglyphs : FT_UInt;
  262. subglyphs : PFT_SubGlyph;
  263. control_data : pointer;
  264. control_len : longint;
  265. other : pointer;
  266. end;
  267. TFT_Face = record
  268. num_faces : FT_Long;
  269. face_index : FT_Long;
  270. face_flags : FT_Long;
  271. style_flags : FT_Long;
  272. num_glyphs : FT_Long;
  273. family_name : pchar;
  274. style_name : pchar;
  275. num_fixed_sizes : FT_Int;
  276. available_sizes : PFT_Bitmap_Size; // is array
  277. num_charmaps : FT_Int;
  278. charmaps : PPFT_CharMap; // is array
  279. generic : FT_Generic;
  280. bbox : FT_BBox;
  281. units_per_EM : FT_UShort;
  282. ascender : FT_Short;
  283. descender : FT_Short;
  284. height : FT_Short;
  285. max_advance_width : FT_Short;
  286. max_advance_height : FT_Short;
  287. underline_position : FT_Short;
  288. underline_thickness : FT_Short;
  289. glyph : PFT_GlyphSlot;
  290. size : PFT_Size;
  291. charmap : PFT_CharMap;
  292. end;
  293. TFT_Glyph = record
  294. FTlibrary : PFT_Library;
  295. clazz : pointer;
  296. aFormat : longword;
  297. advance : FT_Vector;
  298. end;
  299. TFT_BitmapGlyph = record
  300. root : TFT_Glyph;
  301. left, top : FT_Int;
  302. bitmap : FT_Bitmap;
  303. end;
  304. TFT_OutlineGlyph = record
  305. root : TFT_Glyph;
  306. outline : FT_Outline;
  307. end;
  308. //Base Interface
  309. function FT_Done_Face(face: PFT_Face): integer; cdecl; external freetypedll Name 'FT_Done_Face';
  310. function FT_Done_FreeType(alibrary: PFT_Library): integer; cdecl; external freetypedll Name 'FT_Done_FreeType';
  311. function FT_Get_Char_Index(face: PFT_Face; charcode: FT_ULong): FT_UInt; cdecl; external freetypedll Name 'FT_Get_Char_Index';
  312. function FT_Get_Kerning(face: PFT_Face; left_glyph, right_glyph, kern_mode: FT_UInt; out akerning: FT_Vector): integer; cdecl; external freetypedll Name 'FT_Get_Kerning';
  313. function FT_Init_FreeType(var alibrary: PFT_Library): integer; cdecl; external freetypedll Name 'FT_Init_FreeType';
  314. function FT_IS_SCALABLE(face: PFT_Face): boolean;
  315. function FT_Load_Char(face: PFT_Face; charcode: FT_ULong; load_flags: longint): integer; cdecl; external freetypedll Name 'FT_Load_Char';
  316. function FT_Load_Glyph(face: PFT_Face; glyph_index: FT_UInt; load_flags: longint): integer; cdecl; external freetypedll Name 'FT_Load_Glyph';
  317. function FT_New_Face(alibrary: PFT_Library; filepathname: PChar; face_index: integer; var aface: PFT_Face): integer; cdecl; external freetypedll Name 'FT_New_Face';
  318. function FT_Set_Char_Size(face: PFT_Face; char_width, char_height: FT_F26dot6; horz_res, vert_res: FT_UInt): integer; cdecl; external freetypedll Name 'FT_Set_Char_Size';
  319. function FT_Set_Pixel_Sizes(face: PFT_Face; pixel_width, pixel_height: FT_UInt): integer; cdecl; external freetypedll Name 'FT_Set_Pixel_Sizes';
  320. procedure FT_Set_Transform(face: PFT_Face; matrix: PFT_Matrix; delta: PFT_Vector); cdecl; external freetypedll Name 'FT_Set_Transform';
  321. //Outline Processing
  322. function FT_Outline_Decompose(outline: PFT_Outline; const func_interface: PFT_Outline_Funcs; user: Pointer): integer; cdecl; external freetypedll Name 'FT_Outline_Decompose';
  323. //FreeType Version
  324. procedure FT_Library_Version(alibrary: PFT_Library; var amajor, aminor, apatch: integer); cdecl; external freetypedll Name 'FT_Library_Version';
  325. //Glyph Management
  326. function FT_Get_Glyph(slot: PFT_GlyphSlot; out aglyph: PFT_Glyph): integer; cdecl; external freetypedll Name 'FT_Get_Glyph';
  327. function FT_Glyph_Copy(Source: PFT_Glyph; out target: PFT_Glyph): integer; cdecl; external freetypedll Name 'FT_Glyph_Copy';
  328. function FT_Glyph_To_Bitmap(var the_glyph: PFT_Glyph; render_mode: FT_Render_Mode; origin: PFT_Vector; Destroy: FT_Bool): integer; cdecl; external freetypedll Name 'FT_Glyph_To_Bitmap';
  329. function FT_Glyph_Transform(glyph: PFT_Glyph; matrix: PFT_Matrix; delta: PFT_Vector): integer; cdecl; external freetypedll Name 'FT_Glyph_Transform';
  330. procedure FT_Done_Glyph(glyph: PFT_Glyph); cdecl; external freetypedll Name 'FT_Done_Glyph';
  331. procedure FT_Glyph_Get_CBox(glyph: PFT_Glyph; bbox_mode: FT_UInt; var acbox: FT_BBox); cdecl; external freetypedll Name 'FT_Glyph_Get_CBox';
  332. implementation
  333. function FT_IS_SCALABLE(face: PFT_Face): boolean;
  334. begin
  335. Result := (face^.face_flags and FT_FACE_FLAG_SCALABLE) = 1;
  336. end;
  337. end.