问题
I'm trying to specifically change out text from an .EPS file that's generated by an Adobe product, like Illustrator or InDesign. For whatever reason some fonts are broken onto separate lines and moved a tiny bit. It's not a TrueType versus OpenType thing.
Here's an example, the text is "$$tag1$$":
%ADOEndSubsetFont
/ZDCMCB+NiagaraSolid-Reg /NiagaraSolid-Reg findfont ct_VMDictPut
/ZDCMCB+NiagaraSolid-Reg*1
[36{/.notdef}rp /dollar 12{/.notdef}rp /one 47{/.notdef}rp /a 5{/.notdef}rp /g
12{/.notdef}rp /t 139{/.notdef}rp]
ZDCMCB+NiagaraSolid-Reg nf
ZDCMCB+NiagaraSolid-Reg*1 [9 0 0 -9 0 0 ]msf
264.206 109.1 mo
($$t)sh
270.916 109.1 mo
(ag1$$)
[2.42188 2.51758 1.45117 2.53906 0 ]xsh
Here's an example where it doesn't break, the text is "$$tag1$$":
%ADOEndSubsetFont
/ZDCMCC+Utsaah-BoldItalic /Utsaah-BoldItalic findfont ct_VMDictPut
/ZDCMCC+Utsaah-BoldItalic*1
[36{/.notdef}rp /dollar 13{/.notdef}rp /two 46{/.notdef}rp /a 5{/.notdef}rp /g
12{/.notdef}rp /t 139{/.notdef}rp]
ZDCMCC+Utsaah-BoldItalic nf
ZDCMCC+Utsaah-BoldItalic*1 [9 0 0 -9 0 0 ]msf
264.206 118.1 mo
($$tag2$$)sh
%ADOBeginSubsetFont: Garamond-Bold Initial
%ADOt1write: (1.0.24)
We're using PHP to swap out the variables and resave the file with new values. The problem is we can't reliably determine where the text will break and if it does we can't replace it or the file will error out when trying to convert it to something like a PDF.
Any help is greatly greatly greatly appreciated!
回答1:
Postscript generated by products is normally - as is the case - not humam readable or editable.
As a fully featured Language, if one does indeed create a postscript file more or less from scratch, it ends up being much more readable than the samples above, and it is in this case, editable.
Postscript is not hard per se - since you are generating an EPS, maybe it would be easier for you to do all the text generating parts as a human-generated piece of code, instead of rely on automatically generated code as above. You will loose some typesetting niceties, since the distance between each letter pair seems to be calculated (outside of postscript) and hardcoded above. You might just want keep teh remainign of the EPS file and replace the "text core" parts - then, maiking adjusts to human readable parts as you do in a regular program in any language.
A sample rendering could be like:
%!PS-Adobe EPSF-3.0
%%BoundingBox: 0 0 800 200
(VeraSeeBd.ttf) findfont 70 scalefont setfont
10 10 moveto
(Hello World!) show
It is a lot easier to mark your text break from there. If you want something more sophisticatedand have the postscrit to take care of the line breaks itself, instead of estimating from the generator code, it is possible - but you have to code that logic into postscript itself.
来源:https://stackoverflow.com/questions/4892176/how-do-i-stop-an-eps-file-from-breaking-text-into-multiple-lines-in-postscript