Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #630 > unrolled thread

Embedding a subset of Type 1 fonts in EPS

Started byKesh <tikuma@gmail.com>
First post2012-03-18 13:39 -0700
Last post2012-03-25 13:37 -0400
Articles 11 — 3 participants

Back to article view | Back to comp.lang.postscript


Contents

  Embedding a subset of Type 1 fonts in EPS Kesh <tikuma@gmail.com> - 2012-03-18 13:39 -0700
    Re: Embedding a subset of Type 1 fonts in EPS ken <ken@spamcop.net> - 2012-03-19 08:04 +0000
      Re: Embedding a subset of Type 1 fonts in EPS Kesh <tikuma@gmail.com> - 2012-03-19 07:00 -0700
        Re: Embedding a subset of Type 1 fonts in EPS ken <ken@spamcop.net> - 2012-03-19 17:34 +0000
          Re: Embedding a subset of Type 1 fonts in EPS Kesh <tikuma@gmail.com> - 2012-03-19 19:40 -0700
            Re: Embedding a subset of Type 1 fonts in EPS ken <ken@spamcop.net> - 2012-03-20 09:41 +0000
              Re: Embedding a subset of Type 1 fonts in EPS Kesh <tikuma@gmail.com> - 2012-03-20 06:12 -0700
    Re: Embedding a subset of Type 1 fonts in EPS Kesh <tikuma@gmail.com> - 2012-03-24 14:51 -0700
      Re: Embedding a subset of Type 1 fonts in EPS tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2012-03-24 20:45 -0400
        Re: Embedding a subset of Type 1 fonts in EPS ken <ken@spamcop.net> - 2012-03-25 12:50 +0100
          Re: Embedding a subset of Type 1 fonts in EPS tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2012-03-25 13:37 -0400

#630 — Embedding a subset of Type 1 fonts in EPS

FromKesh <tikuma@gmail.com>
Date2012-03-18 13:39 -0700
SubjectEmbedding a subset of Type 1 fonts in EPS
Message-ID<c8840951-0de8-4932-8b1b-48958a45c676@w5g2000yqi.googlegroups.com>
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

[toc] | [next] | [standalone]


#631

Fromken <ken@spamcop.net>
Date2012-03-19 08:04 +0000
Message-ID<MPG.29d0f8f3984b7d798987f@usenet.plus.net>
In reply to#630
In article <c8840951-0de8-4932-8b1b-48958a45c676
@w5g2000yqi.googlegroups.com>, tikuma@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

[toc] | [prev] | [next] | [standalone]


#632

FromKesh <tikuma@gmail.com>
Date2012-03-19 07:00 -0700
Message-ID<876c6837-b52a-4b9e-b92b-37132adc6573@h12g2000yqi.googlegroups.com>
In reply to#631
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

[toc] | [prev] | [next] | [standalone]


#634

Fromken <ken@spamcop.net>
Date2012-03-19 17:34 +0000
Message-ID<MPG.29d17e8e99d96fb7989880@usenet.plus.net>
In reply to#632
In article <876c6837-b52a-4b9e-b92b-37132adc6573
@h12g2000yqi.googlegroups.com>, tikuma@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

[toc] | [prev] | [next] | [standalone]


#635

FromKesh <tikuma@gmail.com>
Date2012-03-19 19:40 -0700
Message-ID<33319794.3735.1332211247556.JavaMail.geo-discussion-forums@vbbfy7>
In reply to#634
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

[toc] | [prev] | [next] | [standalone]


#637

Fromken <ken@spamcop.net>
Date2012-03-20 09:41 +0000
Message-ID<MPG.29d2611812499c0f989881@usenet.plus.net>
In reply to#635
In article <33319794.3735.1332211247556.JavaMail.geo-discussion-
forums@vbbfy7>, tikuma@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

[toc] | [prev] | [next] | [standalone]


#638

FromKesh <tikuma@gmail.com>
Date2012-03-20 06:12 -0700
Message-ID<1236021.659.1332249168823.JavaMail.geo-discussion-forums@ynmb12>
In reply to#637
> > /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ÛTq4ëÛ-.8<¼ ND

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

end

[toc] | [prev] | [next] | [standalone]


#639

FromKesh <tikuma@gmail.com>
Date2012-03-24 14:51 -0700
Message-ID<9549190.169.1332625878922.JavaMail.geo-discussion-forums@yncd8>
In reply to#630
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!!

[toc] | [prev] | [next] | [standalone]


#640

Fromtlvp <mPiOsUcB.EtLlLvEp@att.net>
Date2012-03-24 20:45 -0400
Message-ID<b6cptbk1jttp$.11ojbxd4kujzr.dlg@40tude.net>
In reply to#639
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.

[toc] | [prev] | [next] | [standalone]


#641

Fromken <ken@spamcop.net>
Date2012-03-25 12:50 +0100
Message-ID<MPG.29d916e7271f732989882@usenet.plus.net>
In reply to#640
In article <b6cptbk1jttp$.11ojbxd4kujzr.dlg@40tude.net>, 
mPiOsUcB.EtLlLvEp@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

[toc] | [prev] | [next] | [standalone]


#642

Fromtlvp <mPiOsUcB.EtLlLvEp@att.net>
Date2012-03-25 13:37 -0400
Message-ID<1r1ayafu575d7$.dwr6kvv2hrg7$.dlg@40tude.net>
In reply to#641
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.postscript


csiph-web