diskfont.pas 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. {
  2. This file is part of the Free Pascal run time library.
  3. A file in Amiga system run time library.
  4. Copyright (c) 1998-2003 by Nils Sjoholm
  5. member of the Amiga RTL development team.
  6. MorphOS version (c) 2015 by Karoly Balogh
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {$PACKRECORDS 2}
  14. unit diskfont;
  15. interface
  16. uses
  17. exec, agraphics, utility;
  18. const
  19. MAXFONTPATH = 256;
  20. type
  21. PFontContents = ^TFontContents;
  22. TFontContents = record
  23. fc_FileName: array[0..MAXFONTPATH - 1] of Char;
  24. fc_YSize: Word;
  25. fc_Style: Byte;
  26. fc_Flags: Byte;
  27. end;
  28. PTFontContents = ^TTFontContents;
  29. TTFontContents = record
  30. tfc_FileName: array[0..MAXFONTPATH - 3] of Char;
  31. tfc_TagCount: Word;
  32. tfc_YSize: Word;
  33. tfc_Style: Byte;
  34. tfc_Flags: Byte;
  35. end;
  36. const
  37. FCH_ID = $0f00;
  38. TFCH_ID = $0f02;
  39. OFCH_ID = $0f03;
  40. type
  41. PFontContentsHeader = ^TFontContentsHeader;
  42. TFontContentsHeader = record
  43. fch_FileID: Word;
  44. fch_NumEntries: Word;
  45. end;
  46. const
  47. DFH_ID = $0f80;
  48. MAXFONTNAME = 32;
  49. type
  50. PDiskFontHeader = ^TDiskFontHeader;
  51. TDiskFontHeader = record
  52. dfh_DF: TNode;
  53. dfh_FileID: Word;
  54. dfh_Revision: Word;
  55. dfh_Segment: LongInt;
  56. dfh_Name: array[0..MAXFONTNAME - 1] of Char;
  57. dfh_TF: TTextFont;
  58. end;
  59. const
  60. AFB_MEMORY = 0;
  61. AFF_MEMORY = 1 shl AFB_MEMORY;
  62. AFB_DISK = 1;
  63. AFF_DISK = 1 shl AFB_DISK;
  64. AFB_SCALED = 2;
  65. AFF_SCALED = 1 shl AFB_SCALED;
  66. AFB_BITMAP = 3;
  67. AFF_BITMAP = 1 shl AFB_BITMAP;
  68. AFB_TAGGED = 16;
  69. AFF_TAGGED = 1 shl AFB_TAGGED;
  70. type
  71. PAvailFonts = ^TAvailFonts;
  72. TAvailFonts = record
  73. af_Type: Word;
  74. af_Attr: TTextAttr;
  75. end;
  76. PTAvailFonts = ^TTAvailFonts;
  77. TTAvailFonts = record
  78. taf_Type: Word;
  79. taf_Attr: tTTextAttr;
  80. end;
  81. PAvailFontsHeader = ^TAvailFontsHeader;
  82. TAvailFontsHeader = record
  83. afh_NumEntries: Word;
  84. end;
  85. // diskfont tag defines
  86. const
  87. OT_Level0 = TAG_USER;
  88. OT_Level1 = TAG_USER or $1000;
  89. OT_Level2 = TAG_USER or $2000;
  90. OT_Level3 = TAG_USER or $3000;
  91. OT_Indirect = $8000;
  92. OT_DeviceDPI = OT_Level0 or $01;
  93. OT_DotSize = OT_Level0 or $02;
  94. OT_PointHeight = OT_Level0 or $08;
  95. OT_SetFactor = OT_Level0 or $09;
  96. OT_ShearSin = OT_Level0 or $0a;
  97. OT_ShearCos = OT_Level0 or $0b;
  98. OT_RotateSin = OT_Level0 or $0c;
  99. OT_RotateCos = OT_Level0 or $0d;
  100. OT_EmboldenX = OT_Level0 or $0e;
  101. OT_EmboldenY = OT_Level0 or $0f;
  102. OT_PointSize = OT_Level0 or $10;
  103. OT_GlyphCode = OT_Level0 or $11;
  104. OT_GlyphCode2 = OT_Level0 or $12;
  105. OT_GlyphWidth = OT_Level0 or $13;
  106. OT_OTagPath = OT_Level0 or OT_Indirect or $14;
  107. OT_OTagList = OT_Level0 or OT_Indirect or $15;
  108. OT_GlyphMap = OT_Level0 or OT_Indirect or $20;
  109. OT_WidthList = OT_Level0 or OT_Indirect or $21;
  110. OT_TextKernPair = OT_Level0 or OT_Indirect or $22;
  111. OT_DesignKernPair = OT_Level0 or OT_Indirect or $23;
  112. OT_UnderLined = OT_Level0 or $24;
  113. OT_StrikeThrough = OT_Level0 or $25;
  114. OT_GlyphMap8Bits = OT_Level0 or OT_Indirect or $50;
  115. // More sane support of real bold and italic fonts via families and/or algostyling
  116. OT_StyleFlags = OT_Level0 or $101; // Obtain with or OT_Indirect
  117. { Setting OTSF_Designed flags tells engine to try to open a styled
  118. font in the same family, failing that it will algorithmically create
  119. the right style = if you require only real designed styles, obtain the
  120. actual flags afterwards and compare against desired result;.
  121. OTSF_Algo flags tells engine to algorithmically style the font for
  122. you, this can be applied on top of OTSF_Designed to achieve whichever
  123. effect you need.}
  124. OTSF_DesignedBold = 1 shl 0;
  125. OTSF_DesignedItalic = 1 shl 1;
  126. OTSF_AlgoBold = 1 shl 16;
  127. OTSF_AlgoItalic = 1 shl 17;
  128. OTUL_None = 0;
  129. OTUL_Solid = 1;
  130. OTUL_Broken = 2;
  131. OTUL_DoubleSolid = 3;
  132. OTUL_DoubleBroken = 4;
  133. OUTL_DoubleBroken = OTUL_DoubleBroken;
  134. OTSUFFIX = '.otag';
  135. OTE_Bullet = 'bullet';
  136. OT_FileIdent = OT_Level1 or $01;
  137. OT_Engine = OT_Level1 or OT_Indirect or $02;
  138. OT_Family = OT_Level1 or OT_Indirect or $03;
  139. OT_BName = OT_Level2 or OT_Indirect or $05;
  140. OT_IName = OT_Level2 or OT_Indirect or $06;
  141. OT_BIName = OT_Level2 or OT_Indirect or $07;
  142. OT_RName = OT_Level2 or OT_Indirect or $09;
  143. OT_SymbolSet = OT_Level1 or $10;
  144. OT_YSizeFactor = OT_Level1 or $11;
  145. OT_SpaceWidth = OT_Level2 or $12;
  146. OT_IsFixed = OT_Level2 or $13;
  147. OT_SerifFlag = OT_Level1 or $14;
  148. OT_StemWeight = OT_Level1 or $15;
  149. OT_SlantStyle = OT_Level1 or $16;
  150. OT_HorizStyle = OT_Level1 or $17;
  151. OT_SpaceFactor = OT_Level2 or $18;
  152. OT_InhibitAlgoStyle = OT_Level2 or $19;
  153. OT_AvailSizes = OT_Level1 or OT_Indirect or $20;
  154. OT_MAXAVAILSIZES = 20;
  155. OTS_Upright = 0;
  156. OTS_Italic = 1;
  157. OTS_LeftItalic = 2;
  158. OTS_UltraThin = 8;
  159. OTS_ExtraThin = 24;
  160. OTS_Thin = 40;
  161. OTS_ExtraLight = 56;
  162. OTS_Light = 72;
  163. OTS_DemiLight = 88;
  164. OTS_SemiLight = 104;
  165. OTS_Book = 120;
  166. OTS_Medium = 136;
  167. OTS_SemiBold = 152;
  168. OTS_DemiBold = 168;
  169. OTS_Bold = 184;
  170. OTS_ExtraBold = 200;
  171. OTS_Black = 216;
  172. OTS_ExtraBlack = 232;
  173. OTS_UltraBlack = 248;
  174. OTH_UltraCompressed = 16;
  175. OTH_ExtraCompressed = 48;
  176. OTH_Compressed = 80;
  177. OTH_Condensed = 112;
  178. OTH_Normal = 144;
  179. OTH_SemiExpanded = 176;
  180. OTH_Expanded = 208;
  181. OTH_ExtraExpanded = 240;
  182. OT_SpecCount = OT_Level1 or $100;
  183. OT_Spec = OT_Level1 or $100;
  184. OT_Spec1 = OT_Level1 or $101;
  185. DFCTRL_BASE = TAG_USER + $0B000000;
  186. DFCTRL_XDPI = DFCTRL_BASE + 1;
  187. DFCTRL_YDPI = DFCTRL_BASE + 2;
  188. DFCTRL_XDOTP = DFCTRL_BASE + 3;
  189. DFCTRL_YDOTP = DFCTRL_BASE + 4;
  190. DFCTRL_CACHE = DFCTRL_BASE + 5;
  191. DFCTRL_SORTMODE = DFCTRL_BASE + 6;
  192. DFCTRL_SORT_OFF = 0;
  193. DFCTRL_SORT_ASC = 1;
  194. DFCTRL_SORT_DES = -1;
  195. // diskfont glyph defines
  196. type
  197. PGlyphEngine = ^TGlyphEngine;
  198. TGlyphEngine = record
  199. gle_Library: PLibrary;
  200. gle_Name: PChar;
  201. end;
  202. FIXED = LongInt;
  203. PGlyphMap = ^TGlyphMap;
  204. TGlyphMap = record
  205. glm_BMModulo: Word;
  206. glm_BMRows: Word;
  207. glm_BlackLeft: Word;
  208. glm_BlackTop: Word;
  209. glm_BlackWidth: Word;
  210. glm_BlackHeight: Word;
  211. glm_XOrigin: FIXED;
  212. glm_YOrigin: FIXED;
  213. glm_X0: SmallInt;
  214. glm_Y0: SmallInt;
  215. glm_X1: SmallInt;
  216. glm_Y1: SmallInt;
  217. glm_Width: FIXED;
  218. glm_BitMap: PByte;
  219. end;
  220. PGlyphWidthEntry = ^TGlyphWidthEntry;
  221. TGlyphWidthEntry = record
  222. gwe_Node: TMinNode;
  223. gwe_Code: Word;
  224. gwe_Width: FIXED;
  225. end;
  226. // outline errors
  227. const
  228. OTERR_Failure = -1;
  229. OTERR_Success = 0;
  230. OTERR_BadTag = 1;
  231. OTERR_UnknownTag = 2;
  232. OTERR_BadData = 3;
  233. OTERR_NoMemory = 4;
  234. OTERR_NoFace = 5;
  235. OTERR_BadFace = 6;
  236. OTERR_NoGlyph = 7;
  237. OTERR_BadGlyph = 8;
  238. OTERR_NoShear = 9;
  239. OTERR_NoRotate = 10;
  240. OTERR_TooSmall = 11;
  241. OTERR_UnknownGlyph = 12;
  242. const
  243. DISKFONTNAME : PChar = 'diskfont.library';
  244. var DiskfontBase : pLibrary = nil;
  245. function OpenDiskFont(TextAttr: PTextAttr location 'a0'): PTextFont; syscall DiskfontBase 030;
  246. function AvailFonts(Buffer: STRPTR location 'a0'; BufBytes: LongInt location 'd0'; Flags: LongInt location 'd1'): LongInt; syscall DiskfontBase 036;
  247. function NewFontContents(FontsLock: BPTR location 'a0'; FontName: STRPTR location 'a1'): PFontContentsHeader; syscall DiskfontBase 042;
  248. procedure DisposeFontContents(FontContentsHeader: PFontContentsHeader location 'a1'); syscall DiskfontBase 048;
  249. function NewScaledDiskFont(SourceFont: PTextFont location 'a0'; DestTextAttr: PTextAttr location 'a1'): PDiskFontHeader; syscall DiskfontBase 054;
  250. // MorphOS actually supports these V45+ calls
  251. function GetDiskFontCtrl(TagID: LongInt location 'd0'): LongInt; syscall DiskfontBase 060;
  252. procedure SetDiskFontCtrlA(TagList: PTagItem location 'a0'); syscall DiskfontBase 066;
  253. // vartags Version
  254. procedure SetDiskFontCtrl(const Tags: array of PtrUInt); inline;
  255. function InitDiskFontLibrary: boolean; inline;
  256. implementation
  257. procedure SetDiskFontCtrl(const Tags: array of PtrUInt);
  258. begin
  259. SetDiskFontCtrlA(@Tags);
  260. end;
  261. const
  262. LIBVERSION: LongWord = 0;
  263. function InitDiskFontLibrary: boolean; inline;
  264. begin
  265. InitDiskFontLibrary := Assigned(DiskFontBase);
  266. end;
  267. initialization
  268. DiskFontBase := OpenLibrary(DISKFONTNAME, LIBVERSION);
  269. finalization
  270. if Assigned(DiskFontBase) then
  271. CloseLibrary(DiskFontBase);
  272. END.