1. 程式人生 > >【知識普及】PostScript中的“命名資源”詳解

【知識普及】PostScript中的“命名資源”詳解

PS檔案中的“命名資源”(Named Resources)

           作者:bobob     日期:2007.12.11          

ps中的一些特性是用一組object的集合來控制的。比如font,可以用一個字典來描述字元的外形。在ps levle2和level3,這樣的機制同樣用來描述form,pattern,color rendering,以及其他很多object category。

通常,把這些object和一些name關聯起來,並在一箇中樞機構註冊,使用起來是很方便的,特別是font。當font資源建立的時候,就分別給他們關聯一個標準的名字(比如Times New Roman)。其他category的object同樣可以使用這種機制。

如果把所有可用的object(比如,所有可用的字型)放在一個特定的category並一直以字典的形式儲存在於VM裡面,那麼訪問一個named object事實上就是在dictionary上執行“get”操作;判斷一個named object是否可用,實際上也就是執行“known”操作。(注:這裡的get和known是ps裡面定義的針對字典的操作符,get是從字典裡面獲取一個key關聯的值,known是查詢字典裡面有沒有指定的key)

很多字型和其他category的object可以在任意給定的時間,通過以下兩種方式進入VM:
1.生成ps的程式直接把這些物件的定義嵌入工作流。
2.在執行過程中,ps程式通過name請求訪問object,直譯器通過一個“外部源”(磁碟檔案,網路檔案等)把這些object 讀入到VM中。

Named Resources就是上面第二種方式。一個“resource”是一組named object,他們在VM中,或在需要用到的時候可以定位並load到VM中。各個種類(category)的resource有獨立的名字空間,在每個category中,都有一組命名過的資源例項(instance),每個種類都有自己定位和管理例項的方法。

資源操作符
ps level 2有5個資源操作符:findresource,resourcestatus,resourceforall,defineresource,undefineresource。
findresource是在給定的category裡面,根據key的名字查詢資源例項。如果在VM中沒有找到,findresource操作符會從一個外部源load這個例項,並把它放在VM中。一個PS程式可以只用一個key就訪問資源例項,而不管它是在VM中,還是在一個外部源。
resourcestatus返回一個資源例項的資訊,resourceforall列舉一個特定category的所有資源例項,而不管這些例項是否在VM中;他們不會把資源例項放到VM。使用resourceforall要特別注意,因為可用的資源例項集合可能特別巨大。
一個ps程式可以顯式的在VM中定義一個命名資源例項:先在VM中建立一個物件,然後用defineresource操作符把這個物件和一個key關聯在特定category中。這個資源例項可以用於後面的findresource,resourcestatus,resourceforall操作符。同時,ps程式也可以使用undefineresource來取消這種定義。當資源例項包含在外部儲存介質中的時候,findresource自動執行defineresource和undefineresource來管理VM。
資源例項可以定義在Local VM或Global VM中,他們的宣告週期取決於定義的時間和當前VM模式。通常,Local和Global資源例項對程式都是可見和可用的,然而當VM是global的時候,只有global的資源例項才可見,這是為了確保資源例項有正確的行為。

  常規資源表
種類名稱 物件型別 簡要說明
Font  dictionary Font definition
CIDFont  dictionary  CIDFont definition(LanguageLevel 3)
CMap  dictionary  Character code mapping(LanguageLevel 3)
FontSet  dictionary Bundle of font definitions(LanguageLevel 3)
Encoding array  Encoding vector
Form  dictionary Form  definition
Pattern  dictionary Pattern  definition
ProcSet  dictionary Procedure set
ColorSpace array  Parameterized color space
Halftone dictionary Halftone dictionary
ColorRendering dictionary Color rendering dictionary
IdiomSet dictionary Procedure substitution dictionary(LanguageLevel 3)
InkParams dictionary Colorant details dictionary (LanguageLevel 3)
TrapParams dictionary Trapping parameter set (LanguageLevel 3)
OutputDevice dictionary Page device capabilities (LanguageLevel 3)
ControlLanguage dictionary Control language support (LanguageLevel 3)
Localization dictionary Natural language support (LanguageLevel 3)
PDL  dictionary PDL interpreter support (LanguageLevel 3)
HWOptions dictionary Hardware options (LanguageLevel 3)