include "draw.s7i";
include "font.s7i";
include "pixmapfont.s7i";
include "text.s7i";
include "null_file.s7i";
const type: pixmapFontFile is sub null_file struct
var PRIMITIVE_WINDOW: win is PRIMITIVE_WINDOW.value;
var activeFont: font is activeFont.value;
var integer: height is 0;
var integer: width is 0;
var integer: line is 0;
var integer: column is 0;
var integer: minX is 0;
var integer: minY is 0;
var integer: lineStartX is 0;
var integer: currLeftX is 0;
var integer: currTopY is 0;
var integer: currBaseY is 0;
var boolean: useBaseY is FALSE;
end struct;
type_implements_interface(pixmapFontFile, text);
const func text: openPixmapFontFile (in PRIMITIVE_WINDOW: win) is func
result
var text: newFile is STD_NULL;
local
var pixmapFontFile: new_file is pixmapFontFile.value;
begin
new_file.win := win;
new_file.font.baseFont := fontProperties.value;
newFile := toInterface(new_file);
end func;
const func text: openPixmapFontFile (in PRIMITIVE_WINDOW: win,
in integer: minX, in integer: minY) is func
result
var text: newFile is STD_NULL;
local
var pixmapFontFile: new_file is pixmapFontFile.value;
begin
new_file.win := win;
new_file.font.baseFont := fontProperties.value;
new_file.minX := minX;
new_file.minY := minY;
new_file.lineStartX := minX;
new_file.currLeftX := minX;
new_file.currTopY := minY;
newFile := toInterface(new_file);
end func;
const proc: flush (inout pixmapFontFile: aFile) is func
begin
flushGraphic;
end func;
const proc: setFont (inout text: aText, in font: aFont) is DYNAMIC;
const func font: getFont (in text: aText) is DYNAMIC;
const func font: getFont (in pixmapFontFile: fontFile) is
return fontFile.font.baseFont;
const proc: cursor (ref pixmapFontFile: fontFile, ref boolean: active) is noop;
const func integer: height (in pixmapFontFile: fontFile) is
return fontFile.height;
const func integer: width (in pixmapFontFile: fontFile) is
return fontFile.width;
const func integer: line (in pixmapFontFile: fontFile) is
return fontFile.line;
const func integer: column (in pixmapFontFile: fontFile) is
return fontFile.column;
const proc: clear (inout pixmapFontFile: fontFile,
in integer: upper, in integer: left, in integer: lower, in integer: right) is func
begin
rectTo(fontFile.win,
fontFile.minX + column_delta(fontFile.font) * pred(left),
fontFile.minY + line_delta(fontFile.font) * pred(upper),
fontFile.minX + pred(column_delta(fontFile.font) * right),
fontFile.minY + pred(line_delta(fontFile.font) * lower),
background(fontFile.font));
fontFile.lineStartX := fontFile.minX;
fontFile.currTopY := fontFile.minY + line_delta(fontFile.font) * pred(upper);
fontFile.currLeftX := fontFile.minX + column_delta(fontFile.font) * pred(left);
fontFile.useBaseY := FALSE;
end func;
const proc: clear (inout pixmapFontFile: fontFile) is func
begin
rectTo(fontFile.win,
fontFile.minX,
fontFile.minY,
pred(width(fontFile.win)),
pred(height(fontFile.win)),
background(fontFile.font));
fontFile.lineStartX := fontFile.minX;
fontFile.currTopY := fontFile.minY;
fontFile.currLeftX := fontFile.minX;
fontFile.useBaseY := FALSE;
end func;
const proc: v_scroll (inout pixmapFontFile: fontFile,
in integer: upper, in integer: left, in integer: lower, in integer: right,
in integer: count) is func
begin
if count > 0 then
copyArea(fontFile.win, fontFile.win,
fontFile.minX + column_delta(fontFile.font) * pred(left),
fontFile.minY + line_delta(fontFile.font) * pred(upper + count),
column_delta(fontFile.font) * succ(right - left),
line_delta(fontFile.font) * succ(lower - upper - count),
fontFile.minX + column_delta(fontFile.font) * pred(left),
fontFile.minY + line_delta(fontFile.font) * pred(upper));
rect(fontFile.win,
fontFile.minX + column_delta(fontFile.font) * pred(left),
fontFile.minY + line_delta(fontFile.font) * (lower - count),
column_delta(fontFile.font) * succ(right - left),
line_delta(fontFile.font) * count,
black);
elsif count < 0 then
copyArea(fontFile.win, fontFile.win,
fontFile.minX + column_delta(fontFile.font) * pred(left),
fontFile.minY + line_delta(fontFile.font) * pred(upper),
column_delta(fontFile.font) * succ(right - left),
line_delta(fontFile.font) * succ(lower - upper + count),
fontFile.minX + column_delta(fontFile.font) * pred(left),
fontFile.minY + line_delta(fontFile.font) * pred(upper - count));
end if;
end func;
const proc: setPos (inout pixmapFontFile: fontFile,
in integer: line, in integer: column) is func
begin
if fontFile.line <> line or fontFile.column <> column then
fontFile.lineStartX := fontFile.minX;
fontFile.currTopY := fontFile.minY + line_delta(fontFile.font) * pred(line);
fontFile.currLeftX := fontFile.minX + column_delta(fontFile.font) * pred(column);
fontFile.useBaseY := FALSE;
fontFile.line := line;
fontFile.column := column;
end if;
end func;
const proc: setPosXY (inout pixmapFontFile: fontFile, in integer: xPos, in integer: yPos) is func
begin
fontFile.lineStartX := fontFile.minX + xPos;
fontFile.currLeftX := fontFile.minX + xPos;
fontFile.currBaseY := fontFile.minY + yPos;
fontFile.useBaseY := TRUE;
if line_delta(fontFile.font) <> 0 then
fontFile.line := yPos div line_delta(fontFile.font);
end if;
if column_delta(fontFile.font) <> 0 then
fontFile.column := xPos div column_delta(fontFile.font);
end if;
end func;
const proc: setLine (inout pixmapFontFile: fontFile, in integer: line) is func
begin
fontFile.currTopY := fontFile.minY + line_delta(fontFile.font) * pred(line);
fontFile.useBaseY := FALSE;
fontFile.line := line;
end func;
const proc: setColumn (inout pixmapFontFile: fontFile, in integer: column) is func
begin
fontFile.lineStartX := fontFile.minX;
fontFile.currLeftX := fontFile.minX + column_delta(fontFile.font) * pred(column);
fontFile.column := column;
end func;
const proc: color (inout pixmapFontFile: fontFile, in color: col) is func
begin
fontFile.font := getFont(fontFile.font.baseFont, fontSize(fontFile.font),
scale(fontFile.font), col, background(fontFile.font));
end func;
const proc: color (inout pixmapFontFile: fontFile, in color: col, in color: backgr) is func
begin
fontFile.font := getFont(fontFile.font.baseFont, fontSize(fontFile.font),
scale(fontFile.font), col, backgr);
end func;
const proc: scale (inout text: aText, in integer: scale) is DYNAMIC;
const proc: scale (inout pixmapFontFile: fontFile, in integer: scale) is func
begin
fontFile.font := getFont(fontFile.font.baseFont, fontSize(fontFile.font),
scale, foreground(fontFile.font), background(fontFile.font));
end func;
const proc: write (inout pixmapFontFile: fontFile, in string: stri) is func
local
var char: ch is ' ';
var PRIMITIVE_WINDOW: charPixmap is PRIMITIVE_WINDOW.value;
begin
if fontFile.useBaseY then
fontFile.currTopY := fontFile.currBaseY - baseLineDelta(fontFile.font);
else
fontFile.currBaseY := fontFile.currTopY + baseLineDelta(fontFile.font);
fontFile.useBaseY := TRUE;
end if;
for ch range stri do
if ch in fontFile.font.pixmap then
charPixmap := fontFile.font.pixmap[ch];
else
charPixmap := getFontCharPixmap(fontFile.font, ch);
end if;
put(fontFile.win, fontFile.currLeftX, fontFile.currTopY, charPixmap);
fontFile.currLeftX +:= width(charPixmap);
if characterSpacing(fontFile.font) <> 0 then
rect(fontFile.win, fontFile.currLeftX, fontFile.currTopY,
characterSpacing(fontFile.font), height(charPixmap), background(fontFile.font));
fontFile.currLeftX +:= characterSpacing(fontFile.font);
end if;
end for;
fontFile.column +:= length(stri);
end func;
const proc: writeln (inout pixmapFontFile: fontFile) is func
begin
incr(fontFile.line);
fontFile.column := 1;
fontFile.currLeftX := fontFile.lineStartX;
if fontFile.useBaseY then
fontFile.currTopY := fontFile.currBaseY - baseLineDelta(fontFile.font) + line_delta(fontFile.font);
fontFile.useBaseY := FALSE;
else
fontFile.currTopY +:= line_delta(fontFile.font);
end if;
end func;
const proc: moveLeft (inout pixmapFontFile: fontFile, in string: stri) is func
local
var char: ch is ' ';
var PRIMITIVE_WINDOW: charPixmap is PRIMITIVE_WINDOW.value;
begin
for ch range stri do
if ch in fontFile.font.pixmap then
charPixmap := fontFile.font.pixmap[ch];
else
charPixmap := getFontCharPixmap(fontFile.font, ch);
end if;
fontFile.currLeftX -:= width(charPixmap) + characterSpacing(fontFile.font);
end for;
end func;
const proc: erase (inout pixmapFontFile: fontFile, in string: stri) is func
local
var char: ch is ' ';
var PRIMITIVE_WINDOW: charPixmap is PRIMITIVE_WINDOW.value;
var integer: width is 0;
var integer: height is 0;
begin
if stri <> "" then
if fontFile.useBaseY then
fontFile.currTopY := fontFile.currBaseY - baseLineDelta(fontFile.font);
else
fontFile.currBaseY := fontFile.currTopY + baseLineDelta(fontFile.font);
fontFile.useBaseY := TRUE;
end if;
for ch range stri do
if ch in fontFile.font.pixmap then
charPixmap := fontFile.font.pixmap[ch];
else
charPixmap := getFontCharPixmap(fontFile.font, ch);
end if;
width +:= width(charPixmap);
height := max(height, height(charPixmap));
end for;
width +:= characterSpacing(fontFile.font) * length(stri);
rect(fontFile.win, fontFile.currLeftX, fontFile.currTopY, width, height,
background(fontFile.font));
fontFile.currLeftX +:= width;
end if;
end func;
const proc: cursorOn (inout pixmapFontFile: fontFile, in char: cursorChar) is func
local
var activeFont: font is activeFont.value;
var PRIMITIVE_WINDOW: charPixmap is PRIMITIVE_WINDOW.value;
begin
if fontFile.useBaseY then
fontFile.currTopY := fontFile.currBaseY - baseLineDelta(fontFile.font);
else
fontFile.currBaseY := fontFile.currTopY + baseLineDelta(fontFile.font);
fontFile.useBaseY := TRUE;
end if;
font := getFont(fontFile.font.baseFont, fontSize(fontFile.font),
scale(fontFile.font), background(fontFile.font), foreground(fontFile.font));
if cursorChar in font.pixmap then
charPixmap := font.pixmap[cursorChar];
else
charPixmap := getFontCharPixmap(font, cursorChar);
end if;
put(fontFile.win, fontFile.currLeftX, fontFile.currTopY, charPixmap);
end func;
const proc: cursorOff (inout pixmapFontFile: fontFile, in char: cursorChar) is func
local
var PRIMITIVE_WINDOW: charPixmap is PRIMITIVE_WINDOW.value;
begin
if fontFile.useBaseY then
fontFile.currTopY := fontFile.currBaseY - baseLineDelta(fontFile.font);
else
fontFile.currBaseY := fontFile.currTopY + baseLineDelta(fontFile.font);
fontFile.useBaseY := TRUE;
end if;
if cursorChar in fontFile.font.pixmap then
charPixmap := fontFile.font.pixmap[cursorChar];
else
charPixmap := getFontCharPixmap(fontFile.font, cursorChar);
end if;
put(fontFile.win, fontFile.currLeftX, fontFile.currTopY, charPixmap);
end func;