File: drvrib.cpp

package info (click to toggle)
pstoedit 2.60-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,000 kB
  • ctags: 1,095
  • sloc: cpp: 7,865; perl: 796; makefile: 188
file content (143 lines) | stat: -rw-r--r-- 4,168 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* 
   drvrib.cpp - Driver to output RenderMan RIB polygons
			 - written by Glenn M. Lewis (glewis@c2.net) - 6/18/96
			   http://www.c2.net/~glewis/
			   Based on...

   drvSAMPL.cpp : This file is part of pstoedit
   Skeleton for the implementation of new backends

   Copyright (C) 1993,1994,1995,1996,1997 Wolfgang Glunz, Wolfgang.Glunz@mchp.siemens.de

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include <stdio.h>
// rcw2: work round case insensitivity in RiscOS
#ifdef riscos
  #include "unix:string.h"
#else
  #include <string.h>
#endif
#include <stdlib.h>
#include "drvrib.h"

drvRIB::drvRIB(const char * driveroptions_p,ostream & theoutStream,ostream & theerrStream): // Constructor
  drvbase(driveroptions_p,theoutStream,theerrStream,
	  0, // if backend supports subpathes, else 0
	  // if subpathes are supported, the backend must deal with
	  // sequences of the following form
	  // moveto (start of subpath)
	  // lineto (a line segment)
	  // lineto 
	  // moveto (start of a new subpath)
	  // lineto (a line segment)
	  // lineto 
	  //
	  // If this argument is set to 0 each subpath is drawn 
	  // individually which might not necessarily represent
	  // the original drawing.

	  0,  // if backend supports curves, else 0
	  0  // if backend supports elements with fill and edges
	  )
{
  // driver specific initializations
  // and writing of header to output file
  outf << "##RenderMan RIB-Structure 1.0" << endl;
  outf << "version 3.03" << endl;
  outf << "AttributeBegin" << endl;
}

drvRIB::~drvRIB()
{
  // driver specific deallocations
  // and writing of trailer to output file
  outf << "AttributeEnd" << endl;
}

void drvRIB::print_coords()
{
  outf << "PointsGeneralPolygons[1]" << endl;
  outf << "[" << numberOfElementsInPath() << "]" << endl << "[";
  for (unsigned int i = 0; i < numberOfElementsInPath(); i++) {
    outf << i << " ";
  }
  outf << "]" << endl << "\"P\" [";
  for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
    const basedrawingelement & elem = pathElement(n);
    switch (elem.getType()) {
    case moveto: {
      const Point & p = elem.getPoint(0);
      // outf << "\t\tmoveto ";
      outf  << p.x_ + x_offset << " " << p.y_ + y_offset << " 0 " ;
    }
    break;
    case lineto: {
      const Point & p = elem.getPoint(0);
      // outf << "\t\tlineto ";
      outf  << p.x_ + x_offset << " " << p.y_ + y_offset << " 0 " ;
    }
    break;
    case closepath: // Not supported
      // outf << "\t\tclosepath ";
      break;
    case curveto:{  // Not supported
    }
    break;
    default:
      errf << "\t\tFatal: unexpected case in drvpdf " << endl;
      abort();
      break;
    }
    outf << endl;
  }
  outf << "]" << endl;
}


void drvRIB::open_page()
{
  //  outf << "Opening page: " << currentPageNumber << endl;
}

void drvRIB::close_page()
{
  //  outf << "Closing page: " << (currentPageNumber) << endl;
}

void drvRIB::show_text(const TextInfo & textinfo)
{
  // Must use the -dt flag for this, since RenderMan doesn't support text
  unused(&textinfo);
}

void drvRIB::show_path()
{
  outf << "Color " << currentR() << " " << currentG() << " " << currentB() << endl;
  print_coords();
};

void drvRIB::show_rectangle(const float llx, const float lly, const float urx, const float ury)
{
  // outf << "Rectangle ( " << llx << "," << lly << ") (" << urx << "," << ury << ")" << endl;
  // just do show_path for a first guess
  unused(&llx);
  unused(&lly);
  unused(&urx);
  unused(&ury);
  show_path();
}