home *** CD-ROM | disk | FTP | other *** search
/ DTP Toolbox / DTPToolbox.iso / propage4.0 / arexx / mergemetrics.pprx < prev    next >
Encoding:
Text File  |  1995-09-01  |  6.4 KB  |  211 lines

  1. /* This Genie merges up to four selected metric files to make a single set, so that the font will operate with the Type/styles menu item in Pro Page. The .dat files are also altered.
  2. You get four file requesters. If one of the styles does not exist, click on cancel. There has to be a Plain (or Normal, or Book, or Roman) style.
  3. The original files are saved as BAK files. 
  4. Written by Don Cox  Aug 95  */
  5. /* $VER:MergeMetrics Aug 95 */
  6.  
  7. call open("STDERR","ram:traceMM","W")
  8. trace r
  9.  
  10.  
  11. signal on error
  12. signal on syntax
  13. address command
  14. call SafeEndEdit.rexx()
  15. cr="0a"x
  16.  
  17. metfile. = ""
  18. metname. = ""
  19. metbytes. = ""
  20. header. = ""
  21. body. = ""
  22. datbytes. = ""
  23. fullname. = ""
  24.  
  25. headersize = 20 /* seems to be fixed */
  26.  
  27. metfile.1 = ppm_GetFileName(".metric file for NORMAL", "CGFonts:",)
  28. if metfile.1 = "" then exit_msg("Aborted by user")
  29. metpath.1 = getpath(metfile.1)
  30. metname.1 = getname(metfile.1)
  31. if right(metfile.1,7)~=".metric" then exit_msg(metname.1" is not a metric file")
  32. metfile.2 = ppm_GetFileName(".metric file for BOLD", metpath.1,)
  33. if right(metfile.2,7)~=".metric" then metfile.2 = ""
  34. metfile.3 = ppm_GetFileName(".metric file for ITALIC", metpath.1,)
  35. if right(metfile.3,7)~=".metric" then metfile.3 = ""
  36. metfile.4 = ppm_GetFileName(".metric file for BOLD-ITALIC", metpath.1,)
  37. if right(metfile.4,7)~=".metric" then metfile.4 = ""
  38.  
  39. OK = open('metfile1',metfile.1,"R")
  40. if OK ~=1 then exit_msg("Could not open "metfile.1)
  41. metbytes.1 = readch('metfile1',30000) /* 30000 = "plenty" */
  42. if metbytes.1 = "" then exit_msg("Could not read "metfile.1)
  43.  
  44. if metfile.2 ~="" then do
  45.     OK = open('metfile2',metfile.2,"R")
  46.     if OK ~=1 then exit_msg("Could not open "metfile.2)
  47.     metbytes.2 = readch('metfile2',30000)
  48.     if metbytes.2 = "" then exit_msg("Could not read "metfile.2)
  49.     end
  50.  
  51. if metfile.3 ~="" then do
  52.     OK = open('metfile3',metfile.3,"R")
  53.     if OK ~=1 then exit_msg("Could not open "metfile.3)
  54.     metbytes.3 = readch('metfile3',30000)
  55.     if metbytes.3 = "" then exit_msg("Could not read "metfile.3)
  56.     end
  57.  
  58. if metfile.4 ~="" then do
  59.     OK = open('metfile4',metfile.4,"R")
  60.     if OK ~=1 then exit_msg("Could not open "metfile.4)
  61.     metbytes.4 = readch('metfile4',30000)
  62.     if metbytes.4 = "" then exit_msg("Could not read "metfile.4)
  63.     end
  64.  
  65. call close('metfile1')
  66. if metfile.2 ~="" then call close('metfile2')
  67. if metfile.3 ~="" then call close('metfile3')
  68. if metfile.4 ~="" then call close('metfile4')
  69.  
  70. do i=2 to 4
  71.     metpath.i = getpath(metfile.i)
  72.     metname.i = getname(metfile.i)
  73.     end
  74.  
  75. do i=1 to 4
  76.     body.i.length = 0 /* for null files */
  77.     if metbytes.i = "" then iterate i
  78.     header.i.length = c2d(left(metbytes.i,4))
  79.     header.i = left(metbytes.i,header.i.length)
  80.     body.i = substr(metbytes.i,header.i.length+1)
  81.     body.i.length = length(body.i)
  82.     fullname.i = left(body.i,pos('00'x,body.i)-1)
  83.     if length(fullname.i)>26 then exit_msg("Name of font too long for merging")
  84.     end
  85.  
  86. do i=1 to 4
  87.     if metbytes.i = "" then iterate i
  88.     datfile.i = replace(metfile.i,".metric",".dat")
  89.     success = open('infile',datfile.i,"R")
  90.     if success = 0 then exit_msg("No .dat file for "metname.i" - font not usable")
  91.     datbytes.i = readch('infile', 30000)
  92.     call close('infile')
  93.     end
  94.  
  95. /* Put lines of .dat files into an array */
  96. do i= 1 to 4
  97.     if datbytes.i = "" then iterate i
  98.     do j = 1 to 5 /* 5 lines in dat files */
  99.         parse var datbytes.i datline.i.j '0a'x datbytes.i
  100.         end
  101.     end
  102.  
  103. /* Rename old files as BAK */
  104. address command
  105. do i = 1 to 4
  106.     if metfile.i = "" then iterate i
  107.     metfile.i.2 = replace(metfile.i,"ric","BAK")
  108.     if exists(metfile.i.2) then 'delete >nil: ' '"'metfile.i.2'"'
  109.     'rename >nil:'  '"'metfile.i'"' ' as ' '"'metfile.i.2'"'
  110.     datfile.i.2 = replace(datfile.i,"dat","datBAK")
  111.     if exists(datfile.i.2) then 'delete >nil: ' '"'datfile.i.2'"'
  112.     'rename >nil:' '"'datfile.i'"' ' as ' '"'datfile.i.2'"'
  113.     end
  114.  
  115.  
  116. /* Construct header for new file */
  117. newdata = d2c(headersize,4) /* this is actually the start address of the Plain (or Roman, or Book) metric file */
  118. totallength = headersize
  119.  
  120. /* The first number after the header-length number (which is the starting address of the first style) is the start of the second style; the second number is the start of the third style ... */
  121. do i=1 to 3
  122.     totallength = totallength + body.i.length
  123.     totallength2 = totallength
  124.     nextone = i+1
  125.     if body.nextone.length = 0 then totallength2 = 0 /* If a style is missing put a zero */
  126.     newdata = newdata || d2c(totallength2,4)
  127.     end
  128. totallength = totallength + body.4.length
  129. newdata = newdata || d2c(totallength,4) /* no zero option for last number */
  130.  
  131. /* Assemble new file */
  132. do i=1 to 4
  133.     newdata = newdata||body.i
  134.     end
  135. newmetfile = metfile.1
  136. call open('metoutput',newmetfile, "W")
  137. call writech('metoutput',newdata)
  138. newmetname = getname(newmetfile)
  139. newmetname = replace(newmetname,".metric","")
  140.  
  141. /* Edit & save .dat files */
  142. newdat. = ""
  143. do i = 1 to 4
  144.     newdat.i = datline.i.1 || cr || datline.i.2 || cr || datline.i.3 || cr || datline.i.4 || cr || newmetname" "i-1
  145.     newdatfile.i = metpath.i ||fullname.i || ".dat"
  146.     call open('datout', newdatfile.i, "W")
  147.     call writech('datout',newdat.i)
  148.     call close('datout')
  149.     end
  150.  
  151.  
  152. call exit_msg("Quit Pro Page and run CGUpdate before using fonts")
  153. end
  154.  
  155. error:
  156. syntax:
  157.     do
  158.     exit_msg("Genie failed due to error: "errortext(rc))
  159.     end
  160.  
  161. exit_msg:
  162.     do
  163.     parse arg message
  164.     if message ~= "" then
  165.     call ppm_Inform(1,message)
  166.     call ppm_AutoUpdate(1)
  167.     exit
  168.     end
  169.  
  170.  
  171. /* ++++++++++++++++++++++++++++  ++++++++++++++++++++++++++++++++++ */
  172.  
  173. /* Find and replace, not case-sensitive */
  174. replace: procedure
  175. parse arg text, removed, replaced
  176. if text = "" then return text
  177.  
  178. remlength = length(removed)
  179. replength = length(replaced)
  180. textlength = length(text)
  181. removed2 = upper(removed)
  182. text2 = upper(text)
  183.  
  184. do until textlength = 0
  185.     textlength = lastpos(removed2,text2,textlength)
  186.     if textlength ~= 0 then do
  187.         text = insert(replaced,delstr(text, textlength, remlength), textlength-1)
  188.         textlength = textlength -1
  189.         end
  190.     end
  191. return text
  192.  
  193.  
  194. /* ++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++ */
  195.  
  196.  
  197. getpath:
  198. parse arg allname
  199. pos1 = lastpos("/",allname)
  200. if pos1 = 0 then pos1 = lastpos(":",allname)
  201. filepath = left(allname,pos1)
  202. return filepath
  203.  
  204. getname:
  205. parse arg allname
  206. pos1 = lastpos("/",allname)
  207. if pos1 = 0 then pos1 = lastpos(":",allname)
  208. justname = substr(allname,pos1+1)
  209. return justname 
  210.  
  211. /* +++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++ */