ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Stefan Haller via ntg-context <ntg-context@ntg.nl>
To: ntg-context@ntg.nl
Cc: Stefan Haller <stefan+context@stha.de>
Subject: Problems with MetaFun Transparency Groups
Date: Mon, 13 Jun 2022 23:37:26 +0200	[thread overview]
Message-ID: <YqeuFuJvirPEYLfd@stha.de> (raw)

Hi everyone!

I have a question regarding transparency groups in MetaFun. As a toy example, I
want to draw a grid of lines where the whole grid should have an opacity of 25%.

If I draw intersecting lines individually with `withtransparency(1, .25)` the
overlapping parts will have a total opacity of 50%. However, I want to draw the
whole grid as one group and then blend it as a whole so that the whole grid is
evenly colored when blended. According to the MetaFun manual we should be able
to get the desired effect with the `asgroup` operator applied to a picture.
(Actually, the manual says the operator is called `grouped` but the source code
of the graphics above uses the `asgroup` operator [1].)

The `asgroup` does in fact insert a transparency group into the PDF output:

> << /Type /XObject /Subtype /Form /FormType 1 /Group << /S /Transparency /I false /K false

However, the group does not seem to be blended as one group and we can still
see that the overlapping parts are darker than the other parts of the line.
Something seems to be off. Looking at the compiled manual also shows that the
transparency groups are not working (both parts of the arrow, the head and the
tail, are blended independently and not as a group).

When I recreate the graphics in Tikz/PGF everything works. The resulting PDF
output looks similar, at least with my limited understanding of PDF format I am
unable to understand the differences.

The full example is attached below the text of my mail. The Tikz example on the
fifth page shows the desired result.

Do I misunderstand the syntax of transparency groups in MetaFun? Or is there
some other problem? Maybe someone can point me in the right direction.

Thanks in advance!
Stefan Haller

[1]: https://source.contextgarden.net/doc/context/sources/general/manuals/metafun/metafun-effects.tex?search=asgroup&docs=yes#l2543



\nopdfcompression
\usemodule[tikz]

\starttext
\startMPdefinitions
  vardef draw_grid =
    def withmycolor = withcolor red withtransparency(normaltransparent, .25) enddef;
    linecap := butt;
    u := 10mm;
    n := 20;
    pickup pencircle scaled 7mm;
    for i = 1 upto n:
      draw (0, i) * u -- (n+1, i) * u withmycolor;
      draw (i, 0) * u -- (i, n+1) * u withmycolor;
    endfor;
  enddef;
\stopMPdefinitions
\startMPpage
  draw image( draw_grid ) asgroup "";
  addbackground withcolor yellow;
\stopMPpage
\startMPpage
  draw image( draw_grid ) asgroup "isolated";
  addbackground withcolor yellow;
\stopMPpage
\startMPpage
  draw image( draw_grid ) asgroup "knockout";
  addbackground withcolor yellow;
\stopMPpage
\startMPpage
  draw image( draw_grid ) asgroup "isolated,knockout";
  addbackground withcolor yellow;
\stopMPpage
\startTEXpage
\starttikzpicture
  \fill[yellow] (-0.35cm, -0.35cm) rectangle (21.35cm, 21.35cm);
  \startscope[opacity=.25, transparency group]
    \startscope[x=10mm, y=10mm, every path/.style={line width=7mm}]
      \foreach \i in {1,...,20}{
        \draw[red] (0, \i) -- (21, \i);
        \draw[red] (\i, 0) -- (\i, 21);
      };
    \stopscope
  \stopscope
\stoptikzpicture
\stopTEXpage
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

                 reply	other threads:[~2022-06-13 21:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YqeuFuJvirPEYLfd@stha.de \
    --to=ntg-context@ntg.nl \
    --cc=stefan+context@stha.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).