-- TryPress.mesa
-- Test SirPress, the press file interface

DIRECTORY
	SirPress;

TryPress: PROGRAM IMPORTS SirPress =
BEGIN OPEN SirPress;

tryingALotOfFonts: BOOLEAN =	--	TRUE--FALSE
;
tryingColoredFonts: BOOLEAN =	--	TRUE--FALSE
;
showingText: BOOLEAN =		--	TRUE--FALSE
;
showingDots: BOOLEAN =			TRUE--FALSE
;
showingUnsafeDots: BOOLEAN =	TRUE--FALSE
;
drawingObjects: BOOLEAN =	--	TRUE--FALSE
;
showingColors: BOOLEAN =	--	TRUE--FALSE
;
showingLotsOfDots: BOOLEAN =	--	TRUE--FALSE
;
tryingPipe: BOOLEAN =		--	TRUE--FALSE
;
p: PressHandle ← NewPressHandle["Sample.press"--,landscape,tShirt--];
space,place: LONG INTEGER;
sl: REF bitMap ScanLine ← NEW[ScanLine[bitMap][256]];
osl: REF bitMap ScanLine ← NEW[ScanLine[bitMap][512]];
esl: REF bitMap ScanLine ← NEW[ScanLine[bitMap][512]];
size: ARRAY [0..9) OF INTEGER = [6,7,8,9,10,11,12,14,18]; -- sizes for helvetica, timesroman
rot: ARRAY [0..3) OF INTEGER = [0, 60*90, 60*270]; -- good rotations
inch: INTEGER = 2540; -- number of micas in an inch

IF showingText THEN
	BEGIN
	PutText[p, "Default font",1*inch,8*inch];

	SetFont[p, "TimesRoman", 10];
	PutText[p, "This is Times Roman at 10pt",1*inch,7*inch];
	
	SetFont[p, "Gacha", 8];
	PutText[p, "Here is 8-point Gacha", 2*inch,7*inch];
	
	SetFont[p, "HelVetiCa", 10];
	PutText[p, "Some More Helvetica 10", 2540, 2540*6];
	PutSpace[p];
	PutTextHere[p,"... and some more."];
	FOR i:NAT IN [0..9) DO
	    FOR j:NAT IN [0..3) DO
	        IF tryingALotOfFonts THEN
	            SetFont[p,"Timesroman",size[i],0,rot[j]]
		ELSE SetFont[p,"Timesroman",size[8-i/3],0,rot[0]];
		IF tryingColoredFonts THEN
		    BEGIN
		    SetHue[p,40+80*j];
		    SetSaturation[p,IF i<8 THEN i*32 ELSE 255];
		    END;
		PutText[p,"TimesRm",i*(inch*3/4)+1*inch,(2*j+1)*inch];
		ENDLOOP;
	    ENDLOOP;
	END;
    
IF showingDots THEN
        BEGIN
	WritePage[p];
	SetColor[p,120,255,255];
	PutRectangle[p,6*inch,2*inch,500,5*inch];
	SetColor[p,40,255,255];
	space ← 100; -- 1mm
	WHILE space<=500 DO
		SetSpace[p, space, space-100];
		IF space=500 THEN ResetSpace[p];
		PutText[p, "Space out. . .", 2540, 2540*10-10*space];
		space←space+100;
		ENDLOOP;
	space ← 1000;
	place ← 2540;
	WHILE space>0 DO
		PutRectangle[p, place, place, space, space];
		place←place+space;
		space←space/2;
		ENDLOOP;
	
	SetColor[p,200,255,255];
	BeginScannedRectangle[p, 2540*2, 2540, 256, 256];
	FOR i:NAT IN [0..256) DO
	    FOR j:NAT IN [0..256) DO
	        t:LONG INTEGER ← j*j + i*i;
	        sl[j] ← IF t-(t/72)*72<36 THEN 1 ELSE 0;
		ENDLOOP;
	    ShowLine[p, sl];
	    ENDLOOP;
	EndScannedRectangle[p];
	END;

IF showingUnsafeDots THEN
   BEGIN
   scanline: PACKED ARRAY [0..256) OF [0..1];
	WritePage[p];
	BeginScannedRectangle[p, 2540*2, 2540, 256, 256];
	FOR i: INT IN [0..256) DO
	    FOR j: INT IN [0..256) DO
	        t: INT ← j*j + i*i;
	        scanline[j] ← IF t-(t/72)*72<36 THEN 1 ELSE 0;
		ENDLOOP;
	    UnsafeShowLine[p, @scanline];
	    ENDLOOP;
	EndScannedRectangle[p];
	END;
    
IF drawingObjects THEN
        BEGIN
	WritePage[p];
	SetColor[p, 0,127,255];
	StartOutline[p];
	PutMoveTo[p, 3*inch, 5*inch];
--	PutCubic[p, - 4741.3333, 14224.0, 29464.0, -14224.0, - 19642.6665, 0];
	PutCubic[p:p, x3:- 19642.6665, x2:29464.0, x1:- 4741.3333, y3:0, y2:-14224.0, y1:14224.0];
	PutDrawTo[p, 3*inch, 5*inch];
	EndOutline[p];
	
	SetColor[p, 40,200,100];
	StartOutline[p];
	PutMoveTo[p, 3*inch, 5*inch];
	PutDrawTo[p, 5*inch, 5*inch];
	PutDrawTo[p, 4*inch, 2*inch];
	PutDrawTo[p, 3*inch, 5*inch];
	EndOutline[p];
	END;

IF showingColors THEN
	BEGIN
	top:INTEGER = 10*inch;
	left:INTEGER = 1*inch;
	w:INTEGER = (8-2)*inch/16;
	h:INTEGER = (top-1*inch)/41;
	WritePage[p];
	FOR color:INTEGER IN [0..40] DO
	    FOR sat:INTEGER IN [1..16] DO
	        SetColor[p, color*5, sat*16-1, 255];
		PutRectangle[p, left+sat*w-w, top-color*h, w-64, h-64];
		ENDLOOP;
	    ENDLOOP;
	END;

IF showingLotsOfDots THEN
	BEGIN
	WritePage[p];
	BeginScannedRectangle[p, 1*inch, 1*inch, 32*16, 768];
	FOR j:NAT IN [0..256) DO
	    esl[2*j] ← 0;
	    esl[2*j+1] ← 1;
	    osl[2*j] ← 1;
	    osl[2*j+1] ← 0;
	    ENDLOOP;
	FOR i:NAT IN [0..768/2) DO
	    ShowLine[p,esl];
      	    ShowLine[p,osl];
	    ENDLOOP;
	EndScannedRectangle[p];
	END;
	
ClosePress[p];

END.