/* 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.
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.
The original files are saved as BAK files.
Written by Don Cox Aug 95 */
/* $VER:MergeMetrics Aug 95 */
call open("STDERR","ram:traceMM","W")
trace r
signal on error
signal on syntax
address command
call SafeEndEdit.rexx()
cr="0a"x
metfile. = ""
metname. = ""
metbytes. = ""
header. = ""
body. = ""
datbytes. = ""
fullname. = ""
headersize = 20 /* seems to be fixed */
metfile.1 = ppm_GetFileName(".metric file for NORMAL", "CGFonts:",)
if metfile.1 = "" then exit_msg("Aborted by user")
metpath.1 = getpath(metfile.1)
metname.1 = getname(metfile.1)
if right(metfile.1,7)~=".metric" then exit_msg(metname.1" is not a metric file")
metfile.2 = ppm_GetFileName(".metric file for BOLD", metpath.1,)
if right(metfile.2,7)~=".metric" then metfile.2 = ""
metfile.3 = ppm_GetFileName(".metric file for ITALIC", metpath.1,)
if right(metfile.3,7)~=".metric" then metfile.3 = ""
metfile.4 = ppm_GetFileName(".metric file for BOLD-ITALIC", metpath.1,)
if right(metfile.4,7)~=".metric" then metfile.4 = ""
OK = open('metfile1',metfile.1,"R")
if OK ~=1 then exit_msg("Could not open "metfile.1)
if metbytes.1 = "" then exit_msg("Could not read "metfile.1)
if metfile.2 ~="" then do
OK = open('metfile2',metfile.2,"R")
if OK ~=1 then exit_msg("Could not open "metfile.2)
metbytes.2 = readch('metfile2',30000)
if metbytes.2 = "" then exit_msg("Could not read "metfile.2)
end
if metfile.3 ~="" then do
OK = open('metfile3',metfile.3,"R")
if OK ~=1 then exit_msg("Could not open "metfile.3)
metbytes.3 = readch('metfile3',30000)
if metbytes.3 = "" then exit_msg("Could not read "metfile.3)
end
if metfile.4 ~="" then do
OK = open('metfile4',metfile.4,"R")
if OK ~=1 then exit_msg("Could not open "metfile.4)
metbytes.4 = readch('metfile4',30000)
if metbytes.4 = "" then exit_msg("Could not read "metfile.4)
end
call close('metfile1')
if metfile.2 ~="" then call close('metfile2')
if metfile.3 ~="" then call close('metfile3')
if metfile.4 ~="" then call close('metfile4')
do i=2 to 4
metpath.i = getpath(metfile.i)
metname.i = getname(metfile.i)
end
do i=1 to 4
body.i.length = 0 /* for null files */
if metbytes.i = "" then iterate i
header.i.length = c2d(left(metbytes.i,4))
header.i = left(metbytes.i,header.i.length)
body.i = substr(metbytes.i,header.i.length+1)
body.i.length = length(body.i)
fullname.i = left(body.i,pos('00'x,body.i)-1)
if length(fullname.i)>26 then exit_msg("Name of font too long for merging")
end
do i=1 to 4
if metbytes.i = "" then iterate i
datfile.i = replace(metfile.i,".metric",".dat")
success = open('infile',datfile.i,"R")
if success = 0 then exit_msg("No .dat file for "metname.i" - font not usable")
datbytes.i = readch('infile', 30000)
call close('infile')
end
/* Put lines of .dat files into an array */
do i= 1 to 4
if datbytes.i = "" then iterate i
do j = 1 to 5 /* 5 lines in dat files */
parse var datbytes.i datline.i.j '0a'x datbytes.i
end
end
/* Rename old files as BAK */
address command
do i = 1 to 4
if metfile.i = "" then iterate i
metfile.i.2 = replace(metfile.i,"ric","BAK")
if exists(metfile.i.2) then 'delete >nil: ' '"'metfile.i.2'"'
'rename >nil:' '"'metfile.i'"' ' as ' '"'metfile.i.2'"'
datfile.i.2 = replace(datfile.i,"dat","datBAK")
if exists(datfile.i.2) then 'delete >nil: ' '"'datfile.i.2'"'
'rename >nil:' '"'datfile.i'"' ' as ' '"'datfile.i.2'"'
end
/* Construct header for new file */
newdata = d2c(headersize,4) /* this is actually the start address of the Plain (or Roman, or Book) metric file */
totallength = headersize
/* 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 ... */
do i=1 to 3
totallength = totallength + body.i.length
totallength2 = totallength
nextone = i+1
if body.nextone.length = 0 then totallength2 = 0 /* If a style is missing put a zero */
newdata = newdata || d2c(totallength2,4)
end
totallength = totallength + body.4.length
newdata = newdata || d2c(totallength,4) /* no zero option for last number */