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.

305 line
7.2 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. TtsAnsiToWideCharFunc = procedure(aDst: PWideChar; const aSize: Integer; aSource: PAnsiChar; const aCodePage: TtsCodePage; const aDefaultChar: WideChar);
  149. function tsColor4f(r, g, b, a: Single): TtsColor4f;
  150. function tsRect(const l, t, r, b: Integer): TtsRect;
  151. function tsPosition(const x, y: Integer): TtsPosition;
  152. function tsFormatSize(const aFormat: TtsFormat): Integer;
  153. procedure tsFormatMap(const aFormat: TtsFormat; var aData: PByte; const aColor: TtsColor4f);
  154. procedure tsFormatUnmap(const aFormat: TtsFormat; var aData: PByte; out aColor: TtsColor4f);
  155. function tsImageModeFuncIgnore(const aSource, aDest: Single): Single;
  156. function tsImageModeFuncReplace(const aSource, aDest: Single): Single;
  157. function tsImageModeFuncModulate(const aSource, aDest: Single): Single;
  158. implementation
  159. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  160. function tsColor4f(r, g, b, a: Single): TtsColor4f;
  161. begin
  162. result.r := r;
  163. result.g := g;
  164. result.b := b;
  165. result.a := a;
  166. end;
  167. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  168. function tsRect(const l, t, r, b: Integer): TtsRect;
  169. begin
  170. result.Left := l;
  171. result.Top := t;
  172. result.Right := r;
  173. result.Bottom := b;
  174. end;
  175. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  176. function tsPosition(const x, y: Integer): TtsPosition;
  177. begin
  178. result.x := x;
  179. result.y := y;
  180. end;
  181. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  182. function tsFormatSize(const aFormat: TtsFormat): Integer;
  183. begin
  184. case aFormat of
  185. tsFormatRGBA8: result := 4;
  186. tsFormatLumAlpha8: result := 2;
  187. tsFormatAlpha8: result := 1;
  188. else
  189. result := 0;
  190. end;
  191. end;
  192. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  193. procedure tsFormatMap(const aFormat: TtsFormat; var aData: PByte; const aColor: TtsColor4f);
  194. var
  195. i: Integer;
  196. s: Single;
  197. begin
  198. case aFormat of
  199. tsFormatRGBA8: begin
  200. for i := 0 to 3 do begin
  201. aData^ := Trunc($FF * aColor.arr[i]);
  202. inc(aData);
  203. end;
  204. end;
  205. tsFormatLumAlpha8: begin
  206. s := 0.30 * aColor.r + 0.59 * aColor.g + 0.11 * aColor.b;
  207. aData^ := Trunc($FF * s); inc(aData);
  208. aData^ := Trunc($FF * s); inc(aData);
  209. aData^ := Trunc($FF * s); inc(aData);
  210. aData^ := Trunc($FF * aColor.a); inc(aData);
  211. end;
  212. tsFormatAlpha8: begin
  213. aData^ := Trunc($FF * aColor.a);
  214. inc(aData);
  215. end;
  216. end;
  217. end;
  218. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  219. procedure tsFormatUnmap(const aFormat: TtsFormat; var aData: PByte; out aColor: TtsColor4f);
  220. var
  221. i: Integer;
  222. begin
  223. case aFormat of
  224. tsFormatRGBA8: begin
  225. for i := 0 to 3 do begin
  226. aColor.arr[i] := aData^ / $FF;
  227. inc(aData);
  228. end;
  229. end;
  230. tsFormatLumAlpha8: begin
  231. aColor.r := aData^ / $FF;
  232. aColor.g := aData^ / $FF;
  233. aColor.b := aData^ / $FF;
  234. inc(aData);
  235. aColor.a := aData^ / $FF;
  236. inc(aData);
  237. end;
  238. tsFormatAlpha8: begin
  239. aColor.r := 1.0;
  240. aColor.g := 1.0;
  241. aColor.b := 1.0;
  242. aColor.a := aData^ / $FF;
  243. inc(aData);
  244. end;
  245. end;
  246. end;
  247. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  248. function tsImageModeFuncIgnore(const aSource, aDest: Single): Single;
  249. begin
  250. result := aDest;
  251. end;
  252. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  253. function tsImageModeFuncReplace(const aSource, aDest: Single): Single;
  254. begin
  255. result := aSource;
  256. end;
  257. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  258. function tsImageModeFuncModulate(const aSource, aDest: Single): Single;
  259. begin
  260. result := aSource * aDest;
  261. end;
  262. end.