User Tools

Site Tools


pdf:colors

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
pdf:colors [2015/03/28 17:14] 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.   * **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.   * **DeviceCMYK** subtractive (for printing); 4 components [0..1]; `0 0 0 1` is black, `0 0 0 0` is white.
  
-=== CIE-based colorspaces ===+===== CIE-based colorspaces =====
  
 Calibrated: device independent, reproducable. Calibrated: device independent, reproducable.
  
   * **CalGray**   * **CalGray**
- 
   * **CalRGB**   * **CalRGB**
- 
   * **Lab**   * **Lab**
- 
   * **ICCBased**   * **ICCBased**
  
-=== Special colorspaces === +===== Special colorspaces =====
  
   * **Indexed**   * **Indexed**
- 
   * **Pattern**   * **Pattern**
- 
   * **Separation**   * **Separation**
- 
   * **DeviceN**   * **DeviceN**
  
 Most commonly used and easiest are the device colorspaces. Setting black is done like this in the different colorspaces: Most commonly used and easiest are the device colorspaces. Setting black is done like this in the different colorspaces:
- % DeviceGray +  % DeviceGray 
- 0 G        % stroking +  0 G        % stroking 
- 0 g        % filling +  0 g        % filling 
- % DeviceRGB +  % DeviceRGB 
- 0 0 0 RG   % stroking +  0 0 0 RG   % stroking 
- 0 0 0 rg   % filling +  0 0 0 rg   % filling 
- % DeviceCMYK +  % DeviceCMYK 
- 0 0 0 1 K  % stroking +  0 0 0 1 K  % stroking 
- 0 0 0 1 k  % filling+  0 0 0 1 k  % filling 
 + 
 +The renderer supports the device color spaces. If you need other color spaces, you need to work directly with the color operators.
  
-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