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

  1. /* 
  2.    drvMIF.cpp : This file is part of pstoedit
  3.    Backend for Framemaker(TM) MIF format
  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 "drvmif.h"
  24. #include <iostream.h>
  25. #include <string.h>
  26. #include <stdio.h>
  27.  
  28. static const char * colorstring(float r, float g, float b)
  29. {
  30. static char buffer[15];
  31.     sprintf(buffer,"R%.3dG%.3dB%.3d", (int) (r * 255), (int) ( g * 255) ,  (int) (b * 255));
  32.     return buffer;
  33. }
  34.  
  35. static ColorTable colorTable(0,0,colorstring);
  36.  
  37. static void writeColorCatEntry(ostream & out, float r, float g, float b)
  38. {
  39. // all ColorCatEntries are written directly to the output file.
  40. // the other stuff is written to the buffer
  41. if (!colorTable.isKnownColor(r,g,b)) {
  42. // color not known so far
  43.     int cyan    = (int) (100 * (1.0 - r)) ;
  44.     int magenta = (int) (100 * (1.0 - g)) ;
  45.     int yellow  = (int) (100 * (1.0 - b)) ;
  46.     //int black   = ((cyan + magenta + yellow) == 300 ) ? 100 : 0; // black 0 if not black
  47.     int black = 0;
  48.  
  49.     // remember, getColorString registers the new color
  50.     out << " <Color "
  51.         << "<ColorTag " << colorTable.getColorString(r,g,b) << " > " 
  52.         << "<ColorCyan " << cyan  << " >"
  53.         << "<ColorMagenta " << magenta  << " >"
  54.         << "<ColorYellow " << yellow  << " >"
  55.         << "<ColorBlack " << black  << " >"
  56.         << ">" << endl;
  57. }
  58.  
  59. drvMIF::drvMIF(const char * driveroptions_p,ostream & theoutStream,ostream & theerrStream):
  60.     drvbase(driveroptions_p,theoutStream,theerrStream,0,0,0),
  61.         buffer(tempFile.asOutput())
  62. {
  63.     outf << "<MIFFile 4.00>\n";
  64.     outf << "<Units Upt >\n";
  65.     outf << "<ColorCatalog\n";
  66.                  // output buffer, needed because
  67.                  // color entries must be written at
  68.                  // top of output file, but are known
  69.                  // only after processing the full input
  70.  
  71. }
  72.  
  73. drvMIF::~drvMIF() 
  74. {
  75.  
  76.     outf << ">\n";// end of ColorCatalog
  77.     ifstream & inbuffer = tempFile.asInput();
  78.     copy_file(inbuffer,outf);
  79.  
  80. void drvMIF::print_coords()
  81. {
  82.     for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
  83.     const Point & p = pathElement(n).getPoint(0);
  84.         buffer <<" <Point "  
  85.          << p.x_ + x_offset << " pt " 
  86.          << currentDeviceHeight - p.y_ + y_offset << " pt>" 
  87.          << endl;
  88.     }
  89. }
  90.  
  91. void drvMIF::close_page()
  92. {
  93.     buffer << "> # end of Frame\n";
  94.     buffer << "> # end of Page\n";
  95. }
  96.  
  97. static const int Fill   = 0;  // solid fill
  98. static const int noFill = 15; // no fill
  99.  
  100. void drvMIF::open_page()
  101. {
  102.     buffer << "<Page\n";
  103.     buffer << " <PageType BodyPage >\n";
  104.     buffer << " <PageNum `" << currentPageNumber << "'>\n";
  105. //    buffer << " <PageSize  612.0 pt 792.0 pt>\n";
  106.     //     currentDeviceWidth), RND(currentDeviceHeight
  107.     buffer << " <PageSize  " << currentDeviceWidth << " pt " << currentDeviceHeight  << " pt>\n";
  108.     buffer << " <PageOrientation Portrait >\n";
  109.     buffer << " <PageBackground `Default'>\n";
  110.     buffer << "<Frame\n";
  111.     buffer << "  <Pen 0>\n";
  112.     buffer << "  <Fill " << noFill << ">\n"; 
  113.     buffer << "  <PenWidth  1.0 pt>\n";
  114.     buffer << "  <Separation 0>\n";
  115. //    buffer << "  <BRect  0.0 pt 0.0 pt 612.0 pt 792.0 pt>\n";
  116.     buffer << "  <BRect  0.0 pt 0.0 pt " << currentDeviceWidth << " pt " << currentDeviceHeight  << " pt>\n";
  117.     buffer << "  <FrameType NotAnchored >\n";
  118. }
  119.  
  120. void drvMIF::show_text(const TextInfo & textinfo)
  121. {
  122.     const char * start_of_text = textinfo.thetext;
  123.     buffer << "  <TextLine \n";
  124.     buffer << "   <TLOrigin  " 
  125.      << textinfo.x + x_offset << " pt " 
  126.      << currentDeviceHeight - textinfo.y + y_offset << " pt>\n";
  127.     buffer << "   <TLAlignment Left >\n";
  128.     buffer << "   <Angle " << textinfo.currentFontAngle << " >" << endl;
  129.     buffer << "   <Font \n";
  130.     buffer << "    <FTag `'>\n";
  131.     buffer << "    <FFamily `";
  132.     const char * cp = textinfo.currentFontName.value();
  133.     // print up to first '-' or end of string 
  134.     while (cp && *cp && (*cp != '-') ) {
  135.     buffer << *cp;
  136.     cp++;
  137.     }
  138.     buffer << "'>\n";
  139.  
  140.     buffer << "# currentFontFamilyName: " <<  textinfo.currentFontFamilyName.value() << endl;
  141.     buffer << "# currentFontFullName: " << textinfo.currentFontFullName.value() << endl;
  142.     buffer << "# currentFontName: " << textinfo.currentFontName.value() << endl;
  143.     buffer << "    <FVar `Regular'>\n";
  144.     buffer << "    <FWeight `" << textinfo.currentFontWeight.value() << "'>"<< endl;
  145.     if (  (strstr(textinfo.currentFontName.value(),"Italic") != NULL)  ||
  146.           (strstr(textinfo.currentFontName.value(),"Oblique") != NULL))  {
  147.         buffer << "    <FAngle `Italic'>\n";
  148.     } else {
  149.         buffer << "    <FAngle `Regular'>\n";
  150.     }
  151.     buffer << "    <FSize  " << textinfo.currentFontSize << " pt>\n" ;
  152.     buffer << "    <FUnderline No >\n";
  153.     buffer << "    <FOverline No >\n";
  154.     buffer << "    <FStrike No >\n";
  155.     buffer << "    <FSupScript No >\n";
  156.     buffer << "    <FSubScript No >\n";
  157.     buffer << "    <FChangeBar No >\n";
  158.     buffer << "    <FOutline No >\n";
  159.     buffer << "    <FShadow No >\n";
  160.     buffer << "    <FPairKern Yes >\n";
  161.     buffer << "    <FDoubleUnderline No >\n";
  162.     buffer << "    <FNumericUnderline No >\n";
  163.     buffer << "    <FDX  0.0 pt>\n";
  164.     buffer << "    <FDY  0.0 pt>\n";
  165.     buffer << "    <FDW  0.0 pt>\n";
  166.     buffer << "    <FSeparation 0>\n";
  167.     writeColorCatEntry(outf,textinfo.currentR,textinfo.currentG,textinfo.currentB);
  168.     buffer << "     <FColor `" << colorTable.getColorString(textinfo.currentR,textinfo.currentG,textinfo.currentB) << "'> ";
  169.     buffer << "\n" << endl;
  170.     buffer << "   > # end of Font\n";
  171.     buffer << "   <String `";
  172.     while (*start_of_text) {
  173.         if ( (*start_of_text == '>') ||
  174.              (*start_of_text == '\'')
  175.                      ){
  176.         buffer << "\\";
  177.         }
  178.         buffer << *start_of_text;
  179.         start_of_text++;
  180.     }
  181.     buffer << "'>\n";
  182.     buffer << "  > # end of TextLine\n";
  183. }
  184.  
  185.  
  186. void drvMIF::show_path()
  187. {
  188.  
  189.     if (isPolygon()) {
  190.     numberOfElementsInPath()--; // MIF does not need end=start
  191.     buffer << "<Polygon\n <NumPoints " << numberOfElementsInPath() << ">\n";
  192.     if (currentShowType() == drvbase::stroke) {
  193.         buffer << " <Fill " << noFill << ">\n";
  194.     } else {
  195.         buffer << " <Fill " << Fill << ">\n";
  196.     }
  197.     buffer << " <Pen  " << Fill << ">\n";
  198.     buffer << " <PenWidth "  << currentLineWidth() << " pt>\n";
  199.     writeColorCatEntry(outf,currentR(),currentG(),currentB()) ;
  200.     buffer << " <ObColor `" << colorTable.getColorString(currentR(),currentG(),currentB()) << "'>";
  201.     buffer << "\n" << endl;
  202.     print_coords();
  203.     buffer << "> # end of Polygon\n";
  204.     numberOfElementsInPath()++; // restore old value for proper cleanup
  205.     } else {
  206.     buffer << "<PolyLine\n <NumPoints " << numberOfElementsInPath() << ">\n";
  207.     if (currentShowType() == drvbase::stroke) {
  208.         buffer << " <Fill " << noFill << ">\n";
  209.     } else {
  210.         buffer << " <Fill " << Fill << ">\n";
  211.     }
  212.     buffer << " <Pen " << Fill << ">\n";
  213.     buffer << " <PenWidth " << currentLineWidth() << " pt>\n";
  214.     writeColorCatEntry(outf,currentR(),currentG(),currentB()) ;
  215.     buffer << " <ObColor `" << colorTable.getColorString(currentR(),currentG(),currentB()) << "'>";
  216.     buffer << endl;
  217.     print_coords();
  218.     buffer << "> # end of PolyLine\n";
  219.     }
  220. }
  221.  
  222. void drvMIF::show_rectangle(const float llx, const float lly, const float urx, const float ury)
  223. {
  224.     buffer << "<Rectangle\n";
  225.     if (currentShowType() == drvbase::stroke) {
  226.         buffer << " <Fill " << noFill << ">\n";
  227.     } else {
  228.         buffer << " <Fill " << Fill << ">\n";
  229.     }
  230.     buffer << " <Pen  " << Fill << ">\n";
  231.     buffer << " <PenWidth " << currentLineWidth() << " pt>\n";
  232.     writeColorCatEntry(outf,currentR(),currentG(),currentB()) ;
  233.     buffer << " <ObColor `" << colorTable.getColorString(currentR(),currentG(),currentB()) << "'>";
  234.     buffer << "\n" << endl;
  235.     buffer << " <BRect ";
  236.     buffer <<  llx + x_offset << " pt ";
  237.     buffer <<  currentDeviceHeight - ury + y_offset << " pt ";
  238.     buffer <<  urx - llx << " pt "; /* dx */
  239.     buffer <<  ury - lly << " pt "; /* dy */
  240.     buffer << "> \n> # end of Rectangle\n";
  241. }
  242.