CommandRep:
TYPE ~
RECORD[
SELECT type: *
FROM
DoSave => [body: CommandList, all: BOOL],
SetInt => [key: IntKey, val: INT],
SetReal => [key: RealKey, val: REAL],
SetT => [m: Transformation],
SetFont => [font: Font],
SetColor => [color: Color],
SetClipper => [clipper: Clipper],
SetStrokeDashes => [strokeDashes: StrokeDashes],
ConcatT => [m: Transformation],
Scale2T => [s: VEC],
RotateT => [a: REAL],
TranslateT => [t: VEC],
Move => [rounded: BOOL],
SetXY => [p: VEC],
SetXYRel => [v: VEC],
Show => [string: XStringSeq, xrel: BOOL],
ShowShort => [text: Rope.Text, xrel: BOOL],
StartUnderline => [],
MaskUnderline => [dy, h: REAL],
CorrectMask => [],
CorrectSpace => [v: VEC],
Space => [x: REAL],
SetCorrectMeasure => [v: VEC],
SetCorrectTolerance => [v: VEC],
Correct => [body: CommandList],
DontCorrect => [body: CommandList, saveCP: BOOL],
SetGray => [f: REAL],
SetSampledColor => [d: REF SetSampledColorData],
SetSampledBlack => [d: REF SetSampledBlackData],
MaskFill => [path: Path, parity: BOOL],
MaskRectangle => [r: REF Rectangle],
MaskRectangleI => [x, y, w, h: INTEGER],
MaskStroke => [path: Path, closed: BOOL],
MaskVector => [p: REF ARRAY [0..2) OF VEC],
MaskPixel => [pa: PixelArray],
MaskBits => [bits: Bits],
DrawBits => [bits: Bits],
Clip => [path: Path, parity: BOOL, exclude: BOOL],
ClipRectangle => [r: REF Rectangle, exclude: BOOL]
ENDCASE
];
Memory Context Procs
Bits: TYPE ~ REF BitsRep;
BitsRep:
TYPE ~
RECORD [
wordsPerLine, sMin, fMin, sSize, fSize: NAT,
tx, ty: INTEGER,
vm: CountedVM.Handle
];
MakeBits:
PROC [base:
LONG
POINTER, wordsPerLine:
NAT, sMin, fMin, sSize, fSize:
NAT, tx, ty:
INTEGER]
RETURNS [bits: Bits] ~ {
nwords: INT ← Basics.LongMult[wordsPerLine, sSize];
vm: CountedVM.Handle ← CountedVM.SimpleAllocate[nwords];
bits ← NEW[BitsRep ← [wordsPerLine, sMin, fMin, sSize, fSize, tx, ty, vm]];
TRUSTED {PrincOpsUtils.LongCopy[from: base, to: vm.pointer, nwords: nwords]}
};
MemoryDoSave:
PROC[context: Context, action:
PROC, all:
BOOL] ~ {
body: CommandList ~ GetBody[context, action];
Append[context, [DoSave [body, all]]];
};
MemorySetInt:
PROC[context: Context, key: IntKey, val:
INT] ~ {
Append[context, [SetInt [key, val]]];
};
MemorySetReal:
PROC[context: Context, key: RealKey, val:
REAL] ~ {
Append[context, [SetReal [key, val]]];
};
MemoryGetT:
PROC[context: Context]
RETURNS[Transformation] ~ {
m: Transformation ← ImagerTransformation.Scale[1.0];
data: Data ~ NARROW[context.data];
IF
NOT data.getTDone
THEN {
data.getTDone ← TRUE;
IF (data.getTForm ← data.getTForm + 1) = endMemForm THEN data.getTForm ← firstMemForm;
};
m.form ← data.getTForm;
RETURN [m];
};
MemorySetT:
PROC[context: Context, m: Transformation] ~ {
Append[context, [SetT [m]]];
};
MemorySetFont:
PROC[context: Context, font: Font] ~ {
Append[context, [SetFont [font]]];
};
MemorySetColor:
PROC[context: Context, color: Color] ~ {
WITH color
SELECT
FROM
sampledColor: SampledColor => {
data: Data ~ NARROW[context.data];
IF data.getTDone
AND sampledColor.um.form = data.getTForm
THEN {
opClass: ATOM ~ ImagerColorOperator.GetColorOperatorClass[sampledColor.colorOperator];
um: Transformation ← ImagerTransformation.Copy[sampledColor.um];
um.form ← 0;
ImagerTransformation.ApplyPreScale[um, 1];
IF opClass = $SampledBlack
OR opClass = $SampledBlackClear
THEN
MemorySetSampledBlack[context, sampledColor.pa, um, opClass=$SampledBlackClear]
ELSE MemorySetSampledColor[context, sampledColor.pa, um, sampledColor.colorOperator];
RETURN;
};
};
ENDCASE => NULL;
Append[context, [SetColor [color]]];
};
MemorySetClipper:
PROC[context: Context, clipper: Clipper] ~ {
Append[context, [SetClipper [clipper]]];
};
MemorySetStrokeDashes:
PROC[context: Context, strokeDashes: StrokeDashes] ~ {
Append[context, [SetStrokeDashes [strokeDashes]]];
};
MemoryGetInt:
PROC[context: Context, key: IntKey]
RETURNS[
INT] ~ {
Imager.Error[[$unimplemented, "Not implemented"]]};
MemoryGetReal:
PROC[context: Context, key: RealKey]
RETURNS[
REAL] ~ {
Imager.Error[[$unimplemented, "Not implemented"]]};
MemoryGetFont:
PROC[context: Context]
RETURNS[Font] ~ {
Imager.Error[[$unimplemented, "Not implemented"]]};
MemoryGetColor:
PROC[context: Context]
RETURNS[Color] ~ {
Imager.Error[[$unimplemented, "Not implemented"]]};
MemoryGetClipper:
PROC[context: Context]
RETURNS[Clipper] ~ {
Imager.Error[[$unimplemented, "Not implemented"]]};
MemoryGetStrokeDashes:
PROC[context: Context]
RETURNS[StrokeDashes] ~ {
Imager.Error[[$unimplemented, "Not implemented"]]};
MemoryConcatT:
PROC[context: Context, m: Transformation] ~ {
Append[context, [ConcatT [m]]];
};
MemoryScale2T:
PROC[context: Context, s:
VEC] ~ {
Append[context, [Scale2T [s]]];
};
MemoryRotateT:
PROC[context: Context, a:
REAL] ~ {
Append[context, [RotateT [a]]];
};
MemoryTranslateT:
PROC[context: Context, t:
VEC] ~ {
Append[context, [TranslateT [t]]];
};
MemoryMove:
PROC[context: Context, rounded:
BOOL] ~ {
Append[context, [Move [rounded]]];
};
MemorySetXY:
PROC[context: Context, p:
VEC] ~ {
Append[context, [SetXY [p]]];
};
MemorySetXYRel:
PROC[context: Context, v:
VEC] ~ {
Append[context, [SetXYRel [v]]];
};
MemoryShow:
PROC[context: Context, string: XStringProc, xrel:
BOOL] ~ {
eightbit: BOOL ← TRUE;
n: INT ← 0;
CountXChars: ImagerFont.XCharProc ~ {
IF char.set # 0 THEN eightbit ← FALSE;
n ← n+1;
};
InstallXChar: ImagerFont.XCharProc ~ {
xString[n] ← char;
n ← n+1;
};
xString: XStringSeq;
string[CountXChars]; -- Count number of chars fed back, set eightbit
IF eightbit
THEN {
text: Rope.Text ~ Rope.NewText[n];
i: NAT ← 0;
InstallChar: ImagerFont.XCharProc ~ {
text[i] ← VAL[char.code];
i ← i+1;
};
text.length ← n;
string[InstallChar]; -- Install each character
Append[context, [ShowShort [text: text, xrel: xrel]]];
}
ELSE {
xString: XStringSeq ~ NEW[XStringSeqRec[n]];
i: INT ← 0;
InstallXChar: ImagerFont.XCharProc ~ {
xString[i] ← char;
i ← i+1;
};
string[InstallXChar]; -- Install each character
Append[context, [Show [string: xString, xrel: xrel]]];
};
};
MemoryShowText:
PROC[context: Context, text:
REF
READONLY
TEXT, start, len:
NAT, xrel:
BOOL] ~ {
class: Class ~ context.class;
string: XStringProc ~ { ImagerFont.MapText[text, start, len, charAction] };
class.Show[context, string, xrel];
};
MemoryStartUnderline:
PROC[context: Context] ~ {
Append[context, [StartUnderline []]]};
MemoryMaskUnderline:
PROC[context: Context, dy, h:
REAL] ~ {
Append[context, [MaskUnderline [dy, h]]];
};
MemoryCorrectMask:
PROC[context: Context] ~ {
Append[context, [CorrectMask []]]};
MemoryCorrectSpace:
PROC[context: Context, v:
VEC] ~ {
Append[context, [CorrectSpace [v]]];
};
MemorySpace:
PROC[context: Context, x:
REAL] ~ {
Append[context, [Space [x]]];
};
MemorySetCorrectMeasure:
PROC[context: Context, v:
VEC] ~ {
Append[context, [SetCorrectMeasure [v]]];
};
MemorySetCorrectTolerance:
PROC[context: Context, v:
VEC] ~ {
Append[context, [SetCorrectTolerance [v]]];
};
MemoryCorrect:
PROC[context: Context, action:
PROC] ~ {
body: CommandList ~ GetBody[context, action];
Append[context, [Correct [body]]];
};
MemoryDontCorrect:
PROC[context: Context, action:
PROC, saveCP:
BOOL] ~ {
body: CommandList ~ GetBody[context, action];
Append[context, [DontCorrect [body, saveCP]]];
};
MemorySetGray:
PROC[context: Context, f:
REAL] ~ {
Append[context, [SetGray [f]]];
};
MemorySetSampledColor:
PROC[context: Context, pa: PixelArray, m: Transformation, colorOperator: ColorOperator] ~ {
Append[context, [SetSampledColor [NEW[SetSampledColorData ← [pa, m, colorOperator]]]]];
};
MemorySetSampledBlack:
PROC[context: Context, pa: PixelArray, m: Transformation, clear:
BOOL] ~ {
Append[context, [SetSampledBlack [NEW[SetSampledBlackData ← [pa, m, clear]]]]];
};
MemoryMaskFill:
PROC[context: Context, path: PathProc, parity:
BOOL] ~ {
pathList: Path ~ GetPath[path];
Append[context, [MaskFill [pathList, parity]]];
};
MemoryMaskRectangle:
PROC[context: Context, r: Rectangle] ~ {
Append[context, [MaskRectangle [NEW[Rectangle ← r]]]];
};
MemoryMaskRectangleI:
PROC[context: Context, x, y, w, h:
INTEGER] ~ {
Append[context, [MaskRectangleI [x, y, w, h]]];
};
MemoryMaskStroke:
PROC[context: Context, path: PathProc, closed:
BOOL] ~ {
pathList: Path ~ GetPath[path];
Append[context, [MaskStroke [pathList, closed]]];
};
MemoryMaskVector:
PROC[context: Context, p1, p2:
VEC] ~ {
Append[context, [MaskVector [NEW[ARRAY [0..2) OF VEC ← [p1, p2]]]]];
};
MemoryMaskPixel:
PROC[context: Context, pa: PixelArray] ~ {
Append[context, [MaskPixel [pa]]];
};
MemoryMaskBits:
PROC[context: Context, base:
LONG
POINTER, wordsPerLine:
NAT, sMin, fMin, sSize, fSize:
NAT, tx, ty:
INTEGER] ~ {
bits: Bits ~ MakeBits[base, wordsPerLine, sMin, fMin, sSize, fSize, tx, ty];
Append[context, [MaskBits [bits]]];
};
MemoryDrawBits:
PROC[context: Context, base:
LONG
POINTER, wordsPerLine:
NAT, sMin, fMin, sSize, fSize:
NAT, tx, ty:
INTEGER] ~ {
bits: Bits ~ MakeBits[base, wordsPerLine, sMin, fMin, sSize, fSize, tx, ty];
Append[context, [DrawBits [bits]]];
};
MemoryClip:
PROC[context: Context, path: PathProc, parity:
BOOL, exclude:
BOOL] ~ {
pathList: Path ~ GetPath[path];
Append[context, [Clip [pathList, parity, exclude]]];
};
MemoryClipRectangle:
PROC[context: Context, r: Rectangle, exclude:
BOOL] ~ {
Append[context, [ClipRectangle [NEW[Rectangle ← r], exclude]]];
};
MemoryClipRectangleI:
PROC[context: Context, x, y, w, h:
INTEGER, exclude:
BOOL] ~ {
Append[context, [ClipRectangle [NEW[Rectangle ← [x, y, w, h]], exclude]]];
};
MemoryGetCP:
PROC[context: Context, rounded:
BOOL]
RETURNS[
VEC] ~ {
Imager.Error[[$unimplemented, "Not implemented"]]};
MemoryGetBoundingRectangle:
PROC[context: Context]
RETURNS[Rectangle] ~ {
Imager.Error[[$unimplemented, "Not implemented"]]};
memoryClass: Class ~
NEW[ClassRep ← [
type: $Memory,
DoSave: MemoryDoSave,
SetInt: MemorySetInt,
SetReal: MemorySetReal,
SetT: MemorySetT,
SetFont: MemorySetFont,
SetColor: MemorySetColor,
SetClipper: MemorySetClipper,
SetStrokeDashes: MemorySetStrokeDashes,
GetInt: MemoryGetInt,
GetReal: MemoryGetReal,
GetT: MemoryGetT,
GetFont: MemoryGetFont,
GetColor: MemoryGetColor,
GetClipper: MemoryGetClipper,
GetStrokeDashes: MemoryGetStrokeDashes,
ConcatT: MemoryConcatT,
Scale2T: MemoryScale2T,
RotateT: MemoryRotateT,
TranslateT: MemoryTranslateT,
Move: MemoryMove,
SetXY: MemorySetXY,
SetXYRel: MemorySetXYRel,
Show: MemoryShow,
ShowText: MemoryShowText,
StartUnderline: MemoryStartUnderline,
MaskUnderline: MemoryMaskUnderline,
CorrectMask: MemoryCorrectMask,
CorrectSpace: MemoryCorrectSpace,
Space: MemorySpace,
SetCorrectMeasure: MemorySetCorrectMeasure,
SetCorrectTolerance: MemorySetCorrectTolerance,
Correct: MemoryCorrect,
DontCorrect: MemoryDontCorrect,
SetGray: MemorySetGray,
SetSampledColor: MemorySetSampledColor,
SetSampledBlack: MemorySetSampledBlack,
MaskFill: MemoryMaskFill,
MaskRectangle: MemoryMaskRectangle,
MaskRectangleI: MemoryMaskRectangleI,
MaskStroke: MemoryMaskStroke,
MaskVector: MemoryMaskVector,
MaskPixel: MemoryMaskPixel,
MaskBits: MemoryMaskBits,
DrawBits: MemoryDrawBits,
Clip: MemoryClip,
ClipRectangle: MemoryClipRectangle,
ClipRectangleI: MemoryClipRectangleI,
GetCP: MemoryGetCP,
GetBoundingRectangle: MemoryGetBoundingRectangle
]];