User Tools

Site Tools


pdf:colors

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
pdf:colors [2015/03/28 13:40] – created dokuadminpdf:colors [2016/05/12 12:37] (current) – [Special colorspaces] christian
Line 1: Line 1:
 +====== Colours in PDF ======
 +
 PDF distinguishes between filling (paint the interior of a closed path) and stroking (paint the outline of a path) when painting. Each mode has its own color and is used with the appropriate paint operators. PDF distinguishes between filling (paint the interior of a closed path) and stroking (paint the outline of a path) when painting. Each mode has its own color and is used with the appropriate paint operators.
  
Line 4: Line 6:
  
 In order to set a color, first the colorspace and then the actual color has to be set with the right parameters for that colorspace. For example setting the stroking color to red in RGB: In order to set a color, first the colorspace and then the actual color has to be set with the right parameters for that colorspace. For example setting the stroking color to red in RGB:
- /DeviceRGB CS   % set colorspace for stroking +  /DeviceRGB CS   % set colorspace for stroking 
- 1 0 0 SC        % set stroking color+  1 0 0 SC        % set stroking color
  
 For the device colorspaces, there exist short cut operators doing both at once. For the above example one can write: For the device colorspaces, there exist short cut operators doing both at once. For the above example one can write:
- 1 0 0 RG        % set RGB colorspace and color for stroking+  1 0 0 RG        % set RGB colorspace and color for stroking
  
 There are 11 distinct colorspaces available in PDF: There are 11 distinct colorspaces available in PDF:
  
-### Device colorspaces+===== Device colorspaces ===== 
 Device dependent, Not reproducable. Device dependent, Not reproducable.
  
-* **DeviceGray** 1 components [0..1]; `0` is black, `1` is white.+  * **DeviceGray** 1 components [0..1]; `0` is black, `1` is white. 
 +  * **DeviceRGB** additive (for screens); 3 components [0..1]; `0 0 0` is black, `1 1 1` is white. 
 +  * **DeviceCMYK** subtractive (for printing); 4 components [0..1]; `0 0 0 1` is black, `0 0 0 0` is white.
  
-* **DeviceRGB** additive (for screens); 3 components [0..1]; `0 0 0` is black, `1 1 1` is white.+===== CIE-based colorspaces =====
  
-* **DeviceCMYK** subtractive (for printing); 4 components [0..1]; `0 0 0 1` is black, `0 0 0 0` is white. 
- 
-### CIE-based colorspaces 
 Calibrated: device independent, reproducable. Calibrated: device independent, reproducable.
  
-* **CalGray**+  * **CalGray** 
 +  * **CalRGB** 
 +  * **Lab** 
 +  * **ICCBased**
  
-* **CalRGB**+===== Special colorspaces =====
  
-* **Lab**+  * **Indexed** 
 +  * **Pattern** 
 +  * **Separation** 
 +  * **DeviceN**
  
-* **ICCBased**+Most commonly used and easiest are the device colorspaces. Setting black is done like this in the different colorspaces: 
 +  % DeviceGray 
 +  0 G        % stroking 
 +  0 g        % filling 
 +  % DeviceRGB 
 +  0 0 0 RG   % stroking 
 +  0 0 0 rg   % filling 
 +  % DeviceCMYK 
 +  0 0 0 1 K  % stroking 
 +  0 0 0 1 k  % filling
  
-### Special colorspaces +The renderer supports the device color spacesIf you need other color spaces, you need to work directly with the color operators.
- +
-* **Indexed** +
- +
-* **Pattern** +
- +
-* **Separation** +
- +
-* **DeviceN** +
- +
-Most commonly used and easiest are the device colorspacesSetting black is done like this in the different colorspaces: +
- % DeviceGray +
- 0 G        % stroking +
- 0 g        % filling +
- % DeviceRGB +
- 0 0 0 RG   % stroking +
- 0 0 0 rg   % filling +
- % DeviceCMYK +
- 0 0 0 1 K  % stroking +
- 0 0 0 1 k  % filling+
  
-The PDF4Smalltalk library supports these variations by initializing the renderer with a colorspaceThe renderer can than select the right operators when the fill or stroke color is setThe API is:+<code smalltalk> 
 +renderer strokeColor: <ColorValue or CMYKColor>. 
 +renderer fillColor: <ColorValue or CMYKColor>. 
 +</code>
  
- "colorspace: DeviceGray new" +The renderer will insert ''/DeviceRGB'' operators for ColorValues and ''/DeviceCMYK'' for CMYKColorsIf the color is gray, ''/DevideGray'' is used.
- renderer strokeColor: <ColorValue or CMYKColor>  "with conversion" +
- renderer fillColor: <ColorValue or CMYKColor>    "with conversion" +
- "colorspace: DeviceRGB new" +
- renderer strokeColor: <ColorValue>  "no conversion" +
- renderer fillColor: <ColorValue>    "no conversion" +
- "colorspace: DeviceCMYK new" +
- renderer strokeColor: <CMYKColor>   "no conversion" +
- renderer fillColor: <CMYKColor>     "no conversion"+
  
 Example: Example:
- page := Page newInBounds: (0 @ 0 corner: 100 @ 100) colorspace: DeviceRGB new render: [:renderer | +<code smalltalk> 
- renderer fillColor: ColorValue red. +page := Page newInBounds: (0 @ 0 corner: 100 @ 100) colorspace: DeviceRGB new render: [:renderer | 
- renderer addRectangleLeft: 20 bottom: 20 width: 20 height: 40. +  renderer fillColor: ColorValue red. 
- renderer fill. +  renderer addRectangleLeft: 20 bottom: 20 width: 20 height: 40. 
- renderer strokeColor: ColorValue blue. +  renderer fill. 
- renderer linewidth: 5. +  renderer strokeColor: ColorValue blue. 
- renderer addRectangleLeft: 20 bottom: 20 width: 20 height: 40. +  renderer linewidth: 5. 
- renderer stroke].+  renderer addRectangleLeft: 20 bottom: 20 width: 20 height: 40. 
 +  renderer stroke]. 
 +</code>
/var/www/virtual/code4hl/html/dokuwiki/data/pages/pdf/colors.txt · Last modified: 2016/05/12 12:37 by christian