Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Embedding a subset of Type 1 fonts in EPS

47 views
Skip to first unread message

Kesh

unread,
Mar 18, 2012, 4:39:36 PM3/18/12
to
Hi,

I've been trying to embed a minimal subset of Type 1 font in an EPS
file but so far without success. If anybody here can right my ship,
I'd be greatly appreciated.

Upon studying the PLRM and Type1 font spec documents from Adobe, I've
implemented the following:

1. Read in PFB file and decrypt eexec coded /Private dict
2. Remove CharString dict entries that are not used in the EPS figure
3. Adjust encoding so that all undefined characters point to /.notdef
4. Re-encrypt modified /Private dict
5. Convert the binary section to hex (ASCII) format
6. Replace the fullset font dict in the EPS file with the created
reduced set dict
7. Open it in Ghostscript... -> errors out (with code -101, which is a
generic error code)

Am I missing something?

Thanks,
Kesh

ken

unread,
Mar 19, 2012, 4:04:35 AM3/19/12
to
In article <c8840951-0de8-4932-8b1b-48958a45c676
@w5g2000yqi.googlegroups.com>, tik...@gmail.com says...

> Upon studying the PLRM and Type1 font spec documents from Adobe, I've
> implemented the following:
>
> 1. Read in PFB file and decrypt eexec coded /Private dict
> 2. Remove CharString dict entries that are not used in the EPS figure

What about Subrs and OtherSubrs, have you checked for SEAC glyphs ?

> 3. Adjust encoding so that all undefined characters point to /.notdef
> 4. Re-encrypt modified /Private dict

Actually you don't *have* to eexec encrypt fonts, its done for historic
reasons.

> 5. Convert the binary section to hex (ASCII) format
> 6. Replace the fullset font dict in the EPS file with the created
> reduced set dict
> 7. Open it in Ghostscript... -> errors out (with code -101, which is a
> generic error code)
>
> Am I missing something?

To be honest, without seeing the font, and the usage, its not possible
to tell, you may be. If you'd like to post an example somewhere public
I'd be happy to look at it. (I can also debug Ghostscript and find out
what its complaining about).


Ken

Kesh

unread,
Mar 19, 2012, 10:00:22 AM3/19/12
to
Ken,

Thanks for the reply.

> > 2. Remove CharString dict entries that are not used in the EPS figure
>
> What about Subrs and OtherSubrs, have you checked for SEAC glyphs ?

Both Subrs and OtherSubrs (and all other dict entries not named
Encoding and CharString) were untouched. As far as I know, there
aren't any SEAC glyphs (my test EPS image consists of digits, period,
\alpha, \beta, \in, \Omega)

> > 4. Re-encrypt modified /Private dict
>
> Actually you don't *have* to eexec encrypt fonts, its done for historic
> reasons.

This might make debugging a bit easier. What do I need to do to remove
the encryption?

Would simply removing "currentfile eexec" and "mark currentfile
closefile 0000...000 cleartomark" do the trick?

Can I also remove CharString encryption or do they need to stay?

> > Am I missing something?
>
> To be honest, without seeing the font, and the usage, its not possible
> to tell, you may be. If you'd like to post an example somewhere public
> I'd be happy to look at it. (I can also debug Ghostscript and find out
> what its complaining about).

That would be great! I'll try to post unencrypted subset dict that I
created later.

Kesh

ken

unread,
Mar 19, 2012, 1:34:54 PM3/19/12
to
In article <876c6837-b52a-4b9e-b92b-37132adc6573
@h12g2000yqi.googlegroups.com>, tik...@gmail.com says...

> > > 4. Re-encrypt modified /Private dict
> >
> > Actually you don't *have* to eexec encrypt fonts, its done for historic
> > reasons.
>
> This might make debugging a bit easier. What do I need to do to remove
> the encryption?
>
> Would simply removing "currentfile eexec" and "mark currentfile
> closefile 0000...000 cleartomark" do the trick?

currentfile exec rather than 'eexec' you have to leave the closefile
etc.


> Can I also remove CharString encryption or do they need to stay?

You can remove that too yes.


> That would be great! I'll try to post unencrypted subset dict that I
> created later.

OK it may be a day or so before I can look at it.


Ken

Kesh

unread,
Mar 19, 2012, 10:40:47 PM3/19/12
to
Ken,

