home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / pstoedit.zip / source.zip / pstoedit.2.50 / src / drvrib.cpp < prev    next >
C/C++ Source or Header  |  1996-10-29  |  4KB  |  139 lines

  1. /* 
  2.    drvrib.cpp - Driver to output RenderMan RIB polygons
  3.              - written by Glenn M. Lewis (glewis@c2.net) - 6/18/96
  4.                http://www.c2.net/~glewis/
  5.                Based on...
  6.  
  7.    drvSAMPL.cpp : This file is part of pstoedit
  8.    Skeleton for the implementation of new backends
  9.  
  10.    Copyright (C) 1993,1994,1995,1996 Wolfgang Glunz, Wolfgang.Glunz@zfe.siemens.de
  11.  
  12.     This program is free software; you can redistribute it and/or modify
  13.     it under the terms of the GNU General Public License as published by
  14.     the Free Software Foundation; either version 2 of the License, or
  15.     (at your option) any later version.
  16.  
  17.     This program is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.     GNU General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU General Public License
  23.     along with this program; if not, write to the Free Software
  24.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  
  26. */
  27.  
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <stdlib.h>
  31. #include "drvrib.h"
  32.  
  33. drvRIB::drvRIB(const char * driveroptions_p,ostream & theoutStream,ostream & theerrStream): // Constructor
  34.   drvbase(driveroptions_p,theoutStream,theerrStream,
  35.       0, // if backend supports subpathes, else 0
  36.       // if subpathes are supported, the backend must deal with
  37.       // sequences of the following form
  38.       // moveto (start of subpath)
  39.       // lineto (a line segment)
  40.       // lineto 
  41.       // moveto (start of a new subpath)
  42.       // lineto (a line segment)
  43.       // lineto 
  44.       //
  45.       // If this argument is set to 0 each subpath is drawn 
  46.       // individually which might not necessarily represent
  47.       // the original drawing.
  48.  
  49.       0,  // if backend supports curves, else 0
  50.       0  // if backend supports elements with fill and edges
  51.       )
  52. {
  53.   // driver specific initializations
  54.   // and writing of header to output file
  55.   outf << "##RenderMan RIB-Structure 1.0" << endl;
  56.   outf << "version 3.03" << endl;
  57.   outf << "AttributeBegin" << endl;
  58. }
  59.  
  60. drvRIB::~drvRIB()
  61. {
  62.   // driver specific deallocations
  63.   // and writing of trailer to output file
  64.   outf << "AttributeEnd" << endl;
  65. }
  66.  
  67. void drvRIB::print_coords()
  68. {
  69.   outf << "PointsGeneralPolygons[1]" << endl;
  70.   outf << "[" << numberOfElementsInPath() << "]" << endl << "[";
  71.   for (unsigned int i = 0; i < numberOfElementsInPath(); i++) {
  72.     outf << i << " ";
  73.   }
  74.   outf << "]" << endl << "\"P\" [";
  75.   for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
  76.     const basedrawingelement & elem = pathElement(n);
  77.     switch (elem.getType()) {
  78.     case moveto: {
  79.       const Point & p = elem.getPoint(0);
  80.       // outf << "\t\tmoveto ";
  81.       outf  << p.x_ + x_offset << " " << p.y_ + y_offset << " 0 " ;
  82.     }
  83.     break;
  84.     case lineto: {
  85.       const Point & p = elem.getPoint(0);
  86.       // outf << "\t\tlineto ";
  87.       outf  << p.x_ + x_offset << " " << p.y_ + y_offset << " 0 " ;
  88.     }
  89.     break;
  90.     case closepath: // Not supported
  91.       // outf << "\t\tclosepath ";
  92.       break;
  93.     case curveto:{  // Not supported
  94.     }
  95.     break;
  96.     default:
  97.       errf << "\t\tFatal: unexpected case in drvpdf " << endl;
  98.       abort();
  99.       break;
  100.     }
  101.     outf << endl;
  102.   }
  103.   outf << "]" << endl;
  104. }
  105.  
  106.  
  107. void drvRIB::open_page()
  108. {
  109.   //  outf << "Opening page: " << currentPageNumber << endl;
  110. }
  111.  
  112. void drvRIB::close_page()
  113. {
  114.   //  outf << "Closing page: " << (currentPageNumber) << endl;
  115. }
  116.  
  117. void drvRIB::show_text(const TextInfo & textinfo)
  118. {
  119.   // Must use the -dt flag for this, since RenderMan doesn't support text
  120.   unused(&textinfo);
  121. }
  122.  
  123. void drvRIB::show_path()
  124. {
  125.   outf << "Color " << currentR() << " " << currentG() << " " << currentB() << endl;
  126.   print_coords();
  127. };
  128.  
  129. void drvRIB::show_rectangle(const float llx, const float lly, const float urx, const float ury)
  130. {
  131.   // outf << "Rectangle ( " << llx << "," << lly << ") (" << urx << "," << ury << ")" << endl;
  132.   // just do show_path for a first guess
  133.   unused(&llx);
  134.   unused(&lly);
  135.   unused(&urx);
  136.   unused(&ury);
  137.   show_path();
  138. }
  139.