Subversion Repositories Kolibri OS

Rev

Rev 7696 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7983 leency 1
(*
7597 akron1 2
    Copyright 2016, 2018 KolibriOS team
6613 leency 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
 
7597 akron1 27
  bold            *=   1;
28
  italic          *=   2;
29
  underline       *=   4;
6613 leency 30
  strike_through  *=   8;
7597 akron1 31
  align_right     *=  16;
32
  align_center    *=  32;
6613 leency 33
 
7597 akron1 34
  bpp32           *= 128;
6613 leency 35
 
36
 
37
(* encoding *)
38
 
7597 akron1 39
  cp866           *=   1;
40
  utf16le         *=   2;
41
  utf8            *=   3;
6613 leency 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]:
7597 akron1 51
    xSize        dd  ?
52
    ySize        dd  ?
53
    picture      rb  xSize * ySize * bpp
6613 leency 54
 
7597 akron1 55
   fontColor     dd  AARRGGBB
56
    AA = alpha channel   ; 0 = transparent, FF = non transparent
6613 leency 57
 
7597 akron1 58
   params        dd  ffeewwhh
6613 leency 59
    hh = char height
7597 akron1 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
6613 leency 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
7597 akron1 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
6613 leency 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
 
7597 akron1 104
  PROCEDURE GetProc(Lib, v: INTEGER; name: ARRAY OF CHAR);
6613 leency 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);
7597 akron1 115
  GetProc(Lib, sys.ADR(drawText), "drawText");
116
  GetProc(Lib, sys.ADR(cntUTF_8), "cntUTF-8");
117
  GetProc(Lib, sys.ADR(charsFit), "charsFit");
118
  GetProc(Lib, sys.ADR(strWidth), "strWidth");
6613 leency 119
END main;
120
 
121
 
122
BEGIN
123
  main
7983 leency 124
END RasterWorks.