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

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