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

Named Resources

79 views
Skip to first unread message

luser- -droog

unread,
Sep 24, 2013, 6:19:43 PM9/24/13
to
I've spent the last few weeks trying to wrap my head
around how to implement Named Resources. I'm just going
to talk about what I think I know. Please correct any
mistakes!

Named Resources exist in up to 3 places at any given time
while "part of the system".

* in a filesystem directory
* in a data structure in local vm
* in a data structure in global vm

So, I'm going to create 2 data structures,
as a rough start:

true setglobal
globaldict begin
/globalresourcedict <<
/Category <<
>>
/Generic <<
>>
/ProcSet <<
>>
>> def
end

false setglobal
userdict begin
/localresourcedict <<
/Encoding <<
/StandardEncoding [ ]
/ISOLatin1Encoding [ ]
>>
>> def
end

I still don't understand Category and Generic. :(

John Deubert

unread,
Sep 27, 2013, 10:31:55 AM9/27/13
to
Category is the resource category that keeps track of resource
categories. (That sentence was a paragon of clarity, no?)

The resources in the Category category have names like /Form, /Font,
/Pattern, /Encoding, etc. The resource data associated with each of
these names is a dictionary whose contents are mostly procedures with
names corresponding to the resource-related PostScript operators,
though capitalized differently: /FindResource, /DefineResource,
/ResourceForAll, etc. These are the procedures that implement the
operator activities for that particular resource category.

The findresource operator does the following:
/Category findresource /FindResource get exec

That is, if you do this:
/Helvetica /Font findresource

The findresource operator gets the Font Category resource dictionary,
fetches the FindResource procedure from that dictionary, and then
executes it. The other resource operators do similar things.

The Generic category is used when you want to create your own resource
Category. Creating your own category is simple, in principle: just
create a new Category resource:

/MyNewCategory
<<
/DefineResource { … }
/FindResource { … }

>> /Category defineresource

The Generic category exists so you don’t need to forever be coming up
with your own definitions for those operator-implementation procedures.
You can simply copy the procedures from the Generic category
dictionary. (The Generic procedures are parameterized based on the name
of the category.)

Thus, to create a BBox resource category (to use an example from my
Advanced PostScript class), you’d do this:

/BBox
/Generic /Category findresource % Get the Generic category dict
dup length dict % Create an identically-sized dict
copy % and copy Generic into the new dict
/Category defineresource pop % Then make it a resource.

% Now you can create BBox resources:
/Letter [ 0 0 612 792 ] /BBox defineresource pop

% And use them
/Letter /BBox findresource clip

Hope that helped some. Resources takes quite a while to get the hang
of; it’s a two-hour discussion in the Advanced PostScript class.

In particular, using resources aren’t extremely useful (for what I
usually do, anyway) unless you have external storage available to the
interpreter. In that case, you can arrange it so that findresource
looks on the disk if it doesn’t find the resource you want in memory;
all future programs sent to that interpreter can use BBox resources (or
whatever) with no initial work.

I hope some part of that was lucid.

- John


========
John Deubert
Acumen Training
PostScript & PDF Engineering Classes & Consulting
www.acumentraining.com

Learn PostScript programming techniques
Read the free Acumen Journal
acumentraining.com/acumenjournal.html

John Deubert

unread,
Sep 27, 2013, 10:44:47 AM9/27/13
to
On 2013-09-24 22:19:43 +0000, luser- -droog said:

--

John Deubert

unread,
Sep 27, 2013, 10:49:17 AM9/27/13
to
On 2013-09-24 22:19:43 +0000, luser- -droog said:

X-Received: by 10.66.145.7 with SMTP id
sq7mr2745294pab.43.1380292315848; Fri, 27 Sep 2013 07:31:55 -0700 (PDT)
Path:
border1.nntp.dca3.giganews.com!Xl.tags.giganews.com!border2.nntp.dca3.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!border1.nntp.hkg.giganews.com!news.netfront.net!news.glorb.com!z6no27972927pbz.1!news-out.google.com!z6ni74626pbu.0!nntp.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail

