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.
 
 
 
 
 

483 lines
16 KiB

  1. unit ultsTextBlock;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. utsTextSuite,
  7. ultsTypes;
  8. function ltsTextBlockGetRect (aHandle: TltsTextBlockHandle; var aValue: TtsRect): TltsErrorCode; stdcall;
  9. function ltsTextBlockGetWidth (aHandle: TltsTextBlockHandle; var aValue: Integer): TltsErrorCode; stdcall;
  10. function ltsTextBlockGetHeight (aHandle: TltsTextBlockHandle; var aValue: Integer): TltsErrorCode; stdcall;
  11. function ltsTextBlockGetFlags (aHandle: TltsTextBlockHandle; var aValue: TtsBlockFlags): TltsErrorCode; stdcall;
  12. function ltsTextBlockGetTop (aHandle: TltsTextBlockHandle; var aValue: Integer): TltsErrorCode; stdcall;
  13. function ltsTextBlockGetLeft (aHandle: TltsTextBlockHandle; var aValue: Integer): TltsErrorCode; stdcall;
  14. function ltsTextBlockGetVertAlign (aHandle: TltsTextBlockHandle; var aValue: TtsVertAlignment): TltsErrorCode; stdcall;
  15. function ltsTextBlockGetHorzAlign (aHandle: TltsTextBlockHandle; var aValue: TtsHorzAlignment): TltsErrorCode; stdcall;
  16. function ltsTextBlockGetClipping (aHandle: TltsTextBlockHandle; var aValue: TtsClipping): TltsErrorCode; stdcall;
  17. function ltsTextBlockGetColor (aHandle: TltsTextBlockHandle; var aValue: TtsColor4f): TltsErrorCode; stdcall;
  18. function ltsTextBlockGetFont (aHandle: TltsTextBlockHandle; var aValue: TltsFontHandle): TltsErrorCode; stdcall;
  19. function ltsTextBlockSetTop (aHandle: TltsTextBlockHandle; aValue: Integer): TltsErrorCode; stdcall;
  20. function ltsTextBlockSetLeft (aHandle: TltsTextBlockHandle; aValue: Integer): TltsErrorCode; stdcall;
  21. function ltsTextBlockSetVertAlign (aHandle: TltsTextBlockHandle; aValue: TtsVertAlignment): TltsErrorCode; stdcall;
  22. function ltsTextBlockSetHorzAlign (aHandle: TltsTextBlockHandle; aValue: TtsHorzAlignment): TltsErrorCode; stdcall;
  23. function ltsTextBlockSetClipping (aHandle: TltsTextBlockHandle; aValue: TtsClipping): TltsErrorCode; stdcall;
  24. function ltsTextBlockSetColor (aHandle: TltsTextBlockHandle; aValue: TtsColor4f): TltsErrorCode; stdcall;
  25. function ltsTextBlockSetFont (aHandle: TltsTextBlockHandle; aValue: TltsFontHandle): TltsErrorCode; stdcall;
  26. function ltsTextBlockGetActualHeight(aHandle: TltsTextBlockHandle): Integer; stdcall;
  27. function ltsTextBlockGetTextWidthA (aHandle: TltsTextBlockHandle; aText: PAnsiChar): Integer; stdcall;
  28. function ltsTextBlockGetTextWidthW (aHandle: TltsTextBlockHandle; aText: PWideChar): Integer; stdcall;
  29. function ltsTextBlockTextOutA (aHandle: TltsTextBlockHandle; aText: PAnsiChar): TltsErrorCode; stdcall;
  30. function ltsTextBlockTextOutW (aHandle: TltsTextBlockHandle; aText: PWideChar): TltsErrorCode; stdcall;
  31. function ltsTextBlockDestroy (aHandle: TltsTextBlockHandle): TltsErrorCode; stdcall;
  32. implementation
  33. uses
  34. ultsUtils;
  35. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  36. //TextBlock/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  37. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  38. function ltsTextBlockGetRect(aHandle: TltsTextBlockHandle; var aValue: TtsRect): TltsErrorCode; stdcall;
  39. var
  40. b: TtsTextBlock;
  41. begin
  42. try
  43. result := ltsErrNone;
  44. if CheckTextBlockHandle(aHandle, b)
  45. then aValue := b.Rect
  46. else result := LastErrorCode;
  47. except
  48. on ex: Exception do begin
  49. SetLastError(ex);
  50. result := LastErrorCode;
  51. end;
  52. end;
  53. end;
  54. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  55. function ltsTextBlockGetWidth(aHandle: TltsTextBlockHandle; var aValue: Integer): TltsErrorCode; stdcall;
  56. var
  57. b: TtsTextBlock;
  58. begin
  59. try
  60. result := ltsErrNone;
  61. if CheckTextBlockHandle(aHandle, b)
  62. then aValue := b.Width
  63. else result := LastErrorCode;
  64. except
  65. on ex: Exception do begin
  66. SetLastError(ex);
  67. result := LastErrorCode;
  68. end;
  69. end;
  70. end;
  71. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  72. function ltsTextBlockGetHeight(aHandle: TltsTextBlockHandle; var aValue: Integer): TltsErrorCode; stdcall;
  73. var
  74. b: TtsTextBlock;
  75. begin
  76. try
  77. result := ltsErrNone;
  78. if CheckTextBlockHandle(aHandle, b)
  79. then aValue := b.Height
  80. else result := LastErrorCode;
  81. except
  82. on ex: Exception do begin
  83. SetLastError(ex);
  84. result := LastErrorCode;
  85. end;
  86. end;
  87. end;
  88. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  89. function ltsTextBlockGetFlags(aHandle: TltsTextBlockHandle; var aValue: TtsBlockFlags): TltsErrorCode; stdcall;
  90. var
  91. b: TtsTextBlock;
  92. begin
  93. try
  94. result := ltsErrNone;
  95. if CheckTextBlockHandle(aHandle, b)
  96. then aValue := b.Flags
  97. else result := LastErrorCode;
  98. except
  99. on ex: Exception do begin
  100. SetLastError(ex);
  101. result := LastErrorCode;
  102. end;
  103. end;
  104. end;
  105. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  106. function ltsTextBlockGetTop(aHandle: TltsTextBlockHandle; var aValue: Integer): TltsErrorCode; stdcall;
  107. var
  108. b: TtsTextBlock;
  109. begin
  110. try
  111. result := ltsErrNone;
  112. if CheckTextBlockHandle(aHandle, b)
  113. then aValue := b.Top
  114. else result := LastErrorCode;
  115. except
  116. on ex: Exception do begin
  117. SetLastError(ex);
  118. result := LastErrorCode;
  119. end;
  120. end;
  121. end;
  122. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  123. function ltsTextBlockGetLeft(aHandle: TltsTextBlockHandle; var aValue: Integer): TltsErrorCode; stdcall;
  124. var
  125. b: TtsTextBlock;
  126. begin
  127. try
  128. result := ltsErrNone;
  129. if CheckTextBlockHandle(aHandle, b)
  130. then aValue := b.Left
  131. else result := LastErrorCode;
  132. except
  133. on ex: Exception do begin
  134. SetLastError(ex);
  135. result := LastErrorCode;
  136. end;
  137. end;
  138. end;
  139. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  140. function ltsTextBlockGetVertAlign(aHandle: TltsTextBlockHandle; var aValue: TtsVertAlignment): TltsErrorCode; stdcall;
  141. var
  142. b: TtsTextBlock;
  143. begin
  144. try
  145. result := ltsErrNone;
  146. if CheckTextBlockHandle(aHandle, b)
  147. then aValue := b.VertAlign
  148. else result := LastErrorCode;
  149. except
  150. on ex: Exception do begin
  151. SetLastError(ex);
  152. result := LastErrorCode;
  153. end;
  154. end;
  155. end;
  156. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  157. function ltsTextBlockGetHorzAlign(aHandle: TltsTextBlockHandle; var aValue: TtsHorzAlignment): TltsErrorCode; stdcall;
  158. var
  159. b: TtsTextBlock;
  160. begin
  161. try
  162. result := ltsErrNone;
  163. if CheckTextBlockHandle(aHandle, b)
  164. then aValue := b.HorzAlign
  165. else result := LastErrorCode;
  166. except
  167. on ex: Exception do begin
  168. SetLastError(ex);
  169. result := LastErrorCode;
  170. end;
  171. end;
  172. end;
  173. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  174. function ltsTextBlockGetClipping(aHandle: TltsTextBlockHandle; var aValue: TtsClipping): TltsErrorCode; stdcall;
  175. var
  176. b: TtsTextBlock;
  177. begin
  178. try
  179. result := ltsErrNone;
  180. if CheckTextBlockHandle(aHandle, b)
  181. then aValue := b.Clipping
  182. else result := LastErrorCode;
  183. except
  184. on ex: Exception do begin
  185. SetLastError(ex);
  186. result := LastErrorCode;
  187. end;
  188. end;
  189. end;
  190. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  191. function ltsTextBlockGetColor(aHandle: TltsTextBlockHandle; var aValue: TtsColor4f): TltsErrorCode; stdcall;
  192. var
  193. b: TtsTextBlock;
  194. begin
  195. try
  196. result := ltsErrNone;
  197. if CheckTextBlockHandle(aHandle, b)
  198. then aValue := b.CurrentColor
  199. else result := LastErrorCode;
  200. except
  201. on ex: Exception do begin
  202. SetLastError(ex);
  203. result := LastErrorCode;
  204. end;
  205. end;
  206. end;
  207. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  208. function ltsTextBlockGetFont(aHandle: TltsTextBlockHandle; var aValue: TltsFontHandle): TltsErrorCode; stdcall;
  209. var
  210. b: TtsTextBlock;
  211. begin
  212. try
  213. result := ltsErrNone;
  214. if CheckTextBlockHandle(aHandle, b)
  215. then aValue := b.CurrentFont
  216. else result := LastErrorCode;
  217. except
  218. on ex: Exception do begin
  219. SetLastError(ex);
  220. result := LastErrorCode;
  221. end;
  222. end;
  223. end;
  224. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  225. function ltsTextBlockSetTop(aHandle: TltsTextBlockHandle; aValue: Integer): TltsErrorCode; stdcall;
  226. var
  227. b: TtsTextBlock;
  228. begin
  229. try
  230. result := ltsErrNone;
  231. if CheckTextBlockHandle(aHandle, b)
  232. then b.Top := aValue
  233. else result := LastErrorCode;
  234. except
  235. on ex: Exception do begin
  236. SetLastError(ex);
  237. result := LastErrorCode;
  238. end;
  239. end;
  240. end;
  241. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  242. function ltsTextBlockSetLeft(aHandle: TltsTextBlockHandle; aValue: Integer): TltsErrorCode; stdcall;
  243. var
  244. b: TtsTextBlock;
  245. begin
  246. try
  247. result := ltsErrNone;
  248. if CheckTextBlockHandle(aHandle, b)
  249. then b.Left := aValue
  250. else result := LastErrorCode;
  251. except
  252. on ex: Exception do begin
  253. SetLastError(ex);
  254. result := LastErrorCode;
  255. end;
  256. end;
  257. end;
  258. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  259. function ltsTextBlockSetVertAlign(aHandle: TltsTextBlockHandle; aValue: TtsVertAlignment): TltsErrorCode; stdcall;
  260. var
  261. b: TtsTextBlock;
  262. begin
  263. try
  264. result := ltsErrNone;
  265. if CheckTextBlockHandle(aHandle, b)
  266. then b.VertAlign := aValue
  267. else result := LastErrorCode;
  268. except
  269. on ex: Exception do begin
  270. SetLastError(ex);
  271. result := LastErrorCode;
  272. end;
  273. end;
  274. end;
  275. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  276. function ltsTextBlockSetHorzAlign(aHandle: TltsTextBlockHandle; aValue: TtsHorzAlignment): TltsErrorCode; stdcall;
  277. var
  278. b: TtsTextBlock;
  279. begin
  280. try
  281. result := ltsErrNone;
  282. if CheckTextBlockHandle(aHandle, b)
  283. then b.HorzAlign := aValue
  284. else result := LastErrorCode;
  285. except
  286. on ex: Exception do begin
  287. SetLastError(ex);
  288. result := LastErrorCode;
  289. end;
  290. end;
  291. end;
  292. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  293. function ltsTextBlockSetClipping(aHandle: TltsTextBlockHandle; aValue: TtsClipping): TltsErrorCode; stdcall;
  294. var
  295. b: TtsTextBlock;
  296. begin
  297. try
  298. result := ltsErrNone;
  299. if CheckTextBlockHandle(aHandle, b)
  300. then b.Clipping := aValue
  301. else result := LastErrorCode;
  302. except
  303. on ex: Exception do begin
  304. SetLastError(ex);
  305. result := LastErrorCode;
  306. end;
  307. end;
  308. end;
  309. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  310. function ltsTextBlockSetColor(aHandle: TltsTextBlockHandle; aValue: TtsColor4f): TltsErrorCode; stdcall;
  311. var
  312. b: TtsTextBlock;
  313. begin
  314. try
  315. result := ltsErrNone;
  316. if CheckTextBlockHandle(aHandle, b)
  317. then b.CurrentColor := aValue
  318. else result := LastErrorCode;
  319. except
  320. on ex: Exception do begin
  321. SetLastError(ex);
  322. result := LastErrorCode;
  323. end;
  324. end;
  325. end;
  326. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  327. function ltsTextBlockSetFont(aHandle: TltsTextBlockHandle; aValue: TltsFontHandle): TltsErrorCode; stdcall;
  328. var
  329. b: TtsTextBlock;
  330. f: TtsFont;
  331. begin
  332. try
  333. result := ltsErrNone;
  334. if CheckTextBlockHandle(aHandle, b) and CheckFontHandle(aValue, f)
  335. then b.CurrentFont := f
  336. else result := LastErrorCode;
  337. except
  338. on ex: Exception do begin
  339. SetLastError(ex);
  340. result := LastErrorCode;
  341. end;
  342. end;
  343. end;
  344. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  345. function ltsTextBlockGetActualHeight(aHandle: TltsTextBlockHandle): Integer; stdcall;
  346. var
  347. b: TtsTextBlock;
  348. begin
  349. try
  350. if CheckTextBlockHandle(aHandle, b)
  351. then result := b.GetActualBlockHeight
  352. else result := -1;
  353. except
  354. on ex: Exception do begin
  355. SetLastError(ex);
  356. result := -1;
  357. end;
  358. end;
  359. end;
  360. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  361. function ltsTextBlockGetTextWidthA(aHandle: TltsTextBlockHandle; aText: PAnsiChar): Integer; stdcall;
  362. var
  363. b: TtsTextBlock;
  364. begin
  365. try
  366. if CheckTextBlockHandle(aHandle, b)
  367. then result := b.GetTextWidthA(aText)
  368. else result := -1;
  369. except
  370. on ex: Exception do begin
  371. SetLastError(ex);
  372. result := -1;
  373. end;
  374. end;
  375. end;
  376. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  377. function ltsTextBlockGetTextWidthW(aHandle: TltsTextBlockHandle; aText: PWideChar): Integer; stdcall;
  378. var
  379. b: TtsTextBlock;
  380. begin
  381. try
  382. if CheckTextBlockHandle(aHandle, b)
  383. then result := b.GetTextWidthW(aText)
  384. else result := -1;
  385. except
  386. on ex: Exception do begin
  387. SetLastError(ex);
  388. result := -1;
  389. end;
  390. end;
  391. end;
  392. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  393. function ltsTextBlockTextOutA(aHandle: TltsTextBlockHandle; aText: PAnsiChar): TltsErrorCode; stdcall;
  394. var
  395. b: TtsTextBlock;
  396. begin
  397. try
  398. result := ltsErrNone;
  399. if CheckTextBlockHandle(aHandle, b)
  400. then b.TextOutA(aText)
  401. else result := LastErrorCode;
  402. except
  403. on ex: Exception do begin
  404. SetLastError(ex);
  405. result := LastErrorCode;
  406. end;
  407. end;
  408. end;
  409. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  410. function ltsTextBlockTextOutW(aHandle: TltsTextBlockHandle; aText: PWideChar): TltsErrorCode; stdcall;
  411. var
  412. b: TtsTextBlock;
  413. begin
  414. try
  415. result := ltsErrNone;
  416. if CheckTextBlockHandle(aHandle, b)
  417. then b.TextOutW(aText)
  418. else result := LastErrorCode;
  419. except
  420. on ex: Exception do begin
  421. SetLastError(ex);
  422. result := LastErrorCode;
  423. end;
  424. end;
  425. end;
  426. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  427. function ltsTextBlockDestroy(aHandle: TltsTextBlockHandle): TltsErrorCode; stdcall;
  428. var
  429. b: TtsTextBlock;
  430. begin
  431. try
  432. result := ltsErrNone;
  433. if CheckTextBlockHandle(aHandle, b) then begin
  434. DelReference(ltsObjTypeTextBlock, b);
  435. FreeAndNil(b);
  436. end else
  437. result := LastErrorCode;
  438. except
  439. on ex: Exception do begin
  440. SetLastError(ex);
  441. result := LastErrorCode;
  442. end;
  443. end;
  444. end;
  445. end.