📄 internaldocument.cpp
字号:
if( m_overrideOrientation != CDSC_ORIENT_UNKNOWN ) return m_overrideOrientation; else if( m_dsc->page_orientation() != CDSC_ORIENT_UNKNOWN ) return static_cast< CDSC_ORIENTATION_ENUM >( m_dsc->page_orientation()); else if( m_dsc->bbox().get() != 0 && m_dsc->bbox()->width() > m_dsc->bbox()->height() ) return CDSC_LANDSCAPE; else return CDSC_PORTRAIT;}CDSC_ORIENTATION_ENUM GSInternalDocument::orientation( int pagenumber ) const{ if ( !m_dsc || unsigned( pagenumber ) >= m_dsc->page_count() ) { return orientation(); } if( m_overrideOrientation != CDSC_ORIENT_UNKNOWN ) { return m_overrideOrientation; } if( m_dsc->page()[ pagenumber ].orientation != CDSC_ORIENT_UNKNOWN ) { return static_cast< CDSC_ORIENTATION_ENUM >( m_dsc->page()[ pagenumber ].orientation ); } if( m_dsc->page_orientation() != CDSC_ORIENT_UNKNOWN ) { return static_cast< CDSC_ORIENTATION_ENUM >( m_dsc->page_orientation()); } if( !m_dsc->epsf() ) { return CDSC_PORTRAIT; } if( m_dsc->bbox().get() != 0 && m_dsc->bbox()->width() > m_dsc->bbox()->height() ) { return CDSC_LANDSCAPE; } return CDSC_PORTRAIT;}KDSCBBOX GSInternalDocument::boundingBox() const{ QString currentMedia = pageMedia(); if( currentMedia == "BoundingBox" ) return KDSCBBOX( * (m_dsc->bbox().get()) ); else { QSize size = computePageSize( currentMedia ); return KDSCBBOX( 0, 0, size.width(), size.height() ); }}KDSCBBOX GSInternalDocument::boundingBox( int pageNo ) const{ QString currentMedia = pageMedia( pageNo ); if( currentMedia == "BoundingBox" ) return KDSCBBOX( *(m_dsc->bbox().get()) ); else { QSize size = computePageSize( currentMedia ); return KDSCBBOX( 0, 0, size.width(), size.height() ); }}bool GSInternalDocument::savePages( const QString& saveFileName, const PageList& pageList ){ if( pageList.empty() ) return true; /* if( _format == PDF ) { KTempFile psSaveFile( QString::null, ".ps" ); psSaveFile.setAutoDelete( true ); if( psSaveFile.status() != 0 ) return false; // Find the minimum and maximum pagenumber in pageList. int minPage = pageList.first(), maxPage = pageList.first(); for( PageList::const_iterator ci = pageList.begin(); ci != pageList.end(); ++ci ) { minPage = qMin( *ci, minPage ); maxPage = qMax( *ci, maxPage ); } // TODO: Optimize "print whole document" case // // The convertion below from PDF to PS creates a temporary file which, in // the case where we are printing the whole document will then be // completelly copied to another temporary file. // // In very large files, the inefficiency is visible (measured in // seconds). // // luis_pedro 4 Jun 2003 // Convert the pages in the range [minPage,maxPage] from PDF to // PostScript. if( !convertFromPDF( psSaveFile.name(), minPage, maxPage ) ) return false; // The page minPage in the original file becomes page 1 in the // converted file. We still have to select the desired pages from // this file, so we need to take into account that difference. PageList normedPageList; transform( pageList.begin(), pageList.end(), back_inserter( normedPageList ), bind2nd( minus<int>(), minPage - 1 ) ); // Finally select the desired pages from the converted file. psCopyDoc( psSaveFile.name(), saveFileName, normedPageList ); } else {*/ psCopyDoc( m_fileName, saveFileName, pageList ); //} return true;}// length calculates string length at compile time// can only be used with character constants#define length( a ) ( sizeof( a ) - 1 )// Copy the headers, marked pages, and trailer to fpbool GSInternalDocument::psCopyDoc( const QString& inputFile, const QString& outputFile, const PageList& pageList ){ FILE* from; FILE* to; char text[ PSLINELENGTH ]; char* comment; bool pages_written = false; bool pages_atend = false; unsigned int i = 0; unsigned int pages = 0; long here; kDebug(4656) << "Copying pages from " << inputFile << " to " << outputFile << endl; from = fopen( QFile::encodeName( inputFile ), "r" ); to = fopen( QFile::encodeName( outputFile ), "w" ); pages = pageList.size(); if( pages == 0 ) {// FIXME ERROR HANDLING/* KMessageBox::sorry( 0, i18n( "Printing failed because the list of " "pages to be printed was empty." ), i18n( "Error Printing" ) );*/ return false; } // Hack in order to make printing of PDF files work. FIXME CDSC* dsc; if( m_format == PS ) dsc = m_dsc->cdsc();/* else { FILE* fp = fopen( QFile::encodeName( inputFile ), "r"); char buf[256]; int count; dsc = dsc_init( 0 ); while( ( count = fread( buf, 1, sizeof( buf ), fp ) ) != 0 ) dsc_scan_data( dsc, buf, count ); dsc_fixup( dsc ); fclose( fp ); if( !dsc ) return false; }*/ here = dsc->begincomments; while( ( comment = pscopyuntil( from, to, here, dsc->endcomments, "%%Pages:" ) ) ) { here = ftell( from ); if( pages_written || pages_atend ) { free( comment ); continue; } sscanf( comment + length("%%Pages:" ), "%256s", text ); text[256] = 0; // Just in case of an overflow if( strcmp( text, "(atend)" ) == 0 ) { fputs( comment, to ); pages_atend = true; } else { switch ( sscanf( comment + length( "%%Pages:" ), "%*d %u", &i ) ) { case 1: fprintf( to, "%%%%Pages: %d %d\n", pages, i ); break; default: fprintf( to, "%%%%Pages: %d\n", pages ); break; } pages_written = true; } free(comment); } pscopy( from, to, dsc->beginpreview, dsc->endpreview ); pscopy( from, to, dsc->begindefaults, dsc->enddefaults ); pscopy( from, to, dsc->beginprolog, dsc->endprolog ); pscopy( from, to, dsc->beginsetup, dsc->endsetup ); //TODO -- Check that a all dsc attributes are copied unsigned int count = 1; PageList::const_iterator it; for( it = pageList.begin(); it != pageList.end(); ++it ) { i = (*it) - 1; comment = pscopyuntil( from, to, dsc->page[i].begin, dsc->page[i].end, "%%Page:" ); if ( comment ) free( comment ); fprintf( to, "%%%%Page: %s %d\n", dsc->page[i].label, count++ ); pscopy( from, to, -1, dsc->page[i].end ); } here = dsc->begintrailer; while( ( comment = pscopyuntil( from, to, here, dsc->endtrailer, "%%Pages:" ) ) ) { here = ftell( from ); if ( pages_written ) { free( comment ); continue; } switch ( sscanf( comment + length( "%%Pages:" ), "%*d %u", &i ) ) { case 1: fprintf( to, "%%%%Pages: %d %d\n", pages, i ); break; default: fprintf( to, "%%%%Pages: %d\n", pages ); break; } pages_written = true; free( comment ); } fclose( from ); fclose( to );/* if( format == PDF ) dsc_free( dsc );*/ return true;}#undef length
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -