TSRuleImpl.mesa
Copyright (C) 1984, Xerox Corporation. All rights reserved.
Last Edited by: Michael Plass, April 2, 1985 1:06:17 pm PST
Last Edited by: Beach, December 3, 1984 8:27:23 pm PST
DIRECTORY
IO,
NodeStyle,
NodeStyleOps,
Rope,
TextNode,
TSArtwork,
TSGraphic,
TSObject,
TSOutput,
TSTypes;
TSRuleImpl: CEDAR PROGRAM
IMPORTS IO, NodeStyle, NodeStyleOps, Rope, TextNode, TSArtwork, TSTypes = {
OPEN TSTypes;
ObjectFromBranchProc: TYPE = TSArtwork.ObjectFromBranchProc;
ROPE: TYPE = Rope.ROPE;
RuleRec: TYPE = RECORD [thickness, length: Dimn ← zeroDimn];
RuleFromBranch: ObjectFromBranchProc = {
data: REF RuleRec ← NEW[RuleRec];
textNode: TextNode.RefTextNode ← TextNode.NarrowToTextNode[node];
nodeContents: ROPE ← textNode.rope;
stream: IO.STREAMIO.RIS[nodeContents];
style: NodeStyle.Ref ← NodeStyleOps.Create[];
NodeStyleOps.ApplyAll[style, node, print];
data.thickness ← RealDimn[0.4, pt];
data.length ← RealDimn[NodeStyle.GetLineLength[style] - NodeStyle.GetLeftIndent[style] - NodeStyle.GetFirstIndent[style] - NodeStyle.GetRightIndent[style], pt];
UNTIL IO.EndOf[stream] DO
keyword: ROPE ← stream.GetTokenRope[Break].token;
SELECT keyword.Fetch[0] FROM
'- => data.thickness ← RealDimn[0.4, pt];
'— => data.thickness ← RealDimn[0.4, pt];
'= => data.thickness ← RealDimn[1.0, pt];
'~ => data.thickness ← RealDimn[0.8*NodeStyle.GetFontSize[style], pt];
'# => data.thickness ← RealDimn[0.8*NodeStyle.GetFontSize[style], pt];
ENDCASE => {
colon: ROPE ← GetName[stream];
IF colon.Equal[":"] THEN
SELECT TRUE FROM
keyword.Equal["Thickness", FALSE] => data.thickness ← RealDimn[GetBP[stream],bp];
keyword.Equal["Length", FALSE] => data.length ← RealDimn[GetBP[stream],bp];
ENDCASE => ERROR
ELSE ERROR;
};
ENDLOOP;
object ← NEW[TSGraphic.ObjectRec];
object.paintProc ← RulePaint;
object.layoutProc ← RuleLayout;
object.data ← data;
};
RuleLayout: TSGraphic.LayoutProc = {
rule: REF RuleRec ← NARROW[self.data];
rule.length ← RealDimn[MIN[suggestedX.texPts, rule.length.texPts], pt];
extent ← [zeroDimn, rule.length, rule.thickness, zeroDimn];
};
RulePaint: TSGraphic.PaintProc = {
rule: REF RuleRec ← NARROW[self.data];
handle: TSOutput.Handle ← NARROW[context];
handle.ruleProc[handle, originX, originY, rule.length, rule.thickness];
};
Break: PROC [char: CHAR] RETURNS [IO.CharClass] = {
IF char = ': THEN RETURN [break];
IF char = ' OR char = '  OR char = ', OR char = '; OR char = '\n THEN RETURN [sepr];
RETURN [other];
};
GetName: PROC [stream: IO.STREAM] RETURNS [name: ROPE] ~ {
name ← NIL;
name ← IO.GetTokenRope[stream, Break ! IO.EndOfStream => CONTINUE].token;
};
GetBP: PROC [stream: IO.STREAM] RETURNS [REAL] = {
r: REAL ← stream.GetReal;
unit: ROPE ← stream.GetTokenRope[Break].token;
multipler: REALSELECT TRUE FROM
unit.Equal["in"] => 72.0,
unit.Equal["pc"] => 72.0/72.27/6.0,
unit.Equal["pt"] => 72.0/72.27,
unit.Equal["cm"] => 72.0/2.54,
unit.Equal["mm"] => 72.0/25.4,
unit.Equal["bp"] => 1.0,
ENDCASE => 0.0;
IF multipler = 0.0 THEN ERROR;
RETURN [r*multipler];
};
TSArtwork.Register["Rule", RuleFromBranch];
}.