diskfont.pas 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. History:
  14. Added the defines use_amiga_smartlink and
  15. use_auto_openlib. Implemented autoopening
  16. of the library.
  17. 13 Jan 2003.
  18. Update for AmigaOS 3.9.
  19. FUNCTION GetDiskFontCtrl
  20. PROCEDURE SetDiskFontCtrlA
  21. Varargs for SetDiskFontCtrl is in
  22. systemvartags.
  23. Changed startup for library.
  24. 01 Feb 2003.
  25. Changed cardinal > longword.
  26. 09 Feb 2003.
  27. [email protected] Nils Sjoholm
  28. }
  29. {$I useamigasmartlink.inc}
  30. {$ifdef use_amiga_smartlink}
  31. {$smartlink on}
  32. {$endif use_amiga_smartlink}
  33. unit diskfont;
  34. INTERFACE
  35. uses exec, graphics,utility;
  36. Const
  37. MAXFONTPATH = 256;
  38. Type
  39. pFontContents = ^tFontContents;
  40. tFontContents = record
  41. fc_FileName : Array [0..MAXFONTPATH-1] of Char;
  42. fc_YSize : Word;
  43. fc_Style : Byte;
  44. fc_Flags : Byte;
  45. end;
  46. pTFontContents = ^tTFontContents;
  47. tTFontContents = record
  48. tfc_FileName : Array[0..MAXFONTPATH-3] of Char;
  49. tfc_TagCount : Word;
  50. tfc_YSize : Word;
  51. tfc_Style,
  52. tfc_Flags : Byte;
  53. END;
  54. Const
  55. FCH_ID = $0f00;
  56. TFCH_ID = $0f02;
  57. OFCH_ID = $0f03;
  58. Type
  59. pFontContentsHeader = ^tFontContentsHeader;
  60. tFontContentsHeader = record
  61. fch_FileID : Word;
  62. fch_NumEntries : Word;
  63. end;
  64. Const
  65. DFH_ID = $0f80;
  66. MAXFONTNAME = 32;
  67. Type
  68. pDiskFontHeader = ^tDiskFontHeader;
  69. tDiskFontHeader = record
  70. dfh_DF : tNode;
  71. dfh_FileID : Word;
  72. dfh_Revision : Word;
  73. dfh_Segment : Longint;
  74. dfh_Name : Array [0..MAXFONTNAME-1] of Char;
  75. dfh_TF : tTextFont;
  76. end;
  77. Const
  78. AFB_MEMORY = 0;
  79. AFF_MEMORY = 1;
  80. AFB_DISK = 1;
  81. AFF_DISK = 2;
  82. AFB_SCALED = 2;
  83. AFF_SCALED = $0004;
  84. AFB_BITMAP = 3;
  85. AFF_BITMAP = $0008;
  86. AFB_TAGGED = 16;
  87. AFF_TAGGED = $10000;
  88. Type
  89. pAvailFonts = ^tAvailFonts;
  90. tAvailFonts = record
  91. af_Type : Word;
  92. af_Attr : tTextAttr;
  93. end;
  94. pTAvailFonts = ^tTAvailFonts;
  95. tTAvailFonts = record
  96. taf_Type : Word;
  97. taf_Attr : tTTextAttr;
  98. END;
  99. pAvailFontsHeader = ^tAvailFontsHeader;
  100. tAvailFontsHeader = record
  101. afh_NumEntries : Word;
  102. end;
  103. const
  104. DISKFONTNAME : PChar = 'diskfont.library';
  105. VAR DiskfontBase : pLibrary;
  106. FUNCTION AvailFonts(buffer : pCHAR; bufBytes : LONGINT; flags : LONGINT) : LONGINT;
  107. PROCEDURE DisposeFontContents(fontContentsHeader : pFontContentsHeader);
  108. FUNCTION NewFontContents(fontsLock : BPTR; fontName : pCHAR) : pFontContentsHeader;
  109. FUNCTION NewScaledDiskFont(sourceFont : pTextFont; destTextAttr : pTextAttr) : pDiskFontHeader;
  110. FUNCTION OpenDiskFont(textAttr : pTextAttr) : pTextFont;
  111. FUNCTION GetDiskFontCtrl(tagid : LONGINT) : LONGINT;
  112. PROCEDURE SetDiskFontCtrlA(taglist : pTagItem);
  113. {Here we read how to compile this unit}
  114. {You can remove this include and use a define instead}
  115. {$I useautoopenlib.inc}
  116. {$ifdef use_init_openlib}
  117. procedure InitDISKFONTLibrary;
  118. {$endif use_init_openlib}
  119. {This is a variable that knows how the unit is compiled}
  120. var
  121. DISKFONTIsCompiledHow : longint;
  122. IMPLEMENTATION
  123. {
  124. If you don't use array of const then just remove tagsarray
  125. }
  126. uses
  127. {$ifndef dont_use_openlib}
  128. msgbox;
  129. {$endif dont_use_openlib}
  130. FUNCTION AvailFonts(buffer : pCHAR; bufBytes : LONGINT; flags : LONGINT) : LONGINT;
  131. BEGIN
  132. ASM
  133. MOVE.L A6,-(A7)
  134. MOVEA.L buffer,A0
  135. MOVE.L bufBytes,D0
  136. MOVE.L flags,D1
  137. MOVEA.L DiskfontBase,A6
  138. JSR -036(A6)
  139. MOVEA.L (A7)+,A6
  140. MOVE.L D0,@RESULT
  141. END;
  142. END;
  143. PROCEDURE DisposeFontContents(fontContentsHeader : pFontContentsHeader);
  144. BEGIN
  145. ASM
  146. MOVE.L A6,-(A7)
  147. MOVEA.L fontContentsHeader,A1
  148. MOVEA.L DiskfontBase,A6
  149. JSR -048(A6)
  150. MOVEA.L (A7)+,A6
  151. END;
  152. END;
  153. FUNCTION NewFontContents(fontsLock : BPTR; fontName : pCHAR) : pFontContentsHeader;
  154. BEGIN
  155. ASM
  156. MOVE.L A6,-(A7)
  157. MOVEA.L fontsLock,A0
  158. MOVEA.L fontName,A1
  159. MOVEA.L DiskfontBase,A6
  160. JSR -042(A6)
  161. MOVEA.L (A7)+,A6
  162. MOVE.L D0,@RESULT
  163. END;
  164. END;
  165. FUNCTION NewScaledDiskFont(sourceFont : pTextFont; destTextAttr : pTextAttr) : pDiskFontHeader;
  166. BEGIN
  167. ASM
  168. MOVE.L A6,-(A7)
  169. MOVEA.L sourceFont,A0
  170. MOVEA.L destTextAttr,A1
  171. MOVEA.L DiskfontBase,A6
  172. JSR -054(A6)
  173. MOVEA.L (A7)+,A6
  174. MOVE.L D0,@RESULT
  175. END;
  176. END;
  177. FUNCTION OpenDiskFont(textAttr : pTextAttr) : pTextFont;
  178. BEGIN
  179. ASM
  180. MOVE.L A6,-(A7)
  181. MOVEA.L textAttr,A0
  182. MOVEA.L DiskfontBase,A6
  183. JSR -030(A6)
  184. MOVEA.L (A7)+,A6
  185. MOVE.L D0,@RESULT
  186. END;
  187. END;
  188. FUNCTION GetDiskFontCtrl(tagid : LONGINT) : LONGINT;
  189. BEGIN
  190. ASM
  191. MOVE.L A6,-(A7)
  192. MOVE.L tagid,D0
  193. MOVEA.L DiskfontBase,A6
  194. JSR -060(A6)
  195. MOVEA.L (A7)+,A6
  196. MOVE.L D0,@RESULT
  197. END;
  198. END;
  199. PROCEDURE SetDiskFontCtrlA(taglist : pTagItem);
  200. BEGIN
  201. ASM
  202. MOVE.L A6,-(A7)
  203. MOVEA.L taglist,A0
  204. MOVEA.L DiskfontBase,A6
  205. JSR -066(A6)
  206. MOVEA.L (A7)+,A6
  207. END;
  208. END;
  209. const
  210. { Change VERSION and LIBVERSION to proper values }
  211. VERSION : string[2] = '0';
  212. LIBVERSION : longword = 0;
  213. {$ifdef use_init_openlib}
  214. {$Info Compiling initopening of diskfont.library}
  215. {$Info don't forget to use InitDISKFONTLibrary in the beginning of your program}
  216. var
  217. diskfont_exit : Pointer;
  218. procedure ClosediskfontLibrary;
  219. begin
  220. ExitProc := diskfont_exit;
  221. if DiskfontBase <> nil then begin
  222. CloseLibrary(DiskfontBase);
  223. DiskfontBase := nil;
  224. end;
  225. end;
  226. procedure InitDISKFONTLibrary;
  227. begin
  228. DiskfontBase := nil;
  229. DiskfontBase := OpenLibrary(DISKFONTNAME,LIBVERSION);
  230. if DiskfontBase <> nil then begin
  231. diskfont_exit := ExitProc;
  232. ExitProc := @ClosediskfontLibrary;
  233. end else begin
  234. MessageBox('FPC Pascal Error',
  235. 'Can''t open diskfont.library version ' + VERSION + #10 +
  236. 'Deallocating resources and closing down',
  237. 'Oops');
  238. halt(20);
  239. end;
  240. end;
  241. begin
  242. DISKFONTIsCompiledHow := 2;
  243. {$endif use_init_openlib}
  244. {$ifdef use_auto_openlib}
  245. {$Info Compiling autoopening of diskfont.library}
  246. var
  247. diskfont_exit : Pointer;
  248. procedure ClosediskfontLibrary;
  249. begin
  250. ExitProc := diskfont_exit;
  251. if DiskfontBase <> nil then begin
  252. CloseLibrary(DiskfontBase);
  253. DiskfontBase := nil;
  254. end;
  255. end;
  256. begin
  257. DiskfontBase := nil;
  258. DiskfontBase := OpenLibrary(DISKFONTNAME,LIBVERSION);
  259. if DiskfontBase <> nil then begin
  260. diskfont_exit := ExitProc;
  261. ExitProc := @ClosediskfontLibrary;
  262. DISKFONTIsCompiledHow := 1;
  263. end else begin
  264. MessageBox('FPC Pascal Error',
  265. 'Can''t open diskfont.library version ' + VERSION + #10 +
  266. 'Deallocating resources and closing down',
  267. 'Oops');
  268. halt(20);
  269. end;
  270. {$endif use_auto_openlib}
  271. {$ifdef dont_use_openlib}
  272. begin
  273. DISKFONTIsCompiledHow := 3;
  274. {$Warning No autoopening of diskfont.library compiled}
  275. {$Warning Make sure you open diskfont.library yourself}
  276. {$endif dont_use_openlib}
  277. END. (* UNIT DISKFONT *)