2019-10-06 19:55:12 +02:00
|
|
|
(*
|
2019-03-11 09:59:55 +01:00
|
|
|
Copyright 2016, 2018 KolibriOS team
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE RasterWorks;
|
|
|
|
|
|
|
|
IMPORT sys := SYSTEM, KOSAPI;
|
|
|
|
|
|
|
|
|
|
|
|
CONST
|
|
|
|
|
|
|
|
(* flags *)
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
bold *= 1;
|
|
|
|
italic *= 2;
|
|
|
|
underline *= 4;
|
2016-10-24 01:30:27 +02:00
|
|
|
strike_through *= 8;
|
2019-03-11 09:59:55 +01:00
|
|
|
align_right *= 16;
|
|
|
|
align_center *= 32;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
bpp32 *= 128;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
(* encoding *)
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
cp866 *= 1;
|
|
|
|
utf16le *= 2;
|
|
|
|
utf8 *= 3;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
VAR
|
|
|
|
|
|
|
|
// draw text on 24bpp or 32bpp image
|
|
|
|
// autofits text between 'x' and 'xSize'
|
|
|
|
drawText *: PROCEDURE (canvas, x, y, string, charQuantity, fontColor, params: INTEGER): INTEGER;
|
|
|
|
(*
|
|
|
|
[canvas]:
|
2019-03-11 09:59:55 +01:00
|
|
|
xSize dd ?
|
|
|
|
ySize dd ?
|
|
|
|
picture rb xSize * ySize * bpp
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
fontColor dd AARRGGBB
|
|
|
|
AA = alpha channel ; 0 = transparent, FF = non transparent
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
params dd ffeewwhh
|
2016-10-24 01:30:27 +02:00
|
|
|
hh = char height
|
2019-03-11 09:59:55 +01:00
|
|
|
ww = char width ; 0 = auto (proportional)
|
|
|
|
ee = encoding ; 1 = cp866, 2 = UTF-16LE, 3 = UTF-8
|
|
|
|
ff = flags ; 0001 = bold, 0010 = italic
|
|
|
|
; 0100 = underline, 1000 = strike-through
|
2016-10-24 01:30:27 +02:00
|
|
|
00010000 = align right, 00100000 = align center
|
|
|
|
01000000 = set text area between higher and lower halfs of 'x'
|
|
|
|
10000000 = 32bpp canvas insted of 24bpp
|
|
|
|
all flags combinable, except align right + align center
|
|
|
|
|
|
|
|
returns: char width (0 = error)
|
|
|
|
*)
|
|
|
|
|
|
|
|
// calculate amount of valid chars in UTF-8 string
|
|
|
|
// supports zero terminated string (set byteQuantity = -1)
|
|
|
|
cntUTF_8 *: PROCEDURE (string, byteQuantity: INTEGER): INTEGER;
|
|
|
|
|
|
|
|
|
|
|
|
// calculate amount of chars that fits given width
|
|
|
|
charsFit *: PROCEDURE (areaWidth, charHeight: INTEGER): INTEGER;
|
|
|
|
|
|
|
|
|
|
|
|
// calculate string width in pixels
|
|
|
|
strWidth *: PROCEDURE (charQuantity, charHeight: INTEGER): INTEGER;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE params* (charHeight, charWidth, encoding, flags: INTEGER): INTEGER;
|
|
|
|
(*
|
|
|
|
hh = char height
|
2019-03-11 09:59:55 +01:00
|
|
|
ww = char width ; 0 = auto (proportional)
|
|
|
|
ee = encoding ; 1 = cp866, 2 = UTF-16LE, 3 = UTF-8
|
|
|
|
ff = flags ; 0001 = bold, 0010 = italic
|
|
|
|
; 0100 = underline, 1000 = strike-through
|
2016-10-24 01:30:27 +02:00
|
|
|
00010000 = align right, 00100000 = align center
|
|
|
|
01000000 = set text area between higher and lower halfs of 'x'
|
|
|
|
10000000 = 32bpp canvas insted of 24bpp
|
|
|
|
all flags combinable, except align right + align center
|
|
|
|
*)
|
|
|
|
RETURN charHeight + LSL(charWidth, 8) + LSL(encoding, 16) + LSL(flags, 24)
|
|
|
|
END params;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE main;
|
|
|
|
VAR Lib: INTEGER;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE GetProc(Lib, v: INTEGER; name: ARRAY OF CHAR);
|
2016-10-24 01:30:27 +02:00
|
|
|
VAR a: INTEGER;
|
|
|
|
BEGIN
|
|
|
|
a := KOSAPI.GetProcAdr(name, Lib);
|
|
|
|
ASSERT(a # 0);
|
|
|
|
sys.PUT(v, a)
|
|
|
|
END GetProc;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
Lib := KOSAPI.LoadLib("/rd/1/lib/RasterWorks.obj");
|
|
|
|
ASSERT(Lib # 0);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetProc(Lib, sys.ADR(drawText), "drawText");
|
|
|
|
GetProc(Lib, sys.ADR(cntUTF_8), "cntUTF-8");
|
|
|
|
GetProc(Lib, sys.ADR(charsFit), "charsFit");
|
|
|
|
GetProc(Lib, sys.ADR(strWidth), "strWidth");
|
2016-10-24 01:30:27 +02:00
|
|
|
END main;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
main
|
2019-10-06 19:55:12 +02:00
|
|
|
END RasterWorks.
|