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

  1. /* 
  2.    drvSAMPL.cpp : This file is part of pstoedit
  3.    Skeleton for the implementation of new backends
  4.  
  5.    Copyright (C) 1993,1994,1995,1996 Wolfgang Glunz, Wolfgang.Glunz@zfe.siemens.de
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21. */
  22.  
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <stdlib.h>
  26. #include "drvsampl.h"
  27.  
  28. drvSAMPL::drvSAMPL(const char * driveroptions_p,ostream & theoutStream,ostream & theerrStream): // Constructor
  29.     drvbase(driveroptions_p,theoutStream,theerrStream,
  30.         1, // if backend supports subpathes, else 0
  31.            // if subpathes are supported, the backend must deal with
  32.            // sequences of the following form
  33.            // moveto (start of subpath)
  34.            // lineto (a line segment)
  35.            // lineto 
  36.            // moveto (start of a new subpath)
  37.            // lineto (a line segment)
  38.            // lineto 
  39.            //
  40.            // If this argument is set to 0 each subpath is drawn 
  41.            // individually which might not necessarily represent
  42.            // the original drawing.
  43.  
  44.         1,  // if backend supports curves, else 0
  45.         0  // if backend supports elements with fill and edges
  46.     )
  47. {
  48. // driver specific initializations
  49. // and writing of header to output file
  50.     outf << "Sample header \n";
  51. //    float           scale;
  52. //    float           x_offset;
  53. //    float           y_offset;
  54. }
  55.  
  56. drvSAMPL::~drvSAMPL() {
  57. // driver specific deallocations
  58. // and writing of trailer to output file
  59.     outf << "Sample trailer \n";
  60. }
  61.  
  62. void drvSAMPL::print_coords()
  63. {
  64.     for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
  65.     const basedrawingelement & elem = pathElement(n);
  66.     switch (elem.getType()) {
  67.         case moveto: {
  68.             const Point & p = elem.getPoint(0);
  69.             outf << "\t\tmoveto ";
  70.                 outf  << p.x_ + x_offset << " " 
  71.                      <<  /*   currentDeviceHeight -  */   p.y_ + y_offset << " " ;
  72.             }
  73.             break;
  74.         case lineto: {
  75.             const Point & p = elem.getPoint(0);
  76.             outf << "\t\tlineto ";
  77.                 outf  << p.x_ + x_offset << " " 
  78.                      <<  /*   currentDeviceHeight -  */   p.y_ + y_offset << " " ;
  79.             }
  80.             break;
  81.         case closepath: 
  82.             outf << "\t\tclosepath ";
  83.             break;
  84.         case curveto:{
  85.             outf << "\t\tcurveto " ;
  86.             for (unsigned int cp = 0 ; cp < 3; cp++ ) {
  87.                 const Point & p = elem.getPoint(cp);
  88.                     outf  << (p.x_ + x_offset) << " " 
  89.                          <<  /*   currentDeviceHeight -  */   (p.y_ + y_offset) << " " ;
  90.             }
  91.             }
  92.             break;
  93.         default:
  94.             errf << "\t\tFatal: unexpected case in drvpdf " << endl;
  95.             abort();
  96.             break;
  97.     }
  98.     outf << endl;
  99.     }
  100. }
  101.  
  102.  
  103. void drvSAMPL::open_page()
  104. {
  105.     outf << "Opening page: " << currentPageNumber << endl;
  106. }
  107.  
  108. void drvSAMPL::close_page()
  109. {
  110.     outf << "Closing page: " << (currentPageNumber) << endl;
  111. }
  112.  
  113. void drvSAMPL::show_text(const TextInfo & textinfo)
  114. {
  115.     outf << "Text String : " << textinfo.thetext << endl;
  116.     outf << '\t' << "X " << textinfo.x << " Y " << textinfo.y << endl;
  117.     outf << '\t' << "currentFontName: " <<  textinfo.currentFontName.value() << endl;
  118.     outf << '\t' << "is_non_standard_font: " <<  textinfo.is_non_standard_font << endl;
  119.     outf << '\t' << "currentFontFamilyName: " << textinfo.currentFontFamilyName.value() << endl;
  120.     outf << '\t' << "currentFontFullName: " << textinfo.currentFontFullName.value() << endl;
  121.     outf << '\t' << "currentFontWeight: " << textinfo.currentFontWeight.value() << endl;
  122.     outf << '\t' << "currentFontSize: " << textinfo.currentFontSize << endl;
  123.     outf << '\t' << "currentFontAngle: " << textinfo.currentFontAngle << endl;
  124.     outf << '\t' << "currentR: " << textinfo.currentR << endl;
  125.     outf << '\t' << "currentG: " << textinfo.currentG << endl;
  126.     outf << '\t' << "currentB: " << textinfo.currentB << endl;
  127. }
  128.  
  129. void drvSAMPL::show_path()
  130. {
  131.     outf << "Path # " << pathnumber ;
  132.         if (isPolygon()) outf << " (polygon): "  << endl;
  133.         else   outf << " (polyline): " << endl;
  134.     outf << "\tcurrentShowType: ";
  135.         switch (currentShowType() ) {
  136.         case drvbase::stroke : 
  137.         outf << "stroked";
  138.               break;
  139.         case drvbase::fill :
  140.         outf << "filled";
  141.               break;
  142.         case drvbase::eofill :
  143.         outf << "eofilled";
  144.               break;
  145.         default: 
  146.     // cannot happen
  147.               outf << "unexpected ShowType " << (int) currentShowType() ;
  148.               break;
  149.         }
  150.     outf << endl;
  151.     if (currentShowType() == drvbase::fill)   outf << "\tcurrentShowType: filled " << endl;
  152.     if (currentShowType() == drvbase::eofill) outf << "\tcurrentShowType: eofilled " << endl;
  153.     outf << "\tcurrentLineWidth: " <<  currentLineWidth() << endl;
  154.     outf << "\tcurrentR: " << currentR() << endl;
  155.     outf << "\tcurrentG: " << currentG() << endl;
  156.     outf << "\tcurrentB: " << currentB() << endl;
  157.     outf << "\tcurrentLineCap: " << currentLineCap() << endl;
  158.     outf << "\tdashPattern: " << dashPattern() << endl;
  159.     outf << "\tPath Elements 0 to "  <<  numberOfElementsInPath()-1  << endl;
  160.     print_coords();
  161.  
  162. };
  163.  
  164. void drvSAMPL::show_rectangle(const float llx, const float lly, const float urx, const float ury)
  165. {
  166.     outf << "Rectangle ( " << llx << "," << lly << ") (" << urx << "," << ury << ")" << endl;
  167. // just do show_path for a first guess
  168.     show_path();
  169. }
  170.