"Fossies" - the Fresh Open Source Software Archive

Member "PDFlib-Lite-7.0.5p3/bind/pdflib/perl/starter_type3font.pl" (6 Jun 2012, 2606 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) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "starter_type3font.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/perl
    2 # $Id: starter_type3font.pl,v 1.1.2.5 2009/11/18 00:16:12 rjs Exp $
    3 # Type 3 font starter:
    4 # Create a simple Type 3 font from vector data
    5 #
    6 # Define a type 3 font with the glyphs "l" and "space" and output text with
    7 # that font. In addition the glyph ".notdef" is defined which any undefined
    8 # character will be mapped to.
    9 #
   10 # Required software: PDFlib/PDFlib+PDI/PPS 7
   11 # Required data: none
   12 
   13 
   14 use pdflib_pl 7.0;
   15 use strict;
   16 
   17 # This is where the data files are. Adjust as necessary.
   18 my $searchpath = "../data";
   19 my $outfile = "starter_type3font.pdf";
   20 my $title = "Starter Type 3 Font";
   21 
   22 my $buf;
   23 my $font;
   24 my ($x, $y);
   25 # create a new PDFlib object
   26 my $p = PDF_new();
   27 
   28 eval {
   29     PDF_set_parameter($p, "SearchPath", $searchpath);
   30 
   31     # This means we must check return values of load_font() etc.
   32     PDF_set_parameter($p, "errorpolicy", "return");
   33 
   34     if (PDF_begin_document($p, $outfile, "") == -1) {
   35     printf("Error: %s\n", PDF_get_errmsg($p));
   36     PDF_delete($p);
   37     exit(2);
   38     }
   39 
   40     PDF_set_info($p, "Creator", "PDFlib Cookbook");
   41     $buf = $title . '  $Revision: 1.1.2.5 $';
   42     PDF_set_info($p, "Title", $buf);
   43 
   44     # Create the font "SimpleFont" containing the glyph "l",
   45     # the glyph "space" for spaces and the glyph ".notdef" for any
   46     # undefined character
   47 
   48     PDF_begin_font($p, "SimpleFont",
   49         0.001, 0.0, 0.0, 0.001, 0.0, 0.0, "");
   50     PDF_begin_glyph($p, ".notdef", 266, 0, 0, 0, 0);
   51     PDF_end_glyph($p);
   52     PDF_begin_glyph($p, "space", 266, 0, 0, 0, 0);
   53     PDF_end_glyph($p);
   54     PDF_begin_glyph($p, "l", 266, 0, 0, 266, 570);
   55     PDF_setlinewidth($p, 20);
   56     PDF_setdash($p, 0, 0);
   57     $x = 197;
   58     $y = 10;
   59     PDF_moveto($p, $x, $y);
   60     $y += 530;
   61     PDF_lineto($p, $x, $y);
   62     $x -= 64;
   63     PDF_lineto($p, $x, $y);
   64     $y -= 530;
   65     PDF_moveto($p, $x, $y);
   66     $x += 128;
   67     PDF_lineto($p, $x, $y);
   68 
   69     PDF_stroke($p);
   70     PDF_end_glyph($p);
   71 
   72     PDF_end_font($p);
   73 
   74     # Start page
   75     PDF_begin_page_ext($p, 0, 0, "width=300 height=200");
   76 
   77     # Load the new "SimpleFont" font
   78     $font = PDF_load_font($p, "SimpleFont", "winansi", "");
   79 
   80     if ($font == -1) {
   81     printf("Error: %s\n", PDF_get_errmsg($p));
   82     PDF_delete($p);
   83     exit(2);
   84     }
   85 
   86     # Output the characters "l" and "space" of the "SimpleFont" font.
   87     # The character "x" is undefined and will be mapped to ".notdef"
   88 
   89     $buf = " font=" . $font . " fontsize=40";
   90     PDF_fit_textline($p, "lll lllxlll", 100, 100, $buf);
   91 
   92     PDF_end_page_ext($p, "");
   93 
   94     PDF_end_document($p, "");
   95 };
   96 
   97 if ($@) {
   98     printf("starter_type3font: PDFlib Exception occurred:\n");
   99     printf(" $@\n");
  100     exit;
  101 }