Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

379 lignes
14 KiB

  1. unit ultsPostProcessor;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. ultsTypes, utsTextSuite;
  7. function ltsPostProcessorAddRange (const aHandle: TltsPostProcessorHandle; const aUsage: TtsCharRangeUsage; const aStart, aStop: WideChar): TltsErrorCode; stdcall;
  8. function ltsPostProcessorAddChars (const aHandle: TltsPostProcessorHandle; const aUsage: TtsCharRangeUsage; const aChars: PWideChar): TltsErrorCode; stdcall;
  9. function ltsPostProcessorClearRanges (const aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall;
  10. function ltsPostProcessorFillColorCreate (const aContext: TltsContextHandle; const aColor: TtsColor4f;
  11. const aModes: TtsImageModes; const aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall;
  12. function ltsPostProcessorFillPatterCreate (const aContext: TltsContextHandle; const aPattern: TltsImageHandle; const aOwnsPatter: Boolean;
  13. const aPosition: TtsPosition; const aModes: TtsImageModes; const aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall;
  14. function ltsPostProcessorBorderCreate (const aContext: TltsContextHandle; const aWidth, aStrength: Single;
  15. const aColor: TtsColor4f; const aKeepSize: Boolean): TltsPostProcessorHandle; stdcall;
  16. function ltsPostProcessorShadowCreate (const aContext: TltsContextHandle; const aRadius, aStrength: Single;
  17. const aOffset: TtsPosition; const aColor: TtsColor4f): TltsPostProcessorHandle; stdcall;
  18. function ltsPostProcessorListCreate (const aContext: TltsContextHandle): TltsPostProcessorHandle; stdcall;
  19. function ltsPostProcessorListGetCount (const aHandle: TltsPostProcessorHandle): Integer; stdcall;
  20. function ltsPostProcessorListGetItem (const aHandle: TltsPostProcessorHandle; const aIndex: Integer): TltsPostProcessorHandle; stdcall;
  21. function ltsPostProcessorListGetOwnsObjects (const aHandle: TltsPostProcessorHandle; var aValue: Boolean): TltsErrorCode; stdcall;
  22. function ltsPostProcessorListSetOwnsObjects (const aHandle: TltsPostProcessorHandle; const aValue: Boolean): TltsErrorCode; stdcall;
  23. function ltsPostProcessorListAdd (const aHandle, aItem: TltsPostProcessorHandle): TltsErrorCode; stdcall;
  24. function ltsPostProcessorListDel (const aHandle: TltsPostProcessorHandle; const aIndex: Integer): TltsErrorCode; stdcall;
  25. function ltsPostProcessorListClear (const aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall;
  26. function ltsPostProcessorListRem (const aHandle, aItem: TltsPostProcessorHandle): Integer; stdcall;
  27. function ltsPostProcessorListIndexOf (const aHandle, aItem: TltsPostProcessorHandle): Integer; stdcall;
  28. implementation
  29. uses
  30. ultsUtils;
  31. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  32. //ltsPostProcessor//////////////////////////////////////////////////////////////////////////////////////////////////////
  33. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  34. function ltsPostProcessorAddRange(const aHandle: TltsPostProcessorHandle; const aUsage: TtsCharRangeUsage; const aStart, aStop: WideChar): TltsErrorCode; stdcall;
  35. var
  36. pp: TtsPostProcessor;
  37. begin
  38. try
  39. result := ltsErrNone;
  40. if ValidateCharRangeUsage(aUsage) and CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp)
  41. then pp.AddRange(aUsage, aStart, aStop)
  42. else result := LastErrorCode;
  43. except
  44. on ex: Exception do begin
  45. SetLastError(ex);
  46. result := LastErrorCode;
  47. end;
  48. end;
  49. end;
  50. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  51. function ltsPostProcessorAddChars(const aHandle: TltsPostProcessorHandle; const aUsage: TtsCharRangeUsage; const aChars: PWideChar): TltsErrorCode; stdcall;
  52. var
  53. pp: TtsPostProcessor;
  54. begin
  55. try
  56. result := ltsErrNone;
  57. if ValidateCharRangeUsage(aUsage) and CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp)
  58. then pp.AddChars(aUsage, aChars)
  59. else result := LastErrorCode;
  60. except
  61. on ex: Exception do begin
  62. SetLastError(ex);
  63. result := LastErrorCode;
  64. end;
  65. end;
  66. end;
  67. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  68. function ltsPostProcessorClearRanges(const aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall;
  69. var
  70. pp: TtsPostProcessor;
  71. begin
  72. try
  73. result := ltsErrNone;
  74. if CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp)
  75. then pp.ClearRanges
  76. else result := LastErrorCode;
  77. except
  78. on ex: Exception do begin
  79. SetLastError(ex);
  80. result := LastErrorCode;
  81. end;
  82. end;
  83. end;
  84. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  85. function ltsPostProcessorFillColorCreate(const aContext: TltsContextHandle; const aColor: TtsColor4f; const aModes: TtsImageModes; const aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall;
  86. var
  87. c: TtsContext;
  88. pp: TtsPostProcessor;
  89. begin
  90. try
  91. result := nil;
  92. if CheckContextHandle(aContext, c) then begin
  93. pp := TtsPostProcessorFillColor.Create(c, aColor, aModes, aChannels);
  94. AddReference(ltsObjTypePostProcessor, pp);
  95. result := pp;
  96. end;
  97. except
  98. on ex: Exception do begin
  99. SetLastError(ex);
  100. result := nil;
  101. end;
  102. end;
  103. end;
  104. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  105. function ltsPostProcessorFillPatterCreate(const aContext: TltsContextHandle; const aPattern: TltsImageHandle; const aOwnsPatter: Boolean; const aPosition: TtsPosition; const aModes: TtsImageModes; const aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall;
  106. var
  107. c: TtsContext;
  108. img: TtsImage;
  109. pp: TtsPostProcessor;
  110. begin
  111. try
  112. result := nil;
  113. img := nil;
  114. if CheckContextHandle(aContext, c) and CheckImageHandle(aPattern, img) then begin
  115. pp := TtsPostProcessorFillPattern.Create(c, img, aOwnsPatter, aPosition, aModes, aChannels);
  116. AddReference(ltsObjTypePostProcessor, pp);
  117. if aOwnsPatter then
  118. DelReference(ltsObjTypeImage, img);
  119. result := pp;
  120. end;
  121. except
  122. on ex: Exception do begin
  123. SetLastError(ex);
  124. result := nil;
  125. end;
  126. end;
  127. end;
  128. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  129. function ltsPostProcessorBorderCreate(const aContext: TltsContextHandle; const aWidth, aStrength: Single; const aColor: TtsColor4f; const aKeepSize: Boolean): TltsPostProcessorHandle; stdcall;
  130. var
  131. c: TtsContext;
  132. pp: TtsPostProcessor;
  133. begin
  134. try
  135. result := nil;
  136. if CheckContextHandle(aContext, c) then begin
  137. pp := TtsPostProcessorBorder.Create(c, aWidth, aStrength, aColor, aKeepSize);
  138. AddReference(ltsObjTypePostProcessor, pp);
  139. result := pp;
  140. end;
  141. except
  142. on ex: Exception do begin
  143. SetLastError(ex);
  144. result := nil;
  145. end;
  146. end;
  147. end;
  148. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  149. function ltsPostProcessorShadowCreate(const aContext: TltsContextHandle; const aRadius, aStrength: Single; const aOffset: TtsPosition; const aColor: TtsColor4f): TltsPostProcessorHandle; stdcall;
  150. var
  151. c: TtsContext;
  152. pp: TtsPostProcessor;
  153. begin
  154. try
  155. result := nil;
  156. if CheckContextHandle(aContext, c) then begin
  157. pp := TtsPostProcessorShadow.Create(c, aRadius, aStrength, aOffset, aColor);
  158. AddReference(ltsObjTypePostProcessor, pp);
  159. result := pp;
  160. end;
  161. except
  162. on ex: Exception do begin
  163. SetLastError(ex);
  164. result := nil;
  165. end;
  166. end;
  167. end;
  168. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  169. function ltsPostProcessorListCreate(const aContext: TltsContextHandle): TltsPostProcessorHandle; stdcall;
  170. var
  171. c: TtsContext;
  172. pp: TtsPostProcessor;
  173. begin
  174. try
  175. result := nil;
  176. if CheckContextHandle(aContext, c) then begin
  177. pp := TtsPostProcessorList.Create(c, false);
  178. AddReference(ltsObjTypePostProcessor, pp);
  179. result := pp;
  180. end;
  181. except
  182. on ex: Exception do begin
  183. SetLastError(ex);
  184. result := nil;
  185. end;
  186. end;
  187. end;
  188. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  189. function ltsPostProcessorListGetCount(const aHandle: TltsPostProcessorHandle): Integer; stdcall;
  190. var
  191. pp: TtsPostProcessorList;
  192. begin
  193. try
  194. if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp)
  195. then result := pp.Count
  196. else result := -1;
  197. except
  198. on ex: Exception do begin
  199. SetLastError(ex);
  200. result := -1;
  201. end;
  202. end;
  203. end;
  204. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  205. function ltsPostProcessorListGetItem(const aHandle: TltsPostProcessorHandle; const aIndex: Integer): TltsPostProcessorHandle; stdcall;
  206. var
  207. pp: TtsPostProcessorList;
  208. begin
  209. try
  210. result := nil;
  211. if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) then begin
  212. if (aIndex < 0) or (aIndex >= pp.Count)
  213. then SetLastError(ltsErrInvalidValue, 'index is out of range')
  214. else result := pp.Items[aIndex];
  215. end else
  216. result := nil;
  217. except
  218. on ex: Exception do begin
  219. SetLastError(ex);
  220. result := nil;
  221. end;
  222. end;
  223. end;
  224. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  225. function ltsPostProcessorListGetOwnsObjects(const aHandle: TltsPostProcessorHandle; var aValue: Boolean): TltsErrorCode; stdcall;
  226. var
  227. pp: TtsPostProcessorList;
  228. begin
  229. try
  230. result := ltsErrNone;
  231. if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp)
  232. then aValue := pp.OwnsObjects
  233. else result := LastErrorCode;
  234. except
  235. on ex: Exception do begin
  236. SetLastError(ex);
  237. result := LastErrorCode;
  238. end;
  239. end;
  240. end;
  241. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  242. function ltsPostProcessorListSetOwnsObjects(const aHandle: TltsPostProcessorHandle; const aValue: Boolean): TltsErrorCode; stdcall;
  243. var
  244. pp: TtsPostProcessorList;
  245. begin
  246. try
  247. result := ltsErrNone;
  248. if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp)
  249. then pp.OwnsObjects := aValue
  250. else result := LastErrorCode;
  251. except
  252. on ex: Exception do begin
  253. SetLastError(ex);
  254. result := LastErrorCode;
  255. end;
  256. end;
  257. end;
  258. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  259. function ltsPostProcessorListAdd(const aHandle, aItem: TltsPostProcessorHandle): TltsErrorCode; stdcall;
  260. var
  261. pp, itm: TtsPostProcessorList;
  262. begin
  263. try
  264. result := ltsErrNone;
  265. if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) and
  266. CheckPostProcessorHandle(aItem, TtsPostProcessor, itm)
  267. then pp.Add(itm)
  268. else result := LastErrorCode;
  269. except
  270. on ex: Exception do begin
  271. SetLastError(ex);
  272. result := LastErrorCode;
  273. end;
  274. end;
  275. end;
  276. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  277. function ltsPostProcessorListDel(const aHandle: TltsPostProcessorHandle; const aIndex: Integer): TltsErrorCode; stdcall;
  278. var
  279. pp: TtsPostProcessorList;
  280. begin
  281. try
  282. result := ltsErrNone;
  283. if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) then begin
  284. if (aIndex < 0) or (aIndex >= pp.Count) then begin
  285. SetLastError(ltsErrInvalidValue, 'index is out of range');
  286. result := LastErrorCode
  287. end
  288. else pp.Delete(aIndex);
  289. end else
  290. result := LastErrorCode;
  291. except
  292. on ex: Exception do begin
  293. SetLastError(ex);
  294. result := LastErrorCode;
  295. end;
  296. end;
  297. end;
  298. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  299. function ltsPostProcessorListClear(const aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall;
  300. var
  301. pp: TtsPostProcessorList;
  302. begin
  303. try
  304. result := ltsErrNone;
  305. if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp)
  306. then pp.ClearRanges
  307. else result := LastErrorCode;
  308. except
  309. on ex: Exception do begin
  310. SetLastError(ex);
  311. result := LastErrorCode;
  312. end;
  313. end;
  314. end;
  315. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  316. function ltsPostProcessorListRem(const aHandle, aItem: TltsPostProcessorHandle): Integer; stdcall;
  317. var
  318. pp, itm: TtsPostProcessorList;
  319. begin
  320. try
  321. result := -1;
  322. if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) and
  323. CheckPostProcessorHandle(aItem, TtsPostProcessor, itm)
  324. then result := pp.Remove(itm)
  325. else result := -1;
  326. except
  327. on ex: Exception do begin
  328. SetLastError(ex);
  329. result := -1;
  330. end;
  331. end;
  332. end;
  333. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  334. function ltsPostProcessorListIndexOf(const aHandle, aItem: TltsPostProcessorHandle): Integer; stdcall;
  335. var
  336. pp, itm: TtsPostProcessorList;
  337. begin
  338. try
  339. result := -1;
  340. if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) and
  341. CheckPostProcessorHandle(aItem, TtsPostProcessor, itm)
  342. then result := pp.IndexOf(itm)
  343. else result := -1;
  344. except
  345. on ex: Exception do begin
  346. SetLastError(ex);
  347. result := -1;
  348. end;
  349. end;
  350. end;
  351. end.