Difference between revisions of "Transparency"

From Wiki
Jump to navigation Jump to search
(Created page with "= Defining transparent colors = You can define '''transparent''' colors through setting t, e.g. <tt>t=0.5</tt>. Beware, some PDF viewers and printshops can't handle PDF transpar...")
 
m (Garulfo moved page Color/Transparency to Transparency without leaving a redirect: simplification)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Defining transparent colors =
+
== Defining transparent colors ==
  
You can define '''transparent''' colors through setting t, e.g. <tt>t=0.5</tt>. Beware, some PDF viewers and printshops can't handle PDF transparences!
+
You can define '''transparent''' colors through setting <tt>t</tt> and <tt>a</tt>, e.g. <tt>t=0.5,a=1</tt>, where the first is the opacity and the latter the transparency mode (there are 17).
  
Hans Hagen posted the following sample code for transparent colors on the mailing list on 2005-07-13; the yellow blocks have been added to demonstrate the order in which the blocks are drawn on the page; the first yellow block is behind the transparent red and blue blocks, while the second is in front of them.
+
Beware, some PDF viewers and printshops can't handle transparencies in PDF!
 +
 
 +
In the following example by Hans Hagen the yellow blocks have been added to demonstrate the order in which the blocks are drawn on the page; the first yellow block is behind the transparent red and blue blocks, while the second is in front of them.
  
 
{|
 
{|
Line 49: Line 51:
  
  
 +
== Transparency modes ==
 +
 +
There are different algorithms for "mixing" transparent colors with their background, maybe you know them from the layer settings in Photoshop.
 +
 +
* 0 none
 +
* 1 normal
 +
* 2 multiply
 +
* 3 screen
 +
* 4 overlay
 +
* 5 softlight
 +
* 6 hardlight
 +
* 7 colordodge
 +
* 8 colorburn
 +
* 9 darken
 +
* 10 lighten
 +
* 11 difference
 +
* 12 exclusion
 +
* 13 hue
 +
* 14 saturation
 +
* 15 color
 +
* 16 luminosity
 +
 +
They are defined in {{src|mkiv/lpdf-col.lua}} and demonstrated in the [http://www.pragma-ade.com/general/manuals/colors-mkiv.pdf color manual].
 +
 +
 +
== Transparent images ==
 +
 +
Since October 2016, you can also make external figures and every other element transparent using {{cmd|definetransparency}} and {{cmd|starttransparent}}.
  
= Rendering =
+
<texcode>
 +
\definetransparency[tnormal]    [a=normal,t=.5]
 +
\definetransparency[tmultiply]  [a=multiply,t=.5]
 +
\definetransparency[tdifference][a=difference,t=.5]
 +
 
 +
\startoverlay
 +
    {\framed[width=10cm,align=normal,foregroundcolor=red]{\input tufte }}
 +
    {\starttransparent[tnormal]\externalfigure[cow.pdf][width=9cm]\stoptransparent}
 +
\stopoverlay
 +
 
 +
\startoverlay
 +
    {\framed[width=10cm,align=normal,foregroundcolor=red]{\input tufte }}
 +
    {\starttransparent[tmultiply]\externalfigure[cow.pdf][width=9cm]\stoptransparent}
 +
\stopoverlay
 +
 
 +
\startoverlay
 +
    {\framed[width=10cm,align=normal,foregroundcolor=red]{\input tufte }}
 +
    {\starttransparent[tdifference]\externalfigure[cow.pdf][width=9cm]\stoptransparent}
 +
\stopoverlay
 +
</texcode>
 +
 
 +
 
 +
== Rendering ==
  
 
Acrobat Reader might not render transparency using RGB in a PDF that is displayed on a monitor. If the colours do not appear correctly, add the following code:
 
Acrobat Reader might not render transparency using RGB in a PDF that is displayed on a monitor. If the colours do not appear correctly, add the following code:
  
<code>
+
<texcode>
 
\setupcolors[pagecolormodel=auto]
 
\setupcolors[pagecolormodel=auto]
</code>
+
</texcode>
  
 
In Acrobat, when transparency is used, a different route is followed (at least in the past) when rendering. Rendering colorspaces might be adapted to the output medium so it's a combination of colorspace, monitor/paper, calibration, knockout/overprint, transparency groups, assumptions, and so forth.
 
In Acrobat, when transparency is used, a different route is followed (at least in the past) when rendering. Rendering colorspaces might be adapted to the output medium so it's a combination of colorspace, monitor/paper, calibration, knockout/overprint, transparency groups, assumptions, and so forth.
 +
 +
[[Category:Color]]

Latest revision as of 12:27, 10 June 2020

Defining transparent colors

You can define transparent colors through setting t and a, e.g. t=0.5,a=1, where the first is the opacity and the latter the transparency mode (there are 17).

Beware, some PDF viewers and printshops can't handle transparencies in PDF!

In the following example by Hans Hagen the yellow blocks have been added to demonstrate the order in which the blocks are drawn on the page; the first yellow block is behind the transparent red and blue blocks, while the second is in front of them.

\definecolor [transparentred]  [r=1,t=.5,a=1]
\definecolor [transparentblue] [b=1,t=.5,a=1]
\definecolor [solidyellow]  [y=1,t=1,a=1]

\starttext

\startTEXpage
This is some sample text that goes behind the rectangles\hskip-8cm
\blackrule[width=2cm,height=1cm,depth=1cm,color=solidyellow]\hskip-0.67cm
\blackrule[width=2cm,height=2cm,color=transparentred]\hskip-0.67cm
\blackrule[width=2cm,height=1cm,depth=1cm,color=transparentblue]\hskip-0.67cm
\blackrule[width=2cm,height=2cm,color=solidyellow]\hskip2cm.
\stopTEXpage

\stoptext


Transparency modes

There are different algorithms for "mixing" transparent colors with their background, maybe you know them from the layer settings in Photoshop.

  • 0 none
  • 1 normal
  • 2 multiply
  • 3 screen
  • 4 overlay
  • 5 softlight
  • 6 hardlight
  • 7 colordodge
  • 8 colorburn
  • 9 darken
  • 10 lighten
  • 11 difference
  • 12 exclusion
  • 13 hue
  • 14 saturation
  • 15 color
  • 16 luminosity

They are defined in mkiv/lpdf-col.lua and demonstrated in the color manual.


Transparent images

Since October 2016, you can also make external figures and every other element transparent using \definetransparency and \starttransparent.

\definetransparency[tnormal]    [a=normal,t=.5]
\definetransparency[tmultiply]  [a=multiply,t=.5]
\definetransparency[tdifference][a=difference,t=.5]

\startoverlay
    {\framed[width=10cm,align=normal,foregroundcolor=red]{\input tufte }}
    {\starttransparent[tnormal]\externalfigure[cow.pdf][width=9cm]\stoptransparent}
\stopoverlay

\startoverlay
    {\framed[width=10cm,align=normal,foregroundcolor=red]{\input tufte }}
    {\starttransparent[tmultiply]\externalfigure[cow.pdf][width=9cm]\stoptransparent}
\stopoverlay

\startoverlay
    {\framed[width=10cm,align=normal,foregroundcolor=red]{\input tufte }}
    {\starttransparent[tdifference]\externalfigure[cow.pdf][width=9cm]\stoptransparent}
\stopoverlay


Rendering

Acrobat Reader might not render transparency using RGB in a PDF that is displayed on a monitor. If the colours do not appear correctly, add the following code:

\setupcolors[pagecolormodel=auto]

In Acrobat, when transparency is used, a different route is followed (at least in the past) when rendering. Rendering colorspaces might be adapted to the output medium so it's a combination of colorspace, monitor/paper, calibration, knockout/overprint, transparency groups, assumptions, and so forth.