[NTG-context] ConTeXt-defined colours broken in TikZ in MkIV with latest betas

Hans Hagen pragma at wxs.nl
Mon Apr 13 22:51:16 CEST 2015


On 4/13/2015 7:45 PM, Mojca Miklavec wrote:
> Hi,
>
> The following example works in MkII and it works in TeX Live 2014, but
> it fails with the latest beta (it draws a black rectangle instead of
> using the defined colour):
>
> \usemodule[tikz]
> \starttext
> \definecolor[mycol][r=0.9,g=0.8,b=0.8]
> \starttikzpicture
> \fill[mycol] (0, 0) rectangle (2,4);
> \stoptikzpicture
> \stoptext
>
> It would be really nice to fix this in time for TeX Live 2015.

Hm, i'm a bit puzzled why some suggested patched are nto in the 
distribution. Anyway, attached a more modern variant

you need a beta that i just uploaded because i found out that when tijz 
predefines some mixed colors it assumes rgb color space

your example then runs ok here

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
-------------- next part --------------
% Copyright 2006 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.
%
% Adapted for colors and pdf resources by Hans Hagen. There can be a few more
% optimizations but they are not critital.

\pgfutil at format@is at contexttrue

% an aux files, needed for reading back coordinates

\def\pgfutil at aux@read at hook{%
  \pgfutil at IfFileExists{\jobname.pgf}{\input \jobname.pgf\relax}{}
  \csname newwrite\endcsname\pgfutil at auxout
  \csname openout\endcsname\pgfutil at auxout\jobname.pgf\relax
}

% no need for x colors (users can load it if needed)

\def\pgfutil at color#1{%
  \pgfutil at colorlet{.}{#1}%
  \pgfsysprotocol at getcurrentprotocol\pgfutil at emu@temp%
  {%
    \pgfsysprotocol at setcurrentprotocol\pgfutil at empty%
    \pgfsysprotocol at bufferedtrue%
    \pgfsetcolor{.}%
    \expandafter\pgfsys at outerinvoke\expandafter{\pgfsysprotocol at currentprotocol}%
  }%
  \pgfsysprotocol at setcurrentprotocol\pgfutil at emu@temp%
  \aftergroup\pgfutil at reset@color%
}

\def\pgfutil at extractcolorspec#1#2{%
  \def#2{{#1}}%
}

\def\pgfutil at convertcolorspec#1#2#3{%
  \edef#3{\expandafter\expandafter\expandafter\pgfutil at emu@select\csname\string\color@#1\endcsname}%
}

