diskfont.pas 8.9 KB

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