Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 

2581 рядки
111 KiB

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