Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

monrtfwr.cpp

Go to the documentation of this file.
00001 //**********************************************************************
00002 //                                                                     *
00003 //    Filename:      monrtfwr.cpp                                      *
00004 //    Date:          16 Feb 2002                                       *
00005 //    File Version:  1                                                 *
00006 //                                                                     *
00007 //    Author:        Chris White (whitecf@bcs.org.uk)                  *
00008 //    Company:       Monitor Computing Services Ltd.                   *
00009 //                                                                     *
00010 //**********************************************************************
00011 //                                                                     *
00012 //    Copyright (C) 2002  Monitor Computing Services Ltd.              *
00013 //                                                                     *
00014 //    This program is free software; you can redistribute it and/or    *
00015 //    modify it under the terms of the GNU General Public License      *
00016 //    as published by the Free Software Foundation; either version 2   *
00017 //    of the License, or any later version.                            *
00018 //                                                                     *
00019 //    This program is distributed in the hope that it will be useful,  *
00020 //    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00021 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00022 //    GNU General Public License for more details.                     *
00023 //                                                                     *
00024 //    You should have received a copy of the GNU General Public        *
00025 //    License (http://www.gnu.org/copyleft/gpl.html) along with this   *
00026 //    program; if not, write to:                                       *
00027 //       The Free Software Foundation Inc.,                            *
00028 //       59 Temple Place - Suite 330,                                  *
00029 //       Boston, MA  02111-1307,                                       *
00030 //       USA.                                                          *
00031 //                                                                     *
00032 //**********************************************************************
00033 //                                                                     *
00034 //    Notes:                                                           *
00035 //                                                                     *
00036 //**********************************************************************
00037 
00038 #include <cstring.h>
00039 #include <fstream.h>
00040 
00041 #include "monrtfwr.h"
00042 
00043 
00044 const float  MonRtfWriter::twipsPerInch = 1440.0;
00045 
00046 
00047 MonRtfWriter::MonRtfWriter(const char  *inFileName)
00048 {
00049   static const string  extSep(".");
00050   static const char    *outExt = ".rtf";
00051   string               outFileName(inFileName);
00052   int                  extSepAt = outFileName.find_last_of(extSep);
00053 
00054   if (0 != extSepAt)
00055   {
00056      outFileName.resize(extSepAt);
00057   }
00058   outFileName += outExt;
00059 
00060   output = new ofstream(outFileName.c_str());
00061 }
00062 
00063 
00064 MonRtfWriter::~MonRtfWriter()
00065 {
00066   delete  output;
00067   output = 0;
00068 }
00069 
00070 
00071 void
00072 MonRtfWriter::Begin()
00073 {
00074   *output << "{\\rtf1\\ansi" << endl <<
00075                  "{\\fonttbl{\\f0\\froman Times New Roman}}" << endl <<
00076                  "\\fs24 ";
00077 }
00078 
00079 
00080 void
00081 MonRtfWriter::leftMargin(float  inches)
00082 {
00083   *output << "\\margl" << (int)(twipsPerInch * inches) << " ";
00084 }
00085 
00086 
00087 void
00088 MonRtfWriter::rightMargin(float  inches)
00089 {
00090   *output << "\\margr" << (int)(twipsPerInch * inches) << " ";
00091 }
00092 
00093 
00094 void
00095 MonRtfWriter::topMargin(float  inches)
00096 {
00097   *output << "\\margt" << (int)(twipsPerInch * inches) << " ";
00098 }
00099 
00100 
00101 void
00102 MonRtfWriter::bottomMargin(float  inches)
00103 {
00104   *output << "\\margb" << (int)(twipsPerInch * inches) << " ";
00105 }
00106 
00107 
00108 void
00109 MonRtfWriter::leftIndent(float  inches)
00110 {
00111   *output << "\\li" << (int)(twipsPerInch * inches) << " ";
00112 }
00113 
00114 
00115 void
00116 MonRtfWriter::firstLineIndent(float  inches)
00117 {
00118   *output << "\\fi" << (int)(twipsPerInch * inches) << " ";
00119 }
00120 
00121 
00122 void
00123 MonRtfWriter::write(char  charToWrite)
00124 {
00125   switch (charToWrite)
00126   {
00127   case '\\':
00128      *output << "\\\\";
00129      break;
00130   case '{':
00131      *output << "\\{";
00132      break;
00133   case '}':
00134      *output << "\\}";
00135      break;
00136   default:
00137      *output << charToWrite;
00138      break;
00139   }
00140 }
00141 
00142 
00143 void
00144 MonRtfWriter::writeHardSpace()
00145 {
00146   *output << "\\~ ";
00147 }
00148 
00149 
00150 void
00151 MonRtfWriter::justify()
00152 {
00153   *output << "\\qj ";
00154 }
00155 
00156 
00157 void
00158 MonRtfWriter::leftJustify()
00159 {
00160   *output << "\\ql ";
00161 }
00162 
00163 
00164 void
00165 MonRtfWriter::endParagraph()
00166 {
00167   *output << "\\par" << endl;
00168 }
00169 
00170 
00171 void
00172 MonRtfWriter::endPage()
00173 {
00174   *output << "\\page " << endl;
00175 }
00176 
00177 
00178 void
00179 MonRtfWriter::End()
00180 {
00181   endParagraph();
00182   *output << endl << "}" << endl;
00183 
00184   output->close();
00185 }
00186 

Generated on Sun Jul 20 02:35:50 2003 for WordWise to RTF, Win32 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002