include "font.s7i";
include "pixmapfont.s7i";
include "pixmap_file.s7i";
const type: fontPicType is hash [char] array string;
const type: bitmapFont is sub fontProperties struct
var fontPicType: fontPictures is fontPicType.value;
end struct;
type_implements_interface(bitmapFont, font);
const func integer: width (in bitmapFont: bmpFont, in string: stri) is func
result
var integer: width is 0;
local
var char: ch is ' ';
begin
for ch range stri do
if ch in bmpFont.fontPictures then
width +:= length(bmpFont.fontPictures[ch][1]);
else
width +:= length(bmpFont.fontPictures[' '][1]);
end if;
end for;
width +:= characterSpacing(bmpFont) * length(stri);
end func;
const func integer: numOfCharsInWidth (in bitmapFont: bmpFont,
in string: stri, in integer: allowedWidth) is func
result
var integer: numOfChars is 0;
local
var integer: index is 1;
var integer: totalWidth is 0;
begin
while index <= length(stri) and totalWidth <= allowedWidth do
if stri[index] in bmpFont.fontPictures then
totalWidth +:= length(bmpFont.fontPictures[stri[index]][1]);
else
totalWidth +:= length(bmpFont.fontPictures[' '][1]);
end if;
totalWidth +:= characterSpacing(bmpFont);
if totalWidth <= allowedWidth then
incr(index);
end if;
end while;
numOfChars := pred(index);
end func;
const func PRIMITIVE_WINDOW: genPixmap (in array string: pattern,
in color: foreground, in color: background, in integer: scale) is func
result
var PRIMITIVE_WINDOW: pixmap is PRIMITIVE_WINDOW.value;
local
var integer: height is 0;
var integer: width is 0;
var integer: line is 0;
var integer: column is 0;
begin
height := length(pattern);
width := length(pattern[1]);
pixmap := newPixmap(width * scale, height * scale);
clear(pixmap, background);
for line range 1 to height do
for column range 1 to width do
if pattern[line][column] <> ' ' then
rect(pixmap, pred(column) * scale, pred(line) * scale,
scale, scale, foreground);
end if;
end for;
end for;
end func;
const func pixmapFontType: genPixmapFont (in bitmapFont: bmpFont,
in integer: fontSize, in integer: scale,
in color: foreground, in color: background) is func
result
var pixmapFontType: pixmapFont is pixmapFontType.value;
begin
if ' ' in bmpFont.fontPictures then
incl(pixmapFont.pixmap, ' ', genPixmap(bmpFont.fontPictures[' '],
foreground, background, scale));
end if;
pixmapFont.baseFont := bmpFont;
pixmapFont.fontSize := fontSize;
pixmapFont.scale := scale;
pixmapFont.foreground := foreground;
pixmapFont.background := background;
pixmapFont.baseLineDelta := baseLineDelta(bmpFont) * scale;
pixmapFont.line_delta := lineHeight(bmpFont) * scale;
pixmapFont.column_delta := columnWidth(bmpFont) * scale;
pixmapFont.characterSpacing := characterSpacing(bmpFont) * scale;
end func;
const func PRIMITIVE_WINDOW: getFontCharPixmap (in bitmapFont: bmpFont,
inout pixmapFontType: pixmapFont, in char: ch) is func
result
var PRIMITIVE_WINDOW: charPixmap is PRIMITIVE_WINDOW.value;
begin
if ch in bmpFont.fontPictures then
charPixmap := genPixmap(bmpFont.fontPictures[ch],
pixmapFont.foreground, pixmapFont.background, pixmapFont.scale);
incl(pixmapFont.pixmap, ch, charPixmap);
else
charPixmap := pixmapFont.pixmap[' '];
end if;
end func;
const proc: setFont (inout pixmapFontFile: fontFile, in bitmapFont: aFont) is func
begin
fontFile.font := getFont(aFont, fontSize(fontFile.font),
scale(fontFile.font), foreground(fontFile.font), background(fontFile.font));
end func;
const func integer: columnWidth (in fontPicType: fontPictures) is func
result
var integer: maxWidth is 0;
local
var char: ch is ' ';
begin
for key ch range fontPictures do
if length(fontPictures[ch][1]) > maxWidth then
maxWidth := length(fontPictures[ch][1]);
end if;
end for;
end func;