diff --git a/optex/base/graphics.opm b/optex/base/graphics.opm index de17178a..54ffa60d 100644 --- a/optex/base/graphics.opm +++ b/optex/base/graphics.opm @@ -313,39 +313,6 @@ \_public \inoval \incircle \ratio \lwidth \fcolor \lcolor \shadow \overlapmargins ; - \_doc ----------------------------- - Just before defining shadows, which require special graphics states), we - define means for managing these graphics states. This is important, because - otherwise our use of `\pdfpageresources` register might clash with other - packages (TikZ) or even with our other usage (slides). - - The macro \`\addextgstate`` ` shall be used for - adding more graphics states. It must be used {\em after} `\dump`. First use - of it detects PGF/TikZ and either uses its mechanism or defines our own. Our - mechanism is very similar though -- use single `/ExtGState` dictionary for all - pages (`\pdfpageresources` just points to it). - \_cod ----------------------------- - -\_def\_initpageresources{% - \_glet\_initpageresources=\_relax - \_ifcsname pgf@sys@addpdfresource@extgs@plain\_endcsname - % TikZ loaded - \_global\_slet{_addextgstate}{pgf@sys@addpdfresource@extgs@plain}% - \_else - % TikZ not loaded - \_pdfobj reserveobjnum% not to be used in iniTeX - \_xdef\_extgstatesobj{\_the\_pdflastobj}% - \_expanded{\_global\_pdfpageresources={/ExtGState \_extgstatesobj\_space 0 R}}% - \_global\_addto\_byehook{\_immediate\_pdfobj useobjnum\_extgstatesobj {<<\_extgstates>>}}% - \_gdef\_extgstates{}% - \_gdef\_addextgstate##1{\_xdef\_extgstates{\_extgstates\_space##1}}% - \_fi -} -% first initialize page resources, then execute new meaning of itself -\_def\_addextgstate#1{\_initpageresources \_addextgstate{#1}} - -\_public \addextgstate ; - \_doc ----------------------------- A shadow effect is implemented here. The shadow is equal to the silhouette of the given path in a gray-transparent color shifted by @@ -361,11 +328,27 @@ \_def\_shadowmoveto{1.8 -2.5} % vector defines shifting layer (in bp) \_def\_shadowb{1} % 2*shadowb = blurring area thickness + \_doc ----------------------------- + The `\_pdfpageresources` primitive is used to define transparency. + It does not work when used in a box. So, we use it at the beginning of + the output routine. The modification of the output routine is done + using \`\_insertshadowresources` only once when the shadow effect is used first. + \_cod ----------------------------- + \_def\_insertshadowresources{% - \_addextgstate{/op1 <>}% - \_addextgstate{/op2 <>}% - \_glet\_insertshadowresources=\_relax + \_global\_addto\_begoutput{\_setshadowresources}% + \_xdef\_setshadowresources{% + \_pdfpageresources{/ExtGState + << + /op1 <> + /op2 <> + \_morepgresources + >> + }% + }% + \_global\_let\_insertshadowresources=\_relax } +\_def\_morepgresources{} \_doc ----------------------------- The \`\_doshadow``{}` does the shadow effect. diff --git a/optex/base/optex.lua b/optex/base/optex.lua index be389062..27a27f21 100644 --- a/optex/base/optex.lua +++ b/optex/base/optex.lua @@ -558,51 +558,6 @@ callback.add_to_callback("pre_shipout_filter", function(list) return tonode(list) end, "_colors") -- --- -local function create_pre_shipout_injector(attribute, default, namespace) - local current - local function injector(head) - for n, id, subtype in traverse(head) do - if id == hlist_id or id == vlist_id then - -- nested list, just recurse - setlist(n, injector(getlist(n))) - elseif id == disc_id then - -- only replace part is interesting at this point - local replace = getfield(n, "replace") - if replace then - setfield(n, "replace", injector(replace)) - end - elseif id == glyph_id or id == rule_id - or (id == glue_id and getleader(n)) then - local new = getattribute(n, attribute) or 0 - if new ~= current then - local literal = token_getmacro(namespace..new) - head = insertbefore(head, n, pdfliteral(literal)) - current = new - end - end - end - return head - end - - return function(list) - current = default - return tonode(injector(todirect(list))) - end -end --- -callback.add_to_callback( - "pre_shipout_filter", - create_pre_shipout_injector(registernumber("_transpattr"), 0, "_transp:"), - "_transp" -) --- -callback.add_to_callback( - "pre_shipout_filter", - create_pre_shipout_injector(registernumber("_fntoutattr"), 0, "_fntout:"), - "_fntout" -) --- -- We also hook into `luaotfload`'s handling of color. Instead of the default -- behavior (inserting colorstack whatsits) we set our own attribute. The hook -- has to be registered {\em after} `luaotfload` is loaded. diff --git a/optex/base/slides.opm b/optex/base/slides.opm index 0fed12ac..a491d1f5 100644 --- a/optex/base/slides.opm +++ b/optex/base/slides.opm @@ -53,20 +53,19 @@ \_doc ----------------------------- The \`\pshow``` prints the text in invisible (transparent) font when \^`\layernum`\code{<}``. - For transparency we need to define special graphics states. + The transparency is set by `\pdfpageresoyrces` primitive. \_cod ----------------------------- -\_addextgstate{/Invisible <>} -\_addextgstate {/Visible <>} - -\_def\_Invisible {\_pdfliteral{/Invisible gs}} -\_def\_Visible {\_pdfliteral{/Visible gs}} -\_def\_Transparent {\_Invisible \_aftergroup \_Visible} - -\_public \Invisible \Visible \Transparent ; +\pdfpageresources{/ExtGState << /Invisible << /Type /ExtGState /ca 0 /CA 0 >> + /Visible << /Type /ExtGState /ca 1 /CA 1 >> >>} +\addto\_morepgresources{/Invisible << /Type /ExtGState /ca 0 /CA 0 >> + /Visible << /Type /ExtGState /ca 1 /CA 1 >>} +\def\Invisible {\_pdfliteral{/Invisible gs}} +\def\Visible {\_pdfliteral{/Visible gs}} +\def\Transparent {\Invisible \_aftergroup \Visible} \_def\_use#1#2{\_ifnum\_layernum#1\_relax#2\_fi} -\_def\_pshow#1{\_use{=#1}\Red \_use{<#1}\_Transparent \_ignorespaces} +\_def\_pshow#1{\_use{=#1}\Red \_use{<#1}\Transparent \_ignorespaces} \_doc ----------------------------- The main level list of items is activated here. The `\_item:X` and