NNTP-Posting-Date: Fri, 27 Sep 2013 09:31:55 -0500
From: John Deubert <jo...@acumentraining.com>
Organization: Acumen Training
Newsgroups: comp.lang.postscript
Date: Fri, 27 Sep 2013 07:31:55 -0700
Message-ID: <2013092707315563519-john@acumentrainingcom>
References: <ad8a9d89-952f-4e17...@googlegroups.com>
MIME-Version: 1.0
Subject: Re: Named Resources
User-Agent: Unison/2.1.10
Lines: 120
X-Usenet-Provider: http://www.giganews.com
X-Trace:
sv3-ezYP0wfR3Cu/Bz3fBd/WLu0tLHKnRFHiQljeVduelQWqfXMpSAZGc5fcvYlCKa9ShgBlWC1Cq9kte29!FY94CF6efQpZyIiXTWXyiDhRJSZ2SC8tz5DMhDa4TmYKu47Xi/XcsTVIjB8JuIE5msk=

X-Complaints-To: ab...@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your
complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 5354
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Bytes: 5406
Xref: number.nntp.dca.giganews.com comp.lang.postscript:73766

On 2013-09-24 22:19:43 +0000, luser- -droog said:

Category is the resource category that keeps track of resource
categories. (That sentence was a paragon of clarity, no?)

The resources in the Category category have names like /Form, /Font,
/Pattern, /Encoding, etc. The resource data associated with each of
these names is a dictionary whose contents are mostly procedures with
names corresponding to the resource-related PostScript operators,
though capitalized differently: /FindResource, /DefineResource,
/ResourceForAll, etc. These are the procedures that implement the
operator activities for that particular resource category.

The findresource operator does the following:

/Category findresource /FindResource get exec

That is, if you do this:

/Helvetica /Font findresource

The findresource operator gets the Font Category resource dictionary,
fetches the FindResource procedure from that dictionary, and then
executes it. The other resource operators do similar things.

The Generic category is used when you want to create your own resource
Category. Creating your own category is simple, in principle: just
create a new Category resource:

/MyNewCategory
<<
/DefineResource { ... }
/FindResource { ... }
...
>>
/Category defineresource

The Generic category exists so you don't need to forever be coming up
with your own definitions for those operator-implementation procedures.
You can simply copy the procedures from the Generic category
dictionary. (The Generic procedures are parameterized based on the name
of the category.)

Thus, to create a BBox resource category (to use an example from my
Advanced PostScript class), you'd do this:

/BBox
/Generic /Category findresource % Get the Generic category dict
dup length dict % Create an identically-sized dict
copy % and copy Generic into the new dict
/Category defineresource pop % Then make it a resource.

% Now you can create BBox resources:
/Letter [ 0 0 612 792 ] /BBox defineresource pop

% And use them
/Letter /BBox findresource clip

John Deubert

unread,
Sep 27, 2013, 11:44:03 AM9/27/13
to
On 2013-09-24 22:19:43 +0000, luser- -droog said:

[[ Sorry if this is a repeat post; I'm trying out a new newsreader and
the first attempt didn't seem to take.]]

Category is the resource category that keeps track of resource
categories. (That sentence was a paragon of clarity, no?)

The resources in the Category category have names like /Form, /Font,
/Pattern, /Encoding, etc. The resource data associated with each of
these names is a dictionary whose contents are mostly procedures with
names corresponding to the resource-related PostScript operators,
though capitalized differently: /FindResource, /DefineResource,
/ResourceForAll, etc. These are the procedures that implement the
operator activities for that particular resource category.

The findresource operator does the following:

/Category findresource % Get the appropriate Category resource dictionary
/FindResource get % Get the FindResource procedure out of that dict
exec % execute it
Hope that helped some. Resources takes quite a while to get the hang

luser- -droog

unread,
Sep 30, 2013, 1:32:18 AM9/30/13
to
On Friday, September 27, 2013 9:31:55 AM UTC-5, John Deubert wrote:
> On 2013-09-24 22:19:43 +0000, luser- -droog said:
>
>
>
> > I've spent the last few weeks trying to wrap my head
> > around how to implement Named Resources. I'm just going
> > to talk about what I think I know. Please correct any
> > mistakes!
> >
> > Named Resources exist in up to 3 places at any given time
> > while "part of the system".
> >
> > * in a filesystem directory
> > * in a data structure in local vm
> > * in a data structure in global vm
> >
> > So, I'm going to create 2 data structures,
> > as a rough start:
> >
> > true setglobal
> > globaldict begin
> > /globalresourcedict <<
> > /Category <<

Here's one error, I think. /Generic belongs inside the /Category dict.
It's unclear to me whether it exists as a category in its own right.

> > >>
> > /Generic <<
> > >>

> > /ProcSet <<
> > >>
> >>> def
> > end
> >
> > false setglobal
> > userdict begin
> > /localresourcedict <<
> > /Encoding <<
> > /StandardEncoding [ ]
> > /ISOLatin1Encoding [ ]
> > >>
> >>> def
> > end
> >
> > I still don't understand Category and Generic. :(
>
>
>
>
>
> Category is the resource category that keeps track of resource
> categories. (That sentence was a paragon of clarity, no?)
>

It's no worse than manual. Possibly, it's as good as the material
allows. :)

Between this write-up, anastigmatix's pages, and the manual: this
should theoretically be enough for me to go on. According to my
personality test, I'm an intuitive. So 3 coherent perspectives
should enable me to build a coherent model. But there's no telling
how much sleep it's require!! :)

>
>
> The resources in the Category category have names like /Form, /Font,
> /Pattern, /Encoding, etc. The resource data associated with each of
> these names is a dictionary whose contents are mostly procedures with
> names corresponding to the resource-related PostScript operators,
> though capitalized differently: /FindResource, /DefineResource,
> /ResourceForAll, etc. These are the procedures that implement the
> operator activities for that particular resource category.
>
>
>
> The findresource operator does the following:
> /Category findresource /FindResource get exec
>

Not to kick a gift-horse in the mouth, but the manual says it should
`begin` the category dict, and call FindResource by name. This enables
the category implementation dict to hold extra convenience procedures
for the implementation procedures to use. Presumably they stress this
so as not to encourage people to stop writing well-factored code. :)
Yes. I think so. It's beginning to gel.

