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.

301 lines
7.0 KiB

  1. unit utsTypes;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils;
  6. type
  7. TtsCodePage = (
  8. tsUTF8,
  9. tsISO_8859_1,
  10. tsISO_8859_2,
  11. tsISO_8859_3,
  12. tsISO_8859_4,
  13. tsISO_8859_5,
  14. tsISO_8859_6,
  15. tsISO_8859_7,
  16. tsISO_8859_8,
  17. tsISO_8859_9,
  18. tsISO_8859_10,
  19. tsISO_8859_11,
  20. tsISO_8859_13,
  21. tsISO_8859_14,
  22. tsISO_8859_15,
  23. tsISO_8859_16,
  24. tsISO_037,
  25. tsISO_437,
  26. tsISO_500,
  27. tsISO_737,
  28. tsISO_775,
  29. tsISO_850,
  30. tsISO_852,
  31. tsISO_855,
  32. tsISO_857,
  33. tsISO_860,
  34. tsISO_861,
  35. tsISO_862,
  36. tsISO_863,
  37. tsISO_864,
  38. tsISO_865,
  39. tsISO_866,
  40. tsISO_869,
  41. tsISO_874,
  42. tsISO_875,
  43. tsISO_1026,
  44. tsISO_1250,
  45. tsISO_1251,
  46. tsISO_1252,
  47. tsISO_1253,
  48. tsISO_1254,
  49. tsISO_1255,
  50. tsISO_1256,
  51. tsISO_1257,
  52. tsISO_1258);
  53. TtsFontStyle = (
  54. tsStyleBold,
  55. tsStyleItalic,
  56. tsStyleUnderline,
  57. tsStyleStrikeout);
  58. TtsFontStyles = set of TtsFontStyle;
  59. TtsVertAlignment = (
  60. tsVertAlignTop,
  61. tsVertAlignCenter,
  62. tsVertAlignBottom);
  63. TtsHorzAlignment = (
  64. tsHorzAlignLeft,
  65. tsHorzAlignCenter,
  66. tsHorzAlignRight,
  67. tsHorzAlignJustify);
  68. TtsFormat = (
  69. tsFormatEmpty,
  70. tsFormatRGBA8,
  71. tsFormatLumAlpha8,
  72. tsFormatAlpha8);
  73. TtsAntiAliasing = (
  74. tsAANone,
  75. tsAANormal);
  76. TtsColorChannel = (
  77. tsChannelRed,
  78. tsChannelGreen,
  79. tsChannelBlue,
  80. tsChannelAlpha);
  81. TtsColorChannels = set of TtsColorChannel;
  82. TtsImageMode = (
  83. tsModeIgnore,
  84. tsModeReplace,
  85. tsModeModulate);
  86. TtsImageModes = array[TtsColorChannel] of TtsImageMode;
  87. TtsImageModeFunc = function(const aSource, aDest: Single): Single;
  88. TtsFontProperties = packed record
  89. Fontname: String;
  90. Copyright: String;
  91. FaceName: String;
  92. StyleName: String;
  93. FullName: String;
  94. Size: Integer;
  95. Style: TtsFontStyles;
  96. AntiAliasing: TtsAntiAliasing;
  97. DefaultChar: WideChar;
  98. Ascent: Integer;
  99. Descent: Integer;
  100. ExternalLeading: Integer;
  101. BaseLineOffset: Integer;
  102. UnderlinePos: Integer;
  103. UnderlineSize: Integer;
  104. StrikeoutPos: Integer;
  105. StrikeoutSize: Integer;
  106. end;
  107. TtsPosition = packed record
  108. x, y: Integer;
  109. end;
  110. PtsPosition = ^TtsPosition;
  111. TtsPositionF = packed record
  112. x, y: Single;
  113. end;
  114. PtsPositionF = ^TtsPositionF;
  115. TtsRect = packed record
  116. case Byte of
  117. 0: (TopLeft: TtsPosition; BottomRight: TtsPosition);
  118. 1: (Left, Top, Right, Bottom: Integer);
  119. end;
  120. PtsRect = ^TtsRect;
  121. TtsRectF = packed record
  122. case Byte of
  123. 0: (TopLeft: TtsPositionF; BottomRight: TtsPositionF);
  124. 1: (Left, Top, Right, Bottom: Single);
  125. end;
  126. PtsRectF = ^TtsRectF;
  127. TtsColor4f = packed record
  128. case Boolean of
  129. true: (r, g, b, a: Single);
  130. false: (arr: array[0..3] of Single);
  131. end;
  132. PtsColor4f = ^TtsColor4f;
  133. TtsColor4ub = packed record
  134. case Boolean of
  135. true: (r, g, b, a: Byte);
  136. false: (arr: array[0..3] of Byte);
  137. end;
  138. PtsColor4ub = ^TtsColor4ub;
  139. TtsTextMetric = packed record
  140. Ascent: Integer;
  141. Descent: Integer;
  142. ExternalLeading: Integer;
  143. BaseLineOffset: Integer;
  144. CharSpacing: Integer;
  145. LineHeight: Integer;
  146. LineSpacing: Integer;
  147. end;
  148. function tsColor4f(r, g, b, a: Single): TtsColor4f;
  149. function tsRect(const l, t, r, b: Integer): TtsRect;
  150. function tsPosition(const x, y: Integer): TtsPosition;
  151. function tsFormatSize(const aFormat: TtsFormat): Integer;
  152. procedure tsFormatMap(const aFormat: TtsFormat; var aData: PByte; const aColor: TtsColor4f);
  153. procedure tsFormatUnmap(const aFormat: TtsFormat; var aData: PByte; out aColor: TtsColor4f);
  154. function tsImageModeFuncIgnore(const aSource, aDest: Single): Single;
  155. function tsImageModeFuncReplace(const aSource, aDest: Single): Single;
  156. function tsImageModeFuncModulate(const aSource, aDest: Single): Single;
  157. implementation
  158. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  159. function tsColor4f(r, g, b, a: Single): TtsColor4f;
  160. begin
  161. result.r := r;
  162. result.g := g;
  163. result.b := b;
  164. result.a := a;
  165. end;
  166. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  167. function tsRect(const l, t, r, b: Integer): TtsRect;
  168. begin
  169. result.Left := l;
  170. result.Top := t;
  171. result.Right := r;
  172. result.Bottom := b;
  173. end;
  174. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  175. function tsPosition(const x, y: Integer): TtsPosition;
  176. begin
  177. result.x := x;
  178. result.y := y;
  179. end;
  180. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  181. function tsFormatSize(const aFormat: TtsFormat): Integer;
  182. begin
  183. case aFormat of
  184. tsFormatRGBA8: result := 4;
  185. tsFormatLumAlpha8: result := 2;
  186. tsFormatAlpha8: result := 1;
  187. else
  188. result := 0;
  189. end;
  190. end;
  191. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  192. procedure tsFormatMap(const aFormat: TtsFormat; var aData: PByte; const aColor: TtsColor4f);
  193. var
  194. i: Integer;
  195. s: Single;
  196. begin
  197. case aFormat of
  198. tsFormatRGBA8: begin
  199. for i := 0 to 3 do begin
  200. aData^ := Trunc($FF * aColor.arr[i]);
  201. inc(aData);
  202. end;
  203. end;
  204. tsFormatLumAlpha8: begin
  205. s := 0.30 * aColor.r + 0.59 * aColor.g + 0.11 * aColor.b;
  206. aData^ := Trunc($FF * s); inc(aData);
  207. aData^ := Trunc($FF * aColor.a); inc(aData);
  208. end;
  209. tsFormatAlpha8: begin
  210. aData^ := Trunc($FF * aColor.a);
  211. inc(aData);
  212. end;
  213. end;
  214. end;
  215. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  216. procedure tsFormatUnmap(const aFormat: TtsFormat; var aData: PByte; out aColor: TtsColor4f);
  217. var
  218. i: Integer;
  219. begin
  220. case aFormat of
  221. tsFormatRGBA8: begin
  222. for i := 0 to 3 do begin
  223. aColor.arr[i] := aData^ / $FF;
  224. inc(aData);
  225. end;
  226. end;
  227. tsFormatLumAlpha8: begin
  228. aColor.r := aData^ / $FF;
  229. aColor.g := aData^ / $FF;
  230. aColor.b := aData^ / $FF;
  231. inc(aData);
  232. aColor.a := aData^ / $FF;
  233. inc(aData);
  234. end;
  235. tsFormatAlpha8: begin
  236. aColor.r := 1.0;
  237. aColor.g := 1.0;
  238. aColor.b := 1.0;
  239. aColor.a := aData^ / $FF;
  240. inc(aData);
  241. end;
  242. end;
  243. end;
  244. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  245. function tsImageModeFuncIgnore(const aSource, aDest: Single): Single;
  246. begin
  247. result := aDest;
  248. end;
  249. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  250. function tsImageModeFuncReplace(const aSource, aDest: Single): Single;
  251. begin
  252. result := aSource;
  253. end;
  254. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  255. function tsImageModeFuncModulate(const aSource, aDest: Single): Single;
  256. begin
  257. result := aSource * aDest;
  258. end;
  259. end.