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

2031 lignes
89 KiB

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