On 28-10-2010 9:54, Cedric Mauclair wrote:
On Wed, Oct 27, 2010 at 22:08, Michael Murphy<michael.mur...@uni-ulm.de>  wrote:
On 27/10/2010 19:18, Marius wrote:

Hello,
I had the same problem, so I desided to define colors by hand.

\definecolor [lightgray] [h=D3D3D3]

\usemodule[tikz]

\unprotect
\pgfu...@definecolor{black}{gray}{0}
\pgfu...@definecolor{gray}{gray}{0.5}
\pgfu...@definecolor{lightgray}{gray}{0.9}
\pgfu...@definecolor{white}{gray}{1}
\protect

Yes, this is what I've resorted to. But it would be nice to define things
properly.

If you want to fix script, you need to change line:

local cv = colors.value(attributes)
The table "colors" is expected to have a function named "value" that
take the "attributes" parameter as its sole parameter itself. It then
assigns the result to the local variable cv. After some research,
adding  "local colors = global.attributes.colors" below the line
"local prtcatcodes = tex.prtcatcodes" works. There is a catch however,
you can't use opacity on these colors. I suppose we have to generate
all the transparency level by using spot colors or something like
that.

There are several solutions to the problem.

\usemodule[tikz]

\startmode[mkiv]

\startluacode
thirddata     = thirddata     or { }
thirddata.pgf = thirddata.pgf or { }

local texsprint, prtcatcodes, format = tex.sprint, tex.prtcatcodes, string.format

local function unsupported_color(name)
texsprint(prtcatcodes,format("\\PackageError{pgf}{color %s has unsupported model}{}", name)) texsprint(prtcatcodes,format("\\pgfu...@definecolor{%s}{gray}{0}", name))
end

local colors = attributes.colors

function thirddata.pgf.registercolor(name,attribute) -- solution 1
    local cv = colors.value(attribute)
    if cv then
        local model = colors.forcedmodel(cv[1])
        if model > 3 then
            model = 3 -- no cmyk or spot or multitone
        end
        if model == 2 then

texsprint(prtcatcodes,format("\\pgfu...@definecolor{%s}{gray}{%1.3f}", name, cv[2]))
        elseif model == 3 then

texsprint(prtcatcodes,format("\\pgfu...@definecolor{%s}{rgb}{%1.3f,%1.3f,%1.3f}", name, cv[3], cv[4], cv[5]))
        else
            unsupported_color(name)
        end
    else
        unsupported_color(name)
    end
end

function lpdf.pdfcolor(attribute)
    context(lpdf.color(1,attribute))
end
\stopluacode

\stopmode

\unprotect

% solution 1 (also fallback when cmyk is used):