I'm hoping to use Named Resourcces to handle the selection of output devices.
PLRM 3ed, p.97:

> OutputDevice
> Instances of the OutputDevice resource category (LanguageLevel 3) are dictionaries that describe certain capabilities of a particular page device, such as the possible page sizes or resolutions (see Section 6.4, “Output Device Dictionary”).

The output device handling is somewhat vague in the Warnock/Wyatt paper, presumably due to the fact that so much of it must have depended on the flexible binding features in the Mesa language. One of the histories of
postscript describe this paper as Warnock's "smuggling" of knowledge
out of Xerox.

It describes a device constructor function, image constructor, and a
graphics-state constructor which receives a device or image object.

> Device NewXXXDevice (<optional params>);
> Image NewXXXImage (<optional params>);

> DisplayContext NewDisplayContext (Device device);

So, using named resources would let me give different names to different
device-types, but with a smooth common interface (fingers-crossed).

... [ I also hope this setup to work in tandem with NeWS-style
"magic" dictionaries, once those are designed and written. ]



--
too many smileys?

wst wst

unread,
Aug 29, 2017, 5:02:13 AM8/29/17
to
Op woensdag 25 september 2013 00:19:43 UTC+2 schreef luser droog:
How do you handle the local and global VM?

The red book states:
"The resources dictionary should take care of local and global VM resources".

Ghostscript comments say:

% The PostScript manual says that each category must
% manage global and local instances separately. However, objects in
% global VM other than systemdict can't reference objects in local VM."

Now how is it possible to manage both local and global VM in a single dictionary (the resources dictionary) ?

Is it possible to explain this as I'm confused with the local/global VM in combination with Named Resources... how does that work together?

luser droog

unread,
Aug 29, 2017, 10:25:57 PM8/29/17
to
The OP was several years ago, but I'm still around! It appears from my earlier
message that I had planned 2 dictionaries to manage the local and global stuff
separately. Indeed, it seems impossible to do with 1 dictionary in either memory.
Global of course is forbidden to contain references to objects in local memory.
Conversely, local memory is too perishable. If the user were to do

save ... findresource ... restore

then it all would get lost.

So I think you have to use 2. Unless there's something else I'm not seeing.

Carlos

unread,
Aug 30, 2017, 1:24:13 PM8/30/17
to
[wst wst <wouter_...@hotmail.com>, 2017-08-29 02:02]
Are you talking about "category implementation dictionaries"? That's the
dictionary that holds procedures implementing defineresource, etc. AFAICT, the
book says that each category has only one implementation dictionary for
both its local and global resources, not that the resources should be stored in
a single dictionary. I think it doesn't say how they should be stored at all; as
long as you implement the procedures to define/find/etc them, what
your implementation does is nobody's business.

I also don't see another way than to use two dictionaries, one
global and one local.

--

0 new messages