Source Code (Use browser search to find items of interest.)
Class Index
kdvi'DVIFile (./kdegraphics/kdvi/print.cpp:25)
class DVIFile
{
Q_OBJECT
public:
DVIFile(){}
~DVIFile(){};
void dviCopy(QString ifile, QString ofile, QStrList *pagelist,
int first = 0, int last = 999999 );
};
kdvi'DVIFile::dviCopy() (./kdegraphics/kdvi/print.cpp:110)
void DVIFile::dviCopy(QString ifile, QString ofile, QStrList *pagelist,
int first, int last)
{
QFile in(ifile);
QFile out(ofile);
char buf[1024];
/* these would be needed for better handling the used fonts
int texfont[256], fontdeflen[256], fontseen[256];
for (int i=0; i<256; i++ )
texfont[i] = fontdeflen[i] = fontseen[i] = 0;
*/
if (!in.open(IO_ReadOnly))
KMessageBox::sorry( 0L,
i18n("Cannot open dvi file!"));
if (!out.open(IO_WriteOnly))
KMessageBox::sorry( 0L,
i18n("Cannot open output dvi file!"));
in.readBlock( buf, 14 );
out.writeBlock( buf, 14 );
out.writeBlock( "\013kdvi output", 12 );
int c, p = in.size()-3, n, tot, totout = 0, o = -1;
in.at(p);
while ( ( c = in.getch() ) == 223 ) // trailer
in.at( --p );
if ( c != 2 )
KMessageBox::sorry( 0L,
i18n("Cannot handle this dvi version!"));
int post_post = p - 5;
in.at( post_post + 1 );
int post = get4( in );
in.at( post + 27 );
tot = n = get2( in );
int fntdefslen = post_post - in.at();
int *pg = new int[tot + 1];
pg[ tot ] = post;
p = post - 40;
while (n--)
{
in.at( p + 41 ),
pg[n] = p = get4( in );
}
/*
for ( p = post + 29; p < post_post; p++ )
{
in.at( p );
c = in.getch();
if ( c == 138 ) ) // nop
continue;
if ( c == 243 ) // fnt_def1
{
texfont[ n = in.getch() ] = p;
in.at( p + 14 );
fontdeflen[ n ] = in.getch() + in.getch();
p += 16 + fontdeflen[ n ];
}
else debug("DVI file format error!");
}
*/
int defsdone = 0;
for ( n=0; n < tot; n++ ) // copy pages to out
{
if ( pagelist &&
pagelist->find( QString().sprintf( "%4d", n + 1 ) ) < 0 )
continue;
if ( n + 1 < first || n + 1 > last )
continue;
in.at( pg[n] );
in.readBlock( buf, 41 );
out.writeBlock( buf, 41 );
put4( out, o );
o = out.at() - 45;
if ( !defsdone ) // cannot copy fnt defs before page 1 due to bug in dvips
{
in.at( post + 29 );
// copy font defs from postamble (bug: all not needed)
for ( int i = fntdefslen; i>0; i-- )
out.putch( in.getch() );
defsdone = 1;
}
in.at( pg[n] + 45 );
for ( int i = pg[n+1] - pg[n] - 45; i > 0; i-- )
out.putch( in.getch() );
totout++;
}
out.putch( 248 ); // post
put4( out, o );
o = out.at() - 5;
in.at( post + 5 );
in.readBlock( buf, 22 );
out.writeBlock( buf, 22 );
put2( out, totout );
in.at( post + 29 );
for ( int i = post_post - ( post + 29 ); i > 0; i-- )
out.putch( in.getch() );
out.putch( 249 ); // post_post
put4( out, o );
out.putch( 2 ); // dvi file version id
put4( out, 0xdfdfdfdf );// trailers
while ( out.at() & 3 )
out.putch( 0xdf );
in.close();
out.close();
delete pg;
}