home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 10
/
Fresh_Fish_10_2352.bin
/
new
/
dev
/
obero
/
oberon
/
projectoberonsrc
/
textprinter.mod
(
.txt
)
< prev
next >
Wrap
Oberon Text
|
1994-10-17
|
23KB
|
501 lines
Syntax10.Scn.Fnt
Syntax10b.Scn.Fnt
Syntax10i.Scn.Fnt
Syntax12.Scn.Fnt
MODULE TextPrinter; (** CAS/MH/HM 23.9.1993 **)
IMPORT
Files, Display, Fonts, Printer, Texts, TextFrames;
CONST
Unit* = 3048; (**unit for a 300 dpi printer**)
unit = TextFrames.Unit;
mm = TextFrames.mm; Scale = mm DIV 10;
gridAdj = TextFrames.gridAdj;
leftAdj = TextFrames.leftAdj; rightAdj = TextFrames.rightAdj; AdjMask = {leftAdj, rightAdj};
pageBreak = TextFrames.pageBreak;
twoColumns = TextFrames.twoColumns;
AdjustSpan = 30; MinTabWidth = 1 * Scale; StdTabWidth = 4 * mm;
ColumnGap = 7*mm;
TAB = 9X; CR = 0DX;
MaxDict = 32; MaxLine = 512;
TYPE
PrintMsg* = RECORD (Texts.ElemMsg)
prepare*: BOOLEAN;
indent*: LONGINT; (**prepare => width already consumed in line, in units**)
fnt*: Fonts.Font;
col*: SHORTINT;
pos*: LONGINT; (**position in host text**)
X0*, Y0*, pno*: INTEGER (**receiver origin in screen space; page number**)
END;
PrintLine = RECORD
eot: BOOLEAN; (*marked to skip, contains end of text*)
indent: LONGINT;
w, h, dsr: INTEGER; (*bounding box clipped to frame*)
nob: INTEGER; (*number of contained blanks; > 0 if text line wraps around*)
org, len, span: LONGINT; (*len w/o; span w/ trailing CR or white space, if any*)
pbeg: LONGINT (*position of corresponding parc*)
END;
P: TextFrames.Parc;
pbeg: LONGINT;
R: Texts.Reader;
nextCh: CHAR;
fname: ARRAY 32 OF CHAR;
fonts: RECORD
num: SHORTINT;
dict: ARRAY MaxDict OF Fonts.Font;
dx: ARRAY MaxDict, 256 OF SHORTINT
END;
line: RECORD
first: BOOLEAN;
fno: SHORTINT;
px, x, y: INTEGER;
len: INTEGER;
buf: ARRAY MaxLine OF CHAR
END;
PROCEDURE Min (x, y: LONGINT): LONGINT;
BEGIN
IF x < y THEN RETURN x ELSE RETURN y END
END Min;
PROCEDURE Max (x, y: INTEGER): INTEGER;
BEGIN
IF x > y THEN RETURN x ELSE RETURN y END
END Max;
PROCEDURE Append (VAR s1: ARRAY OF CHAR; i: INTEGER; s2: ARRAY OF CHAR);
VAR j: INTEGER;
BEGIN j := 0; (*s1 large enough*)
WHILE s2[j] # 0X DO s1[i] := s2[j]; INC(i); INC(j) END;
s1[i] := 0X
END Append;
(** Printer Metrics **)
PROCEDURE SetMetrics (fno: SHORTINT; fnt: Fonts.Font);
VAR f: Files.File; r: Files.Rider; pat: Display.Pattern;
off, i, j, k, dx, x, y, w, h: INTEGER; size, s: SHORTINT; mod, m: CHAR;
name: ARRAY 32 OF CHAR;
BEGIN COPY(fnt.name, name);
i := 0; WHILE name[i] > "9" DO INC(i) END;
j := i; WHILE ("0" <= name[j]) & (name[j] < "9") DO INC(j) END;
k := j; WHILE (name[k] # ".") & (name[k] # 0X) DO INC(k) END;
IF k > j THEN mod := name[k-1] ELSE mod := " " END;
size := 0; k := i; WHILE i < j DO size := 10 * size + SHORT(ORD(name[i]) - 30H); INC(i) END;
Append(name, k, ".Lm3.Fnt"); f := Files.Old(name);
IF f # NIL THEN Files.Set(r, f, 2); Files.ReadInt(r, off); Files.Set(r, f, 6); i := -1;
REPEAT INC(i); Files.Read(r, s); Files.Read(r, m) UNTIL (s = size) & (m = mod) OR (Files.Pos(r) >= off);
IF (s = size) & (m = mod) THEN Files.Set(r, f, off + i * 260 + 4); Files.ReadBytes(r, fonts.dx[fno], 256)
ELSE f := NIL
END
END;
IF f = NIL THEN i := 0; (*no printer metrics file found - construct from screen metrics*)
WHILE i < 256 DO Display.GetChar(fnt.raster, CHR(i), dx, x, y, w, h, pat);
fonts.dx[fno, i] := SHORT(SHORT(LONG(dx) * unit * 12 DIV 10 DIV Unit)); INC(i)
(*+20% : heuristical correction*)
END
END
END SetMetrics;
PROCEDURE FontNo* (fnt: Fonts.Font): SHORTINT;
VAR fno: SHORTINT;
BEGIN fno := 0; fonts.dict[fonts.num] := fnt;
WHILE fonts.dict[fno] # fnt DO INC(fno) END;
IF fno = fonts.num THEN SetMetrics(fno, fnt); INC(fonts.num) END;
RETURN fno
END FontNo;
PROCEDURE Font* (fno: SHORTINT): Fonts.Font;
BEGIN RETURN fonts.dict[fno]
END Font;
PROCEDURE DX* (fno: SHORTINT; ch: CHAR): LONGINT;
BEGIN RETURN LONG(LONG(fonts.dx[fno, ORD(ch)])) * Unit
END DX;
PROCEDURE Get* (fno: SHORTINT; ch: CHAR; VAR dx, x, y, w, h: LONGINT);
VAR pat: Display.Pattern; dx0, x0, y0, w0, h0: INTEGER;
BEGIN Display.GetChar(fonts.dict[fno].raster, ch, dx0, x0, y0, w0, h0, pat);
x := LONG(x0) * unit; y := LONG(y0) * unit; h := LONG(h0) * unit;
dx := LONG(LONG(fonts.dx[fno, ORD(ch)])) * Unit; w := dx
END Get;
PROCEDURE GetChar* (fno: SHORTINT; targetUnit: LONGINT; ch: CHAR;
VAR pdx: LONGINT; VAR dx, x, y, w, h: INTEGER; VAR pat: Display.Pattern);
BEGIN Display.GetChar(fonts.dict[fno].raster, ch, dx, x, y, w, h, pat);
x := SHORT(x * LONG(unit) DIV targetUnit); y := SHORT(y * LONG(unit) DIV targetUnit);
h := SHORT(h * LONG(unit) DIV targetUnit);
pdx := LONG(LONG(fonts.dx[fno, ORD(ch)])) * Unit;
dx := SHORT(pdx DIV targetUnit); w := dx
END GetChar;
PROCEDURE InitFonts*;
VAR fno: SHORTINT;
BEGIN fonts.num := 0; fno := FontNo(Fonts.Default)
END InitFonts;
PROCEDURE Width (fno: SHORTINT; VAR s: ARRAY OF CHAR): INTEGER;
VAR i, w: INTEGER;
BEGIN i := 0; w := 0;
WHILE s[i] # 0X DO INC(w, LONG(fonts.dx[fno, ORD(s[i])]) ); INC(i) END;
RETURN w
END Width;
PROCEDURE GetPrintChar (fnt: Fonts.Font; ch: CHAR; VAR fno: SHORTINT; VAR dx, x, y, w, h: INTEGER);
VAR pat: Display.Pattern;
BEGIN Display.GetChar(fnt.raster, ch, dx, x, y, w, h, pat);
x := SHORT(x * LONG(unit) DIV Unit); y := -SHORT((-y) * LONG(unit) DIV Unit);
h := SHORT(h * LONG(unit) DIV Unit);
fno := FontNo(fnt); dx := fonts.dx[fno, ORD(ch)]; w := dx
END GetPrintChar;
PROCEDURE Tab (dw: INTEGER; VAR dx: INTEGER); (*P set*)
VAR i, n: INTEGER; w: LONGINT;
BEGIN i := 0; n := P.nofTabs; w := LONG(dw) * Unit + MinTabWidth;
IF dw < 0 THEN dx := -dw
ELSE
WHILE (i < n) & (P.tab[i] < w) DO INC(i) END;
IF i < n THEN dx := SHORT((P.tab[i] - LONG(dw) * Unit) DIV Unit)
ELSE dx := StdTabWidth DIV Unit
END
END
END Tab;
PROCEDURE Offset (): INTEGER; (*R set*)
BEGIN
IF R.voff = 0 THEN RETURN 0
ELSE RETURN SHORT(R.fnt.height * R.voff * LONG(unit) DIV 64 DIV Unit)
END
END Offset;
PROCEDURE MeasureSpecial (pno, dw: INTEGER; VAR fno: SHORTINT; VAR dx, x, y, w, h: INTEGER);
(*P, R, nextCh set*)
VAR e: Texts.Elem; i: INTEGER; msg: PrintMsg;
BEGIN
IF nextCh = " " THEN GetPrintChar(R.fnt, nextCh, fno, dx, x, y, w, h);
x := 0; y := 0; w := dx; h := 0
ELSIF nextCh = TAB THEN Tab(dw, dx); x := 0; y := 0; w := dx; h := 0
ELSIF R.elem # NIL THEN e := R.elem;
msg.prepare := TRUE; msg.indent := LONG(dw) * Unit;
msg.fnt := R.fnt; msg.col := R.col; msg.pos := Texts.Pos(R) - 1; msg.pno := pno;
msg.Y0 := -SHORT(P.dsr DIV Unit);
e.handle(e, msg);
w := SHORT(e.W DIV Unit); dx := w; h := SHORT(e.H DIV Unit);
x := 0; y := msg.Y0
ELSE GetPrintChar(R.fnt, nextCh, fno, dx, x, y, w, h)
END
END MeasureSpecial;
PROCEDURE GetSpecial (VAR n: INTEGER; maxW, cn, ddx, dw: INTEGER;
VAR fno: SHORTINT; VAR dx, x, y, w, h: INTEGER); (*P, R, nextCh set*)
VAR e: Texts.Elem;
BEGIN
IF nextCh = " " THEN GetPrintChar(R.fnt, nextCh, fno, dx, x, y, w, h);
x := 0; y := 0; INC(dx, ddx); INC(n); IF n <= cn THEN INC(dx) END; (*space correction for block adjustment*)
w := dx; h := 0
ELSIF nextCh = TAB THEN Tab(dw, dx); x := 0; y := 0; w := dx; h := 0
ELSIF R.elem # NIL THEN e := R.elem;
IF e IS TextFrames.Parc THEN w := SHORT(Min(P.width DIV Unit, maxW)); e.W := LONG(w) * Unit
ELSE w := SHORT(e.W DIV Unit)
END;
dx := w; x := 0; y := -SHORT(P.dsr DIV Unit); h := SHORT(e.H DIV Unit)
ELSE GetPrintChar(R.fnt, nextCh, fno, dx, x, y, w, h)
END
END GetSpecial;
PROCEDURE AdjustMetrics (T: Texts.Text; VAR t: PrintLine; left: INTEGER; VAR pw, tw, ddx, cn: INTEGER);
(*sets P, pbeg*)
BEGIN pw := left; tw := t.w; ddx := 0; cn := 0;
TextFrames.ParcBefore(T, t.org, P, pbeg);
IF pbeg # t.org THEN
INC(pw, SHORT((P.left + t.indent) DIV Unit));
DEC(tw, SHORT(t.indent DIV Unit));
IF leftAdj IN P.opts THEN
IF (rightAdj IN P.opts) & (t.nob > 0) THEN
tw := SHORT((P.width - t.indent) DIV Unit); ddx := (tw - t.w) DIV t.nob; cn := (tw - t.w) MOD t.nob
END
ELSIF rightAdj IN P.opts THEN INC(pw, SHORT(P.width DIV Unit) - t.w)
ELSE (*center*) INC(pw, (SHORT(P.width DIV Unit) - t.w) DIV 2)
END
END
END AdjustMetrics;
(* Printer Line Casting *)
PROCEDURE MeasureLine (T: Texts.Text