No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

3651 líneas
111 KiB

  1. {
  2. TextSuite (C) Steffen Xonna (aka Lossy eX)
  3. http://www.opengl24.de/
  4. -----------------------------------------------------------------------
  5. For copyright informations see file copyright.txt.
  6. }
  7. {$I TextSuiteOptions.inc}
  8. unit TextSuite;
  9. interface
  10. type
  11. tsBool = Cardinal;
  12. tsByte = Byte;
  13. tsInt = Integer;
  14. tsFloat = Single;
  15. tsEnum = Cardinal;
  16. tsBitmask = Cardinal;
  17. tsError = Cardinal;
  18. ptsBool = ^tsBool;
  19. ptsByte = ^tsByte;
  20. ptsInt = ^tsInt;
  21. ptsEnum = ^tsEnum;
  22. tsContextID = Cardinal;
  23. tsFontID = Cardinal;
  24. tsImageID = Cardinal;
  25. ptsContextID = ^tsContextID;
  26. ptsFontID = ^tsFontID;
  27. ptsImageID = ^tsImageID;
  28. PPointer = ^Pointer;
  29. tsPostProcessProc = procedure(ImageID: tsImageID; CharCode: WideChar; Data: Pointer); cdecl;
  30. // these types are more internally.
  31. ptsColor = ^tsColor;
  32. tsColor = packed record
  33. Red: Byte;
  34. Green: Byte;
  35. Blue: Byte;
  36. Alpha: Byte;
  37. end;
  38. ptsRect = ^tsRect;
  39. tsRect = packed record
  40. Left: Integer;
  41. Top: Integer;
  42. Right: Integer;
  43. Bottom: Integer;
  44. end;
  45. ptsPoint = ^tsPoint;
  46. tsPoint = packed record
  47. X: Integer;
  48. Y: Integer;
  49. end;
  50. const
  51. {$ifdef TS_EXTERN_STATIC}
  52. {$ifdef WINDOWS}
  53. TS_LIBRARY = 'libTextSuite.dll';
  54. {$else}
  55. {$ifdef darwin}
  56. TS_LIBRARY = 'libTextSuite.dylib';
  57. {$else}
  58. TS_LIBRARY = 'libTextSuite.so';
  59. {$endif}
  60. {$endif}
  61. {$endif}
  62. // Booleans
  63. TS_TRUE = 1;
  64. TS_FALSE = 0;
  65. TS_DEFAULT = 0;
  66. // Inits
  67. TS_INIT_TEXTSUITE = $01;
  68. TS_INIT_SDL_TTF = $02;
  69. TS_INIT_SDL_IMAGE = $04;
  70. TS_INIT_GDI = $08;
  71. TS_INIT_OPENGL = $10;
  72. // TS_INIT_FREETYPE2 = $20;
  73. // library infos
  74. TS_INFO_MAYOR_VERSION = $01;
  75. TS_INFO_MINOR_VERSION = $02;
  76. TS_INFO_BUILD_NUMBER = $03;
  77. TS_INFO_VERSION = $04;
  78. TS_INFO_COPYRIGHT = $05;
  79. TS_GLOBAL_ANTIALIASING = $11;
  80. TS_GLOBAL_FORMAT = $12;
  81. // debug infos
  82. TS_DEBUG_DRAW_CHAR_RECTS = $30;
  83. // context
  84. TS_CONTEXT_BINDING = $40;
  85. // Renderer
  86. TS_RENDERER = $50;
  87. TS_RENDERER_NULL = $51;
  88. TS_RENDERER_OPENGL = $52;
  89. TS_RENDERER_NULL_SAVE_IMAGES = $60;
  90. TS_RENDERER_OPENGL_TEXTURE_SIZE = $70;
  91. TS_RENDERER_OPENGL_TEXTURE_SIZE_128 = $71;
  92. TS_RENDERER_OPENGL_TEXTURE_SIZE_256 = $72;
  93. TS_RENDERER_OPENGL_TEXTURE_SIZE_512 = $73;
  94. TS_RENDERER_OPENGL_TEXTURE_SIZE_1024 = $74;
  95. // Font
  96. TS_FONT_BINDING = $100;
  97. TS_FONT_COPYRIGHT = $101;
  98. TS_FONT_FACE_NAME = $102;
  99. TS_FONT_STYLE_NAME = $103;
  100. TS_FONT_FULL_NAME = $104;
  101. TS_FONT_SIZE = $105;
  102. TS_FONT_STYLE = $106;
  103. TS_FONT_FILE_STYLE = $107;
  104. TS_FONT_FIXED_WIDTH = $108;
  105. TS_FONT_ANTIALIASING = $109;
  106. TS_FONT_FORMAT = $10A;
  107. TS_FONT_ASCENT = $10B;
  108. TS_FONT_DESCENT = $113;
  109. TS_FONT_EXTERNAL_LEADING = $114;
  110. TS_FONT_LINESKIP = $10C;
  111. TS_FONT_CHAR_SPACING = $10D;
  112. TS_FONT_LINE_SPACING = $10E;
  113. TS_FONT_UNDERLINE_POSITION = $10F;
  114. TS_FONT_UNDERLINE_SIZE = $110;
  115. TS_FONT_STRIKEOUT_POSITION = $111;
  116. TS_FONT_STRIKEOUT_SIZE = $112;
  117. TS_FONT_BASELINE_OFFSET = $115;
  118. // Char parameters
  119. TS_CHAR_ADVANCE = $131;
  120. TS_CHAR_GLYPHORIGIN = $132;
  121. TS_CHAR_GLYPHORIGIN_X = $133;
  122. TS_CHAR_GLYPHORIGIN_Y = $134;
  123. TS_CHAR_GLYPHRECT = $135;
  124. TS_CHAR_GLYPHRECT_TOP = $136;
  125. TS_CHAR_GLYPHRECT_LEFT = $137;
  126. TS_CHAR_GLYPHRECT_RIGHT = $138;
  127. TS_CHAR_GLYPHRECT_BOTTOM = $139;
  128. // Creator
  129. TS_CREATOR = $200;
  130. TS_CREATOR_SDL = $201;
  131. TS_CREATOR_GDI = $202;
  132. TS_CREATOR_GDI_FACENAME = $203;
  133. // TS_CREATOR_FREETYPE2 = $204;
  134. TS_CREATOR_GDI_STREAM = $205;
  135. TS_CREATOR_CREATE_CHARS = $210;
  136. TS_CREATOR_ADD_RESIZING_BORDER = $211;
  137. // Font Style
  138. TS_STYLE_NORMAL = $00;
  139. TS_STYLE_BOLD = $01;
  140. TS_STYLE_ITALIC = $02;
  141. TS_STYLE_UNDERLINE = $04;
  142. TS_STYLE_STRIKEOUT = $08;
  143. // AntiAliasing
  144. TS_ANTIALIASING_NONE = $221;
  145. TS_ANTIALIASING_NORMAL = $222;
  146. // Formats
  147. TS_FORMAT_EMPTY = $231;
  148. TS_FORMAT_RGBA8 = $232;
  149. // PostProcessing usage type
  150. TS_POST_INDEX_ALL = -2;
  151. TS_POST_INDEX_LAST = -1;
  152. TS_POST_USAGE_INCLUDE = $291;
  153. TS_POST_USAGE_EXCLUDE = $292;
  154. // output consts
  155. // Single line
  156. TS_SINGLE_LINE = $300;
  157. TS_SINGLE_LINE_TOP = $301;
  158. TS_SINGLE_LINE_BASELINE = $302;
  159. // Textalign
  160. TS_ALIGN = $310;
  161. TS_ALIGN_LEFT = $311;
  162. TS_ALIGN_CENTER = $312;
  163. TS_ALIGN_RIGHT = $313;
  164. TS_ALIGN_BLOCK = $314;
  165. TS_VALIGN = $320;
  166. TS_VALIGN_TOP = $321;
  167. TS_VALIGN_CENTER = $322;
  168. TS_VALIGN_BOTTOM = $323;
  169. // Textblockflags
  170. TS_BLOCK_OFFSET_X = $331;
  171. TS_BLOCK_OFFSET_Y = $332;
  172. TS_BLOCKFLAG_NONE = $00;
  173. TS_BLOCKFLAG_NO_CLIP = $01;
  174. TS_BLOCKFLAG_CALC_SIZE = $02;
  175. TS_BLOCKFLAG_WORD_WRAP = $04;
  176. // TS_BF_SINGLE_LINE = $08;
  177. // TS_BF_END_ELLIPSIS = $10;
  178. TS_CLIP = $340;
  179. TS_CLIP_COMPLETE = $341;
  180. TS_CLIP_BORDER = $342;
  181. {
  182. TS_TAB = $350;
  183. TS_TAB_FIXED = $351;
  184. TS_TAB_ABSOLUTE = $352;
  185. TS_TAB_FIXED_WIDTH = $353;
  186. TS_TAB_ABSOLUTE_POSITIONS = $354;
  187. }
  188. // Code pages
  189. TS_EMPTY_CP_ENTRY = $1000;
  190. TS_EMPTY_CP_ENTRY_IGNORE = $1001;
  191. TS_EMPTY_CP_ENTRY_USE_DEFAULT = $1002;
  192. TS_CODEPAGE = $1100;
  193. TS_CODEPAGE_UTF8 = TS_CODEPAGE + 1;
  194. TS_CODEPAGE_8859_1 = TS_CODEPAGE + 11;
  195. TS_CODEPAGE_8859_2 = TS_CODEPAGE + 12;
  196. TS_CODEPAGE_8859_3 = TS_CODEPAGE + 13;
  197. TS_CODEPAGE_8859_4 = TS_CODEPAGE + 14;
  198. TS_CODEPAGE_8859_5 = TS_CODEPAGE + 15;
  199. TS_CODEPAGE_8859_6 = TS_CODEPAGE + 16;
  200. TS_CODEPAGE_8859_7 = TS_CODEPAGE + 17;
  201. TS_CODEPAGE_8859_8 = TS_CODEPAGE + 18;
  202. TS_CODEPAGE_8859_9 = TS_CODEPAGE + 19;
  203. TS_CODEPAGE_8859_10 = TS_CODEPAGE + 20;
  204. TS_CODEPAGE_8859_11 = TS_CODEPAGE + 21;
  205. TS_CODEPAGE_8859_13 = TS_CODEPAGE + 22;
  206. TS_CODEPAGE_8859_14 = TS_CODEPAGE + 23;
  207. TS_CODEPAGE_8859_15 = TS_CODEPAGE + 24;
  208. TS_CODEPAGE_8859_16 = TS_CODEPAGE + 25;
  209. TS_CODEPAGE_037 = TS_CODEPAGE + 31;
  210. TS_CODEPAGE_437 = TS_CODEPAGE + 32;
  211. TS_CODEPAGE_500 = TS_CODEPAGE + 33;
  212. TS_CODEPAGE_737 = TS_CODEPAGE + 34;
  213. TS_CODEPAGE_775 = TS_CODEPAGE + 35;
  214. TS_CODEPAGE_850 = TS_CODEPAGE + 36;
  215. TS_CODEPAGE_852 = TS_CODEPAGE + 37;
  216. TS_CODEPAGE_855 = TS_CODEPAGE + 38;
  217. TS_CODEPAGE_857 = TS_CODEPAGE + 39;
  218. TS_CODEPAGE_860 = TS_CODEPAGE + 40;
  219. TS_CODEPAGE_861 = TS_CODEPAGE + 41;
  220. TS_CODEPAGE_862 = TS_CODEPAGE + 42;
  221. TS_CODEPAGE_863 = TS_CODEPAGE + 43;
  222. TS_CODEPAGE_864 = TS_CODEPAGE + 44;
  223. TS_CODEPAGE_865 = TS_CODEPAGE + 45;
  224. TS_CODEPAGE_866 = TS_CODEPAGE + 46;
  225. TS_CODEPAGE_869 = TS_CODEPAGE + 47;
  226. TS_CODEPAGE_874 = TS_CODEPAGE + 48;
  227. TS_CODEPAGE_875 = TS_CODEPAGE + 49;
  228. TS_CODEPAGE_1026 = TS_CODEPAGE + 50;
  229. TS_CODEPAGE_1250 = TS_CODEPAGE + 51;
  230. TS_CODEPAGE_1251 = TS_CODEPAGE + 52;
  231. TS_CODEPAGE_1252 = TS_CODEPAGE + 53;
  232. TS_CODEPAGE_1253 = TS_CODEPAGE + 54;
  233. TS_CODEPAGE_1254 = TS_CODEPAGE + 55;
  234. TS_CODEPAGE_1255 = TS_CODEPAGE + 56;
  235. TS_CODEPAGE_1256 = TS_CODEPAGE + 57;
  236. TS_CODEPAGE_1257 = TS_CODEPAGE + 58;
  237. TS_CODEPAGE_1258 = TS_CODEPAGE + 59;
  238. // channel masks
  239. TS_CHANNEL_RED = $01;
  240. TS_CHANNEL_GREEN = $02;
  241. TS_CHANNEL_BLUE = $04;
  242. TS_CHANNEL_ALPHA = $08;
  243. TS_CHANNEL_LUMINANCE = $10;
  244. TS_CHANNELS_RGB = TS_CHANNEL_RED or TS_CHANNEL_GREEN or TS_CHANNEL_BLUE;
  245. TS_CHANNELS_RGBA = TS_CHANNELS_RGB or TS_CHANNEL_ALPHA;
  246. TS_CHANNELS_LUMINANCE_ALPHA = TS_CHANNEL_LUMINANCE or TS_CHANNEL_ALPHA;
  247. TS_IMAGE_RED_MODE = $401;
  248. TS_IMAGE_GREEN_MODE = $402;
  249. TS_IMAGE_BLUE_MODE = $403;
  250. TS_IMAGE_ALPHA_MODE = $404;
  251. TS_IMAGE_LUMINANCE_MODE = $405;
  252. TS_MODE_REPLACE = $411;
  253. TS_MODE_MODULATE = $412;
  254. // Imagelibrary
  255. TS_IMAGE_LIBRARY = $420;
  256. TS_IMAGE_LIBRARY_SDL = $421;
  257. // Errorcode
  258. TS_NO_ERROR = $0000;
  259. TS_ERROR = $8000;
  260. TS_NO_ACTIVE_CONTEXT = TS_ERROR + $1;
  261. TS_NO_ACTIVE_RENDERER = TS_ERROR + $2;
  262. TS_NO_ACTIVE_FONT = TS_ERROR + $3;
  263. TS_INVALID_OPERATION = TS_ERROR + $4;
  264. TS_INVALID_ENUM = TS_ERROR + $5;
  265. TS_INVALID_VALUE = TS_ERROR + $6;
  266. TS_OUT_OF_MEMORY = TS_ERROR + $7;
  267. TS_NOT_INITIALIZED = TS_ERROR + $8;
  268. TS_NO_FUNC = $0000;
  269. TS_FUNC = $4000;
  270. TS_FUNC_INIT = TS_FUNC + $01;
  271. TS_FUNC_QUIT = TS_FUNC + $02;
  272. TS_FUNC_SET_PARAMETER = TS_FUNC + $03;
  273. TS_FUNC_GET_PARAMETER = TS_FUNC + $04;
  274. TS_FUNC_GET_STRING = TS_FUNC + $05;
  275. TS_FUNC_CONTEXT_CREATE = TS_FUNC + $06;
  276. TS_FUNC_CONTEXT_DESTROY = TS_FUNC + $07;
  277. TS_FUNC_CONTEXT_BIND = TS_FUNC + $08;
  278. TS_FUNC_FONT_CREATE_CREATOR = TS_FUNC + $09;
  279. TS_FUNC_FONT_DESTROY = TS_FUNC + $0A;
  280. TS_FUNC_FONT_BIND = TS_FUNC + $0B;
  281. TS_FUNC_FONT_ADD_CHAR = TS_FUNC + $0C;
  282. TS_FUNC_FONT_DELETE_CHAR = TS_FUNC + $0D;
  283. TS_FUNC_FONT_SET_CHAR_PARAMETER = TS_FUNC + $0E;
  284. TS_FUNC_FONT_GET_CHAR_PARAMETER = TS_FUNC + $0F;
  285. TS_FUNC_POST_ADD_FILL_COLOR = TS_FUNC + $10;
  286. TS_FUNC_POST_ADD_FILL_PATTERN = TS_FUNC + $11;
  287. TS_FUNC_POST_ADD_BORDER = TS_FUNC + $12;
  288. TS_FUNC_POST_ADD_SHADOW = TS_FUNC + $13;
  289. TS_FUNC_POST_ADD_CUSTOM = TS_FUNC + $14;
  290. TS_FUNC_POST_DELETE = TS_FUNC + $15;
  291. TS_FUNC_POST_ADD_USAGE = TS_FUNC + $16;
  292. TS_FUNC_POST_CLEAR_USAGE = TS_FUNC + $17;
  293. TS_FUNC_STRING_ANSI_TO_WIDE = TS_FUNC + $18;
  294. TS_FUNC_STRING_ALLOC = TS_FUNC + $19;
  295. TS_FUNC_STRING_DISPOSE = TS_FUNC + $1A;
  296. TS_FUNC_TEXT_BEGIN_BLOCK = TS_FUNC + $1B;
  297. TS_FUNC_TEXT_END_BLOCK = TS_FUNC + $1C;
  298. TS_FUNC_TEXT_COLOR = TS_FUNC + $1D;
  299. TS_FUNC_TEXT_OUT = TS_FUNC + $1E;
  300. TS_FUNC_TEXT_GET_WIDTH = TS_FUNC + $1F;
  301. TS_FUNC_TEXT_GET_HEIGHT = TS_FUNC + $20;
  302. TS_FUNC_IMAGE_CREATE = TS_FUNC + $21;
  303. TS_FUNC_IMAGE_DESTROY = TS_FUNC + $22;
  304. TS_FUNC_IMAGE_LOAD = TS_FUNC + $23;
  305. TS_FUNC_IMAGE_ASSIGN_FROM = TS_FUNC + $24;
  306. TS_FUNC_IMAGE_NEW = TS_FUNC + $25;
  307. TS_FUNC_IMAGE_GET_INFO = TS_FUNC + $26;
  308. TS_FUNC_IMAGE_SCANLINE = TS_FUNC + $27;
  309. TS_FUNC_IMAGE_RESIZE = TS_FUNC + $28;
  310. TS_FUNC_IMAGE_BLEND = TS_FUNC + $29;
  311. TS_FUNC_IMAGE_BLUR = TS_FUNC + $2A;
  312. TS_FUNC_IMAGE_FILL_COLOR = TS_FUNC + $2B;
  313. TS_FUNC_IMAGE_FILL_PATTERN = TS_FUNC + $2C;
  314. // *** global functions ***
  315. function tsInit(Names: tsEnum): tsBool; cdecl;
  316. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsInit'; {$endif}
  317. function tsWasInit(Names: tsEnum): tsBool; cdecl;
  318. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsWasInit'; {$endif}
  319. procedure tsQuit; cdecl;
  320. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsQuit'; {$endif}
  321. function tsGetError: tsEnum; cdecl;
  322. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsGetError'; {$endif}
  323. function tsGetErrorFunction: tsEnum; cdecl;
  324. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsGetErrorFunction'; {$endif}
  325. function tsGetErrorStringA(ErrorCode: tsEnum): pAnsiChar; cdecl;
  326. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsGetErrorStringA'; {$endif}
  327. procedure tsSetParameteri(ParamName: tsEnum; Param: tsInt); cdecl;
  328. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsSetParameteri'; {$endif}
  329. procedure tsSetParameteriv(ParamName: tsEnum; pParam: ptsInt); cdecl;
  330. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsSetParameteriv'; {$endif}
  331. function tsGetParameteri(ParamName: tsEnum): tsInt; cdecl;
  332. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsGetParameteri'; {$endif}
  333. procedure tsGetParameteriv(ParamName: tsEnum; pParam: ptsInt); cdecl;
  334. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsGetParameteriv'; {$endif}
  335. function tsGetStringA(ParamName: tsEnum): pAnsiChar; cdecl;
  336. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsGetStringA'; {$endif}
  337. // *** context functions ***
  338. procedure tsContextCreate(pContextID: ptsContextID); cdecl;
  339. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsContextCreate'; {$endif}
  340. procedure tsContextDestroy(ContextID: tsContextID); cdecl;
  341. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsContextDestroy'; {$endif}
  342. procedure tsContextBind(ContextID: tsContextID); cdecl;
  343. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsContextBind'; {$endif}
  344. // *** font functions ***
  345. // procedure tsFontCreate(pFontID: ptsFontID); cdecl;
  346. // {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name ; {$endif}
  347. procedure tsFontCreateCreatorA(Name: pAnsiChar; Size: tsInt; Style: tsBitmask; AntiAliasing: tsEnum; Format: tsEnum; pFontID: ptsFontID); cdecl;
  348. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsFontCreateCreatorA'; {$endif}
  349. procedure tsFontDestroy(FontID: tsFontID); cdecl;
  350. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsFontDestroy'; {$endif}
  351. procedure tsFontBind(FontID: tsFontID); cdecl;
  352. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsFontBind'; {$endif}
  353. procedure tsFontAddCharRange(CharStart: WideChar; CharEnd: WideChar); cdecl;
  354. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsFontAddCharRange'; {$endif}
  355. procedure tsFontAddChars(Chars: pWideChar); cdecl;
  356. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsFontAddChars'; {$endif}
  357. procedure tsFontAddChar(Char: WideChar); cdecl;
  358. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsFontAddChar'; {$endif}
  359. procedure tsFontDeleteCharRange(CharStart: WideChar; CharEnd: WideChar); cdecl;
  360. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsFontDeleteCharRange'; {$endif}
  361. procedure tsFontDeleteChars(Chars: pWideChar); cdecl;
  362. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsFontDeleteChars'; {$endif}
  363. procedure tsFontDeleteChar(Char: WideChar); cdecl;
  364. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsFontDeleteChar'; {$endif}
  365. procedure tsFontSetCharParameteri(Char: WideChar; ParamName: tsEnum; Param: tsInt); cdecl;
  366. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsFontSetCharParameteri'; {$endif}
  367. procedure tsFontSetCharParameteriv(Char: WideChar; ParamName: tsEnum; pParam: ptsInt); cdecl;
  368. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsFontSetCharParameteri'; {$endif}
  369. function tsFontGetCharParameteri(Char: WideChar; ParamName: tsEnum): tsInt; cdecl;
  370. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsFontGetCharParameteri'; {$endif}
  371. procedure tsFontGetCharParameteriv(Char: WideChar; ParamName: tsEnum; pParam: ptsInt); cdecl;
  372. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsFontGetCharParameteri'; {$endif}
  373. procedure tsPostAddFillColor3ub(Red, Green, Blue: tsByte; ChannelMask: tsBitmask); cdecl;
  374. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddFillColor3ub'; {$endif}
  375. procedure tsPostAddFillColor3f(Red, Green, Blue: tsFloat; ChannelMask: tsBitmask); cdecl;
  376. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddFillColor3f'; {$endif}
  377. procedure tsPostAddFillColor4ub(Red, Green, Blue, Alpha: tsByte; ChannelMask: tsBitmask); cdecl;
  378. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddFillColor4ub'; {$endif}
  379. procedure tsPostAddFillColor4f(Red, Green, Blue, Alpha: tsFloat; ChannelMask: tsBitmask); cdecl;
  380. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddFillColor4f'; {$endif}
  381. procedure tsPostAddFillPattern(PatternImageID: tsImageID; X, Y: tsInt; ChannelMask: tsBitmask); cdecl;
  382. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddFillPattern'; {$endif}
  383. procedure tsPostAddBorder3ub(Width, Strength: tsFloat; Red, Green, Blue: tsByte); cdecl;
  384. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddBorder3ub'; {$endif}
  385. procedure tsPostAddBorder3f(Width, Strength: tsFloat; Red, Green, Blue: tsFloat); cdecl;
  386. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddBorder3f'; {$endif}
  387. procedure tsPostAddBorder4ub(Width, Strength: tsFloat; Red, Green, Blue, Alpha: tsByte); cdecl;
  388. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddBorder4ub'; {$endif}
  389. procedure tsPostAddBorder4f(Width, Strength: tsFloat; Red, Green, Blue, Alpha: tsFloat); cdecl;
  390. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddBorder4f'; {$endif}
  391. procedure tsPostAddShadow3ub(Radius: tsFloat; X, Y: tsInt; Red, Green, Blue: tsByte); cdecl;
  392. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddShadow3ub'; {$endif}
  393. procedure tsPostAddShadow3f(Radius: tsFloat; X, Y: tsInt; Red, Green, Blue: tsFloat); cdecl;
  394. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddShadow3f'; {$endif}
  395. procedure tsPostAddShadow4ub(Radius: tsFloat; X, Y: tsInt; Red, Green, Blue, Alpha: tsByte); cdecl;
  396. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddShadow4ub'; {$endif}
  397. procedure tsPostAddShadow4f(Radius: tsFloat; X, Y: tsInt; Red, Green, Blue, Alpha: tsFloat); cdecl;
  398. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddShadow4f'; {$endif}
  399. // procedure tsPostAddKerning; cdecl;
  400. // {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddKerning'; {$endif}
  401. procedure tsPostAddCustom(PostProcessProc: tsPostProcessProc; Data: Pointer); cdecl;
  402. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddCustom'; {$endif}
  403. procedure tsPostDelete(PostIndex: tsInt); cdecl;
  404. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostDelete'; {$endif}
  405. procedure tsPostAddUsageRange(PostIndex: tsInt; UsageType: tsEnum; CharStart, CharEnd: WideChar); cdecl;
  406. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddUsageRange'; {$endif}
  407. procedure tsPostAddUsageChars(PostIndex: tsInt; UsageType: tsEnum; Chars: pWideChar); cdecl;
  408. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostAddUsageChars'; {$endif}
  409. procedure tsPostClearUsage(PostIndex: tsInt); cdecl;
  410. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsPostClearUsage'; {$endif}
  411. // *** string functions ***
  412. function tsStringAnsiToWide(pText: pAnsiChar): pWideChar; cdecl;
  413. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsStringAnsiToWide'; {$endif}
  414. function tsStringAlloc(Size: tsInt): pWideChar; cdecl;
  415. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsStringAlloc'; {$endif}
  416. procedure tsStringDispose(pText: pWideChar); cdecl;
  417. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsStringDispose'; {$endif}
  418. // *** drawing functions ***
  419. procedure tsTextBeginBlock(Left, Top, Width, Height: tsInt; Flags: tsBitmask); cdecl;
  420. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsTextBeginBlock'; {$endif}
  421. procedure tsTextEndBlock; cdecl;
  422. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsTextEndBlock'; {$endif}
  423. procedure tsTextColor3ub(Red, Green, Blue: tsByte); cdecl;
  424. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsTextColor3ub'; {$endif}
  425. procedure tsTextColor3f(Red, Green, Blue: tsFloat); cdecl;
  426. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsTextColor3f'; {$endif}
  427. procedure tsTextColor4ub(Red, Green, Blue, Alpha: tsByte); cdecl;
  428. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsTextColor4ub'; {$endif}
  429. procedure tsTextColor4f(Red, Green, Blue, Alpha: tsFloat); cdecl;
  430. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsTextColor4f'; {$endif}
  431. procedure tsTextOutA(pText: pAnsiChar); cdecl;
  432. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsTextOutA'; {$endif}
  433. procedure tsTextOutW(pText: pWideChar); cdecl;
  434. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsTextOutW'; {$endif}
  435. function tsTextGetWidthA(pText: pAnsiChar): tsInt; cdecl;
  436. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsTextGetWidthA'; {$endif}
  437. function tsTextGetWidthW(pText: pWideChar): tsInt; cdecl;
  438. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsTextGetWidthW'; {$endif}
  439. function tsTextGetHeightA(pText: pAnsiChar): tsInt; cdecl;
  440. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsTextGetHeightA'; {$endif}
  441. function tsTextGetHeightW(pText: pWideChar): tsInt; cdecl;
  442. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsTextGetHeightW'; {$endif}
  443. procedure tsCharOutW(CharCode: WideChar); cdecl;
  444. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsCharOutW'; {$endif}
  445. // *** Image functions ***
  446. procedure tsImageCreate(pImageID: ptsImageID); cdecl;
  447. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageCreate'; {$endif}
  448. procedure tsImageDestroy(ImageID: tsImageID); cdecl;
  449. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageDestroy'; {$endif}
  450. procedure tsImageLoadA(ImageID: tsImageID; Filename: pAnsiChar); cdecl;
  451. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageLoadA'; {$endif}
  452. procedure tsImageAssignFrom(ImageID: tsImageID; FromImageID: tsImageID); cdecl;
  453. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageAssignFrom'; {$endif}
  454. procedure tsImageNew(ImageID: tsImageID; Width: tsInt; Height: tsInt; Format: tsEnum); cdecl;
  455. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageNew'; {$endif}
  456. procedure tsImageGetInfo(ImageID: tsImageID; pisEmpty: ptsBool; pWidth: ptsInt; pHeight: ptsInt; pFormat: ptsEnum; pData: PPointer); cdecl;
  457. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageGetInfo'; {$endif}
  458. function tsImageGetIsEmpty(ImageID: tsImageID): tsBool; cdecl;
  459. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageGetIsEmpty'; {$endif}
  460. function tsImageGetWidth(ImageID: tsImageID): tsInt; cdecl;
  461. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageGetWidth'; {$endif}
  462. function tsImageGetHeight(ImageID: tsImageID): tsInt; cdecl;
  463. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageGetHeight'; {$endif}
  464. function tsImageGetFormat(ImageID: tsImageID): tsEnum; cdecl;
  465. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageGetFormat'; {$endif}
  466. function tsImageGetData(ImageID: tsImageID): Pointer; cdecl;
  467. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageGetData'; {$endif}
  468. function tsImageScanline(ImageID: tsImageID; Scanline: tsInt): Pointer; cdecl;
  469. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageScanline'; {$endif}
  470. procedure tsImageResize(ImageID: tsImageID; Width, Height, X, Y: tsInt); cdecl;
  471. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageResize'; {$endif}
  472. procedure tsImageBlend(ImageID, OverImageID: tsImageID; X, Y: tsInt; AutoExpand: tsBool); cdecl;
  473. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageBlend'; {$endif}
  474. procedure tsImageBlur(ImageID: tsImageID; X, Y: tsFloat; ChannelMask: tsBitmask; AutoExpand: tsBool; ExpandSizeX, ExpandSizeY: ptsInt); cdecl;
  475. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageBlur'; {$endif}
  476. procedure tsImageFillColor3ub(ImageID: tsImageID; Red, Green, Blue: tsByte; ChannelMask: tsBitmask); cdecl;
  477. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageFillColor3ub'; {$endif}
  478. procedure tsImageFillColor3f(ImageID: tsImageID; Red, Green, Blue: tsFloat; ChannelMask: tsBitmask); cdecl;
  479. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageFillColor3f'; {$endif}
  480. procedure tsImageFillColor4ub(ImageID: tsImageID; Red, Green, Blue, Alpha: tsByte; ChannelMask: tsBitmask); cdecl;
  481. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageFillColor4ub'; {$endif}
  482. procedure tsImageFillColor4f(ImageID: tsImageID; Red, Green, Blue, Alpha: tsFloat; ChannelMask: tsBitmask); cdecl;
  483. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageFillColor4f'; {$endif}
  484. procedure tsImageFillPattern(ImageID, PatternImageID: tsImageID; X, Y: tsInt; ChannelMask: tsBitmask); cdecl;
  485. {$ifdef TS_EXTERN_STATIC} external TS_LIBRARY name 'tsImageFillPattern'; {$endif}
  486. implementation
  487. { This define ignores implementations of all functions }
  488. {$ifndef TS_EXTERN_STATIC}
  489. uses
  490. Classes,
  491. SysUtils,
  492. SyncObjs,
  493. TextSuiteClasses,
  494. TextSuitePostProcess,
  495. TextSuiteImports,
  496. {$ifndef TS_PURE_PASCAL}
  497. TextSuiteCPUUtils,
  498. {$endif}
  499. TextSuiteVersion,
  500. TextSuiteWideUtils;
  501. // string consts
  502. const
  503. TS_COPYRIGHT_STR = 'TextSuite (c) 2007-2009 by Steffen Xonna';
  504. // error consts
  505. const
  506. TS_NO_ERROR_STR = 'no error';
  507. TS_ERROR_STR = 'unknown error';
  508. TS_NO_ACTIVE_CONTEXT_STR = 'no active context';
  509. TS_NO_ACTIVE_RENDERER_STR = 'no active renderer';
  510. TS_NO_ACTIVE_FONT_STR = 'no active font';
  511. TS_INVALID_OPERATION_STR = 'invalid operation';
  512. TS_INVALID_ENUM_STR = 'invalid enum';
  513. TS_INVALID_VALUE_STR = 'invalid value';
  514. TS_OUT_OF_MEMORY_STR = 'out of memory';
  515. TS_NOT_INITIALIZED_STR = 'not initialized';
  516. // global variables
  517. var
  518. TextSuite_initialized: Boolean;
  519. TextSuite_initialized_count: Integer;
  520. gCriticalSection: TCriticalSection;
  521. gContexts: TtsHash;
  522. gStrings: TtsStringHash;
  523. // globals for the threads
  524. threadvar
  525. gError: tsEnum;
  526. gErrorFunction: tsEnum;
  527. gContext: TtsContext;
  528. procedure SetError(Error, ErrorFunction: tsEnum);
  529. begin
  530. gError := Error;
  531. gErrorFunction := ErrorFunction;
  532. end;
  533. procedure ClearContexts;
  534. var
  535. List: TList;
  536. Context: TtsContext;
  537. Idx: Integer;
  538. begin
  539. List := TList.Create;
  540. try
  541. gContexts.GetValues(List);
  542. gContexts.Clear;
  543. gContext := nil;
  544. for Idx := 0 to List.Count - 1 do begin
  545. Context := List[Idx];
  546. Context.Free;
  547. end;
  548. finally
  549. List.Free;
  550. end;
  551. end;
  552. function Init_TextSuite: boolean;
  553. begin
  554. if (TextSuite_initialized_count = 0) or (not TextSuite_initialized) then begin
  555. {$ifndef TS_PURE_PASCAL}
  556. ReadCPUFlags;
  557. if supportFPU and supportCMOV and supportMMX then begin
  558. {$endif}
  559. // global section
  560. if gCriticalSection = nil then
  561. gCriticalSection := TCriticalSection.Create;
  562. // Context management
  563. if gContexts = nil then
  564. gContexts := TtsHash.Create(113);
  565. // string management
  566. if gStrings = nil then
  567. gStrings := TtsStringHash.Create(4219);
  568. TextSuite_initialized :=
  569. (gCriticalSection <> nil) and
  570. (gContexts <> nil) and
  571. (gStrings <> nil);
  572. {$ifndef TS_PURE_PASCAL}
  573. end;
  574. {$endif}
  575. end;
  576. Inc(TextSuite_initialized_count);
  577. Result := TextSuite_initialized;
  578. end;
  579. procedure Quit_TextSuite;
  580. begin
  581. Dec(TextSuite_initialized_count);
  582. if TextSuite_initialized_count = 0 then begin
  583. // destroy all contexts
  584. ClearContexts;
  585. // destroy hash
  586. gStrings.Free;
  587. gStrings := nil;
  588. gContexts.Free;
  589. gContexts := nil;
  590. gCriticalSection.Free;
  591. gCriticalSection := nil;
  592. gContext := nil;
  593. TextSuite_initialized := False;
  594. end;
  595. end;
  596. // *** global functions
  597. function tsInit(Names: tsEnum): tsBool;
  598. var
  599. ResNames: tsEnum;
  600. begin
  601. Result := TS_FALSE;
  602. try
  603. ResNames := 0;
  604. if (Names and TS_INIT_TEXTSUITE) > 0 then
  605. if Init_TextSuite then
  606. ResNames := ResNames or TS_INIT_TEXTSUITE;
  607. if (Names and TS_INIT_SDL_TTF) > 0 then
  608. if Init_SDL_TTF then
  609. ResNames := ResNames or TS_INIT_SDL_TTF;
  610. if (Names and TS_INIT_SDL_IMAGE) > 0 then
  611. if Init_SDL_IMAGE then
  612. ResNames := ResNames or TS_INIT_SDL_IMAGE;
  613. if (Names and TS_INIT_GDI) > 0 then
  614. if Init_GDI then
  615. ResNames := ResNames or TS_INIT_GDI;
  616. if (Names and TS_INIT_OPENGL) > 0 then
  617. if Init_OpenGL then
  618. ResNames := ResNames or TS_INIT_OPENGL;
  619. if ResNames = Names then
  620. Result := TS_TRUE;
  621. if Result = TS_FALSE then
  622. SetError(TS_NOT_INITIALIZED, TS_FUNC_INIT);
  623. except
  624. SetError(TS_ERROR, TS_FUNC_INIT);
  625. end;
  626. end;
  627. function tsWasInit(Names: tsEnum): tsBool;
  628. var
  629. ResNames: tsEnum;
  630. begin
  631. ResNames := 0;
  632. if (Names and TS_INIT_TEXTSUITE) > 0 then
  633. if TextSuite_initialized then
  634. ResNames := ResNames or TS_INIT_TEXTSUITE;
  635. if (Names and TS_INIT_SDL_TTF) > 0 then
  636. if SDL_TTF_initialized then
  637. ResNames := ResNames or TS_INIT_SDL_TTF;
  638. if (Names and TS_INIT_SDL_IMAGE) > 0 then
  639. if SDL_IMAGE_initialized then
  640. ResNames := ResNames or TS_INIT_SDL_IMAGE;
  641. if (Names and TS_INIT_GDI) > 0 then
  642. if GDI_initialized then
  643. ResNames := ResNames or TS_INIT_GDI;
  644. if (Names and TS_INIT_OPENGL) > 0 then
  645. if OpenGL_initialized then
  646. ResNames := ResNames or TS_INIT_OPENGL;
  647. if ResNames = Names then
  648. Result := TS_TRUE
  649. else
  650. Result := TS_FALSE;
  651. end;
  652. procedure tsQuit;
  653. begin
  654. try
  655. // maybe quit library if count is zero
  656. if TextSuite_initialized then
  657. Quit_TextSuite;
  658. // if count is zero then quit all other systems
  659. if TextSuite_initialized_count = 0 then begin
  660. if SDL_TTF_initialized then
  661. Quit_SDL_TTF;
  662. if SDL_IMAGE_initialized then
  663. Quit_SDL_IMAGE;
  664. if GDI_initialized then
  665. Quit_GDI;
  666. if OpenGL_initialized then
  667. Quit_OpenGL;
  668. Quit_SDL;
  669. end;
  670. except
  671. SetError(TS_ERROR, TS_FUNC_QUIT);
  672. end;
  673. end;
  674. function tsGetError: tsEnum;
  675. begin
  676. Result := gError;
  677. gError := TS_NO_ERROR;
  678. end;
  679. function tsGetErrorFunction: tsEnum;
  680. begin
  681. Result := gErrorFunction;
  682. gErrorFunction := TS_NO_FUNC;
  683. end;
  684. function tsGetErrorStringA(ErrorCode: tsEnum): pAnsiChar;
  685. begin
  686. case ErrorCode of
  687. TS_NO_ERROR:
  688. Result := pAnsiChar(TS_NO_ERROR_STR);
  689. TS_ERROR:
  690. Result := pAnsiChar(TS_ERROR_STR);
  691. TS_NO_ACTIVE_CONTEXT:
  692. Result := pAnsiChar(TS_NO_ACTIVE_CONTEXT_STR);
  693. TS_NO_ACTIVE_RENDERER:
  694. Result := pAnsiChar(TS_NO_ACTIVE_RENDERER_STR);
  695. TS_NO_ACTIVE_FONT:
  696. Result := pAnsiChar(TS_NO_ACTIVE_FONT_STR);
  697. TS_INVALID_OPERATION:
  698. Result := pAnsiChar(TS_INVALID_OPERATION_STR);
  699. TS_INVALID_ENUM:
  700. Result := pAnsiChar(TS_INVALID_ENUM_STR);
  701. TS_INVALID_VALUE:
  702. Result := pAnsiChar(TS_INVALID_VALUE_STR);
  703. TS_OUT_OF_MEMORY:
  704. Result := pAnsiChar(TS_OUT_OF_MEMORY_STR);
  705. TS_NOT_INITIALIZED:
  706. Result := pAnsiChar(TS_NOT_INITIALIZED_STR);
  707. else
  708. if ErrorCode and TS_ERROR = TS_ERROR then
  709. Result := pAnsiChar(TS_ERROR_STR)
  710. else
  711. Result := pAnsiChar(TS_NO_ERROR);
  712. end;
  713. end;
  714. procedure SetCodePage(CodePage: tsEnum; CodePageFunc: TtsAnsiToWideCharFunc; pCodePage: Pointer);
  715. var
  716. Context: TtsContext;
  717. begin
  718. Context := gContext;
  719. Context.gCodePage := CodePage;
  720. Context.gCodePageFunc := CodePageFunc;
  721. Context.gCodePagePtr := pCodePage;
  722. end;
  723. procedure tsSetParameteri(ParamName: tsEnum; Param: tsInt);
  724. begin
  725. tsSetParameteriv(ParamName, @Param);
  726. end;
  727. procedure tsSetParameteriv(ParamName: tsEnum; pParam: ptsInt);
  728. var
  729. Context: TtsContext;
  730. begin
  731. Context := gContext;
  732. if Context <> nil then begin
  733. if pParam <> nil then begin
  734. case ParamName of
  735. // font
  736. TS_FONT_ASCENT:
  737. if not Context.IsLocked then begin
  738. if Context.ActiveFont <> nil then begin
  739. Context.ActiveFont.Ascent := pParam^;
  740. end else
  741. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_SET_PARAMETER);
  742. end else
  743. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  744. TS_FONT_DESCENT:
  745. if not Context.IsLocked then begin
  746. if Context.ActiveFont <> nil then begin
  747. Context.ActiveFont.Descent := pParam^;
  748. end else
  749. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_SET_PARAMETER);
  750. end else
  751. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  752. TS_FONT_EXTERNAL_LEADING:
  753. if not Context.IsLocked then begin
  754. if Context.ActiveFont <> nil then begin
  755. Context.ActiveFont.ExternalLeading := pParam^;
  756. end else
  757. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_SET_PARAMETER);
  758. end else
  759. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  760. TS_FONT_BASELINE_OFFSET:
  761. if not Context.IsLocked then begin
  762. if Context.ActiveFont <> nil then begin
  763. Context.ActiveFont.BaselineOffset := pParam^;
  764. end else
  765. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_SET_PARAMETER);
  766. end else
  767. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  768. TS_FONT_CHAR_SPACING:
  769. if not Context.IsLocked then begin
  770. if Context.ActiveFont <> nil then begin
  771. Context.ActiveFont.CharSpacing := pParam^;
  772. end else
  773. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_SET_PARAMETER);
  774. end else
  775. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  776. TS_FONT_LINE_SPACING:
  777. if not Context.IsLocked then begin
  778. if Context.ActiveFont <> nil then begin
  779. Context.ActiveFont.LineSpacing := pParam^;
  780. end else
  781. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_SET_PARAMETER);
  782. end else
  783. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  784. TS_FONT_UNDERLINE_POSITION:
  785. if not Context.IsLocked then begin
  786. if Context.ActiveFont <> nil then begin
  787. Context.ActiveFont.UnderlinePosition := pParam^;
  788. end else
  789. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_SET_PARAMETER);
  790. end else
  791. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  792. TS_FONT_UNDERLINE_SIZE:
  793. if not Context.IsLocked then begin
  794. if Context.ActiveFont <> nil then begin
  795. Context.ActiveFont.UnderlineSize := pParam^;
  796. end else
  797. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_SET_PARAMETER);
  798. end else
  799. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  800. TS_FONT_STRIKEOUT_POSITION:
  801. if not Context.IsLocked then begin
  802. if Context.ActiveFont <> nil then begin
  803. Context.ActiveFont.StrikeoutPosition := pParam^;
  804. end else
  805. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_SET_PARAMETER);
  806. end else
  807. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  808. TS_FONT_STRIKEOUT_SIZE:
  809. if not Context.IsLocked then begin
  810. if Context.ActiveFont <> nil then begin
  811. Context.ActiveFont.StrikeoutSize := pParam^;
  812. end else
  813. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_SET_PARAMETER);
  814. end else
  815. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  816. // globals
  817. TS_GLOBAL_ANTIALIASING:
  818. case pParam^ of
  819. TS_ANTIALIASING_NONE:
  820. Context.gGlobalAntiAliasing := TS_ANTIALIASING_NONE;
  821. TS_ANTIALIASING_NORMAL:
  822. Context.gGlobalAntiAliasing := TS_ANTIALIASING_NORMAL;
  823. else
  824. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  825. end;
  826. TS_GLOBAL_FORMAT:
  827. case pParam^ of
  828. TS_FORMAT_RGBA8:
  829. Context.gGlobalFormat := TS_FORMAT_RGBA8;
  830. else
  831. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  832. end;
  833. // creator
  834. TS_CREATOR:
  835. case pParam^ of
  836. TS_CREATOR_SDL:
  837. Context.gCreator := TS_CREATOR_SDL;
  838. TS_CREATOR_GDI:
  839. Context.gCreator := TS_CREATOR_GDI;
  840. TS_CREATOR_GDI_FACENAME:
  841. Context.gCreator := TS_CREATOR_GDI_FACENAME;
  842. TS_CREATOR_GDI_STREAM:
  843. Context.gCreator := TS_CREATOR_GDI_STREAM;
  844. else
  845. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  846. end;
  847. TS_CREATOR_CREATE_CHARS:
  848. if Context.ActiveFont <> nil then begin
  849. if Context.ActiveFont is TtsFontCreator then begin
  850. case pParam^ of
  851. TS_TRUE:
  852. TtsFontCreator(Context.ActiveFont).CreateChars := True;
  853. TS_FALSE:
  854. TtsFontCreator(Context.ActiveFont).CreateChars := False;
  855. else
  856. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  857. end;
  858. end else
  859. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  860. end else
  861. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_SET_PARAMETER);
  862. TS_CREATOR_ADD_RESIZING_BORDER:
  863. if Context.ActiveFont <> nil then begin
  864. if Context.ActiveFont is TtsFontCreator then begin
  865. case pParam^ of
  866. TS_TRUE:
  867. TtsFontCreator(Context.ActiveFont).AddResizingBorder := True;
  868. TS_FALSE:
  869. TtsFontCreator(Context.ActiveFont).AddResizingBorder := False;
  870. else
  871. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  872. end;
  873. end else
  874. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  875. end else
  876. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_SET_PARAMETER);
  877. // renderer
  878. TS_RENDERER:
  879. if not Context.IsLocked then begin
  880. if tsGetParameteri(TS_RENDERER) <> pParam^ then begin
  881. if (Context.FontCount = 0) and (Context.ImageCount = 0) then begin
  882. case pParam^ of
  883. TS_RENDERER_NULL:
  884. begin
  885. if Context.Renderer <> nil then
  886. Context.Renderer.Free;
  887. Context.Renderer := TtsRendererNULL.Create(Context);
  888. end;
  889. TS_RENDERER_OPENGL:
  890. begin
  891. if OpenGL_initialized then begin
  892. if Context.Renderer <> nil then
  893. Context.Renderer.Free;
  894. Context.Renderer := TtsRendererOpenGL.Create(Context);
  895. end else
  896. SetError(TS_NOT_INITIALIZED, TS_FUNC_SET_PARAMETER);
  897. end
  898. else
  899. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  900. end;
  901. end else
  902. // Renderer only can set if no Images/Fonts exist
  903. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  904. end;
  905. end else
  906. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  907. // opengl texture size
  908. TS_RENDERER_OPENGL_TEXTURE_SIZE:
  909. if Context.Renderer <> nil then begin
  910. if Context.Renderer is TtsRendererOpenGL then begin
  911. case pParam^ of
  912. TS_RENDERER_OPENGL_TEXTURE_SIZE_128:
  913. TtsRendererOpenGL(Context.Renderer).TextureSize := 128;
  914. TS_RENDERER_OPENGL_TEXTURE_SIZE_256:
  915. TtsRendererOpenGL(Context.Renderer).TextureSize := 256;
  916. TS_RENDERER_OPENGL_TEXTURE_SIZE_512:
  917. TtsRendererOpenGL(Context.Renderer).TextureSize := 512;
  918. TS_RENDERER_OPENGL_TEXTURE_SIZE_1024:
  919. TtsRendererOpenGL(Context.Renderer).TextureSize := 1024;
  920. else
  921. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  922. end;
  923. end else
  924. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  925. end else
  926. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_SET_PARAMETER);
  927. // null renderer saves char images
  928. TS_RENDERER_NULL_SAVE_IMAGES:
  929. if Context.Renderer <> nil then begin
  930. if Context.Renderer is TtsRendererNULL then begin
  931. case pParam^ of
  932. TS_FALSE:
  933. Context.Renderer.SaveImages := False;
  934. TS_TRUE:
  935. Context.Renderer.SaveImages := True;
  936. else
  937. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  938. end;
  939. end else
  940. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  941. end else
  942. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_SET_PARAMETER);
  943. // Align
  944. TS_ALIGN:
  945. if not Context.IsLocked then begin
  946. case pParam^ of
  947. TS_ALIGN_LEFT:
  948. Context.gAlign := TS_ALIGN_LEFT;
  949. TS_ALIGN_CENTER:
  950. Context.gAlign := TS_ALIGN_CENTER;
  951. TS_ALIGN_RIGHT:
  952. Context.gAlign := TS_ALIGN_RIGHT;
  953. TS_ALIGN_BLOCK:
  954. Context.gAlign := TS_ALIGN_BLOCK;
  955. else
  956. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  957. end;
  958. end else
  959. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  960. // Vertical Align
  961. TS_VALIGN:
  962. if not Context.IsLocked then begin
  963. case pParam^ of
  964. TS_VALIGN_TOP:
  965. Context.gVAlign := TS_VALIGN_TOP;
  966. TS_VALIGN_CENTER:
  967. Context.gVAlign := TS_VALIGN_CENTER;
  968. TS_VALIGN_BOTTOM:
  969. Context.gVAlign := TS_VALIGN_BOTTOM;
  970. else
  971. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  972. end;
  973. end else
  974. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  975. // Clipping
  976. TS_CLIP:
  977. if not Context.IsLocked then begin
  978. case pParam^ of
  979. TS_CLIP_COMPLETE:
  980. Context.gClip := TS_CLIP_COMPLETE;
  981. TS_CLIP_BORDER:
  982. Context.gClip := TS_CLIP_BORDER;
  983. else
  984. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  985. end;
  986. end else
  987. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  988. // block offset
  989. TS_BLOCK_OFFSET_X:
  990. if not Context.IsLocked then begin
  991. Context.gBlockOffsetX := pParam^;
  992. end else
  993. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  994. TS_BLOCK_OFFSET_Y:
  995. if not Context.IsLocked then begin
  996. Context.gBlockOffsetY := pParam^;
  997. end else
  998. SetError(TS_INVALID_OPERATION, TS_FUNC_SET_PARAMETER);
  999. // single line
  1000. TS_SINGLE_LINE:
  1001. case pParam^ of
  1002. TS_SINGLE_LINE_TOP:
  1003. Context.gSingleLine := TS_SINGLE_LINE_TOP;
  1004. TS_SINGLE_LINE_BASELINE:
  1005. Context.gSingleLine := TS_SINGLE_LINE_BASELINE;
  1006. else
  1007. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  1008. end;
  1009. {
  1010. TS_TAB:
  1011. case pParam^ of
  1012. TS_TAB_FIXED:
  1013. gTab := TS_TAB_FIXED;
  1014. TS_TAB_ABSOLUTE:
  1015. gTab := TS_TAB_ABSOLUTE;
  1016. else
  1017. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  1018. end;
  1019. TS_TAB_FIXED_WIDTH:
  1020. gTabWidth := pParam^;
  1021. }
  1022. // image modes
  1023. TS_IMAGE_RED_MODE:
  1024. case pParam^ of
  1025. TS_MODE_REPLACE:
  1026. Context.gImageMode[tsModeRed] := TS_MODE_REPLACE;
  1027. TS_MODE_MODULATE:
  1028. Context.gImageMode[tsModeRed] := TS_MODE_MODULATE;
  1029. else
  1030. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  1031. end;
  1032. TS_IMAGE_GREEN_MODE:
  1033. case pParam^ of
  1034. TS_MODE_REPLACE:
  1035. Context.gImageMode[tsModeGreen] := TS_MODE_REPLACE;
  1036. TS_MODE_MODULATE:
  1037. Context.gImageMode[tsModeGreen] := TS_MODE_MODULATE;
  1038. else
  1039. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  1040. end;
  1041. TS_IMAGE_BLUE_MODE:
  1042. case pParam^ of
  1043. TS_MODE_REPLACE:
  1044. Context.gImageMode[tsModeBlue] := TS_MODE_REPLACE;
  1045. TS_MODE_MODULATE:
  1046. Context.gImageMode[tsModeBlue] := TS_MODE_MODULATE;
  1047. else
  1048. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  1049. end;
  1050. TS_IMAGE_ALPHA_MODE:
  1051. case pParam^ of
  1052. TS_MODE_REPLACE:
  1053. Context.gImageMode[tsModeAlpha] := TS_MODE_REPLACE;
  1054. TS_MODE_MODULATE:
  1055. Context.gImageMode[tsModeAlpha] := TS_MODE_MODULATE;
  1056. else
  1057. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  1058. end;
  1059. TS_IMAGE_LUMINANCE_MODE:
  1060. case pParam^ of
  1061. TS_MODE_REPLACE:
  1062. Context.gImageMode[tsModeLuminance] := TS_MODE_REPLACE;
  1063. TS_MODE_MODULATE:
  1064. Context.gImageMode[tsModeLuminance] := TS_MODE_MODULATE;
  1065. else
  1066. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  1067. end;
  1068. TS_IMAGE_LIBRARY:
  1069. case pParam^ of
  1070. TS_IMAGE_LIBRARY_SDL:
  1071. Context.gImageLibrary := TS_IMAGE_LIBRARY_SDL;
  1072. else
  1073. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  1074. end;
  1075. // code pages
  1076. TS_EMPTY_CP_ENTRY:
  1077. case pParam^ of
  1078. TS_EMPTY_CP_ENTRY_IGNORE:
  1079. Context.gEmptyCodePageEntry := TS_EMPTY_CP_ENTRY_IGNORE;
  1080. TS_EMPTY_CP_ENTRY_USE_DEFAULT:
  1081. Context.gEmptyCodePageEntry := TS_EMPTY_CP_ENTRY_USE_DEFAULT;
  1082. else
  1083. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  1084. end;
  1085. TS_CODEPAGE:
  1086. case pParam^ of
  1087. TS_CODEPAGE_UTF8:
  1088. SetCodePage(TS_CODEPAGE_UTF8, nil, nil);
  1089. TS_CODEPAGE_8859_1:
  1090. SetCodePage(TS_CODEPAGE_8859_1, nil, nil);
  1091. TS_CODEPAGE_8859_2:
  1092. SetCodePage(TS_CODEPAGE_8859_2, tsAnsiSBCDToWide, @CP_8859_2);
  1093. TS_CODEPAGE_8859_3:
  1094. SetCodePage(TS_CODEPAGE_8859_3, tsAnsiSBCDToWide, @CP_8859_3);
  1095. TS_CODEPAGE_8859_4:
  1096. SetCodePage(TS_CODEPAGE_8859_4, tsAnsiSBCDToWide, @CP_8859_4);
  1097. TS_CODEPAGE_8859_5:
  1098. SetCodePage(TS_CODEPAGE_8859_5, tsAnsiSBCDToWide, @CP_8859_5);
  1099. TS_CODEPAGE_8859_6:
  1100. SetCodePage(TS_CODEPAGE_8859_6, tsAnsiSBCDToWide, @CP_8859_6);
  1101. TS_CODEPAGE_8859_7:
  1102. SetCodePage(TS_CODEPAGE_8859_7, tsAnsiSBCDToWide, @CP_8859_7);
  1103. TS_CODEPAGE_8859_8:
  1104. SetCodePage(TS_CODEPAGE_8859_8, tsAnsiSBCDToWide, @CP_8859_8);
  1105. TS_CODEPAGE_8859_9:
  1106. SetCodePage(TS_CODEPAGE_8859_9, tsAnsiSBCDToWide, @CP_8859_9);
  1107. TS_CODEPAGE_8859_10:
  1108. SetCodePage(TS_CODEPAGE_8859_10, tsAnsiSBCDToWide, @CP_8859_10);
  1109. TS_CODEPAGE_8859_11:
  1110. SetCodePage(TS_CODEPAGE_8859_11, tsAnsiSBCDToWide, @CP_8859_11);
  1111. TS_CODEPAGE_8859_13:
  1112. SetCodePage(TS_CODEPAGE_8859_13, tsAnsiSBCDToWide, @CP_8859_13);
  1113. TS_CODEPAGE_8859_14:
  1114. SetCodePage(TS_CODEPAGE_8859_14, tsAnsiSBCDToWide, @CP_8859_14);
  1115. TS_CODEPAGE_8859_15:
  1116. SetCodePage(TS_CODEPAGE_8859_15, tsAnsiSBCDToWide, @CP_8859_15);
  1117. TS_CODEPAGE_8859_16:
  1118. SetCodePage(TS_CODEPAGE_8859_16, tsAnsiSBCDToWide, @CP_8859_16);
  1119. TS_CODEPAGE_037:
  1120. SetCodePage(TS_CODEPAGE_037, tsAnsiSBCDToWide, @CP_037);
  1121. TS_CODEPAGE_437:
  1122. SetCodePage(TS_CODEPAGE_437, tsAnsiSBCDToWide, @CP_437);
  1123. TS_CODEPAGE_500:
  1124. SetCodePage(TS_CODEPAGE_500, tsAnsiSBCDToWide, @CP_500);
  1125. TS_CODEPAGE_737:
  1126. SetCodePage(TS_CODEPAGE_737, tsAnsiSBCDToWide, @CP_737);
  1127. TS_CODEPAGE_775:
  1128. SetCodePage(TS_CODEPAGE_775, tsAnsiSBCDToWide, @CP_775);
  1129. TS_CODEPAGE_850:
  1130. SetCodePage(TS_CODEPAGE_850, tsAnsiSBCDToWide, @CP_850);
  1131. TS_CODEPAGE_852:
  1132. SetCodePage(TS_CODEPAGE_852, tsAnsiSBCDToWide, @CP_852);
  1133. TS_CODEPAGE_855:
  1134. SetCodePage(TS_CODEPAGE_855, tsAnsiSBCDToWide, @CP_855);
  1135. TS_CODEPAGE_857:
  1136. SetCodePage(TS_CODEPAGE_857, tsAnsiSBCDToWide, @CP_857);
  1137. TS_CODEPAGE_860:
  1138. SetCodePage(TS_CODEPAGE_860, tsAnsiSBCDToWide, @CP_860);
  1139. TS_CODEPAGE_861:
  1140. SetCodePage(TS_CODEPAGE_861, tsAnsiSBCDToWide, @CP_861);
  1141. TS_CODEPAGE_862:
  1142. SetCodePage(TS_CODEPAGE_862, tsAnsiSBCDToWide, @CP_862);
  1143. TS_CODEPAGE_863:
  1144. SetCodePage(TS_CODEPAGE_863, tsAnsiSBCDToWide, @CP_863);
  1145. TS_CODEPAGE_864:
  1146. SetCodePage(TS_CODEPAGE_864, tsAnsiSBCDToWide, @CP_864);
  1147. TS_CODEPAGE_865:
  1148. SetCodePage(TS_CODEPAGE_865, tsAnsiSBCDToWide, @CP_865);
  1149. TS_CODEPAGE_866:
  1150. SetCodePage(TS_CODEPAGE_866, tsAnsiSBCDToWide, @CP_866);
  1151. TS_CODEPAGE_869:
  1152. SetCodePage(TS_CODEPAGE_869, tsAnsiSBCDToWide, @CP_869);
  1153. TS_CODEPAGE_874:
  1154. SetCodePage(TS_CODEPAGE_874, tsAnsiSBCDToWide, @CP_874);
  1155. TS_CODEPAGE_875:
  1156. SetCodePage(TS_CODEPAGE_875, tsAnsiSBCDToWide, @CP_875);
  1157. TS_CODEPAGE_1026:
  1158. SetCodePage(TS_CODEPAGE_1026, tsAnsiSBCDToWide, @CP_1026);
  1159. TS_CODEPAGE_1250:
  1160. SetCodePage(TS_CODEPAGE_1250, tsAnsiSBCDToWide, @CP_1250);
  1161. TS_CODEPAGE_1251:
  1162. SetCodePage(TS_CODEPAGE_1251, tsAnsiSBCDToWide, @CP_1251);
  1163. TS_CODEPAGE_1252:
  1164. SetCodePage(TS_CODEPAGE_1252, tsAnsiSBCDToWide, @CP_1252);
  1165. TS_CODEPAGE_1253:
  1166. SetCodePage(TS_CODEPAGE_1253, tsAnsiSBCDToWide, @CP_1253);
  1167. TS_CODEPAGE_1254:
  1168. SetCodePage(TS_CODEPAGE_1254, tsAnsiSBCDToWide, @CP_1254);
  1169. TS_CODEPAGE_1255:
  1170. SetCodePage(TS_CODEPAGE_1255, tsAnsiSBCDToWide, @CP_1255);
  1171. TS_CODEPAGE_1256:
  1172. SetCodePage(TS_CODEPAGE_1256, tsAnsiSBCDToWide, @CP_1256);
  1173. TS_CODEPAGE_1257:
  1174. SetCodePage(TS_CODEPAGE_1257, tsAnsiSBCDToWide, @CP_1257);
  1175. TS_CODEPAGE_1258:
  1176. SetCodePage(TS_CODEPAGE_1258, tsAnsiSBCDToWide, @CP_1258);
  1177. else
  1178. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  1179. end;
  1180. TS_DEBUG_DRAW_CHAR_RECTS:
  1181. case pParam^ of
  1182. TS_TRUE:
  1183. Context.gDebugDrawCharRects := True;
  1184. TS_FALSE:
  1185. Context.gDebugDrawCharRects := False;
  1186. else
  1187. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  1188. end;
  1189. else
  1190. SetError(TS_INVALID_ENUM, TS_FUNC_SET_PARAMETER);
  1191. end;
  1192. end else
  1193. SetError(TS_INVALID_VALUE, TS_FUNC_SET_PARAMETER);
  1194. end else
  1195. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_SET_PARAMETER);
  1196. end;
  1197. function tsGetParameteri(ParamName: tsEnum): tsInt;
  1198. begin
  1199. tsGetParameteriv(ParamName, @Result);
  1200. end;
  1201. procedure tsGetParameteriv(ParamName: tsEnum; pParam: ptsInt);
  1202. var
  1203. Context: TtsContext;
  1204. begin
  1205. Context := gContext;
  1206. if pParam <> nil then begin
  1207. pParam^ := 0;
  1208. case ParamName of
  1209. TS_INFO_MAYOR_VERSION:
  1210. pParam^ := TS_MAYOR_VERSION;
  1211. TS_INFO_MINOR_VERSION:
  1212. pParam^ := TS_MINOR_VERSION;
  1213. TS_INFO_BUILD_NUMBER:
  1214. pParam^ := TS_BUILD_NUMBER;
  1215. TS_CONTEXT_BINDING:
  1216. if Context <> nil then begin
  1217. pParam^ := Context.ContextID;
  1218. end;
  1219. // font
  1220. TS_FONT_STYLE:
  1221. if Context <> nil then begin
  1222. if Context.ActiveFont <> nil then begin
  1223. pParam^ := TS_STYLE_NORMAL;
  1224. with Context.ActiveFont do begin
  1225. if tsStyleBold in Style then
  1226. pParam^ := pParam^ or TS_STYLE_BOLD;
  1227. if tsStyleItalic in Style then
  1228. pParam^ := pParam^ or TS_STYLE_ITALIC;
  1229. if tsStyleUnderline in Style then
  1230. pParam^ := pParam^ or TS_STYLE_UNDERLINE;
  1231. if tsStyleStrikeout in Style then
  1232. pParam^ := pParam^ or TS_STYLE_STRIKEOUT;
  1233. end;
  1234. end else
  1235. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1236. end else
  1237. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1238. TS_FONT_FILE_STYLE:
  1239. if Context <> nil then begin
  1240. if Context.ActiveFont <> nil then begin
  1241. pParam^ := Context.ActiveFont.FontFileStyle;
  1242. end else
  1243. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1244. end else
  1245. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1246. TS_FONT_FIXED_WIDTH:
  1247. if Context <> nil then begin
  1248. if Context.ActiveFont <> nil then begin
  1249. if Context.ActiveFont.FixedWidth then
  1250. pParam^ := TS_TRUE
  1251. else
  1252. pParam^ := TS_FALSE;
  1253. end else
  1254. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1255. end else
  1256. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1257. TS_FONT_ASCENT:
  1258. if Context <> nil then begin
  1259. if Context.ActiveFont <> nil then begin
  1260. pParam^ := Context.ActiveFont.Ascent;
  1261. end else
  1262. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1263. end else
  1264. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1265. TS_FONT_DESCENT:
  1266. if Context <> nil then begin
  1267. if Context.ActiveFont <> nil then begin
  1268. pParam^ := Context.ActiveFont.Descent;
  1269. end else
  1270. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1271. end else
  1272. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1273. TS_FONT_EXTERNAL_LEADING:
  1274. if Context <> nil then begin
  1275. if Context.ActiveFont <> nil then begin
  1276. pParam^ := Context.ActiveFont.ExternalLeading;
  1277. end else
  1278. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1279. end else
  1280. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1281. TS_FONT_BASELINE_OFFSET:
  1282. if Context <> nil then begin
  1283. if Context.ActiveFont <> nil then begin
  1284. pParam^ := Context.ActiveFont.BaselineOffset;
  1285. end else
  1286. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1287. end else
  1288. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1289. TS_FONT_LINESKIP:
  1290. if Context <> nil then begin
  1291. if Context.ActiveFont <> nil then begin
  1292. with Context.ActiveFont do
  1293. pParam^ := Ascent + Descent + ExternalLeading;
  1294. end else
  1295. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1296. end else
  1297. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1298. TS_FONT_ANTIALIASING:
  1299. if Context <> nil then begin
  1300. if Context.ActiveFont <> nil then begin
  1301. case Context.ActiveFont.AntiAliasing of
  1302. tsAANone:
  1303. pParam^ := TS_ANTIALIASING_NONE;
  1304. tsAANormal:
  1305. pParam^ := TS_ANTIALIASING_NORMAL;
  1306. end;
  1307. end else
  1308. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1309. end else
  1310. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1311. TS_FONT_FORMAT:
  1312. if Context <> nil then begin
  1313. if Context.ActiveFont <> nil then begin
  1314. case Context.ActiveFont.Format of
  1315. tsFormatEmpty:
  1316. pParam^ := TS_FORMAT_EMPTY;
  1317. tsFormatRGBA8:
  1318. pParam^ := TS_FORMAT_RGBA8;
  1319. end;
  1320. end else
  1321. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1322. end else
  1323. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1324. TS_FONT_CHAR_SPACING:
  1325. if Context <> nil then begin
  1326. if Context.ActiveFont <> nil then begin
  1327. pParam^ := Context.ActiveFont.CharSpacing;
  1328. end else
  1329. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1330. end else
  1331. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1332. TS_FONT_LINE_SPACING:
  1333. if Context <> nil then begin
  1334. if Context.ActiveFont <> nil then begin
  1335. pParam^ := Context.ActiveFont.LineSpacing;
  1336. end else
  1337. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1338. end else
  1339. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1340. TS_FONT_UNDERLINE_POSITION:
  1341. if Context <> nil then begin
  1342. if Context.ActiveFont <> nil then begin
  1343. pParam^ := Context.ActiveFont.UnderlinePosition;
  1344. end else
  1345. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1346. end else
  1347. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1348. TS_FONT_UNDERLINE_SIZE:
  1349. if Context <> nil then begin
  1350. if Context.ActiveFont <> nil then begin
  1351. pParam^ := Context.ActiveFont.UnderlineSize;
  1352. end else
  1353. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1354. end else
  1355. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1356. TS_FONT_STRIKEOUT_POSITION:
  1357. if Context <> nil then begin
  1358. if Context.ActiveFont <> nil then begin
  1359. pParam^ := Context.ActiveFont.StrikeoutPosition;
  1360. end else
  1361. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1362. end else
  1363. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1364. TS_FONT_STRIKEOUT_SIZE:
  1365. if Context <> nil then begin
  1366. if Context.ActiveFont <> nil then begin
  1367. pParam^ := Context.ActiveFont.StrikeoutSize;
  1368. end else
  1369. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1370. end else
  1371. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1372. // globals
  1373. TS_GLOBAL_ANTIALIASING:
  1374. if Context <> nil then begin
  1375. pParam^ := Context.gGlobalAntiAliasing;
  1376. end else
  1377. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1378. TS_GLOBAL_FORMAT:
  1379. if Context <> nil then begin
  1380. pParam^ := Context.gGlobalFormat;
  1381. end else
  1382. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1383. // creator
  1384. TS_CREATOR:
  1385. if Context <> nil then begin
  1386. pParam^ := Context.gCreator;
  1387. end else
  1388. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1389. TS_CREATOR_CREATE_CHARS:
  1390. if Context <> nil then begin
  1391. if Context.ActiveFont <> nil then begin
  1392. if Context.ActiveFont is TtsFontCreator then begin
  1393. if TtsFontCreator(Context.ActiveFont).CreateChars then
  1394. pParam^ := TS_TRUE
  1395. else
  1396. pParam^ := TS_FALSE;
  1397. end else
  1398. SetError(TS_INVALID_OPERATION, TS_FUNC_GET_PARAMETER);
  1399. end else
  1400. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1401. end else
  1402. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1403. TS_CREATOR_ADD_RESIZING_BORDER:
  1404. if Context <> nil then begin
  1405. if Context.ActiveFont <> nil then begin
  1406. if Context.ActiveFont is TtsFontCreator then begin
  1407. if TtsFontCreator(Context.ActiveFont).AddResizingBorder then
  1408. pParam^ := TS_TRUE
  1409. else
  1410. pParam^ := TS_FALSE;
  1411. end else
  1412. SetError(TS_INVALID_OPERATION, TS_FUNC_GET_PARAMETER);
  1413. end else
  1414. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_PARAMETER);
  1415. end else
  1416. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1417. // Renderer
  1418. TS_RENDERER:
  1419. if Context <> nil then begin
  1420. if Context.Renderer <> nil then begin
  1421. if Context.Renderer is TtsRendererNULL then begin
  1422. pParam^ := TS_RENDERER_NULL;
  1423. end else
  1424. if Context.Renderer is TtsRendererOpenGL then begin
  1425. pParam^ := TS_RENDERER_OPENGL;
  1426. end else
  1427. SetError(TS_ERROR, TS_FUNC_GET_PARAMETER);
  1428. end;
  1429. end else
  1430. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1431. // opengl texture size
  1432. TS_RENDERER_OPENGL_TEXTURE_SIZE:
  1433. if Context <> nil then begin
  1434. if Context.Renderer <> nil then begin
  1435. if Context.Renderer is TtsRendererOpenGL then begin
  1436. pParam^ := TtsRendererOpenGL(Context.Renderer).TextureSize;
  1437. end else
  1438. SetError(TS_INVALID_OPERATION, TS_FUNC_GET_PARAMETER);
  1439. end else
  1440. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_GET_PARAMETER);
  1441. end else
  1442. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1443. // null renderer must save images
  1444. TS_RENDERER_NULL_SAVE_IMAGES:
  1445. if Context <> nil then begin
  1446. if Context.Renderer <> nil then begin
  1447. if Context.Renderer is TtsRendererNULL then begin
  1448. case Context.Renderer.SaveImages of
  1449. True:
  1450. pParam^ := TS_TRUE;
  1451. False:
  1452. pParam^ := TS_FALSE;
  1453. end;
  1454. end else
  1455. SetError(TS_INVALID_OPERATION, TS_FUNC_GET_PARAMETER);
  1456. end else
  1457. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_GET_PARAMETER);
  1458. end else
  1459. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1460. TS_ALIGN:
  1461. if Context <> nil then begin
  1462. pParam^ := Context.gAlign;
  1463. end else
  1464. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1465. TS_VALIGN:
  1466. if Context <> nil then begin
  1467. pParam^ := Context.gVAlign;
  1468. end else
  1469. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1470. TS_CLIP:
  1471. if Context <> nil then begin
  1472. pParam^ := Context.gClip;
  1473. end else
  1474. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1475. TS_BLOCK_OFFSET_X:
  1476. if Context <> nil then begin
  1477. pParam^ := Context.gBlockOffsetX;
  1478. end else
  1479. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1480. TS_BLOCK_OFFSET_Y:
  1481. if Context <> nil then begin
  1482. pParam^ := Context.gBlockOffsetY;
  1483. end else
  1484. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1485. {
  1486. TS_TAB:
  1487. pParam^ := gTab;
  1488. TS_TAB_FIXED_WIDTH:
  1489. pParam^ := gTabWidth;
  1490. }
  1491. TS_SINGLE_LINE:
  1492. if Context <> nil then begin
  1493. pParam^ := Context.gSingleLine;
  1494. end else
  1495. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1496. TS_IMAGE_RED_MODE:
  1497. if Context <> nil then begin
  1498. pParam^ := Context.gImageMode[tsModeRed];
  1499. end else
  1500. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1501. TS_IMAGE_GREEN_MODE:
  1502. if Context <> nil then begin
  1503. pParam^ := Context.gImageMode[tsModeGreen];
  1504. end else
  1505. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1506. TS_IMAGE_BLUE_MODE:
  1507. if Context <> nil then begin
  1508. pParam^ := Context.gImageMode[tsModeBlue];
  1509. end else
  1510. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1511. TS_IMAGE_ALPHA_MODE:
  1512. if Context <> nil then begin
  1513. pParam^ := Context.gImageMode[tsModeAlpha];
  1514. end else
  1515. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1516. TS_IMAGE_LUMINANCE_MODE:
  1517. if Context <> nil then begin
  1518. pParam^ := Context.gImageMode[tsModeLuminance];
  1519. end else
  1520. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1521. TS_IMAGE_LIBRARY:
  1522. if Context <> nil then begin
  1523. pParam^ := Context.gImageLibrary;
  1524. end else
  1525. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1526. TS_EMPTY_CP_ENTRY:
  1527. if Context <> nil then begin
  1528. pParam^ := Context.gEmptyCodePageEntry;
  1529. end else
  1530. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1531. TS_CODEPAGE:
  1532. if Context <> nil then begin
  1533. pParam^ := Context.gCodePage;
  1534. end else
  1535. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1536. TS_DEBUG_DRAW_CHAR_RECTS:
  1537. if Context <> nil then begin
  1538. case Context.gDebugDrawCharRects of
  1539. True:
  1540. pParam^ := TS_TRUE;
  1541. False:
  1542. pParam^ := TS_FALSE;
  1543. end;
  1544. end else
  1545. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1546. TS_FONT_BINDING:
  1547. if Context <> nil then begin
  1548. if Context.Renderer <> nil then begin
  1549. pParam^ := Context.Renderer.ActiveFontID;
  1550. end
  1551. else SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_GET_PARAMETER);
  1552. end else
  1553. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_PARAMETER);
  1554. else
  1555. SetError(TS_INVALID_ENUM, TS_FUNC_GET_PARAMETER);
  1556. end;
  1557. end else
  1558. SetError(TS_INVALID_VALUE, TS_FUNC_GET_PARAMETER);
  1559. end;
  1560. function tsGetStringA(ParamName: tsEnum): pAnsiChar;
  1561. var
  1562. Context: TtsContext;
  1563. begin
  1564. Result := nil;
  1565. Context := gContext;
  1566. case ParamName of
  1567. TS_INFO_VERSION:
  1568. if TS_VERSION_STR <> '' then
  1569. Result := pAnsiChar(TS_VERSION_STR);
  1570. TS_INFO_COPYRIGHT:
  1571. if TS_COPYRIGHT_STR <> '' then
  1572. Result := pAnsiChar(TS_COPYRIGHT_STR);
  1573. TS_FONT_COPYRIGHT:
  1574. if Context <> nil then begin
  1575. if Context.ActiveFont <> nil then begin
  1576. if Context.ActiveFont.Copyright <> '' then
  1577. Result := pAnsiChar(Context.ActiveFont.Copyright);
  1578. end else
  1579. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_STRING);
  1580. end else
  1581. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_STRING);
  1582. TS_FONT_FACE_NAME:
  1583. if Context <> nil then begin
  1584. if Context.ActiveFont <> nil then begin
  1585. if Context.ActiveFont.FaceName <> '' then
  1586. Result := pAnsiChar(Context.ActiveFont.FaceName);
  1587. end else
  1588. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_STRING);
  1589. end else
  1590. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_STRING);
  1591. TS_FONT_STYLE_NAME:
  1592. if Context <> nil then begin
  1593. if Context.ActiveFont <> nil then begin
  1594. if Context.ActiveFont.StyleName <> '' then
  1595. Result := pAnsiChar(Context.ActiveFont.StyleName);
  1596. end else
  1597. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_STRING);
  1598. end else
  1599. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_STRING);
  1600. TS_FONT_FULL_NAME:
  1601. if Context <> nil then begin
  1602. if Context.ActiveFont <> nil then begin
  1603. if Context.ActiveFont.FullName <> '' then
  1604. Result := pAnsiChar(Context.ActiveFont.FullName);
  1605. end else
  1606. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_GET_STRING);
  1607. end else
  1608. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_GET_STRING);
  1609. else
  1610. SetError(TS_INVALID_ENUM, TS_FUNC_GET_STRING);
  1611. end;
  1612. end;
  1613. // *** Context functions ***
  1614. procedure tsContextCreate(pContextID: ptsContextID);
  1615. begin
  1616. if TextSuite_initialized then begin
  1617. if pContextID <> nil then begin
  1618. try
  1619. gCriticalSection.Enter;
  1620. try
  1621. // unbound current context
  1622. if gContext <> nil then begin
  1623. gContext.gBoundThreadID := 0;
  1624. gContext := nil;
  1625. end;
  1626. // create Context and bound it
  1627. gContext := TtsContext.Create;
  1628. gContext.gBoundThreadID := GetCurrentThreadId;
  1629. // add to list
  1630. gContexts.Add(gContext.ContextID, gContext);
  1631. // return context id
  1632. pContextID^ := gContext.ContextID;
  1633. finally
  1634. gCriticalSection.Leave;
  1635. end;
  1636. except
  1637. on E: Exception do begin
  1638. if E is EOutOfMemory then
  1639. SetError(TS_OUT_OF_MEMORY, TS_FUNC_CONTEXT_CREATE)
  1640. else
  1641. SetError(TS_ERROR, TS_FUNC_CONTEXT_CREATE);
  1642. pContextID^ := 0;
  1643. end;
  1644. end;
  1645. end else
  1646. SetError(TS_INVALID_VALUE, TS_FUNC_CONTEXT_CREATE);
  1647. end else
  1648. SetError(TS_NOT_INITIALIZED, TS_FUNC_CONTEXT_CREATE);
  1649. end;
  1650. procedure tsContextDestroy(ContextID: tsContextID);
  1651. var
  1652. Context: TtsContext;
  1653. begin
  1654. if TextSuite_initialized then begin
  1655. try
  1656. gCriticalSection.Enter;
  1657. try
  1658. Context := gContexts.Get(ContextID);
  1659. if Context <> nil then begin
  1660. // if context isn't bound or to actual thread
  1661. if (Context.gBoundThreadID = 0) or (Context.gBoundThreadID = GetCurrentThreadId) then begin
  1662. // if it's bound to actual thread
  1663. if Context.gBoundThreadID = GetCurrentThreadId then begin
  1664. gContext.gBoundThreadID := 0;
  1665. gContext := nil;
  1666. end;
  1667. // delete from list
  1668. gContexts.Delete(ContextID);
  1669. // free them
  1670. Context.Free;
  1671. end else
  1672. SetError(TS_INVALID_OPERATION, TS_FUNC_CONTEXT_DESTROY);
  1673. end else
  1674. SetError(TS_INVALID_VALUE, TS_FUNC_CONTEXT_DESTROY);
  1675. finally
  1676. gCriticalSection.Leave;
  1677. end;
  1678. except
  1679. SetError(TS_ERROR, TS_FUNC_CONTEXT_DESTROY);
  1680. end;
  1681. end else
  1682. SetError(TS_NOT_INITIALIZED, TS_FUNC_CONTEXT_DESTROY);
  1683. end;
  1684. procedure tsContextBind(ContextID: tsContextID);
  1685. var
  1686. Context: TtsContext;
  1687. begin
  1688. if TextSuite_initialized then begin
  1689. gCriticalSection.Enter;
  1690. try
  1691. // if any context is bound then release him
  1692. if gContext <> nil then begin
  1693. gContext.gBoundThreadID := 0;
  1694. gContext := nil;
  1695. end;
  1696. // bind new context if <> zero
  1697. if ContextID <> 0 then begin
  1698. Context := gContexts.Get(ContextID);
  1699. if Context <> nil then begin
  1700. // check if the context is bound or bound to actual context
  1701. if (Context.gBoundThreadID = 0) or (Context.gBoundThreadID = GetCurrentThreadId) then begin
  1702. gContext := Context;
  1703. gContext.gBoundThreadID := GetCurrentThreadId;
  1704. end else
  1705. SetError(TS_INVALID_OPERATION, TS_FUNC_CONTEXT_BIND);
  1706. end else
  1707. SetError(TS_INVALID_VALUE, TS_FUNC_CONTEXT_BIND);
  1708. end;
  1709. finally
  1710. gCriticalSection.Leave;
  1711. end;
  1712. end else
  1713. SetError(TS_NOT_INITIALIZED, TS_FUNC_CONTEXT_BIND);
  1714. end;
  1715. // *** font functions ***
  1716. //procedure tsFontCreate(pFontID: ptsFontID);
  1717. //begin
  1718. //end;
  1719. procedure tsFontCreateCreatorA(Name: pAnsiChar; Size: tsInt; Style: tsBitmask; AntiAliasing: tsEnum; Format: tsEnum; pFontID: ptsFontID);
  1720. var
  1721. Context: TtsContext;
  1722. TempStyle: TtsFontStyles;
  1723. TempAntiAliasing: TtsAntiAliasing;
  1724. TempFormat: TtsFormat;
  1725. Creator: TtsFontCreator;
  1726. begin
  1727. Context := gContext;
  1728. if Context <> nil then begin
  1729. if Context.Renderer <> nil then begin
  1730. if pFontID <> nil then begin
  1731. pFontID^ := 0;
  1732. // Style
  1733. TempStyle := [];
  1734. if (Style and TS_STYLE_BOLD) > 0 then
  1735. TempStyle := TempStyle + [tsStyleBold];
  1736. if (Style and TS_STYLE_ITALIC) > 0 then
  1737. TempStyle := TempStyle + [tsStyleItalic];
  1738. if (Style and TS_STYLE_UNDERLINE) > 0 then
  1739. TempStyle := TempStyle + [tsStyleUnderline];
  1740. if (Style and TS_STYLE_STRIKEOUT) > 0 then
  1741. TempStyle := TempStyle + [tsStyleStrikeout];
  1742. // AntiAliasing
  1743. if AntiAliasing = TS_DEFAULT then
  1744. AntiAliasing := Context.gGlobalAntiAliasing;
  1745. case AntiAliasing of
  1746. TS_ANTIALIASING_NONE:
  1747. TempAntiAliasing := tsAANone;
  1748. TS_ANTIALIASING_NORMAL:
  1749. TempAntiAliasing := tsAANormal;
  1750. else
  1751. SetError(TS_INVALID_ENUM, TS_FUNC_FONT_CREATE_CREATOR);
  1752. Exit;
  1753. end;
  1754. // Format
  1755. if Format = TS_DEFAULT then
  1756. Format := Context.gGlobalFormat;
  1757. case Format of
  1758. TS_FORMAT_RGBA8:
  1759. TempFormat := tsFormatRGBA8;
  1760. else
  1761. SetError(TS_INVALID_ENUM, TS_FUNC_FONT_CREATE_CREATOR);
  1762. Exit;
  1763. end;
  1764. Creator := nil;
  1765. // create font
  1766. try
  1767. case Context.gCreator of
  1768. TS_CREATOR_SDL:
  1769. begin
  1770. if SDL_TTF_initialized then
  1771. Creator := TtsFontCreatorSDL.Create(Context.Renderer, Name, Size, TempStyle, TempFormat, TempAntiAliasing)
  1772. else
  1773. SetError(TS_NOT_INITIALIZED, TS_FUNC_FONT_CREATE_CREATOR);
  1774. end;
  1775. TS_CREATOR_GDI:
  1776. begin
  1777. if GDI_initialized then
  1778. Creator := TtsFontCreatorGDIFile.Create(Context.Renderer, Name, Size, TempStyle, TempFormat, TempAntiAliasing)
  1779. else
  1780. SetError(TS_NOT_INITIALIZED, TS_FUNC_FONT_CREATE_CREATOR);
  1781. end;
  1782. TS_CREATOR_GDI_FACENAME:
  1783. begin
  1784. if GDI_initialized then
  1785. Creator := TtsFontCreatorGDIFontFace.Create(Context.Renderer, Name, Size, TempStyle, TempFormat, TempAntiAliasing)
  1786. else
  1787. SetError(TS_NOT_INITIALIZED, TS_FUNC_FONT_CREATE_CREATOR);
  1788. end;
  1789. TS_CREATOR_GDI_STREAM:
  1790. begin
  1791. if GDI_initialized then
  1792. Creator := TtsFontCreatorGDIStream.Create(Context.Renderer, TStream(Name), Size, TempStyle, TempFormat, TempAntiAliasing)
  1793. else
  1794. SetError(TS_NOT_INITIALIZED, TS_FUNC_FONT_CREATE_CREATOR);
  1795. end;
  1796. else
  1797. SetError(TS_INVALID_ENUM, TS_FUNC_FONT_CREATE_CREATOR);
  1798. end;
  1799. except
  1800. on E: Exception do begin
  1801. if E is EOutOfMemory then
  1802. SetError(TS_OUT_OF_MEMORY, TS_FUNC_FONT_CREATE_CREATOR)
  1803. else
  1804. SetError(TS_ERROR, TS_FUNC_FONT_CREATE_CREATOR);
  1805. Exit;
  1806. end;
  1807. end;
  1808. // Bind font
  1809. if Creator <> nil then begin
  1810. pFontID^ := Context.FontAdd(Creator);
  1811. tsFontBind(pFontID^);
  1812. end;
  1813. end else
  1814. SetError(TS_INVALID_VALUE, TS_FUNC_FONT_CREATE_CREATOR);
  1815. end else
  1816. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_FONT_CREATE_CREATOR);
  1817. end else
  1818. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_FONT_CREATE_CREATOR);
  1819. end;
  1820. procedure tsFontDestroy(FontID: tsFontID);
  1821. var
  1822. Context: TtsContext;
  1823. Font: TtsFont;
  1824. begin
  1825. Context := gContext;
  1826. if Context <> nil then begin
  1827. if not Context.IsLocked then begin
  1828. Font := Context.FontGet(FontID);
  1829. if Font <> nil then begin
  1830. Context.FontDelete(FontID);
  1831. Font.Free;
  1832. end else
  1833. SetError(TS_INVALID_VALUE, TS_FUNC_FONT_DESTROY);
  1834. end else
  1835. SetError(TS_INVALID_OPERATION, TS_FUNC_FONT_DESTROY);
  1836. end else
  1837. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_FONT_DESTROY);
  1838. end;
  1839. procedure tsFontBind(FontID: tsFontID);
  1840. var
  1841. Context: TtsContext;
  1842. begin
  1843. Context := gContext;
  1844. if Context <> nil then begin
  1845. if Context.Renderer <> nil then begin
  1846. if (FontID = 0) or (Context.FontGet(FontID) <> nil) then begin
  1847. Context.Renderer.FontActivate(FontID);
  1848. end else
  1849. SetError(TS_INVALID_VALUE, TS_FUNC_FONT_BIND);
  1850. end else
  1851. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_FONT_BIND);
  1852. end else
  1853. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_FONT_BIND);
  1854. end;
  1855. procedure tsFontAddCharRange(CharStart: WideChar; CharEnd: WideChar);
  1856. var
  1857. ActiveFont: TtsFont;
  1858. CharIdx: WideChar;
  1859. Context: TtsContext;
  1860. begin
  1861. Context := gContext;
  1862. if Context <> nil then begin
  1863. ActiveFont := Context.ActiveFont;
  1864. if ActiveFont <> nil then begin
  1865. if ActiveFont is TtsFontCreator then begin
  1866. for CharIdx := CharStart to CharEnd do
  1867. TtsFontCreator(ActiveFont).AddChar(CharIdx);
  1868. end else
  1869. SetError(TS_INVALID_OPERATION, TS_FUNC_FONT_ADD_CHAR);
  1870. end else
  1871. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_FONT_ADD_CHAR);
  1872. end else
  1873. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_FONT_ADD_CHAR);
  1874. end;
  1875. procedure tsFontAddChars(Chars: pWideChar);
  1876. var
  1877. ActiveFont: TtsFont;
  1878. Context: TtsContext;
  1879. begin
  1880. Context := gContext;
  1881. if Context <> nil then begin
  1882. ActiveFont := Context.ActiveFont;
  1883. if ActiveFont <> nil then begin
  1884. if ActiveFont is TtsFontCreator then begin
  1885. if Chars <> nil then begin
  1886. while Chars^ <> #0 do begin
  1887. TtsFontCreator(ActiveFont).AddChar(Chars^);
  1888. Inc(Chars);
  1889. end;
  1890. end else
  1891. SetError(TS_INVALID_VALUE, TS_FUNC_FONT_ADD_CHAR);
  1892. end else
  1893. SetError(TS_INVALID_OPERATION, TS_FUNC_FONT_ADD_CHAR);
  1894. end else
  1895. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_FONT_ADD_CHAR);
  1896. end else
  1897. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_FONT_ADD_CHAR);
  1898. end;
  1899. procedure tsFontAddChar(Char: WideChar);
  1900. var
  1901. ActiveFont: TtsFont;
  1902. Context: TtsContext;
  1903. begin
  1904. Context := gContext;
  1905. if Context <> nil then begin
  1906. ActiveFont := Context.ActiveFont;
  1907. if ActiveFont <> nil then begin
  1908. if ActiveFont is TtsFontCreator then begin
  1909. TtsFontCreator(ActiveFont).AddChar(Char);
  1910. end else
  1911. SetError(TS_INVALID_OPERATION, TS_FUNC_FONT_ADD_CHAR);
  1912. end else
  1913. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_FONT_ADD_CHAR);
  1914. end else
  1915. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_FONT_ADD_CHAR);
  1916. end;
  1917. procedure tsFontDeleteCharRange(CharStart: WideChar; CharEnd: WideChar);
  1918. var
  1919. Char: WideChar;
  1920. ActiveFont: TtsFont;
  1921. Context: TtsContext;
  1922. begin
  1923. Context := gContext;
  1924. if Context <> nil then begin
  1925. ActiveFont := Context.ActiveFont;
  1926. if ActiveFont <> nil then begin
  1927. if ActiveFont is TtsFontCreator then begin
  1928. for Char := CharStart to CharEnd do
  1929. TtsFontCreator(ActiveFont).DeleteChar(Char);
  1930. end else
  1931. SetError(TS_INVALID_OPERATION, TS_FUNC_FONT_DELETE_CHAR);
  1932. end else
  1933. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_FONT_DELETE_CHAR);
  1934. end else
  1935. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_FONT_DELETE_CHAR);
  1936. end;
  1937. procedure tsFontDeleteChars(Chars: pWideChar);
  1938. var
  1939. ActiveFont: TtsFont;
  1940. Context: TtsContext;
  1941. begin
  1942. Context := gContext;
  1943. if Context <> nil then begin
  1944. ActiveFont := Context.ActiveFont;
  1945. if ActiveFont <> nil then begin
  1946. if ActiveFont is TtsFontCreator then begin
  1947. if Chars <> nil then begin
  1948. while Chars^ <> #0 do begin
  1949. TtsFontCreator(ActiveFont).DeleteChar(Chars^);
  1950. Inc(Chars);
  1951. end;
  1952. end else
  1953. SetError(TS_INVALID_VALUE, TS_FUNC_FONT_DELETE_CHAR);
  1954. end else
  1955. SetError(TS_INVALID_OPERATION, TS_FUNC_FONT_DELETE_CHAR);
  1956. end else
  1957. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_FONT_DELETE_CHAR);
  1958. end else
  1959. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_FONT_DELETE_CHAR);
  1960. end;
  1961. procedure tsFontDeleteChar(Char: WideChar);
  1962. var
  1963. ActiveFont: TtsFont;
  1964. Context: TtsContext;
  1965. begin
  1966. Context := gContext;
  1967. if Context <> nil then begin
  1968. ActiveFont := Context.ActiveFont;
  1969. if ActiveFont <> nil then begin
  1970. if ActiveFont is TtsFontCreator then begin
  1971. TtsFontCreator(Context.ActiveFont).DeleteChar(Char);
  1972. end else
  1973. SetError(TS_INVALID_OPERATION, TS_FUNC_FONT_DELETE_CHAR);
  1974. end else
  1975. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_FONT_DELETE_CHAR);
  1976. end else
  1977. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_FONT_DELETE_CHAR);
  1978. end;
  1979. procedure tsFontSetCharParameteri(Char: WideChar; ParamName: tsEnum; Param: tsInt);
  1980. begin
  1981. if ((ParamName <> TS_CHAR_GLYPHORIGIN) and
  1982. (ParamName <> TS_CHAR_GLYPHRECT)) then begin
  1983. tsFontSetCharParameteriv(Char, ParamName, @Param);
  1984. end else
  1985. SetError(TS_INVALID_ENUM, TS_FUNC_FONT_SET_CHAR_PARAMETER);
  1986. end;
  1987. procedure tsFontSetCharParameteriv(Char: WideChar; ParamName: tsEnum; pParam: ptsInt);
  1988. var
  1989. tsChar: TtsChar;
  1990. Context: TtsContext;
  1991. begin
  1992. Context := gContext;
  1993. if Context <> nil then begin
  1994. if Context.ActiveFont <> nil then begin
  1995. if pParam <> nil then begin
  1996. tsChar := Context.ActiveFont.Char[Char];
  1997. if tsChar <> nil then begin
  1998. case ParamName of
  1999. TS_CHAR_ADVANCE:
  2000. tsChar.Advance := pParam^;
  2001. TS_CHAR_GLYPHORIGIN:
  2002. begin
  2003. tsChar.GlyphOriginX := ptsPoint(pParam)^.X;
  2004. tsChar.GlyphOriginY := ptsPoint(pParam)^.Y;
  2005. end;
  2006. TS_CHAR_GLYPHORIGIN_X:
  2007. tsChar.GlyphOriginX := pParam^;
  2008. TS_CHAR_GLYPHORIGIN_Y:
  2009. tsChar.GlyphOriginY := pParam^;
  2010. TS_CHAR_GLYPHRECT:
  2011. tsChar.GlyphRect := pTsRect(pParam)^;
  2012. TS_CHAR_GLYPHRECT_TOP:
  2013. tsChar.GlyphRect.Top := pParam^;
  2014. TS_CHAR_GLYPHRECT_LEFT:
  2015. tsChar.GlyphRect.Left := pParam^;
  2016. TS_CHAR_GLYPHRECT_RIGHT:
  2017. tsChar.GlyphRect.Right := pParam^;
  2018. TS_CHAR_GLYPHRECT_BOTTOM:
  2019. tsChar.GlyphRect.Bottom := pParam^;
  2020. else
  2021. SetError(TS_INVALID_ENUM, TS_FUNC_FONT_SET_CHAR_PARAMETER);
  2022. end;
  2023. end else
  2024. SetError(TS_INVALID_VALUE, TS_FUNC_FONT_SET_CHAR_PARAMETER);
  2025. end else
  2026. SetError(TS_INVALID_VALUE, TS_FUNC_FONT_SET_CHAR_PARAMETER);
  2027. end else
  2028. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_FONT_SET_CHAR_PARAMETER);
  2029. end else
  2030. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_FONT_SET_CHAR_PARAMETER);
  2031. end;
  2032. function tsFontGetCharParameteri(Char: WideChar; ParamName: tsEnum): tsInt;
  2033. begin
  2034. if ((ParamName <> TS_CHAR_GLYPHORIGIN) and
  2035. (ParamName <> TS_CHAR_GLYPHRECT)) then begin
  2036. tsFontGetCharParameteriv(Char, ParamName, @Result);
  2037. end else
  2038. SetError(TS_INVALID_ENUM, TS_FUNC_FONT_GET_CHAR_PARAMETER);
  2039. end;
  2040. procedure tsFontGetCharParameteriv(Char: WideChar; ParamName: tsEnum; pParam: ptsInt);
  2041. var
  2042. tsChar: TtsChar;
  2043. Context: TtsContext;
  2044. begin
  2045. pParam^ := 0;
  2046. Context := gContext;
  2047. if Context <> nil then begin
  2048. if Context.ActiveFont <> nil then begin
  2049. if pParam <> nil then begin
  2050. tsChar := Context.ActiveFont.Char[Char];
  2051. if tsChar <> nil then begin
  2052. case ParamName of
  2053. TS_CHAR_ADVANCE:
  2054. pParam^ := tsChar.Advance;
  2055. TS_CHAR_GLYPHORIGIN:
  2056. begin
  2057. ptsPoint(pParam)^.X := tsChar.GlyphOriginX;
  2058. ptsPoint(pParam)^.Y := tsChar.GlyphOriginY;
  2059. end;
  2060. TS_CHAR_GLYPHORIGIN_X:
  2061. pParam^ := tsChar.GlyphOriginX;
  2062. TS_CHAR_GLYPHORIGIN_Y:
  2063. pParam^ := tsChar.GlyphOriginY;
  2064. TS_CHAR_GLYPHRECT:
  2065. PtsRect(pParam)^ := tsChar.GlyphRect;
  2066. TS_CHAR_GLYPHRECT_TOP:
  2067. pParam^ := tsChar.GlyphRect.Top;
  2068. TS_CHAR_GLYPHRECT_LEFT:
  2069. pParam^ := tsChar.GlyphRect.Left;
  2070. TS_CHAR_GLYPHRECT_RIGHT:
  2071. pParam^ := tsChar.GlyphRect.Right;
  2072. TS_CHAR_GLYPHRECT_BOTTOM:
  2073. pParam^ := tsChar.GlyphRect.Bottom;
  2074. else
  2075. SetError(TS_INVALID_ENUM, TS_FUNC_FONT_GET_CHAR_PARAMETER);
  2076. end;
  2077. end else
  2078. SetError(TS_INVALID_VALUE, TS_FUNC_FONT_GET_CHAR_PARAMETER);
  2079. end else
  2080. SetError(TS_INVALID_VALUE, TS_FUNC_FONT_GET_CHAR_PARAMETER);
  2081. end else
  2082. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_FONT_GET_CHAR_PARAMETER);
  2083. end else
  2084. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_FONT_GET_CHAR_PARAMETER);
  2085. end;
  2086. procedure tsPostAddFillColor3ub(Red, Green, Blue: tsByte; ChannelMask: tsBitmask);
  2087. begin
  2088. tsPostAddFillColor4f(Red / $FF, Green / $FF, Blue / $FF, 1, ChannelMask);
  2089. end;
  2090. procedure tsPostAddFillColor3f(Red, Green, Blue: tsFloat; ChannelMask: tsBitmask);
  2091. begin
  2092. tsPostAddFillColor4f(Red, Green, Blue, 1, ChannelMask);
  2093. end;
  2094. procedure tsPostAddFillColor4ub(Red, Green, Blue, Alpha: tsByte; ChannelMask: tsBitmask);
  2095. begin
  2096. tsPostAddFillColor4f(Red / $FF, Green / $FF, Blue / $FF, Alpha / $FF, ChannelMask);
  2097. end;
  2098. procedure tsPostAddFillColor4f(Red, Green, Blue, Alpha: tsFloat; ChannelMask: tsBitmask);
  2099. var
  2100. Context: TtsContext;
  2101. begin
  2102. Context := gContext;
  2103. if Context <> nil then begin
  2104. if Context.ActiveFont <> nil then begin
  2105. if Context.ActiveFont is TtsFontCreator then begin
  2106. TtsFontCreator(Context.ActiveFont).AddPostProcessStep(TtsPostFillColor.Create(Red, Green, Blue, Alpha, ChannelMask, Context.gImageMode));
  2107. end else
  2108. SetError(TS_INVALID_OPERATION, TS_FUNC_POST_ADD_FILL_COLOR);
  2109. end else
  2110. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_POST_ADD_FILL_COLOR);
  2111. end else
  2112. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_POST_ADD_FILL_COLOR);
  2113. end;
  2114. procedure tsPostAddFillPattern(PatternImageID: tsImageID; X, Y: tsInt; ChannelMask: tsBitmask);
  2115. var
  2116. Context: TtsContext;
  2117. Image: TtsImage;
  2118. begin
  2119. Context := gContext;
  2120. if Context <> nil then begin
  2121. if Context.ActiveFont <> nil then begin
  2122. if Context.ActiveFont is TtsFontCreator then begin
  2123. Image := Context.ImageGet(PatternImageID);
  2124. if Image <> nil then
  2125. TtsFontCreator(Context.ActiveFont).AddPostProcessStep(TtsPostFillPattern.Create(Image, X, Y, ChannelMask, Context.gImageMode))
  2126. else
  2127. SetError(TS_INVALID_VALUE, TS_FUNC_POST_ADD_FILL_PATTERN);
  2128. end else
  2129. SetError(TS_INVALID_OPERATION, TS_FUNC_POST_ADD_FILL_PATTERN);
  2130. end else
  2131. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_POST_ADD_FILL_PATTERN);
  2132. end else
  2133. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_POST_ADD_FILL_PATTERN);
  2134. end;
  2135. procedure tsPostAddBorder3ub(Width, Strength: Single; Red, Green, Blue: tsByte);
  2136. begin
  2137. tsPostAddBorder4f(Width, Strength, Red / $FF, Green / $FF, Blue / $FF, 1);
  2138. end;
  2139. procedure tsPostAddBorder3f(Width, Strength: Single; Red, Green, Blue: tsFloat);
  2140. begin
  2141. tsPostAddBorder4f(Width, Strength, Red, Green, Blue, 1);
  2142. end;
  2143. procedure tsPostAddBorder4ub(Width, Strength: Single; Red, Green, Blue, Alpha: tsByte);
  2144. begin
  2145. tsPostAddBorder4f(Width, Strength, Red / $FF, Green / $FF, Blue / $FF, Alpha / $FF);
  2146. end;
  2147. procedure tsPostAddBorder4f(Width, Strength: Single; Red, Green, Blue, Alpha: tsFloat);
  2148. var
  2149. Context: TtsContext;
  2150. begin
  2151. Context := gContext;
  2152. if Context <> nil then begin
  2153. if Context.ActiveFont <> nil then begin
  2154. if Context.ActiveFont is TtsFontCreator then begin
  2155. TtsFontCreator(Context.ActiveFont).AddPostProcessStep(TtsPostBorder.Create(Width, Strength, Red, Green, Blue, Alpha));
  2156. end else
  2157. SetError(TS_INVALID_OPERATION, TS_FUNC_POST_ADD_BORDER);
  2158. end else
  2159. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_POST_ADD_BORDER);
  2160. end else
  2161. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_POST_ADD_BORDER);
  2162. end;
  2163. procedure tsPostAddShadow3ub(Radius: Single; X, Y: tsInt; Red, Green, Blue: tsByte);
  2164. begin
  2165. tsPostAddShadow4f(Radius, X, Y, Red / $FF, Green / $FF, Blue / $FF, 1);
  2166. end;
  2167. procedure tsPostAddShadow3f(Radius: Single; X, Y: tsInt; Red, Green, Blue: tsFloat);
  2168. begin
  2169. tsPostAddShadow4f(Radius, X, Y, Red, Green, Blue, 1);
  2170. end;
  2171. procedure tsPostAddShadow4ub(Radius: Single; X, Y: tsInt; Red, Green, Blue, Alpha: tsByte);
  2172. begin
  2173. tsPostAddShadow4f(Radius, X, Y, Red / $FF, Green / $FF, Blue / $FF, Alpha / $FF);
  2174. end;
  2175. procedure tsPostAddShadow4f(Radius: Single; X, Y: tsInt; Red, Green, Blue, Alpha: tsFloat);
  2176. var
  2177. Context: TtsContext;
  2178. begin
  2179. Context := gContext;
  2180. if Context <> nil then begin
  2181. if Context.ActiveFont <> nil then begin
  2182. if Context.ActiveFont is TtsFontCreator then begin
  2183. TtsFontCreator(Context.ActiveFont).AddPostProcessStep(TtsPostShadow.Create(Radius, X, Y, Red, Green, Blue, Alpha));
  2184. end else
  2185. SetError(TS_INVALID_OPERATION, TS_FUNC_POST_ADD_SHADOW);
  2186. end else
  2187. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_POST_ADD_SHADOW);
  2188. end else
  2189. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_POST_ADD_SHADOW);
  2190. end;
  2191. (*
  2192. procedure tsPostAddKerning;
  2193. var
  2194. Context: TtsContext;
  2195. begin
  2196. Context := gContext;
  2197. if Context <> nil then begin
  2198. if Context.ActiveFont <> nil then begin
  2199. if Context.ActiveFont is TtsFontCreator then begin
  2200. TtsFontCreator(Context.ActiveFont).AddPostProcessStep(TtsPostKerning.Create);
  2201. end else
  2202. SetError(TS_INVALID_OPERATION;
  2203. end else
  2204. SetError(TS_NO_ACTIVE_FONT;
  2205. end else
  2206. SetError(TS_NO_ACTIVE_CONTEXT;
  2207. end;
  2208. *)
  2209. procedure tsPostAddCustom(PostProcessProc: tsPostProcessProc; Data: Pointer);
  2210. var
  2211. Context: TtsContext;
  2212. begin
  2213. Context := gContext;
  2214. if Context <> nil then begin
  2215. if Context.ActiveFont <> nil then begin
  2216. if Context.ActiveFont is TtsFontCreator then begin
  2217. TtsFontCreator(Context.ActiveFont).AddPostProcessStep(TtsPostCustom.Create(Context, PostProcessProc, Data));
  2218. end else
  2219. SetError(TS_INVALID_OPERATION, TS_FUNC_POST_ADD_CUSTOM);
  2220. end else
  2221. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_POST_ADD_CUSTOM);
  2222. end else
  2223. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_POST_ADD_CUSTOM);
  2224. end;
  2225. procedure tsPostDelete(PostIndex: tsInt);
  2226. var
  2227. Context: TtsContext;
  2228. begin
  2229. Context := gContext;
  2230. if Context <> nil then begin
  2231. if Context.ActiveFont <> nil then begin
  2232. if Context.ActiveFont is TtsFontCreator then begin
  2233. if PostIndex = TS_POST_INDEX_ALL then begin
  2234. TtsFontCreator(Context.ActiveFont).ClearPostProcessSteps;
  2235. end else
  2236. begin
  2237. // tranlate to direct index
  2238. if PostIndex = TS_POST_INDEX_LAST then
  2239. PostIndex := TtsFontCreator(Context.ActiveFont).PostProcessStepCount -1;
  2240. TtsFontCreator(Context.ActiveFont).DeletePostProcessStep(PostIndex);
  2241. end;
  2242. end else
  2243. SetError(TS_INVALID_OPERATION, TS_FUNC_POST_DELETE);
  2244. end else
  2245. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_POST_DELETE);
  2246. end else
  2247. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_POST_DELETE);
  2248. end;
  2249. procedure tsPostAddUsageRange(PostIndex: tsInt; UsageType: tsEnum; CharStart, CharEnd: WideChar);
  2250. var
  2251. Context: TtsContext;
  2252. ActFont: TtsFont;
  2253. Usage: TtsFontProcessStepUsage;
  2254. Idx: Integer;
  2255. procedure AssignUsage(Idx: Integer);
  2256. var
  2257. PostProcess: TtsPostProcessStep;
  2258. begin
  2259. PostProcess := TtsFontCreator(ActFont).PostProcessStep[Idx];
  2260. if PostProcess <> nil then begin
  2261. PostProcess.AddUsageRange(Usage, CharStart, CharEnd);
  2262. end else
  2263. SetError(TS_INVALID_VALUE, TS_FUNC_POST_ADD_USAGE);
  2264. end;
  2265. begin
  2266. Context := gContext;
  2267. if Context <> nil then begin
  2268. ActFont := Context.ActiveFont;
  2269. if ActFont <> nil then begin
  2270. if ActFont is TtsFontCreator then begin
  2271. // getting usagetype
  2272. case UsageType of
  2273. TS_POST_USAGE_INCLUDE:
  2274. Usage := tsUInclude;
  2275. TS_POST_USAGE_EXCLUDE:
  2276. Usage := tsUExclude;
  2277. else
  2278. SetError(TS_INVALID_ENUM, TS_FUNC_POST_ADD_USAGE);
  2279. Exit;
  2280. end;
  2281. // add usage to post processors
  2282. if PostIndex = TS_POST_INDEX_ALL then begin
  2283. for Idx := 0 to TtsFontCreator(ActFont).PostProcessStepCount -1 do
  2284. AssignUsage(Idx);
  2285. end else
  2286. begin
  2287. if PostIndex = TS_POST_INDEX_LAST then
  2288. PostIndex := TtsFontCreator(ActFont).PostProcessStepCount -1;
  2289. AssignUsage(PostIndex);
  2290. end;
  2291. end else
  2292. SetError(TS_INVALID_OPERATION, TS_FUNC_POST_ADD_USAGE);
  2293. end else
  2294. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_POST_ADD_USAGE);
  2295. end else
  2296. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_POST_ADD_USAGE);
  2297. end;
  2298. procedure tsPostAddUsageChars(PostIndex: tsInt; UsageType: tsEnum; Chars: pWideChar);
  2299. var
  2300. Context: TtsContext;
  2301. ActFont: TtsFont;
  2302. Usage: TtsFontProcessStepUsage;
  2303. Idx: Integer;
  2304. procedure AssignUsage(Idx: Integer);
  2305. var
  2306. PostProcess: TtsPostProcessStep;
  2307. begin
  2308. PostProcess := TtsFontCreator(ActFont).PostProcessStep[Idx];
  2309. if PostProcess <> nil then begin
  2310. PostProcess.AddUsageChars(Usage, Chars);
  2311. end else
  2312. SetError(TS_INVALID_VALUE, TS_FUNC_POST_ADD_USAGE);
  2313. end;
  2314. begin
  2315. Context := gContext;
  2316. if Context <> nil then begin
  2317. if Chars <> nil then begin
  2318. ActFont := Context.ActiveFont;
  2319. if ActFont <> nil then begin
  2320. if ActFont is TtsFontCreator then begin
  2321. // getting usagetype
  2322. case UsageType of
  2323. TS_POST_USAGE_INCLUDE:
  2324. Usage := tsUInclude;
  2325. TS_POST_USAGE_EXCLUDE:
  2326. Usage := tsUExclude;
  2327. else
  2328. SetError(TS_INVALID_ENUM, TS_FUNC_POST_ADD_USAGE);
  2329. Exit;
  2330. end;
  2331. // add usage to post processors
  2332. if PostIndex = TS_POST_INDEX_ALL then begin
  2333. for Idx := 0 to TtsFontCreator(ActFont).PostProcessStepCount -1 do
  2334. AssignUsage(Idx);
  2335. end else
  2336. begin
  2337. if PostIndex = TS_POST_INDEX_LAST then
  2338. PostIndex := TtsFontCreator(ActFont).PostProcessStepCount -1;
  2339. AssignUsage(PostIndex);
  2340. end;
  2341. end else
  2342. SetError(TS_INVALID_OPERATION, TS_FUNC_POST_ADD_USAGE);
  2343. end else
  2344. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_POST_ADD_USAGE);
  2345. end else
  2346. SetError(TS_INVALID_VALUE, TS_FUNC_POST_ADD_USAGE);
  2347. end else
  2348. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_POST_ADD_USAGE);
  2349. end;
  2350. procedure tsPostClearUsage(PostIndex: tsInt); cdecl;
  2351. var
  2352. Context: TtsContext;
  2353. ActFont: TtsFont;
  2354. Idx: Integer;
  2355. procedure ClearUsage(Idx: Integer);
  2356. var
  2357. PostProcess: TtsPostProcessStep;
  2358. begin
  2359. PostProcess := TtsFontCreator(ActFont).PostProcessStep[Idx];
  2360. if PostProcess <> nil then begin
  2361. PostProcess.ClearIncludeRange;
  2362. PostProcess.ClearExcludeRange;
  2363. end else
  2364. SetError(TS_INVALID_VALUE, TS_FUNC_POST_CLEAR_USAGE);
  2365. end;
  2366. begin
  2367. Context := gContext;
  2368. if Context <> nil then begin
  2369. ActFont := Context.ActiveFont;
  2370. if ActFont <> nil then begin
  2371. if ActFont is TtsFontCreator then begin
  2372. if PostIndex = TS_POST_INDEX_ALL then begin
  2373. for Idx := 0 to TtsFontCreator(ActFont).PostProcessStepCount -1 do
  2374. ClearUsage(Idx);
  2375. end else
  2376. begin
  2377. if PostIndex = TS_POST_INDEX_LAST then
  2378. PostIndex := TtsFontCreator(ActFont).PostProcessStepCount -1;
  2379. ClearUsage(PostIndex);
  2380. end;
  2381. end else
  2382. SetError(TS_INVALID_OPERATION, TS_FUNC_POST_CLEAR_USAGE);
  2383. end else
  2384. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_POST_CLEAR_USAGE);
  2385. end else
  2386. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_POST_CLEAR_USAGE);
  2387. end;
  2388. function tsStringAnsiToWide(pText: pAnsiChar): pWideChar;
  2389. var
  2390. Context: TtsContext;
  2391. begin
  2392. Result := nil;
  2393. if TextSuite_initialized then begin
  2394. Context := gContext;
  2395. try
  2396. if Context <> nil then begin
  2397. if pText <> nil then begin
  2398. Result := Context.AnsiToWide(pText);
  2399. if Result <> nil then begin
  2400. gCriticalSection.Enter;
  2401. try
  2402. gStrings.Add(Result);
  2403. finally
  2404. gCriticalSection.Leave;
  2405. end;
  2406. end else
  2407. SetError(TS_INVALID_OPERATION, TS_FUNC_STRING_ANSI_TO_WIDE);
  2408. end else
  2409. SetError(TS_INVALID_VALUE, TS_FUNC_STRING_ANSI_TO_WIDE);
  2410. end else
  2411. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_STRING_ANSI_TO_WIDE);
  2412. except
  2413. on E: Exception do begin
  2414. if E is EOutOfMemory then
  2415. SetError(TS_OUT_OF_MEMORY, TS_FUNC_STRING_ANSI_TO_WIDE)
  2416. else
  2417. SetError(TS_ERROR, TS_FUNC_STRING_ANSI_TO_WIDE);
  2418. end;
  2419. end;
  2420. end else
  2421. SetError(TS_NOT_INITIALIZED, TS_FUNC_STRING_ANSI_TO_WIDE);
  2422. end;
  2423. function tsStringAlloc(Size: tsInt): pWideChar; cdecl;
  2424. begin
  2425. Result := nil;
  2426. if TextSuite_initialized then begin
  2427. try
  2428. Result := tsStrAlloc(Size);
  2429. gCriticalSection.Enter;
  2430. try
  2431. gStrings.Add(Result);
  2432. finally
  2433. gCriticalSection.Leave;
  2434. end;
  2435. except
  2436. on E: Exception do begin
  2437. if E is EOutOfMemory then
  2438. SetError(TS_OUT_OF_MEMORY, TS_FUNC_STRING_ALLOC)
  2439. else
  2440. SetError(TS_ERROR, TS_FUNC_STRING_ALLOC);
  2441. end;
  2442. end;
  2443. end else
  2444. SetError(TS_NOT_INITIALIZED, TS_FUNC_STRING_ALLOC);
  2445. end;
  2446. procedure tsStringDispose(pText: pWideChar);
  2447. var
  2448. ValidString: Boolean;
  2449. begin
  2450. if TextSuite_initialized then begin
  2451. if pText <> nil then begin
  2452. try
  2453. // delete String from hash
  2454. gCriticalSection.Enter;
  2455. try
  2456. ValidString := gStrings.Delete(pText);
  2457. finally
  2458. gCriticalSection.Leave;
  2459. end;
  2460. // if sting valid free them
  2461. if ValidString then
  2462. tsStrDispose(pText)
  2463. else
  2464. SetError(TS_INVALID_OPERATION, TS_FUNC_STRING_DISPOSE);
  2465. except
  2466. on E: Exception do begin
  2467. if E is EAccessViolation then
  2468. SetError(TS_INVALID_OPERATION, TS_FUNC_STRING_DISPOSE)
  2469. else
  2470. SetError(TS_ERROR, TS_FUNC_STRING_DISPOSE);
  2471. end;
  2472. end;
  2473. end else
  2474. SetError(TS_INVALID_VALUE, TS_FUNC_STRING_DISPOSE);
  2475. end else
  2476. SetError(TS_NOT_INITIALIZED, TS_FUNC_STRING_DISPOSE);
  2477. end;
  2478. procedure tsTextBeginBlock(Left, Top, Width, Height: tsInt; Flags: tsBitmask);
  2479. var
  2480. Context: TtsContext;
  2481. begin
  2482. Context := gContext;
  2483. if Context <> nil then begin
  2484. if Context.Renderer <> nil then begin
  2485. if not Context.IsLocked then begin
  2486. Context.Renderer.BeginBlock(Left, Top, Width, Height, Flags);
  2487. end else
  2488. SetError(TS_INVALID_OPERATION, TS_FUNC_TEXT_BEGIN_BLOCK);
  2489. end else
  2490. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_TEXT_BEGIN_BLOCK);
  2491. end else
  2492. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_TEXT_BEGIN_BLOCK);
  2493. end;
  2494. procedure tsTextEndBlock;
  2495. var
  2496. Context: TtsContext;
  2497. begin
  2498. Context := gContext;
  2499. if Context <> nil then begin
  2500. if Context.Renderer <> nil then begin
  2501. if Context.IsLocked then begin
  2502. Context.Renderer.EndBlock;
  2503. end else
  2504. SetError(TS_INVALID_OPERATION, TS_FUNC_TEXT_END_BLOCK);
  2505. end else
  2506. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_TEXT_END_BLOCK);
  2507. end else
  2508. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_TEXT_END_BLOCK);
  2509. end;
  2510. procedure tsTextColor3ub(Red, Green, Blue: tsByte);
  2511. begin
  2512. tsTextColor4f(Red / $FF, Green / $FF, Blue / $FF, 1);
  2513. end;
  2514. procedure tsTextColor3f(Red, Green, Blue: tsFloat);
  2515. begin
  2516. tsTextColor4f(Red, Green, Blue, 1);
  2517. end;
  2518. procedure tsTextColor4ub(Red, Green, Blue, Alpha: tsByte);
  2519. begin
  2520. tsTextColor4f(Red / $FF, Green / $FF, Blue / $FF, Alpha / $FF);
  2521. end;
  2522. procedure tsTextColor4f(Red, Green, Blue, Alpha: tsFloat);
  2523. var
  2524. Context: TtsContext;
  2525. begin
  2526. Context := gContext;
  2527. if Context <> nil then begin
  2528. if Context.Renderer <> nil then begin
  2529. Context.Renderer.Color(Red, Green, Blue, Alpha);
  2530. end else
  2531. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_TEXT_COLOR);
  2532. end else
  2533. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_TEXT_COLOR);
  2534. end;
  2535. procedure tsTextOutA(pText: pAnsiChar);
  2536. var
  2537. pTemp: PWideChar;
  2538. Context: TtsContext;
  2539. begin
  2540. Context := gContext;
  2541. if Context <> nil then begin
  2542. if Context.Renderer <> nil then begin
  2543. if Context.ActiveFont <> nil then begin
  2544. if pText <> nil then begin
  2545. // convert text via codepage
  2546. pTemp := Context.AnsiToWide(pText);
  2547. if pTemp <> nil then begin
  2548. try
  2549. Context.Renderer.TextOut(pTemp);
  2550. finally
  2551. tsStrDispose(pTemp);
  2552. end;
  2553. end else
  2554. SetError(TS_INVALID_OPERATION, TS_FUNC_TEXT_OUT);
  2555. end else
  2556. SetError(TS_INVALID_VALUE, TS_FUNC_TEXT_OUT);
  2557. end else
  2558. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_TEXT_OUT);
  2559. end else
  2560. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_TEXT_OUT);
  2561. end else
  2562. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_TEXT_OUT);
  2563. end;
  2564. procedure tsTextOutW(pText: pWideChar);
  2565. var
  2566. Context: TtsContext;
  2567. begin
  2568. Context := gContext;
  2569. if Context <> nil then begin
  2570. if Context.Renderer <> nil then begin
  2571. if Context.ActiveFont <> nil then begin
  2572. if pText <> nil then begin
  2573. Context.Renderer.TextOut(pText);
  2574. end else
  2575. SetError(TS_INVALID_VALUE, TS_FUNC_TEXT_OUT);
  2576. end else
  2577. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_TEXT_OUT);
  2578. end else
  2579. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_TEXT_OUT);
  2580. end else
  2581. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_TEXT_OUT);
  2582. end;
  2583. function tsTextGetWidthA(pText: pAnsiChar): tsInt;
  2584. var
  2585. pTemp: PWideChar;
  2586. Context: TtsContext;
  2587. begin
  2588. Result := 0;
  2589. Context := gContext;
  2590. if Context <> nil then begin
  2591. pTemp := nil;
  2592. // if pText is assigned convert it
  2593. if pText <> nil then begin
  2594. pTemp := Context.AnsiToWide(pText);
  2595. if pTemp = nil then begin
  2596. SetError(TS_INVALID_OPERATION, TS_FUNC_TEXT_GET_WIDTH);
  2597. Exit;
  2598. end;
  2599. end;
  2600. try
  2601. Result := tsTextGetWidthW(pTemp);
  2602. finally
  2603. if pTemp <> nil then
  2604. tsStrDispose(pTemp);
  2605. end;
  2606. end else
  2607. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_TEXT_GET_WIDTH);
  2608. end;
  2609. function tsTextGetWidthW(pText: pWideChar): tsInt;
  2610. var
  2611. Context: TtsContext;
  2612. begin
  2613. Result := 0;
  2614. Context := gContext;
  2615. if Context <> nil then begin
  2616. if Context.Renderer <> nil then begin
  2617. // Width from the text
  2618. if pText <> nil then begin
  2619. if Context.ActiveFont <> nil then begin
  2620. Result := Context.Renderer.TextGetWidth(pText);
  2621. end else
  2622. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_TEXT_GET_WIDTH);
  2623. end else
  2624. // Width from blockmode
  2625. begin
  2626. if Context.IsLocked then begin
  2627. Result := Context.Renderer.TextGetDrawWidth;
  2628. end else
  2629. SetError(TS_INVALID_VALUE, TS_FUNC_TEXT_GET_WIDTH);
  2630. end;
  2631. end else
  2632. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_TEXT_GET_WIDTH);
  2633. end else
  2634. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_TEXT_GET_WIDTH);
  2635. end;
  2636. function tsTextGetHeightA(pText: pAnsiChar): tsInt;
  2637. var
  2638. pTemp: PWideChar;
  2639. Context: TtsContext;
  2640. begin
  2641. Result := 0;
  2642. Context := gContext;
  2643. if Context <> nil then begin
  2644. pTemp := nil;
  2645. // if pText is assigned convert it
  2646. if pText <> nil then begin
  2647. pTemp := Context.AnsiToWide(pText);
  2648. if pTemp = nil then begin
  2649. SetError(TS_INVALID_OPERATION, TS_FUNC_TEXT_GET_WIDTH);
  2650. Exit;
  2651. end;
  2652. end;
  2653. try
  2654. Result := tsTextGetHeightW(pTemp);
  2655. finally
  2656. if pTemp <> nil then
  2657. tsStrDispose(pTemp);
  2658. end;
  2659. end else
  2660. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_TEXT_GET_WIDTH);
  2661. end;
  2662. function tsTextGetHeightW(pText: pWideChar): tsInt;
  2663. var
  2664. Context: TtsContext;
  2665. begin
  2666. Result := 0;
  2667. Context := gContext;
  2668. if Context <> nil then begin
  2669. if Context.Renderer <> nil then begin
  2670. // Height from the text
  2671. if pText <> nil then begin
  2672. if Context.ActiveFont <> nil then begin
  2673. with Context.ActiveFont do
  2674. Result := Ascent + Descent + ExternalLeading;
  2675. end else
  2676. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_TEXT_GET_HEIGHT);
  2677. end else
  2678. // Height from blockmode
  2679. begin
  2680. if Context.IsLocked then begin
  2681. Result := Context.Renderer.TextGetDrawHeight;
  2682. end else
  2683. SetError(TS_INVALID_VALUE, TS_FUNC_TEXT_GET_HEIGHT);
  2684. end;
  2685. end else
  2686. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_TEXT_GET_HEIGHT);
  2687. end else
  2688. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_TEXT_GET_HEIGHT);
  2689. end;
  2690. procedure tsCharOutW(CharCode: WideChar); cdecl;
  2691. var
  2692. Context: TtsContext;
  2693. begin
  2694. Context := gContext;
  2695. if Context <> nil then begin
  2696. if Context.Renderer <> nil then begin
  2697. if not Context.IsLocked then begin
  2698. if Context.Renderer.ActiveFont <> nil then begin
  2699. if Context.Renderer.ActiveFont.Char[CharCode] <> nil then begin
  2700. Context.Renderer.CharOut(CharCode);
  2701. end else
  2702. SetError(TS_INVALID_VALUE, TS_FUNC_TEXT_OUT);
  2703. end else
  2704. SetError(TS_NO_ACTIVE_FONT, TS_FUNC_TEXT_OUT);
  2705. end else
  2706. SetError(TS_INVALID_OPERATION, TS_FUNC_TEXT_OUT);
  2707. end else
  2708. SetError(TS_NO_ACTIVE_RENDERER, TS_FUNC_TEXT_OUT);
  2709. end else
  2710. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_TEXT_OUT);
  2711. end;
  2712. // *** image functions ***
  2713. procedure tsImageCreate(pImageID: ptsImageID);
  2714. var
  2715. Context: TtsContext;
  2716. Image: TtsImage;
  2717. begin
  2718. Context := gContext;
  2719. if Context <> nil then begin
  2720. if pImageID <> nil then begin
  2721. // create image
  2722. try
  2723. Image := TtsImage.Create;
  2724. except
  2725. on E: Exception do begin
  2726. if E is EOutOfMemory then
  2727. SetError(TS_OUT_OF_MEMORY, TS_FUNC_IMAGE_CREATE)
  2728. else
  2729. SetError(TS_ERROR, TS_FUNC_IMAGE_CREATE);
  2730. Exit;
  2731. end;
  2732. end;
  2733. // add image
  2734. pImageID^ := Context.ImageAdd(Image);
  2735. end else
  2736. SetError(TS_INVALID_VALUE, TS_FUNC_IMAGE_CREATE);
  2737. end else
  2738. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_IMAGE_CREATE);
  2739. end;
  2740. procedure tsImageDestroy(ImageID: tsImageID);
  2741. var
  2742. Context: TtsContext;
  2743. Image: TtsImage;
  2744. begin
  2745. Context := gContext;
  2746. if Context <> nil then begin
  2747. Image := Context.ImageGet(ImageID);
  2748. if Image <> nil then begin
  2749. Context.ImageDelete(ImageID);
  2750. Image.Free;
  2751. end else
  2752. SetError(TS_INVALID_VALUE, TS_FUNC_IMAGE_DESTROY);
  2753. end else
  2754. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_IMAGE_DESTROY);
  2755. end;
  2756. procedure tsImageLoadA(ImageID: tsImageID; Filename: pAnsiChar);
  2757. var
  2758. Context: TtsContext;
  2759. Image: TtsImage;
  2760. begin
  2761. Context := gContext;
  2762. if Context <> nil then begin
  2763. case gContext.gImageLibrary of
  2764. // SDL_image
  2765. TS_IMAGE_LIBRARY_SDL:
  2766. begin
  2767. if SDL_IMAGE_initialized then begin
  2768. Image := Context.ImageGet(ImageID);
  2769. if Image <> nil then begin
  2770. try
  2771. Image.LoadFromFile(Filename);
  2772. except
  2773. on E: Exception do begin
  2774. if E is EOutOfMemory then
  2775. SetError(TS_OUT_OF_MEMORY, TS_FUNC_IMAGE_LOAD)
  2776. else
  2777. SetError(TS_ERROR, TS_FUNC_IMAGE_LOAD);
  2778. end;
  2779. end;
  2780. end else
  2781. SetError(TS_INVALID_VALUE, TS_FUNC_IMAGE_LOAD);
  2782. end else
  2783. SetError(TS_NOT_INITIALIZED, TS_FUNC_IMAGE_LOAD);
  2784. end;
  2785. else
  2786. SetError(TS_INVALID_OPERATION, TS_FUNC_IMAGE_LOAD);
  2787. end;
  2788. end else
  2789. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_IMAGE_LOAD);
  2790. end;
  2791. procedure tsImageAssignFrom(ImageID: tsImageID; FromImageID: tsImageID);
  2792. var
  2793. Context: TtsContext;
  2794. Image, ImageFrom: TtsImage;
  2795. begin
  2796. Context := gContext;
  2797. if Context <> nil then begin
  2798. Image := Context.ImageGet(ImageID);
  2799. ImageFrom := Context.ImageGet(FromImageID);
  2800. if (Image <> nil) and (ImageFrom <> nil) then begin
  2801. if not ImageFrom.Empty then begin
  2802. try
  2803. Image.AssignFrom(ImageFrom)
  2804. except
  2805. on E: Exception do begin
  2806. if E is EOutOfMemory then
  2807. SetError(TS_OUT_OF_MEMORY, TS_FUNC_IMAGE_ASSIGN_FROM)
  2808. else
  2809. SetError(TS_ERROR, TS_FUNC_IMAGE_ASSIGN_FROM);
  2810. Exit;
  2811. end;
  2812. end;
  2813. end else
  2814. SetError(TS_INVALID_OPERATION, TS_FUNC_IMAGE_ASSIGN_FROM);
  2815. end else
  2816. SetError(TS_INVALID_VALUE, TS_FUNC_IMAGE_ASSIGN_FROM);
  2817. end else
  2818. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_IMAGE_ASSIGN_FROM);
  2819. end;
  2820. procedure tsImageNew(ImageID: tsImageID; Width: tsInt; Height: tsInt; Format: tsEnum);
  2821. var
  2822. Context: TtsContext;
  2823. Image: TtsImage;
  2824. ImageFormat: TtsFormat;
  2825. begin
  2826. Context := gContext;
  2827. if Context <> nil then begin
  2828. Image := Context.ImageGet(ImageID);
  2829. if Image <> nil then begin
  2830. // format
  2831. if Format = TS_DEFAULT then
  2832. Format := Context.gGlobalFormat;
  2833. case Format of
  2834. TS_FORMAT_RGBA8:
  2835. ImageFormat := tsFormatRGBA8;
  2836. else
  2837. SetError(TS_INVALID_ENUM, TS_FUNC_IMAGE_NEW);
  2838. // leave the function
  2839. Exit;
  2840. end;
  2841. if (Width > 0) and (Height > 0) then begin
  2842. try
  2843. Image.CreateEmpty(ImageFormat, Width, Height);
  2844. except
  2845. on E: Exception do begin
  2846. if E is EOutOfMemory then
  2847. SetError(TS_OUT_OF_MEMORY, TS_FUNC_IMAGE_NEW)
  2848. else
  2849. SetError(TS_ERROR, TS_FUNC_IMAGE_NEW);
  2850. end;
  2851. end;
  2852. end else
  2853. SetError(TS_INVALID_VALUE, TS_FUNC_IMAGE_NEW);
  2854. end else
  2855. SetError(TS_INVALID_VALUE, TS_FUNC_IMAGE_NEW);
  2856. end else
  2857. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_IMAGE_NEW);
  2858. end;
  2859. procedure tsImageGetInfo(ImageID: tsImageID; pisEmpty: ptsBool; pWidth: ptsInt; pHeight: ptsInt; pFormat: ptsEnum; pData: PPointer);
  2860. var
  2861. Context: TtsContext;
  2862. Image: TtsImage;
  2863. begin
  2864. Context := gContext;
  2865. // defaults
  2866. if pisEmpty <> nil then
  2867. pisEmpty^ := TS_FALSE;
  2868. if pWidth <> nil then
  2869. pWidth^ := 0;
  2870. if pHeight <> nil then
  2871. pHeight^ := 0;
  2872. if pFormat <> nil then
  2873. pFormat^ := TS_FORMAT_EMPTY;
  2874. if pData <> nil then
  2875. pData^ := nil;
  2876. // query values
  2877. if Context <> nil then begin
  2878. Image := Context.ImageGet(ImageID);
  2879. if Image <> nil then begin
  2880. // isEmpty
  2881. if pisEmpty <> nil then
  2882. if Image.Empty then
  2883. pisEmpty^ := TS_TRUE
  2884. else
  2885. pisEmpty^ := TS_FALSE;
  2886. // Width
  2887. if pWidth <> nil then
  2888. pWidth^ := Image.Width;
  2889. // Height
  2890. if pHeight <> nil then
  2891. pHeight^ := Image.Height;
  2892. // Format
  2893. if pFormat <> nil then begin
  2894. case Image.Format of
  2895. tsFormatEmpty:
  2896. pFormat^ := TS_FORMAT_EMPTY;
  2897. tsFormatRGBA8:
  2898. pFormat^ := TS_FORMAT_RGBA8;
  2899. end;
  2900. end;
  2901. // Data
  2902. if pData <> nil then
  2903. pData^ := Image.Data;
  2904. end else
  2905. SetError(TS_INVALID_VALUE, TS_FUNC_IMAGE_GET_INFO);
  2906. end else
  2907. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_IMAGE_GET_INFO);
  2908. end;
  2909. function tsImageGetIsEmpty(ImageID: tsImageID): tsBool;
  2910. begin
  2911. tsImageGetInfo(ImageID, @Result, nil, nil, nil, nil);
  2912. end;
  2913. function tsImageGetWidth(ImageID: tsImageID): tsInt;
  2914. begin
  2915. tsImageGetInfo(ImageID, nil, @Result, nil, nil, nil);
  2916. end;
  2917. function tsImageGetHeight(ImageID: tsImageID): tsInt;
  2918. begin
  2919. tsImageGetInfo(ImageID, nil, nil, @Result, nil, nil);
  2920. end;
  2921. function tsImageGetFormat(ImageID: tsImageID): tsEnum;
  2922. begin
  2923. tsImageGetInfo(ImageID, nil, nil, nil, @Result, nil);
  2924. end;
  2925. function tsImageGetData(ImageID: tsImageID): Pointer;
  2926. begin
  2927. tsImageGetInfo(ImageID, nil, nil, nil, nil, @Result);
  2928. end;
  2929. function tsImageScanline(ImageID: tsImageID; ScanLine: tsInt): Pointer;
  2930. var
  2931. Context: TtsContext;
  2932. Image: TtsImage;
  2933. begin
  2934. Result := nil;
  2935. Context := gContext;
  2936. if Context <> nil then begin
  2937. Image := Context.ImageGet(ImageID);
  2938. if Image <> nil then begin
  2939. if not Image.Empty then begin
  2940. Result := Image.ScanLine[ScanLine];
  2941. end else
  2942. SetError(TS_INVALID_OPERATION, TS_FUNC_IMAGE_SCANLINE);
  2943. end else
  2944. SetError(TS_INVALID_VALUE, TS_FUNC_IMAGE_SCANLINE);
  2945. end else
  2946. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_IMAGE_SCANLINE);
  2947. end;
  2948. procedure tsImageResize(ImageID: tsImageID; Width, Height, X, Y: tsInt);
  2949. var
  2950. Context: TtsContext;
  2951. Image: TtsImage;
  2952. begin
  2953. Context := gContext;
  2954. if Context <> nil then begin
  2955. Image := Context.ImageGet(ImageID);
  2956. if Image <> nil then begin
  2957. if not Image.Empty then begin
  2958. Image.Resize(Width, Height, X, Y);
  2959. end else
  2960. SetError(TS_INVALID_OPERATION, TS_FUNC_IMAGE_RESIZE);
  2961. end else
  2962. SetError(TS_INVALID_VALUE, TS_FUNC_IMAGE_RESIZE);
  2963. end else
  2964. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_IMAGE_RESIZE);
  2965. end;
  2966. procedure tsImageBlend(ImageID, OverImageID: tsImageID; X, Y: tsInt; AutoExpand: tsBool);
  2967. var
  2968. Context: TtsContext;
  2969. Image, ImageOver: TtsImage;
  2970. begin
  2971. Context := gContext;
  2972. if Context <> nil then begin
  2973. Image := Context.ImageGet(ImageID);
  2974. ImageOver := Context.ImageGet(OverImageID);
  2975. if (Image <> nil) and (ImageOver <> nil) then begin
  2976. if (not Image.Empty) and (not ImageOver.Empty) then begin
  2977. Image.BlendImage(ImageOver, X, Y, AutoExpand = TS_TRUE);
  2978. end else
  2979. SetError(TS_INVALID_OPERATION, TS_FUNC_IMAGE_BLEND);
  2980. end else
  2981. SetError(TS_INVALID_VALUE, TS_FUNC_IMAGE_BLEND);
  2982. end else
  2983. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_IMAGE_BLEND);
  2984. end;
  2985. procedure tsImageBlur(ImageID: tsImageID; X, Y: tsFloat; ChannelMask: tsBitmask; AutoExpand: tsBool; ExpandSizeX, ExpandSizeY: ptsInt);
  2986. var
  2987. Context: TtsContext;
  2988. Image: TtsImage;
  2989. HorzKernel, VertKernel: TtsKernel1D;
  2990. begin
  2991. Context := gContext;
  2992. if Context <> nil then begin
  2993. Image := Context.ImageGet(ImageID);
  2994. if Image <> nil then begin
  2995. if not Image.Empty then begin
  2996. // Creating kernels
  2997. HorzKernel := TtsKernel1D.Create(X, 0);
  2998. VertKernel := TtsKernel1D.Create(Y, 0);
  2999. if AutoExpand = TS_TRUE then begin
  3000. // resizing image
  3001. Image.Resize(Image.Width + HorzKernel.Size * 2, Image.Height + VertKernel.Size * 2, HorzKernel.Size, VertKernel.Size);
  3002. if ExpandSizeX <> nil then
  3003. ExpandSizeX^ := HorzKernel.Size;
  3004. if ExpandSizeY <> nil then
  3005. ExpandSizeY^ := VertKernel.Size
  3006. end else
  3007. begin
  3008. if ExpandSizeX <> nil then
  3009. ExpandSizeX^ := 0;
  3010. if ExpandSizeY <> nil then
  3011. ExpandSizeY^ := 0;
  3012. end;
  3013. // bluring image
  3014. Image.Blur(HorzKernel, VertKernel, ChannelMask);
  3015. // freeing
  3016. HorzKernel.Free;
  3017. VertKernel.Free;
  3018. end else
  3019. SetError(TS_INVALID_OPERATION, TS_FUNC_IMAGE_BLUR);
  3020. end else
  3021. SetError(TS_INVALID_VALUE, TS_FUNC_IMAGE_BLUR);
  3022. end else
  3023. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_IMAGE_BLUR);
  3024. end;
  3025. procedure tsImageFillColor3ub(ImageID: tsImageID; Red, Green, Blue: tsByte; ChannelMask: tsBitmask);
  3026. begin
  3027. tsImageFillColor4f(ImageID, Red / $FF, Green / $FF, Blue / $FF, 1, ChannelMask);
  3028. end;
  3029. procedure tsImageFillColor3f(ImageID: tsImageID; Red, Green, Blue: tsFloat; ChannelMask: tsBitmask);
  3030. begin
  3031. tsImageFillColor4f(ImageID, Red, Green, Blue, 1, ChannelMask);
  3032. end;
  3033. procedure tsImageFillColor4ub(ImageID: tsImageID; Red, Green, Blue, Alpha: tsByte; ChannelMask: tsBitmask);
  3034. begin
  3035. tsImageFillColor4f(ImageID, Red / $FF, Green / $FF, Blue / $FF, Alpha / $FF, ChannelMask);
  3036. end;
  3037. procedure tsImageFillColor4f(ImageID: tsImageID; Red, Green, Blue, Alpha: tsFloat; ChannelMask: tsBitmask);
  3038. var
  3039. Context: TtsContext;
  3040. Image: TtsImage;
  3041. begin
  3042. Context := gContext;
  3043. if Context <> nil then begin
  3044. Image := Context.ImageGet(ImageID);
  3045. if Image <> nil then begin
  3046. if not Image.Empty then begin
  3047. Image.FillColor(Red, Green, Blue, Alpha, ChannelMask, Context.gImageMode);
  3048. end else
  3049. SetError(TS_INVALID_OPERATION, TS_FUNC_IMAGE_FILL_COLOR);
  3050. end else
  3051. SetError(TS_INVALID_VALUE, TS_FUNC_IMAGE_FILL_COLOR);
  3052. end else
  3053. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_IMAGE_FILL_COLOR);
  3054. end;
  3055. procedure tsImageFillPattern(ImageID, PatternImageID: tsImageID; X, Y: tsInt; ChannelMask: tsBitmask);
  3056. var
  3057. Context: TtsContext;
  3058. Image, ImagePattern: TtsImage;
  3059. begin
  3060. Context := gContext;
  3061. if Context <> nil then begin
  3062. Image := Context.ImageGet(ImageID);
  3063. ImagePattern := Context.ImageGet(PatternImageID);
  3064. if (Image <> nil) and (ImagePattern <> nil) then begin
  3065. if (not Image.Empty) and (not ImagePattern.Empty) then begin
  3066. Image.FillPattern(ImagePattern, X, Y, ChannelMask, Context.gImageMode);
  3067. end else
  3068. SetError(TS_INVALID_OPERATION, TS_FUNC_IMAGE_FILL_PATTERN);
  3069. end else
  3070. SetError(TS_INVALID_VALUE, TS_FUNC_IMAGE_FILL_PATTERN);
  3071. end else
  3072. SetError(TS_NO_ACTIVE_CONTEXT, TS_FUNC_IMAGE_FILL_PATTERN);
  3073. end;
  3074. {$endif}
  3075. end.