home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / POSTOGRF.ZIP / COPYBLOC.INC < prev    next >
Encoding:
Text File  |  1990-06-04  |  33.5 KB  |  918 lines

  1. { program CopyBlock.inc
  2.   written by Thomas B. Passin in Turbo Pascal 4.0.
  3.    For use in POSTogrf/LIPSogrf.  Shows, resizes, and moves an open
  4.    rectangle.  This represents the allowed size of the graph when printed
  5.    (e.g., 8 X 6.25 in for a MITRE report).  When the box is located in
  6.    the upper left corner of the screen, the box represents the copybox
  7.    as located at the printer margin.  If the box is moved away from the
  8.    corner, it shows whether the graph can be cropped to fit inside the box.
  9.  
  10.   22 May 90 Other sections of code have also been moved here:
  11.          procedures Repaint1, MoveLabel, Attributes.
  12.  
  13.  27 Apr 89 Now XOR's the box when moving.
  14.  18 Oct 88 v1.0x4.  Added var noshow to toggle rectangle on or off:
  15.          modified CopyBlock, CopyBlockMenu.
  16.  20 Sept 88. v1.0x3.  Surounded each readln by textcolor(white),
  17.          textcolor(black) pairs.  Needed to overcome BGI bug.
  18.          Changed type colors to word to avoid collision with
  19.          CRT unit.
  20.  14 Sept 88.  v1.0x2.  Added HOME key to MoveCopyBlock: takes box to upper
  21.          left corner. Added HOME to set of Movers in CopyBlockMenu.
  22.  13 Sept 88.  v1.0x1.  Works.
  23.  }
  24.  
  25. (*{$DEFINE test}*)
  26. {$IFDEF test}
  27. uses graph, CRT;
  28. type videocolors = (color, mono);
  29.      {mcolors = (yellow, white, black);}
  30.      colors = word;
  31.      string80 = string[80];
  32. const  ESC = #27;  BS  = #8; CR = #13;  LF = #10;
  33.        Uparrow  = #72;     Downarrow  = #80;
  34.        Leftarrow  = #75;   Rightarrow  = #77;
  35.        Del  = #83;         Ins  = #82;
  36.        Home  = #71;        En  = #79;
  37.        PF1 = #59;   PF2 = #60;   PF3 = #61;   PF4 = #62;   PF5 = #63;
  38.        PF6 = #64;   PF7 = #65;   PF8 = #66;   PF9 = #67;   PF10 = #68;
  39. var VidCol :videocolors;
  40.     key :char;
  41. procedure ScrConv(x,y:integer); begin end;  { dummy procedures for debugging }
  42. procedure SetColor(cc:colors); begin end;
  43. procedure repaint; begin end;
  44. {$ENDIF}
  45.  
  46. { ---------------------------------------------------------------------
  47.                      Part of the RePaint procedure
  48.   --------------------------------------------------------------------- }
  49. Procedure RePaint1;
  50. var savePrtSize: integer;
  51.     t1: integer;
  52. begin
  53.      here := JimFileStart;
  54.      SavePrtSize := TempText.PrtSize;
  55.      SetColor(white);
  56.      t1:= 10; SetPrtFontSize(t1);
  57.      SetTextStyle(SansSerifFont,Horizdir,UserCHarSize);
  58.      done := false;
  59.      if count > 0 then Repeat DrawJimFile until done ;
  60.      if VidCol = color then SetColor(yellow) else SetColor(white);
  61.      Line(0,GetMaxY - 3*LinesPerChar,GetMaxX,GetMaxY-3*LinesPerChar);
  62.      if head = nil then exit;
  63.      cp := head;
  64.      repeat
  65.            showLabel(cp, white);
  66.            cp := cp^.link;
  67.      until cp = nil;
  68.      if select <> nil then HighLight(select);
  69.      if LConfig.DoBar then DoVGBar;
  70.      RestorePrtFontSize(SavePrtSize);
  71.      TempText := select^;
  72.      SetUpLabel(select);
  73. end;
  74.  
  75. { ------------------------------------------------------------------------
  76.                  Size the copyblock to fit the graph
  77.   ------------------------------------------------------------------------ }
  78. procedure AutoSizeCopyBlock;
  79. var maxMinRect: rect;        {accumulate max, min corners}
  80.     x1, x2, y1, y2: integer;
  81.     cpx, cpy      : integer; {current point in Postscript coords}
  82.  
  83.     procedure DoRectMaxMin(x,y: integer; var r: rect);
  84.     begin
  85.        with r do begin
  86.            if x < LLx then LLx := x else
  87.               if x > URx then URx := x;
  88.            if y < LLy then LLy := y else
  89.               if y > URy then URy := y;
  90.         end;
  91.     end;
  92.  
  93.     procedure SizeJimFile;
  94.     var XPos, Ypos, error, temp  : integer;
  95.         PenDia                   : word;
  96.         n1                       : word;
  97.         str                      : string80;
  98.         sFlag                    : boolean;
  99.     begin
  100.         GetAWord(str);
  101.         case GraphFile of
  102.             GRAPHL, LIPSGRF: begin
  103.                (*if str = 'EXIT' then begin done := true; exit ; end ELSE
  104.                if str = 'MAP' then   { move to position }
  105.                   begin GetAWord(str); Val(str,Xpos,error);
  106.                   GetAWord(str); Val(str,Ypos,error);
  107.                   ScrConv(XPos, YPos);
  108.                   MoveTo(Xpos,YPos);
  109.                 end ELSE
  110.                   if str = 'DAP' then   { draw to position }
  111.                   begin GetAWord(str); Val(str,Xpos,error);
  112.                   GetAWord(str); Val(str,Ypos,error);
  113.                   ScrConv(XPos,YPos);
  114.                   LineTo(Xpos,YPos);
  115.                end ELSE
  116.                   if str = 'SPD' then  {set pen diameter - only an approximation }
  117.                   begin GetAWord(str); Val(str,PenDia, error);
  118.                   PenDia := word(round(10 * PenDia/VPrtScale)) div 3;
  119.                   SetLineStyle(0,0,PenDia);
  120.                end ELSE
  121.                   if str = 'FONT' then {he asks for internal landscape font - fake it }
  122.                     begin GetAWord(str);
  123.                        if str = '3' then  begin
  124.                           temp:= 12; SetPrtFontSize(temp);
  125.                         end; {else;}
  126.                end ELSE
  127.                   if str = 'TEXT' then begin {write the following text string }
  128.                      GetAQuote(str); OutText(str);
  129.                   end ELSE {nothing} *)
  130.              end; {case GRAPHL, LIPSGRF}
  131.             POSTSCRIPT: begin
  132.            temp := 13; SetPrtFontSize(temp);
  133.            if str[1] = 's' then sFlag := true else sFlag := false;
  134.                if str[1] = '%' then
  135.            repeat
  136.                   inc(here)
  137.                 until (JimFile^[here] = CR) or (JimFile^[here] = LF);
  138.                if str[1] = '(' then begin       {found a label}
  139.                   ParsePSstring(str,mark);
  140.                   x1 := textwidth(str);
  141.                   y1 := textheight(str);
  142.                   x1 := round(x1/Hscale);
  143.                   y1 := round(y1/VScale);
  144.                   doRectMaxMin(cpx - 50, cpy, maxMinRect);
  145.                   doRectmaxMin(cpx + x1 ,cpy +50 + y1 + y1 div 2, maxMinRect);
  146.                   here := mark;
  147.                 end ELSE
  148.                 if (str[1] = 'm') then begin
  149.                   if ((str = 'm') or (str = 'moveto')) then begin
  150.                     n1 := here - 1;
  151.                     GetAWordBack(str,n1); GetAWordBack(str, n1);
  152.                     Val(str, YPos, error);
  153.                     if error <> 0 then exit;
  154.                     GetAWordBack(str,n1);
  155.                     Val(str,XPos,error);
  156.                     if error <> 0 then exit;
  157.                     cpx := Xpos; cpy := Ypos;
  158.                     doRectMaxMin(cpx, cpy, maxMinRect);
  159.                    end;
  160.                 end ELSE
  161.                 if (str[1] = 'l') then begin
  162.                    if ((str = 'l') or (str = 'lineto')) then begin
  163.                       n1 := here - 1;
  164.                       GetAWordBack(str,n1); GetAWordBack(str, n1);
  165.                       Val(str, YPos, error);
  166.                       GetAWordBack(str,n1);
  167.                       Val(str,XPos,error);
  168.                       cpx := Xpos; cpy := Ypos;
  169.                       doRectMaxMin(cpx, cpy, maxMinRect);
  170.                     end;
  171.                 end ELSE if
  172.                    (sflag) and (str = 'setlinewidth') then begin
  173.                    {n1 := here -1; GetAWordBack(str,n1); GetAWordBack(str, n1);
  174.                    Val(str,PenDia,error);
  175.                    if error = 0 then
  176.                       PenDia := word(round(PenDia)) div 10;
  177.                       else PenDia := 1;
  178.                    SetLineStyle(0,0,PenDia);}
  179.                 end ELSE if (sFlag) and (str = 'sf') then begin
  180.                       {set active font size}
  181.                       {any labels here are default 13 pt labels}
  182.                    temp := 13; SetPrtFontSize(temp);
  183.                 end ELSE if (sFlag) and (str = 'setfont') then begin
  184.                    {temp := 13; SetPrtFontSize(temp);}
  185.                 end ELSE if (sFlag) and (str = 'showpage') then begin
  186.                    done := true; exit ;
  187.             end; {if..ELSE}
  188.          end; {POSTSCRIPT}
  189.       end; {case}
  190.     end; {SizeJimFile}
  191.  
  192.     procedure SizeLabels;
  193.     var x1, y1, cpx, cpy: integer;
  194.     begin
  195.        if head = nil then exit;
  196.        cp := head;
  197.        repeat
  198.            SetUpLabel(cp);
  199.            x1 := textwidth(cp^.tstr);
  200.            y1 := textheight(cp^.tstr);
  201.            with cp^.Currtext do begin
  202.              cpx := Horiz ;
  203.              cpy := Vert;
  204.             end;
  205.           cpx := round(cpx / HScale) - 1000;
  206.           cpy := 6360 - round(cpy / VScale);
  207.            x1 := round(x1/Hscale);
  208.            y1 := round(y1/VScale);
  209.           if cp^.Currtext.Direction = Horizdir then begin
  210.               doRectMaxMin(cpx - 50, cpy, maxMinRect);
  211.               doRectmaxMin(cpx + x1 ,cpy +50 + y1 + y1 div 2, maxMinRect);
  212.            end else begin
  213.               doRectMaxMin(cpx, cpy, maxMinRect);
  214.               doRectmaxMin(cpx + y1 +25, cpy + 50 + x1 + y1 div 2, maxMinRect);
  215.            end;
  216.           cp := cp^.link;
  217.         until cp = nil;
  218.         TempText := select^;
  219.         SetUpLabel(select);
  220.     end; {SizeLabels}
  221.  
  222. begin
  223.    with maxMinRect do begin
  224.       LLx := 32000; LLy := 32000; URx := -32000; URy := -32000;
  225.       cpx := 0; cpy := 0;
  226.       if GRAPHLIName <> '' then begin
  227.           here := JimFileStart;
  228.           if count > 0 then Repeat
  229.               SizeJimFile;
  230.               if here > EndGraph then done := true;
  231.            until done ;
  232.        end;
  233.       SizeLabels;
  234.       w := URx - LLx; h := URy - LLy;
  235.       if (w <> 0) and (h <> 0) then CopyBlock := maxMinRect;
  236.     end;
  237. end; {AutoSizeCopyBlock}
  238.  
  239. { ------------------------------------------------------------------------
  240.      Draw the box on screen.  CopyBlkOffsetX, Y are the upper left
  241.      coordinates.  CopyBlkX,Y are the width, height of the box (scaled
  242.      by a factor 1/3 for historical reasons based on the original LIPS
  243.      conversion factors).
  244.   ------------------------------------------------------------------------ }
  245.  
  246. procedure markCBCorner;
  247. var x1, x2, y1, y2: integer;
  248. begin
  249. {    if CBMode = size then}
  250.       with CopyBLock do begin
  251.                  setlinestyle(solidln, 0, thickwidth);
  252.                  x1 := LLx; y1 := LLy;
  253.                  x2 := x1 + 1000; y2 := y1 + 1000;
  254.                  PStoScreen(x1, y1);
  255.                  PStoScreen(x2, y2);
  256.                  line(x1, y1, x1, y2);
  257.                  line(x1, y1, x2, y1);
  258.                  setlinestyle(solidln, 0, normwidth);
  259.        end;
  260. end;
  261.  
  262. Procedure ShowCopyBlock;
  263. var CopyBlockX, CopyBlockY: real;
  264.     x1, x2, y1, y2 : integer;
  265.     TRect: screenRect;
  266. begin if noshow then exit;
  267.      with TRect do begin
  268.          with CopyBlock do begin
  269.               ULx := LLx; ULy := LLy + h;
  270.               LRx := URx; LRy := URy - h;
  271.          PStoScreen(ULx, ULy); PStoScreen(LRx, LRy);
  272.          sw := LRx - ULx; sh := ULy - LRy;
  273.          Rectangle(ULx, ULy, LRx, LRy);
  274.       end; {with copyblock}
  275.      end; {with tRect}
  276. end;
  277.  
  278. procedure MoveCopyBlock;
  279. var moving, newbox : boolean;
  280.     delX, delY: integer;
  281.     x1, x2, y1, y2: integer;
  282. begin   moving := false; newbox := false;
  283.         {SetWriteMode(XorPut);}
  284.         delX := integer(round(1/(Expand.SF*Hscale)));
  285.         delY := integer(round(1/(Expand.SF*Vscale)));
  286.    repeat
  287.         ShowCopyBlock;
  288.         if CBMode = size then markCBCorner;
  289.         with CopyBlock do begin
  290.              case key of
  291.                   rightarrow : LLx := LLx + delX;
  292.                   leftarrow  : LLx := LLx - delX;
  293.                   uparrow    : LLy := LLy + delY;
  294.                   downarrow  : LLy := LLy - delY;
  295.   (* CNTRL -> *) #116        : LLx := LLx + 10*delX;
  296.   (* CNTRL <- *) #115        : LLx := LLx - 10*delX;
  297.   (* page up  *) #73         : LLy := LLy + 10*delY;
  298.   (* page down *) #81        : LLy := LLy - 10*delY;
  299.                  {Home        : begin
  300.                                  LLx := 0; LLy := 0;
  301.                                end;}
  302.               end; {case}
  303.              if CBMode = move then begin
  304.                URx := LLx + w; URy := LLy + h;
  305.               end else begin
  306.                  w := URx - LLx; h := URy - LLy;
  307.               end;
  308.         end; {with CopyBlock do...}
  309.      ShowCopyBlock;
  310.      if CBMode = size then markCBCorner;
  311.      if keypressed
  312.      then begin repeat key := readkey; until (not keypressed) ;
  313.                 moving := true;
  314.           end
  315.      else begin delay(50);
  316.                 if keypressed
  317.                 then begin key := readkey; moving := true; end
  318.                 else moving := false;
  319.           end;
  320.  until not moving ;
  321.  onoff := on;
  322. end;
  323.  
  324. Procedure GetCopyBlock;
  325. const menustr1 =
  326. 'resize copyblock...  F1 move copyblock   F3 autosize   <ESC> quit';
  327.       menustr2 =
  328. 'move copyblock...... F1 size copyblock   <ESC> quit';
  329. var tx,ty:real;
  330.     err1, n: integer;
  331.     x1, x2, y1, y2: integer;
  332.     err2, onlyOne, done:boolean;
  333.     str1, str2: string;
  334.     default: string80;
  335.     gkey: char;
  336. begin
  337.    if onoff = on then done := false else done := true;
  338.    with CopyBlock do begin
  339.    tx := w/1000; ty := h/1000;
  340.    clrscr; write(menustr1);
  341.    setwritemode(XORput);
  342.    markCBCorner;
  343.     repeat
  344.      if CBMode = size then begin
  345.          gotoxy(1, 2);
  346.          write('key X,Y dimensions of copyblock (now: ', w/1000:4:2,
  347.            h/1000:5:2, ' inches): ');
  348.        end;
  349.       str1 := ''; str2 := ''; onlyOne := false;
  350.     (*textcolor(white);
  351.     {$I-} readln(tx,ty); {$I+}
  352.       textcolor(black);*)
  353.       if key <> ESC then key := readkey;
  354.       case key of
  355.        '0'..'9', '.': begin
  356.              write(key);
  357.              str1 := str1 + key;
  358.              repeat
  359.                 key := readkey;
  360.                 case key of
  361.                    '0'..'9', '.', SP: begin
  362.                         write(key);
  363.                         str1 := str1 + key;
  364.                       end;
  365.                     BS: if length(str1) > 0 then begin
  366.                          gotoxy(wherex - 1, wherey); write(' ');
  367.                          gotoxy(wherex-1, wherey);
  368.                          delete(str1, length(str1), 1);
  369.                       end;
  370.                     ESC: str1 := '';
  371.                     #0: key := readkey;   {dump function keys}
  372.                   end; {case}
  373.              until (key = CR) or (key = ESC);
  374.              if str1 = '' then key := ESC else begin
  375.                 n := pos(' ', str1);
  376.                 str2 := copy(str1, n+1, length(str1) - n + 1);
  377.                 if pos(' ', str2) <> 0 then delete(str2, pos(' ', str2), 1);
  378.                 if (n > 0) and (n < length(str1)) then begin
  379.                    str1 := copy(str1, 1, n);
  380.                    if pos(' ', str1) <> 0 then delete(str1, pos(' ', str1), 1);
  381.                    onlyOne := false;
  382.                  end else onlyOne := true;
  383.                 val(str1, tx, err1);
  384.                 if (err1 = 0) and (not onlyOne) then val(str2,ty,err1);
  385.                 err2 := (err1 <> 0) or (tx > 11) or (tx < 0.5) or (ty > 8.5)
  386.                     or (ty < 0.5);
  387.                 if err2 then begin
  388.            sound(300); delay(50); nosound;
  389.            GoToXY(1, whereY-1); clrEOL;
  390.            writeln('bad number - try again');delay(1000);
  391.                    tx := w/1000; ty := h/1000;
  392.                 end else begin
  393.                   ShowCopyBlock;
  394.                   markCBCorner;
  395.                   w := integer(round(1000*tx)); h := integer(round(1000*ty));
  396.                   done := true;
  397.                   URx := LLx + w; URy := LLy + h;
  398.                   if vidcol = color then setcolor(yellow) else setcolor(white);
  399.                   ShowCopyBlock;
  400.                   markCBCorner;
  401.                end; {if str1  ''}
  402.               end; {case numbers of}
  403.           end;
  404.        ESC: done := true;
  405.         #0: begin
  406.               key := readkey;
  407.               case key of
  408.                PF1: begin
  409.                     clrscr;
  410.                     if CBmode = size then begin
  411.                        write(menustr2);
  412.                        CBMode := move;
  413.                        markCBCorner;
  414.                      end else begin
  415.                        clrscr;
  416.                        write(menustr1);
  417.                        CBMode := size;
  418.                        markCBCorner;
  419.                       end;
  420.                  end; {PF1}
  421.                PF3: if CBMode = size then begin
  422.                       clrscr; write('auto-sizing copyblock...');
  423.                       ShowCopyBlock;
  424.                       markCBCorner;
  425.                       if vidcol = color then SetColor(yellow)
  426.                         else SetColor(white);
  427.                       AutosizeCopyBlock;
  428.                       SetWriteMode(XORput);
  429.                       ShowCopyBlock;
  430.                       markCBCorner;
  431.                       clrscr;
  432.                       write(menustr1);
  433.                     end;
  434.                else if key in movers then MoveCopyBlock;
  435.                end; {case key of...}
  436.               end; {#0}
  437.        end; {case}
  438.       until done;
  439.     end; {with Copyblock do...}
  440.     onoff := on;
  441.     saved := false;
  442.     if CBMode = size then markCBCorner;
  443.     CBMode := move;
  444.     key := #200;
  445. end;
  446.  
  447. procedure CopyBlockMenu;
  448. const HelpStr =
  449. 'copyblock: F1 resize  F5 repaint  F7 on/off  ESC quit';
  450.      Helpstr1 = 'copyblock: F7 on/off  ESC quit';
  451. var btemp:boolean;
  452. begin clrscr;
  453.       key := #200;
  454.       if not noshow then begin
  455.           setwritemode(copyput);
  456.           SetColor(black);
  457.           ShowCopyBlock;
  458.        end;
  459.       if vidcol = color then SetColor(yellow);
  460.       setwritemode(XORput);
  461.       if not noshow then ShowCopyBLock;
  462.       CBMode := move;
  463.       repeat
  464.         if key = #200
  465.         then begin
  466.            clrscr;
  467.            if noshow then write(Helpstr1)
  468.            else begin write(Helpstr);
  469.               gotoxy(1,2);
  470.               write('copyblock size is ',
  471.                   CopyBlock.w/1000:4:2, ' X ',
  472.                   CopyBlock.h/1000:5:2,
  473.                   ' inches');
  474.               Gotoxy(1,1);
  475.             end;
  476.          end;
  477.         key := ReadKey;
  478.         if key = #0
  479.         then begin key := readkey;
  480.            case key of      {function keys}
  481.               PF1: if not noshow then begin
  482.                       CBmode := size;
  483.                       GetCopyBlock; key := #200;
  484.                       CBMode := move;
  485.                     end;
  486.               PF5: if not noshow then begin
  487.                       clrscr;
  488.                       setwritemode(copyput);
  489.                       SetColor(Black);
  490.                       ShowCopyBlock;
  491.                       SetColor(white);
  492.                       Repaint1;
  493.                       SetWriteMode(XORPut);
  494.                       ShowCopyBlock;
  495.                       key := #200;
  496.                     end;
  497.               PF7: begin
  498.                       btemp := noshow;
  499.                       if noshow then onoff := on
  500.                        else onoff := off; noshow := false;
  501.                       SetWriteMode(XORPut);
  502.                       ShowCopyBlock;
  503.                       noshow := not btemp;
  504.                       if noshow then key := CR else key := #200;
  505.                     end;
  506.               else if key in movers then MoveCopyBlock;
  507.            end ;{case}
  508.         end;
  509.       until (key = ESC) or (key = CR);
  510.       key := #0;
  511.       setwritemode(copyput);
  512.       ShowCopyBLock;
  513. {      SetColor(white);}
  514. end;
  515.  
  516. Procedure Repaint;
  517. begin
  518.      SetColor(Black);
  519.      ShowCopyBlock;
  520.      SetColor(white);
  521.      Repaint1;
  522.      if vidcol = color then SetColor(yellow);
  523.      SetWriteMode(XORPut);
  524.      ShowCopyBlock;
  525.      SetWriteMode(CopyPut);
  526.      SetColor(white);
  527. end;
  528.  
  529. procedure MoveLabel;
  530. var moving, moved, newbox, showing: boolean;
  531.     nn: word;
  532. begin   if select = nil then exit;
  533.         moving := false; newbox := false;
  534.         showlabel(select, black);
  535.         newbox := false;
  536.    repeat
  537.      {if newbox then begin}
  538.         if (vidcol = mono) or (moving and newbox) then BoxLabel(select, white);
  539.         if moving then newbox := true;
  540.      {end;}
  541.      case key of
  542.   (* -> *)       #77: TempText.CurrText.horiz := TempText.CurrText.horiz + 1;
  543.   (* <- *)       #75:  if TempText.CurrText.Horiz > 1 then
  544.                        TempText.CurrText.horiz := TempText.CurrText.horiz - 1;
  545.             uparrow : if TempText.CurrText.vert > 1 then
  546.                       TempText.CurrText.vert := TempText.CurrText.vert - 1;
  547.            downarrow: TempText.CurrText.vert := TempText.CurrText.vert + 1;
  548.   (* CNTRL -> *) #116: TempText.CurrText.horiz := TempText.CurrText.horiz + 10;
  549.   (* CNTRL <- *) #115: if TempText.CurrText.horiz > 10 then
  550.                        TempText.CurrText.horiz := TempText.CurrText.horiz - 10;
  551.   (* page up  *) #73 :if TempText.CurrText.vert > 10 then
  552.                        TempText.CurrText.vert := TempText.CurrText.vert - 10;
  553.   (* page down *) #81 : TempText.CurrText.vert := TempText.CurrText.vert + 10;
  554.      end; {case}
  555.      select^ := TempText;
  556.      if moving or (vidcol = mono) then begin
  557.         Boxlabel(select,white);
  558.      end;
  559.      if keypressed
  560.      then begin repeat key := readkey; until (not keypressed) ;
  561.                 moving := true;
  562.           end
  563.      else begin
  564.               nn := 0;
  565.               repeat
  566.                  delay(5);
  567.                  inc(nn);
  568.               until keypressed or (nn = 30);
  569.               if keypressed
  570.               then begin {key := readkey;} moving := true; end
  571.               else moving := false;
  572.           end;
  573.  until not moving ;
  574.     if newbox and (vidcol = color) then BoxLabel(select, white);
  575.     {SetWriteMode(CopyPut);}
  576.     if vidcol = color then highlight(select) else showlabel (select, white);
  577.     saved := false;
  578. end;
  579.  
  580. procedure Attributes;
  581. const HelpStr: string80 =
  582. 'F1  font  F2 size  F3 background <ESC> quit' ;
  583. var ans: char;
  584.     changed: boolean;
  585.  
  586.   procedure ShowAttrib;
  587.   begin
  588.     gotoxy(1,2);
  589.     Write('font style: ',userStyleNames[TempText.LipsFont.LIPSstyle]);
  590.     write('        point size: ', TempText.PrtSize); write('      ');
  591.     if TempText.LabelBkGround = trans then
  592.        write('transparent ')
  593.        else write('opaque ');
  594.     clrEOL; writeln;
  595.   end;
  596.  
  597. begin
  598.             if select = nil
  599.             then begin
  600.                       writeln('no label is selected - didn''t do anything');
  601.                       delay(1000);
  602.                       exit;
  603.                   end;
  604.             clrscr;
  605.             write(HelpStr);
  606.             showAttrib;
  607.             repeat key := readkey;
  608.             until (key = #0) or (key = ESC) or (key = CR);
  609.             changed := (key = #0);
  610.             if key = #0 then key := readkey;
  611.         case key of      {function keys}
  612.              PF1: SetLipsFont;
  613.              PF2: begin select^ := TempText;     { update }
  614.                         ShowLabel(Select, black);
  615.                         UnBoxLabel(select);
  616.                         ChangeSize;
  617.                         select^ := TempText;
  618.                         HighLight(select);
  619.                   end;
  620.              PF3: begin
  621.                       gotoxy(1,wherey); clrEOL;
  622.         Write('select label background O)pague or T)ransparent): ');
  623.                          ans := readkey; write(ans);
  624.                       if (upcase(ans) = 'O')
  625.                          then TempText.LabelBkGround := opaque
  626.                         else if (upcase(ans) = 'T')
  627.                          then TempText.LabelBkGround := trans;
  628.                       { --- set paint type for next label --- }
  629.                       defaultPaintType := TempText.LabelBkGround;
  630.                    end; {PF3}
  631.         end; {case}
  632.       key := #0;
  633.       if changed then saved := false;
  634. end;
  635.  
  636. { -----------------------------------------------------------------------
  637.                Show & move CopyBlock relative to page.
  638.   ----------------------------------------------------------------------- }
  639. Procedure ChangeLayout;
  640. const menustringL: string =
  641. 'F8 change to portrait            <HOME> center graph           <ESC> quit';
  642.       menustringP: string =
  643. 'F8 change to landscape           <HOME> center graph           <ESC> quit';
  644.  
  645.       marginStr: string =
  646. 'margins:    left       top      right    bottom' + CR + LF + '(inches)';
  647. var a, b, AA, BB: real;       {conversion constants}
  648.     lmargin, rmargin, tmargin, bmargin: real;
  649.     orgX, orgY: integer;  {PS coords of origin relative to LL of paper}
  650.     tLM, tRM, tTM, tBM: integer;  {for adjusting margins}
  651.     PsPageSize: rect;
  652.     key: char;
  653.  
  654.     procedure ShowPageBox;
  655.     var tlineInfo: LineSettingsType;
  656.     begin
  657.           Setcolor(white);
  658.           GetLineSettings(tlineInfo);
  659.           with tlineinfo do SetLineStyle(LineStyle, Pattern, thickwidth);
  660.           with PageRect do rectangle(ULx, ULy, LRx, LRy);
  661.           with tlineinfo do SetLineStyle(LineStyle, Pattern, Thickness);
  662.     end; {ShowPageBox}
  663.  
  664.     procedure SetUp;
  665.     const PSpageSizeLand:rect = (
  666.               LLx:0; LLy:0; URx: 11000; URy: 8500; w:11000; h: 8500);
  667.           PSpageSizePort: rect = (
  668.               LLx: 0; LLy: 0; URx: 8500; URy: 11000; w: 8500; h:11000);
  669.     begin
  670.         ClearViewPort;
  671.         with PageRect do begin
  672.            if Layout.Landscape then begin
  673.                  {ULx := 1;}
  674.                  ULy := 1;
  675.                  ULx := round(0.5*0.1*GetMaxX); {fudge factor for VGA}
  676.                  {sw := GetMaxX-ULx - 1;}
  677.                  sw := round(0.9*GetMaxX);
  678.                  sh := GetMaxY - 3*LinesperChar - 3;
  679.                  LRx := ULx + sw; LRY := ULy + sh;
  680.                  PsPageSize := PSpageSizeLand;
  681.             end else begin
  682.                  sw := integer(round(GetMaxX*sqr(0.9*8.5/11)));
  683.                  sh := GetMaxY - 3*LinesperChar - 3;
  684.                  ULx := (GetMaxX - sw) div 2; ULy := 1;
  685.                  LRx := ULx + sw; LRy := ULy + sh;
  686.                  PSpageSize := PSpageSizePort;
  687.              end;
  688.             a := (LRx - ULx)/PSpageSize.w;
  689.             b := ULx;
  690.             AA := (ULy - LRy)/PSpageSize.h;
  691.             BB := LRy;
  692.          end;
  693.         with Layout.Origin do
  694.            if Layout.Landscape then begin
  695.                  orgX := y;
  696.                  orgY := PSPageSize.h - x;
  697.             end else begin
  698.                  orgX := x;
  699.                  orgY := y;
  700.             end;
  701.         MenuLine;
  702.         setcolor(white);
  703.         {Line(0,GetMaxY - 3*LinesPerChar,GetMaxX,GetMaxY-3*LinesPerChar);}
  704.         SetWriteMode(XORPut);
  705.         ShowPageBox;
  706.         if vidcol = color then setcolor(yellow);
  707.         gotoxy(1,1); clrscr;
  708.         if layout.Landscape then write(menustringL) else write(menustringP);
  709.         gotoxy(1,2);
  710.         write(marginStr);
  711.         gotoxy(1,3);
  712.     end; {SetUp}
  713.  
  714.     procedure PStoScreenx(PS: integer; var Screen: integer);
  715.     begin
  716.         Screen := integer(round(a*PS+ b));
  717.     end;
  718.  
  719.     procedure PStoScreenY(PS: integer; var Screen: integer);
  720.     begin
  721.         Screen := integer(round(AA*PS + BB));
  722.     end;
  723.  
  724.     procedure ShowMargins;
  725.     begin
  726.         gotoxy(10,3);
  727.         with CopyBlock do begin
  728.            write((LLx + OrgX)/1000:8:3);
  729.            gotoxy(wherex + 2, wherey);
  730.            write((PSpageSize.h - (OrgY + URy))/1000:8:3);
  731.            gotoxy(wherex + 2, wherey);
  732.            write((PSpageSize.w - (OrgX + URx))/1000:8:3);
  733.            gotoxy(wherex + 2, wherey);
  734.            write((OrgY + URy - h)/1000:8:3);
  735.          end;
  736.     end; {ShowMargins}
  737.  
  738.     procedure GetMargins;
  739.     begin
  740.        tLM := OrgX;
  741.        tRM := PSPageSize.w - OrgX;
  742.        tTM := PSPageSize.h - OrgY;
  743.        tBM := OrgY;
  744.     end; {GetMargins}
  745.  
  746.     { -------------------------------------------------------------------
  747.        Set OrgX, OrgY, and copyblock corners to give specifed position
  748.        of upper left corner of bounding box relative to paper.
  749.       ------------------------------------------------------------------- }
  750.     procedure SetULmargins(lm, tm:integer);
  751.     begin
  752.        OrgX := lm;
  753.        OrgY := PSPagesize.h - tm;
  754.        with Layout.Origin do
  755.           if layout.Landscape then begin
  756.                y := OrgX;
  757.                x := PSPageSize.h - OrgY;
  758.            end else begin
  759.                y := OrgY;
  760.                x := OrgX;
  761.            end;
  762.     end; {SetULmargins}
  763.  
  764.     procedure ShowBBox;
  765.     var x1, y1, x2, y2: integer;
  766.     begin
  767.        with CopyBlock do begin
  768.             PStoScreenX(LLx + OrgX, x1);
  769.             PStoScreenY(LLy + h + OrgY, y1);
  770.             PStoScreenX(URx + OrgX, x2);
  771.             PStoScreenY(URy - h + OrgY, y2);
  772.         end;
  773.        rectangle(x1, y1, x2, y2);
  774.     end; {ShowBBox}
  775.  
  776.     procedure CenterBBox;
  777.     var tx, ty: integer;
  778.     begin
  779.         tx := OrgX + CopyBlock.LLx + CopyBlock.w div 2;
  780.         orgX := orgX + (PSPageSize.w div 2 - tx);
  781.         if LConfig.DoBar then begin
  782.              Layout.origin.x := CopyBlock.lly + 7130;
  783.              orgY := PSPageSize.h - Layout.origin.x;
  784.              setWritemode(copyput);
  785.              DeleteLogoLabel;
  786.              AddNewLogo;
  787.              setWriteMode(Xorput);
  788.              barY := Layout.origin.x - 1750;
  789.              if vidcol = color then setcolor(yellow) else setcolor(white);
  790.          end else begin
  791.              ty := OrgY + CopyBlock.LLy + CopyBlock.h div 2;
  792.              orgY := orgY + (PSpageSize.h div 2 - ty);
  793.          end;
  794.     end; {CenterBBox}
  795.  
  796.     procedure MoveBBox;
  797.     var moving, newbox : boolean;
  798.         delX, delY: integer;
  799.     begin
  800.            moving := false;
  801.            Layout.ChangeLayout := true;
  802.            delX := integer(round(0.5/a));
  803.            delY := -integer(round(0.5/AA));
  804.            repeat
  805.              ShowBBox;
  806.              case key of
  807.                   rightarrow : orgX := OrgX + delX;
  808.                   leftarrow  : orgX := OrgX - delX;
  809.                   uparrow    : OrgY := OrgY + delY;
  810.                   downarrow  : orgY := orgY - delY;
  811.   (* CNTRL -> *) #116        : orgX := orgX + 10*delX;
  812.   (* CNTRL <- *) #115        : orgX := orgX - 10*delX;
  813.   (* page up  *) #73         : orgY := orgY + 10*delY;
  814.   (* page down *) #81        : orgY := orgY - 10*delY;
  815.                  Home        : CenterBBox;
  816.               end; {case}
  817.              ShowBBox;
  818.              ShowMargins;
  819.              if keypressed then begin
  820.                   repeat key := readkey; until (not keypressed) ;
  821.                   moving := true;
  822.                   if key = #0 then key := readkey;
  823.               end else begin
  824.                 delay(50);
  825.                 if keypressed then begin
  826.                    key := readkey; moving := true;
  827.                    if key = #0 then key := readkey;
  828.                  end else moving := false;
  829.                end;
  830.            until not moving ;
  831.     end; {MoveBBox}
  832.  
  833.     procedure SaveSettings;
  834.     begin
  835.         with Layout do begin
  836.           if LandScape then begin
  837.                origin.x := PSpageSize.h - OrgY;
  838.                origin.y := orgX;
  839.                with BoundingBox do begin
  840.                  LLx := integer(round(72.0*
  841.                        (PSPageSize.h -(orgY + CopyBlock.LLy)) /1000));
  842.                  LLy := integer(round(72.0*(orgX + CopyBlock.LLx) /1000));
  843.                  URx := integer(round(72.0*
  844.                         (PSpageSize.h -(orgY + CopyBlock.URy)) /1000));
  845.                  URy := integer(round(72.0*(orgX + CopyBlock.URx) /1000));
  846.                 end;
  847.             end else begin
  848.                origin.x := orgX;
  849.                origin.Y := orgY;
  850.                with BoundingBox do begin
  851.                  LLx := integer(round(72.0*(origin.x + CopyBlock.LLx) /1000));
  852.                  LLy := integer(round(72.0*(origin.y + CopyBlock.LLy)/1000));
  853.                  URx := integer(round(72.0*(origin.x + CopyBlock.URx)/1000));
  854.                  URy := integer(round(72.0*(origin.y + CopyBlock.URy)/1000));
  855.                 end;
  856.             end;
  857.            with BoundingBox do begin
  858.                if (URx < LLx) then begin
  859.                    w := URx; URx := LLx; LLx := w;
  860.                 end;
  861.                if (URy < LLy) then begin
  862.                    w := URy; URy := LLy; LLy := w;
  863.                 end;
  864.                w := URx - LLx;
  865.                h := URy - LLy;
  866.             end;
  867.          end; {with Layout do...}
  868.          if Layout.Changelayout then saved := false;
  869.     end; {SaveSettings}
  870.  
  871.     procedure Cleanup;
  872.     begin
  873.         ShowBBox;
  874.         if vidcol = color then setcolor(white);
  875.         ShowPageBox;
  876.         SetWriteMode(Copyput);
  877.     end; {Cleanup}
  878.  
  879.     procedure UserInterface;
  880.     const movers: set of char = [leftarrow, rightarrow, uparrow, downarrow,
  881.                                  Home, #115, #116, #73, #81];
  882.     var done: boolean;
  883.     begin
  884.       done := false;
  885.       repeat
  886.          key := readkey;
  887.          case key of
  888.             ESC: done := true;
  889.             #0: begin
  890.                    key := readkey;
  891.                    case key of
  892.                       PF8: begin
  893.                              ShowBBox;
  894.                              ShowPageBox;
  895.                              GetMargins;
  896.                              Layout.LandScape := not Layout.LandScape;
  897.                              Layout.ChangeLayout := true;
  898.                              SetUp;
  899.                              SetULMargins(tLM, tTM);
  900.                              MenuLine;
  901.                              ShowBBox;
  902.                              ShowMargins;
  903.                             end;
  904.                      else if key in movers then MoveBBox;
  905.                     end; {case key of}
  906.                   end; {#0}
  907.           end; {case key of...}
  908.        until done;
  909.     end; {UserInterface}
  910.  
  911. begin
  912.    Setup;
  913.    ShowBBox;
  914.    ShowMargins;
  915.    UserInterface;
  916.    SaveSettings;
  917.    Cleanup;
  918. end; {ChangeLayout}