Code covered by the BSD License
-
getCharCoordinates(c, fontHei...
-
getStringCoordinates(font, in...
-
loadAndParseTFF(filename)
load and parse tff file
-
matprint(image, position, inp...
function [image] = matprint(image, position, inputString, color, font, fontHeight[, options])
-
parseChar(line, filename, ln)
-
processText(line)
-
main.m
-
View all files
from
matprint
by Karel Lebeda
Prints (rasterizes) text directly to image matrix.
|
| getStringCoordinates(font, inputString, fontHeight) |
function [coords] = getStringCoordinates(font, inputString, fontHeight)
coords = zeros(2,0);
currentMax = 1;
for i = 1:length(inputString)
if i ~= 1 % spacing between characters
currentMax = currentMax + round(font.spacing * fontHeight);
end
% rasterize and add character
charIndex = inputString(i) + 0;
if isempty(font.char(charIndex).char) % default is question mark which is mandatory in every font file
charIndex = '?' + 0;
end
c = font.char(charIndex); % find character
newCoords = getCharCoordinates(c, fontHeight); % rasterize character locally
newCoords(1,:) = newCoords(1,:) + currentMax; % shift horizontally to the final position inside string
coords = [coords newCoords];
currentMax = currentMax + round(c.width * fontHeight);
end
coords = unique(coords', 'rows')';
end
|
|
Contact us