Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6613 leency 1
(*
2
    Copyright 2016 KolibriOS team
3
 
4
    This program is free software: you can redistribute it and/or modify
5
    it under the terms of the GNU Lesser General Public License as published by
6
    the Free Software Foundation, either version 3 of the License, or
7
    (at your option) any later version.
8
 
9
    This program is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    GNU Lesser General Public License for more details.
13
 
14
    You should have received a copy of the GNU Lesser General Public License
15
    along with this program.  If not, see .
16
*)
17
 
18
MODULE RasterWorks;
19
 
20
IMPORT sys := SYSTEM, KOSAPI;
21
 
22
 
23
CONST
24
 
25
(* flags *)
26
 
27
  bold		  *=   1;
28
  italic	  *=   2;
29
  underline	  *=   4;
30
  strike_through  *=   8;
31
  align_right	  *=  16;
32
  align_center	  *=  32;
33
 
34
  bpp32 	  *= 128;
35
 
36
 
37
(* encoding *)
38
 
39
  cp866 	  *=   1;
40
  utf16le	  *=   2;
41
  utf8		  *=   3;
42
 
43
 
44
VAR
45
 
46
  // draw text on 24bpp or 32bpp image
47
  // autofits text between 'x' and 'xSize'
48
  drawText *: PROCEDURE (canvas, x, y, string, charQuantity, fontColor, params: INTEGER): INTEGER;
49
(*
50
  [canvas]:
51
    xSize	 dd  ?
52
    ySize	 dd  ?
53
    picture	 rb  xSize * ySize * bpp
54
 
55
   fontColor	 dd  AARRGGBB
56
    AA = alpha channel	 ; 0 = transparent, FF = non transparent
57
 
58
   params	 dd  ffeewwhh
59
    hh = char height
60
    ww = char width	 ; 0 = auto (proportional)
61
    ee = encoding	 ; 1 = cp866, 2 = UTF-16LE, 3 = UTF-8
62
    ff = flags		 ; 0001 = bold, 0010 = italic
63
			 ; 0100 = underline, 1000 = strike-through
64
   00010000 = align right, 00100000 = align center
65
   01000000 = set text area between higher and lower halfs of 'x'
66
   10000000 = 32bpp canvas insted of 24bpp
67
   all flags combinable, except align right + align center
68
 
69
   returns: char width (0 = error)
70
*)
71
 
72
  // calculate amount of valid chars in UTF-8 string
73
  // supports zero terminated string (set byteQuantity = -1)
74
  cntUTF_8 *: PROCEDURE (string, byteQuantity: INTEGER): INTEGER;
75
 
76
 
77
  // calculate amount of chars that fits given width
78
  charsFit *: PROCEDURE (areaWidth, charHeight: INTEGER): INTEGER;
79
 
80
 
81
  // calculate string width in pixels
82
  strWidth *: PROCEDURE (charQuantity, charHeight: INTEGER): INTEGER;
83
 
84
 
85
PROCEDURE params* (charHeight, charWidth, encoding, flags: INTEGER): INTEGER;
86
(*
87
    hh = char height
88
    ww = char width	 ; 0 = auto (proportional)
89
    ee = encoding	 ; 1 = cp866, 2 = UTF-16LE, 3 = UTF-8
90
    ff = flags		 ; 0001 = bold, 0010 = italic
91
			; 0100 = underline, 1000 = strike-through
92
   00010000 = align right, 00100000 = align center
93
   01000000 = set text area between higher and lower halfs of 'x'
94
   10000000 = 32bpp canvas insted of 24bpp
95
   all flags combinable, except align right + align center
96
*)
97
  RETURN charHeight + LSL(charWidth, 8) + LSL(encoding, 16) + LSL(flags, 24)
98
END params;
99
 
100
 
101
PROCEDURE main;
102
VAR Lib: INTEGER;
103
 
104
  PROCEDURE GetProc(v: INTEGER; name: ARRAY OF CHAR);
105
  VAR a: INTEGER;
106
  BEGIN
107
    a := KOSAPI.GetProcAdr(name, Lib);
108
    ASSERT(a # 0);
109
    sys.PUT(v, a)
110
  END GetProc;
111
 
112
BEGIN
113
  Lib := KOSAPI.LoadLib("/rd/1/lib/RasterWorks.obj");
114
  ASSERT(Lib # 0);
115
  GetProc(sys.ADR(drawText), "drawText");
116
  GetProc(sys.ADR(cntUTF_8), "cntUTF-8");
117
  GetProc(sys.ADR(charsFit), "charsFit");
118
  GetProc(sys.ADR(strWidth), "strWidth");
119
END main;
120
 
121
 
122
BEGIN
123
  main
124
END RasterWorks.