星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138
  1. % Copyright (C) 1994, 2000 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This software is provided AS-IS with no warranty, either express or
  4. % implied.
  5. %
  6. % This software is distributed under license and may not be copied,
  7. % modified or distributed except as expressly authorized under the terms
  8. % of the license contained in the file LICENSE in this distribution.
  9. %
  10. % For more information about licensing, please refer to
  11. % http://www.ghostscript.com/licensing/. For information on
  12. % commercial licensing, go to http://www.artifex.com/licensing/ or
  13. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  14. % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  15. % $Id: pdf_draw.ps 10687 2010-02-02 07:23:57Z alexcher $
  16. % pdf_draw.ps
  17. % PDF drawing operations (graphics, text, and images).
  18. /.setlanguagelevel where { pop 2 .setlanguagelevel } if
  19. .currentglobal true .setglobal
  20. /pdfdict where { pop } { /pdfdict 100 dict def } ifelse
  21. GS_PDF_ProcSet begin
  22. pdfdict begin
  23. % For simplicity, we use a single interpretation dictionary for all
  24. % PDF graphics operations, even though this is too liberal.
  25. /drawopdict 100 dict def
  26. % ================================ Graphics ================================ %
  27. % ---------------- Functions ---------------- %
  28. % Note that resolvefunction converts a PDF Function to a PostScript Function;
  29. % resolve*fnproc converts a PDF function to a PostScript procedure.
  30. % We need to process all required and optional parameters to resolve any
  31. % use of indirect references.
  32. /fnrdict mark
  33. 0 { .resolvefn0 }
  34. 2 { .resolvefn2 }
  35. 3 { .resolvefn3 }
  36. 4 { .resolvefn4 }
  37. .dicttomark readonly def
  38. /.resolvefn0 {
  39. dup length 1 add dict .copydict % make room for DataSource
  40. % now resolve any indirect references
  41. dup /Size 2 copy knownoget { put } { pop pop } ifelse
  42. dup /BitsPerSample 2 copy knownoget { put } { pop pop } ifelse
  43. dup /Order 2 copy knownoget { put } { pop pop } ifelse
  44. dup /Encode 2 copy knownoget { put } { pop pop } ifelse
  45. dup /Decode 2 copy knownoget { put } { pop pop } ifelse
  46. % Don't lose our place in PDFfile.
  47. PDFfile fileposition exch
  48. dup //true resolvestream
  49. % The stream isn't positionable, so read all the data now.
  50. % Stack: filepos fndict stream
  51. 1 index /Range get length 2 idiv 2 index /BitsPerSample get mul
  52. 2 index /Size get { mul } forall
  53. 7 add 8 idiv
  54. dup 65535 le {
  55. string 1 index exch readstring pop
  56. } {
  57. 1 index exch () /SubFileDecode filter /ReusableStreamDecode filter
  58. } ifelse
  59. exch closefile
  60. % Stack: filepos fndict data
  61. exch dup /DataSource 4 -1 roll put
  62. exch PDFfile exch setfileposition
  63. } bdef
  64. /.resolvefn2 {
  65. dup length dict .copydict
  66. dup /C0 2 copy knownoget { put } { pop pop } ifelse
  67. dup /C1 2 copy knownoget { put } { pop pop } ifelse
  68. dup /N 2 copy knownoget { put } { pop pop } ifelse
  69. } bdef
  70. /.resolvefn3 {
  71. dup length dict .copydict
  72. dup /Bounds 2 copy knownoget { put } { pop pop } ifelse
  73. dup /Encode 2 copy knownoget { put } { pop pop } ifelse
  74. dup /Functions 2 copy oget mark exch dup {
  75. oforce .resolvefn
  76. } forall
  77. counttomark -1 roll astore exch pop put
  78. } bdef
  79. /.resolvefn4 {
  80. PDFfile fileposition exch % filepos fndict
  81. dup true resolvestream % filepos fndict stream
  82. exch dup length dict copy % filepos stream fndict2
  83. dup /Function undef % filepos stream fndict2
  84. exch dup token not {
  85. () /rangecheck cvx signalerror
  86. } if
  87. exch token {
  88. /rangecheck cvx signalerror
  89. } if
  90. % Use .bind to avoid idiom recognition.
  91. .bind
  92. 1 index /Function 3 -1 roll put
  93. exch PDFfile exch setfileposition
  94. } bdef
  95. /.resolvefn { % <fndict> .resolvefn <fndict'>
  96. dup length dict .copydict
  97. dup /Domain 2 copy knownoget { put } { pop pop } ifelse
  98. dup /Range 2 copy knownoget { put } { pop pop } ifelse
  99. dup /FunctionType oget //fnrdict exch get exec
  100. } bdef
  101. /resolvefunction { % <fndict> resolvefunction <function>
  102. .resolvefn
  103. PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { true } ifelse { (%Function: ) print dup === flush } if } if
  104. } bdef
  105. /resolvefnproc { % <fndict> resolvefnproc <proc>
  106. resolvefunction .buildfunction
  107. } bdef
  108. /resolveidfnproc { % <fndict> resolveidfnproc <proc>
  109. dup /Identity eq { pop { } } { resolvefnproc } ifelse
  110. } bdef
  111. /resolvedefaultfnproc { % <fndict> <default> resolved'fnproc <proc>
  112. 1 index /Default eq { exch pop } { pop resolveidfnproc } ifelse
  113. } bdef
  114. % ---------------- Shadings ---------------- %
  115. /shrdict mark
  116. /BBox {
  117. dup dup dup aload pop normrect_elems
  118. 5 -1 roll astore
  119. } bind
  120. /ColorSpace {
  121. resolvecolorspace
  122. } bind
  123. /Function {
  124. dup type /dicttype eq {
  125. resolvefunction
  126. } {
  127. [ exch { oforce resolvefunction } forall ]
  128. } ifelse
  129. } bind
  130. .dicttomark readonly def
  131. /resolveshading { % <shadingstream> resolveshading <shading>
  132. dup /.shading_dict .knownget {
  133. exch pop
  134. dup /ShadingType get 4 ge {
  135. dup /DataSource get 0 setfileposition
  136. } if
  137. } {
  138. dup
  139. PDFfile fileposition exch
  140. mark exch {
  141. oforce //shrdict 2 index .knownget { exec } if
  142. } forall .dicttomark
  143. dup /ShadingType get 4 ge {
  144. dup dup true resolvestream
  145. % Make a reusable stream so that the shading doesn't
  146. % reposition PDFfile at unexpected times.
  147. /ReusableStreamDecode filter /DataSource exch put
  148. } if
  149. exch PDFfile exch setfileposition
  150. dup 3 1 roll /.shading_dict exch put
  151. } ifelse
  152. } bdef
  153. /resolvesh { % <shname> resolvesh <shading>
  154. % <shname> resolvesh <null>
  155. Page /Shading rget {
  156. resolveshading
  157. } {
  158. null
  159. }ifelse
  160. } bdef
  161. % ---------------- Halftones ---------------- %
  162. /spotfunctions mark
  163. /Round {
  164. abs exch abs 2 copy add 1 le {
  165. dup mul exch dup mul add 1 exch sub
  166. } {
  167. 1 sub dup mul exch 1 sub dup mul add 1 sub
  168. } ifelse
  169. }
  170. /Diamond {
  171. abs exch abs 2 copy add .75 le {
  172. dup mul exch dup mul add 1 exch sub
  173. } {
  174. 2 copy add 1.23 le {
  175. .85 mul add 1 exch sub
  176. } {
  177. 1 sub dup mul exch 1 sub dup mul add 1 sub
  178. } ifelse
  179. } ifelse
  180. }
  181. /Ellipse {
  182. abs exch abs 2 copy 3 mul exch 4 mul add 3 sub dup 0 lt {
  183. pop dup mul exch .75 div dup mul add 4 div 1 exch sub
  184. } {
  185. dup 1 gt {
  186. pop 1 exch sub dup mul exch 1 exch sub
  187. .75 div dup mul add 4 div 1 sub
  188. } {
  189. .5 exch sub exch pop exch pop
  190. } ifelse
  191. } ifelse
  192. }
  193. /EllipseA { dup mul .9 mul exch dup mul add 1 exch sub }
  194. /InvertedEllipseA { dup mul .9 mul exch dup mul add 1 sub }
  195. /EllipseB { dup 5 mul 8 div mul exch dup mul exch add sqrt 1 exch sub }
  196. /EllipseC { dup mul .9 mul exch dup mul add 1 exch sub }
  197. /InvertedEllipseC { dup mul .9 mul exch dup mul add 1 sub }
  198. /Line { exch pop abs neg }
  199. /LineX { pop }
  200. /LineY { exch pop }
  201. /Square { abs exch abs 2 copy lt { exch } if pop neg }
  202. /Cross { abs exch abs 2 copy gt { exch } if pop neg }
  203. /Rhomboid { abs exch abs 0.9 mul add 2 div }
  204. /DoubleDot { 2 {360 mul sin 2 div exch } repeat add }
  205. /InvertedDoubleDot { 2 {360 mul sin 2 div exch } repeat add neg }
  206. /SimpleDot { dup mul exch dup mul add 1 exch sub }
  207. /InvertedSimpleDot { dup mul exch dup mul add 1 sub }
  208. /CosineDot { 180 mul cos exch 180 mul cos add 2 div }
  209. /Double { exch 2 div exch 2 { 360 mul sin 2 div exch } repeat add }
  210. /InvertedDouble {
  211. exch 2 div exch 2 { 360 mul sin 2 div exch } repeat add neg
  212. }
  213. .dicttomark readonly def
  214. /htrdict mark
  215. 1 { .resolveht1 }
  216. 5 { .resolveht5 }
  217. % We don't support types 6, 10, or 16 yet.
  218. .dicttomark readonly def
  219. /.resolveht1 {
  220. mark exch {
  221. oforce
  222. 1 index /SpotFunction eq {
  223. dup type /nametype eq
  224. { //spotfunctions exch get } { resolvefnproc }
  225. ifelse
  226. } {
  227. 1 index /TransferFunction eq {
  228. resolveidfnproc
  229. } if
  230. } ifelse
  231. } forall .dicttomark
  232. } bdef
  233. /.resolveht5 {
  234. mark exch {
  235. oforce dup type /dicttype eq { resolvehalftone } if
  236. } forall .dicttomark
  237. } bdef
  238. /resolvehalftone { % <dict> resolvehalftone <halftone>
  239. dup /HalftoneType oget
  240. dup //htrdict exch .knownget {
  241. exch pop exec
  242. } {
  243. (\n\n **** Unsupported HalftoneType ) pdfformaterror
  244. =string cvs pdfformaterror (. ***\n\n) pdfformaterror
  245. /resolvehalftone cvx /unregistered signalerror
  246. } ifelse
  247. } bdef
  248. % ---------------- Graphics state management ---------------- %
  249. /cmmatrix matrix def
  250. drawopdict begin
  251. % Graphics state stack
  252. /q { q } def
  253. /Q { Q } def
  254. % Graphics state setting
  255. /cm { //cmmatrix astore
  256. .getpath
  257. exch concat
  258. newpath { exec } forall
  259. % If inside a BT/ET block, we need to update the TextSaveMatrix
  260. currentdict /TextSaveMatrix .knownget {
  261. //cmmatrix exch dup concatmatrix pop
  262. } if
  263. } bdef
  264. /i { 1 .min setflat } bdef
  265. /J /setlinecap load def
  266. /d /setdash load def
  267. /j /setlinejoin load def
  268. /w /setlinewidth load def
  269. /M { 1 .max setmiterlimit } bdef
  270. /gs { gs } def
  271. end
  272. % Each entry in this dictionary is
  273. % <gsres> <value> -proc- <gsres>
  274. /gsbg {
  275. /BGDefault load resolvedefaultfnproc setblackgeneration
  276. } bdef
  277. /gsucr {
  278. /UCRDefault load resolvedefaultfnproc setundercolorremoval
  279. } bdef
  280. /gstr {
  281. dup type /arraytype eq {
  282. { oforce /TRDefault load resolvedefaultfnproc } forall
  283. setcolortransfer
  284. } {
  285. /TRDefault load resolvedefaultfnproc settransfer
  286. } ifelse
  287. } bdef
  288. /gsparamdict mark
  289. /SA { setstrokeadjust }
  290. /OP { 1 index /op known not { dup op } if OP }
  291. % The PDF 1.3 specification says that the name /Default is only
  292. % recognized for {BG,UCR,TR}2. However, PDF 1.3 files produced
  293. % by Adobe Acrobat Distiller 4.0 for Windows use the name /Default
  294. % with the older keys, so we have to implement this.
  295. /BG { 1 index /BG2 known { pop } { gsbg } ifelse }
  296. /UCR { 1 index /UCR2 known { pop } { gsucr } ifelse }
  297. /TR { 1 index /TR2 known { pop } { gstr } ifelse }
  298. /HT {
  299. dup /Default eq {
  300. pop .setdefaulthalftone
  301. } {
  302. %****** DOESN'T IMPLEMENT THE STREAM CASE YET ******
  303. resolvehalftone sethalftone
  304. } ifelse
  305. % the transfer function may dependent on the halftone, so make sure
  306. % it is set if included in the graphic state (otherwise this is
  307. % subject to order of a dictionary forall, which is unpredictable)
  308. dup /TR2 .knownget {
  309. dup /Default eq { oforce gsparamdict /TR2 get exec } { pop } ifelse
  310. } {
  311. dup /TR .knownget {
  312. /dup /Default eq { oforce gsparamdict /TR get exec } { pop } ifelse
  313. } if
  314. } ifelse
  315. }
  316. /HTP {
  317. % HTP may be present even if this isn't a DPS interpreter.
  318. /sethalftonephase where { pop aload pop sethalftonephase } { pop } ifelse
  319. }
  320. % PDF 1.3
  321. /Font { aload pop Tf }
  322. /LW { setlinewidth }
  323. /LC { setlinecap }
  324. /LJ { setlinejoin }
  325. /ML { 1 .max setmiterlimit }
  326. /D { aload pop setdash }
  327. /RI { ri }
  328. /op { op }
  329. /OPM { OPM }
  330. /BG2 { gsbg }
  331. /UCR2 { gsucr }
  332. /TR2 { gstr }
  333. /FL { 1 .min setflat }
  334. /SM {
  335. % SM may be present even if this is only a Level 2 interpreter.
  336. /setsmoothness where { pop setsmoothness } { pop } ifelse
  337. }
  338. % PDF 1.4
  339. % All of these require the "transparency" feature in the interpreter.
  340. /ca { ca }
  341. /CA { CA }
  342. /SMask { gssmask }
  343. /AIS { AIS }
  344. /BM { BM }
  345. /TK { TK }
  346. .dicttomark readonly def
  347. /gs { % <gsres> gs -
  348. Page /ExtGState rget {
  349. % We keep the dictionary on the stack during the forall so that
  350. % keys that interact with each other have access to it.
  351. dup {
  352. oforce exch gsparamdict exch .knownget { exec } { pop } ifelse
  353. } forall pop
  354. } if
  355. } bdef
  356. % ------ Transparency support ------ %
  357. /gssmask {
  358. dup /None eq 1 index //null eq or PDFusingtransparency not or {
  359. pop null
  360. } {
  361. % Preprocess the SMask value into a parameter dictionary for
  362. % .begintransparencymaskgroup, with added /BBox and /Draw keys.
  363. mark exch % Stack: mark smaskdict
  364. dup /S oget /Subtype exch 3 2 roll
  365. % Stack: mark ... smaskdict
  366. dup /BC knownoget {
  367. dup /Background exch 4 2 roll
  368. gsave //nodict begin
  369. 1 index /G oget /Group oget /CS knownoget {
  370. resolvecolorspace dup setgcolorspace csput
  371. } if
  372. aload pop setcolor [ currentgray ]
  373. end grestore
  374. /GrayBackground exch 3 2 roll
  375. } if
  376. dup /TR knownoget {
  377. dup /Identity eq {
  378. pop
  379. } {
  380. resolvefnproc /TransferFunction exch 3 2 roll
  381. } ifelse
  382. } if
  383. dup /G oget dup /BBox oget /BBox exch 4 2 roll
  384. /.execmaskgroup cvx 2 packedarray cvx /Draw exch 3 2 roll
  385. pop .dicttomark
  386. } ifelse SMask
  387. } bdef
  388. % Functions specific to the Device* colorspaces to force the switch to
  389. % the Device* colorspace so that the SMask will not get a CIEBased* colorspace
  390. % in the case when UseCIEColor changes the Device* colorspace to something else.
  391. % Also see the logic in pdf_main.ps:pdfopen that similarly defines these resources.
  392. /forceDefaultCS <<
  393. {
  394. currentcolorspace setcolorspace % this will switch to Device colorspace
  395. } bind
  396. /DeviceGray exch
  397. /DeviceRGB 1 index
  398. /DeviceCMYK 1 index
  399. >>
  400. def
  401. % This procedure is called to actually render the soft mask.
  402. /.execmaskgroup { % <masknum> <paramdict> <formdict> .execmaskgroup -
  403. % Save our place in PDFfile. Do not use gsave-grestore when creating
  404. % a soft mask with .begintransparencygroup because high level devices
  405. % need to modify the graphic state by storing the soft mask ID.
  406. % Save the ExtGState (//nodict begin) BEFORE changing the colorspace
  407. mark currentcolor counttomark dup 4 add exch roll pop
  408. currentcolorspace 4 1 roll .getuseciecolor 4 1 roll //nodict begin
  409. PDFfile fileposition 4 1 roll
  410. % We have to select the group's color space so that the
  411. % background color will be interpreted correctly.
  412. % [save/restore]DefaultCS make sure that the SMask logic sees
  413. % the Device* spaces, not CIEBased* that UseCIEColor may have
  414. % established.
  415. false .setuseciecolor % SMask gets processed without UseCIEColor
  416. dup /Group oget /CS knownoget {
  417. resolvecolorspace dup setgcolorspace csput
  418. //true % use currentcolorspace
  419. } {
  420. % inheriting the colorspace -- make sure Device* spaces are not CIEBased
  421. forceDefaultCS currentcolorspace 0 get .knownget { exec } if
  422. //false % no defined colorspace
  423. } ifelse
  424. 3 -1 roll dup /BBox get aload pop .begintransparencymaskgroup {
  425. dup /Resources knownoget { oforce } { 0 dict } ifelse
  426. exch false resolvestream
  427. .execgroup .endtransparencymask
  428. } stopped {
  429. .discardtransparencymask stop
  430. } if
  431. PDFfile exch setfileposition
  432. .setuseciecolor setcolorspace setcolor end % restore colorspace, color and ExtGState (end)
  433. } bdef
  434. % Paint a Form+Group XObject, either for a transparency mask or for a Do.
  435. /.execgroup { % <resdict> <stream> .execgroup -
  436. gsave //nodict begin
  437. newpath null SMask
  438. 1 .setopacityalpha 1 .setshapealpha
  439. 1 CA 1 ca
  440. /Compatible .setblendmode
  441. % Execute the body of the Form, similar to DoForm.
  442. pdfopdict .pdfruncontext
  443. end grestore
  444. } bdef
  445. /.beginformgroup { % groupdict bbox .beginformgroup -
  446. exch mark exch % bbox mark groupdict
  447. dup /CS knownoget { resolvecolorspace setgcolorspace } if
  448. dup /I knownoget { /Isolated exch 3 2 roll } if
  449. dup /K knownoget { /Knockout exch 3 2 roll } if
  450. pop .dicttomark
  451. % Stack: bbox paramdict
  452. exch aload pop
  453. .begintransparencygroup
  454. } bdef
  455. % .paintgroupform implements the Form PaintProc in the case where the
  456. % Form XObject dictionary includes a Group key. See .paintform below.
  457. /.paintgroupform { % <resdict> <stream> <formdict> .paintgroupform -
  458. dup /Group oget exch /BBox oget
  459. % Stack: resdict stream groupdict bbox
  460. .beginformgroup {
  461. .execgroup
  462. } stopped {
  463. .discardtransparencygroup stop
  464. } if .endtransparencygroup
  465. } bdef
  466. % Make an ImageType 103 (soft-masked) image.
  467. /makesoftmaskimage { % <datasource> <imagemask> <SMask> makesoftmaskimage
  468. % <datasource> <imagemask>, updates currentdict =
  469. % imagedict
  470. % See the ImageType 3 case of makemaskimage below.
  471. % SMask is a stream, another Image XObject.
  472. % Stack: datasource imagemask(false) smaskstreamdict
  473. PDFfile fileposition exch
  474. dup /Matte knownoget { /Matte exch def } if
  475. dup length dict makeimagedict pop
  476. % In order to prevent the two data sources from being
  477. % aliased, we need to make at least one a reusable stream.
  478. % We pick the mask, since it's smaller (in case we need to
  479. % read all its data now).
  480. % Stack: datasource imagemask(false) savedpos
  481. % maskdict is currentdict
  482. /DataSource DataSource mark
  483. /Intent 1
  484. /AsyncRead true
  485. .dicttomark .reusablestreamdecode def
  486. PDFfile exch setfileposition
  487. currentdict end currentdict end
  488. 5 dict begin
  489. /ImageType 103 def
  490. /DataDict exch def
  491. dup /InterleaveType 3 put
  492. DataDict /Matte knownoget {
  493. /Matte exch def
  494. } if
  495. AlphaIsShape { /ShapeMaskDict } { /OpacityMaskDict } ifelse exch def
  496. /ColorSpace DataDict /ColorSpace get def
  497. } bdef
  498. % ---------------- Color setting ---------------- %
  499. /01_1 [0 1] readonly def
  500. /01_3 [0 1 0 1 0 1] readonly def
  501. /01_4 [0 1 0 1 0 1 0 1] readonly def
  502. % The keys here are resolved (PostScript, not PDF) color space names.
  503. /csncompdict 9 dict begin
  504. /DeviceGray { pop 1 } bdef
  505. /DeviceRGB { pop 3 } bdef
  506. /DeviceCMYK { pop 4 } bdef
  507. /CIEBasedA //DeviceGray def
  508. /CIEBasedABC //DeviceRGB def
  509. /ICCBased { 1 oget /N oget } bdef
  510. /Separation //DeviceGray def
  511. /DeviceN { 1 oget length } bdef
  512. /Indexed //DeviceGray def
  513. currentdict end readonly def
  514. /csrdict 13 dict begin
  515. /DeviceGray { } bdef
  516. /DeviceRGB { } bdef
  517. /DeviceCMYK { } bdef
  518. /CalGray {
  519. 1 oget 6 dict begin
  520. dup /Gamma knownoget {
  521. /exp load 2 packedarray cvx /DecodeA exch def
  522. } if
  523. dup /BlackPoint knownoget { /BlackPoint exch def } if
  524. dup /WhitePoint knownoget {
  525. dup /WhitePoint exch def
  526. dup /MatrixA exch def
  527. /RangeLMN [ 3 2 roll { 0 exch } forall ] def
  528. } if
  529. /PDFColorSpace exch def [ /CIEBasedA currentdict end ]
  530. } bdef
  531. /CalRGB {
  532. 1 oget 6 dict begin
  533. dup /Gamma knownoget {
  534. [ exch { /exp load 2 packedarray cvx } forall
  535. ] /DecodeABC exch def
  536. } if
  537. dup /Matrix knownoget { /MatrixABC exch def } if
  538. dup /BlackPoint knownoget { /BlackPoint exch def } if
  539. dup /WhitePoint knownoget { /WhitePoint exch def } if
  540. /PDFColorSpace exch def [ /CIEBasedABC currentdict end ]
  541. } bdef
  542. /CalCMYK {
  543. pop /DeviceCMYK % not defined by Adobe
  544. } bdef
  545. /Lab {
  546. 1 oget 6 dict begin
  547. dup /Range knownoget not { [-100 100 -100 100] } if
  548. [0 100 null null null null] dup 2 4 -1 roll putinterval
  549. /RangeABC exch def
  550. /DecodeABC [{16 add 116 div} bind {500 div} bind {200 div} bind] def
  551. /MatrixABC [1 1 1 1 0 0 0 0 -1] def
  552. dup /BlackPoint knownoget { /BlackPoint exch def } if
  553. dup /WhitePoint knownoget { /WhitePoint exch def } {
  554. ( **** Warning: Lab colorspace is missing WhitePoint.\n)
  555. pdfformaterror
  556. /WhitePoint [0.9505 1 1.089] def
  557. } ifelse
  558. % scaling function g() for DecodeLMN construction
  559. { dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse }
  560. /DecodeLMN [
  561. % Store white point implicitly inside procedures.
  562. [ 3 index aload pop WhitePoint 0 get /mul .systemvar ] cvx bind
  563. [ 4 index aload pop WhitePoint 1 get /mul .systemvar ] cvx bind
  564. [ 5 index aload pop WhitePoint 2 get /mul .systemvar ] cvx bind
  565. ] def pop
  566. /PDFColorSpace exch def [ /CIEBasedABC currentdict end ]
  567. } bdef
  568. /ICCBased {
  569. dup 1 get type /dicttype ne { % don't resolve more than once
  570. PDFfile fileposition exch
  571. dup dup 1 oget
  572. mark exch { oforce } forall .dicttomark
  573. dup dup true resolvestream
  574. /ReusableStreamDecode filter /DataSource exch put
  575. 1 exch put
  576. exch PDFfile exch setfileposition
  577. % Resolve alternate color space
  578. dup 1 get % Get colorspace dictionary
  579. dup /Alternate .knownget % Check for alternate color space
  580. { oforce resolvecolorspace /Alternate exch put } % resolve and replace
  581. { pop } % remove colorspace dictionary
  582. ifelse
  583. } if
  584. } bdef
  585. /Separation {
  586. aload pop exch oforce resolvecolorspace
  587. % Contrary to PDF manuals up to v.1.5, Acrobat Distiller 3.01
  588. % can use /Identity name here instead of a function.
  589. exch oforce resolveidfnproc
  590. 4 array astore
  591. } bdef
  592. /DeviceN {
  593. [ exch aload pop ] % Copy into a new array
  594. dup dup 1 oget % Resolve Names array
  595. [ exch { oforce } forall ] % resolve each of the names
  596. 1 exch put
  597. dup dup 2 oget resolvecolorspace
  598. 2 exch put
  599. dup dup 3 oget resolvefnproc
  600. 3 exch put
  601. dup length 4 gt { % Check for attributes dict
  602. dup dup 4 oget % devn_array devn_array attr_dict
  603. dup /Colorants knownoget % Check for Colorants Dict
  604. { % Create a new attribute dict with only a Colorants dict entry.
  605. % Resolve all of the Colorant dict entries. This is needed
  606. % to prevent a conflict if we attempt to resolve the tint
  607. % transform functions of the Colorant color spaces multiple
  608. % times.
  609. exch pop % Remove old attributes dict
  610. << exch % Start new attributes dict
  611. % Build new Colorants dict with resolved entries
  612. << exch { oforce resolvecolorspace } forall >>
  613. /Colorants exch >> % Finish new attributes dict
  614. } if
  615. 4 exch put % Put resolved or new attributes dict
  616. } if
  617. } bdef
  618. /Indexed {
  619. aload pop 3 -1 roll oforce resolvecolorspace
  620. % Stack: /Indexed hival lookup basespace
  621. % If the underlying space is a Lab space, we must scale
  622. % the output of the lookup table as part of DecodeABC.
  623. dup dup type /arraytype eq { 0 get } if /CIEBasedABC eq {
  624. dup 1 get /DecodeLMN known {
  625. 1 get dup length dict copy
  626. begin /DecodeABC [ 0 2 4 {
  627. RangeABC 1 index 1 add get RangeABC 2 index get sub /mul load
  628. RangeABC 3 index get /add load
  629. DecodeABC 6 -1 roll 2 idiv get [ 6 1 roll aload pop ] cvx
  630. } for ] def
  631. /RangeABC //01_3 def
  632. currentdict end /CIEBasedABC exch 2 array astore
  633. } if
  634. } if
  635. 3 1 roll
  636. oforce dup type /stringtype ne {
  637. % The color lookup table is a stream.
  638. % Get its contents. Don't lose our place in PDFfile.
  639. % Stack: /Indexed basespace hival lookup
  640. PDFfile fileposition 5 1 roll true resolvestream
  641. % Stack: filepos /Indexed basespace hival lookupstream
  642. 1 index 1 add
  643. % Stack: filepos /Indexed basespace hival lookupstream len
  644. 3 index
  645. dup dup type /arraytype eq { 0 get } if
  646. //csncompdict exch get exec mul
  647. string dup 3 1 roll readstring pop % the string is padded with 0s
  648. length 1 index length lt {
  649. ( **** Warning: Short look-up table in the Indexed color space was padded with 0's.\n)
  650. pdfformaterror
  651. } if
  652. % Stack: filepos /Indexed basespace hival table table'
  653. 5 -1 roll PDFfile exch setfileposition
  654. }
  655. if 4 array astore
  656. % Replace the PDFColorSpace with the Indexed space if needed.
  657. dup 1 get
  658. dup type /arraytype eq {
  659. dup length 2 ge {
  660. dup 1 get type /dicttype eq {
  661. dup 1 get /PDFColorSpace known {
  662. dup 1 get /PDFColorSpace 3 index put
  663. } if
  664. } if
  665. } if
  666. } if pop
  667. } bdef
  668. /I { % Bug 689815
  669. ( **** Warning: The name /Indexed cannot be abbreviated to /I in the color space\n)
  670. pdfformaterror
  671. dup 0 /Indexed put
  672. //Indexed exec
  673. } bdef
  674. /Pattern {
  675. dup type /nametype ne {
  676. dup length 1 gt {
  677. 1 oget resolvecolorspace
  678. /Pattern exch 2 array astore
  679. } if
  680. } if
  681. } bdef
  682. currentdict end readonly def
  683. /cssubst { % <csname> cssubst <cspace'> true
  684. % <csname> cssubst false
  685. dup resolvecolorspace
  686. dup 1 index ne { exch pop true } { pop pop false } ifelse
  687. } bdef
  688. /csnames mark
  689. /DeviceGray dup /DeviceRGB dup /DeviceCMYK dup /Pattern dup
  690. .dicttomark readonly def
  691. /csresolve { % <csresourcename> csresolve <cspace>
  692. dup type /nametype ne {
  693. (\n **** Warning: CS/cs (setcolorspace) operand not a name: ) pdfformaterror
  694. dup stderrfile dup 3 -1 roll write==only flushfile
  695. ( ****\n) pdfformaterror
  696. dup type /arraytype eq { % Adobe InDesign + PDF Library has array
  697. resolvecolorspace
  698. } if
  699. } {
  700. dup Page /ColorSpace rget {
  701. exch pop resolvecolorspace
  702. } {
  703. //csnames 1 index known not { /undefined cvx signalerror } if
  704. } ifelse
  705. } ifelse
  706. } bdef
  707. /resolvecolorspace { % <cspace> resolvecolorspace <cspace'>
  708. dup dup type /arraytype eq { 0 get } if
  709. //csrdict exch .knownget
  710. {
  711. exec dup type /nametype ne { dup length 1 eq { 0 get } if } if
  712. } {
  713. dup type /nametype eq { csresolve } { csset exch pop } ifelse
  714. } ifelse
  715. } bdef
  716. /scresolve { % <c0> ... scresolve <multi>
  717. % We can't really make sc[n] and SC[N] work, because
  718. % the color space information isn't available at
  719. % conversion time; so we hack it by assuming that
  720. % all the operands on the stack are used, and that
  721. % if the top operand is a name, it's a Pattern resource.
  722. dup type /nametype eq
  723. { Page /Pattern rget { resolvepattern } { null } ifelse }
  724. if
  725. dup type /dicttype eq {
  726. % Check the PaintType, if any (shading patterns don't
  727. % have one).
  728. dup /PaintType knownoget { 2 eq } { false } ifelse
  729. } {
  730. .pdfcount 1 gt
  731. } ifelse
  732. } bdef
  733. /.pdfpaintproc { % <patdict> <resdict> .pdfpaintproc -
  734. PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { true } ifelse { (%Begin PaintProc) print dup === flush } if } if
  735. PDFfile fileposition 3 1 roll
  736. q
  737. 1 index /PaintType oget 1 eq {
  738. % For colored patterns, set default fill and stroke colors.
  739. 0 g 0 G
  740. } {
  741. % For uncolored patterns, we have to unbind the current
  742. % color and color space before running the PaintProc.
  743. //null sc1 //null SC1
  744. } ifelse
  745. % Save old values on opstack, set pdfemptycount to new value.
  746. pdfemptycount countdictstack
  747. /pdfemptycount count 3 sub def 4 2 roll
  748. %
  749. % Stack: ... <old emptycount> <dictcount> <patdict> <resdict>
  750. % |
  751. % New empty count points here -----+
  752. exch //false resolvestream pdfopdict .pdfruncontext
  753. countdictstack exch sub dup 0 gt {
  754. ( **** Warning: Pattern stream has unbalanced q/Q operators \(too many q's\)\n)
  755. pdfformaterror
  756. { Q } repeat
  757. } {
  758. pop
  759. } ifelse
  760. % restore pdfemptycount
  761. /pdfemptycount exch def
  762. Q
  763. PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { //true } ifelse { (%End PaintProc) print dup === flush } if } if
  764. PDFfile exch setfileposition
  765. } bdef
  766. /resolvepattern { % <patternstreamdict> resolvepattern <patterndict>
  767. % Don't do the resolvestream now: just capture the data
  768. % from the file if necessary.
  769. dup length dict copy
  770. dup /FilePosition .knownget {
  771. 1 index /File get dup fileposition 3 1 roll
  772. % Stack: dict savepos pos file
  773. dup 3 -1 roll setfileposition
  774. dup 3 index /Length knownoget {
  775. dup 65535 le {
  776. dup 0 eq {
  777. pop pop ()
  778. } {
  779. string readstring pop
  780. } ifelse
  781. } {
  782. () /SubFileDecode filter /ReusableStreamDecode filter
  783. } ifelse
  784. } {
  785. 0 (endstream) /SubFileDecode filter /ReusableStreamDecode filter
  786. } ifelse
  787. % Stack: dict savepos file string
  788. 3 1 roll exch setfileposition
  789. 1 index /File 3 -1 roll put
  790. dup /FilePosition undef
  791. } if
  792. dup /Shading knownoget {
  793. resolveshading 1 index /Shading 3 -1 roll put
  794. } if
  795. dup /PaintProc [
  796. % Bind the resource dictionary into the PaintProc.
  797. 2 index /Resources knownoget { oforce } { 0 dict } ifelse
  798. /.pdfpaintproc cvx
  799. ] cvx put
  800. dup /.pattern_uses_transparency 1 index patternusestransparency put
  801. PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { true } ifelse { (%Pattern: ) print dup === flush } if } if
  802. } bdef
  803. /ignore_color_op ( **** Warning: Ignoring a color operation in a cached context.\n) readonly def
  804. drawopdict begin
  805. /g { .incachedevice { % Bug 689302
  806. pop //ignore_color_op pdfformaterror
  807. } {
  808. /DeviceGray cssubst { cs sc1 } { g } ifelse
  809. } ifelse
  810. } bdef
  811. /rg { .incachedevice {
  812. pop pop pop //ignore_color_op pdfformaterror
  813. } {
  814. /DeviceRGB cssubst { cs sc* } { rg } ifelse
  815. } ifelse
  816. } bdef
  817. /k { .incachedevice {
  818. pop pop pop pop //ignore_color_op pdfformaterror
  819. } {
  820. k
  821. } ifelse
  822. } bdef
  823. /cs { .incachedevice {
  824. pop //ignore_color_op pdfformaterror
  825. } {
  826. csresolve cs
  827. } ifelse
  828. } bdef
  829. /sc { .incachedevice {
  830. .pdfcount { pop } repeat //ignore_color_op pdfformaterror
  831. } {
  832. scresolve { sc* } { sc1 } ifelse
  833. } ifelse
  834. } bdef
  835. /scn /sc load def
  836. /G { .incachedevice {
  837. pop //ignore_color_op pdfformaterror
  838. } {
  839. /DeviceGray cssubst { CS SC1 } { G } ifelse
  840. } ifelse
  841. } bdef
  842. /RG { .incachedevice {
  843. pop pop pop //ignore_color_op pdfformaterror
  844. } {
  845. /DeviceRGB cssubst { CS SC* } { RG } ifelse
  846. } ifelse
  847. } bdef
  848. /K { .incachedevice {
  849. pop pop pop pop //ignore_color_op pdfformaterror
  850. } {
  851. K
  852. } ifelse
  853. } bdef
  854. /CS { .incachedevice {
  855. pop //ignore_color_op pdfformaterror
  856. } {
  857. csresolve CS
  858. } ifelse
  859. } bdef
  860. /ri { .incachedevice {
  861. pop //ignore_color_op pdfformaterror
  862. } {
  863. ri
  864. } ifelse
  865. } bdef
  866. /SC { .incachedevice {
  867. .pdfcount { pop } repeat //ignore_color_op pdfformaterror
  868. } {
  869. scresolve { SC* } { SC1 } ifelse
  870. } ifelse
  871. } bdef
  872. /SCN /SC load def
  873. end
  874. currentdict /ignore_color_op undef
  875. % ---------------- Paths ---------------- %
  876. drawopdict begin
  877. % Path construction
  878. /m /moveto load def
  879. /l /lineto load def
  880. /c /curveto load def
  881. /v { currentpoint 6 2 roll curveto } bdef
  882. /y { 2 copy curveto } bdef
  883. /re {
  884. 4 2 roll moveto exch dup 0 rlineto 0 3 -1 roll rlineto neg 0 rlineto
  885. closepath
  886. } bdef
  887. /h /closepath load def
  888. % Path painting and clipping
  889. /n { n } def
  890. /S { S } def
  891. /s { s } def
  892. /f { f } def
  893. /f* { f* } def
  894. /B { B } def
  895. /b { b } def
  896. /B* { B* } def
  897. /b* { b* } def
  898. /W { W } def
  899. /W* { W* } def
  900. /sh {
  901. OFFlevels length 0 eq {
  902. setfillstate resolvesh
  903. gsave 0 .setoverprintmode
  904. dup /.shading .knownget {
  905. exch
  906. pop
  907. } {
  908. dup
  909. .buildshading
  910. dup 3 1 roll /.shading exch put
  911. } ifelse
  912. .shfill grestore
  913. } {
  914. pop
  915. } ifelse
  916. } bdef
  917. end
  918. % ---------------- XObjects ---------------- %
  919. /xobjectprocs mark % <dict> -proc- -
  920. /Image { DoImage }
  921. /Form { DoForm }
  922. /PS { DoPS }
  923. .dicttomark readonly def
  924. % Note that the keys in defaultdecodedict are resolved (PostScript, not PDF)
  925. % color space names.
  926. /defaultdecodedict mark
  927. /DeviceGray { pop //01_1 } bind
  928. /DeviceRGB { pop //01_3 } bind
  929. /DeviceCMYK { pop //01_4 } bind
  930. /CIEBasedA { 1 get /RangeA knownoget not { //01_1 } if } bind
  931. /CIEBasedABC { 1 get /RangeABC knownoget not { //01_3 } if } bind
  932. /ICCBased {
  933. 1 oget dup /Range knownoget {
  934. exch pop
  935. }{
  936. /N get [ exch {0 1} repeat ] readonly
  937. } ifelse
  938. } bind
  939. /Separation { pop //01_1 } bind
  940. /DeviceN {
  941. 1 oget length [ exch {0 1} repeat ] readonly
  942. } bind
  943. /Indexed {
  944. pop [ 0 1 BitsPerComponent bitshift 1 sub ]
  945. } bind
  946. .dicttomark readonly def
  947. /checkaltimage { % <resdict> checkaltimage <resdict[']>
  948. Printed {
  949. dup /Alternates knownoget {
  950. {
  951. dup /DefaultForPrinting knownoget {
  952. {
  953. /Image oget exch pop exit
  954. } {
  955. pop
  956. } ifelse
  957. } {
  958. pop
  959. } ifelse
  960. } forall
  961. } if
  962. } if
  963. } bdef
  964. % <string> <index> getu16 <integer>
  965. /getu16 {
  966. 2 copy get 8 bitshift 3 1 roll 1 add get add
  967. } bind def
  968. % <string> <index> getu32 <integer>
  969. /getu32 {
  970. 2 copy getu16 16 bitshift 3 1 roll 2 add getu16 add
  971. } bind def
  972. /jp2_csp_dict <<
  973. 16 { /sRGB /ColorSpace findresource } bind
  974. 18 1 index % YCC is convertrd to RGB
  975. 17 { /sGray /ColorSpace findresource } bind
  976. >> readonly def
  977. % Process jp2 blocks (aka boxes). All procedures have the signature
  978. % <file> <length> -> ... <file> <flush_length>
  979. /jp2_tag_dict <<
  980. /jp2h { % descend into a sub-stream, don't return.
  981. () /SubFileDecode filter 0
  982. } bind
  983. /ihdr {
  984. 14 sub % file len-14
  985. 1 index 14 string readstring pop % file len-14 (14)
  986. /Components 1 index 8 getu16 % file len-14 (14) /Components NC
  987. def % file len-14 (14)
  988. 10 get 16#7F and 1 add
  989. 8 .min % color depth is reduced in the library
  990. /BitsPerComponent exch def % file len-14
  991. } bind
  992. /colr {
  993. currentdict /ColorSpace known not {
  994. 3 sub
  995. 1 index 3 string readstring pop % file len-3 (3)
  996. 0 get dup 1 eq {
  997. pop 4 sub % file len-7
  998. 1 index 4 string readstring pop % file len-16 (4)
  999. 0 getu32 % file len-16 enum
  1000. //jp2_csp_dict exch .knownget {
  1001. exec /ColorSpace exch def % file len-7
  1002. } {
  1003. ( **** Warning: Unknown enumerated color space in JPX stream.\n)
  1004. pdfformaterror
  1005. } ifelse
  1006. } {
  1007. 2 eq {
  1008. 3 dict begin
  1009. /N /Components load def
  1010. string 1 index exch readstring pop % file ()
  1011. /ReusableStreamDecode filter /DataSource exch def
  1012. currentdict end
  1013. /ICCBased exch 2 array astore
  1014. /ColorSpace exch % file /ColorSpace [...]
  1015. def 0 % file 0
  1016. } {
  1017. ( **** Warning: Unknown color space method in JPX stream.\n)
  1018. pdfformaterror
  1019. } ifelse
  1020. } ifelse
  1021. } if
  1022. } bind
  1023. % Palette colors are decoded by the library.
  1024. % For now, ignore 'pclr' table.
  1025. /pclr { }
  1026. >> readonly def
  1027. % Parse jp2 file format to get color space and image depth info.
  1028. % <file> get_jp2_csp -
  1029. /get_jp2_csp {
  1030. {
  1031. dup (01234567) readstring pop % f (LBoxTBox)
  1032. dup length 8 lt {
  1033. pop exit
  1034. } if
  1035. dup 4 4 getinterval exch % f (TBox) (LBoxTBox)
  1036. 0 getu32 % f (TBox) LBox
  1037. dup 0 eq {
  1038. pop pop exit % cannot happen
  1039. } {
  1040. dup 1 eq {
  1041. pop 1 index (01234567) readstring pop
  1042. 4 getu32 % f (TBox) LBox
  1043. 16 sub
  1044. } {
  1045. 8 sub
  1046. } ifelse
  1047. } ifelse % f (TBox) LBox-8..16
  1048. PDFDEBUG {
  1049. 2 copy 2 packedarray == % f (TBox) LBox-8..16
  1050. } if
  1051. //jp2_tag_dict 3 -1 roll .knownget {
  1052. exec
  1053. } if % f flush
  1054. dup 0 ne {
  1055. 1 index exch % f f flush
  1056. () /SubFileDecode filter flushfile % skip unwanted blocks
  1057. } {
  1058. pop
  1059. } ifelse
  1060. } loop
  1061. pop
  1062. } bind def
  1063. currentdict /jp2_tag_dict .undef
  1064. currentdict /jp2_csp_dict .undef
  1065. /makeimagedict { % <resdict> <newdict> makeimagedict <imagemask>
  1066. % On return, newdict' is currentdict
  1067. begin
  1068. /Width 2 copy oget def
  1069. /Height 2 copy oget def
  1070. % Handle missing BitsPerComponent later.
  1071. /BitsPerComponent 2 copy knownoget { def } { pop } ifelse
  1072. /Interpolate 2 copy knownoget { def } { pop } ifelse
  1073. makeimagekeys
  1074. } bdef
  1075. /makeimagekeys { % <resdict> makeimagekeys <imagemask>
  1076. % newdict is currentdict
  1077. % Assumes Width, Height, BPC, Interpolate already copied.
  1078. /ImageType 1 def
  1079. /ImageMatrix Width 0 0
  1080. % Handle 0-height images specially.
  1081. Height dup 0 eq { pop 1 } if neg 0 1 index neg
  1082. 6 array astore def
  1083. dup /ImageMask knownoget dup { and } if {
  1084. % Image mask
  1085. % Decode is required for the PostScript image operators.
  1086. % AI8 writes bogus decode array [0 1 0 0 0 0 0 0]
  1087. /Decode 2 copy knownoget { 0 2 getinterval } { //01_1 } ifelse def
  1088. % BitsPerComponent is optional for masks.
  1089. /BitsPerComponent 2 copy known { pop } { 1 def } ifelse
  1090. % Even though we're going to read data,
  1091. % pass false to resolvestream so that
  1092. % it doesn't try to use Length (which may not be present).
  1093. //false resolvestream /DataSource exch def
  1094. //true
  1095. } {
  1096. % Opaque image
  1097. dup /ColorSpace oknown
  1098. 1 index /BitsPerComponent oknown and not {
  1099. dup /Filter knownoget {
  1100. dup type /arraytype eq {
  1101. dup length
  1102. dup 0 gt {
  1103. 1 sub get oforce
  1104. } {
  1105. pop
  1106. } ifelse
  1107. } if
  1108. /JPXDecode eq {
  1109. % JPXDecode filters can omit the /ColorSpace and /BitsPerComponent
  1110. % keys, in which case the interpreter must retrieve this information
  1111. % from inside the compressed stream. Here we substitute the most
  1112. % likely values as a work-around.
  1113. dup /IDFlag known {
  1114. ( **** Warning: PDF spec bans inline JPX images.\n) pdfformaterror
  1115. % Inline stream is not positionable. Cannot get ColorSpace.
  1116. } {
  1117. % Drop the last filter (JPXDecode) from the pipeline
  1118. dup dup length dict copy
  1119. dup /Filter oget
  1120. dup type /arraytype eq {
  1121. dup length 1 gt {
  1122. dup length 1 sub 0 exch getinterval
  1123. 1 index exch /Filter exch put
  1124. dup /Params knownoget {
  1125. dup type /arraytype eq {
  1126. dup length 1 gt {
  1127. dup length 1 sub 0 exch getinterval
  1128. 1 index exch /Params exch put
  1129. } {
  1130. pop
  1131. dup /Params undef
  1132. } ifelse
  1133. } {
  1134. pop
  1135. dup /Params undef
  1136. } ifelse
  1137. } if
  1138. } {
  1139. pop
  1140. dup /Filter undef
  1141. dup /Params undef
  1142. } ifelse
  1143. } {
  1144. pop
  1145. dup /Filter undef
  1146. dup /Params undef
  1147. } ifelse
  1148. //false resolvestream get_jp2_csp
  1149. } ifelse
  1150. } if
  1151. } if
  1152. currentdict /BitsPerComponent oknown not {
  1153. ( **** Warning: image has no /BitsPerComponent key; assuming 8 bit.\n)
  1154. pdfformaterror
  1155. /BitsPerComponent 8 def
  1156. } if
  1157. } if
  1158. currentdict /ColorSpace knownoget not {
  1159. dup /ColorSpace knownoget not {
  1160. ( **** Warning: image has no /ColorSpace key; assuming /DeviceRGB.\n)
  1161. pdfformaterror
  1162. /DeviceRGB
  1163. } if
  1164. } if
  1165. resolvecolorspace /ColorSpace exch def
  1166. % Decode is required for the PostScript image operators.
  1167. /Decode 2 copy knownoget not {
  1168. ColorSpace //defaultdecodedict
  1169. ColorSpace dup type /arraytype eq { 0 get } if get exec
  1170. } if def
  1171. % Even though we're going to read data,
  1172. % pass false to resolvestream so that
  1173. % it doesn't try to use Length (which may not be present).
  1174. //false resolvestream /DataSource exch def
  1175. //false
  1176. } ifelse
  1177. } bdef
  1178. /DoImage {
  1179. checkaltimage dup length 6 add dict
  1180. 1 index /SMask knownoget { 1 index exch /SMask exch put } if
  1181. 1 index /Mask knownoget { 1 index exch /Mask exch put } if
  1182. makeimagedict doimagesmask
  1183. } bdef
  1184. /makemaskimage { % <datasource> <imagemask> <Mask> makemaskimage
  1185. % <datasource> <imagemask>, updates currentdict =
  1186. % imagedict
  1187. dup type /arraytype eq {
  1188. /ImageType 4 def
  1189. % Check that every element of the Mask is an integer.
  1190. //false 1 index {
  1191. type /integertype ne or
  1192. } forall {
  1193. (\n **** Warning: Some elements of Mask array are not integers.\n)
  1194. pdfformaterror
  1195. [ exch { 0.5 add cvi } forall ] % following AR4, 5, 6 implementation
  1196. } if
  1197. % Check elements of array are within 0::(2**BitsPerComponent)-1
  1198. % This is a PostScript error, but AR ignores Mask in that case
  1199. 1 BitsPerComponent bitshift 1 sub //false 2 index {
  1200. % stack: max_value result_bool value
  1201. dup 0 lt exch 3 index gt or or
  1202. } forall exch pop {
  1203. (\n **** Warning: Some elements of Mask array are out of range.\n)
  1204. pdfformaterror
  1205. [ exch { 1 BitsPerComponent bitshift 1 sub and } forall ] % AR5 does this
  1206. } if
  1207. /MaskColor exch def
  1208. } {
  1209. % Mask is a stream, another Image XObject.
  1210. % Stack: datasource imagemask(false) maskstreamdict
  1211. PDFfile fileposition exch
  1212. dup length dict makeimagedict pop
  1213. % In order to prevent the two data sources from being
  1214. % aliased, we need to make at least one a reusable stream.
  1215. % We pick the mask, since it's smaller (in case we need to
  1216. % read all its data now).
  1217. % Stack: datasource imagemask(false) savedpos
  1218. % maskdict is currentdict
  1219. /DataSource DataSource mark
  1220. /Intent 1
  1221. /AsyncRead true
  1222. .dicttomark .reusablestreamdecode def
  1223. PDFfile exch setfileposition
  1224. currentdict end currentdict end
  1225. 5 dict begin
  1226. /ImageType 3 def
  1227. /InterleaveType 3 def
  1228. /DataDict exch def
  1229. /MaskDict exch def
  1230. /ColorSpace DataDict /ColorSpace get def
  1231. } ifelse
  1232. } bdef
  1233. /doimagesmask { % <imagemask> doimagesmask -
  1234. PDFusingtransparency {
  1235. currentdict /SMask knownoget
  1236. } {
  1237. false
  1238. } ifelse
  1239. { % We are doing transparency and SMask is present in the image
  1240. % stack: <imagemask> <SMask>
  1241. currentdevice .devicename /pdfwrite eq {
  1242. pop % pdfwrite will process SMask directly during 'doimage'
  1243. } {
  1244. .begintransparencymaskimage
  1245. PDFfile fileposition exch
  1246. gsave //nodict begin
  1247. null /SoftMask gput
  1248. 1 .setopacityalpha 1 .setshapealpha
  1249. 1 CA 1 ca
  1250. /Compatible .setblendmode
  1251. DoImage
  1252. end grestore
  1253. PDFfile exch setfileposition
  1254. 0 .endtransparencymask
  1255. } ifelse
  1256. << /Subtype /Group /Isolated true
  1257. /.image_with_SMask true % pdfwrite needs : see gs/src/ztrans.c, gs/src/gdevpdft.c
  1258. >> 0 0 1 1 .begintransparencygroup
  1259. doimage
  1260. .endtransparencygroup
  1261. } {
  1262. SoftMask //null ne {
  1263. % the image doesn't have an SMask, but the ExtGState does, force a group.
  1264. << /Subtype /Group /Isolated true >> 0 0 1 1 .begintransparencygroup
  1265. doimage
  1266. .endtransparencygroup
  1267. }
  1268. { doimage }
  1269. ifelse
  1270. } ifelse
  1271. } bdef
  1272. % For development needs we define a special option for running with a new handler
  1273. % for images with a soft mask.
  1274. //systemdict /NEW_IMAGE3X .knownget not { //false } if {
  1275. /doimagesmask { % <imagemask> doimagesmask -
  1276. doimage
  1277. } bdef
  1278. } if
  1279. /is_big_mask { % - is_big_mask <bool>
  1280. 1 0 dtransform dup mul exch dup mul sqrt add
  1281. 0 1 dtransform dup mul exch dup mul sqrt add mul
  1282. currentdevice getdeviceprops .dicttomark /BufferSpace .knownget not {
  1283. 4000000 % hack: Can't get the real default value from C source.
  1284. } if
  1285. 2 % arbitrary
  1286. div gt
  1287. } bind def
  1288. % For development needs we define a special option for running with a new handler
  1289. % for images with a soft mask.
  1290. //systemdict /NEW_IMAGE3X .knownget not { //false } if {
  1291. /is_big_mask { % - is_big_mask <bool>
  1292. //false
  1293. } bdef
  1294. } if
  1295. /doimage { % <imagemask> doimage -
  1296. % imagedict is currentdict, gets popped from dstack
  1297. DataSource exch
  1298. PDFusingtransparency
  1299. currentdevice .devicename /pdfwrite ne {
  1300. % This is a temporary workaround for the bug 689080,
  1301. % which is done under a rush of 8.63 release.
  1302. % The purpose is to disable a conversion of an image with soft mask
  1303. % into a Type 103 image, which currently allocates a full mask buffer
  1304. % before writing clist.
  1305. % With this workaround the Matte color is not working (ignored).
  1306. is_big_mask not
  1307. } {
  1308. true % pdfwrite doesn't need the workaround explained above,
  1309. % and cannot work with it.
  1310. } ifelse
  1311. and {
  1312. currentdict /SMask knownoget
  1313. } {
  1314. false
  1315. } ifelse {
  1316. makesoftmaskimage
  1317. } {
  1318. currentdict /Mask knownoget {
  1319. makemaskimage
  1320. } if
  1321. } ifelse
  1322. % Stack: datasource imagemask
  1323. { currentdict end setfillstate { imagemask } }
  1324. { ColorSpace setgcolorspace currentdict end setfillblend { image } }
  1325. ifelse
  1326. stopped {
  1327. dup type /dicttype eq { pop } if % Sometimes image fails to restore the stack
  1328. $error /errorname get dup /ioerror eq {
  1329. pop (\n **** Warning: File has insufficient data for an image.\n)
  1330. pdfformaterror
  1331. } {
  1332. (\n **** Warning: File encountered ')
  1333. exch 40 string cvs concatstrings
  1334. (' error while processing an image.\n) concatstrings
  1335. pdfformaterror
  1336. } ifelse
  1337. } if
  1338. % Close the input stream, unless it is PDFfile or
  1339. % PDFsource.
  1340. dup dup PDFfile eq exch PDFsource eq or { pop } { closefile } ifelse
  1341. } bdef
  1342. /.paintform { % <formdict> <resdict> <stream> .paintform -
  1343. 3 -1 roll dup /Group known PDFusingtransparency and {
  1344. .paintgroupform
  1345. } {
  1346. pop pdfopdict .pdfruncontext
  1347. } ifelse
  1348. } bdef
  1349. /DoForm {
  1350. % Adobe 2nd edition of the PDF 1.3 spec makes /FormType
  1351. % and /Matrix keys optional. Cope with the missing keys.
  1352. begin <<
  1353. currentdict /FormType known not { /FormType 1 } if
  1354. currentdict /Matrix known not { /Matrix { 1 0 0 1 0 0 } cvlit } if
  1355. currentdict end { oforce } forall
  1356. >>
  1357. dup [ 2 index /Resources knownoget { oforce } { 0 dict } ifelse
  1358. 3 index false /resolvestream cvx
  1359. /.paintform cvx
  1360. ] cvx /PaintProc exch put
  1361. % Adjust pdfemptycount since we have an extra dictionary on the stack
  1362. pdfemptycount countdictstack 3 -1 roll
  1363. /pdfemptycount count 2 sub store
  1364. q execform % gsave / grestore around the Form
  1365. % Restore pdfemptycount
  1366. countdictstack exch sub
  1367. dup 1 gt {
  1368. ( **** Warning: Pattern stream has unbalanced q/Q operators \(too many q's\)\n)
  1369. pdfformaterror
  1370. } if
  1371. { Q } repeat
  1372. /pdfemptycount exch store
  1373. } bdef
  1374. /_dops_save 1 array def
  1375. /DoPS {
  1376. DOPS
  1377. {
  1378. //_dops_save 0 save put
  1379. true resolvestream cvx exec
  1380. //_dops_save 0 get restore
  1381. }
  1382. { pop }
  1383. ifelse
  1384. } bdef
  1385. currentdict /_dops_save undef
  1386. /ocg_pocs 4 dict begin
  1387. /AllOn {
  1388. //true exch {
  1389. oforce dup type /dicttype eq {
  1390. /OFF known not and
  1391. } {
  1392. pop
  1393. } ifelse
  1394. } forall
  1395. } bdef
  1396. /AnyOn {
  1397. //false exch {
  1398. oforce dup type /dicttype eq {
  1399. /OFF known not or
  1400. } {
  1401. pop
  1402. } ifelse
  1403. } forall
  1404. } bdef
  1405. /AnyOff {
  1406. //AllOn exec not
  1407. } bdef
  1408. /AllOff {
  1409. //AnyOn exec not
  1410. } bdef
  1411. currentdict end readonly def
  1412. % Check whether OCG or OCMD is visible
  1413. % <dict> oc-is-visible <bool>
  1414. /ocg-is-visible {
  1415. dup /Type knownoget {
  1416. /OCMD eq {
  1417. dup /OCGs knownoget not { {} } if % OC OCGs
  1418. dup type /dicttype eq { 1 array astore } if
  1419. //true 1 index { //null eq and } forall {
  1420. pop pop //true % all nulls => show
  1421. } {
  1422. exch /P knownoget not { /AnyOn } if % OCGs P
  1423. //ocg_pocs exch get exec % bool
  1424. } ifelse
  1425. } {
  1426. /OFF known not % OFF is inserted by process_trailer_attrs
  1427. } ifelse
  1428. } {
  1429. /OFF known not % OFF is inserted by process_trailer_attrs
  1430. } ifelse
  1431. } bdef
  1432. drawopdict begin
  1433. /Do { % /Name
  1434. setfillblend
  1435. PDFfile fileposition exch % pos /Name
  1436. dup Page /XObject rget {
  1437. exch pop % pos obj
  1438. OFFlevels length 0 eq {
  1439. dup /OC knownoget { ocg-is-visible } { //true } ifelse
  1440. } {
  1441. //false
  1442. } ifelse {
  1443. dup /Subtype get //xobjectprocs exch get % pos obj {proc}
  1444. % Don't leave extra objects on the stack while executing
  1445. % the definition of the form.
  1446. 3 -1 roll % obj {proc} pos
  1447. 2 .execn % pos
  1448. } {
  1449. pop % pos
  1450. } ifelse
  1451. } {
  1452. % This should cause an error, but Acrobat Reader can
  1453. % continue, so we do too.
  1454. ( **** Undefined XObject resource: )
  1455. exch =string cvs concatstrings (\n) concatstrings
  1456. pdfformaterror
  1457. } ifelse
  1458. PDFfile exch setfileposition
  1459. } bdef
  1460. end
  1461. currentdict /xobjectprocs .undef
  1462. currentdict /ocg_pocs .undef
  1463. % ---------------- In-line images ---------------- %
  1464. % Undo the abbreviations in an in-line image dictionary.
  1465. % Note that we must look inside array values.
  1466. % /I is context-dependent.
  1467. /unabbrevkeydict mark
  1468. /BPC /BitsPerComponent /CS /ColorSpace /D /Decode /DP /DecodeParms
  1469. /F /Filter /H /Height /I /Interpolate /IM /ImageMask /W /Width
  1470. .dicttomark readonly def
  1471. /unabbrevvaluedict mark
  1472. /AHx /ASCIIHexDecode /A85 /ASCII85Decode /CC /CalCMYK
  1473. /CCF /CCITTFaxDecode /CG /CalGray /CR /CalRGB
  1474. /DCT /DCTDecode /CMYK /DeviceCMYK /Fl /FlateDecode
  1475. /G /DeviceGray /RGB /DeviceRGB
  1476. /I /Indexed /LZW /LZWDecode /RL /RunLengthDecode
  1477. .dicttomark readonly def
  1478. /unabbrevtypedict mark
  1479. /nametype {
  1480. //unabbrevvaluedict 1 index .knownget { exch pop } if
  1481. }
  1482. /arraytype {
  1483. dup 0 1 2 index length 1 sub {
  1484. 2 copy get unabbrevvalue put dup
  1485. } for pop
  1486. }
  1487. .dicttomark readonly def
  1488. /unabbrevvalue { % <obj> unabbrevvalue <obj'>
  1489. oforce //unabbrevtypedict 1 index type .knownget { exec } if
  1490. } bdef
  1491. /is_space_dict << 0 0 9 9 10 10 12 12 13 13 32 32 >> readonly def
  1492. drawopdict begin
  1493. /BI { mark } bdef
  1494. /ID {
  1495. counttomark 2 idiv dup 7 add dict begin {
  1496. exch //unabbrevkeydict 1 index .knownget { exch pop } if
  1497. exch unabbrevvalue def
  1498. } repeat pop
  1499. /IDFlag true def % flag for stream processing.
  1500. /File PDFsource def
  1501. currentdict makeimagekeys
  1502. OFFlevels length 0 eq {
  1503. doimage
  1504. } {
  1505. Width
  1506. 1 index /ImageMask knownoget dup { and } if not {
  1507. 1 index /ColorSpace oget
  1508. dup type /arraytype eq { 0 oget } if
  1509. //csncompdict exch get exec
  1510. BitsPerComponent mul
  1511. } if
  1512. 7 add 8 idiv Height mul
  1513. DataSource exch () /SubFileDecode filter flushfile
  1514. end
  1515. } ifelse
  1516. % The Adobe documentation says that the data following ID
  1517. % consists of "lines", and some PDF files (specifically, some files
  1518. % produced by PCL2PDF from Visual Software) contain garbage bytes
  1519. % between the last byte of valid data and an EOL.
  1520. % Some files (PDFOUT v3.8d by GenText) have EI immediately following
  1521. % the stream. Some have no EOL and garbage bytes.
  1522. % Sometimes (bug 690300) CCITTDecode filter consumes 'E' in 'EI'.
  1523. % Therefore, we search for <start>I<sp|end> or <start|sp>EI<sp|end>
  1524. PDFsource read not {
  1525. /ID cvx /syntaxerror signalerror
  1526. } if
  1527. dup 73 eq {
  1528. pop 10 69 73 % Seed to: <sp>EI
  1529. } {
  1530. 10 10 3 -1 roll % Seed to: <sp><sp><any>
  1531. } ifelse
  1532. { PDFsource read not dup { 10 exch } if
  1533. //is_space_dict 2 index known
  1534. 3 index 73 eq and 4 index 69 eq and
  1535. //is_space_dict 6 index known and {
  1536. pop pop pop pop pop exit
  1537. } {
  1538. {
  1539. pop pop pop /ID cvx /syntaxerror signalerror
  1540. } {
  1541. 4 -1 roll pop
  1542. } ifelse
  1543. } ifelse
  1544. } loop
  1545. } bdef
  1546. end
  1547. currentdict /is_space_dict undef
  1548. % ================================ Text ================================ %
  1549. drawopdict begin
  1550. % Text control
  1551. /BT { BT } def
  1552. /ET { ET } def
  1553. /Tc { Tc } def
  1554. /TL { TL } def
  1555. /Tr { Tr } def
  1556. /Ts { Ts } def
  1557. /Tw { Tw } def
  1558. /Tz { Tz } def
  1559. % Text positioning
  1560. /Td { Td } def
  1561. /TD { TD } def
  1562. /Tm { Tm } def
  1563. /T* { T* } def
  1564. % Text painting
  1565. /Tj { Tj } def
  1566. /' { ' } def
  1567. /" { " } def
  1568. /TJ { TJ } def
  1569. /Tform { Tform } def % Text formatting and painting for AcroForm
  1570. % without appearance streams.
  1571. end
  1572. % ======================= Invalid operators ============================ %
  1573. drawopdict begin
  1574. /QBT {
  1575. Q BT
  1576. ( **** Warning: invalid operator QBT processed as Q BT .\n)
  1577. pdfformaterror % Bug 690089
  1578. } def
  1579. /. {
  1580. 0.
  1581. ( **** Warning: invalid operator . processed as number 0. .\n)
  1582. pdfformaterror % Bug 690730
  1583. } def
  1584. end
  1585. % ============================== Annotations ============================== %
  1586. % Get and normalize an annotation's rectangle.
  1587. /annotrect { % <annot> annotrect <x> <y> <w> <h>
  1588. /Rect oget aload pop
  1589. exch 3 index sub dup 0 lt { dup 5 -1 roll add 4 1 roll neg } if
  1590. exch 2 index sub dup 0 lt { dup 4 -1 roll add 3 1 roll neg } if
  1591. } bdef
  1592. % Set an annotation color.
  1593. /annotsetcolor { % <annot> annotsetcolor -
  1594. /C knownoget { aload pop setrgbcolor } { 0 setgray } ifelse
  1595. } bdef
  1596. % Draw the border. Currently, we ignore requests for beveling, and we
  1597. % don't round the corners of rectangles.
  1598. /strokeborder { % <annot> <width> <dash> strokeborder -
  1599. 1 index 0 ne { % do not draw if border width is 0
  1600. gsave
  1601. 2 index annotsetcolor
  1602. 0 setdash dup setlinewidth
  1603. exch annotrect
  1604. 2 { 4 index sub 4 1 roll } repeat
  1605. 2 { 4 index 0.5 mul add 4 1 roll } repeat
  1606. rectstroke pop
  1607. grestore
  1608. } {
  1609. pop pop pop
  1610. } ifelse
  1611. } bdef
  1612. % Draw an annotation border.
  1613. /drawborder { % <annot> drawborder -
  1614. gsave
  1615. dup /BS known 1 index /Border known or {
  1616. dup /BS knownoget {
  1617. dup type /dicttype ne % <annot> <border> <bad?>
  1618. } {
  1619. dup /Border oget
  1620. dup type /arraytype eq {
  1621. dup length 3 lt
  1622. } {
  1623. //true
  1624. } ifelse % <annot> [border] <bad?>
  1625. } ifelse {
  1626. ( **** Warning: Wrong annotation border object, no border is drawn.\n)
  1627. pdfformaterror
  1628. pop { 0 0 0 }
  1629. } if
  1630. dup type /dicttype eq {
  1631. dup /W knownoget not { 1 } if
  1632. % Per PDF1.6 Reference table 8.13, /W in the border style dictionary is
  1633. % expressed in points (an absolute unit), so compensate here for any
  1634. % scaling of the PostScript user space done due to /UserUnit.
  1635. % Scaling due to -dPDFFitPage is not undone, to keep the correct border width
  1636. % compared to the size of the surrounding marks.
  1637. //systemdict /NoUserUnit .knownget not { //false } if not
  1638. //systemdict /PDFFitPage known not and { % UserUnit is ignored if -dPDFFitPage
  1639. Page /UserUnit knownoget { div } if
  1640. } if
  1641. {} 2 index /S knownoget {
  1642. /D eq { 2 index /D knownoget not { {3} } if exch pop } if
  1643. } if 3 -1 roll pop strokeborder
  1644. } {
  1645. dup 2 get
  1646. exch dup length 3 gt { 3 get } { pop {} } ifelse
  1647. strokeborder
  1648. } ifelse
  1649. } {
  1650. 1 {} strokeborder
  1651. } ifelse
  1652. grestore
  1653. } bdef
  1654. %
  1655. % The PDF annotation F (flags) integer is bit encoded.
  1656. % Bit 1 (LSB) Invisible: 1 --> Do not display if no handler.
  1657. % Note: We have no handlers but we ignore this bit.
  1658. % Bit 2 Hidden: 1 --> Do not display. We will not display if this bit is set.
  1659. % Bit 3 Print: 1 --> Display if printing. We will display if this bit set
  1660. % (and not hidden) and Printed is true
  1661. % Bit 4 NoZoom: 1 --> Do not zoom annotation even if image is zoomed.
  1662. % Bit 5 NoRotate: 1 --> Do not rotate annotation even if image is rotated.
  1663. % Bit 6 NoView: 0 --> Display if this is a 'viewer'. We will display
  1664. % if this bit is not set (and not hidden) and Printed is false
  1665. % Bit 7 Read Only - 1 --> No interaction. We ignore this bit
  1666. %
  1667. /annotvisible { % <annot> annotvisible <visible>
  1668. /F knownoget not { 0 } if % Get flag value
  1669. dup 2 and 0 eq % Check hidden flag
  1670. exch dup 4 and 0 ne Printed and % Check print flag
  1671. exch 32 and 0 eq Printed not and % Check noview flag
  1672. or % Combine print and view
  1673. and % Combine with 'hidden' flag test
  1674. } bdef
  1675. /drawwidget { % <scalefactor_x> <scalefactor_y> <annot> drawwidget -
  1676. dup /AP knownoget {
  1677. dup /N known not {
  1678. ( **** Appearance dictionary (AP) lacks the mandatory normal (N) appearance.\n)
  1679. pdfformaterror
  1680. } if
  1681. //false
  1682. [/N /R /D] {
  1683. % stack: scalex scaley annot appearance false key
  1684. 2 index exch knownogetdict {
  1685. exch not exit
  1686. } if
  1687. } forall
  1688. % stack: scalex scaley annot appearance value true
  1689. % stack: scalex scaley annot appearance false
  1690. dup {
  1691. pop exch pop
  1692. % Acrobat Distiller produces files in which this Form
  1693. % XObject lacks Type and Subtype keys. This is illegal,
  1694. % but Acrobat Reader accepts it. The only way we can
  1695. % tell whether this is a Form or a set of sub-appearances
  1696. % is by testing for the stream Length or File key.
  1697. % If the stream lacks Length key, try File key.
  1698. dup /Length known 1 index /File known or {
  1699. % If this is a form then simply use it
  1700. //true
  1701. } {
  1702. 1 index /AS knownoget not {
  1703. % If we do not have AS then use any appearance
  1704. { exch pop oforce exit } forall //true
  1705. } {
  1706. % Stack: annot Ndict AS
  1707. % Get the specified appearance. If no appearance, then
  1708. % display nothing - set stack = false.
  1709. knownoget
  1710. } ifelse
  1711. } ifelse
  1712. } {
  1713. exch pop % discard useless AP dictionary
  1714. } ifelse
  1715. % Stack: scalex scaley annot appearance true
  1716. % Stack: scalex scaley annot false
  1717. {
  1718. % Draw appearance
  1719. % Initialize graphic following "7.4.4 Appearance Streams"
  1720. q graphicsbeginpage textbeginpage
  1721. 1 index annotrect pop pop translate
  1722. 3 index 3 index scale % Apply scale factors
  1723. dup /BBox knownoget {
  1724. 1 index /Matrix knownoget not { {1 0 0 1 0 0} } if
  1725. .bbox_transform pop pop
  1726. % Compensate for non-zero origin of BBox
  1727. neg exch neg exch translate
  1728. } if
  1729. DoForm Q
  1730. } if
  1731. } {
  1732. dup /FT knownoget {
  1733. /Tx eq {
  1734. % Stack: scalex scaley annot
  1735. dup /DA known 1 index /V known and {
  1736. dup /DA oget
  1737. q graphicsbeginpage textbeginpage
  1738. 1 index annotrect pop pop translate
  1739. 3 index 3 index scale % Apply scale factors
  1740. cvx exec
  1741. dup /V oget
  1742. 0 0 moveto dup false charpath pathbbox newpath 3 -1 roll
  1743. sub abs 3 1 roll sub abs
  1744. 3 index annotrect 4 2 roll pop pop
  1745. 6 index mul exch 6 index mul
  1746. % stack: scale annot V vsize hsize vrect hrect
  1747. % Calculate horizontal justification first
  1748. % horizontal can be left (Q=0), center (Q=1), or right (Q=2) justification
  1749. 3 -1 roll
  1750. % stack: scalex scaley annot V vsize vrect hrect hsize
  1751. 5 index /Q knownoget not { 0 } if % default 0 == left
  1752. dup 0 eq {
  1753. pop pop pop 0 % left justified
  1754. } {
  1755. 1 eq {
  1756. 2 div exch 2 div exch sub % centered
  1757. } {
  1758. sub % right justified (hrect - hsize)
  1759. } ifelse
  1760. } ifelse
  1761. % stack: scalex scaley annot V vsize vrect hoffset
  1762. % Center the text vertically in the rect (Acrobat Reader seems to do this)
  1763. 3 1 roll 2 div exch 2 div sub abs
  1764. % stack: scalex scaley annot V hoffset voffset
  1765. moveto show
  1766. Q
  1767. } if
  1768. } if
  1769. } if
  1770. } ifelse
  1771. pop pop pop
  1772. } bdef
  1773. % For annotation object we have to determine the size of the output rectangle
  1774. % and the size of the BBox for the form XObject. From these we calculate
  1775. % a scale factors for drawing it.
  1776. /calc_annot_scale { % <annot> calc_annot_scale <x_scale> <y_scale>
  1777. dup /Rect knownoget {
  1778. pop dup annotrect 4 2 roll pop pop % get width height size in user space
  1779. 3 -1 roll /AP knownoget {
  1780. /N knownogetdict {
  1781. dup /Matrix knownoget not { {1 0 0 1 0 0} } if
  1782. exch /BBox knownoget { % x y {matrix} [box]
  1783. exch .bbox_transform % x y x0 y0 x1 y1
  1784. 3 -1 roll sub % x y x0 x1 y1-y0
  1785. 3 1 roll exch sub % x y y1-y0 x1-x0
  1786. 2 copy mul 0 eq {
  1787. ( **** Warning: /BBox has zero width or height, which is not allowed.\n)
  1788. pdfformaterror
  1789. pop pop pop pop 1 1 % zero size -- revert to unity scaling
  1790. } {
  1791. 3 1 roll div % x x1-x0 y/(y1-y0)
  1792. 3 1 roll div % y/(y1-y0) x/(x1-x0)
  1793. exch % x/(x1-x0) y/(y1-y0)
  1794. } ifelse
  1795. } {
  1796. pop pop pop 1 1 % default to unity scaling
  1797. } ifelse % if we have /BBox
  1798. } {
  1799. pop pop 1 1
  1800. } ifelse % if we have /N
  1801. } {
  1802. pop pop 1 1
  1803. } ifelse % if we have /AP
  1804. } {
  1805. ( **** Warning: /Annot dict is missing required /Rect entry.\n)
  1806. pdfformaterror
  1807. pop 1 1
  1808. } ifelse
  1809. } bdef
  1810. % Draw an annotation.
  1811. /drawannottypes mark
  1812. /Link { % <annot> -> <false>
  1813. dup drawborder dup calc_annot_scale 3 -1 roll drawwidget //false
  1814. } bind
  1815. /Ink { % <annot> -> <annot> <true>
  1816. % <annot> -> <false>
  1817. dup /AP oknown {
  1818. //true
  1819. } {
  1820. 1 setlinewidth
  1821. 1 setlinecap
  1822. 1 setlinejoin
  1823. dup annotsetcolor
  1824. dup calc_annot_scale
  1825. 3 index annotrect pop pop translate
  1826. scale
  1827. /InkList knownoget {
  1828. { oforce
  1829. mark exch { oforce } forall
  1830. .pdfinkpath
  1831. stroke
  1832. } forall
  1833. } if
  1834. //false
  1835. } ifelse
  1836. } bind
  1837. .dicttomark readonly def
  1838. /drawannot { % <annot> drawannot -
  1839. dup annotvisible {
  1840. gsave
  1841. dup dup /Subtype knownoget {
  1842. //drawannottypes exch .knownget { exec } { //true } ifelse
  1843. {
  1844. dup calc_annot_scale 3 -1 roll drawwidget % Draw rejected annots as widgets
  1845. } if % type known
  1846. } {
  1847. pop
  1848. ( **** Warning: /Annot dict without required /Subtype entry is ignored.\n)
  1849. pdfformaterror
  1850. } ifelse
  1851. grestore
  1852. } if pop % annotvisible
  1853. } bdef
  1854. currentdict /drawannottypes undef
  1855. % ============================ AcroForm fields ============================ %
  1856. % Get an attribure of the 0th annotation of a node
  1857. /annot_oget { % <annot> /Name annot_oget <value>
  1858. 1 index /Kids knownoget {
  1859. 0 oget exch oget exch pop
  1860. } {
  1861. oget
  1862. } ifelse
  1863. } bdef
  1864. % All procedures have the signature:
  1865. % <acroform> <field> <annot|field> foo <acroform> <field> <annot|field>
  1866. /draw_terminal_field_dict 4 dict begin
  1867. /Btn {
  1868. 1 index /Tf pget not { 0 } if
  1869. dup 16#20000 and 0 ne {
  1870. pop % Push button
  1871. dup /AP known {
  1872. 1 1 2 index drawwidget
  1873. } {
  1874. (Push button without appearance stream is not yet implemented) =
  1875. } ifelse
  1876. } {
  1877. 16#10000 and 0 ne {
  1878. % Radio button
  1879. dup /AP known {
  1880. 1 index /Kids oget {
  1881. 1 1 3 -1 roll drawwidget
  1882. } forall
  1883. } {
  1884. (Radio button without appearance stream is not yet implemented) =
  1885. } ifelse
  1886. } {
  1887. % Checkbox
  1888. dup /AP known {
  1889. dup 1 1 3 -1 roll drawwidget
  1890. } {
  1891. (CkeckBox without appearance stream is not yet implemented) =
  1892. } ifelse
  1893. } ifelse
  1894. } ifelse
  1895. } bdef
  1896. /Tx {
  1897. dup /AP known {
  1898. dup 1 1 3 -1 roll drawwidget
  1899. } {
  1900. 2 index /NeedAppearances knownoget not { //false } if {
  1901. dup /AP << /N 10 dict dup cvx begin >> put
  1902. /Subtype /Form def
  1903. /BBox [ 0 0 4 index /Rect oget { oforce } forall 3 -1 roll sub abs 3 1 roll sub abs exch ] def
  1904. /Resources 3 index /DR pget not { 0 dict } if def
  1905. /File 1000 string dup 3 1 roll def
  1906. /Length 0 def
  1907. % <acroform> <field> <annot> (string)
  1908. /NullEncode filter % <acroform> <field> <annot> file
  1909. dup (BT ) writestring
  1910. 2 index /DA pget not { () } if
  1911. [ exch
  1912. { token {
  1913. dup /Tf eq {
  1914. 2 index 0 eq {
  1915. /BBox load 3 get
  1916. 0.75 mul % empirical constant
  1917. 4 -1 roll pop 3 1 roll
  1918. } if
  1919. } if
  1920. exch
  1921. } {
  1922. exit
  1923. } ifelse
  1924. } loop
  1925. ]
  1926. { 1 index exch write== } forall
  1927. dup 3 index /MaxLen pget not { 0 } if write=
  1928. dup 3 index /V pget not { () } if write==
  1929. dup 3 index /Ff pget not { 0 } if write=
  1930. dup 3 index /Q pget not { 0 } if write=
  1931. dup (Tform ET) write=
  1932. end
  1933. closefile % <acroform> <field> <annot>
  1934. dup 1 1 3 -1 roll drawwidget
  1935. } if
  1936. } ifelse
  1937. } bdef
  1938. /Ch {
  1939. (Ch is not yet implemened) ==
  1940. } bdef
  1941. /Sig {
  1942. (Sig is not yet implemened ) ==
  1943. } bdef
  1944. currentdict end def
  1945. /draw_terminal_field { % <field> draw_terminal_field -
  1946. dup /Kids knownoget { 0 oget } { dup } ifelse
  1947. dup /P knownoget {
  1948. /Page load eq {
  1949. //draw_terminal_field_dict 2 index /FT pget not { 0 } if .knownget {
  1950. exec
  1951. } if
  1952. } if
  1953. } if
  1954. pop pop
  1955. } bdef
  1956. % We distinguish 4 types of nodes on the form field tree:
  1957. % - non-terminal field - has a kid that refers to the parent (or anywhere else)
  1958. % - terminal field with separate widget annotations - has a kid that doesn't have a parent
  1959. % - terminal field with a merged widget annotation - has no kids
  1960. % - widget annotation - has /Subtype and /Rect
  1961. %
  1962. % The recursive enumeration of the form fields doesn't descend into widget annotations.
  1963. /draw_form_field { % <field> draw_form_field -
  1964. dup /Kids knownoget { % field []
  1965. dup 0 oget /Parent knownoget { % field [] kid
  1966. pop % mon-terminal field % field []
  1967. exch pop % []
  1968. { oforce draw_form_field } forall
  1969. } {
  1970. pop draw_terminal_field % separate annots % -
  1971. } ifelse
  1972. } {
  1973. draw_terminal_field % merged annotation % -
  1974. } ifelse
  1975. } bdef
  1976. /draw_acro_form { % <form> draw_acro_form -
  1977. dup /Fields knownoget {
  1978. { oforce draw_form_field } forall
  1979. } if
  1980. pop
  1981. } bdef
  1982. currentdict /draw_terminal_field_dict undef
  1983. end % pdfdict
  1984. end % GS_PDF_ProcSet
  1985. .setglobal