\def\pgfutil at doifcolorelse#1#2#3{%
  \expandafter\ifx\csname\string\color@#1\endcsname\relax%
    \doifcolorelse{#1}{\let\pgf at next=\pgfutil at firstoftwo}{\let\pgf at next=\pgfutil at secondoftwo}%
  \else
    \let\pgf at next=\pgfutil at firstoftwo%
  \fi%
  \pgf at next{#2}{#3}%
}

\def\pgfutil at reset@color{%
  \pgfsysprotocol at getcurrentprotocol\pgfutil at emu@temp%
  {%
    \pgfsysprotocol at setcurrentprotocol\pgfutil at empty%
    \pgfsysprotocol at bufferedtrue%
    \pgfsetcolor{.}%
    \expandafter\pgfsys at outerinvoke\expandafter{\pgfsysprotocol at currentprotocol}%
  }%
  \pgfsysprotocol at setcurrentprotocol\pgfutil at emu@temp%
}

\expandafter\def\csname\string\color at .\endcsname{\xcolor@{}{}{rgb}{0,0,0}}

\def\pgfutil at colorlet#1#2{%
  \edef\pgf at marshal{#2}%
  \expandafter\pgfutil at in@\expandafter!\expandafter{\pgf at marshal}%
  \ifpgfutil at in@%
    % compute mixture
    {%
      \expandafter\pgfutil at emu@mix\pgf at marshal!white!\@nil%
      \xdef\pgf at marshal{\noexpand\def\expandafter\noexpand\csname\string\color@#1\endcsname{%
          \noexpand\xcolor@{}{}{rgb}{\pgf at sys@tonumber\pgf at xa,\pgf at sys@tonumber\pgf at xb,\pgf at sys@tonumber\pgf at xc}}}%
    }%
    \pgf at marshal%
  \else%
    \expandafter\ifx\csname\string\color@#2\endcsname\relax%
      \pgfutil at registerrgb{#2}%
    \fi%
    \edef\pgf at marshal{\noexpand\let\expandafter\noexpand\csname\string\color@#1\endcsname=%
                      \expandafter\noexpand\csname\string\color@#2\endcsname}%
    \pgf at marshal%
  \fi%
}

\def\pgfutil at emu@mix#1!#2!#3!#4\@nil{%
  \expandafter\ifx\csname\string\color@#1\endcsname\relax%
    \pgfutil at registerrgb{#1}%
  \fi%
  \expandafter\ifx\csname\string\color@#3\endcsname\relax%
    \pgfutil at registerrgb{#3}%
  \fi%
  \expandafter\expandafter\expandafter\pgfutil at emu@unpack\csname\string\color@#1\endcsname%
  \pgf at ya=\pgf at xa%
  \pgf at yb=\pgf at xb%
  \pgf at yc=\pgf at xc%
  \expandafter\expandafter\expandafter\pgfutil at emu@unpack\csname\string\color@#3\endcsname%
  \c at pgf@counta=#2\relax%
  \c at pgf@countb=100\relax%
  \advance\c at pgf@countb by-\c at pgf@counta\relax%
  \pgf at xa=\c at pgf@countb\pgf at xa%
  \advance\pgf at xa by\c at pgf@counta\pgf at ya%
  \divide\pgf at xa by 100\relax%
  \pgf at xb=\c at pgf@countb\pgf at xb%
  \advance\pgf at xb by\c at pgf@counta\pgf at yb%
  \divide\pgf at xb by 100\relax%
  \pgf at xc=\c at pgf@countb\pgf at xc%
  \advance\pgf at xc by\c at pgf@counta\pgf at yc%
  \divide\pgf at xc by 100\relax%
}

\def\pgfutil at emu@unpack#1#2#3#4#5{%
  \pgfutil at emu@@unpack#5\@nil%
}

\def\pgfutil at emu@@unpack#1,#2,#3\@nil{%
  \pgf at xa=#1pt%
  \pgf at xb=#2pt%
  \pgf at xc=#3pt%
}

\def\pgfutil at emu@select#1#2#3#4#5{#5}

% goody

\let\colorlet=\pgfutil at colorlet

% latex stuff

\newskip\pgfutil at flushglue
\pgfutil at flushglue=0pt plus 1fil

\def\AtBeginDocument#1{#1}%

% pgfutil at minipage

\def\pgfutil at minipage[#1]#2{%
  \hbox to#2\bgroup
    \hsize=#2\relax
    \vbox\bgroup\leavevmode
}

\def\pgfutil at endminipage{%
  \egroup
  \egroup
}

% global colors

\let\pgfutil at globalcolorsfalse\relax
\let\pgfutil at globalcolorstrue \relax

% font stuff

\def\pgfutil at font@tiny        {\tfxx}
\def\pgfutil at font@scriptsize  {\tfxx}
\def\pgfutil at font@footnotesize{\tfx}
\def\pgfutil at font@small       {\tfx}
\def\pgfutil at font@normalsize  {\tf}
\def\pgfutil at font@large       {\tfa}
\def\pgfutil at font@Large       {\tfb}
\def\pgfutil at font@huge        {\tfc}
\def\pgfutil at font@Huge        {\tfc}
\def\pgfutil at font@itshape     {\it}
\def\pgfutil at font@bfseries    {\bf}
\def\pgfutil at font@normalfont  {\tf}
\def\pgfutil at selectfont       {\tf}

% registers

\newcount\pgfutil at tempcnta
\newcount\pgfutil at tempcntb

\newbox  \pgfutil at tempboxa

\newbox  \pgfutil at voidb@x
\newtoks \pgfutil at toks@

\let\pgfmath at tempdima\pgfutil at tempdima
\let\pgfmath at tempdima\pgfutil at tempdima
\let\pgfmath at tempcnta\pgfutil at tempcnta
\let\pgfmath at tempcntb\pgfutil at tempcntb

% module stuff

\def\pgfutil at usemodule#1{\usemodule[#1]}

% more adaptions

\let\pgfutil at insertatbegincurrentpagefrombox\flushatshipout
\let\pgfutil at insertatbegincurrentpage       \flushatshipout
\def\pgfutil at insertatbegineverypage         #1{\appendtoks#1\to\everyshipout} % space removed after #1

\let\pgfutil at setuppdfresources \relax

\doifmodeelse {mkiv} {

    \def\pgfsysdriver{pgfsys-pdftex.def}

    \def\pgfutil at driver@if at in#1#2{%
        \edef\pgf at marshal{\noexpand\pgfutil at in@{#1}{\preloadedspecials}}%
        \pgf at marshal
        \ifpgfutil at in@
            \def\pgfsysdriver{#2}%
        \fi
    }

    \def\pgf at sys@pdf at pdfbackendset@one#1#2%
      {\normalexpanded{\noexpand\pgf at sys@pdf at pdfbackendset@two\noexpand#1#2\relax}}

    \def\pgf at sys@pdf at pdfbackendset@two#1/#2 #3\relax
      {#1{#2}{#3}}

    \def\pgf at sys@pdf at addtopageresource@pattern   {\pgf at sys@pdf at pdfbackendset@one\pdfbackendsetpattern}
    \def\pgf at sys@pdf at addtopageresource@colorspace{\pgf at sys@pdf at pdfbackendset@one\pdfbackendsetcolorspace}
    \def\pgf at sys@pdf at addtopageresource@extgstate {\pgf at sys@pdf at pdfbackendset@one\pdfbackendsetextgstate}
    \def\pgf at sys@pdf at possible@resources          {\pdfbackendcurrentresources}
    \def\pgf at sys@pdf at check@resources             {}

    \let\pgfutil at registercolor\pgf at context@registercolor
    \let\pgfutil at registerrgb  \pgf at context@registerrgb
    \let\pgfutil at registercmyk \pgf at context@registercmyk
    \let\pgfutil at registergray \pgf at context@registergray

} {


    \ifx\pdfoutput\undefined\newcount\pdfoutput\fi
    \ifx\pdfoutput\relax    \newcount\pdfoutput\fi

    \def\pgfutil at guessdriver{
      \ifx\XeTeXversion\@undefined
        \ifx\preloadedspecials\@undefined%
          \ifcase\pdfoutput%
            \def\pgfsysdriver{pgfsys-dvips.def}%
          \else%
            \def\pgfsysdriver{pgfsys-pdftex.def}% pdfTeX & LuaTeX
          \fi%
        \else%
          \pgfutil at driver@if at in{postscript}{pgfsys-dvips.def}
          \pgfutil at driver@if at in{tpd}{pgfsys-pdftex.def}
          \pgfutil at driver@if at in{dpm}{pgfsys-dvipdfm.def}
          \pgfutil at driver@if at in{dpx}{pgfsys-dvipdfmx.def}
          \pgfutil at driver@if at in{xetex}{pgfsys-xetex.def}
          \ifx\pgfsysdriver\relax%
            \PackageWarning{pgf}{I was not able to discern the driver, the
              preloaded specials were \preloadedspecials. I am going to use
              pgfsys-dvips.def}%
            \def\pgfsysdriver{pgfsys-dvips.def}
          \fi%
        \fi
      \else
        \def\pgfsysdriver{pgfsys-xetex.def}% should be right
      \fi
    }

    \def\pgfutil at driver@if at in#1#2{%
      \edef\pgf at marshal{\noexpand\pgfutil at in@{#1}{\preloadedspecials}}%
      \pgf at marshal
      \ifpgfutil at in@
        \def\pgfsysdriver{#2}%
      \fi
    }

    \def\pgfutil at registercolor#1{%
      \edef\pgf at temp{\PDFcolor{#1}}%
      \edef\pgf at marshal{\noexpand\pgfutil at in@{ g}{\pgf at temp}}%
      \pgf at marshal
      \ifpgfutil at in@
        \expandafter\pgfutil at context@parse at gray\pgf at temp\pgf at stop{#1}%
      \else
        \edef\pgf at marshal{\noexpand\pgfutil at in@{ rg}{\pgf at temp}}%
        \pgf at marshal
        \ifpgfutil at in@
          \expandafter\pgfutil at context@parse at rgb\pgf at temp\pgf at stop{#1}%
        \else
          \PackageError{pgf}{Color #1 has an unsupported color model.}{}%
          \pgfutil at definecolor{#1}{gray}{0}%
        \fi
      \fi
    }

    \def\pgfutil at context@parse at gray#1 g#2\pgf at stop#3{%
      \pgfutil at definecolor{#3}{gray}{#1}%
    }

    \def\pgfutil at context@parse at rgb#1 #2 #3 rg#4\pgf at stop#5{%
      \pgfutil at definecolor{#5}{rgb}{#1,#2,#3}%
    }

    \let\pgfutil at registerrgb  \pgfutil at registercolor
    \let\pgfutil at registercmyk \pgfutil at registercolor
    \let\pgfutil at registergray \pgfutil at registercolor

    \def\pgf at sys@pdf at addtopageresource@extgstate  {\appendtoPDFdocumentextgstates }
    \def\pgf at sys@pdf at addtopageresource@colorspace {\appendtoPDFdocumentcolorspaces}
    \def\pgf at sys@pdf at addtopageresource@pattern    {\appendtoPDFdocumentpatterns   }
    \def\pgf at sys@pdf at possible@resources           {\currentPDFresources}
    \def\pgf at sys@pdf at check@resources              {}

}

\let\pgf at sys@addpdfresource at extgs@plain      \pgf at sys@pdf at addtopageresource@extgstate
\let\pgf at sys@addpdfresource at patterns@plain   \pgf at sys@pdf at addtopageresource@pattern
\let\pgf at sys@addpdfresource at colorspaces@plain\pgf at sys@pdf at addtopageresource@colorspace
\let\pgf at sys@pdf at check@resources at plain       \pgf at sys@pdf at check@resources

\pgf at sys@addpdfresource at colorspaces@plain{/pgfprgb [/Pattern /DeviceRGB]}

% do something at the end of a job

\appendtoks \the\pgfutil at everybye \to \everybye

\endinput


More information about the ntg-context mailing list