"Fossies" - the Fresh Open Source Software Archive

Member "PDFlib-Lite-7.0.5p3/bind/pdflib/cpp/starter_3d.cpp" (6 Jun 2012, 3158 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) C and C++ 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_3d.cpp" see the Fossies "Dox" file reference documentation.

    1 // $Id: starter_3d.cpp,v 1.1.2.1 2008/02/20 21:47:01 rjs Exp $
    2 // 3D Starter:
    3 // Create a 3D model and load it into a U3D annotation.
    4 //
    5 // Define a 3D view and load some 3D data with the view defined. Then create
    6 // an annotation containing the loaded 3D data with the defined 3D view as the
    7 // initial view.
    8 //
    9 // Acrobat 7.07 or above is required for viewing PDF documents containing a
   10 // 3D model.
   11 //
   12 // Required software: PDFlib/PDFlib+PDI/PPS 7.0.1
   13 // Required data: U3D data file
   14 //
   15 
   16 #include <iostream>
   17 
   18 #include "pdflib.hpp"
   19 
   20 using namespace std;
   21 
   22 int
   23 main(void)
   24 {
   25     try {
   26     // This is where the data files are. Adjust if necessary.
   27     string searchpath = "../data";
   28     string outfile = "starter_3d.pdf";
   29 
   30     // Required minimum PDFlib version
   31     double requiredversion = 701;
   32     string requiredvstr = "7.0.1";
   33 
   34     char buf[1024];
   35     char *optlist;
   36     int font, u3dview, u3ddata;
   37     PDFlib p;
   38 
   39         p.set_parameter("SearchPath", searchpath);
   40 
   41         // This means we must check return values of load_font() etc.
   42         p.set_parameter("errorpolicy", "return");
   43 
   44         // Check whether the required minimum PDFlib version is available
   45         double major = p.get_value("major", 0);
   46         double minor = p.get_value("minor", 0);
   47         double revision = p.get_value("revision", 0);
   48 
   49         if (major*100 + minor*10 + revision < requiredversion) {
   50             cerr << "Error: PDFlib " << requiredvstr
   51         << " or above is required" << endl;
   52             return 2;
   53         }
   54 
   55         // Start the document
   56         if (p.begin_document(outfile, "") == -1) {
   57             cerr << "Error: " << p.get_errmsg() << endl;
   58             return 2;
   59         }
   60 
   61         p.set_info("Creator", "PDFlib Cookbook");
   62         p.set_info("Title", "starter_3d");
   63 
   64         font = p.load_font("Helvetica", "winansi", "");
   65         if (font == -1) {
   66             cerr << "Error: " << p.get_errmsg() << endl;
   67             return 2;
   68         }
   69 
   70         p.begin_page_ext(0, 0, "width=a4.width height=a4.height");
   71 
   72         // Define a U3D view
   73         optlist = "name=FirstView background={fillcolor={rgb 1 0.5 0.1}}";
   74         if ((u3dview = p.create_3dview("First view", optlist)) == -1) {
   75             cerr << "Error: " << p.get_errmsg() << endl;
   76             return 2;
   77         }
   78 
   79         // Load some U3D data with the view defined above
   80     sprintf(buf, "views={%d}", u3dview);
   81         if ((u3ddata = p.load_3ddata("box.u3d", buf)) == -1) {
   82             cerr << "Error: " << p.get_errmsg() << endl;
   83             return 2;
   84         }
   85 
   86         // Create an annotation containing the loaded U3D data with the
   87         // defined 3D view as the initial view
   88         //
   89     sprintf(buf, "name=annot usercoordinates contents=U3D 3ddata= %d"
   90             " 3dactivate={enable=open} 3Dinitialview=%d", u3ddata, u3dview);
   91         p.create_annotation(116, 400, 447, 580, "3D", buf);
   92 
   93         p.end_page_ext("");
   94 
   95         p.end_document("");
   96 
   97     }
   98 
   99     catch (PDFlib::Exception &ex) {
  100         cerr << "PDFlib exception occurred in hello sample: " << endl;
  101         cerr << "[" << ex.get_errnum() << "] " << ex.get_apiname()
  102             << ": " << ex.get_errmsg() << endl;
  103         return 2;
  104     }
  105 
  106 
  107 
  108     return 0;
  109 }