00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #ifdef HAVE_UNISTD_H
00023 #include <unistd.h>
00024 #endif
00025
00026 #include <qtextcodec.h>
00027 #include <qfile.h>
00028 #include <qfileinfo.h>
00029 #include <qtextstream.h>
00030
00031 #include <KWEFBaseWorker.h>
00032 #include <KWEFKWordLeader.h>
00033 #include <KWEFUtil.h>
00034
00035 #include <wp5.h>
00036
00037 bool WPFiveWorker::doOpenFile(const QString& filenameOut, const QString& )
00038 {
00039 filename = filenameOut;
00040 outfile.setName( filename );
00041 if( !outfile.open( IO_WriteOnly ) )
00042 return false;
00043
00044 output.setDevice( &outfile );
00045 output.setByteOrder (QDataStream::LittleEndian);
00046 return true;
00047 }
00048
00049 bool WPFiveWorker::doCloseFile(void)
00050 {
00051
00052 Q_UINT32 total_filesize = outfile.at();
00053
00054
00055 outfile.close();
00056
00057
00058 if( !outfile.open( IO_ReadWrite ) )
00059 return false;
00060 output.setDevice( &outfile );
00061 output.setByteOrder (QDataStream::LittleEndian);
00062
00063
00064
00065
00066 outfile.at( 20 );
00067 output << total_filesize;
00068
00069
00070 outfile.at( 4 );
00071 output << document_area_ptr;
00072
00073 outfile.close();
00074 return true;
00075 }
00076
00077 bool WPFiveWorker::doOpenDocument(void)
00078 {
00079
00080
00081
00082
00083 Q_UINT8 magic[] = { 0xff, 0x57, 0x50, 0x43 };
00084 for( int i=0; i<4; i++ ) output << magic[i];
00085
00086
00087 Q_UINT8 docptr[] = { 0x0E, 0x02, 0x00, 0x00 } ;
00088 for( int i=0; i<4; i++ ) output << docptr[i];
00089
00090
00091 Q_UINT8 product_type = 1;
00092 output << product_type;
00093
00094
00095 Q_UINT8 file_type = 10;
00096 output << file_type;
00097
00098
00099 Q_UINT16 version = 0x0100;
00100 output << version;
00101
00102
00103 Q_UINT16 encrypt = 0;
00104 output << encrypt;
00105
00106
00107 Q_UINT16 index_header_ptr = 0x200;
00108 output << index_header_ptr;
00109
00110
00111 Q_UINT32 extheader = 5;
00112 output << extheader;
00113
00114
00115 Q_UINT32 filesize = 0;
00116 output << filesize;
00117
00118
00119 Q_UINT8 dummy = 0;
00120 for( int i=0; i<488; i++ ) output << dummy;
00121
00122
00123 Q_UINT8 index_header[] = { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00124 0, 0, 0, 0 };
00125 for( int i=0; i<14; i++ ) output << index_header[i];
00126
00127
00128 document_area_ptr = output.device()->at();
00129
00130 return true;
00131 }
00132
00133 bool WPFiveWorker::doCloseDocument(void)
00134 {
00135 return true;
00136 }
00137
00138
00139
00140 static QCString WPFiveEscape( const QString& text )
00141 {
00142 QCString result;
00143
00144 for( unsigned int i=0; i < text.length(); i++ )
00145 {
00146 int c = text[i].unicode();
00147 if( c < 32 ) result += '.';
00148 else if ( c == 32 ) result += 0x20 ;
00149 else if ( c < 128 ) result += text[i].latin1();
00150 else result += '.';
00151 }
00152
00153 return result;
00154 }
00155
00156
00157 bool WPFiveWorker::doFullParagraph(const QString& paraText,
00158 const LayoutData& , const ValueListFormatData& paraFormatDataList)
00159 {
00160 ValueListFormatData::ConstIterator it;
00161 for( it = paraFormatDataList.begin(); it!=paraFormatDataList.end(); ++it )
00162 {
00163 const FormatData& formatData = *it;
00164
00165
00166 if( formatData.id == 1 )
00167 {
00168
00169 Q_UINT8 attr = 0;
00170 if( formatData.text.weight >= 75 ) attr = 12;
00171 if( formatData.text.italic ) attr = 8;
00172 if( formatData.text.underline )
00173 {
00174 if( formatData.text.underlineValue == "double" )
00175 attr = 11;
00176 else
00177 attr = 14;
00178 }
00179 if( formatData.text.verticalAlignment == 1 ) attr = 6;
00180 if( formatData.text.verticalAlignment == 2 ) attr = 5;
00181 if( formatData.text.strikeout ) attr = 13;
00182
00183
00184
00185
00186
00187 if( attr > 0 ) output << (Q_UINT8)0xc3 << attr << (Q_UINT8)0xc3;
00188
00189
00190 QColor fgColor = formatData.text.fgColor;
00191 if( fgColor.isValid() )
00192 {
00193 Q_UINT8 wp_color[] = { 0xd1, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0xd1 };
00194 wp_color[7] = (Q_UINT8) fgColor.red();
00195 wp_color[8] = (Q_UINT8) fgColor.green();
00196 wp_color[9] = (Q_UINT8) fgColor.blue();
00197 output.writeRawBytes( (const char*)wp_color, 14 );
00198 }
00199
00200
00201 QCString out = WPFiveEscape( paraText.mid( formatData.pos, formatData.len ) );
00202 output.writeRawBytes( (const char*)out, out.length() );
00203
00204
00205 if( attr > 0 ) output << (Q_UINT8)0xc4 << attr << (Q_UINT8)0xc4;
00206 }
00207 }
00208
00209
00210 output << (Q_UINT8) 0x0a;
00211
00212 return true;
00213 }
00214