TSTranslatePrivateImpl.mesa
Michael Plass, December 13, 1983 4:39 pm
Last Edited by: Beach, April 3, 1984 6:05:34 pm PST
DIRECTORY
JaMBasic, JaMOps, LooksReader, NameSymbolTable, NodeStyle, NodeStyleExtra, Real, Rope, RopeReader, TextEdit, TextLooks, TextNode, TSTranslatePrivate, TSFont, TSGlue, TSObject, TSOps, TSTypes;
TSTranslatePrivateImpl:
PROGRAM
IMPORTS JaMOps, LooksReader, NameSymbolTable, NodeStyle, NodeStyleExtra, Real, Rope, RopeReader, TextEdit, TextNode, TSFont, TSObject, TSOps, TSTypes
EXPORTS TSTranslatePrivate =
BEGIN OPEN TSTypes, TSTranslatePrivate;
NewState:
PUBLIC
PROCEDURE
RETURNS [s:State] =
BEGIN
s ← NEW[StateRec];
s.nodeStyle ← NodeStyle.Create[];
s.charStyle ← NodeStyle.Create[];
s.ropeReader ← RopeReader.Create[];
s.looksReader ← LooksReader.Create[];
END;
noUnderline: TSObject.Parameter ← NEW[TSObject.ParameterRec ← [underlineThickness, zeroDimn]];
noStrikeout: TSObject.Parameter ← NEW[TSObject.ParameterRec ← [strikeoutThickness, zeroDimn]];
fill: LIST OF REF ANY = LIST[noUnderline, noStrikeout, TSObject.fillGlue];
InitializeStateForNewNode:
PUBLIC
PROCEDURE [listWriter: TSObject.ListWriter, state: State] = {
OPEN state^;
LastLineFormatting: TYPE = {Default, FlushLeft, FlushRight, Centered, Justified};
GetLastLineFormatting:
PROCEDURE []
RETURNS [LastLineFormatting] = {
ObjectToName:
PROCEDURE [obj: JaMBasic.Object]
RETURNS [name: NameSymbolTable.Name] = {
WITH x:obj
SELECT
FROM
name => RETURN [LOOPHOLE[x.id]];
string => {
nameObj: name JaMBasic.Object ← JaMOps.StringToName[x];
RETURN[LOOPHOLE[nameObj.id]];
};
ENDCASE => ERROR;
};
lastLineFormatting: NameSymbolTable.Name = NameSymbolTable.MakeName["lastLineFormatting"];
default: NameSymbolTable.Name = NameSymbolTable.MakeName["default"];
flushLeft: NameSymbolTable.Name = NameSymbolTable.MakeName["flushLeft"];
flushRight: NameSymbolTable.Name = NameSymbolTable.MakeName["flushRight"];
centered: NameSymbolTable.Name = NameSymbolTable.MakeName["centered"];
justified: NameSymbolTable.Name = NameSymbolTable.MakeName["justified"];
name: NameSymbolTable.Name ← ObjectToName[NodeStyleExtra.GetStyleParam[nodeStyle, lastLineFormatting, NodeStyle.GetStyleName[nodeStyle], print]];
RETURN[
SELECT name
FROM
default => Default,
flushLeft => FlushLeft,
flushRight => FlushRight,
centered => Centered,
justified => Justified,
ENDCASE => ERROR];
};
leftFill, rightFill: LIST OF REF ANY;
firstBaselineSpacing: Dimn;
currentTextNode ← TextNode.NarrowToTextNode[currentNode];
rope ← TextEdit.GetRope[currentTextNode];
runs ← TextEdit.GetRuns[currentTextNode];
oldLooks ← TextLooks.allLooks; -- to force apply on first char
remainingLength ← Rope.Size[rope];
tabStops ← 8.0;
minTabWidth ← 1.0;
bodyIndent ← zeroDimn;
nodeStyle.ApplyAll[currentNode, print];
RopeReader.SetPosition[ropeReader, rope, 0];
LooksReader.SetPosition[looksReader, runs, 0];
exceptionalskip ← RealDimn[nodeStyle.GetTopLeading[], pt];
curbaselineskip ← MaxDimn[curbaselineskip, exceptionalskip];
The following line exhibits a compiler bug: temporaries are reused when they should not be.
leftIndent ← Pt[nodeStyle.GetLeftIndent[]+nodeStyle.GetRestIndent[]];
The following sop circumvents the problem.
leftIndent ← Pt[nodeStyle.GetLeftIndent[]+nodeStyle.GetBodyIndent[]];
galleyWidth ← Pt[nodeStyle.GetLineLength[]].SubDimn[Pt[nodeStyle.GetRightIndent[]]];
firstBaselineSpacing ←
bottomLeading.MaxDimn[Pt[nodeStyle.GetTopLeading[]]];
bottomLeading ← Pt[nodeStyle.GetBottomLeading[]];
SELECT nodeStyle.GetLineFormatting[]
FROM
FlushLeft => {
leftFill ← LIST[noUnderline, noStrikeout, TSObject.MakeGlue[space: leftIndent]];
rightFill ← fill;
endFill ← fill;
};
FlushRight => {
leftFill ← LIST[noUnderline, noStrikeout, TSObject.MakeGlue[space: leftIndent, plus: TSGlue.fill]];
rightFill ← NIL;
endFill ← NIL;
};
Justified => {
leftFill ← LIST[noUnderline, noStrikeout, TSObject.MakeGlue[space: leftIndent]];
rightFill ← NIL;
endFill ← fill;
};
Centered => {
leftFill ← LIST[noUnderline, noStrikeout, TSObject.MakeGlue[space: leftIndent, plus: TSGlue.fill]];
rightFill ← fill;
endFill ← fill;
};
ENDCASE;
SELECT GetLastLineFormatting[]
FROM
Default => NULL;
FlushLeft => endFill ← fill;
FlushRight => endFill ← NIL;
Justified => endFill ← NIL;
Centered => endFill ← fill;
ENDCASE;
listWriter.ProduceParameter[minbaseline, Pt[nodeStyle.GetLeading[]]];
listWriter.ProduceParameter[mingaps, Pt[0]];
listWriter.ProduceItem[
NEW[TSObject.ListParameterRec ← [
lineskip,
LIST[
TSObject.MakeGlue[
Pt[0],
Pt[nodeStyle.GetLeadingStretch[]],
Pt[nodeStyle.GetLeadingShrink[]]
]
]
]]];
listWriter.ProduceItem[TSObject.MakeGlue[
space: firstBaselineSpacing.SubDimn[Pt[nodeStyle.GetLeading[]]],
plus: Pt[nodeStyle.GetTopLeadingStretch[]],
minus: Pt[nodeStyle.GetTopLeadingShrink[]]
]];
leftFillParameter ←
IF leftFill =
NIL
THEN
NIL
ELSE
NEW[TSObject.ListParameterRec ← [leftfill, leftFill]];
rightFillParameter ←
IF rightFill =
NIL
THEN
NIL
ELSE
NEW[TSObject.ListParameterRec ← [rightfill, rightFill]];
{firstIndent: Dimn ← Pt[nodeStyle.GetFirstIndent[]-nodeStyle.GetRestIndent[]];
firstIndentItem ←
IF firstIndent = zeroDimn
THEN
NIL
ELSE TSObject.MakeGlue[firstIndent];
};
};
FontFromStyle:
PUBLIC
PROCEDURE [style: NodeStyle.Ref]
RETURNS [TSFont.Ref] =
BEGIN
face: NodeStyle.FontFace = style.GetFontFace[];
fontName: Rope.ROPE ← NameSymbolTable.RopeFromName[style.GetFontFamily[]];
IF face = Bold OR face = BoldItalic THEN fontName ← Rope.Cat[fontName, "B"];
IF face = Italic OR face = BoldItalic THEN fontName ← Rope.Cat[fontName, "I"];
RETURN [TSFont.Lookup[Rope.Flatten[fontName], Pt[style.GetFontSize[]], Real.RoundI[style.GetTextRotation[]]]]
END;
GetNewLooks:
PUBLIC
PROCEDURE [listWriter: TSObject.ListWriter, state: State, looks: TextLooks.Looks] = {
OPEN state^;
family: NodeStyle.Name;
NodeStyle.Copy[charStyle, nodeStyle];
charStyle.ApplyLooks[looks, print];
family ← charStyle.GetFontFamily[];
curfont ← FontFromStyle[charStyle];
tabStops ← charStyle.GetTabStops[];
IF tabStops=0 THEN tabStops ← 1;
bodyIndent ← Pt[charStyle.GetBodyIndent[]];
listWriter.ProduceParameter[shift, Pt[charStyle.GetVShift[]]];
listWriter.ProduceParameter[hue, [charStyle.GetTextHue[]]];
listWriter.ProduceParameter[saturation, [charStyle.GetTextSaturation[]]];
listWriter.ProduceParameter[brightness, [charStyle.GetTextBrightness[]]];
underlining ← charStyle.GetUnderlining[];
strikeout ← charStyle.GetStrikeout[];
oldLooks ← looks
};
ProduceBottomLeadingStretchAndShrink:
PUBLIC
PROCEDURE [
listWriter: TSObject.ListWriter,
state: State
] = {
listWriter.ProduceItem[TSObject.MakeGlue[
plus: Pt[state.nodeStyle.GetBottomLeadingStretch[]],
minus: Pt[state.nodeStyle.GetBottomLeadingShrink[]]
]];
};
Tabify:
PUBLIC
PROCEDURE [
hlist: TSObject.ItemList,
state: State
] RETURNS [newHList: TSObject.ItemList] = {
OPEN state^;
tempLineReader: TSObject.ListReader ← hlist.CreateReader[];
lineSoFar: TSObject.Box ← TSOps.Package[
tempLineReader,
right,
[zeroDimn,nilDimn,nilDimn,nilDimn]].box;
distFromIndent: Dimn ← lineSoFar.extent[right].SubDimn[leftIndent];
widthSoFar: Dimn ← distFromIndent.AddDimn[
RealDimn[minTabWidth, [MAX[0.05, curfont.SpaceGlue[].space]]]
];
r: REAL ← widthSoFar.DimnRatio[Pt[MAX[tabStops, 0.1]]];
w: Dimn ← IntDimn[Real.RoundLI[r+0.5], Pt[MAX[tabStops, 0.1]]];
underThickness: Dimn ← tempLineReader.parameter[underlineThickness];
underBottom: Dimn ← tempLineReader.parameter[underlineBottom];
strikeThickness: Dimn ← tempLineReader.parameter[strikeoutThickness];
strikeBottom: Dimn ← tempLineReader.parameter[strikeoutBottom];
tempLineReader.DestroyReader[];
newHList ← TSObject.CreateItemList[producer: NIL];
newHList.listWriter.ProduceItem[lineSoFar];
newHList.listWriter.ProduceParameter[underlineThickness, underThickness];
newHList.listWriter.ProduceParameter[underlineBottom, underBottom];
newHList.listWriter.ProduceParameter[strikeoutThickness, strikeThickness];
newHList.listWriter.ProduceParameter[strikeoutBottom, strikeBottom];
newHList.listWriter.ProduceItem[TSObject.MakeGlue[space: w.SubDimn[distFromIndent]]];
IF leftFillParameter # NIL THEN newHList.listWriter.ProduceItem[leftFillParameter];
IF rightFillParameter # NIL THEN newHList.listWriter.ProduceItem[rightFillParameter];
oldLooks ← TextLooks.allLooks;
};
END.
Michael Plass, June 28, 1982 9:00 am. Renamed from TPTranslatePrivateImpl.
Michael Plass, July 15, 1982 11:03 am. Restored left & rightFillParameters after tabs.
Michael Plass, September 7, 1982 1:39 pm. Replaced RealDimn[ ,pt] with Pt[ ].
Michael Plass, November 12, 1982 1:43 pm. Eliminated underline and strikeout on right fill glue.
Michael Plass, November 16, 1982 9:56 am. GetLineLength.
Michael Plass, February 15, 1983 1:14 pm. Eliminated divide checks due to zero width spaces.
Michael Plass, May 2, 1983 9:40 am. Tried again to eliminate divide checks due to zero width spaces.
Michael Plass, November 15, 1983 1:58 pm. RealOps => Real (Cedar 5).