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.
 
 
 
 
 

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