home *** CD-ROM | disk | FTP | other *** search
/ DTP Toolbox / DTPToolbox.iso / propage4.0 / arexx / autopages.pprx < prev    next >
Encoding:
Text File  |  1995-07-23  |  10.0 KB  |  307 lines

  1. /* This Genie will make the necessary number of new pages to accommodate an article which is currently overflowing its box. It is intended for use with simple essays and the like, not complex layouts. I have set the genie to underflow rather than overflow.
  2. Written by Don Cox   July 93  Revised Feb 94, Nov 94. Not Public Domain. All rights reserved. */
  3.  
  4. /* $VER: AutoPages July 95 */
  5.  
  6. /* call open("STDERR","ram:traceAP","W")
  7. trace r */ 
  8.  
  9. signal on error
  10. signal on syntax
  11. address command
  12.  
  13. call SafeEndEdit.rexx()
  14. call ppm_AutoUpdate(0)
  15. fsize = ppm_GetSize()
  16. cr="0a"x
  17. currentunits=ppm_GetUnits()
  18. call ppm_SetUnits(2)
  19.  
  20. changetext = 0
  21. resize = ppm_Inform(2, "Make type 17% larger?", "Yes", "No")
  22. doparas = ppm_Inform(3, "Set paragraph indent?", "Essays", "Scripts", "No change")
  23. if doparas =0 | doparas = 1 | resize = 0 then changetext = 1
  24. paraspace = 150  /* per cent of line spacing */
  25.  
  26. cpage = ppm_CurrentPage()
  27. psize = ppm_GetPageSize(cpage)
  28. pagewidth = word(psize,1)
  29. pageheight = word(psize,2)
  30. numberleft = pagewidth-6 /* position of page number box */
  31. numbertop = pageheight-2
  32.  
  33. numberbox = 0
  34. pagebox = 0 /* Is there a page number box already? */
  35. testbox = ppm_PageFirstBox(cpage)
  36. do until testbox=0
  37.     boxtxt = ppm_GetBoxText(testbox,1)
  38.     if (words(boxtxt)=2 & pos("Page \#<Pc0>",boxtxt)~=0) then pagebox = 1
  39.     if pagebox = 1 then numberbox = testbox
  40.     if pagebox = 1 then break
  41.     testbox = ppm_PageNextBox(testbox)
  42.     end
  43.  
  44. if pagebox = 0 then do
  45.     numberbox = ppm_CreateBox(numberleft, numbertop,3,1,0,)
  46.     call ppm_SetSize(12)
  47.     overflow = ppm_TextIntoBox(numberbox,"\jl\fs<12.000>Page \#<Pc0>")
  48.     end
  49.  
  50. box=ppm_ClickOnBox("Click on box containing article")
  51. if box=0 then exit_msg("No box selected")
  52. call ppm_SelectBox(box)
  53.  
  54.  
  55. call ppm_ShowStatus("  Fitting text...")
  56.     
  57. boxtype = upper(word(ppm_GetBoxInfo(box), 1))
  58. if boxtype~="TEXT" then exit_msg("Not a text box")
  59. howbig = ppm_GetBoxSize(box)
  60. boxwidth = word(howbig,1)
  61. boxheight = word(howbig,2)
  62. where = ppm_GetBoxPosition(box)
  63. boxX = word(where,1)
  64. boxY = word(where,2)
  65. tilt = ppm_GetBoxAngle(box)
  66. thispage = ppm_DocLastPage()
  67. lastbox = ppm_ArtLastBox(box)
  68. firstbox = ppm_ArtFirstBox(box)
  69.  
  70.  
  71. factor = 1.17   /* Type 17% larger - 12pt goes to 14pt */
  72. if changetext = 1 then do
  73.     text = ppm_GetArticleText(firstbox,1)
  74.     text = ResizeFonts(text,factor)
  75.     gone = ppm_DeleteContents(firstbox) /* Removes entire article */
  76.     overflow = ppm_TextIntoBox(firstbox,text)
  77.     end
  78.  
  79. do 150  /* 150 pages is enough for most purposes - you can always run the genie again */
  80.     call ppm_ShowStatus("  Fitting text... " )
  81. /* Create a new page without adding a blank page at end of document */
  82.     newpage = ppm_CreatePage(thispage,1,1,0,0)
  83.     newpage = ppm_MovePage(newpage+1,newpage)
  84.     thispage = ppm_GoToPage(newpage+1)
  85.  
  86.     newbox = ppm_CreateBox(boxX, boxY, boxwidth, boxheight, tilt, )
  87.     call ppm_BoxChangePage(newbox,thispage)
  88.     overflow = ppm_LinkBox(lastbox,newbox)
  89.  
  90.     pagebox = 0 /* Is there a page number box already? */
  91.     testbox = ppm_PageFirstBox(thispage)
  92.     do until testbox=0
  93.         boxtxt = ppm_GetBoxText(testbox,1)
  94.         if (words(boxtxt)=2 & pos("Page \#<Pc0>",boxtxt)~=0) then pagebox = 1
  95.         if pagebox = 1 then break
  96.         testbox = ppm_PageNextBox(testbox)
  97.         end
  98.  
  99.     if pagebox = 0 then do
  100.         numberbox = ppm_CloneBox(numberbox,0,0)
  101.         call ppm_BoxChangePage(numberbox,thispage)
  102.         end
  103.     lastbox = newbox
  104.     if newtext="" | overflow = 0  then break 
  105.  
  106.     end
  107.  
  108. newpage = ppm_GoToPage(cpage)
  109. call ppm_SetUnits(currentunits)
  110.  
  111. call exit_msg()
  112. end
  113.  
  114.  
  115. /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
  116.  
  117. error:
  118. syntax:
  119.     do
  120.     exit_msg("Genie failed due to error: "errortext(rc))
  121.     end
  122.  
  123. exit_msg:
  124.     do
  125.     parse arg message
  126.     if message ~= "" then
  127.     call ppm_Inform(1,message,"Resume")
  128.     call ppm_ClearStatus()
  129.     call ppm_AutoUpdate(1)
  130.     exit
  131.     end
  132.  
  133. /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
  134.  
  135. ResizeFonts: 
  136. parse arg text, factor
  137. position = 1
  138. position2 = 1
  139.  
  140. do forever  /* we have to open up style tags to get sizes */
  141.     position = pos("\dS<",text,position2)
  142.     if position = 0 then break
  143.     position2 = pos(">",text,position)
  144.     if position2 = 0 then break
  145.     styletag = substr(text,position+4, position2-position-4)
  146.     styledef = ppm_GetStyleTagData(styletag)
  147.     styledef = left(styledef,pos("}",styledef)-1) /* remove name of tag */
  148.     styledef = substr(styledef,pos("{",styledef)+1)
  149.     text = delstr(text,position, (position2-position+1)) /* delete tag name */
  150.     text = insert("\ds"styledef,text,(position-1))
  151.     end
  152.  
  153. if resize = 0 then do
  154.     position2 = 1
  155.     do forever  /* first change font sizes */
  156.         position = pos("\fs<",text,position2)+4
  157.         if position = 4 then break  /* would be 0 but we added 4 */
  158.         position2 = pos(">",text,position)
  159.         if position2 = 0 then break
  160.         oldsize = substr(text,position, position2-position)
  161.         text = delstr(text,position, position2-position) /* delete old size */
  162.         newsize = oldsize*factor
  163.         if newsize>720 then newsize = 720
  164.         oddsize = newsize//0.125  /* round correctly to nearest 1/8 point - PPage always rounds down */
  165.         if oddsize>0.0625 then newsize = newsize-oddsize+0.125
  166.         else newsize = newsize-oddsize
  167.         text = insert(newsize,text,position-1)
  168.         end
  169.  
  170.  
  171.     position2 = 1
  172.     do forever  /*  now do fixed line spacings  */
  173.         position = pos("\lf<",text,position2)+4
  174.         if position = 4 then break  /* would be 0 but we added 4 */
  175.         position2 = pos(">",text,position)
  176.         if position2 = 0 then break
  177.         oldsize = substr(text,position, position2-position)
  178.         text = delstr(text,position, position2-position) /* delete old size */
  179.         newsize = oldsize*factor
  180.         if newsize>720 then newsize = 720
  181.         oddsize = newsize//0.125  /* round correctly to nearest 1/8 point - PPage always rounds down */
  182.         if oddsize>0.0625 then newsize = newsize-oddsize+0.125
  183.         else newsize = newsize-oddsize
  184.         text = insert(newsize,text,position-1)
  185.         end
  186.  
  187.     position2 = 1
  188.     do forever   /* and fixed leading  */
  189.         position = pos("\ll<",text,position2)+4
  190.         if position = 4 then break  /* would be 0 but we added 4 */
  191.         position2 = pos(">",text,position)
  192.         if position2 = 0 then break
  193.         oldsize = substr(text,position, position2-position)
  194.         text = delstr(text,position, position2-position) /* delete old size */
  195.         newsize = oldsize*factor
  196.         if newsize>720 then newsize = 720
  197.         oddsize = newsize//0.125  /* round correctly to nearest 1/8 point - PPage always rounds down */
  198.         if oddsize>0.0625 then newsize = newsize-oddsize+0.125
  199.         else newsize = newsize-oddsize
  200.         text = insert(newsize,text,position-1)
  201.         end
  202.     end  /* of resizing text */
  203.  
  204.  
  205. if doparas = 0 then do /* essay style */
  206.     IndentCode = "i"
  207.  
  208.     position2 = 1
  209.     do forever  /* paragraph spacing */
  210.         position = pos("\ps<",text,position2)+4
  211.         if position = 4 then break  /* would be 0 but we added 4 */
  212.         position2 = pos(">",text,position)
  213.         if position2 = 0 then break
  214.         oldsize = substr(text,position, position2-position)
  215.         text = delstr(text,position, position2-position) /* delete old size */
  216.         text = insert(paraspace,text,position-1)
  217.         end
  218.  
  219.     position2 = 1
  220.     do forever  /* now paragraph indent amount */
  221.         position = pos("\pv<",text,position2)
  222.         if position = 0 then break
  223.         position = position+7
  224.         position2 = pos(">",text,position)
  225.         if position2 = 0 then break
  226.         oldsize = substr(text,position, position2-position)
  227.         text = delstr(text,position, position2-position) /* delete old size */
  228.         newsize = 0.2
  229.         text = insert(newsize,text,position-1)
  230.         end
  231.  
  232.     position2 = 1
  233.     do forever  /* paragraph indent type */
  234.         position = pos("\po",text,position2)
  235.         if position = 0 then break
  236.         position = position+2
  237.         text = delstr(text,position, 1) /* delete old code */
  238.         text = insert(IndentCode,text,position-1)
  239.         end
  240.  
  241.     position2 = 1
  242.     do forever  /* paragraph indent type */
  243.         position = pos("\pn",text,position2)
  244.         if position = 0 then break
  245.         position = position+2
  246.         text = delstr(text,position, 1) /* delete old code */
  247.         text = insert(IndentCode,text,position-1)
  248.         end
  249.  
  250.  
  251.     end
  252.  
  253.  
  254. if doparas = 1 then do  /* script style */
  255.     IndentCode = "o"
  256.     
  257.     position2 = 1
  258.     do forever  /* paragraph spacing */
  259.         position = pos("\ps<",text,position2)+4
  260.         if position = 4 then break  /* would be 0 but we added 4 */
  261.         position2 = pos(">",text,position)
  262.         if position2 = 0 then break
  263.         oldsize = substr(text,position, position2-position)
  264.         text = delstr(text,position, position2-position) /* delete old size */
  265.         text = insert(paraspace,text,position-1)
  266.         end
  267.  
  268.     position2 = 1
  269.     do forever  /* now paragraph indent amount */
  270.         position = pos("\pv<",text,position2)
  271.         if position = 0 then break
  272.         position = position+7
  273.         position2 = pos(">",text,position)
  274.         if position2 = 0 then break
  275.         oldsize = substr(text,position, position2-position)
  276.         text = delstr(text,position, position2-position) /* delete old size */
  277.         newsize = 0.5
  278.         text = insert(newsize,text,position-1)
  279.         end
  280.  
  281.     position2 = 1
  282.     do forever  /* now paragraph indent type */
  283.         position = pos("\pi",text,position2)
  284.         if position = 0 then break
  285.         position = position+2
  286.         text = delstr(text,position, 1) /* delete old code */
  287.         text = insert(IndentCode,text,position-1)
  288.         end
  289.  
  290.     position2 = 1
  291.     do forever  /* now paragraph indent type */
  292.         position = pos("\pn",text,position2)
  293.         if position = 0 then break
  294.         position = position+2
  295.         text = delstr(text,position, 1) /* delete old code */
  296.         text = insert(IndentCode,text,position-1)
  297.         end
  298.  
  299.  
  300.     end
  301.  
  302.  
  303.  
  304. return text
  305.  
  306.  
  307. /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */