"Fossies" - the Fresh Open Source Software Archive

Member "PDFlib-Lite-7.0.5p3/bind/pdflib/tcl/starter_color.tcl" (6 Jun 2012, 10812 Bytes) of package /linux/misc/old/PDFlib-Lite-7.0.5p3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Tcl/Tk source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "starter_color.tcl" see the Fossies "Dox" file reference documentation.

    1 #!/bin/sh
    2 # $Id: starter_color.tcl,v 1.1.2.4 2008/01/10 12:08:01 kurt Exp $
    3 #
    4 # Hide the exec to Tcl but not to the shell by appending a backslash\
    5 exec tclsh "$0" ${1+"$@"}
    6 
    7 # The lappend line is unnecessary if PDFlib has been installed
    8 # in the Tcl package directory
    9 set auto_path [linsert $auto_path 0 .libs .]
   10 
   11 package require pdflib 7.0
   12 
   13 # Starter color:
   14 # Demonstrate the basic use of supported color spaces
   15 #
   16 # Apply the following color spaces to text and vector graphics:
   17 # - gray
   18 # - rgb
   19 # - cmyk
   20 # - iccbasedgray/rgb/cmyk
   21 # - spot
   22 # - lab
   23 # - pattern
   24 # - shadings
   25 #
   26 # Required software: PDFlib/PDFlib+PDI/PPS 7
   27 # Required data: none
   28  
   29 set p [PDF_new]
   30 
   31 if { [catch {
   32 
   33     # This is where the data files are. Adjust as necessary. 
   34     set searchpath "../data"
   35     set outfile "starter_color.pdf"
   36 
   37     set y 800 
   38     set x 50 
   39     set xoffset1 80 
   40     set xoffset2 100 
   41     set yoffset 70 
   42     set r 30
   43 
   44     PDF_set_parameter $p "SearchPath" $searchpath
   45 
   46     PDF_set_parameter $p "errorpolicy" "exception"
   47 
   48     PDF_begin_document $p $outfile ""   
   49 
   50     PDF_set_info $p "Creator" "PDFlib starter sample" 
   51     PDF_set_info $p "Title" "starter_color" 
   52 
   53     # Load the font 
   54     set font [PDF_load_font $p "Helvetica" "winansi" ""]
   55 
   56     # Start the page 
   57     PDF_begin_page_ext $p 0 0 "width=a4.width height=a4.height" 
   58 
   59     PDF_setfont $p $font 14 
   60 
   61     # -------------------------------------------------------------------
   62     # Use default colors
   63     #
   64     # If no special color is set the default values will be used. The
   65     # default values are restored at the beginning of the page.
   66     # 0=black in the Gray color space is the default fill and stroke
   67     # color in many cases as shown in our sample.
   68     # -------------------------------------------------------------------
   69 
   70     # Fill a circle with the default black fill color 
   71     set y [expr $y - $yoffset] 
   72     PDF_circle $p $x $y $r 
   73     PDF_fill $p 
   74 
   75     # Output text with default black fill color 
   76     PDF_fit_textline $p \
   77             "Circle and text filled with default color {gray 0}" \
   78             [expr $x + $xoffset2] $y "" 
   79 
   80     PDF_fit_textline $p "1." [expr $x + $xoffset1] $y "" 
   81 
   82     # -------------------------------------------------------------------
   83     # Use the Gray color space
   84     #
   85     # Gray color is defined by Gray values between 0=black and 1=white.
   86     # -------------------------------------------------------------------
   87 
   88     # Using setcolor(  set the current fill color to a light gray
   89     # represented by (0.5 0 0 0  which defines 50% gray. Since gray
   90     # colors are defined by only one value the last three function
   91     # parameters must be set to 0.
   92 
   93     PDF_setcolor $p "fill" "gray" 0.5 0 0 0 
   94 
   95     # Fill a circle with the current fill color defined above 
   96     set y [expr $y - $yoffset] 
   97     PDF_circle $p $x $y $r 
   98     PDF_fill $p 
   99 
  100     # Output text with the current fill color 
  101     PDF_fit_textline $p "Circle and text filled with {gray 0.5}" \
  102             [expr $x + $xoffset2] $y "" 
  103 
  104     # Alternatively you can set the fill color in the call to
  105     # fit_textline(  using the "fillcolor" option. This case applies the
  106     # fill color just the single function call. The current fill color
  107     # won't be affected.
  108 
  109     PDF_fit_textline $p "2." [expr $x + $xoffset1] $y \
  110             "fillcolor={gray 0.5}" 
  111 
  112 
  113     # --------------------------------------------------------------------
  114     # Use the RGB color space
  115     #
  116     # RGB color is defined by RGB triples i.e. three values between 0 and
  117     # 1 specifying the percentage of red green and blue.
  118     # (0 0 0  is black and (1 1 1  is white. The commonly used RGB
  119     # color values in the range 0...255 must be divided by 255 in order to
  120     # scale them to the range 0...1 as required by PDFlib.
  121     # --------------------------------------------------------------------
  122 
  123 
  124     # Use setcolor(  to set the fill color to a grass-green
  125     # represented by (0.1 0.95 0.3 0  which defines 10% red 95% green,
  126     # 30% blue. Since RGB colors are defined by only three values the last
  127     # function parameter must be set to 0.
  128 
  129     PDF_setcolor $p "fill" "rgb" 0.1 0.95 0.3 0 
  130 
  131     # Draw a circle with the current fill color defined above 
  132     set y [expr $y - $yoffset] 
  133     PDF_circle $p $x $y $r 
  134     PDF_fill $p 
  135 
  136     # Output a text line with the RGB fill color defined above 
  137     PDF_fit_textline $p "Circle and text filled with {rgb 0.1 0.95 0.3}" \
  138             [expr $x + $xoffset2] $y ""
  139 
  140     # Alternatively you can set the fill color in the call to
  141     # fit_textline(  using the "fillcolor" option. This case applies the
  142     # fill color just the single function call. The current fill color
  143     # won't be affected.
  144 
  145     PDF_fit_textline $p "3." [expr $x + $xoffset1] $y \
  146              "fillcolor={rgb 0.1 0.95 0.3}" 
  147 
  148 
  149     # --------------------------------------------------------------------
  150     # Use the CMYK color space
  151     #
  152     # CMYK color is defined by four CMYK values between 0 no color and
  153     # 1 full color representing cyan magenta yellow and black values
  154     # (0 0 0 0  is white and (0 0 0 1  is black.
  155     # --------------------------------------------------------------------
  156 
  157 
  158     # Use setcolor(  to set the current fill color to a pale
  159     # orange represented by (0.1 0.7 0.7 0.1  which defines 10% Cyan,
  160     # 70% Magenta 70% Yellow and 10% Black.
  161 
  162     PDF_setcolor $p "fill" "cmyk" 0.1 0.7 0.7 0.1 
  163 
  164     # Fill a circle with the current fill color defined above 
  165     set y [expr $y - $yoffset] 
  166     PDF_circle $p $x $y $r 
  167     PDF_fill $p 
  168 
  169     # Output a text line with the CMYK fill color defined above 
  170     PDF_fit_textline $p "Circle and text filled with {cmyk 0.1 0.7 0.7 0.1}" \
  171             [expr $x + $xoffset2] $y ""
  172 
  173     # Alternatively you can set the fill color in the call to
  174     # fit_textline(  using the "fillcolor" option. This case applies the
  175     # fill color just the single function call. The current fill color
  176     # won't be affected.
  177 
  178     PDF_fit_textline $p "4." [expr $x + $xoffset1] $y \
  179             "fillcolor={cmyk 0.1 0.7 0.7 0.1}" 
  180 
  181     # --------------------------------------------------------------------
  182     # Use a Lab color
  183     #
  184     # Device-independent color in the CIE L*a*b* color space is specified
  185     # by a luminance value in the range 0-100 and two color values in the
  186     # range -127 to 128. The first value contains the green-red axis,
  187     # while the second value contains the blue-yellow axis.
  188     # --------------------------------------------------------------------
  189 
  190 
  191     # Set the current fill color to a loud blue represented by
  192     # (100 -127 -127 0 . Since Lab colors are defined by only three
  193     # values the last function parameter must be set to 0.
  194 
  195     PDF_setcolor $p "fill" "lab" 100 -127 -127 0 
  196 
  197     # Fill a circle with the fill color defined above 
  198     set y [expr $y - $yoffset] 
  199     PDF_circle $p $x $y $r 
  200     PDF_fill $p 
  201 
  202     # Output a text line with the Lab fill color defined above 
  203     PDF_fit_textline $p "Circle and text filled with {lab 100 -127 -127}" \
  204             [expr $x + $xoffset2] $y ""
  205 
  206     # Alternatively you can set the fill color in the call to
  207     # fit_textline(  using the "fillcolor" option. This case applies the
  208     # fill color just the single function call. The current fill color
  209     # won't be affected.
  210 
  211     PDF_fit_textline $p "5." [expr $x + $xoffset1] $y \
  212             "fillcolor={lab 100 -127 -127}" 
  213 
  214 
  215     # ---------------------------------------------------------------
  216     # Use an ICC based color
  217     #
  218     # ICC-based colors are specified with the help of an ICC profile.
  219     # ---------------------------------------------------------------
  220 
  221 
  222     # Load the sRGB profile. sRGB is guaranteed to be always available 
  223     set icchandle [PDF_load_iccprofile $p "sRGB" "usage=iccbased"]
  224 
  225     # Set the sRGB profile. (Accordingly you can use
  226     # "setcolor:iccprofilergb" or "setcolor:iccprofilegray" with an
  227     # appropriate profile 
  228 
  229     PDF_set_value $p "setcolor:iccprofilergb" $icchandle 
  230 
  231     # Use setcolor(  with the "iccbasedrgb" color space to set the current
  232     # fill and stroke color to a grass-green represented
  233     # by the RGB color values (0.1 0.95 0.3 0  which define 10% Red,
  234     # 95% Green and 30% Blue. Since iccbasedrgb colors are defined by only
  235     # three values the last function parameter must be set to 0.
  236 
  237     PDF_setcolor $p "fill" "iccbasedrgb" 0.1 0.95 0.3 0 
  238 
  239     # Fill a circle with the ICC based RGB fill color defined above 
  240     set y [expr $y - $yoffset] 
  241     PDF_circle $p $x $y $r 
  242     PDF_fill $p 
  243 
  244     # Output a text line with the ICC based RGB fill color defined above 
  245     PDF_fit_textline $p "Circle and text filled with {iccbasedrgb 0.1 0.95 0.3}" \
  246             [expr $x + $xoffset2] $y ""
  247 
  248     # Alternatively you can set the fill color in the call to
  249     # fit_textline(  using the "fillcolor" option. This case applies the
  250     # fill color just the single function call. The current fill color
  251     # won't be affected.
  252 
  253     PDF_fit_textline $p "6." [expr $x + $xoffset1] $y \
  254             "fillcolor={iccbasedrgb 0.1 0.95 0.3}" 
  255 
  256     # --------------------------------------------------------------------
  257     # Use a spot color
  258     #
  259     # Spot color (separation color space  is a predefined or arbitrarily
  260     # named custom color with an alternate representation in one of the
  261     # other color spaces above this is generally used for preparing
  262     # documents which are intended to be printed on an offset printing
  263     # machine with one or more custom colors. The tint value  $percentage 
  264     # ranges from 0 no color to 1 maximum intensity of the spot color.
  265     # --------------------------------------------------------------------
  266 
  267 
  268     # Define the spot color "PANTONE 281 U" from the builtin color
  269     # library PANTONE
  270 
  271     set spot [PDF_makespotcolor $p "PANTONE 281 U"]
  272 
  273     # Set the spot color "PANTONE 281 U" with a tint value of 1 (=100% 
  274     # and output some text. Since spot colors are defined by only two
  275     # values the last two function parameters must be set to 0.
  276 
  277     PDF_setcolor $p "fill" "spot" $spot 1.0 0 0 
  278 
  279     # Fill a circle with the ICC based RGB fill color defined above 
  280     set y [expr $y - $yoffset] 
  281     PDF_circle $p $x $y $r 
  282     PDF_fill $p 
  283 
  284     PDF_fit_textline $p "Circle and text filled with {spotname {PANTONE 281 U} 1}" \
  285             [expr $x + $xoffset2] $y ""
  286 
  287     # Alternatively you can set the fill color in the call to
  288     # fit_textline(  using the "fillcolor" option. This case applies the
  289     # fill color just the single function call. The current fill color
  290     # won't be affected.
  291 
  292     PDF_fit_textline $p "7." [expr $x + $xoffset1] $y \
  293         "fillcolor={spotname {PANTONE 281 U} 1}" 
  294 
  295     # or 
  296     PDF_fit_textline $p "7." [expr $x + $xoffset1] $y "fillcolor={spot $spot 1}"
  297     
  298     # ---------------------------------------------------------
  299     # For using the Pattern color space see the Cookbook topics
  300     # graphics/fill_pattern and images/background_pattern.
  301     # ----------------------------------------------------------
  302 
  303 
  304     # --------------------------------------------------------
  305     # For using the Shading color space see the Cookbook topic
  306     # color/color_gradient.
  307     # ---------------------------------------------------------
  308 
  309 
  310     PDF_end_page_ext $p ""
  311 
  312     PDF_end_document $p ""
  313 
  314 } result]} {
  315     puts stderr $result
  316 }
  317 
  318 PDF_delete $p