% \def\PDFcolor#1%
%   {\ctxlua{thirddata.pgf.pdfcolor(\thecolorattribute{#1})}}

% solution 2 (faster as less parsing at the tex end):

% \def\pgfu...@registercolor#1%
%   {\ctxlua{thirddata.pgf.registercolor("#1",\thecolorattribute{#1})}}

% solution 3 (backward compatible):

\def\PDFcolor#1%
  {\ctxlua{lpdf.pdfcolor(\thecolorattribute{#1})}}

\protect

\definecolor[mycolora][r=1,g=0,b=1]
\definecolor[mycolorb][m=1]

\starttext
    \starttikzpicture
        \fill[mycolora] (0,0) circle (2);
        \fill[mycolorb] (0,0) circle (1);
    \stoptikzpicture
\stoptext

I'll define \pdfcolor for this purpose as that's what tikz expects.

However, I still need to
add"\let\appendtoPDFdocumentcolorspaces\gobbleoneargument"
"\let\appendtoPDFdocumentextgstates\gobbleoneargument" and
"\let\PDFcolor\gobbleoneargument" before loading the TikZ module in
order for my documents to build without errors. These macros used to
be defined in mkii (spec-fdf.mkii) and TikZ relies on them
(tex/generic/pgf/utilities/pgfutil-context.def) but not anymore in
mkiv since the color support has changed between mkii and mkiv. I
suppose they had to do with the color support for PDF files, but
letting them gobble their argument still seems to work. On what side
should this problem be looked into: ConTeXt or TikZ?

In pgfutil-context.def there should be no such commands called when mkiv is used. Isn't there a

\doifmodeelse {mkiv} { ...

section? anyhow, in that section one can add

\ifdefined\PDFcolor \else

\ctxlua{function lpdf.pdfcolor(attribute) context(lpdf.color(1,attribute)) end}

  \def\PDFcolor#1{\ctxlua{lpdf.pdfcolor(\thecolorattribute{#1})}}

\fi

(in the next beta this is not needed as \PDFcolor is defined then)

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
-----------------------------------------------------------------
% 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.

% The aux files, needed for reading back coordinates

\def\pgfu...@aux@r...@hook{
  \pgfu...@iffileexists{\jobname.pgf}{\input \jobname.pgf\relax}{}
  \csname newwrite\endcsname\pgfu...@auxout
  \csname openout\endcsname\pgfu...@auxout\jobname.pgf
}

% XColor-like support for ConTeXt

\def\pgfu...@definecolor#1#2#3{\csname pgfu...@emu@#2\endcsname{#1}...@nil}

\def\pgfu...@emu@rgb#1#2,#3,#...@nil{\expandafter\def\csname\string\color@#1\endcsname{\xco...@{}{}{rgb}{#2,#3,#4}}}
\def\pgfu...@emu@gray#1...@nil{\expandafter\def\csname\string\color@#1\endcsname{\xco...@{}{}{rgb}{#2,#2,#2}}}

\pgfu...@definecolor{white}{gray}{1}
\pgfu...@definecolor{black}{gray}{0}
\pgfu...@definecolor{gray}{gray}{0.5}
\pgfu...@definecolor{red}{rgb}{1,0,0}
\pgfu...@definecolor{green}{rgb}{0,1,0}
\pgfu...@definecolor{blue}{rgb}{0,0,1}
\pgfu...@definecolor{cyan}{rgb}{0,1,1}
\pgfu...@definecolor{magenta}{rgb}{1,0,1}
\pgfu...@definecolor{yellow}{rgb}{1,1,0}
\pgfu...@definecolor{orange}{rgb}{1,0.5,0}
\pgfu...@definecolor{violet}{rgb}{0.5,0,0.5}
\pgfu...@definecolor{purple}{rgb}{0.75,0,0.25}
\pgfu...@definecolor{brown}{rgb}{0.75,0.5,0.25}

\def\pgfu...@color#1{%
  \pgfu...@colorlet{.}{#1}%
  \pgfsysproto...@getcurrentprotocol\pgfutil@e...@temp%
  {%
    \pgfsysproto...@setcurrentprotocol\pgfutil@empty%
    \pgfsysproto...@bufferedtrue%
    \pgfsetcolor{.}%
    \expandafter\pgf...@outerinvoke\expandafter{\pgfsysprotocol@currentprotocol}%
  }%
  \pgfsysproto...@setcurrentprotocol\pgfutil@e...@temp%
  \aftergroup\pgfu...@reset@color%
}

\def\pgfu...@extractcolorspec#1#2{%
  \def#2{{#1}}%
}

\def\pgfu...@convertcolorspec#1#2#3{%
  \edef#3{\expandafter\expandafter\expandafter\pgfu...@emu@select\csname\string\co...@#1\endcsname}%
}


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


\def\pgfu...@reset@color{%
  \pgfsysproto...@getcurrentprotocol\pgfutil@e...@temp%
  {%
    \pgfsysproto...@setcurrentprotocol\pgfutil@empty%
    \pgfsysproto...@bufferedtrue%
    \pgfsetcolor{.}%
    \expandafter\pgf...@outerinvoke\expandafter{\pgfsysprotocol@currentprotocol}%
  }%
  \pgfsysproto...@setcurrentprotocol\pgfutil@e...@temp%
}
\expandafter\def\csname\string\co...@.\endcsname{\xcolor@{}{}{rgb}{0,0,0}}

\def\pgfu...@colorlet#1#2{%
  \edef\...@marshal{#2}%
  \expandafter\pgfu...@in@\expandafter!\expandafter{\...@marshal}%
  \ifpgfu...@in@%
    % compute mixture
    {%
      \expandafter\pgfu...@emu@mix\...@marshal!white!\@nil%
      \xdef\...@marshal{\noexpand\def\expandafter\noexpand\csname\string\color@#1\endcsname{%
          \noexpand\xco...@{}{}{rgb}{\pgf@s...@tonumber\pgf@xa,\...@sys@tonumber\...@xb,\...@sys@tonumber\...@xc}}}%
    }%
    \...@marshal%
  \else%
    \expandafter\ifx\csname\string\co...@#2\endcsname\relax%
      \pgfu...@registercolor{#2}%
    \fi%
    \edef\...@marshal{\noexpand\let\expandafter\noexpand\csname\string\color@#1\endcsname=%
                      \expandafter\noexpand\csname\string\co...@#2\endcsname}%
    \...@marshal%
  \fi%
}
\def\pgfu...@emu@mix#1!#2!#3!...@nil{%
  \expandafter\ifx\csname\string\co...@#1\endcsname\relax%
    \pgfu...@registercolor{#1}%
  \fi%
  \expandafter\ifx\csname\string\co...@#3\endcsname\relax%
    \pgfu...@registercolor{#3}%
  \fi%
  \expandafter\expandafter\expandafter\pgfu...@emu@unpack\csname\string\co...@#1\endcsname%
  \...@ya=\pgf@xa%
  \...@yb=\pgf@xb%
  \...@yc=\pgf@xc%
  \expandafter\expandafter\expandafter\pgfu...@emu@unpack\csname\string\co...@#3\endcsname%
  \...@pgf@counta=#2\relax%
  \...@pgf@countb=100\relax%
  \advanc...@pgf@countb by...@pgf@counta\relax%
  \...@xa=\c@p...@countb\pgf@xa%
  \advance\...@xa b...@pgf@counta\...@ya%
  \divide\...@xa by 100\relax%
  \...@xb=\c@p...@countb\pgf@xb%
  \advance\...@xb b...@pgf@counta\...@yb%
  \divide\...@xb by 100\relax%
  \...@xc=\c@p...@countb\pgf@xc%
  \advance\...@xc b...@pgf@counta\...@yc%
  \divide\...@xc by 100\relax%
}
\def\pgfu...@emu@unpack#1#2#3#4#5{%
  \pgfu...@emu@@unpack...@nil%
}
\def\pgfu...@emu@@unpack#1,#2,#...@nil{%
  \...@xa=#1pt%
  \...@xb=#2pt%
  \...@xc=#3pt%
}

\def\pgfu...@emu@select#1#2#3#4#5{#5}


\def\pgfu...@registercolor#1{%
  \edef\...@temp{\pdfcolor{#1}}%
  \edef\...@marshal{\noexpand\pgfutil@i...@{ g}{\...@temp}}%
  \...@marshal%
  \ifpgfu...@in@%
    \expandafter\pgfu...@context@pa...@gray\pgf@temp\...@stop{#1}%
  \else%
    \edef\...@marshal{\noexpand\pgfutil@i...@{ rg}{\...@temp}}%
    \...@marshal%
    \ifpgfu...@in@%
      \expandafter\pgfu...@context@pa...@rgb\pgf@temp\...@stop{#1}%
    \else%
      \PackageError{pgf}{Color #1 has an unsupported color model.}{}%
      \pgfu...@definecolor{#1}{gray}{0}
    \fi%
  \fi%
}

\def\pgfu...@context@pa...@gray#1 g#2\...@stop#3{%
  \pgfu...@definecolor{#3}{gray}{#1}
}

\def\pgfu...@context@pa...@rgb#1 #2 #3 rg#4\...@stop#5{%
  \pgfu...@definecolor{#5}{rgb}{#1,#2,#3}
}

% Make this command available in general:
\let\colorlet=\pgfu...@colorlet


% pgfu...@minipage

\def\pgfu...@minipage[#1]#2{%
  \hbox to#2\bgroup%
    \hsize=#2\relax%
    \vbox\bgroup\leavevmode%
}
\def\pgfu...@endminipage{\egroup\egroup}



% Driver detector (how should we do this in ConTeXt?) :

\ifx\pdfoutp...@undefined\newcount\pdfoutput\fi
\ifx\pdfoutput\relax\newcount\pdfoutput\fi

\def\pgfu...@guessdriver{
  \ifx\xetexversi...@undefined
    \ifx\preloadedspecia...@undefined%
      \ifcase\pdfoutput%
        \def\pgfsysdriver{pgfsys-dvips.def}%
      \else%
        \def\pgfsysdriver{pgfsys-pdftex.def}% pdfTeX & LuaTeX
      \fi%
    \else%
      \pgfu...@driver@i...@in{postscript}{pgfsys-dvips.def}
      \pgfu...@driver@i...@in{tpd}{pgfsys-pdftex.def}
      \pgfu...@driver@i...@in{dpm}{pgfsys-dvipdfm.def}
      \pgfu...@driver@i...@in{dpx}{pgfsys-dvipdfmx.def}
      \pgfu...@driver@i...@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\pgfu...@driver@i...@in#1#2{%
  \edef\...@marshal{\noexpand\pgfutil@i...@{#1}{\preloadedspecials}}
  \...@marshal
  \ifpgfu...@in@%
    \def\pgfsysdriver{#2}%
  \fi%
}


% Global colors

\let\pgfu...@globalcolorsfalse=\relax
\let\pgfu...@globalcolorstrue=\relax



% Font stuff

\def\pgfu...@font@tiny{\tfxx}
\def\pgfu...@font@scriptsize{\tfxx}
\def\pgfu...@font@footnotesize{\tfx}
\def\pgfu...@font@small{\tfx}
\def\pgfu...@font@normalsize{\tf}
\def\pgfu...@font@large{\tfa}
\def\pgfu...@font@Large{\tfb}
\def\pgfu...@font@huge{\tfc}
\def\pgfu...@font@Huge{\tfc}

\def\pgfu...@font@itshape{\it}
\def\pgfu...@font@bfseries{\bf}

\let\pgfu...@font@normalfont=\tf

\let\pgfu...@selectfont=\tf


% Extra counters, registers, boxes

\newcount\pgfu...@tempcnta
\newcount\pgfu...@tempcntb

\newbox\pgfu...@tempboxa

\newdimen\pgfu...@tempdima
\newdimen\pgfu...@tempdimb

\newbox  \pgfu...@voidb@x
\newtoks \pgfu...@toks@

% Module stuff

\def\pgfu...@usemodule#1{\usemodule[#1]}

% % % % begin patches by HH % % % %

\let\pgfu...@insertatbegincurrentpagefrombox\flushatshipout
\let\pgfu...@insertatbegincurrentpage       \flushatshipout
\def\pgfu...@insertatbegineverypage         #1{\appendtoks#1\to\everyshipout} % space removed after #1

\let\pgfu...@setuppdfresources \relax

\doifmodeelse {mkiv} {

    \def\...@sys@p...@pdfbackendset@one#1#2%
      {\normalexpanded{\noexpand\...@sys@p...@pdfbackendset@two\noexpand#1#2\relax}}

    \def\...@sys@p...@pdfbackendset@two#1/#2 #3\relax
      {#1{#2}{#3}}

    \def\...@sys@p...@addtopageresource@pattern   {\...@sys@p...@pdfbackendset@one\pdfbackendsetpattern}
    \def\...@sys@p...@addtopageresource@colorspace{\...@sys@p...@pdfbackendset@one\pdfbackendsetcolorspace}
    \def\...@sys@p...@addtopageresource@extgstate {\...@sys@p...@pdfbackendset@one\pdfbackendsetextgstate}
    \def\...@sys@p...@possible@resources          {\pdfbackendcurrentresources}
    \def\...@sys@p...@check@resources             {}

    \ifdefined\PDFcolor \else

        \ctxlua{function lpdf.pdfcolor(attribute) context(lpdf.color(1,attribute)) end}

        \def\PDFcolor#1{\ctxlua{lpdf.pdfcolor(\thecolorattribute{#1})}}

    \fi

} {

    \def\...@sys@p...@addtopageresource@extgstate  {\appendtoPDFdocumentextgstates }
    \def\...@sys@p...@addtopageresource@colorspace {\appendtoPDFdocumentcolorspaces}
    \def\...@sys@p...@addtopageresource@pattern    {\appendtoPDFdocumentpatterns   }
    \def\...@sys@p...@possible@resources           {\currentPDFresources}
    \def\...@sys@p...@check@resources              {}

}

\let\...@sys@addpdfresou...@extgs@plain      \...@sys@p...@addtopageresource@extgstate
\let\...@sys@addpdfresou...@patterns@plain   \...@sys@p...@addtopageresource@pattern
\let\...@sys@addpdfresou...@colorspaces@plain\...@sys@p...@addtopageresource@colorspace
\let\...@sys@p...@check@resour...@plain       \...@sys@p...@check@resources

\...@sys@addpdfresou...@colorspaces@plain{/pgfprgb [/Pattern /DeviceRGB]}

% % % % end patches by HH % % % %

% Do something at the end of a job

\appendtoks \the\pgfu...@everybye \to \everybye

% The following is still messy and needs to be cleanup up (everything
% prefixed by pgfutil@):

\def\PackageInfo#1#2{}
\def\PackageWarning#1#2{\immediate\write17{Package #1: Warning! #2.}}%
\def\PackageError#1#2#3{\immediate\write17{Package #1: Error! #2.}}%
\long\def\AtBeginDocument#1{#1}%

\endinput
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to