MakeRasterFontImpl.mesa
Copyright (C) 1984, Xerox Corporation. All rights reserved.
Michael Plass, June 27, 1985 5:35:07 pm PDT
DIRECTORY ImagerMaskCapture, ImagerBox, BitmapViewer, Commander, Imager, ImagerPixelMap, ImagerTransformation,
IO, ImagerFont, FontEdit, Real, Rope, RasterFontIO, MakeRasterFont, ImagerPressFontSubst, ViewerClasses;
EXPORTS MakeRasterFont ~
BEGIN
ROPE: TYPE ~ Rope.ROPE;
Font: TYPE ~ ImagerFont.Font;
InternalFont: TYPE ~ RasterFontIO.InternalFont;
Transformation: TYPE ~ ImagerTransformation.Transformation;
visible:
BOOLEAN ←
FALSE;
FromFont:
PUBLIC
PROC [font: Font]
RETURNS [internalFont: InternalFont] ~ {
bb: Imager.Box ← ImagerBox.BoxFromExtents[ImagerFont.FontBoundingBox[font]];
dbb: ImagerPixelMap.DeviceRectangle ← [Real.RoundLI[-bb.ymax], Real.RoundLI[+bb.xmin], Real.RoundLI[bb.ymax]-Real.RoundLI[bb.ymin], Real.RoundLI[bb.xmax]-Real.RoundLI[bb.xmin]];
viewer: ViewerClasses.Viewer ← IF visible THEN BitmapViewer.Create[[name: font.name], TRUE, center, center] ELSE NIL;
m: Transformation ~ ImagerTransformation.Rotate[90];
pfd: ImagerPressFontSubst.PressFontDescription ~ ImagerPressFontSubst.FindSubstitute[font.name, font.charToClient, press];
internalFont ← RasterFontIO.Create[dbb, dbb.fSize];
IF pfd#
NIL
THEN {
internalFont.family ← pfd.family;
internalFont.face ← pfd.face;
};
internalFont.bitsPerEmQuad ← font.charToClient.SingularValues.x;
FOR c:
CHAR
IN
CHAR
DO
IF font.Contains[[0,
ORD[c]]]
THEN {
op:
PROC[context: Imager.Context] ~ {
Char: ImagerFont.XStringProc ~ {charAction[[0, ORD[c]]]};
Imager.SetFont[context, font];
Imager.Show[context, Char];
};
widthVector: Imager.VEC ← ImagerFont.Width[font, [0, ORD[c]]];
pixels: ImagerPixelMap.PixelMap ← ImagerMaskCapture.CaptureBitmap[op, m];
pixels ← pixels.Trim[0];
IF viewer # NIL THEN BitmapViewer.SetBitmap[viewer, pixels];
internalFont.charRep[c] ← [
fWidth: widthVector.x,
sWidth: -widthVector.y,
pixels: pixels
];
};
ENDLOOP;
};
ConvertFile:
PUBLIC
PROC [outputFileName:
ROPE, fontName:
ROPE, size:
REAL, rotation:
REAL, bitsPerInch:
REAL] ~ {
font: Font ← ImagerFont.Find[fontName].Scale[size];
internalFont: InternalFont ← NIL;
IF rotation # 0.0
THEN {
font ← ImagerFont.Modify[font, ImagerTransformation.Rotate[rotation]];
};
internalFont ← FromFont[font];
internalFont.bitsPerInch ← bitsPerInch;
FontEdit.WriteFormatDerivedFromName[internalFont, outputFileName];
};
Break:
PROC [char:
CHAR]
RETURNS [
IO.CharClass] = {
IF char = '← OR char = '; THEN RETURN [break];
IF char = ' OR char = ' OR char = ', OR char = '\n THEN RETURN [sepr];
RETURN [other];
};
GetToken:
PROC [stream:
IO.
STREAM]
RETURNS [rope:
ROPE ←
NIL] = {
rope ← stream.GetTokenRope[Break ! IO.EndOfStream => CONTINUE].token;
};
GetReal:
PROC [stream:
IO.
STREAM]
RETURNS [real:
REAL ← 0.0] = {
real ← stream.GetReal[! IO.Error, IO.EndOfStream => CONTINUE];
};
MakeRasterFontCommand: Commander.CommandProc ~ {
stream: IO.STREAM ← IO.RIS[cmd.commandLine];
outputName: ROPE ← GetToken[stream];
gets: ROPE ← GetToken[stream];
inputName: ROPE ← GetToken[stream];
size: REAL ← GetReal[stream];
sizeUnits: ROPE ← GetToken[stream];
bitsPerInch: REAL ← GetReal[stream];
bpi: ROPE ← GetToken[stream];
rotation: REAL ← GetReal[stream];
IF bitsPerInch = 0.0 AND bpi = NIL THEN {bitsPerInch ← 384.0; bpi ← "bpi"};
SELECT
TRUE
FROM
sizeUnits = NIL OR sizeUnits.Equal["pxl", FALSE] => NULL;
sizeUnits.Equal["pt", FALSE] => {size ← size/72.0*bitsPerInch};
sizeUnits.Equal["mica", FALSE] => {size ← size/2540.0*bitsPerInch};
ENDCASE => gets ← NIL;
IF
NOT gets.Equal["←"]
OR size <= 0.0
OR
NOT bpi.Equal["bpi",
FALSE]
THEN {
cmd.out.PutRope[helpRope];
cmd.out.PutChar['\n];
RETURN;
};
ConvertFile[outputName, inputName, size, rotation, bitsPerInch];
};
helpRope:
ROPE ~ "Convert an Imager font to raster format\n <outputName> ← <fontName> <size> <sizeUnits> <resolution> bpi <rotation>\n <fontName> is an Interpress hierarchical name\n <size> is the desired output size\n <sizeUnits> is pt, mica, or pxl\n <resolution> is in bits per inch\n <rotation> is in degrees";
Commander.Register["MakeRasterFont", MakeRasterFontCommand, helpRope];