home *** CD-ROM | disk | FTP | other *** search
/ DTP Toolbox / DTPToolbox.iso / propage4.0 / arexx / borderssimpleshapes.pprx < prev    next >
Encoding:
Text File  |  1994-03-29  |  27.2 KB  |  849 lines

  1. /* This Genie puts a decorative border around a box, using data stored in the genie. The resulting border is merged into a single box. The current line and fill colours are used. 
  2. Genie written and © by Don Cox   July 92. Bug fixes Jan 93, Mar 94. Not public domain.  All rights reserved. */
  3. /* $VER: BordersSimpleShapes March 94  */
  4.  
  5. trace n
  6. address command
  7. signal on error
  8. signal on syntax
  9. signal on halt
  10. signal on break_c
  11. signal on break_d
  12. signal on break_e
  13.  
  14. if ~show("l", "gdarexxsupport.library") then
  15.     if ~addlib("gdarexxsupport.library", 0, -30,0) then do
  16.         call ppm_Inform(1,"Please install the gdarexxsupport.library in your libs: directory before running this Genie.")
  17.     end
  18.  
  19. /* rexxmathlib.library is needed to work around the square root bug in gdarexxsupport.library  */
  20. if ~show("l", "rexxmathlib.library") then
  21.     if ~addlib("rexxmathlib.library", 0, -30,0) then do
  22.         call ppm_Inform(1,"Please install the rexxmathlib.library in your libs: directory before running this Genie.")
  23.     end
  24.  
  25. call ppm_AutoUpdate(0)
  26. call SafeEndEdit.rexx()
  27. cr="0a"x
  28.  
  29.  
  30. CurrentUnits = ppm_GetUnits()
  31.  
  32. select
  33.     when CurrentUnits = 1 then do
  34.         units="inches"
  35.         mul = 1
  36.         mul2 = 72
  37.         end
  38.     when CurrentUnits = 2 then do
  39.         units="mm"
  40.         mul = 10
  41.         mul2 = 28.4
  42.         end
  43.     otherwise do 
  44.         call ppm_SetUnits(2)
  45.         units="mm"
  46.         mul = 10
  47.         mul2 = 28.4
  48.         end
  49.     end
  50.  
  51. mainbox = ppm_ClickOnBox("  Click on box to be given a border")
  52. if mainbox = 0 then exit_msg("No box selected")
  53. mainpos = ppm_GetBoxPosition(mainbox)
  54. mainXpos = word(mainpos, 1)
  55. mainYpos = word(mainpos, 2)
  56. mainsize = ppm_GetBoxSize(mainbox)
  57. mainwidth = word(mainsize,1)
  58. mainheight = word(mainsize,2)
  59. mainangle = ppm_GetBoxAngle(mainbox)
  60.  
  61.  
  62. /* Initialize data strings  */
  63. cornerline1 = "" 
  64. cornerline2 = ""
  65. cornerline3 = ""
  66. cornerweight1 = "" 
  67. cornerweight2 = ""
  68. cornerweight3 = ""
  69. sideline1 = ""
  70. sideline2 = ""
  71. sideline3 = ""
  72. cornerXoffset = 0
  73. cornerYoffset = 0
  74. sideXoffset = 0
  75. sideYoffset = 0
  76. cornerfill1 = 0
  77. cornerfill2 = 0
  78. cornerfill3 = 0
  79. sidefill1 = 0
  80. sidefill2 = 0
  81. sidefill3 = 0
  82. lines = 1
  83.  
  84. list = "Greek Key"cr"Two Rules"cr"Two Rules Rounded"cr"Two Rules Reverse Rounded"cr"Three Rules"cr"Battlements"cr"Cutout"cr"Filled Squares"cr"Double Squares"cr"Off-Centre Squares"cr"Filled Triangles"cr"Filled Triangles 2"cr"Three Ls"cr"Bars"
  85. chosen = ppm_SelectFromList("Select Border Pattern",30,14,0,list)
  86. if chosen = "" then exit_msg("Aborted by User")
  87.  
  88. /* Data for various patterns. The numbers are lists of coordinates in the format required by the DrawPoly command.  */
  89.  
  90. select 
  91.  
  92.     when chosen = "Bars" then do
  93.         cornerline1 = "0 0"cr"3 0"cr"3 3"cr"0 3"cr"0 0"
  94.         cornerline2 = "5 0"cr"7 0"cr"7 7"cr"0 7"cr"0 5"cr"5 5"cr"5 0"
  95.         cornerline3 = "9 0"cr"11 0"cr"11 11"cr"0 11"cr"0 9"cr"9 9"cr"9 0"
  96.         sideline1 = "1 0"cr"3 0"cr"3 12"cr"1 12"cr"1 0"
  97.         sideline2 = "5 0"cr"7 0"cr"7 12"cr"5 12"cr"5 0"
  98.         sideheight = 12
  99.         sidewidth = 8
  100.         sideXoffset = 1
  101.         sideYoffset = 0
  102.         cornerheight = 12
  103.         cornerwidth = 12
  104.         cornerXoffset = 0
  105.         cornerYoffset = 0
  106.         cornerfill1 = 1
  107.         cornerfill2 = 1
  108.         cornerfill3 = 1
  109.         sidefill1 = 1
  110.         sidefill2 = 1
  111.         sidefill3 = 0
  112.         lines = 0   /* number of line weights to be set by user  */
  113.         end
  114.  
  115.     when chosen = "Three Ls" then do
  116.         cornerline1 = "0 0"cr"4 0"cr"4 4"cr"0 4"cr"0 0"
  117.         cornerline2 = "6 0"cr"9 0"cr"9 9"cr"0 9"cr"0 6"cr"6 6"cr"6 0"
  118.         sideline1 = "1 0"cr"3 0"cr"3 8"cr"11 8"cr"11 10"cr"1 10"cr"1 0"
  119.         sideline2 = "5 0"cr"7 0"cr"7 4"cr"11 4"cr"11 6"cr"5 6"cr"5 0"
  120.         sideline3 = "9 0"cr"11 0"cr"11 2"cr"9 2"cr"9 0"
  121.         sideheight = 10
  122.         sidewidth = 12
  123.         sideXoffset = 1
  124.         sideYoffset = 0
  125.         cornerheight = 10
  126.         cornerwidth = 10
  127.         cornerXoffset = 0
  128.         cornerYoffset = 0
  129.         cornerfill1 = 1
  130.         cornerfill2 = 1
  131.         sidefill1 = 1
  132.         sidefill2 = 1
  133.         sidefill3 = 1
  134.         lines = 0
  135.         end
  136.  
  137.     when chosen = "Filled Triangles 2" then do
  138.         cornerline1 = "4.3 0"cr"4.3 4.3"cr"0 4.3"cr"4.3 0"
  139.         sideline1 = "0 0"cr"4 0"cr"0 4"cr"0 0"
  140.         sideline2 = "5 1"cr"5 5"cr"1 5"cr"5 1"
  141.         sideheight = 5
  142.         sidewidth = 6.4
  143.         sideXoffset = 0.7
  144.         sideYoffset = 0
  145.         cornerheight = 5
  146.         cornerwidth = 5
  147.         cornerXoffset = 0
  148.         cornerYoffset = 0
  149.         cornerfill1 = 1
  150.         sidefill1 = 1
  151.         sidefill2 = 1
  152.         sidefill3 = 0
  153.         lines = 0
  154.         end
  155.  
  156.     when chosen = "Filled Triangles" then do
  157.         cornerline1 = "2.6 0"cr"2.6 2.6"cr"0 2.6"cr"2.6 0"
  158.         sideline1 = "0 0"cr"4 4"cr"0 4"cr"0 0"
  159.         sideline2 = "2 0"cr"10 0"cr"6 4"cr"2 0"
  160.         sideline3 = "12 0"cr"12 4"cr"8 4"cr"12 0"
  161.         sideheight = 4
  162.         sidewidth = 12
  163.         sideXoffset = 0
  164.         sideYoffset = 0
  165.         cornerheight = 4
  166.         cornerwidth = 4
  167.         cornerXoffset = 0
  168.         cornerYoffset = 0
  169.         cornerfill1 = 1
  170.         sidefill1 = 1
  171.         sidefill2 = 1
  172.         sidefill3 = 1
  173.         lines = 0
  174.         end
  175.  
  176.     when chosen = "Off-Centre Squares" then do
  177.         cornerline1 = "0 0"cr"4 0"cr"4 4"cr"0 4"cr"0 0"
  178.         cornerline2 = "0 0"cr"2 0"cr"2 2"cr"0 2"cr"0 0"
  179.         sideline1 = "1 0"cr"5 0"cr"5 4"cr"1 4"cr"1 0"
  180.         sideline2 = "1 0"cr"3 0"cr"3 2"cr"1 2"cr"1 0"
  181.         sideheight = 5
  182.         sidewidth = 6
  183.         sideXoffset = 1
  184.         sideYoffset = 0
  185.         cornerheight = 5
  186.         cornerwidth = 5
  187.         cornerXoffset = 0
  188.         cornerYoffset = 0
  189.         cornerfill1 = 0
  190.         sidefill1 = 0
  191.         lines = 1
  192.         end
  193.  
  194.     when chosen = "Double Squares" then do
  195.         cornerline1 = "0 0"cr"4 0"cr"4 4"cr"0 4"cr"0 0"
  196.         cornerline2 = "1 1"cr"3 1"cr"3 3"cr"1 3"cr"1 1"
  197.         sideline1 = "1 0"cr"5 0"cr"5 4"cr"1 4"cr"1 0"
  198.         sideline2 = "2 1"cr"4 1"cr"4 3"cr"2 3"cr"2 1"
  199.         sideheight = 5
  200.         sidewidth = 6
  201.         sideXoffset = 1
  202.         sideYoffset = 0
  203.         cornerheight = 5
  204.         cornerwidth = 5
  205.         cornerXoffset = 0
  206.         cornerYoffset = 0
  207.         cornerfill1 = 0
  208.         sidefill1 = 0
  209.         lines = 1
  210.         end
  211.  
  212.     when chosen = "Filled Squares" then do
  213.         cornerline1 = "0 0"cr"4 0"cr"4 4"cr"0 4"cr"0 0"
  214.         sideline1 = "1 0"cr"5 0"cr"5 4"cr"1 4"cr"1 0"
  215.         sideheight = 5
  216.         sidewidth = 6
  217.         sideXoffset = 1
  218.         sideYoffset = 0
  219.         cornerheight = 5
  220.         cornerwidth = 5
  221.         cornerXoffset = 0
  222.         cornerYoffset = 0
  223.         cornerfill1 = 1
  224.         sidefill1 = 1
  225.         lines = 0
  226.         end
  227.  
  228.     when chosen = "Cutout" then do
  229.         cornerline1 = "0 1"cr"0 0"cr"1 0"
  230.         sideline1 = "0 0"cr"1 0"
  231.         sideline2 = "3 0"cr"4 0"
  232.         sideheight = 1
  233.         sidewidth = 4
  234.         sideXoffset = 0
  235.         sideYoffset = 0
  236.         cornerheight = 1
  237.         cornerwidth = 1
  238.         cornerXoffset = 0
  239.         cornerYoffset = 0
  240.         lines = 1
  241.         end
  242.  
  243.     when chosen = "Battlements" then do
  244.         cornerline1 = "0 0"cr"3.3 0"cr"3.3 2.3"cr"2.3 2.3"cr"2.3 3.3"cr"0 3.3"cr"0 0"
  245.         sideline1 = "0 6"cr"1 6"cr"1 0"cr"3 0"cr"3 6"cr"4 6"
  246.         sideheight = 6
  247.         sidewidth = 4
  248.         sideXoffset = 0
  249.         sideYoffset = 0
  250.         cornerheight = 4
  251.         cornerwidth = 4
  252.         cornerXoffset = 0
  253.         cornerYoffset = 0
  254.         lines = 1
  255.         end
  256.  
  257.     when chosen = "Greek Key" then do
  258.         sideline1 = "0 0"cr"6 0"cr"6 5"cr"3 5"cr"3 3"cr"2 3"cr"2 6"cr"7 6"cr"7 0"cr"8 0"
  259.         sideline2 = "0 1"cr"5 1"cr"5 4"cr"4 4"cr"4 2"cr"1 2"cr"1 7"cr"8 7"cr"8 0.8"
  260.         sideheight = 8
  261.         sidewidth = 8
  262.         sideXoffset = 0
  263.         sideYoffset = 0
  264.         cornerheight = 8
  265.         cornerwidth = 8
  266.         cornerXoffset = 0
  267.         cornerYoffset = 0
  268.         Cornerline1 = "0 8"cr"0 0"cr"6 0"cr"6 5"cr"2 5"cr"2 2"cr"4 2"cr"4 3"cr"3 3"cr"3 4"cr"5 4"cr"5 1"cr"1 1"cr"1 6"cr"7 6"cr"7 0"cr"8 0"
  269.         Cornerline2 = "1 8"cr"1 7"cr"8 7"cr"8 0.8"
  270.         lines = 0
  271.         end
  272.  
  273.     when chosen = "Two Rules" then do
  274.         sideline1 = ""
  275.         sideline2 = ""
  276.         Cornerline1 = ""
  277.         cornerline2 = ""
  278.         lines = 2
  279.         end
  280.  
  281.     when chosen = "Two Rules Rounded" | chosen = "Two Rules Reverse Rounded" then do
  282.         sideline1 = ""
  283.         sideline2 = ""
  284.         Cornerline1 = ""
  285.         cornerline2 = ""
  286.         lines = 100    /* impossible number as a flag */
  287.         end
  288.  
  289.     when chosen = "Three Rules" then do
  290.         sideline1 = ""
  291.         sideline2 = ""
  292.         Cornerline1 = ""
  293.         cornerline2 = ""
  294.         lines = 3
  295.         end
  296.  
  297.     otherwise do
  298.         cornerline1 = "" 
  299.         cornerline2 = ""
  300.         cornerline3 = ""
  301.         sideline1 = ""
  302.         sideline2 = ""
  303.         sideline3 = ""
  304.         end
  305.     end
  306.  
  307.  
  308. /* Collect line weights from user  */
  309.  
  310. if lines>3  & lines~=100 then lines = 3
  311.  
  312. select
  313.     when lines = 0 then do
  314.         form = ppm_GetForm("Set sizes",8,"Border width ("units")")
  315.         if form = "" then exit_msg("Aborted by user")
  316.         cornerweight1 = ""
  317.         parse var form breadth 
  318.         end
  319.  
  320.     when lines = 1 then do
  321.         form = ppm_GetForm("Set sizes",8,"Border width ("units")"cr"Line weight (points)")
  322.         if form = "" then exit_msg("Aborted by user")
  323.         parse var form breadth "0a"x cornerweight1
  324.         end
  325.  
  326.     when lines = 2 then do
  327.         form = ppm_GetForm("Set sizes",8,"Border width ("units")"cr"Line 1 (points)"cr"Line 2 (points)")
  328.         if form = "" then exit_msg("Aborted by user")
  329.         parse var form breadth "0a"x cornerweight1 "0a"x cornerweight2
  330.         end
  331.  
  332.     when lines = 3 then do
  333.         form = ppm_GetForm("Set sizes",8,"Border width ("units")"cr"Line 1 (points)"cr"Line 2 (points)"cr"Line 3 (points)")
  334.         if form = "" then exit_msg("Aborted by user")
  335.         parse var form  breadth "0a"x cornerweight1 "0a"x cornerweight2 "0a"x cornerweight3
  336.         end
  337.  
  338.     when lines = 100 then do
  339.         form = ppm_GetForm("Set sizes",8,"Border width ("units")"cr"Line 1 (points)"cr"Line 2 (points)"cr"Corner Radius ("units")")
  340.         if form = "" then exit_msg("Aborted by user")
  341.         parse var form  breadth "0a"x cornerweight1 "0a"x cornerweight2 "0a"x cornerRadius
  342.         if cornerRadius = "" then cornerRadius = breadth*2
  343.         end
  344.  
  345.     otherwise nop
  346.     end
  347.  
  348.  
  349. if breadth="" then exit_msg("Aborted by User")
  350. breadth = breadth/mul /* mm to cm */
  351. if breadth>(word(mainsize,1))/2 | breadth>(word(mainsize,2))/2 then exit_msg("Too big")
  352.  
  353. defaultweight = (breadth*mul2)/20
  354. if cornerweight1 = "" then cornerweight1 = defaultweight
  355. if cornerweight2 = "" then cornerweight2 = defaultweight
  356. if cornerweight3 = "" then cornerweight3 = defaultweight
  357.  
  358. if lines = 1 | lines = 0 then do
  359.     cornerweight2 = cornerweight1
  360.     cornerweight3 = cornerweight1
  361.     end
  362. if lines = 2 then cornerweight3 = cornerweight2
  363. sideweight1 = cornerweight1
  364. sideweight2 = cornerweight2
  365. sideweight3 = cornerweight3
  366. maxweight = max(cornerweight1, cornerweight2, cornerweight3)
  367. maxwt = maxweight/72  /* max. line weight in inches  */
  368. if CurrentUnits = 2 then maxwt = maxwt*2.54  /* or centimetres  */
  369.  
  370.  
  371. /* First deal with plain rectangular borders  */
  372.  
  373. if chosen = "Two Rules" then do
  374.         call ppm_SetFillPattern(0)
  375.         call ppm_NewGroup()
  376.         call ppm_SetLineWeight(sideweight1)
  377.         rect1 = ppm_DrawRect(mainXpos, mainYpos, mainXpos+word(mainsize,1), mainYpos+word(mainsize,2))
  378.         call ppm_AddToGroup(rect1)
  379.         call ppm_SetLineWeight(sideweight2)
  380.         rect2 = ppm_DrawRect(mainXpos+breadth, mainYpos+breadth, mainXpos+word(mainsize,1)-breadth, mainYpos+word(mainsize,2)-breadth)
  381.         call ppm_AddToGroup(rect2)
  382.         borderbox = ppm_MergeGroup()
  383.         call ppm_SetBoxAngle(borderbox,mainangle)
  384.         call ppm_SetBoxPosition(borderbox,mainXpos,mainYpos)
  385. /* Set an arbitrary margin in main box  */
  386.         margin = breadth*2
  387.         call ppm_SetBoxMargins(mainbox, margin, margin, margin, margin)
  388.         exit_msg("Done")
  389.         end
  390.  
  391. if chosen = "Two Rules Rounded" | chosen = "Two Rules Reverse Rounded" then do
  392.         rev = 0
  393.         if chosen = "Two Rules Reverse Rounded" then rev = 1
  394.         call ppm_ShowStatus("  Calculating outer line ...")
  395.         call ppm_SetFillPattern(0)
  396.         call ppm_NewGroup()
  397.  
  398. removed = remlib("gdarexxsupport.library")
  399. if removed~=1 then call ppm_Inform(1,"Could not remove gdarexxsupport.library - curves may be faulty","Resume")
  400.  
  401. cornerRadius = cornerRadius/mul /* convert units */
  402. cRadius = cornerRadius /* for positioning centres of arcs */
  403.  
  404. AA=6.2831853/360    /* 2pi divided by 360 */
  405. AAA=AA*3
  406. angle= 180*AA /* convert to radians  */
  407. if rev = 1 then do /* for reverse curve corners  */
  408.     angle = 90*AA
  409.     AAA=-AAA  /* anti-clockwise arcs  */
  410.     cRadius = 0
  411.     end
  412.  
  413. drawstring = mainXpos (mainYpos+cornerRadius)||"0a"x
  414.  
  415. /* Draw the outer line, using 3 degree steps to give a smooth curve */
  416.         call ppm_SetLineWeight(sideweight1)
  417.         Xcentre = mainXpos+cRadius  /* centre of corner arc  */
  418.         Ycentre = mainYpos+cRadius
  419.         do i = 1 to 30
  420.             X2=Xcentre+(cornerRadius*cos(angle))
  421.             Y2=Ycentre+(cornerRadius*sin(angle))
  422.             angle=angle+AAA
  423.             drawstring=drawstring||X2 Y2"0a"x
  424.             end
  425.         if rev = 1 then drawstring = drawstring||(mainXpos +cornerRadius) mainYpos"0a"x
  426.         drawstring = drawstring||(mainXpos +mainwidth -cornerRadius) mainYpos"0a"x
  427.         Xcentre = mainXpos+mainwidth-cRadius
  428.         Ycentre = mainYpos+cRadius
  429.         if rev = 1 then angle = angle+(60*AAA)
  430.         do i = 1 to 30
  431.             X2=Xcentre+(cornerRadius*cos(angle))
  432.             Y2=Ycentre+(cornerRadius*sin(angle))
  433.             angle=angle+AAA
  434.             drawstring=drawstring||X2 Y2"0a"x
  435.             end
  436.         if rev = 1 then drawstring = drawstring||(mainXpos +mainwidth) (mainYpos+cornerRadius)"0a"x
  437.         drawstring = drawstring||(mainXpos+mainwidth) (mainYpos+mainheight-cornerRadius)"0a"x
  438.  
  439.         Xcentre = mainXpos+mainwidth-cRadius
  440.         Ycentre = mainYpos+mainheight-cRadius
  441.         if rev = 1 then angle = angle+(60*AAA)
  442.         do i = 1 to 30
  443.             X2=Xcentre+(cornerRadius*cos(angle))
  444.             Y2=Ycentre+(cornerRadius*sin(angle))
  445.             angle=angle+AAA
  446.             drawstring=drawstring||X2 Y2"0a"x
  447.             end
  448.         if rev = 1 then drawstring = drawstring||(mainXpos +mainwidth -cornerRadius) (mainYpos+mainheight)"0a"x
  449.         drawstring = drawstring||(mainXpos+cornerRadius) (mainYpos+mainheight)"0a"x
  450.         Xcentre = mainXpos+cRadius
  451.         Ycentre = mainYpos+mainheight-cRadius
  452.         if rev = 1 then angle = angle+(60*AAA)
  453.         do i = 1 to 30
  454.             X2=Xcentre+(cornerRadius*cos(angle))
  455.             Y2=Ycentre+(cornerRadius*sin(angle))
  456.             angle=angle+AAA
  457.             drawstring=drawstring||X2 Y2"0a"x
  458.             end
  459.         if rev = 1 then drawstring = drawstring||mainXpos (mainYpos+mainheight-cornerRadius)"0a"x
  460.         drawstring = drawstring||mainXpos (mainYpos+cornerRadius)"0a"x
  461.         call ppm_SaveText("ram:arcdata",drawstring)
  462.         box = ppm_DrawPoly("ram:arcdata","arcbox")
  463.         call ppm_AddToGroup(box)
  464.  
  465.  
  466. /* Draw the inner arc, in 3 degree steps to give a smooth curve */
  467.         call ppm_ShowStatus("  Calculating inner line ...")
  468.         call ppm_SetLineWeight(sideweight2)
  469.         cornerRadius2 = cornerRadius-breadth
  470.         if rev = 1 then do
  471.             cornerRadius2 = cornerRadius+breadth
  472.             cornerRadius = cornerRadius+breadth
  473.             a2 = sin(90*AA)/cornerRadius*breadth
  474.             a4 = abs(-a2*a2+1)
  475.             a4 = sqrt(a4)
  476.             a2 = atan(a2/a4)
  477.             a3 = 3.1415927-(90*AA)-a2
  478.             startangle = a2
  479.             arcangle = (90*AA)-(2*startangle)
  480.             AAA = -(arcangle/30)
  481.             angle = (90*AA)-startangle
  482.             end
  483.  
  484. /* first corner */
  485.         drawstring = (mainXpos+breadth) (mainYpos+cornerRadius)||"0a"x
  486.         Xcentre = mainXpos+cRadius
  487.         Ycentre = mainYpos+cRadius
  488.         do i = 0 to 30
  489.             X2=Xcentre+(cornerRadius2*cos(angle))
  490.             Y2=Ycentre+(cornerRadius2*sin(angle))
  491.             angle=angle+AAA
  492.             drawstring=drawstring||X2 Y2"0a"x
  493.             end
  494.         if rev = 1 then drawstring = drawstring||(mainXpos +cornerRadius) (mainYpos+breadth)"0a"x
  495.         drawstring = drawstring||(mainXpos +mainwidth -cornerRadius) (mainYpos+breadth)"0a"x
  496.  
  497. /* second corner */
  498.         Xcentre = mainXpos+mainwidth-cRadius
  499.         Ycentre = mainYpos+cRadius
  500.         if rev = 1 then angle = (180*AA)-startangle
  501.         do i = 0 to 30
  502.             X2=Xcentre+(cornerRadius2*cos(angle))
  503.             Y2=Ycentre+(cornerRadius2*sin(angle))
  504.             angle=angle+AAA
  505.             drawstring=drawstring||X2 Y2"0a"x
  506.             end
  507.         if rev = 1 then drawstring = drawstring||(mainXpos +mainwidth -breadth) (mainYpos+cornerRadius)"0a"x
  508.         drawstring = drawstring||(mainXpos+mainwidth-breadth) (mainYpos+mainheight-cornerRadius)"0a"x
  509.  
  510. /* third corner  */
  511.         Xcentre = mainXpos+mainwidth-cRadius
  512.         Ycentre = mainYpos+mainheight-cRadius
  513.         if rev = 1 then angle = (270*AA)-startangle
  514.         do i = 0 to 30
  515.             X2=Xcentre+(cornerRadius2*cos(angle))
  516.             Y2=Ycentre+(cornerRadius2*sin(angle))
  517.             angle=angle+AAA
  518.             drawstring=drawstring||X2 Y2"0a"x
  519.             end
  520.         if rev = 1 then drawstring = drawstring||(mainXpos +mainwidth -cornerRadius) (mainYpos+mainheight-breadth)"0a"x
  521.         drawstring = drawstring||(mainXpos+cornerRadius) (mainYpos+mainheight-breadth)"0a"x
  522.  
  523. /* fourth corner  */
  524.         Xcentre = mainXpos+cRadius
  525.         Ycentre = mainYpos+mainheight-cRadius
  526.         if rev = 1 then angle = 0-startangle
  527.         do i = 0 to 30
  528.             X2=Xcentre+(cornerRadius2*cos(angle))
  529.             Y2=Ycentre+(cornerRadius2*sin(angle))
  530.             angle=angle+AAA
  531.             drawstring=drawstring||X2 Y2"0a"x
  532.             end
  533.         if rev = 1 then drawstring = drawstring||(mainXpos +breadth) (mainYpos+mainheight-cornerRadius)"0a"x
  534.         drawstring = drawstring||(mainXpos+breadth) (mainYpos+cornerRadius)"0a"x
  535.         call ppm_SaveText("ram:arcdata2",drawstring)
  536.         box = ppm_DrawPoly("ram:arcdata2","arcbox2")
  537.         call ppm_AddToGroup(box)
  538.         borderbox = ppm_MergeGroup()
  539.         call ppm_SetBoxAngle(borderbox,mainangle)
  540.         call ppm_SetBoxPosition(borderbox,mainXpos-((sideweight1/2)/mul2), mainYpos-((sideweight1/2)/mul2))  
  541.  
  542.  
  543. /* Set an arbitrary margin in main box  */
  544.         margin = cornerRadius*1.2
  545.         call ppm_SetBoxMargins(mainbox, margin, margin, margin, margin)
  546.         exit_msg()
  547.  
  548.  
  549.  
  550.         end
  551.  
  552.  
  553. if chosen = "Three Rules" then do
  554.         call ppm_NewGroup()
  555.         call ppm_SetLineWeight(sideweight1)
  556.         call ppm_SetFillPattern(0)
  557.         rect1 = ppm_DrawRect(mainXpos, mainYpos, mainXpos+word(mainsize,1), mainYpos+word(mainsize,2))
  558.         call ppm_AddToGroup(rect1)
  559.         call ppm_SetLineWeight(sideweight2)
  560.         rect2 = ppm_DrawRect(mainXpos+(breadth/3), mainYpos+(breadth/3), mainXpos+word(mainsize,1)-(breadth/3), mainYpos+word(mainsize,2)-(breadth/3))
  561.         call ppm_AddToGroup(rect2)
  562.         call ppm_SetLineWeight(sideweight3)
  563.         rect3 = ppm_DrawRect(mainXpos+breadth, mainYpos+breadth, mainXpos+word(mainsize,1)-breadth, mainYpos+word(mainsize,2)-breadth)
  564.         call ppm_AddToGroup(rect3)
  565.         borderbox = ppm_MergeGroup()
  566.         call ppm_SetBoxAngle(borderbox,mainangle)
  567.         call ppm_SetBoxPosition(borderbox,mainXpos,mainYpos)
  568. /* Set an arbitrary margin in main box  */
  569.         margin = breadth*2
  570.         call ppm_SetBoxMargins(mainbox, margin, margin, margin, margin)
  571.         exit_msg("Done")
  572.         end
  573.  
  574.  
  575. /* Now deal with borders using shapes scaled to fit  */
  576.  
  577. mainheight = (word(mainsize, 2))-(breadth*2)
  578. mainwidth = (word(mainsize, 1))-(breadth*2)
  579.  
  580. call ppm_NewGroup()
  581. count = 0
  582.  
  583. if cornerline1 ~= "" then do
  584.     drawstring = cornerline1
  585.     call ppm_SaveText("ram:linedata",drawstring)
  586.     call ppm_SetLineWeight(cornerweight1)
  587.     call ppm_SetFillPattern(cornerfill1)
  588.     cornerbox = ppm_DrawPoly("ram:linedata")
  589.     call ppm_AddToGroup(cornerbox)
  590.     count = count+1
  591.     end
  592.  
  593. if cornerline2 ~= "" then do
  594.     drawstring = cornerline2
  595.     call ppm_SaveText("ram:linedata",drawstring)
  596.     call ppm_SetLineWeight(cornerweight2)
  597.     call ppm_SetFillPattern(cornerfill2)
  598.     cornerbox = ppm_DrawPoly("ram:linedata")
  599.     call ppm_AddToGroup(cornerbox)
  600.     count = count+1
  601.     end
  602.  
  603. if cornerline3 ~= "" then do
  604.     drawstring = cornerline3
  605.     call ppm_SaveText("ram:linedata",drawstring)
  606.     call ppm_SetLineWeight(cornerweight3)
  607.     call ppm_SetFillPattern(cornerfill3)
  608.     cornerbox = ppm_DrawPoly("ram:linedata")
  609.     call ppm_AddToGroup(cornerbox)
  610.     count = count+1
  611.     end
  612.  
  613. if count>1 then cornerbox = ppm_MergeGroup() /* Merge fails with 1 box */
  614.  
  615. if cornerbox ~=0 then do
  616.     if cornerheight~=0 & cornerwidth~=0 then call ppm_SetBoxSize(cornerbox, cornerwidth, cornerheight)
  617.     call ppm_SetBoxOffset(cornerbox,cornerXoffset,cornerYoffset)
  618.     csize = ppm_GetBoxSize(cornerbox)
  619.     cXsize = word(csize, 1)
  620.     cYsize = word(csize, 2)
  621.     cscale = ppm_GetBoxScale(cornerbox)
  622.     cscaleX = word(cscale, 1)
  623.     cscaleY = word(cscale, 2)
  624.     cangle = ppm_GetBoxAngle(cornerbox)
  625.     end
  626.  
  627.  
  628. call ppm_NewGroup()
  629. count = 0
  630.  
  631. if sideline1 ~= "" then do
  632.     drawstring = sideline1
  633.     call ppm_SaveText("ram:linedata",drawstring)
  634.     call ppm_SetLineWeight(sideweight1)
  635.     call ppm_SetFillPattern(sidefill1)
  636.     sidebox = ppm_DrawPoly("ram:linedata")
  637.     call ppm_AddToGroup(sidebox)
  638.     count = count+1
  639.     end
  640.  
  641. if sideline2 ~= "" then do
  642.     drawstring = sideline2
  643.     call ppm_SaveText("ram:linedata",drawstring)
  644.     call ppm_SetLineWeight(sideweight2)
  645.     call ppm_SetFillPattern(sidefill2)
  646.     sidebox = ppm_DrawPoly("ram:linedata")
  647.     call ppm_AddToGroup(sidebox)
  648.     count = count+1
  649.     end
  650.  
  651. if sideline3 ~= "" then do
  652.     drawstring = sideline3
  653.     call ppm_SaveText("ram:linedata",drawstring)
  654.     call ppm_SetLineWeight(sideweight3)
  655.     call ppm_SetFillPattern(sidefill3)
  656.     sidebox = ppm_DrawPoly("ram:linedata")
  657.     call ppm_AddToGroup(sidebox)
  658.     count = count+1
  659.     end
  660.  
  661. if count>1 then sidebox = ppm_MergeGroup()
  662.  
  663. trace n
  664. /* Place Corner Units. Setting angle before position is best for these as the basic unit is always at 0 degrees. It gives good results with boxes smaller than 2.5 mm. (Contrast BordersRepeats which has position before angle. */
  665. call ppm_NewGroup()
  666. call ppm_ShowStatus("Placing Corner Units")
  667. if cornerbox ~=0 then do
  668.     bbreadth = breadth*2
  669.     cbox = ppm_CloneBox(cornerbox, 0, 0)
  670.     call ppm_AddToGroup(cbox)
  671.     call ppm_SetBoxAngle(cbox,0)
  672.     call ppm_SetBoxSize(cbox, breadth, breadth)
  673.     call ppm_SetBoxScale(cbox, cscaleX*breadth/cXsize, cscaleY*breadth/cYsize)
  674.  
  675.     cbox2 = ppm_CloneBox(cbox, 0, 0)
  676.     call ppm_AddToGroup(cbox2)
  677.     call ppm_SetBoxAngle(cbox2, 90)
  678.     call ppm_SetBoxPosition(cbox2, mainXpos, mainYpos+mainheight +bbreadth)
  679.  
  680.     cbox3 = ppm_CloneBox(cbox, 0, 0)
  681.     call ppm_AddToGroup(cbox3)
  682.     call ppm_SetBoxAngle(cbox3, 180)
  683.     call ppm_SetBoxPosition(cbox3, mainXpos+mainwidth+bbreadth, mainYpos+mainheight+bbreadth)
  684.  
  685.     cbox4 = ppm_CloneBox(cbox, 0, 0)
  686.     call ppm_AddToGroup(cbox4)
  687.     call ppm_SetBoxAngle(cbox4, 270)
  688.     call ppm_SetBoxPosition(cbox4, mainXpos+mainwidth+bbreadth, mainYpos)
  689.  
  690.     call ppm_SetBoxAngle(cbox, cangle)
  691.     call ppm_SetBoxPosition(cbox, mainXpos, mainYpos)
  692.     end
  693.  
  694. trace n
  695.  
  696. if sidebox = 0 then exit_msg("Done")
  697.  
  698.  
  699. /* Collect original size and graphic scale of box */
  700.     if sideheight~=0 & sidewidth~=0 then call ppm_SetBoxSize(sidebox, sidewidth, sideheight)
  701.     call ppm_SetBoxOffset(sidebox,sideXoffset,sideYoffset)
  702.     scaleX = word(ppm_GetBoxScale(sidebox), 1)
  703.     scaleY = word(ppm_GetBoxScale(sidebox), 2)
  704.     width = word(ppm_GetBoxSize(sidebox), 1)
  705.     height = word(ppm_GetBoxSize(sidebox), 2)
  706.     scale1 = breadth/height
  707.     width2 = width*scale1
  708. totalwidth = width2
  709.  
  710.  
  711. heightcount = mainheight%totalwidth /* Use integer division to get number of repeats */
  712. widthcount = mainwidth%totalwidth
  713. if widthcount = 0 | heightcount = 0 then do
  714.     gone = ppm_DeleteBox(sidebox)
  715.     gone = ppm_DeleteBox(cornerbox)
  716.     gone = ppm_DeleteBox(cbox)
  717.     gone = ppm_DeleteBox(cbox2)
  718.     gone = ppm_DeleteBox(cbox3)
  719.     gone = ppm_DeleteBox(cbox4)
  720.     exit_msg("Pattern too big")
  721.     end
  722.  
  723. Xtotalwidth = mainwidth/widthcount  /* Exact width of whole pattern */
  724. Ytotalwidth = mainheight/heightcount
  725. Xscale = Xtotalwidth/totalwidth
  726. Yscale = Ytotalwidth/totalwidth
  727.  
  728.  
  729. widthX = width2*Xscale
  730. widthY = width2*Yscale 
  731.  
  732.  
  733. /* Place top units  */
  734.  
  735. call ppm_ShowStatus("Placing Top Units")
  736. leftpos = mainXpos+breadth
  737. do j=1 to widthcount
  738.     newbox = ppm_CloneBox(sidebox, 0, 0)
  739.     call ppm_AddToGroup(newbox)
  740.     call ppm_SetBoxSize(newbox, widthX, breadth)
  741.     call ppm_SetBoxPosition(newbox, leftpos, mainYpos)
  742.     call ppm_SetBoxScale(newbox, (scaleX *scale1* Xscale), (scaleY * abs(scale1)) )
  743.     call ppm_SetBoxAngle(newbox, 0)
  744.     leftpos = leftpos+widthX
  745.     end
  746.  
  747. /* Place right side units */
  748. call ppm_ShowStatus("Placing Right Side Units")
  749. toppos = mainYpos+breadth
  750. leftpos = mainXpos+word(mainsize, 1)
  751.  
  752. do j=1 to heightcount
  753.     newbox = ppm_CloneBox(sidebox, 0, 0)
  754.     call ppm_AddToGroup(newbox)
  755.     call ppm_SetBoxAngle(newbox, 270)
  756.     call ppm_SetBoxSize(newbox, widthY, breadth)
  757.     call ppm_SetBoxPosition(newbox, leftpos, toppos)
  758.     call ppm_SetBoxScale(newbox, (scaleX *scale1* Yscale), (scaleY * abs(scale1)) )
  759.     toppos = toppos+widthY
  760.     end
  761.  
  762.  
  763. /* Place bottom units  */
  764.  
  765. call ppm_ShowStatus("Placing Bottom Units")
  766. leftpos = mainXpos+breadth+mainwidth
  767. toppos = mainYpos+word(mainsize, 2)
  768.  
  769. do j=1 to widthcount
  770.     newbox = ppm_CloneBox(sidebox, 0, 0)
  771.     call ppm_AddToGroup(newbox)
  772.     call ppm_SetBoxAngle(newbox, 180)
  773.     call ppm_SetBoxSize(newbox, widthX, breadth)
  774.     call ppm_SetBoxPosition(newbox, leftpos, toppos)
  775.     call ppm_SetBoxScale(newbox, (scaleX *scale1* Xscale), (scaleY * abs(scale1)) )
  776.     leftpos = leftpos-widthX
  777.     end
  778.  
  779. /* Place left side units */
  780. call ppm_ShowStatus("Placing Left Side Units")
  781. toppos = mainYpos+breadth+mainheight
  782. leftpos = mainXpos
  783.  
  784. do j=1 to heightcount
  785.     newbox = ppm_CloneBox(sidebox, 0, 0)
  786.     call ppm_AddToGroup(newbox)
  787.     call ppm_SetBoxAngle(newbox, 90)
  788.     call ppm_SetBoxSize(newbox, widthY, breadth)
  789.     call ppm_SetBoxPosition(newbox, leftpos, toppos)
  790.     call ppm_SetBoxScale(newbox, (scaleX *scale1* Yscale), (scaleY * abs(scale1)) )
  791.     toppos = toppos-widthY
  792.     end 
  793.  
  794. /* Merge all the units into one box  */
  795. borderbox = ppm_MergeGroup()
  796. call ppm_SetBoxAngle(borderbox,mainangle)
  797.  
  798. /* resize box slightly so that thick lines are not cropped */
  799. bsize = ppm_GetBoxSize(borderbox)
  800. bwidth = word(bsize,1)
  801. bheight = word(bsize,2)
  802. call ppm_SetBoxSize(borderbox,bwidth+(maxwt*2),bheight+(maxwt*2))
  803. call ppm_SetBoxPosition(borderbox,mainXpos-maxwt,mainYpos-maxwt)
  804. call ppm_SetBoxOffset(borderbox,maxwt,maxwt)
  805.  
  806. /* Delete the pattern boxes  */
  807.  
  808.     gone = ppm_DeleteBox(cornerbox)
  809.     gone = ppm_DeleteBox(sidebox)   
  810.  
  811. /* Set an arbitrary margin in main box  */
  812. margin = breadth*1.5
  813. boxtype = upper(word(ppm_GetBoxInfo(mainbox),1))
  814. if boxtype = "TEXT" then margin = breadth*2
  815. call ppm_SetBoxMargins(mainbox, margin, margin, margin, margin)
  816. call ppm_BoxToFront(borderbox)
  817.  
  818. call ppm_NewGroup()
  819. call ppm_AddToGroup(mainbox)
  820. call ppm_AddToGroup(borderbox)
  821.  
  822. call exit_msg()
  823.  
  824. end
  825.  
  826. error:
  827. syntax:
  828.     do
  829.     exit_msg("Genie failed due to error: "errortext(rc))
  830.     end
  831.  
  832. break_d:
  833. break_e:
  834. break_c:
  835. halt:
  836. call exit_msg("Aborted by User")
  837.  
  838. exit_msg:
  839.     do
  840.     parse arg message
  841.     if message ~= "" then
  842.     call ppm_Inform(1, message,"Resume")
  843.     call ppm_ClearStatus()
  844.     call ppm_SetUnits(CurrentUnits)
  845.     call ppm_AutoUpdate(1)
  846.     exit
  847.     end
  848.  
  849.