Alright, I've uploaded a few files to my Google Doc in public sharing mode. The font being subsetted is AMS CMMI10 font for greek alpha & beta characters. (Yes, it is an (infamous?) MATLAB generated EPS with some tweaking.)

EPS file with fully embed font (which opens properly in Ghostscript):
https://docs.google.com/open?id=0B3YjzIrad6oPQ0JQYzgxUzRRUi1GWm5DRzVlQVl1dw

Here's the PNG image (generated by Ghostscript)
https://docs.google.com/open?id=0B3YjzIrad6oPbWRnUlZ1cHhSeE9CUnhqQk96R1JCQQ

Then, the problematic, EPS with subsetted font
https://docs.google.com/open?id=0B3YjzIrad6oPcXlzMC05MXhTREdydExBcUo1RVdzZw

So far I have even failed to embed unencrypted (full-set) font, successfully. So, I just pasted the unencrypted Private dict of the subsetted font below (Binary CharStrings are omitted (shown as '---'). Thank you so much for looking into this. And please take your time. This is my pastime project.

currentfile exec
dup/Private 15 dict dup begin
/RD{string currentfile exch readstring pop}executeonly def
/ND{noaccess def}executeonly def
/NP{noaccess put}executeonly def
/BlueValues [-22 0 683 705 431 442 453 466] def
/OtherBlues [-205 -194] def
/StdHW [31] def
/StdVW [72] def
/StemSnapH [25 31] def
/BlueScale 0.04379 def
/ForceBold false def
/MinFeature{16 16}def
/password 5839 def
/UniqueID 5087385 def
/OtherSubrs[
{}{}{}
{systemdict/internaldict known not
{pop 3}
{1183615869 systemdict/internaldict get exec
dup/startlock known
{/startlock get exec}
{dup/strtlck known
{/strtlck get exec}
{pop 3}
ifelse}
ifelse}
ifelse
}executeonly
]ND
/Subrs 6 array
dup 0 15 RD --- NP
dup 1 9 RD --- NP
dup 2 9 RD --- NP
dup 3 5 RD --- NP
dup 4 12 RD --- NP
dup 5 20 RD --- NP
ND
2 index /CharStrings 3 dict dup begin
/alpha 177 RD --- ND
/beta 242 RD --- ND
/.notdef 12 RD --- ND
end
end
readonly put
noaccess put
dup/FontName get exch definefont pop

ken

unread,
Mar 20, 2012, 5:41:28 AM3/20/12
to
In article <33319794.3735.1332211247556.JavaMail.geo-discussion-
forums@vbbfy7>, tik...@gmail.com says...

> Alright, I've uploaded a few files to my Google Doc in public sharing
mode. The font being subsetted is AMS CMMI10 font for greek alpha & beta
characters. (Yes, it is an (infamous?) MATLAB generated EPS with some
tweaking.)

> /alpha 177 RD --- ND
> /beta 242 RD --- ND

This seems to be the problem, at least in part. The '242' is placed on
the stack as an argument to the ND routine defined earlier. This routine
consumes 'argument' bytes and converts them into a PostScript string.
The argument here is 242, but there are 244 bytes of binary data between
the RD and ND (ignoring the two spaces).

If I alter the argument from 242 to 244 then the file runs to
completion.

BTW if you just decrypt (eexec decrypt) the encrypted portion, put it in
pace of the hex data and remove the 'currentfile eexec' then you shuld
have a decrypted font embedded, it works OK for me here.

I don't actually get any output though, so there may still be a problem.


Ken

Kesh

unread,
Mar 20, 2012, 9:12:48 AM3/20/12
to k...@spamcop.net
> > /beta 242 RD --- ND
>
> This seems to be the problem, at least in part.
> The argument here is 242, but there are 244 bytes of binary data between
> the RD and ND (ignoring the two spaces).
>
> If I alter the argument from 242 to 244 then the file runs to
> completion.

That's strange. I just checked my file and I only count 242 binary bytes for the /beta glyph.

> BTW if you just decrypt (eexec decrypt) the encrypted portion, put it in
> pace of the hex data and remove the 'currentfile eexec' then you shuld
> have a decrypted font embedded, it works OK for me here.

Tried this just now and still errors out in my win32 Ghostscript 9.05. It says there's a syntax error (see the copy of the error dump below).

Error: /syntaxerror in -file-
Operand stack:
--dict:8/11(L)-- --dict:8/11(L)-- Private --dict:15/15(L)-- --dict:8/11(L)-- CharStrings --dict:1/3(L)-- beta (0\356\034Q\364\362\261\026\035\032\032I.-N\032\032\\\357\336\032\315\273y\246s\3418\r\n\335'xGG\366\303\250\343\r\n+|\245\034\275\r\nP>\274\344\362\b\032q,n\304\032Z\314\304?\342\311\177\032\032\032\312\313\317?\273`\315\2711T\025\263\347\032\300\032\017\336\032\006S+\374I\326\036\274\250l\(\240\(\332\312?'D\265Y\032\034\322\326\250gG\032\341\177\372\360h2?\013\346\344gbr\032\242\032n*R\340\b\312\260\312\272\37431\267\265\242\031\333c\2466p\r\nI\013\310c\265\002.cP\334\032}\377\250\032\242\020\372\253\b\255\343\343>\327l'\364\250\253\260\013\337\260z>\342=\032uz\037ya...) 8
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- false 1 %stopped_push 1926 1 3 %oparray_pop 1925 1 3 %oparray_pop 1909 1 3 %oparray_pop 1803 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push
Dictionary stack:
--dict:1176/1684(ro)(G)-- --dict:0/20(G)-- --dict:82/200(L)-- --dict:15/15(L)-- --dict:1/3(L)--
Current allocation mode is local
Last OS error: No such file or directory

--- Begin offending input ---
il ÛTq 4 ë Û -. 8< ¼ ND

/.notdef 12 RD uCI ¥|o ^ & ND

end

Kesh

unread,
Mar 24, 2012, 5:51:18 PM3/24/12
to
Just in case anybody else is encountering a similar problem and bump into this thread, the following was the solution to my problem:

The eexec encrypted section of Type-1 font dictionary is always(?) terminated by "mark currentfile closefile". So, when I re-encrypted my subsetted font dictionary, I re-encrypted up to "mark currentfile closefile".

This turned out was the problem. PS interpreter cannot parse "closefile" as the "closefile" operator until it sees a trailing white space, which also needs to be encrypted. So, instead, the encrypted section must be terminated by "mark currentfile closefile " with the trailing white space character.

Much thanks go to Ken helping me out on debugging the issue off the newsgroup!!

tlvp

unread,
Mar 24, 2012, 8:45:50 PM3/24/12
to
On Sat, 24 Mar 2012 14:51:18 -0700 (PDT), Kesh wrote:

> This turned out was the problem. PS interpreter cannot parse "closefile" as the "closefile" operator until it sees a trailing white space, which also needs to be encrypted. So, instead, the encrypted section must be terminated by "mark currentfile closefile " with the trailing white space character.

And as "whitespace" character, will anything within reason do? A [space], a
[tab], a [newline], a U+0A, a U+0D? Or only a select few of these?

TIA. Cheers, -- tlvp
--
Avant de repondre, jeter la poubelle, SVP.

ken

unread,
Mar 25, 2012, 7:50:40 AM3/25/12
to
In article <b6cptbk1jttp$.11ojbxd4...@40tude.net>,
mPiOsUcB...@att.net says...
>
> On Sat, 24 Mar 2012 14:51:18 -0700 (PDT), Kesh wrote:
>
> > This turned out was the problem. PS interpreter cannot parse "closefile" as the "closefile" operator until it sees a trailing white space, which also needs to be encrypted. So, instead, the encrypted section must be terminated by "mark currentfile closefile " with the trailing white space character.
>
> And as "whitespace" character, will anything within reason do? A [space], a
> [tab], a [newline], a U+0A, a U+0D? Or only a select few of these?

The definition of white space is contained in the PLRM, but basically,
yes; space, return, linefeed or tab.


Ken

tlvp

unread,
Mar 25, 2012, 1:37:09 PM3/25/12
to
On Sun, 25 Mar 2012 12:50:40 +0100, ken wrote:

> The definition of white space is contained in the PLRM, but basically,
> yes; space, return, linefeed or tab.

Many thanks, ken. Cheers,
--
Avant de repondre, jeter la poubelle, SVP. -- tlvp
0 new messages