CDSpecialCaseForTiogaFontsImpl.mesa (add on package for ChipNDale)
Copyright © 1987 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, August 12, 1987 11:42:16 am PDT
Last edited by: Christian Jacobi, August 12, 1987 3:27:01 pm PDT
This package, if loaded replaces the draw procedures for texts to
check for tioga fonts. If a text is a tioga font, and no fontsubstitution
takes place, the draw procedure expands the text into a label and draws
the label instead of the text. This prevents the imager scan conversion
to run for ever scanning huge tioga fonts.
DIRECTORY
CD,
CDBasics,
CDCreateLabels,
CDOps,
CDProperties,
CDTexts,
CDTextsBackdoor,
D2Orient,
Imager,
ImagerFont,
ImagerTransformation,
Rope;
CDSpecialCaseForTiogaFontsImpl:
CEDAR
PROGRAM
IMPORTS CDBasics, CDCreateLabels, CDOps, CDProperties, CDTexts, CDTextsBackdoor, Imager, ImagerFont, ImagerTransformation
SHARES CDTexts =
BEGIN
myProperty: REF ATOM ← NEW[ATOM ← $CDSpecialCaseForTiogaFonts];
InlineImagerPrintFont:
PROC [cdFont: CDTexts.CDFont]
RETURNS [Imager.Font] =
INLINE {
IF cdFont.substitutedFont=
NIL
THEN
cdFont.substitutedFont ← CDTextsBackdoor.SubstituteTiogaFonts[cdFont.font];
RETURN [cdFont.substitutedFont];
};
FixDraw:
CD.DrawProc = {
WithContext:
PROC [context: Imager.Context, ob:
CD.Object, layer:
CD.Layer] = {
tp: CDTexts.TextSpecific = NARROW[ob.specific];
--don't clip: speed;
--Imager.ClipRectangle[context, [x: ob.bbox.x1, y: ob.bbox.y1, w: ob.bbox.x2-ob.bbox.x1, h: ob.bbox.y2-ob.bbox.y1]];
Imager.SetFont[context, (IF pr.fontSubstitution THEN InlineImagerPrintFont[tp.cdFont] ELSE tp.cdFont.font)];
Imager.SetXY[context, [0, 0]]; --always use original font offsets!
Imager.ShowRope[context, tp.text];
};
IF pr.fontSubstitution THEN pr.drawContext[pr, WithContext, ob, trans, ob.layer]
ELSE {
WITH CDProperties.GetObjectProp[ob, myProperty]
SELECT
FROM
ob: CD.Object => ob.class.drawMe[pr, ob, trans, readOnlyInstProps];
a: ATOM => pr.drawContext[pr, WithContext, ob, trans, ob.layer];
ENDCASE => {Checkout[ob]; FixDraw[pr, ob, trans, readOnlyInstProps]};
};
};
FlipDraw: CD.DrawProc = {
WithContext:
PROC [context: Imager.Context, ob:
CD.Object, layer:
CD.Layer] = {
tp: CDTexts.TextSpecific = NARROW[ob.specific];
--don't clip: speed;
SELECT trans.orient
FROM
original, rotate270 => NULL;
ENDCASE => Imager.ConcatT[context, ImagerFlipTransform[ob.bbox, trans.orient]];
IF pr.fontSubstitution
THEN {
f: Imager.Font ← InlineImagerPrintFont[tp.cdFont];
SELECT trans.orient
FROM
mirrorX, rotate90, rotate180, rotate90X => {
--don't cache the extends: normally on display we don't do fontSubstitution
ex1: ImagerFont.Extents ← ImagerFont.RopeBoundingBox[tp.cdFont.font, tp.text];
ex2: ImagerFont.Extents ← ImagerFont.RopeBoundingBox[f, tp.text];
Imager.SetXY[context, [ex1.rightExtent-ex2.rightExtent, 0]];
};
--otherwise we should do the similar with leftExtend...
--but we don't care because the leftExtend error is more or less constant
--independent of rope and we want more speed.
ENDCASE => Imager.SetXY[context, [0, 0]];
Imager.SetFont[context, f];
}
ELSE {
Imager.SetFont[context, tp.cdFont.font];
Imager.SetXY[context, [0, 0]];
};
Imager.ShowRope[context, tp.text];
};
IF pr.fontSubstitution THEN pr.drawContext[pr, WithContext, ob, trans, ob.layer]
ELSE {
WITH CDProperties.GetObjectProp[ob, myProperty]
SELECT
FROM
ob: CD.Object => ob.class.drawMe[pr, ob, trans, readOnlyInstProps];
a:
ATOM => {
trans ← CDBasics.ComposeTransform[
itemInCell: CDFlipTransform[ob.bbox, trans.orient],
cellInWorld: trans
];
pr.drawContext[pr, WithContext, ob, trans, ob.layer];
};
ENDCASE => {Checkout[ob]; FlipDraw[pr, ob, trans, readOnlyInstProps]};
}
};
CDFlipTransform:
PROC [bbox:
CD.Rect, orient:
CD.Orientation]
RETURNS [
CD.Transformation] = {
SELECT orient
FROM
original, rotate270 => RETURN [[[0, 0], original]];
mirrorX, rotate90X => RETURN [[[bbox.x2-bbox.x1, 0], mirrorX]];
rotate180X, rotate270X => RETURN [[[0, bbox.y2+bbox.y1], rotate180X]];
rotate180, rotate90 => RETURN [[[bbox.x2-bbox.x1, bbox.y2+bbox.y1], rotate180]];
ENDCASE => ERROR;
};
ImagerFlipTransform:
PROC [bbox:
CD.Rect, orient:
CD.Orientation]
RETURNS [Imager.Transformation] =
INLINE {
RETURN [
SELECT orient
FROM
--matrix multiplications done manually for speed
mirrorX, rotate90X => ImagerTransformation.Create[-1, 0, bbox.x2-bbox.x1, 0, 1, 0],
rotate180X, rotate270X => ImagerTransformation.Create[1, 0, 0, 0, -1, bbox.y2+bbox.y1],
rotate180, rotate90 => ImagerTransformation.Create[-1, 0, bbox.x2-bbox.x1, 0, -1, bbox.y2+bbox.y1],
original, rotate270 => ImagerTransformation.Create[1, 0, 0, 0, 1, 0],
ENDCASE => ERROR
]
};
Checkout:
PROC [ob:
CD.Object] = {
CDProperties.PutObjectProp[ob, myProperty, $FALSE];
WITH ob.specific
SELECT
FROM
tp: CDTexts.TextSpecific => {
IF tp.cdFont.scaleI=1 THEN RETURN;
IF tp.cdFont.font # InlineImagerPrintFont[tp.cdFont]
--tests for tioga font!--
THEN {
WITH CDProperties.GetProp[tp.cdFont.properties, $OriginalFont]
SELECT
FROM
baseFont: Imager.Font => {
substitute: CD.Object;
substitute ← CDCreateLabels.MakeRopeCell[design: NIL, text: tp.text, font: baseFont, scale: tp.cdFont.scaleI, layer: ob.layer];
IF substitute=NIL THEN RETURN;
[] ← CDOps.MakeImmutable[substitute];
CDProperties.PutObjectProp[ob, myProperty, substitute];
};
ENDCASE => RETURN; --actually some unknown error
};
};
ENDCASE => RETURN;
};
CDTexts.rigidTextClass.drawMe ← FixDraw;
CDTexts.flipTextClass.drawMe ← FlipDraw;
END.