You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

2473 rivejä
108 KiB

  1. unit ulibTextSuite;
  2. {$IFDEF fpc}
  3. {$mode objfpc}{$H+}
  4. {$ENDIF}
  5. interface
  6. uses
  7. Classes, SysUtils, contnrs;
  8. type
  9. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. //Enums/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  11. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  12. {$Z4}
  13. TltsErrorCode = (
  14. ltsErrUnknown = -1,
  15. ltsErrNone = 0,
  16. // misc
  17. ltsErrNotInitialized = 1,
  18. ltsErrInvalidEnum = 2,
  19. ltsErrInvalidValue = 3,
  20. ltsErrInvalidOperation = 4,
  21. ltsErrInvalidType = 5,
  22. // invalid handles
  23. ltsErrInvalidContextHandle = 100,
  24. ltsErrInvalidRendererHandle = 101,
  25. ltsErrInvalidTextBlockHandle = 102,
  26. ltsErrInvalidFontHandle = 103,
  27. ltsErrInvalidFontCreatorHandle = 104,
  28. ltsErrInvalidImageHandle = 105,
  29. ltsErrInvalidPostProcHandle = 106
  30. );
  31. {$Z4}
  32. TltsObjectType = (
  33. ltsObjTypeUnknown,
  34. ltsObjTypeContext,
  35. ltsObjTypeRenderer,
  36. ltsObjTypeFontCreator,
  37. ltsObjTypeFont,
  38. ltsObjTypeTextBlock,
  39. ltsObjTypeImage,
  40. ltsObjTypePostProcessor
  41. );
  42. {$Z4}
  43. TltsRendererType = (
  44. ltsRendererUnknown,
  45. ltsRendererOpenGL,
  46. ltsRendererOpenGLES
  47. );
  48. {$Z4}
  49. TltsFontCreatorType = (
  50. ltsFontCreatorUnknown,
  51. ltsFontCreatorFreeType,
  52. ltsFontCreatorGDI,
  53. ltsFontCreatorCustom
  54. );
  55. {$Z4}
  56. TltsCodePage = (
  57. ltsUTF8,
  58. ltsISO_8859_1,
  59. ltsISO_8859_2,
  60. ltsISO_8859_3,
  61. ltsISO_8859_4,
  62. ltsISO_8859_5,
  63. ltsISO_8859_6,
  64. ltsISO_8859_7,
  65. ltsISO_8859_8,
  66. ltsISO_8859_9,
  67. ltsISO_8859_10,
  68. ltsISO_8859_11,
  69. ltsISO_8859_13,
  70. ltsISO_8859_14,
  71. ltsISO_8859_15,
  72. ltsISO_8859_16,
  73. ltsISO_037,
  74. ltsISO_437,
  75. ltsISO_500,
  76. ltsISO_737,
  77. ltsISO_775,
  78. ltsISO_850,
  79. ltsISO_852,
  80. ltsISO_855,
  81. ltsISO_857,
  82. ltsISO_860,
  83. ltsISO_861,
  84. ltsISO_862,
  85. ltsISO_863,
  86. ltsISO_864,
  87. ltsISO_865,
  88. ltsISO_866,
  89. ltsISO_869,
  90. ltsISO_874,
  91. ltsISO_875,
  92. ltsISO_1026,
  93. ltsISO_1250,
  94. ltsISO_1251,
  95. ltsISO_1252,
  96. ltsISO_1253,
  97. ltsISO_1254,
  98. ltsISO_1255,
  99. ltsISO_1256,
  100. ltsISO_1257,
  101. ltsISO_1258);
  102. TltsFormat = (
  103. ltsFormatEmpty,
  104. ltsFormatRGBA8,
  105. ltsFormatLumAlpha8,
  106. ltsFormatAlpha8,
  107. ltsFormatLum8);
  108. TltsVertAlignment = (
  109. ltsVertAlignTop,
  110. ltsVertAlignCenter,
  111. ltsVertAlignBottom);
  112. TltsHorzAlignment = (
  113. ltsHorzAlignLeft,
  114. ltsHorzAlignCenter,
  115. ltsHorzAlignRight,
  116. ltsHorzAlignJustify);
  117. TltsClipping = (
  118. ltsClipNone,
  119. ltsClipWordBorder,
  120. ltsClipCharBorder,
  121. ltsClipWordComplete,
  122. ltsClipCharComplete
  123. );
  124. TltsAntiAliasing = (
  125. ltsAANone,
  126. ltsAANormal);
  127. TltsCharRangeUsage = (
  128. ltsUsageInclude,
  129. ltsUsageExclude);
  130. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  131. //Flags/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  132. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  133. type
  134. TltsBlockFlag = (
  135. ltsBlockFlagWordWrap
  136. );
  137. TltsBlockFlags = set of TltsBlockFlag;
  138. TltsFontStyle = (
  139. ltsStyleBold,
  140. ltsStyleItalic,
  141. ltsStyleUnderline,
  142. ltsStyleStrikeout);
  143. TltsFontStyles = set of TltsFontStyle;
  144. TltsColorChannel = (
  145. ltsChannelRed,
  146. ltsChannelGreen,
  147. ltsChannelBlue,
  148. ltsChannelAlpha);
  149. TltsColorChannels = set of TltsColorChannel;
  150. TltsImageMode = (
  151. ltsModeIgnore,
  152. ltsModeReplace,
  153. ltsModeModulate);
  154. TltsImageModes = array[TltsColorChannel] of TltsImageMode;
  155. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  156. //Structures////////////////////////////////////////////////////////////////////////////////////////////////////////////
  157. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  158. type
  159. PltsColor4f = ^TltsColor4f;
  160. TltsColor4f = packed record
  161. case Boolean of
  162. true: (r, g, b, a: Single);
  163. false: (arr: array[0..3] of Single);
  164. end;
  165. PltsPosition = ^TltsPosition;
  166. TltsPosition = packed record
  167. x, y: Integer;
  168. end;
  169. PltsRect = ^TltsRect;
  170. TltsRect = packed record
  171. case Byte of
  172. 0: (TopLeft: TltsPosition; BottomRight: TltsPosition);
  173. 1: (Left, Top, Right, Bottom: Integer);
  174. end;
  175. TltsVector4f = array[0..3] of Single;
  176. TltsMatrix4f = array[0..3] of TltsVector4f;
  177. TltsGlyphMetric = packed record
  178. GlyphOrigin: TltsPosition;
  179. GlyphRect: TltsRect;
  180. Advance: Integer;
  181. end;
  182. TltsTextMetric = packed record
  183. Ascent: Integer;
  184. Descent: Integer;
  185. ExternalLeading: Integer;
  186. BaseLineOffset: Integer;
  187. CharSpacing: Integer;
  188. LineHeight: Integer;
  189. LineSpacing: Integer;
  190. end;
  191. TltsFontNames = packed record
  192. Fontname: String;
  193. Copyright: String;
  194. Facename: String;
  195. Stylename: String;
  196. Fullname: String;
  197. end;
  198. TltsFontMetric = packed record
  199. Size: Integer;
  200. Style: TltsFontStyles;
  201. AntiAliasing: TltsAntiAliasing;
  202. DefaultChar: WideChar;
  203. Ascent: Integer;
  204. Descent: Integer;
  205. ExternalLeading: Integer;
  206. BaseLineOffset: Integer;
  207. UnderlinePos: Integer;
  208. UnderlineSize: Integer;
  209. StrikeoutPos: Integer;
  210. StrikeoutSize: Integer;
  211. end;
  212. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  213. //Library Functions/////////////////////////////////////////////////////////////////////////////////////////////////////
  214. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  215. type
  216. TltsHandle = Pointer;
  217. TltsContextHandle = TltsHandle;
  218. TltsRendererHandle = TltsHandle;
  219. TltsTextBlockHandle = TltsHandle;
  220. TltsFontCreatorHandle = TltsHandle;
  221. TltsFontHandle = TltsHandle;
  222. TltsPostProcessorHandle = TltsHandle;
  223. TltsImageHandle = TltsHandle;
  224. TltsCharHandle = TltsHandle;
  225. TltsStreamOrigin = (
  226. ltsStreamOriginBegin = Integer(soBeginning),
  227. ltsStreamOriginCurrent = Integer(soCurrent),
  228. ltsStreamOriginEnd = Integer(soEnd)
  229. );
  230. TltsStreamFuncRead = function(const aArgs: Pointer; const aBuffer: Pointer; const aSize: Integer): Integer; stdcall;
  231. TltsStreamFuncSeek = function(const aArgs: Pointer; const aOrigin: TltsStreamOrigin; const aPos: Integer): Integer; stdcall;
  232. PltsStream = ^TltsStream;
  233. TltsStream = packed record
  234. args: Pointer;
  235. read: TltsStreamFuncRead;
  236. seek: TltsStreamFuncSeek;
  237. end;
  238. TltsPostProcessorExecuteFunc = procedure(const aCharHandle: TltsCharHandle; const aImageHandle: TltsImageHandle; aArgs: Pointer);
  239. PltsPostProcessorCustomData = ^TltsPostProcessorCustomData;
  240. TltsPostProcessorCustomData = packed record
  241. args: Pointer;
  242. execute: TltsPostProcessorExecuteFunc;
  243. end;
  244. TltsRendererCustomBeginRender = procedure(aArgs: Pointer); stdcall;
  245. TltsRendererCustomEndRender = procedure(aArgs: Pointer); stdcall;
  246. TltsRendererCustomGetDrawPos = function (aArgs: Pointer): TltsPosition; stdcall;
  247. TltsRendererCustomSetDrawPos = procedure(const aValue: TltsPosition; aArgs: Pointer); stdcall;
  248. TltsRendererCustomMoveDrawPos = procedure(const aOffset: TltsPosition; aArgs: Pointer); stdcall;
  249. TltsRendererCustomSetColor = procedure(const aValue: TltsColor4f; aArgs: Pointer); stdcall;
  250. TltsRendererCustomRender = procedure(const aRef: Pointer; const aForcedWidth: Integer; aArgs: Pointer); stdcall;
  251. TltsRendererCustomCreateRef = function (const aChar: TltsCharHandle; const aImage: TltsImageHandle; aArgs: Pointer): Pointer; stdcall;
  252. TltsRendererCustomFreeRef = procedure(const aRef: Pointer; aArgs: Pointer); stdcall;
  253. PltsRendererCustomData = ^TltsRendererCustomData;
  254. TltsRendererCustomData = packed record
  255. args: Pointer;
  256. BeginRender: TltsRendererCustomBeginRender;
  257. EndRender: TltsRendererCustomEndRender;
  258. GetDrawPos: TltsRendererCustomGetDrawPos;
  259. SetDrawPos: TltsRendererCustomSetDrawPos;
  260. MoveDrawPos: TltsRendererCustomMoveDrawPos;
  261. SetColor: TltsRendererCustomSetColor;
  262. Render: TltsRendererCustomRender;
  263. CreatRef: TltsRendererCustomCreateRef;
  264. FreeRef: TltsRendererCustomFreeRef;
  265. end;
  266. TltsImage = class;
  267. TltsImageLoadFunc = procedure(const aImage: TltsImage; X, Y: Integer; var aPixel: TltsColor4f; aArgs: Pointer);
  268. TltsImageBlendFunc = function (const aSrc, aDst: TltsColor4f; aArgs: Pointer): TltsColor4f;
  269. TltsImageLoadInternFunc = procedure(const aHandle: TltsImageHandle; const X, Y: Integer; var aPixel: TltsColor4f; aArgs: Pointer); stdcall;
  270. TltsImageBlendInternFunc = function (const aHandle: TltsImageHandle; const aSrc, aDst: TltsColor4f; aArgs: Pointer): TltsColor4f; stdcall;
  271. TltsContextCreate = function(): TltsContextHandle; stdcall;
  272. TltsContextGetCodePage = function(const aHandle: TltsContextHandle; out aCodePage: TltsCodePage): TltsErrorCode; stdcall;
  273. TltsContextGetDefaultChar = function(const aHandle: TltsContextHandle; out aValue: WideChar): TltsErrorCode; stdcall;
  274. TltsContextSetCodePage = function(const aHandle: TltsContextHandle; const aCodePage: TltsCodePage): TltsErrorCode; stdcall;
  275. TltsContextSetDefaultChar = function(const aHandle: TltsContextHandle; const aValue: WideChar): TltsErrorCode; stdcall;
  276. TltsContextAnsiToWide = function(const aHandle: TltsContextHandle; const aText: PAnsiChar): PWideChar; stdcall;
  277. TltsContextDestroy = function(const aHandle: TltsContextHandle): TltsErrorCode; stdcall;
  278. TltsRendererCreate = function(const aHandle: TltsContextHandle; const aType: TltsRendererType; const aFormat: TltsFormat): TltsRendererHandle; stdcall;
  279. TltsRendererCustomCreate = function(const aHandle: TltsContextHandle; const aFormat: TltsFormat; const aData: PltsRendererCustomData): TltsRendererHandle; stdcall;
  280. TltsRendererBeginBlock = function(const aHandle: TltsRendererHandle; const aTop, aLeft, aWidth, aHeight: Integer; const aFlags: TltsBlockFlags): TltsTextBlockHandle; stdcall;
  281. TltsRendererEndBlock = function(const aHandle: TltsRendererHandle; const aBlock: TltsTextBlockHandle): TltsErrorCode; stdcall;
  282. TltsRendererAbortBlock = function(const aHandle: TltsRendererHandle; const aBlock: TltsTextBlockHandle): TltsErrorCode; stdcall;
  283. TltsRendererGetTextWidthA = function(const aHandle: TltsRendererHandle; const aFont: TltsFontHandle; const aText: PAnsiChar): Integer; stdcall;
  284. TltsRendererGetTextWidthW = function(const aHandle: TltsRendererHandle; const aFont: TltsFontHandle; const aText: PWideChar): Integer; stdcall;
  285. TltsRendererDestroy = function(const aHandle: TltsRendererHandle): TltsErrorCode; stdcall;
  286. TltsFontCreatorCreate = function(const aHandle: TltsContextHandle; const aType: TltsFontCreatorType): TltsFontCreatorHandle; stdcall;
  287. TltsFontCreatorGetFontByName = function(const aHandle: TltsFontCreatorHandle; const aFontname: PAnsiChar; const aSize: Integer; const aStyle: TltsFontStyles; const aAntiAliasing: TltsAntiAliasing): TltsFontHandle; stdcall;
  288. TltsFontCreatorGetFontByFile = function(const aHandle: TltsFontCreatorHandle; const aFilename: PAnsiChar; const aSize: Integer; const aStyle: TltsFontStyles; const aAntiAliasing: TltsAntiAliasing): TltsFontHandle; stdcall;
  289. TltsFontCreatorGetFontByStream = function(const aHandle: TltsFontCreatorHandle; const aStream: PltsStream; const aSize: Integer; const aStyle: TltsFontStyles; const aAntiAliasing: TltsAntiAliasing): TltsFontHandle; stdcall;
  290. TltsFontCreatorDestroy = function(const aHandle: TltsFontCreatorHandle): TltsErrorCode; stdcall;
  291. TltsFontGetPostProcessor = function(const aHandle: TltsFontHandle): TltsPostProcessorHandle; stdcall;
  292. TltsFontGetTabWidth = function(const aHandle: TltsFontHandle; out aValue: Integer): TltsErrorCode; stdcall;
  293. TltsFontGetCharSpacing = function(const aHandle: TltsFontHandle; out aValue: Integer): TltsErrorCode; stdcall;
  294. TltsFontGetLineSpacing = function(const aHandle: TltsFontHandle; out aValue: Single): TltsErrorCode; stdcall;
  295. TltsFontGetMetric = function(const aHandle: TltsFontHandle; out aValue: TltsFontMetric): TltsErrorCode; stdcall;
  296. TltsFontGetFontname = function(const aHandle: TltsFontHandle): PAnsiChar; stdcall;
  297. TltsFontGetFacename = function(const aHandle: TltsFontHandle): PAnsiChar; stdcall;
  298. TltsFontGetStylename = function(const aHandle: TltsFontHandle): PAnsiChar; stdcall;
  299. TltsFontGetFullname = function(const aHandle: TltsFontHandle): PAnsiChar; stdcall;
  300. TltsFontGetCopyright = function(const aHandle: TltsFontHandle): PAnsiChar; stdcall;
  301. TltsFontSetPostProcessor = function(const aHandle: TltsFontHandle; const aValue: TltsPostProcessorHandle): TltsErrorCode; stdcall;
  302. TltsFontSetTabWidth = function(const aHandle: TltsFontHandle; const aValue: Integer): TltsErrorCode; stdcall;
  303. TltsFontSetCharSpacing = function(const aHandle: TltsFontHandle; const aValue: Integer): TltsErrorCode; stdcall;
  304. TltsFontSetLineSpacing = function(const aHandle: TltsFontHandle; const aValue: Single): TltsErrorCode; stdcall;
  305. TltsFontDestroy = function(const aHandle: TltsFontHandle): TltsErrorCode; stdcall;
  306. TltsTextBlockGetRect = function(const aHandle: TltsTextBlockHandle; out aValue: TltsRect): TltsErrorCode; stdcall;
  307. TltsTextBlockGetWidth = function(const aHandle: TltsTextBlockHandle; out aValue: Integer): TltsErrorCode; stdcall;
  308. TltsTextBlockGetHeight = function(const aHandle: TltsTextBlockHandle; out aValue: Integer): TltsErrorCode; stdcall;
  309. TltsTextBlockGetFlags = function(const aHandle: TltsTextBlockHandle; out aValue: TltsBlockFlags): TltsErrorCode; stdcall;
  310. TltsTextBlockGetTop = function(const aHandle: TltsTextBlockHandle; out aValue: Integer): TltsErrorCode; stdcall;
  311. TltsTextBlockGetLeft = function(const aHandle: TltsTextBlockHandle; out aValue: Integer): TltsErrorCode; stdcall;
  312. TltsTextBlockGetVertAlign = function(const aHandle: TltsTextBlockHandle; out aValue: TltsVertAlignment): TltsErrorCode; stdcall;
  313. TltsTextBlockGetHorzAlign = function(const aHandle: TltsTextBlockHandle; out aValue: TltsHorzAlignment): TltsErrorCode; stdcall;
  314. TltsTextBlockGetClipping = function(const aHandle: TltsTextBlockHandle; out aValue: TltsClipping): TltsErrorCode; stdcall;
  315. TltsTextBlockGetColor = function(const aHandle: TltsTextBlockHandle; out aValue: TltsColor4f): TltsErrorCode; stdcall;
  316. TltsTextBlockGetFont = function(const aHandle: TltsTextBlockHandle; out aValue: TltsFontHandle): TltsErrorCode; stdcall;
  317. TltsTextBlockSetTop = function(const aHandle: TltsTextBlockHandle; const aValue: Integer): TltsErrorCode; stdcall;
  318. TltsTextBlockSetLeft = function(const aHandle: TltsTextBlockHandle; const aValue: Integer): TltsErrorCode; stdcall;
  319. TltsTextBlockSetVertAlign = function(const aHandle: TltsTextBlockHandle; const aValue: TltsVertAlignment): TltsErrorCode; stdcall;
  320. TltsTextBlockSetHorzAlign = function(const aHandle: TltsTextBlockHandle; const aValue: TltsHorzAlignment): TltsErrorCode; stdcall;
  321. TltsTextBlockSetClipping = function(const aHandle: TltsTextBlockHandle; const aValue: TltsClipping): TltsErrorCode; stdcall;
  322. TltsTextBlockSetColor = function(const aHandle: TltsTextBlockHandle; const aValue: TltsColor4f): TltsErrorCode; stdcall;
  323. TltsTextBlockSetFont = function(const aHandle: TltsTextBlockHandle; const aValue: TltsFontHandle): TltsErrorCode; stdcall;
  324. TltsTextBlockGetActualHeight = function(const aHandle: TltsTextBlockHandle): Integer; stdcall;
  325. TltsTextBlockGetTextWidthA = function(const aHandle: TltsTextBlockHandle; const aText: PAnsiChar): Integer; stdcall;
  326. TltsTextBlockGetTextWidthW = function(const aHandle: TltsTextBlockHandle; const aText: PWideChar): Integer; stdcall;
  327. TltsTextBlockTextOutA = function(const aHandle: TltsTextBlockHandle; const aText: PAnsiChar): TltsErrorCode; stdcall;
  328. TltsTextBlockTextOutW = function(const aHandle: TltsTextBlockHandle; const aText: PWideChar): TltsErrorCode; stdcall;
  329. TltsTextBlockDestroy = function(const aHandle: TltsTextBlockHandle): TltsErrorCode; stdcall;
  330. TltsImageCreate = function(const aContext: TltsContextHandle): TltsImageHandle; stdcall;
  331. TltsImageIsEmpty = function(const aHandle: TltsImageHandle; out aValue: Boolean): TltsErrorCode; stdcall;
  332. TltsImageGetWidth = function(const aHandle: TltsImageHandle): Integer; stdcall;
  333. TltsImageGetHeight = function(const aHandle: TltsImageHandle): Integer; stdcall;
  334. TltsImageGetLineSize = function(const aHandle: TltsImageHandle): Integer; stdcall;
  335. TltsImageGetDataSize = function(const aHandle: TltsImageHandle): Integer; stdcall;
  336. TltsImageGetFormat = function(const aHandle: TltsImageHandle; out aValue: TltsFormat): TltsErrorCode; stdcall;
  337. TltsImageGetData = function(const aHandle: TltsImageHandle): Pointer; stdcall;
  338. TltsImageGetScanline = function(const aHandle: TltsImageHandle; const aIndex: Integer): Pointer; stdcall;
  339. TltsImageGetPixelAt = function(const aHandle: TltsImageHandle; const aX, aY: Integer; out aColor: TltsColor4f): TltsErrorCode; stdcall;
  340. TltsImageAssign = function(const aHandle, aSource: TltsImageHandle): TltsErrorCode; stdcall;
  341. TltsImageCreateEmpty = function(const aHandle: TltsImageHandle; const aFormat: TltsFormat; const aWidth, aHeight: Integer): TltsErrorCode; stdcall;
  342. TltsImageLoadFromFunc = function(const aHandle: TltsImageHandle; const aCallback: TltsImageLoadInternFunc; aArgs: Pointer): TltsErrorCode; stdcall;
  343. TltsImageResize = function(const aHandle: TltsImageHandle; const aWidth, aHeight, aX, aY: Integer): TltsErrorCode; stdcall;
  344. TltsImageFillColor = function(const aHandle: TltsImageHandle; const aColor: TltsColor4f; const aMask: TltsColorChannels; const aModes: TltsImageModes): TltsErrorCode; stdcall;
  345. TltsImageFillPattern = function(const aHandle, aPattern: TltsImageHandle; const aX, aY: Integer; const aMask: TltsColorChannels; const aModes: TltsImageModes): TltsErrorCode; stdcall;
  346. TltsImageBlend = function(const aHandle, aSource: TltsImageHandle; const aX, aY: Integer; const aBlendFunc: TltsImageBlendInternFunc; aArgs: Pointer): TltsErrorCode; stdcall;
  347. TltsImageBlur = function(const aHandle: TltsImageHandle; const aHorzRad, aHorzStr, aVertRad, aVertStr: Single; const aMask: TltsColorChannels): TltsErrorCode; stdcall;
  348. TltsImageDestroy = function(const aHandle: TltsImageHandle): TltsErrorCode; stdcall;
  349. TltsPostProcessorAddRange = function(const aHandle: TltsPostProcessorHandle; const aUsage: TltsCharRangeUsage; const aStart, aStop: WideChar): TltsErrorCode; stdcall;
  350. TltsPostProcessorAddChars = function(const aHandle: TltsPostProcessorHandle; const aUsage: TltsCharRangeUsage; const aChars: PWideChar): TltsErrorCode; stdcall;
  351. TltsPostProcessorClearRanges = function(const aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall;
  352. TltsPostProcessorExecute = function (const aHandle: TltsPostProcessorHandle; const aChar: TltsCharHandle; const aImage: TltsImageHandle): TltsErrorCode; stdcall;
  353. TltsPostProcessorFillColorCreate = function(const aContext: TltsContextHandle; const aColor: TltsColor4f; const aModes: TltsImageModes; const aChannels: TltsColorChannels): TltsPostProcessorHandle; stdcall;
  354. TltsPostProcessorFillPatterCreate = function(const aContext: TltsContextHandle; const aPattern: TltsImageHandle; const aOwnsPatter: Boolean; const aPosition: TltsPosition; const aModes: TltsImageModes; const aChannels: TltsColorChannels): TltsPostProcessorHandle; stdcall;
  355. TltsPostProcessorBorderCreate = function(const aContext: TltsContextHandle; const aWidth, aStrength: Single; const aColor: TltsColor4f; const aKeepSize: Boolean): TltsPostProcessorHandle; stdcall;
  356. TltsPostProcessorShadowCreate = function(const aContext: TltsContextHandle; const aRadius, aStrength: Single; const aOffset: TltsPosition; const aColor: TltsColor4f): TltsPostProcessorHandle; stdcall;
  357. TltsPostProcessorCustomCreate = function(const aContext: TltsContextHandle; const aData: PltsPostProcessorCustomData): TltsPostProcessorHandle; stdcall;
  358. TltsPostProcessorDestroy = function(const aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall;
  359. TltsCharGetCharCode = function(const aHandle: TltsCharHandle; out aValue: WideChar): TltsErrorCode; stdcall;
  360. TltsCharGetGlyphMetric = function(const aHandle: TltsCharHandle; out aValue: TltsGlyphMetric): TltsErrorCode; stdcall;
  361. TltsCharSetGlyphMetric = function(const aHandle: TltsCharHandle; const aValue: TltsGlyphMetric): TltsErrorCode; stdcall;
  362. TltsInitialize = function(): TltsErrorCode; stdcall;
  363. TltsGetLastErrorCode = function(): TltsErrorCode; stdcall;
  364. TltsGetLastErrorMsg = function(): PAnsiChar; stdcall;
  365. TltsFinalize = function(): TltsErrorCode; stdcall;
  366. var
  367. ltsContextCreate: TltsContextCreate;
  368. ltsContextGetCodePage: TltsContextGetCodePage;
  369. ltsContextGetDefaultChar: TltsContextGetDefaultChar;
  370. ltsContextSetCodePage: TltsContextSetCodePage;
  371. ltsContextSetDefaultChar: TltsContextSetDefaultChar;
  372. ltsContextAnsiToWide: TltsContextAnsiToWide;
  373. ltsContextDestroy: TltsContextDestroy;
  374. ltsRendererCreate: TltsRendererCreate;
  375. ltsRendererCustomCreate: TltsRendererCustomCreate;
  376. ltsRendererBeginBlock: TltsRendererBeginBlock;
  377. ltsRendererEndBlock: TltsRendererEndBlock;
  378. ltsRendererAbortBlock: TltsRendererAbortBlock;
  379. ltsRendererGetTextWidthA: TltsRendererGetTextWidthA;
  380. ltsRendererGetTextWidthW: TltsRendererGetTextWidthW;
  381. ltsRendererDestroy: TltsRendererDestroy;
  382. ltsFontCreatorCreate: TltsFontCreatorCreate;
  383. ltsFontCreatorGetFontByName: TltsFontCreatorGetFontByName;
  384. ltsFontCreatorGetFontByFile: TltsFontCreatorGetFontByFile;
  385. ltsFontCreatorGetFontByStream: TltsFontCreatorGetFontByStream;
  386. ltsFontCreatorDestroy: TltsFontCreatorDestroy;
  387. ltsFontGetPostProcessor: TltsFontGetPostProcessor;
  388. ltsFontGetTabWidth: TltsFontGetTabWidth;
  389. ltsFontGetCharSpacing: TltsFontGetCharSpacing;
  390. ltsFontGetLineSpacing: TltsFontGetLineSpacing;
  391. ltsFontGetMetric: TltsFontGetMetric;
  392. ltsFontGetFontname: TltsFontGetFontname;
  393. ltsFontGetFacename: TltsFontGetFacename;
  394. ltsFontGetStylename: TltsFontGetStylename;
  395. ltsFontGetFullname: TltsFontGetFullname;
  396. ltsFontGetCopyright: TltsFontGetCopyright;
  397. ltsFontSetPostProcessor: TltsFontSetPostProcessor;
  398. ltsFontSetTabWidth: TltsFontSetTabWidth;
  399. ltsFontSetCharSpacing: TltsFontSetCharSpacing;
  400. ltsFontSetLineSpacing: TltsFontSetLineSpacing;
  401. ltsFontDestroy: TltsFontDestroy;
  402. ltsTextBlockGetRect: TltsTextBlockGetRect;
  403. ltsTextBlockGetWidth: TltsTextBlockGetWidth;
  404. ltsTextBlockGetHeight: TltsTextBlockGetHeight;
  405. ltsTextBlockGetFlags: TltsTextBlockGetFlags;
  406. ltsTextBlockGetTop: TltsTextBlockGetTop;
  407. ltsTextBlockGetLeft: TltsTextBlockGetLeft;
  408. ltsTextBlockGetVertAlign: TltsTextBlockGetVertAlign;
  409. ltsTextBlockGetHorzAlign: TltsTextBlockGetHorzAlign;
  410. ltsTextBlockGetClipping: TltsTextBlockGetClipping;
  411. ltsTextBlockGetColor: TltsTextBlockGetColor;
  412. ltsTextBlockGetFont: TltsTextBlockGetFont;
  413. ltsTextBlockSetTop: TltsTextBlockSetTop;
  414. ltsTextBlockSetLeft: TltsTextBlockSetLeft;
  415. ltsTextBlockSetVertAlign: TltsTextBlockSetVertAlign;
  416. ltsTextBlockSetHorzAlign: TltsTextBlockSetHorzAlign;
  417. ltsTextBlockSetClipping: TltsTextBlockSetClipping;
  418. ltsTextBlockSetColor: TltsTextBlockSetColor;
  419. ltsTextBlockSetFont: TltsTextBlockSetFont;
  420. ltsTextBlockGetActualHeight: TltsTextBlockGetActualHeight;
  421. ltsTextBlockGetTextWidthA: TltsTextBlockGetTextWidthA;
  422. ltsTextBlockGetTextWidthW: TltsTextBlockGetTextWidthW;
  423. ltsTextBlockTextOutA: TltsTextBlockTextOutA;
  424. ltsTextBlockTextOutW: TltsTextBlockTextOutW;
  425. ltsTextBlockDestroy: TltsTextBlockDestroy;
  426. ltsImageCreate: TltsImageCreate;
  427. ltsImageIsEmpty: TltsImageIsEmpty;
  428. ltsImageGetWidth: TltsImageGetWidth;
  429. ltsImageGetHeight: TltsImageGetHeight;
  430. ltsImageGetLineSize: TltsImageGetLineSize;
  431. ltsImageGetDataSize: TltsImageGetDataSize;
  432. ltsImageGetFormat: TltsImageGetFormat;
  433. ltsImageGetData: TltsImageGetData;
  434. ltsImageGetScanline: TltsImageGetScanline;
  435. ltsImageGetPixelAt: TltsImageGetPixelAt;
  436. ltsImageAssign: TltsImageAssign;
  437. ltsImageCreateEmpty: TltsImageCreateEmpty;
  438. ltsImageLoadFromFunc: TltsImageLoadFromFunc;
  439. ltsImageResize: TltsImageResize;
  440. ltsImageFillColor: TltsImageFillColor;
  441. ltsImageFillPattern: TltsImageFillPattern;
  442. ltsImageBlend: TltsImageBlend;
  443. ltsImageBlur: TltsImageBlur;
  444. ltsImageDestroy: TltsImageDestroy;
  445. ltsPostProcessorAddRange: TltsPostProcessorAddRange;
  446. ltsPostProcessorAddChars: TltsPostProcessorAddChars;
  447. ltsPostProcessorClearRanges: TltsPostProcessorClearRanges;
  448. ltsPostProcessorExecute: TltsPostProcessorExecute;
  449. ltsPostProcessorFillColorCreate: TltsPostProcessorFillColorCreate;
  450. ltsPostProcessorFillPatterCreate: TltsPostProcessorFillPatterCreate;
  451. ltsPostProcessorBorderCreate: TltsPostProcessorBorderCreate;
  452. ltsPostProcessorShadowCreate: TltsPostProcessorShadowCreate;
  453. ltsPostProcessorCustomCreate: TltsPostProcessorCustomCreate;
  454. ltsPostProcessorDestroy: TltsPostProcessorDestroy;
  455. ltsCharGetCharCode: TltsCharGetCharCode;
  456. ltsCharGetGlyphMetric: TltsCharGetGlyphMetric;
  457. ltsCharSetGlyphMetric: TltsCharSetGlyphMetric;
  458. ltsGetLastErrorCode: TltsGetLastErrorCode;
  459. ltsGetLastErrorMsg: TltsGetLastErrorMsg;
  460. procedure ltsInitialize(const aLibName: String);
  461. procedure ltsFinalize;
  462. type
  463. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  464. TltsException = class(Exception)
  465. private
  466. fErrorCode: TltsErrorCode;
  467. public
  468. property ErrorCode: TltsErrorCode read fErrorCode;
  469. constructor Create(const aMessage: String; const aErrorCode: TltsErrorCode = ltsErrNone);
  470. end;
  471. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  472. TltsContext = class(TObject)
  473. private
  474. fHandle: TltsContextHandle;
  475. function GetCodePage: TltsCodePage;
  476. function GetDefaultChar: WideChar;
  477. procedure SetCodePage(aValue: TltsCodePage);
  478. procedure SetDefaultChar(aValue: WideChar);
  479. public
  480. property Handle: TltsContextHandle read fHandle;
  481. property CodePage: TltsCodePage read GetCodePage write SetCodePage;
  482. property DefaultChar: WideChar read GetDefaultChar write SetDefaultChar;
  483. constructor Create;
  484. destructor Destroy; override;
  485. end;
  486. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  487. TltsFont = class(TObject)
  488. private
  489. fHandle: TltsFontHandle;
  490. fNames: TltsFontNames;
  491. fMetric: TltsFontMetric;
  492. function GetCharSpacing: Integer;
  493. function GetLineSpacing: Single;
  494. function GetTabWidth: Integer;
  495. procedure SetCharSpacing(aValue: Integer);
  496. procedure SetLineSpacing(aValue: Single);
  497. procedure SetTabWidth(aValue: Integer);
  498. public
  499. property Handle: TltsFontHandle read fHandle;
  500. property Names: TltsFontNames read fNames;
  501. property Metric: TltsFontMetric read fMetric;
  502. property TabWidth: Integer read GetTabWidth write SetTabWidth;
  503. property CharSpacing: Integer read GetCharSpacing write SetCharSpacing;
  504. property LineSpacing: Single read GetLineSpacing write SetLineSpacing;
  505. constructor Create(const aHandle: TltsFontHandle);
  506. destructor Destroy; override;
  507. end;
  508. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  509. TltsFontCreator = class(TObject)
  510. private
  511. fHandle: TltsFontCreatorHandle;
  512. public
  513. property Handle: TltsFontCreatorHandle read fHandle;
  514. function GetFontByName (const aFontname: String; const aSize: Integer; const aStyle: TltsFontStyles; const aAntiAliasing: TltsAntiAliasing): TltsFont;
  515. function GetFontByFile (const aFilename: String; const aSize: Integer; const aStyle: TltsFontStyles; const aAntiAliasing: TltsAntiAliasing): TltsFont;
  516. function GetFontByStream(const aStream: TStream; const aSize: Integer; const aStyle: TltsFontStyles; const aAntiAliasing: TltsAntiAliasing): TltsFont;
  517. constructor Create(const aHandle: TltsFontCreatorHandle);
  518. destructor Destroy; override;
  519. end;
  520. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  521. TltsFontCreatorGDI = class(TltsFontCreator)
  522. public
  523. constructor Create(const aContext: TltsContext);
  524. end;
  525. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  526. TltsFontCreatorFreeType = class(TltsFontCreator)
  527. public
  528. constructor Create(const aContext: TltsContext);
  529. end;
  530. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  531. TltsTextBlock = class(TObject)
  532. private
  533. fHandle: TltsTextBlockHandle;
  534. fCurrentFont: TltsFont;
  535. function GetClipping: TltsClipping;
  536. function GetColor: TltsColor4f;
  537. function GetFlags: TltsBlockFlags;
  538. function GetHeight: Integer;
  539. function GetHorzAlign: TltsHorzAlignment;
  540. function GetLeft: Integer;
  541. function GetRect: TltsRect;
  542. function GetTop: Integer;
  543. function GetVertAlign: TltsVertAlignment;
  544. function GetWidth: Integer;
  545. procedure SetClipping(aValue: TltsClipping);
  546. procedure SetColor(aValue: TltsColor4f);
  547. procedure SetCurrentFont(aValue: TltsFont);
  548. procedure SetHorzAlign(aValue: TltsHorzAlignment);
  549. procedure SetLeft(aValue: Integer);
  550. procedure SetTop(aValue: Integer);
  551. procedure SetVertAlign(aValue: TltsVertAlignment);
  552. public
  553. property Handle: TltsTextBlockHandle read fHandle;
  554. property Rect: TltsRect read GetRect;
  555. property Width: Integer read GetWidth;
  556. property Height: Integer read GetHeight;
  557. property Flags: TltsBlockFlags read GetFlags;
  558. property Top: Integer read GetTop write SetTop;
  559. property Left: Integer read GetLeft write SetLeft;
  560. property VertAlign: TltsVertAlignment read GetVertAlign write SetVertAlign;
  561. property HorzAlign: TltsHorzAlignment read GetHorzAlign write SetHorzAlign;
  562. property Clipping: TltsClipping read GetClipping write SetClipping;
  563. property CurrentColor: TltsColor4f read GetColor write SetColor;
  564. property CurrentFont: TltsFont read fCurrentFont write SetCurrentFont;
  565. function GetActualBlockHeight: Integer;
  566. procedure ChangeFont(const aFont: TltsFont);
  567. procedure ChangeColor(const aColor: TltsColor4f);
  568. procedure TextOutA(const aText: PAnsiChar);
  569. procedure TextOutW(const aText: PWideChar);
  570. function GetTextWidthA(const aText: PAnsiChar): Integer;
  571. function GetTextWidthW(const aText: PWideChar): Integer;
  572. constructor Create(const aHandle: TltsTextBlockHandle);
  573. destructor Destroy; override;
  574. end;
  575. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  576. TltsImage = class(TObject)
  577. private
  578. fHandle: TltsImageHandle;
  579. fOwnsHandle: Boolean;
  580. function GetData: Pointer;
  581. function GetDataSize: Integer;
  582. function GetFormat: TltsFormat;
  583. function GetHeight: Integer;
  584. function GetIsEmpty: Boolean;
  585. function GetLineSize: Integer;
  586. function GetWidth: Integer;
  587. function GetScanline(const aIndex: Integer): Pointer;
  588. public
  589. property Handle: TltsImageHandle read fHandle;
  590. property IsEmpty: Boolean read GetIsEmpty;
  591. property Width: Integer read GetWidth;
  592. property Height: Integer read GetHeight;
  593. property LineSize: Integer read GetLineSize;
  594. property DataSize: Integer read GetDataSize;
  595. property Format: TltsFormat read GetFormat;
  596. property Data: Pointer read GetData;
  597. property Scanline[const aIndex: Integer]: Pointer read GetScanline;
  598. function GetPixelAt(const x, y: Integer; out aColor: TltsColor4f): Boolean;
  599. procedure Assign(const aImage: TltsImage);
  600. procedure CreateEmpty(const aFormat: TltsFormat; const aWidth, aHeight: Integer);
  601. procedure LoadFromFunc(const aFunc: TltsImageLoadFunc; const aArgs: Pointer);
  602. procedure Resize(const aWidth, aHeight, X, Y: Integer);
  603. procedure FillColor(const aColor: TltsColor4f; const aMask: TltsColorChannels; const aModes: TltsImageModes);
  604. procedure FillPatter(const aPattern: TltsImage; const X, Y: Integer; const aMask: TltsColorChannels; const aModes: TltsImageModes);
  605. procedure Blend(const aImage: TltsImage; const X, Y: Integer; const aFunc: TltsImageBlendFunc; aArgs: Pointer);
  606. procedure Blur(const aHorzRad, aHorzStr, aVertRad, aVertStr: Single; const aMask: TltsColorChannels);
  607. constructor Create(const aHandle: TltsImageHandle);
  608. constructor Create(const aContext: TltsContext);
  609. destructor Destroy; override;
  610. end;
  611. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  612. TltsChar = class(TObject)
  613. private
  614. fHandle: TltsCharHandle;
  615. function GetCharCode: WideChar;
  616. function GetGlyphMetric: TltsGlyphMetric;
  617. procedure SetGlyphMetric(aValue: TltsGlyphMetric);
  618. public
  619. property Handle: TltsCharHandle read fHandle;
  620. property CharCode: WideChar read GetCharCode;
  621. property GlyphMetric: TltsGlyphMetric read GetGlyphMetric write SetGlyphMetric;
  622. constructor Create(const aHandle: TltsCharHandle);
  623. end;
  624. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  625. TltsRenderer = class(TObject)
  626. private
  627. fHandle: TltsRendererHandle;
  628. public
  629. property Handle: TltsRendererHandle read fHandle;
  630. function BeginBlock(const aTop, aLeft, aWidth, aHeight: Integer; const aFlags: TltsBlockFlags): TltsTextBlock;
  631. procedure EndBlock(var aTextBlock: TltsTextBlock);
  632. procedure AbortBlock(var aTextBlock: TltsTextBlock);
  633. function GetTextWidthA(const aFont: TltsFont; const aText: PAnsiChar): Integer;
  634. function GetTextWidthW(const aFont: TltsFont; const aText: PWideChar): Integer;
  635. constructor Create(const aHandle: TltsRendererHandle);
  636. destructor Destroy; override;
  637. end;
  638. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  639. TltsRendererOpenGL = class(TltsRenderer)
  640. public
  641. constructor Create(const aContext: TltsContext; const aFormat: TltsFormat);
  642. end;
  643. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  644. TltsRendererOpenGLES = class(TltsRenderer)
  645. public
  646. constructor Create(const aContext: TltsContext; const aFormat: TltsFormat);
  647. end;
  648. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  649. TltsRendererCustom = class(TltsRenderer)
  650. protected
  651. fDrawPos: TltsPosition;
  652. fColor: TltsColor4f;
  653. procedure BeginRender; virtual;
  654. procedure EndRender; virtual;
  655. function GetDrawPos: TltsPosition; virtual;
  656. procedure SetDrawPos(const aValue: TltsPosition); virtual;
  657. procedure MoveDrawPos(const aOffset: TltsPosition); virtual;
  658. procedure SetColor(const aValue: TltsColor4f); virtual;
  659. procedure Render(const aRenderRef: Pointer; const aForcedWidth: Integer = 0); virtual;
  660. protected
  661. function CreateRenderRef(const aChar: TltsChar; const aImage: TltsImage): Pointer; virtual;
  662. procedure FreeRenderRef(const aRenderRef: Pointer); virtual;
  663. public
  664. constructor Create(const aContext: TltsContext; const aFormat: TltsFormat);
  665. end;
  666. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  667. TltsPostProcessor = class(TObject)
  668. private
  669. fHandle: TltsPostProcessorHandle;
  670. protected
  671. procedure Execute(const aChar: TltsChar; const aImage: TltsImage); virtual;
  672. public
  673. property Handle: TltsPostProcessorHandle read fHandle;
  674. procedure AddRange(const aUsage: TltsCharRangeUsage; const aStart, aStop: WideChar);
  675. procedure AddChars(const aUsage: TltsCharRangeUsage; const aChars: PWideChar);
  676. procedure ClearRanges;
  677. constructor Create(const aHandle: TltsPostProcessorHandle);
  678. destructor Destroy; override;
  679. end;
  680. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  681. TltsPostProcessorFillColor = class(TltsPostProcessor)
  682. private
  683. fColor: TltsColor4f;
  684. fModes: TltsImageModes;
  685. fChannels: TltsColorChannels;
  686. public
  687. property Color: TltsColor4f read fColor;
  688. property Modes: TltsImageModes read fModes;
  689. property Channels: TltsColorChannels read fChannels;
  690. constructor Create(const aContext: TltsContext; const aColor: TltsColor4f; const aModes: TltsImageModes; const aChannels: TltsColorChannels);
  691. end;
  692. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  693. TltsPostProcessorFillPattern = class(TltsPostProcessor)
  694. private
  695. fPattern: TltsImage;
  696. fOwnsPattern: Boolean;
  697. fPosition: TltsPosition;
  698. fModes: TltsImageModes;
  699. fChannels: TltsColorChannels;
  700. public
  701. property Pattern: TltsImage read fPattern;
  702. property OwnsPattern: Boolean read fOwnsPattern;
  703. property Position: TltsPosition read fPosition;
  704. property Modes: TltsImageModes read fModes;
  705. property Channels: TltsColorChannels read fChannels;
  706. constructor Create(const aContext: TltsContext; const aPattern: TltsImage; const aOwnsPatter: Boolean; const aPosition: TltsPosition; const aModes: TltsImageModes; const aChannels: TltsColorChannels);
  707. destructor Destroy; override;
  708. end;
  709. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  710. TltsPostProcessorBorder = class(TltsPostProcessor)
  711. private
  712. fWidth: Single;
  713. fStrength: Single;
  714. fColor: TltsColor4f;
  715. fKeepSize: Boolean;
  716. public
  717. property Width: Single read fWidth;
  718. property Strength: Single read fStrength;
  719. property Color: TltsColor4f read fColor;
  720. property KeepSize: Boolean read fKeepSize;
  721. constructor Create(const aContext: TltsContext; const aWidth, aStrength: Single; const aColor: TltsColor4f; const aKeepSize: Boolean);
  722. end;
  723. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  724. TltsPostProcessorShadow = class(TltsPostProcessor)
  725. private
  726. fRadius: Single;
  727. fStrength: Single;
  728. fOffset: TltsPosition;
  729. fColor: TltsColor4f;
  730. public
  731. property Radius: Single read fRadius;
  732. property Strength: Single read fStrength;
  733. property Offset: TltsPosition read fOffset;
  734. property Color: TltsColor4f read fColor;
  735. constructor Create(const aContext: TltsContext; const aRadius, aStrength: Single; const aOffset: TltsPosition; const aColor: TltsColor4f);
  736. end;
  737. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  738. TltsPostProcessorCustom = class(TltsPostProcessor)
  739. public
  740. constructor Create(const aContext: TltsContext);
  741. end;
  742. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  743. TltsPostProcessorList = class(TltsPostProcessorCustom)
  744. private
  745. fItems: TObjectList;
  746. function GetCount: Integer;
  747. function GetItem(const aIndex: Integer): TltsPostProcessor;
  748. function GetOwnsObjects: Boolean;
  749. procedure SetOwnsObjects(aValue: Boolean);
  750. protected
  751. procedure Execute(const aChar: TltsChar; const aImage: TltsImage); override;
  752. public
  753. property Count: Integer read GetCount;
  754. property OwnsObjects: Boolean read GetOwnsObjects write SetOwnsObjects;
  755. property Items[const aIndex: Integer]: TltsPostProcessor read GetItem;
  756. procedure Add(const aPostProcessor: TltsPostProcessor);
  757. procedure Delete(const aIndex: Integer);
  758. procedure Clear;
  759. function Remove(const aPostProcessor: TltsPostProcessor): Integer;
  760. function IndexOf(const aPostProcessor: TltsPostProcessor): Integer;
  761. constructor Create(const aContext: TltsContext; const aOwnsObjects: Boolean);
  762. destructor Destroy; override;
  763. end;
  764. implementation
  765. {$IF DEFINED(WIN32) OR DEFINED(WIN64)}
  766. uses
  767. windows;
  768. type
  769. TLibHandle = HMODULE;
  770. const
  771. InvalidLibHandle: TLibHandle = 0;
  772. function LibOpen(const aLibName: String; out aError: String): TLibHandle;
  773. begin
  774. result := LoadLibraryA(PAnsiChar(AnsiString(aLibName)));
  775. if (result = 0)
  776. then aError := SysErrorMessage(GetLastError())
  777. else aError := '';
  778. end;
  779. function GetAddr(const aLibHandle: TLibHandle; const aName: String): Pointer;
  780. begin
  781. result := GetProcAddress(aLibHandle, PAnsiChar(AnsiString(aName)));
  782. end;
  783. procedure LibClose(const aLibHandle: TLibHandle);
  784. begin
  785. FreeLibrary(aLibHandle);
  786. end;
  787. {$ELSEIF DEFINED(LINUX)}
  788. uses
  789. dl;
  790. type
  791. TLibHandle = Pointer;
  792. const
  793. InvalidLibHandle: TLibHandle = nil;
  794. function LibOpen(const aLibName: String; out aError: String): TLibHandle;
  795. begin
  796. dlerror();
  797. result := dlopen(PChar(aLibName), RTLD_LAZY);
  798. if (result = InvalidLibHandle)
  799. then aError := dlerror()
  800. else aError := '';
  801. end;
  802. function GetAddr(const aLibHandle: TLibHandle; const aName: String): Pointer;
  803. begin
  804. result := dlsym(aLibHandle, PChar(aName));
  805. end;
  806. procedure LibClose(const aLibHandle: TLibHandle);
  807. begin
  808. dlclose(aLibHandle);
  809. end;
  810. {$ELSE}
  811. {$ERROR 'unknown operation system'}
  812. {$IFEND}
  813. var
  814. libHandle: TLibHandle;
  815. ltsInitializeIntern: TltsInitialize;
  816. ltsFinalizeIntern: TltsFinalize;
  817. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  818. //Stream Callbacks//////////////////////////////////////////////////////////////////////////////////////////////////////
  819. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  820. function ltsStreamReadCallback(const aArgs: Pointer; const aBuffer: Pointer; const aSize: Integer): Integer; stdcall;
  821. var
  822. s: TStream;
  823. begin
  824. result := 0;
  825. if not Assigned(aArgs) then
  826. exit;
  827. s := TStream(aArgs);
  828. result := s.Read(aBuffer^, aSize);
  829. end;
  830. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  831. function ltsStreamSeekCallback(const aArgs: Pointer; const aOrigin: TltsStreamOrigin; const aPos: Integer): Integer; stdcall;
  832. var
  833. s: TStream;
  834. begin
  835. result := 0;
  836. if not Assigned(aArgs) then
  837. exit;
  838. s := TStream(aArgs);
  839. result := s.Seek(aPos, TSeekOrigin(aOrigin));
  840. end;
  841. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  842. //Image Callbacks///////////////////////////////////////////////////////////////////////////////////////////////////////
  843. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  844. type
  845. PImageLoadArgs = ^TImageLoadArgs;
  846. TImageLoadArgs = packed record
  847. callback: TltsImageLoadFunc;
  848. image: TltsImage;
  849. args: Pointer;
  850. end;
  851. PImageBlendArgs = ^TImageBlendArgs;
  852. TImageBlendArgs = packed record
  853. callback: TltsImageBlendFunc;
  854. args: Pointer;
  855. end;
  856. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  857. procedure ltsImageLoadCallback(const aHandle: TltsImageHandle; const X, Y: Integer; var aPixel: TltsColor4f; aArgs: Pointer); stdcall;
  858. var
  859. p: PImageLoadArgs;
  860. begin
  861. p := PImageLoadArgs(aArgs);
  862. p^.callback(p^.image, X, Y, aPixel, p^.args);
  863. end;
  864. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  865. function ltsImageBlendCallback(const aHandle: TltsImageHandle; const aSrc, aDst: TltsColor4f; aArgs: Pointer): TltsColor4f; stdcall;
  866. var
  867. p: PImageBlendArgs;
  868. begin
  869. p := PImageBlendArgs(aArgs);
  870. result := p^.callback(aSrc, aDst, p^.args);
  871. end;
  872. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  873. //General///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  874. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  875. procedure ltsInitialize(const aLibName: String);
  876. function LoadProc(const aName: String): Pointer;
  877. begin
  878. result := GetAddr(libHandle, aName);
  879. if not Assigned(result) then
  880. raise TltsException.CreateFmt('unable to load ''%s'' from ''%s''', [aName, aLibName]);
  881. end;
  882. var
  883. eMsg: String;
  884. err: TltsErrorCode;
  885. begin
  886. libHandle := LibOpen(aLibName, eMsg);
  887. if (libHandle = InvalidLibHandle) then
  888. raise TltsException.Create('unable to load library: ' + eMsg);
  889. ltsContextCreate := TltsContextCreate( LoadProc('ltsContextCreate'));
  890. ltsContextGetCodePage := TltsContextGetCodePage( LoadProc('ltsContextGetCodePage'));
  891. ltsContextGetDefaultChar := TltsContextGetDefaultChar( LoadProc('ltsContextGetDefaultChar'));
  892. ltsContextSetCodePage := TltsContextSetCodePage( LoadProc('ltsContextSetCodePage'));
  893. ltsContextSetDefaultChar := TltsContextSetDefaultChar( LoadProc('ltsContextSetDefaultChar'));
  894. ltsContextAnsiToWide := TltsContextAnsiToWide( LoadProc('ltsContextAnsiToWide'));
  895. ltsContextDestroy := TltsContextDestroy( LoadProc('ltsContextDestroy'));
  896. ltsRendererCreate := TltsRendererCreate( LoadProc('ltsRendererCreate'));
  897. ltsRendererCustomCreate := TltsRendererCustomCreate( LoadProc('ltsRendererCustomCreate'));
  898. ltsRendererBeginBlock := TltsRendererBeginBlock( LoadProc('ltsRendererBeginBlock'));
  899. ltsRendererEndBlock := TltsRendererEndBlock( LoadProc('ltsRendererEndBlock'));
  900. ltsRendererAbortBlock := TltsRendererAbortBlock( LoadProc('ltsRendererAbortBlock'));
  901. ltsRendererGetTextWidthA := TltsRendererGetTextWidthA( LoadProc('ltsRendererGetTextWidthA'));
  902. ltsRendererGetTextWidthW := TltsRendererGetTextWidthW( LoadProc('ltsRendererGetTextWidthW'));
  903. ltsRendererDestroy := TltsRendererDestroy( LoadProc('ltsRendererDestroy'));
  904. ltsFontCreatorCreate := TltsFontCreatorCreate( LoadProc('ltsFontCreatorCreate'));
  905. ltsFontCreatorGetFontByName := TltsFontCreatorGetFontByName( LoadProc('ltsFontCreatorGetFontByName'));
  906. ltsFontCreatorGetFontByFile := TltsFontCreatorGetFontByFile( LoadProc('ltsFontCreatorGetFontByFile'));
  907. ltsFontCreatorGetFontByStream := TltsFontCreatorGetFontByStream( LoadProc('ltsFontCreatorGetFontByStream'));
  908. ltsFontCreatorDestroy := TltsFontCreatorDestroy( LoadProc('ltsFontCreatorDestroy'));
  909. ltsFontGetPostProcessor := TltsFontGetPostProcessor( LoadProc('ltsFontGetPostProcessor'));
  910. ltsFontGetTabWidth := TltsFontGetTabWidth( LoadProc('ltsFontGetTabWidth'));
  911. ltsFontGetCharSpacing := TltsFontGetCharSpacing( LoadProc('ltsFontGetCharSpacing'));
  912. ltsFontGetLineSpacing := TltsFontGetLineSpacing( LoadProc('ltsFontGetLineSpacing'));
  913. ltsFontGetMetric := TltsFontGetMetric( LoadProc('ltsFontGetMetric'));
  914. ltsFontGetFontname := TltsFontGetFontname( LoadProc('ltsFontGetFontname'));
  915. ltsFontGetFacename := TltsFontGetFacename( LoadProc('ltsFontGetFacename'));
  916. ltsFontGetStylename := TltsFontGetStylename( LoadProc('ltsFontGetStylename'));
  917. ltsFontGetFullname := TltsFontGetFullname( LoadProc('ltsFontGetFullname'));
  918. ltsFontGetCopyright := TltsFontGetCopyright( LoadProc('ltsFontGetCopyright'));
  919. ltsFontSetPostProcessor := TltsFontSetPostProcessor( LoadProc('ltsFontSetPostProcessor'));
  920. ltsFontSetTabWidth := TltsFontSetTabWidth( LoadProc('ltsFontSetTabWidth'));
  921. ltsFontSetCharSpacing := TltsFontSetCharSpacing( LoadProc('ltsFontSetCharSpacing'));
  922. ltsFontSetLineSpacing := TltsFontSetLineSpacing( LoadProc('ltsFontSetLineSpacing'));
  923. ltsFontDestroy := TltsFontDestroy( LoadProc('ltsFontDestroy'));
  924. ltsTextBlockGetRect := TltsTextBlockGetRect( LoadProc('ltsTextBlockGetRect'));
  925. ltsTextBlockGetWidth := TltsTextBlockGetWidth( LoadProc('ltsTextBlockGetWidth'));
  926. ltsTextBlockGetHeight := TltsTextBlockGetHeight( LoadProc('ltsTextBlockGetHeight'));
  927. ltsTextBlockGetFlags := TltsTextBlockGetFlags( LoadProc('ltsTextBlockGetFlags'));
  928. ltsTextBlockGetTop := TltsTextBlockGetTop( LoadProc('ltsTextBlockGetTop'));
  929. ltsTextBlockGetLeft := TltsTextBlockGetLeft( LoadProc('ltsTextBlockGetLeft'));
  930. ltsTextBlockGetVertAlign := TltsTextBlockGetVertAlign( LoadProc('ltsTextBlockGetVertAlign'));
  931. ltsTextBlockGetHorzAlign := TltsTextBlockGetHorzAlign( LoadProc('ltsTextBlockGetHorzAlign'));
  932. ltsTextBlockGetClipping := TltsTextBlockGetClipping( LoadProc('ltsTextBlockGetClipping'));
  933. ltsTextBlockGetColor := TltsTextBlockGetColor( LoadProc('ltsTextBlockGetColor'));
  934. ltsTextBlockGetFont := TltsTextBlockGetFont( LoadProc('ltsTextBlockGetFont'));
  935. ltsTextBlockSetTop := TltsTextBlockSetTop( LoadProc('ltsTextBlockSetTop'));
  936. ltsTextBlockSetLeft := TltsTextBlockSetLeft( LoadProc('ltsTextBlockSetLeft'));
  937. ltsTextBlockSetVertAlign := TltsTextBlockSetVertAlign( LoadProc('ltsTextBlockSetVertAlign'));
  938. ltsTextBlockSetHorzAlign := TltsTextBlockSetHorzAlign( LoadProc('ltsTextBlockSetHorzAlign'));
  939. ltsTextBlockSetClipping := TltsTextBlockSetClipping( LoadProc('ltsTextBlockSetClipping'));
  940. ltsTextBlockSetColor := TltsTextBlockSetColor( LoadProc('ltsTextBlockSetColor'));
  941. ltsTextBlockSetFont := TltsTextBlockSetFont( LoadProc('ltsTextBlockSetFont'));
  942. ltsTextBlockGetActualHeight := TltsTextBlockGetActualHeight( LoadProc('ltsTextBlockGetActualHeight'));
  943. ltsTextBlockGetTextWidthA := TltsTextBlockGetTextWidthA( LoadProc('ltsTextBlockGetTextWidthA'));
  944. ltsTextBlockGetTextWidthW := TltsTextBlockGetTextWidthW( LoadProc('ltsTextBlockGetTextWidthW'));
  945. ltsTextBlockTextOutA := TltsTextBlockTextOutA( LoadProc('ltsTextBlockTextOutA'));
  946. ltsTextBlockTextOutW := TltsTextBlockTextOutW( LoadProc('ltsTextBlockTextOutW'));
  947. ltsTextBlockDestroy := TltsTextBlockDestroy( LoadProc('ltsTextBlockDestroy'));
  948. ltsImageCreate := TltsImageCreate( LoadProc('ltsImageCreate'));
  949. ltsImageIsEmpty := TltsImageIsEmpty( LoadProc('ltsImageIsEmpty'));
  950. ltsImageGetWidth := TltsImageGetWidth( LoadProc('ltsImageGetWidth'));
  951. ltsImageGetHeight := TltsImageGetHeight( LoadProc('ltsImageGetHeight'));
  952. ltsImageGetLineSize := TltsImageGetLineSize( LoadProc('ltsImageGetLineSize'));
  953. ltsImageGetDataSize := TltsImageGetDataSize( LoadProc('ltsImageGetDataSize'));
  954. ltsImageGetFormat := TltsImageGetFormat( LoadProc('ltsImageGetFormat'));
  955. ltsImageGetData := TltsImageGetData( LoadProc('ltsImageGetData'));
  956. ltsImageGetScanline := TltsImageGetScanline( LoadProc('ltsImageGetScanline'));
  957. ltsImageGetPixelAt := TltsImageGetPixelAt( LoadProc('lstImageGetPixelAt'));
  958. ltsImageAssign := TltsImageAssign( LoadProc('ltsImageAssign'));
  959. ltsImageCreateEmpty := TltsImageCreateEmpty( LoadProc('ltsImageCreateEmpty'));
  960. ltsImageLoadFromFunc := TltsImageLoadFromFunc( LoadProc('ltsImageLoadFromFunc'));
  961. ltsImageResize := TltsImageResize( LoadProc('ltsImageResize'));
  962. ltsImageFillColor := TltsImageFillColor( LoadProc('ltsImageFillColor'));
  963. ltsImageFillPattern := TltsImageFillPattern( LoadProc('ltsImageFillPattern'));
  964. ltsImageBlend := TltsImageBlend( LoadProc('ltsImageBlend'));
  965. ltsImageBlur := TltsImageBlur( LoadProc('ltsImageBlur'));
  966. ltsImageDestroy := TltsImageDestroy( LoadProc('ltsImageDestroy'));
  967. ltsPostProcessorAddRange := TltsPostProcessorAddRange( LoadProc('ltsPostProcessorAddRange'));
  968. ltsPostProcessorAddChars := TltsPostProcessorAddChars( LoadProc('ltsPostProcessorAddChars'));
  969. ltsPostProcessorClearRanges := TltsPostProcessorClearRanges( LoadProc('ltsPostProcessorClearRanges'));
  970. ltsPostProcessorExecute := TltsPostProcessorExecute( LoadProc('ltsPostProcessorExecute'));
  971. ltsPostProcessorFillColorCreate := TltsPostProcessorFillColorCreate( LoadProc('ltsPostProcessorFillColorCreate'));
  972. ltsPostProcessorFillPatterCreate := TltsPostProcessorFillPatterCreate( LoadProc('ltsPostProcessorFillPatterCreate'));
  973. ltsPostProcessorBorderCreate := TltsPostProcessorBorderCreate( LoadProc('ltsPostProcessorBorderCreate'));
  974. ltsPostProcessorShadowCreate := TltsPostProcessorShadowCreate( LoadProc('ltsPostProcessorShadowCreate'));
  975. ltsPostProcessorCustomCreate := TltsPostProcessorCustomCreate( LoadProc('ltsPostProcessorCustomCreate'));
  976. ltsPostProcessorDestroy := TltsPostProcessorDestroy( LoadProc('ltsPostProcessorShadowCreate'));
  977. ltsCharGetCharCode := TltsCharGetCharCode( LoadProc('ltsCharGetCharCode'));
  978. ltsCharGetGlyphMetric := TltsCharGetGlyphMetric( LoadProc('ltsCharGetGlyphMetric'));
  979. ltsCharSetGlyphMetric := TltsCharSetGlyphMetric( LoadProc('ltsCharSetGlyphMetric'));
  980. ltsInitializeIntern := TltsInitialize( LoadProc('ltsInitialize'));
  981. ltsGetLastErrorCode := TltsGetLastErrorCode( LoadProc('ltsGetLastErrorCode'));
  982. ltsGetLastErrorMsg := TltsGetLastErrorMsg( LoadProc('ltsGetLastErrorMsg'));
  983. ltsFinalizeIntern := TltsFinalize( LoadProc('ltsFinalize'));
  984. err := ltsInitializeIntern();
  985. if (err <> ltsErrNone) then
  986. raise TltsException.Create('error while initializing library: ' + ltsGetLastErrorMsg(), err);
  987. end;
  988. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  989. procedure ltsFinalize;
  990. begin
  991. if Assigned(ltsFinalizeIntern) then
  992. ltsFinalizeIntern();
  993. ltsContextCreate := nil;
  994. ltsContextGetCodePage := nil;
  995. ltsContextGetDefaultChar := nil;
  996. ltsContextSetCodePage := nil;
  997. ltsContextSetDefaultChar := nil;
  998. ltsContextAnsiToWide := nil;
  999. ltsContextDestroy := nil;
  1000. ltsRendererCreate := nil;
  1001. ltsRendererBeginBlock := nil;
  1002. ltsRendererEndBlock := nil;
  1003. ltsRendererAbortBlock := nil;
  1004. ltsRendererGetTextWidthA := nil;
  1005. ltsRendererGetTextWidthW := nil;
  1006. ltsRendererDestroy := nil;
  1007. ltsFontCreatorCreate := nil;
  1008. ltsFontCreatorGetFontByName := nil;
  1009. ltsFontCreatorGetFontByFile := nil;
  1010. ltsFontCreatorGetFontByStream := nil;
  1011. ltsFontCreatorDestroy := nil;
  1012. ltsFontGetPostProcessor := nil;
  1013. ltsFontGetTabWidth := nil;
  1014. ltsFontGetCharSpacing := nil;
  1015. ltsFontGetLineSpacing := nil;
  1016. ltsFontGetMetric := nil;
  1017. ltsFontGetFontname := nil;
  1018. ltsFontGetFacename := nil;
  1019. ltsFontGetStylename := nil;
  1020. ltsFontGetFullname := nil;
  1021. ltsFontGetCopyright := nil;
  1022. ltsFontSetPostProcessor := nil;
  1023. ltsFontSetTabWidth := nil;
  1024. ltsFontSetCharSpacing := nil;
  1025. ltsFontSetLineSpacing := nil;
  1026. ltsTextBlockGetRect := nil;
  1027. ltsTextBlockGetWidth := nil;
  1028. ltsTextBlockGetHeight := nil;
  1029. ltsTextBlockGetFlags := nil;
  1030. ltsTextBlockGetTop := nil;
  1031. ltsTextBlockGetLeft := nil;
  1032. ltsTextBlockGetVertAlign := nil;
  1033. ltsTextBlockGetHorzAlign := nil;
  1034. ltsTextBlockGetClipping := nil;
  1035. ltsTextBlockGetColor := nil;
  1036. ltsTextBlockGetFont := nil;
  1037. ltsTextBlockSetTop := nil;
  1038. ltsTextBlockSetLeft := nil;
  1039. ltsTextBlockSetVertAlign := nil;
  1040. ltsTextBlockSetHorzAlign := nil;
  1041. ltsTextBlockSetClipping := nil;
  1042. ltsTextBlockSetColor := nil;
  1043. ltsTextBlockSetFont := nil;
  1044. ltsTextBlockGetActualHeight := nil;
  1045. ltsTextBlockGetTextWidthA := nil;
  1046. ltsTextBlockGetTextWidthW := nil;
  1047. ltsTextBlockTextOutA := nil;
  1048. ltsTextBlockTextOutW := nil;
  1049. ltsImageCreate := nil;
  1050. ltsImageIsEmpty := nil;
  1051. ltsImageGetWidth := nil;
  1052. ltsImageGetHeight := nil;
  1053. ltsImageGetLineSize := nil;
  1054. ltsImageGetDataSize := nil;
  1055. ltsImageGetFormat := nil;
  1056. ltsImageGetData := nil;
  1057. ltsImageGetScanline := nil;
  1058. ltsImageGetPixelAt := nil;
  1059. ltsImageAssign := nil;
  1060. ltsImageCreateEmpty := nil;
  1061. ltsImageLoadFromFunc := nil;
  1062. ltsImageResize := nil;
  1063. ltsImageFillColor := nil;
  1064. ltsImageFillPattern := nil;
  1065. ltsImageBlend := nil;
  1066. ltsImageBlur := nil;
  1067. ltsImageDestroy := nil;
  1068. ltsPostProcessorAddRange := nil;
  1069. ltsPostProcessorAddChars := nil;
  1070. ltsPostProcessorClearRanges := nil;
  1071. ltsPostProcessorFillColorCreate := nil;
  1072. ltsPostProcessorFillPatterCreate := nil;
  1073. ltsPostProcessorBorderCreate := nil;
  1074. ltsPostProcessorShadowCreate := nil;
  1075. ltsInitializeIntern := nil;
  1076. ltsGetLastErrorCode := nil;
  1077. ltsGetLastErrorMsg := nil;
  1078. ltsFinalizeIntern := nil;
  1079. if (libHandle <> InvalidLibHandle) then begin
  1080. LibClose(libHandle);
  1081. libHandle := InvalidLibHandle;
  1082. end;
  1083. end;
  1084. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1085. //TltsException/////////////////////////////////////////////////////////////////////////////////////////////////////////
  1086. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1087. constructor TltsException.Create(const aMessage: String; const aErrorCode: TltsErrorCode);
  1088. begin
  1089. inherited Create(aMessage);
  1090. fErrorCode := aErrorCode;
  1091. end;
  1092. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1093. //TltsContext///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1094. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1095. function TltsContext.GetCodePage: TltsCodePage;
  1096. var
  1097. err: TltsErrorCode;
  1098. begin
  1099. err := ltsContextGetCodePage(fHandle, result);
  1100. if (err <> ltsErrNone) then
  1101. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1102. end;
  1103. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1104. function TltsContext.GetDefaultChar: WideChar;
  1105. var
  1106. err: TltsErrorCode;
  1107. begin
  1108. err := ltsContextGetDefaultChar(fHandle, result);
  1109. if (err <> ltsErrNone) then
  1110. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1111. end;
  1112. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1113. procedure TltsContext.SetCodePage(aValue: TltsCodePage);
  1114. var
  1115. err: TltsErrorCode;
  1116. begin
  1117. err := ltsContextSetCodePage(fHandle, aValue);
  1118. if (err <> ltsErrNone) then
  1119. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1120. end;
  1121. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1122. procedure TltsContext.SetDefaultChar(aValue: WideChar);
  1123. var
  1124. err: TltsErrorCode;
  1125. begin
  1126. err := ltsContextSetDefaultChar(fHandle, aValue);
  1127. if (err <> ltsErrNone) then
  1128. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1129. end;
  1130. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1131. constructor TltsContext.Create;
  1132. begin
  1133. inherited Create;
  1134. fHandle := ltsContextCreate();
  1135. if not Assigned(fHandle) then
  1136. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1137. end;
  1138. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1139. destructor TltsContext.Destroy;
  1140. begin
  1141. if Assigned(fHandle) then begin
  1142. ltsContextDestroy(fHandle);
  1143. fHandle := nil;
  1144. end;
  1145. inherited Destroy;
  1146. end;
  1147. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1148. //TltsFont//////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1149. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1150. function TltsFont.GetCharSpacing: Integer;
  1151. var
  1152. err: TltsErrorCode;
  1153. begin
  1154. err := ltsFontGetCharSpacing(fHandle, result);
  1155. if (err <> ltsErrNone) then
  1156. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1157. end;
  1158. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1159. function TltsFont.GetLineSpacing: Single;
  1160. var
  1161. err: TltsErrorCode;
  1162. begin
  1163. err := ltsFontGetLineSpacing(fHandle, result);
  1164. if (err <> ltsErrNone) then
  1165. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1166. end;
  1167. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1168. function TltsFont.GetTabWidth: Integer;
  1169. var
  1170. err: TltsErrorCode;
  1171. begin
  1172. err := ltsFontGetTabWidth(fHandle, result);
  1173. if (err <> ltsErrNone) then
  1174. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1175. end;
  1176. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1177. procedure TltsFont.SetCharSpacing(aValue: Integer);
  1178. var
  1179. err: TltsErrorCode;
  1180. begin
  1181. err := ltsFontSetCharSpacing(fHandle, aValue);
  1182. if (err <> ltsErrNone) then
  1183. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1184. end;
  1185. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1186. procedure TltsFont.SetLineSpacing(aValue: Single);
  1187. var
  1188. err: TltsErrorCode;
  1189. begin
  1190. err := ltsFontSetLineSpacing(fHandle, aValue);
  1191. if (err <> ltsErrNone) then
  1192. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1193. end;
  1194. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1195. procedure TltsFont.SetTabWidth(aValue: Integer);
  1196. var
  1197. err: TltsErrorCode;
  1198. begin
  1199. err := ltsFontSetTabWidth(fHandle, aValue);
  1200. if (err <> ltsErrNone) then
  1201. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1202. end;
  1203. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1204. constructor TltsFont.Create(const aHandle: TltsFontHandle);
  1205. procedure HandleErr(const aError: TltsErrorCode);
  1206. begin
  1207. if (aError <> ltsErrNone) then
  1208. raise TltsException.Create(ltsGetLastErrorMsg(), aError);
  1209. end;
  1210. procedure HandleName(const aValue: PAnsiChar; var aName: String);
  1211. begin
  1212. if not Assigned(aValue) then
  1213. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1214. aName := aValue;
  1215. end;
  1216. begin
  1217. inherited Create;
  1218. fHandle := aHandle;
  1219. HandleErr (ltsFontGetMetric(fHandle, fMetric));
  1220. HandleName(ltsFontGetCopyright(fHandle), fNames.Copyright);
  1221. HandleName(ltsFontGetFacename(fHandle), fNames.Facename);
  1222. HandleName(ltsFontGetFontname(fHandle), fNames.Fontname);
  1223. HandleName(ltsFontGetFullname(fHandle), fNames.Fullname);
  1224. HandleName(ltsFontGetStylename(fHandle), fNames.Stylename);
  1225. end;
  1226. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1227. destructor TltsFont.Destroy;
  1228. begin
  1229. if Assigned(fHandle) then begin
  1230. ltsFontDestroy(fHandle);
  1231. fHandle := nil;
  1232. end;
  1233. inherited Destroy;
  1234. end;
  1235. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1236. //TltsFontCreator///////////////////////////////////////////////////////////////////////////////////////////////////////
  1237. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1238. function TltsFontCreator.GetFontByName(const aFontname: String; const aSize: Integer; const aStyle: TltsFontStyles; const aAntiAliasing: TltsAntiAliasing): TltsFont;
  1239. var
  1240. h: TltsFontHandle;
  1241. begin
  1242. h := ltsFontCreatorGetFontByName(fHandle, PAnsiChar(aFontname), aSize, aStyle, aAntiAliasing);
  1243. if not Assigned(h) then
  1244. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1245. result := TltsFont.Create(h);
  1246. end;
  1247. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1248. function TltsFontCreator.GetFontByFile(const aFilename: String; const aSize: Integer; const aStyle: TltsFontStyles; const aAntiAliasing: TltsAntiAliasing): TltsFont;
  1249. var
  1250. h: TltsFontHandle;
  1251. begin
  1252. h := ltsFontCreatorGetFontByFile(fHandle, PAnsiChar(aFilename), aSize, aStyle, aAntiAliasing);
  1253. if not Assigned(h) then
  1254. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1255. result := TltsFont.Create(h);
  1256. end;
  1257. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1258. function TltsFontCreator.GetFontByStream(const aStream: TStream; const aSize: Integer; const aStyle: TltsFontStyles; const aAntiAliasing: TltsAntiAliasing): TltsFont;
  1259. var
  1260. h: TltsFontHandle;
  1261. s: TltsStream;
  1262. begin
  1263. s.args := Pointer(aStream);
  1264. s.read := @ltsStreamReadCallback;
  1265. s.seek := @ltsStreamSeekCallback;
  1266. h := ltsFontCreatorGetFontByStream(fHandle, @s, aSize, aStyle, aAntiAliasing);
  1267. if not Assigned(h) then
  1268. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1269. result := TltsFont.Create(h);
  1270. end;
  1271. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1272. constructor TltsFontCreator.Create(const aHandle: TltsFontCreatorHandle);
  1273. begin
  1274. inherited Create;
  1275. fHandle := aHandle;
  1276. end;
  1277. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1278. destructor TltsFontCreator.Destroy;
  1279. begin
  1280. if Assigned(fHandle) then begin
  1281. ltsFontCreatorDestroy(fHandle);
  1282. fHandle := nil;
  1283. end;
  1284. inherited Destroy;
  1285. end;
  1286. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1287. //TltsFontCreatorGDI////////////////////////////////////////////////////////////////////////////////////////////////////
  1288. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1289. constructor TltsFontCreatorGDI.Create(const aContext: TltsContext);
  1290. var
  1291. h: TltsFontCreatorHandle;
  1292. begin
  1293. h := ltsFontCreatorCreate(aContext.Handle, ltsFontCreatorGDI);
  1294. if not Assigned(h) then
  1295. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1296. inherited Create(h);
  1297. end;
  1298. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1299. //TltsFontCreatorFreeType///////////////////////////////////////////////////////////////////////////////////////////////
  1300. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1301. constructor TltsFontCreatorFreeType.Create(const aContext: TltsContext);
  1302. var
  1303. h: TltsFontCreatorHandle;
  1304. begin
  1305. h := ltsFontCreatorCreate(aContext.Handle, ltsFontCreatorFreeType);
  1306. if not Assigned(h) then
  1307. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1308. inherited Create(h);
  1309. end;
  1310. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1311. //TltsTextBlock/////////////////////////////////////////////////////////////////////////////////////////////////////////
  1312. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1313. function TltsTextBlock.GetClipping: TltsClipping;
  1314. var
  1315. err: TltsErrorCode;
  1316. begin
  1317. err := ltsTextBlockGetClipping(fHandle, result);
  1318. if (err <> ltsErrNone) then
  1319. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1320. end;
  1321. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1322. function TltsTextBlock.GetColor: TltsColor4f;
  1323. var
  1324. err: TltsErrorCode;
  1325. begin
  1326. err := ltsTextBlockGetColor(fHandle, result);
  1327. if (err <> ltsErrNone) then
  1328. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1329. end;
  1330. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1331. function TltsTextBlock.GetFlags: TltsBlockFlags;
  1332. var
  1333. err: TltsErrorCode;
  1334. begin
  1335. err := ltsTextBlockGetFlags(fHandle, result);
  1336. if (err <> ltsErrNone) then
  1337. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1338. end;
  1339. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1340. function TltsTextBlock.GetHeight: Integer;
  1341. var
  1342. err: TltsErrorCode;
  1343. begin
  1344. err := ltsTextBlockGetHeight(fHandle, result);
  1345. if (err <> ltsErrNone) then
  1346. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1347. end;
  1348. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1349. function TltsTextBlock.GetHorzAlign: TltsHorzAlignment;
  1350. var
  1351. err: TltsErrorCode;
  1352. begin
  1353. err := ltsTextBlockGetHorzAlign(fHandle, result);
  1354. if (err <> ltsErrNone) then
  1355. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1356. end;
  1357. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1358. function TltsTextBlock.GetLeft: Integer;
  1359. var
  1360. err: TltsErrorCode;
  1361. begin
  1362. err := ltsTextBlockGetLeft(fHandle, result);
  1363. if (err <> ltsErrNone) then
  1364. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1365. end;
  1366. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1367. function TltsTextBlock.GetRect: TltsRect;
  1368. var
  1369. err: TltsErrorCode;
  1370. begin
  1371. err := ltsTextBlockGetRect(fHandle, result);
  1372. if (err <> ltsErrNone) then
  1373. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1374. end;
  1375. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1376. function TltsTextBlock.GetTop: Integer;
  1377. var
  1378. err: TltsErrorCode;
  1379. begin
  1380. err := ltsTextBlockGetTop(fHandle, result);
  1381. if (err <> ltsErrNone) then
  1382. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1383. end;
  1384. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1385. function TltsTextBlock.GetVertAlign: TltsVertAlignment;
  1386. var
  1387. err: TltsErrorCode;
  1388. begin
  1389. err := ltsTextBlockGetVertAlign(fHandle, result);
  1390. if (err <> ltsErrNone) then
  1391. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1392. end;
  1393. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1394. function TltsTextBlock.GetWidth: Integer;
  1395. var
  1396. err: TltsErrorCode;
  1397. begin
  1398. err := ltsTextBlockGetWidth(fHandle, result);
  1399. if (err <> ltsErrNone) then
  1400. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1401. end;
  1402. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1403. procedure TltsTextBlock.SetClipping(aValue: TltsClipping);
  1404. var
  1405. err: TltsErrorCode;
  1406. begin
  1407. err := ltsTextBlockSetClipping(fHandle, aValue);
  1408. if (err <> ltsErrNone) then
  1409. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1410. end;
  1411. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1412. procedure TltsTextBlock.SetColor(aValue: TltsColor4f);
  1413. var
  1414. err: TltsErrorCode;
  1415. begin
  1416. err := ltsTextBlockSetColor(fHandle, aValue);
  1417. if (err <> ltsErrNone) then
  1418. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1419. end;
  1420. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1421. procedure TltsTextBlock.SetCurrentFont(aValue: TltsFont);
  1422. var
  1423. err: TltsErrorCode;
  1424. begin
  1425. fCurrentFont := aValue;
  1426. err := ltsTextBlockSetFont(fHandle, fCurrentFont.Handle);
  1427. if (err <> ltsErrNone) then
  1428. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1429. end;
  1430. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1431. procedure TltsTextBlock.SetHorzAlign(aValue: TltsHorzAlignment);
  1432. var
  1433. err: TltsErrorCode;
  1434. begin
  1435. err := ltsTextBlockSetHorzAlign(fHandle, aValue);
  1436. if (err <> ltsErrNone) then
  1437. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1438. end;
  1439. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1440. procedure TltsTextBlock.SetLeft(aValue: Integer);
  1441. var
  1442. err: TltsErrorCode;
  1443. begin
  1444. err := ltsTextBlockSetLeft(fHandle, aValue);
  1445. if (err <> ltsErrNone) then
  1446. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1447. end;
  1448. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1449. procedure TltsTextBlock.SetTop(aValue: Integer);
  1450. var
  1451. err: TltsErrorCode;
  1452. begin
  1453. err := ltsTextBlockSetTop(fHandle, aValue);
  1454. if (err <> ltsErrNone) then
  1455. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1456. end;
  1457. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1458. procedure TltsTextBlock.SetVertAlign(aValue: TltsVertAlignment);
  1459. var
  1460. err: TltsErrorCode;
  1461. begin
  1462. err := ltsTextBlockSetVertAlign(fHandle, aValue);
  1463. if (err <> ltsErrNone) then
  1464. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1465. end;
  1466. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1467. function TltsTextBlock.GetActualBlockHeight: Integer;
  1468. begin
  1469. result := ltsTextBlockGetActualHeight(fHandle);
  1470. if (result < 0) then
  1471. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1472. end;
  1473. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1474. procedure TltsTextBlock.ChangeFont(const aFont: TltsFont);
  1475. begin
  1476. SetCurrentFont(aFont);
  1477. end;
  1478. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1479. procedure TltsTextBlock.ChangeColor(const aColor: TltsColor4f);
  1480. begin
  1481. SetColor(aColor);
  1482. end;
  1483. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1484. procedure TltsTextBlock.TextOutA(const aText: PAnsiChar);
  1485. var
  1486. err: TltsErrorCode;
  1487. begin
  1488. err := ltsTextBlockTextOutA(fHandle, aText);
  1489. if (err <> ltsErrNone) then
  1490. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1491. end;
  1492. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1493. procedure TltsTextBlock.TextOutW(const aText: PWideChar);
  1494. var
  1495. err: TltsErrorCode;
  1496. begin
  1497. err := ltsTextBlockTextOutW(fHandle, aText);
  1498. if (err <> ltsErrNone) then
  1499. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1500. end;
  1501. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1502. function TltsTextBlock.GetTextWidthA(const aText: PAnsiChar): Integer;
  1503. begin
  1504. result := ltsTextBlockGetTextWidthA(fHandle, aText);
  1505. if (result < 0) then
  1506. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1507. end;
  1508. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1509. function TltsTextBlock.GetTextWidthW(const aText: PWideChar): Integer;
  1510. begin
  1511. result := ltsTextBlockGetTextWidthW(fHandle, aText);
  1512. if (result < 0) then
  1513. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1514. end;
  1515. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1516. constructor TltsTextBlock.Create(const aHandle: TltsTextBlockHandle);
  1517. begin
  1518. inherited Create;
  1519. fHandle := aHandle;
  1520. end;
  1521. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1522. destructor TltsTextBlock.Destroy;
  1523. begin
  1524. if Assigned(fHandle) then begin
  1525. ltsTextBlockDestroy(fHandle);
  1526. fHandle := nil;
  1527. end;
  1528. inherited Destroy;
  1529. end;
  1530. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1531. //TltsImage/////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1532. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1533. function TltsImage.GetData: Pointer;
  1534. begin
  1535. result := ltsImageGetData(fHandle);
  1536. if not Assigned(result) then
  1537. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1538. end;
  1539. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1540. function TltsImage.GetDataSize: Integer;
  1541. begin
  1542. result := ltsImageGetDataSize(fHandle);
  1543. if (result < 0) then
  1544. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1545. end;
  1546. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1547. function TltsImage.GetFormat: TltsFormat;
  1548. var
  1549. err: TltsErrorCode;
  1550. begin
  1551. err := ltsImageGetFormat(fHandle, result);
  1552. if (err <> ltsErrNone) then
  1553. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1554. end;
  1555. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1556. function TltsImage.GetHeight: Integer;
  1557. begin
  1558. result := ltsImageGetHeight(fHandle);
  1559. if (result < 0) then
  1560. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1561. end;
  1562. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1563. function TltsImage.GetIsEmpty: Boolean;
  1564. var
  1565. err: TltsErrorCode;
  1566. begin
  1567. err := ltsImageIsEmpty(fHandle, result);
  1568. if (err <> ltsErrNone) then
  1569. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1570. end;
  1571. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1572. function TltsImage.GetLineSize: Integer;
  1573. begin
  1574. result := ltsImageGetLineSize(fHandle);
  1575. if (result < 0) then
  1576. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1577. end;
  1578. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1579. function TltsImage.GetWidth: Integer;
  1580. begin
  1581. result := ltsImageGetWidth(fHandle);
  1582. if (result < 0) then
  1583. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1584. end;
  1585. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1586. function TltsImage.GetScanline(const aIndex: Integer): Pointer;
  1587. begin
  1588. result := ltsImageGetScanline(fHandle, aIndex);
  1589. if not Assigned(result) then
  1590. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1591. end;
  1592. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1593. function TltsImage.GetPixelAt(const x, y: Integer; out aColor: TltsColor4f): Boolean;
  1594. var
  1595. err: TltsErrorCode;
  1596. begin
  1597. err := ltsImageGetPixelAt(fHandle, x, y, aColor);
  1598. case err of
  1599. ltsErrNone: result := true;
  1600. ltsErrInvalidValue: result := false;
  1601. else
  1602. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1603. end;
  1604. end;
  1605. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1606. procedure TltsImage.Assign(const aImage: TltsImage);
  1607. var
  1608. err: TltsErrorCode;
  1609. begin
  1610. err := ltsImageAssign(fHandle, aImage.Handle);
  1611. if (err <> ltsErrNone) then
  1612. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1613. end;
  1614. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1615. procedure TltsImage.CreateEmpty(const aFormat: TltsFormat; const aWidth, aHeight: Integer);
  1616. var
  1617. err: TltsErrorCode;
  1618. begin
  1619. err := ltsImageCreateEmpty(fHandle, aFormat, aWidth, aHeight);
  1620. if (err <> ltsErrNone) then
  1621. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1622. end;
  1623. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1624. procedure TltsImage.LoadFromFunc(const aFunc: TltsImageLoadFunc; const aArgs: Pointer);
  1625. var
  1626. err: TltsErrorCode;
  1627. ila: TImageLoadArgs;
  1628. begin
  1629. ila.args := aArgs;
  1630. ila.callback := aFunc;
  1631. ila.image := self;
  1632. err := ltsImageLoadFromFunc(fHandle, @ltsImageLoadCallback, @ila);
  1633. if (err <> ltsErrNone) then
  1634. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1635. end;
  1636. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1637. procedure TltsImage.Resize(const aWidth, aHeight, X, Y: Integer);
  1638. var
  1639. err: TltsErrorCode;
  1640. begin
  1641. err := ltsImageResize(fHandle, aWidth, aHeight, X, Y);
  1642. if (err <> ltsErrNone) then
  1643. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1644. end;
  1645. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1646. procedure TltsImage.FillColor(const aColor: TltsColor4f; const aMask: TltsColorChannels; const aModes: TltsImageModes);
  1647. var
  1648. err: TltsErrorCode;
  1649. begin
  1650. err := ltsImageFillColor(fHandle, aColor, aMask, aModes);
  1651. if (err <> ltsErrNone) then
  1652. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1653. end;
  1654. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1655. procedure TltsImage.FillPatter(const aPattern: TltsImage; const X, Y: Integer; const aMask: TltsColorChannels; const aModes: TltsImageModes);
  1656. var
  1657. err: TltsErrorCode;
  1658. begin
  1659. err := ltsImageFillPattern(fHandle, aPattern.Handle, X, Y, aMask, aModes);
  1660. if (err <> ltsErrNone) then
  1661. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1662. end;
  1663. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1664. procedure TltsImage.Blend(const aImage: TltsImage; const X, Y: Integer; const aFunc: TltsImageBlendFunc; aArgs: Pointer);
  1665. var
  1666. err: TltsErrorCode;
  1667. iba: TImageBlendArgs;
  1668. begin
  1669. iba.callback := aFunc;
  1670. iba.args := aArgs;
  1671. err := ltsImageLoadFromFunc(fHandle, @ltsImageLoadCallback, @iba);
  1672. if (err <> ltsErrNone) then
  1673. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1674. end;
  1675. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1676. procedure TltsImage.Blur(const aHorzRad, aHorzStr, aVertRad, aVertStr: Single; const aMask: TltsColorChannels);
  1677. var
  1678. err: TltsErrorCode;
  1679. begin
  1680. err := ltsImageBlur(fHandle, aHorzRad, aHorzStr, aVertRad, aVertStr, aMask);
  1681. if (err <> ltsErrNone) then
  1682. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1683. end;
  1684. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1685. constructor TltsImage.Create(const aHandle: TltsImageHandle);
  1686. begin
  1687. inherited Create;
  1688. fHandle := aHandle;
  1689. fOwnsHandle := false;
  1690. end;
  1691. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1692. constructor TltsImage.Create(const aContext: TltsContext);
  1693. begin
  1694. fOwnsHandle := true;
  1695. fHandle := ltsImageCreate(aContext.Handle);
  1696. if not Assigned(fHandle) then
  1697. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1698. inherited Create;
  1699. end;
  1700. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1701. destructor TltsImage.Destroy;
  1702. begin
  1703. if Assigned(fHandle) and fOwnsHandle then
  1704. ltsImageDestroy(fHandle);
  1705. fHandle := nil;
  1706. inherited Destroy;
  1707. end;
  1708. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1709. //TltsChar//////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1710. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1711. function TltsChar.GetCharCode: WideChar;
  1712. var
  1713. err: TltsErrorCode;
  1714. begin
  1715. err := ltsCharGetCharCode(fHandle, result);
  1716. if (err <> ltsErrNone) then
  1717. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1718. end;
  1719. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1720. function TltsChar.GetGlyphMetric: TltsGlyphMetric;
  1721. var
  1722. err: TltsErrorCode;
  1723. begin
  1724. err := ltsCharGetGlyphMetric(fHandle, result);
  1725. if (err <> ltsErrNone) then
  1726. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1727. end;
  1728. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1729. procedure TltsChar.SetGlyphMetric(aValue: TltsGlyphMetric);
  1730. var
  1731. err: TltsErrorCode;
  1732. begin
  1733. err := ltsCharSetGlyphMetric(fHandle, aValue);
  1734. if (err <> ltsErrNone) then
  1735. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1736. end;
  1737. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1738. constructor TltsChar.Create(const aHandle: TltsCharHandle);
  1739. begin
  1740. inherited Create;
  1741. fHandle := aHandle;
  1742. end;
  1743. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1744. //TltsRenderer//////////////////////////////////////////////////////////////////////////////////////////////////////////
  1745. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1746. function TltsRenderer.BeginBlock(const aTop, aLeft, aWidth, aHeight: Integer; const aFlags: TltsBlockFlags): TltsTextBlock;
  1747. var
  1748. h: TltsTextBlockHandle;
  1749. begin
  1750. h := ltsRendererBeginBlock(fHandle, aTop, aLeft, aWidth, aHeight, aFlags);
  1751. if not Assigned(h) then
  1752. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1753. result := TltsTextBlock.Create(h);
  1754. end;
  1755. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1756. procedure TltsRenderer.EndBlock(var aTextBlock: TltsTextBlock);
  1757. var
  1758. err: TltsErrorCode;
  1759. begin
  1760. try
  1761. err := ltsRendererEndBlock(fHandle, aTextBlock.Handle);
  1762. if (err <> ltsErrNone) then
  1763. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1764. finally
  1765. FreeAndNil(aTextBlock);
  1766. end;
  1767. end;
  1768. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1769. procedure TltsRenderer.AbortBlock(var aTextBlock: TltsTextBlock);
  1770. var
  1771. err: TltsErrorCode;
  1772. begin
  1773. try
  1774. err := ltsRendererAbortBlock(fHandle, aTextBlock.Handle);
  1775. if (err <> ltsErrNone) then
  1776. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1777. finally
  1778. FreeAndNil(aTextBlock);
  1779. end;
  1780. end;
  1781. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1782. function TltsRenderer.GetTextWidthA(const aFont: TltsFont; const aText: PAnsiChar): Integer;
  1783. begin
  1784. result := ltsRendererGetTextWidthA(fHandle, aFont.Handle, aText);
  1785. if (result < 0) then
  1786. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1787. end;
  1788. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1789. function TltsRenderer.GetTextWidthW(const aFont: TltsFont; const aText: PWideChar): Integer;
  1790. begin
  1791. result := ltsRendererGetTextWidthW(fHandle, aFont.Handle, aText);
  1792. if (result < 0) then
  1793. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1794. end;
  1795. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1796. constructor TltsRenderer.Create(const aHandle: TltsRendererHandle);
  1797. begin
  1798. inherited Create;
  1799. fHandle := aHandle;
  1800. end;
  1801. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1802. destructor TltsRenderer.Destroy;
  1803. begin
  1804. inherited Destroy;
  1805. end;
  1806. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1807. //TltsRendererOpenGL////////////////////////////////////////////////////////////////////////////////////////////////////
  1808. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1809. constructor TltsRendererOpenGL.Create(const aContext: TltsContext; const aFormat: TltsFormat);
  1810. var
  1811. h: TltsRendererHandle;
  1812. begin
  1813. h := ltsRendererCreate(aContext.Handle, ltsRendererOpenGL, aFormat);
  1814. if not Assigned(h) then
  1815. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1816. inherited Create(h);
  1817. end;
  1818. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1819. //TltsRendererOpenGLES//////////////////////////////////////////////////////////////////////////////////////////////////
  1820. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1821. constructor TltsRendererOpenGLES.Create(const aContext: TltsContext; const aFormat: TltsFormat);
  1822. var
  1823. h: TltsRendererHandle;
  1824. begin
  1825. h := ltsRendererCreate(aContext.Handle, ltsRendererOpenGLES, aFormat);
  1826. if not Assigned(h) then
  1827. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1828. inherited Create(h);
  1829. end;
  1830. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1831. //TltsRendererCustom////////////////////////////////////////////////////////////////////////////////////////////////////
  1832. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1833. procedure ltsRendererCustomBeginRender(aArgs: Pointer); stdcall;
  1834. begin
  1835. TltsRendererCustom(aArgs).BeginRender;
  1836. end;
  1837. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1838. procedure ltsRendererCustomEndRender(aArgs: Pointer); stdcall;
  1839. begin
  1840. TltsRendererCustom(aArgs).EndRender;
  1841. end;
  1842. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1843. function ltsRendererCustomGetDrawPos(aArgs: Pointer): TltsPosition; stdcall;
  1844. begin
  1845. result := TltsRendererCustom(aArgs).GetDrawPos;
  1846. end;
  1847. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1848. procedure ltsRendererCustomSetDrawPos(const aValue: TltsPosition; aArgs: Pointer); stdcall;
  1849. begin
  1850. TltsRendererCustom(aArgs).SetDrawPos(aValue);
  1851. end;
  1852. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1853. procedure ltsRendererCustomMoveDrawPos(const aOffset: TltsPosition; aArgs: Pointer); stdcall;
  1854. begin
  1855. TltsRendererCustom(aArgs).MoveDrawPos(aOffset);
  1856. end;
  1857. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1858. procedure ltsRendererCustomSetColor(const aValue: TltsColor4f; aArgs: Pointer); stdcall;
  1859. begin
  1860. TltsRendererCustom(aArgs).SetColor(aValue);
  1861. end;
  1862. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1863. procedure ltsRendererCustomRender(const aRef: Pointer; const aForcedWidth: Integer; aArgs: Pointer); stdcall;
  1864. begin
  1865. TltsRendererCustom(aArgs).Render(aRef, aForcedWidth);
  1866. end;
  1867. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1868. function ltsRendererCustomCreateRef(const aChar: TltsCharHandle; const aImage: TltsImageHandle; aArgs: Pointer): Pointer; stdcall;
  1869. var
  1870. chr: TltsChar;
  1871. img: TltsImage;
  1872. begin
  1873. chr := TltsChar.Create(aChar);
  1874. img := TltsImage.Create(aImage);
  1875. try
  1876. result := TltsRendererCustom(aArgs).CreateRenderRef(chr, img);
  1877. finally
  1878. FreeAndNil(img);
  1879. FreeAndNil(chr);
  1880. end;
  1881. end;
  1882. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1883. procedure ltsRendererCustomFreeRef(const aRef: Pointer; aArgs: Pointer); stdcall;
  1884. begin
  1885. TltsRendererCustom(aArgs).FreeRenderRef(aRef);
  1886. end;
  1887. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1888. procedure TltsRendererCustom.BeginRender;
  1889. begin
  1890. // DUMMY
  1891. end;
  1892. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1893. procedure TltsRendererCustom.EndRender;
  1894. begin
  1895. // DUMMY
  1896. end;
  1897. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1898. function TltsRendererCustom.GetDrawPos: TltsPosition;
  1899. begin
  1900. result := fDrawPos;
  1901. end;
  1902. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1903. procedure TltsRendererCustom.SetDrawPos(const aValue: TltsPosition);
  1904. begin
  1905. fDrawPos := aValue;
  1906. end;
  1907. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1908. procedure TltsRendererCustom.MoveDrawPos(const aOffset: TltsPosition);
  1909. begin
  1910. fDrawPos.x := fDrawPos.x + aOffset.x;
  1911. fDrawPos.y := fDrawPos.y + aOffset.y;
  1912. end;
  1913. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1914. procedure TltsRendererCustom.SetColor(const aValue: TltsColor4f);
  1915. begin
  1916. fColor := aValue;
  1917. end;
  1918. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1919. procedure TltsRendererCustom.Render(const aRenderRef: Pointer; const aForcedWidth: Integer);
  1920. begin
  1921. // DUMMY
  1922. end;
  1923. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1924. function TltsRendererCustom.CreateRenderRef(const aChar: TltsChar; const aImage: TltsImage): Pointer;
  1925. begin
  1926. result := nil; // DUMMY
  1927. end;
  1928. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1929. procedure TltsRendererCustom.FreeRenderRef(const aRenderRef: Pointer);
  1930. begin
  1931. // DUMMY
  1932. end;
  1933. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1934. constructor TltsRendererCustom.Create(const aContext: TltsContext; const aFormat: TltsFormat);
  1935. var
  1936. h: TltsRendererHandle;
  1937. d: TltsRendererCustomData;
  1938. begin
  1939. d.args := self;
  1940. d.BeginRender := @ltsRendererCustomBeginRender;
  1941. d.EndRender := @ltsRendererCustomEndRender;
  1942. d.GetDrawPos := @ltsRendererCustomGetDrawPos;
  1943. d.SetDrawPos := @ltsRendererCustomSetDrawPos;
  1944. d.MoveDrawPos := @ltsRendererCustomMoveDrawPos;
  1945. d.SetColor := @ltsRendererCustomSetColor;
  1946. d.Render := @ltsRendererCustomRender;
  1947. d.CreatRef := @ltsRendererCustomCreateRef;
  1948. d.FreeRef := @ltsRendererCustomFreeRef;
  1949. h := ltsRendererCustomCreate(aContext.Handle, aFormat, @d);
  1950. if not Assigned(h) then
  1951. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  1952. inherited Create(h);
  1953. end;
  1954. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1955. //TltsPostProcessor/////////////////////////////////////////////////////////////////////////////////////////////////////
  1956. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1957. procedure TltsPostProcessor.Execute(const aChar: TltsChar; const aImage: TltsImage);
  1958. var
  1959. err: TltsErrorCode;
  1960. begin
  1961. err := ltsPostProcessorExecute(fHandle, aChar.Handle, aImage.Handle);
  1962. if (err <> ltsErrNone) then
  1963. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1964. end;
  1965. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1966. procedure TltsPostProcessor.AddRange(const aUsage: TltsCharRangeUsage; const aStart, aStop: WideChar);
  1967. var
  1968. err: TltsErrorCode;
  1969. begin
  1970. err := ltsPostProcessorAddRange(fHandle, aUsage, aStart, aStop);
  1971. if (err <> ltsErrNone) then
  1972. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1973. end;
  1974. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1975. procedure TltsPostProcessor.AddChars(const aUsage: TltsCharRangeUsage; const aChars: PWideChar);
  1976. var
  1977. err: TltsErrorCode;
  1978. begin
  1979. err := ltsPostProcessorAddChars(fHandle, aUsage, aChars);
  1980. if (err <> ltsErrNone) then
  1981. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1982. end;
  1983. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1984. procedure TltsPostProcessor.ClearRanges;
  1985. var
  1986. err: TltsErrorCode;
  1987. begin
  1988. err := ltsPostProcessorClearRanges(fHandle);
  1989. if (err <> ltsErrNone) then
  1990. raise TltsException.Create(ltsGetLastErrorMsg(), err);
  1991. end;
  1992. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1993. constructor TltsPostProcessor.Create(const aHandle: TltsPostProcessorHandle);
  1994. begin
  1995. inherited Create;
  1996. fHandle := aHandle;
  1997. end;
  1998. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1999. destructor TltsPostProcessor.Destroy;
  2000. begin
  2001. if Assigned(fHandle) then begin
  2002. ltsPostProcessorDestroy(fHandle);
  2003. fHandle := nil;
  2004. end;
  2005. inherited Destroy;
  2006. end;
  2007. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2008. //TltsPostProcessorFillColor////////////////////////////////////////////////////////////////////////////////////////////
  2009. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2010. constructor TltsPostProcessorFillColor.Create(const aContext: TltsContext; const aColor: TltsColor4f;
  2011. const aModes: TltsImageModes; const aChannels: TltsColorChannels);
  2012. var
  2013. h: TltsPostProcessorHandle;
  2014. begin
  2015. fColor := aColor;
  2016. fModes := aModes;
  2017. fChannels := aChannels;
  2018. h := ltsPostProcessorFillColorCreate(aContext.Handle, fColor, fModes, fChannels);
  2019. if not Assigned(h) then
  2020. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  2021. inherited Create(h);
  2022. end;
  2023. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2024. //TltsPostProcessorFillPattern//////////////////////////////////////////////////////////////////////////////////////////
  2025. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2026. constructor TltsPostProcessorFillPattern.Create(const aContext: TltsContext; const aPattern: TltsImage; const aOwnsPatter: Boolean;
  2027. const aPosition: TltsPosition; const aModes: TltsImageModes; const aChannels: TltsColorChannels);
  2028. var
  2029. h: TltsPostProcessorHandle;
  2030. begin
  2031. fPattern := aPattern;
  2032. fOwnsPattern := aOwnsPatter;
  2033. fPosition := aPosition;
  2034. fModes := aModes;
  2035. fChannels := aChannels;
  2036. h := ltsPostProcessorFillPatterCreate(aContext.Handle, fPattern, fOwnsPattern, fPosition, fModes, fChannels);
  2037. if not Assigned(h) then
  2038. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  2039. inherited Create(h);
  2040. end;
  2041. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2042. destructor TltsPostProcessorFillPattern.Destroy;
  2043. begin
  2044. if Assigned(fPattern) and fOwnsPattern then
  2045. FreeAndNil(fPattern);
  2046. inherited Destroy;
  2047. end;
  2048. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2049. //TltsPostProcessorBorder///////////////////////////////////////////////////////////////////////////////////////////////
  2050. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2051. constructor TltsPostProcessorBorder.Create(const aContext: TltsContext; const aWidth, aStrength: Single;
  2052. const aColor: TltsColor4f; const aKeepSize: Boolean);
  2053. var
  2054. h: TltsPostProcessorHandle;
  2055. begin
  2056. fWidth := aWidth;
  2057. fStrength := aStrength;
  2058. fColor := aColor;
  2059. fKeepSize := aKeepSize;
  2060. h := ltsPostProcessorBorderCreate(aContext.Handle, fWidth, fStrength, fColor, fKeepSize);
  2061. if not Assigned(h) then
  2062. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  2063. inherited Create(h);
  2064. end;
  2065. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2066. //TltsPostProcessorShadow///////////////////////////////////////////////////////////////////////////////////////////////
  2067. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2068. constructor TltsPostProcessorShadow.Create(const aContext: TltsContext; const aRadius, aStrength: Single;
  2069. const aOffset: TltsPosition; const aColor: TltsColor4f);
  2070. var
  2071. h: TltsPostProcessorHandle;
  2072. begin
  2073. fRadius := aRadius;
  2074. fStrength := aStrength;
  2075. fOffset := aOffset;
  2076. fColor := aColor;
  2077. h := ltsPostProcessorShadowCreate(aContext.Handle, fRadius, fStrength, fOffset, fColor);
  2078. if not Assigned(h) then
  2079. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  2080. inherited Create(h);
  2081. end;
  2082. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2083. //TltsPostProcessorCustom///////////////////////////////////////////////////////////////////////////////////////////////
  2084. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2085. procedure ltsPostProcessorExecuteCallback(const aChar: TltsCharHandle; const aImage: TltsImageHandle; aArgs: Pointer);
  2086. var
  2087. chr: TltsChar;
  2088. img: TltsImage;
  2089. begin
  2090. chr := TltsChar.Create(aChar);
  2091. img := TltsImage.Create(aImage);
  2092. try
  2093. TltsPostProcessorCustom(aArgs).Execute(chr, img);
  2094. finally
  2095. FreeAndNil(img);
  2096. FreeAndNil(chr);
  2097. end;
  2098. end;
  2099. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2100. constructor TltsPostProcessorCustom.Create(const aContext: TltsContext);
  2101. var
  2102. h: TltsPostProcessorHandle;
  2103. p: TltsPostProcessorCustomData;
  2104. begin
  2105. p.args := self;
  2106. p.execute := @ltsPostProcessorExecuteCallback;
  2107. h := ltsPostProcessorCustomCreate(aContext.Handle, @p);
  2108. if not Assigned(h) then
  2109. raise TltsException.Create(ltsGetLastErrorMsg(), ltsGetLastErrorCode());
  2110. inherited Create(h);
  2111. end;
  2112. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2113. //TltsPostProcessorList/////////////////////////////////////////////////////////////////////////////////////////////////
  2114. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2115. function TltsPostProcessorList.GetCount: Integer;
  2116. begin
  2117. result := fItems.Count;
  2118. end;
  2119. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2120. function TltsPostProcessorList.GetItem(const aIndex: Integer): TltsPostProcessor;
  2121. begin
  2122. result := TltsPostProcessor(fItems[aIndex]);
  2123. end;
  2124. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2125. function TltsPostProcessorList.GetOwnsObjects: Boolean;
  2126. begin
  2127. result := fItems.OwnsObjects;
  2128. end;
  2129. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2130. procedure TltsPostProcessorList.SetOwnsObjects(aValue: Boolean);
  2131. begin
  2132. fItems.OwnsObjects := aValue;
  2133. end;
  2134. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2135. procedure TltsPostProcessorList.Execute(const aChar: TltsChar; const aImage: TltsImage);
  2136. var
  2137. i: Integer;
  2138. begin
  2139. inherited Execute(aChar, aImage);
  2140. for i := 0 to fItems.Count-1 do
  2141. TltsPostProcessor(fItems[i]).Execute(aChar, aImage);
  2142. end;
  2143. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2144. procedure TltsPostProcessorList.Add(const aPostProcessor: TltsPostProcessor);
  2145. begin
  2146. fItems.Add(aPostProcessor);
  2147. end;
  2148. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2149. procedure TltsPostProcessorList.Delete(const aIndex: Integer);
  2150. begin
  2151. fItems.Delete(aIndex);
  2152. end;
  2153. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2154. procedure TltsPostProcessorList.Clear;
  2155. begin
  2156. fItems.Clear;
  2157. end;
  2158. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2159. function TltsPostProcessorList.Remove(const aPostProcessor: TltsPostProcessor): Integer;
  2160. begin
  2161. result := fItems.Remove(aPostProcessor);
  2162. end;
  2163. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2164. function TltsPostProcessorList.IndexOf(const aPostProcessor: TltsPostProcessor): Integer;
  2165. begin
  2166. result := fItems.IndexOf(aPostProcessor);
  2167. end;
  2168. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2169. constructor TltsPostProcessorList.Create(const aContext: TltsContext; const aOwnsObjects: Boolean);
  2170. begin
  2171. inherited Create(aContext);
  2172. fItems := TObjectList.Create(aOwnsObjects);
  2173. end;
  2174. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2175. destructor TltsPostProcessorList.Destroy;
  2176. begin
  2177. FreeAndNil(fItems);
  2178. inherited Destroy;
  2179. end;
  2180. end.