[dvipdfmx] Color stacks and transformations
Joseph Wright
joseph.wright at morningstar2.co.uk
Wed Mar 17 08:58:10 CET 2021
On 16/03/2021 18:05, Joseph Wright wrote:
> On 16/03/2021 17:26, Shunsaku Hirata wrote:
>> Hi,
>>
>> Thank you for the report.
>>
>> The problem occurs because dvipdfmx tries to re-install the color
>> recorded in the pdf:color color stack (default color in the example)
>> just after graphics state restore operation.
>> This behavior is to ensure the color change induced by pdf:color
>> within a graphics state save-restore block to be propagated outside
>> of the block.
>>
>> I will consider a solution to this issue. Probably it takes some time.
>>
>> Thanks,
>> Shunsaku Hirata
>
> Hello Shunsaku,
>
> Thanks for the feedback.
>
> ----
>
> On the 'restore the color' business, I am slightly confused by the
> intent. I can see it does what you describe, in for example
>
> \leavevmode
> \special{x:gsave}%
> \special{pdf:bc [1 0 0]}%
> Hello
> \special{x:grestore}%
> world
> \special{pdf:ec}%
> \bye
>
> but that behaviour contrasts with pdfTeX
>
> \leavevmode
> \pdfsave
> \pdfcolorstack 0 push{1 0 0 rg}%
> Hello
> \pdfrestore
> world
> \pdfcolorstack 0 pop
> \bye
>
> which admittedly is a lot more aggressive all-round here. However, both
> of these demos look unbalanced to me: I'd expect in a well-behaved real
> example that the color stack would be popped *inside* the graphics state
> save/restore pair.
>
> ----
>
> I can think of at least a couple of approaches that would work for me if
> available from the driver.
>
> - You could disable re-insertion if pdfcolorstackinit is encountered.
> The moment someone is setting \special{pdfcolorstackinit 1 ...} they are
> likely to be using that approach exclusively.
>
> - You could have a keyword-based setting to do the same, for example
>
> \special{pdfcolorstackpriority on}
>
> (would allow \special{pdfcolorstackpriority off} if people really need
> the old behavior back)
>
> ---
>
> At the macro level I might try setting the 'classical' stack to hold the
> same color as first 'new' one, as they should be equivalent anyway. The
> only slight wrinkle is that as the two take different color spec
> formats, there will be places that this is more challenging. That is
> likely the best way to make things work right now.
Actually, there is a much easier macro-level solution. With the
knowledge that color is applied immediately after x:grestore, one can
simply add a line that then reapplies the stack color
\leavevmode
\special{pdfcolorstackinit 1 page direct (0 g 0 g)}
\special{x:gsave}%
\special{pdfcolorstack 1 push (1 0 0 rg)}%
Hello
\special{x:grestore}%
\special{pdfcolorstack 1 current}%
world
\special{pdfcolorstack 1 pop}%
end
\bye
In a richer format, that can be wrapped up such that this is transparent
to the end user.
Probably I will use this solution for the present and we can revisit if
there is a way to do the same in the driver.
Joseph
More information about the dvipdfmx
mailing list.