Source Code (Use browser search to find items of interest.)
Class Index
kghostview'KGVMiniWidget (./kdegraphics/kghostview/kgv_miniwidget.h:44)
class KGVMiniWidget : public QWidget
{
Q_OBJECT
public:
KGVMiniWidget( QWidget *parent=0, const char *name=0 );
~KGVMiniWidget();
enum action { GET, PUT };
void openNetFile( const KURL &u );
KIO::Job* currentJob(){return(iojob);}
bool setup();
void show_page(int number);
void build_pagemedia_menu();
void set_magstep(unsigned int new_magstep);
void magnify(float *dpi, unsigned int magstep);
void new_file(int number);
void openFile( QString name );
bool same_document_media();
bool set_new_orientation(int number);
bool set_new_pagemedia( int number );
bool set_new_magstep();
void readSettings();
void setName();
QFrame *divider;
MarkList *marklist;
KPSWidget *page;
PrintDialog *pd;
InfoDialog *infoDialog;
bool force_pagemedia;
bool force_orientation;
int orientation;
void printStart( int mode, bool reverseOrder, bool toFile,
QString printerName, QString spoolerCommmand,
QString printerVariable,
int pgStart, int pgEnd );
QString printToFile( bool allMode, QStrList *ml );
QString printToPrinter( QString printerName,
QString spoolerCommand, QString printerVariable,
bool allMode, QStrList *ml );
void psCopyDoc( FILE *fp, QStrList *ml );
FILE *psfile;
QString filename;
QString oldfilename;
int current_page;
int pages_in_part[10];
int num_parts;
time_t mtime;
struct document *doc;
struct document *olddoc;
public slots:
//void pageActivated( const char * text); // Dutta 16/3/98
void pageActivated( int pg ); // Dutta 16/3/98
void scrollDown();
void scrollUp();
void scrollLeft();
void scrollRight();
void nextPage();
void prevPage();
void goToPage();
void goToStart();
void goToEnd();
void readDown();
void print();
void zoomIn();
void zoomOut();
void zoom( float zoom_factor );
void markPage();
void shrinkWrap();
void redisplay();
void info();
void copyright();
void configureGhostscript();
void slotIOJobFinished( int );
void slotIOError(int, int, const char *);
void slotStopIO();
signals:
void ioStart();
void ioStop();
void ioError();
protected:
void paletteChange( const QPalette & );
void resizeEvent(QResizeEvent *ev);
private:
int topOffset, bottomOffset;
QString printerName;
int printSelection;
bool isNetFile;
bool isPageListShown;
bool fitWindow;
unsigned int shrink_magsteps, expand_magsteps, magstep,
current_magstep;
bool force_document_media;
int base_papersize;
bool toc_text;
int toc_length;
int toc_entry_length;
char page_total_label[20];
char part_total_label[20];
QString part_string;
QString page_string;
QString page_label_text;
QString part_label_text;
QString position_label;
float default_xdpi, default_ydpi;
int current_llx;
int current_lly;
int current_urx;
int current_ury;
int current_pagemedia, default_pagemedia, document_media;
int current_orientation;
bool changed;
/**
Only one KIOJob should be opened at once. Otherwise kgv could get
confused. If this is 0L, you may create a new iojob.
*/
KIO::Job * iojob;
/// Temporary file for internet purposes
/**
If kgv is waiting for some internet task to finish, this is the
file that is involved. Mention that it is a complete URL like
"file:/tmp/mist.txt".
*/
QString tmpFile;
/// If we load a file from the net this is the corresponding URL
QString netFile;
/// Tells us what kfm is right now doing for us
/**
If this is for example GET, then KFM loads a file from the net
to the local file system.
*/
action kfmAction;
/// The open mode for a net file
/**
If kgv is waiting for an internet file, this is the mode in which
it should open the file.
*/
int openMode;
};
kghostview'KGVMiniWidget::KGVMiniWidget() (./kdegraphics/kghostview/kgv_miniwidget.cpp:61)
KGVMiniWidget::KGVMiniWidget( QWidget *parent, const char *name )
: QWidget(parent, name)
{
// Initialise all the variables declared in this class.
// I ususally forget to do a few resulting in nasty seg. faults !
iojob = 0L;
isNetFile = false;
oldfilename = "";
filename = "";
psfile=0;
doc=0;
olddoc=0;
current_page=0;
num_parts=0;
for(int part_count=0;part_count<10;part_count++) {
pages_in_part[part_count]=0;
}
shrink_magsteps = 10;
current_magstep = magstep = 10;
expand_magsteps = 10;
default_xdpi = 75.0;
default_ydpi = 75.0;
default_pagemedia = 1;
base_papersize=0;
orientation = 1;
force_orientation = false;
force_pagemedia = false;
current_llx = 0;
current_lly = 0;
current_urx = 0;
current_ury = 0;
marklist = new MarkList( this );
CHECK_PTR( marklist );
marklist->setFocusProxy(this);
divider = new QFrame( this );
CHECK_PTR( divider );
divider->setFocusProxy(this);
divider->setFrameStyle( QFrame::Panel | QFrame::Raised );
divider->setLineWidth( 1 );
marklist->setSelectColors( colorGroup().highlight(),
colorGroup().highlightedText() );
connect( marklist, SIGNAL(selected( int )),
SLOT(pageActivated( int )) ); // Duda 16/3/98
//QToolTip::add( marklist, "Select page and mark pages for printing" );
//printf("Done toolbar - Create KPSWidget\n");
page = new KPSWidget( this );
CHECK_PTR( page );
page->setFocusProxy(this);
printSelection = 1;
printerName = "lp0";
readSettings();
//
// READ SETTINGS AND SET OPTIONS MENU, SET LAST OPENED FILES
//
setName();
show();
if (psfile)
{
setup();
//show_page( 0 );
//marklist->select( 0 );
}
}
//void KGVMiniWidget::pageActivated( const char * text) // Duda 16/3/98
//{
// int pg = QString( text ).toInt();
// show_page(pg-1);
//}
kghostview'KGVMiniWidget::pageActivated() (./kdegraphics/kghostview/kgv_miniwidget.cpp:147)
void KGVMiniWidget::pageActivated( int pg ) // Duda 16/3/98
{
// printf("KGVMiniWidget::pageActivated\n");
show_page(pg);
}
kghostview'KGVMiniWidget::resizeEvent() (./kdegraphics/kghostview/kgv_miniwidget.cpp:154)
void KGVMiniWidget::resizeEvent(QResizeEvent *)
{
marklist->setGeometry( 0, 0, PAGELIST_WIDTH-1, height());
divider->setGeometry( PAGELIST_WIDTH, 0, PAGELIST_WIDTH+3, height());
//if( marklist->isVisible() ) { // The window might not be shown yet...
if (isPageListShown) {
page->setGeometry( PAGELIST_WIDTH+3, 0, width()-PAGELIST_WIDTH-3,
height() );
} else {
page->setGeometry( 0, 0, width(), height() );
}
}
kghostview'KGVMiniWidget::~KGVMiniWidget() (./kdegraphics/kghostview/kgv_miniwidget.cpp:170)
KGVMiniWidget::~KGVMiniWidget()
{
;
}
kghostview'KGVMiniWidget::copyright() (./kdegraphics/kghostview/kgv_miniwidget.cpp:176)
void KGVMiniWidget::copyright()
{
CopyrightDialog *cd = new CopyrightDialog( 0, "copyright" );
cd->exec();
}
kghostview'KGVMiniWidget::info() (./kdegraphics/kghostview/kgv_miniwidget.cpp:182)
void KGVMiniWidget::info()
{
QString ftitle, fdate;
if(doc) {
ftitle = doc->title;
fdate = doc->date;
} else {
ftitle = i18n("Not known");
fdate = ftitle;
}
infoDialog = new InfoDialog(filename,
ftitle.data(),
fdate.data(),
this,
0);
infoDialog->exec();
delete infoDialog;
}
kghostview'KGVMiniWidget::configureGhostscript() (./kdegraphics/kghostview/kgv_miniwidget.cpp:203)
void KGVMiniWidget::configureGhostscript()
{
page->intConfig->setCaption(i18n("Configure interpreter"));
page->intConfig->init();
if( page->intConfig->exec() ) {
}
}
kghostview'KGVMiniWidget::openNetFile() (./kdegraphics/kghostview/kgv_miniwidget.cpp:212)
void KGVMiniWidget::openNetFile( const KURL &u )
{
warning("In openNetFile");
if ( u.isMalformed() ) {
KMessageBox::sorry (0, i18n("Malformed URL."));
emit ioStop();
return;
}
// Just a usual file ?
if ( u.isLocalFile() ) {
warning("Opening Local file");
emit ioStart();
openFile( u.path() );
iojob = NULL;
emit ioStop();
return;
}
if ( iojob != 0L ) {
KMessageBox::sorry(0, i18n("Already waiting\n"\
"for an internet job to finish.\n"\
"Please wait until has finished.\n"\
"Alternatively stop the running one."));
emit ioStop();
return;
}
tmpFile.sprintf( "file:"_PATH_TMP"/kghostview%i", (int)time( 0L ) );
connect( iojob, SIGNAL( sigFinished( int ) ), this, SLOT( slotIOJobFinished( int ) ) );
QObject::connect( iojob, SIGNAL( sigError( int, int, const char * ) ),
this, SLOT( slotIOError( int, int, const char * ) ) );
iojob = KIO::copy( netFile, tmpFile );
// iojob->copy( );
kfmAction = KGVMiniWidget::GET;
openMode = 0;
emit ioStart();
}
kghostview'KGVMiniWidget::slotIOJobFinished() (./kdegraphics/kghostview/kgv_miniwidget.cpp:253)
void KGVMiniWidget::slotIOJobFinished( int )
{
if ( kfmAction == KGVMiniWidget::GET ) {
KURL u( tmpFile.data() );
isNetFile = true;
openFile( u.path() );
// Clean up
unlink( tmpFile.data() );
iojob = 0L;
}
emit ioStop();
}
kghostview'KGVMiniWidget::slotIOError() (./kdegraphics/kghostview/kgv_miniwidget.cpp:267)
void KGVMiniWidget::slotIOError(int, int, const char *)
{
slotStopIO();
emit ioError();
}
kghostview'KGVMiniWidget::slotStopIO() (./kdegraphics/kghostview/kgv_miniwidget.cpp:273)
void KGVMiniWidget::slotStopIO()
{
if(iojob)
iojob->kill();
iojob = NULL;
}
kghostview'KGVMiniWidget::readSettings() (./kdegraphics/kghostview/kgv_miniwidget.cpp:280)
void KGVMiniWidget::readSettings()
{
//printf("KGVMiniWidget::readSettings\n");
QString str;
KConfig *config = KApplication::kApplication()->config();
config->setGroup( "General" );
page->intConfig->antialias = config->readBoolEntry("Antialiasing",
true);
str = config->readEntry( "Palette" );
if ( !str.isNull() && str.find( "mono" ) == 0 )
page->intConfig->paletteOpt = MONO_PALETTE;
else if ( !str.isNull() && str.find( "gray" ) == 0 )
page->intConfig->paletteOpt = GRAY_PALETTE;
else
page->intConfig->paletteOpt = COLOR_PALETTE;
str = config->readEntry( "Backing" );
if ( !str.isNull() && str.find( "store" ) == 0 )
page->intConfig->backingOpt = STORE_BACKING;
else
page->intConfig->backingOpt = PIX_BACKING;
str = config->readEntry( "Messages" );
if ( !str.isNull() && str.find( "on" ) == 0 )
page->intConfig->show_messages = true;
else
page->intConfig->show_messages = false;
str = config->readEntry( "Page list" );
if ( !str.isNull() && str.find( "off" ) == 0 ) {
marklist->hide();
isPageListShown = false;
} else {
marklist->show();
isPageListShown = true;
}
str = config->readEntry( "Magstep" );
if ( !str.isNull() ) {
int i = atoi( str );
if( i<20 && i>0 ) {
//printf("Set new magstep in read Settings\n");
magstep = i;
set_new_magstep( );
}
}
str = config->readEntry( "Orientation" );
if ( !str.isNull() ) {
int i = atoi( str );
if( i<4 && i>0 ) {
set_new_orientation(i);
}
}
unsigned int m = config->readUnsignedNumEntry ( "Zoom");
if (m!=0)
magstep = current_magstep = m;
}
kghostview'KGVMiniWidget::shrinkWrap() (./kdegraphics/kghostview/kgv_miniwidget.cpp:347)
void KGVMiniWidget::shrinkWrap()
{
int new_width=0;
if ( !psfile ) return;
new_width=page->fullView->width()+(x()+width()-geometry().right())
+(geometry().left()-x())+2;
if( page->vertScrollBar->isVisible() )
new_width+=page->vertScrollBar->width();
if( marklist->isVisible() )
new_width+=PAGELIST_WIDTH+3;
QWidget *d = QApplication::desktop();
int w=d->width()-10;
if( new_width > w ){
new_width = w;
resize( new_width, height() );
}
}
kghostview'KGVMiniWidget::paletteChange() (./kdegraphics/kghostview/kgv_miniwidget.cpp:370)
void KGVMiniWidget::paletteChange( const QPalette & )
{
marklist->setSelectColors( colorGroup().highlight(),
colorGroup().highlightedText() );
if( psfile )
redisplay();
}
kghostview'KGVMiniWidget::setName() (./kdegraphics/kghostview/kgv_miniwidget.cpp:379)
void KGVMiniWidget::setName()
{
QString s( kapp->caption() );
if( psfile ) {
s.prepend(" - ");
if ( isNetFile ) {
int cutoff = netFile.findRev( "/", netFile.length() );
if ( cutoff != -1 )
s.prepend(netFile.right( netFile.length() - 1 - cutoff ));
else
s.prepend(netFile);
} else
s.prepend(QFileInfo( filename ).fileName());
}
QWidget::setCaption( s );
}
kghostview'KGVMiniWidget::redisplay() (./kdegraphics/kghostview/kgv_miniwidget.cpp:398)
void KGVMiniWidget::redisplay()
{
page->disableInterpreter();
show_page( current_page );
}
//
// SLOTS UP NEXT
//
kghostview'KGVMiniWidget::markPage() (./kdegraphics/kghostview/kgv_miniwidget.cpp:410)
void KGVMiniWidget::markPage()
{
marklist->markSelected();
}
kghostview'KGVMiniWidget::readDown() (./kdegraphics/kghostview/kgv_miniwidget.cpp:415)
void KGVMiniWidget::readDown()
{
if( !page->readDown() )
nextPage();
}
kghostview'KGVMiniWidget::scrollUp() (./kdegraphics/kghostview/kgv_miniwidget.cpp:421)
void KGVMiniWidget::scrollUp()
{
page->scrollUp();
}
kghostview'KGVMiniWidget::scrollDown() (./kdegraphics/kghostview/kgv_miniwidget.cpp:426)
void KGVMiniWidget::scrollDown()
{
page->scrollDown();
}
kghostview'KGVMiniWidget::scrollLeft() (./kdegraphics/kghostview/kgv_miniwidget.cpp:431)
void KGVMiniWidget::scrollLeft()
{
page->scrollLeft();
}
kghostview'KGVMiniWidget::scrollRight() (./kdegraphics/kghostview/kgv_miniwidget.cpp:436)
void KGVMiniWidget::scrollRight()
{
page->scrollRight();
}
kghostview'KGVMiniWidget::goToPage() (./kdegraphics/kghostview/kgv_miniwidget.cpp:442)
void KGVMiniWidget::goToPage()
{
//printf("KGVMiniWidget::goToPage\n");
GoTo gt(this, "Go to");
gt.setCaption(i18n("Go to ..."));
gt.current_page=current_page;
gt.num_parts=num_parts;
for( int j=0; j < 10; j++ ) {
gt.pages_in_part[j]=pages_in_part[j];
}
gt.init();
if( gt.exec() ) {
current_page=gt.current_page;
marklist->select(current_page);
//show_page(current_page);
}
}
kghostview'KGVMiniWidget::print() (./kdegraphics/kghostview/kgv_miniwidget.cpp:463)
void KGVMiniWidget::print()
{
//printf("KGVMiniWidget::print\n");
pd = new PrintDialog( this, "print dialog", doc->numpages,
( marklist->markList()->count() > 0 ) );
pd->setCaption(i18n("Print"));
if( pd->exec() ) {
printStart( pd->pgMode, pd->cbOrder->isChecked(),
pd->cbFile->isChecked(),
pd->printerName, pd->spoolerCommand,
pd->printerVariable,
QString( pd->leStart->text() ).toInt(),
QString( pd->leEnd->text() ).toInt() );
}
}
void
kghostview'KGVMiniWidget::zoomIn() (./kdegraphics/kghostview/kgv_miniwidget.cpp:487)
KGVMiniWidget::zoomIn()
{
set_magstep(magstep+1);
}
kghostview'KGVMiniWidget::zoomOut() (./kdegraphics/kghostview/kgv_miniwidget.cpp:492)
void KGVMiniWidget::zoomOut()
{
int i;
i = magstep - 1;
if (i >= 1)
{
set_magstep((unsigned int) i);
}
}
void
kghostview'KGVMiniWidget::zoom() (./kdegraphics/kghostview/kgv_miniwidget.cpp:505)
KGVMiniWidget::zoom ( float zoom_factor )
{
//What about current_magstep -- Is this used in printing at all?
//We should switch to using a float current_mag
page->disableInterpreter();
page->xdpi=zoom_factor*default_xdpi;
page->ydpi=zoom_factor*default_ydpi;
page->layout();
page->resize(page->width(), page->height());
page->repaint();
show_page(current_page);
shrinkWrap();
}
kghostview'KGVMiniWidget::nextPage() (./kdegraphics/kghostview/kgv_miniwidget.cpp:523)
void KGVMiniWidget::nextPage()
{
//printf("KGVMiniWidget::nextPage\n");
int new_page = 0;
if (toc_text) {
new_page = current_page + 1;
if ((unsigned int) new_page >= doc->numpages)
return;
}
marklist->select(new_page);
//show_page(new_page);
page->scrollTop();
}
kghostview'KGVMiniWidget::goToStart() (./kdegraphics/kghostview/kgv_miniwidget.cpp:539)
void KGVMiniWidget::goToStart()
{
//printf("KGVMiniWidget::goToStart\n");
int new_page = 0;
marklist->select(new_page);
//show_page(new_page);
page->scrollTop();
}
kghostview'KGVMiniWidget::goToEnd() (./kdegraphics/kghostview/kgv_miniwidget.cpp:550)
void KGVMiniWidget::goToEnd()
{
//printf("KGVMiniWidget::goToEnd\n");
int new_page = 0;
if (toc_text) {
new_page = doc->numpages-1;
}
marklist->select(new_page);
//show_page(new_page);
page->scrollTop();
}
kghostview'KGVMiniWidget::prevPage() (./kdegraphics/kghostview/kgv_miniwidget.cpp:566)
void KGVMiniWidget::prevPage()
{
//printf("KGVMiniWidget::prevPage\n");
int new_page = 0;
if (toc_text) {
new_page = current_page - 1;
if (new_page < 0)
return;
}
marklist->select(new_page);
//show_page(new_page);
page->scrollTop();
}
kghostview'KGVMiniWidget::printStart() (./kdegraphics/kghostview/kgv_miniwidget.cpp:583)
void KGVMiniWidget::printStart( int mode, bool reverseOrder,
bool toFile,
QString printerName, QString spoolerCommand,
QString printerVariable,
int pgStart, int pgEnd )
{
QStrList *ml = new QStrList;
switch( mode ) {
case PrintDialog::All:
break;
case PrintDialog::Current:
ml->append( marklist->text( current_page ) );
break;
case PrintDialog::Marked:
ml = marklist->markList();
break;
case PrintDialog::Range:
if ( pgStart <= pgEnd )
for( int j = pgStart-1; j< pgEnd; j++ )
ml->append( marklist->text( j ) );
else
for( int j = pgEnd-1; j< pgStart; j++ )
ml->append( marklist->text( j ) );
break;
}
if ( reverseOrder ) {
QStrList *sl = new QStrList;
for( ml->last(); ml->current(); ml->prev() )
sl->append( ml->current() );
*ml = *sl;
delete sl;
}
QString error;
if ( toFile ) {
error = printToFile( ( mode == PrintDialog::All ), ml );
} else {
error = printToPrinter( printerName, spoolerCommand, printerVariable,
( mode == PrintDialog::All ), ml );
}
if ( !error.isNull() ) KMessageBox::error( 0, error, i18n( "Error printing" ));
delete ml;
}
kghostview'KGVMiniWidget::printToFile() (./kdegraphics/kghostview/kgv_miniwidget.cpp:635)
QString KGVMiniWidget::printToFile( bool allMode, QStrList *ml )
{
FILE *pswrite;
if ( allMode ) {
QString buf( i18n( "You chose to print all pages to a file.\n"
"This would produce a document identical to\n"
"that currently loaded into the viewer.\n"
"There is no need to print all pages into a new file.") );
return buf;
}
QString dir;
if ( filename )
dir = QFileInfo( filename ).dirPath();
QString s = QFileDialog::getSaveFileName( dir, "*.*ps*", this);
if ( s.isNull() ) {
QString buf( i18n( "No file name was given so\n"\
"nothing could be printed to a file.\n") );
return buf;
}
if ( ( pswrite = fopen( s.data(), "w" ) ) == 0L ) {
QString buf;
buf = i18n("Attempt to open file for writing failed.\n\n"
"Error: %1\n")
.arg( strerror(errno) );
return buf;
} else {
psCopyDoc( pswrite, ml );
fclose( pswrite );
return QString::null;
}
}
kghostview'KGVMiniWidget::printToPrinter() (./kdegraphics/kghostview/kgv_miniwidget.cpp:671)
QString KGVMiniWidget::printToPrinter( QString printerName, QString spoolerCommand,
QString printerVariable, bool allMode, QStrList *ml )
{
// printf("KGVMiniWidget::print_file\n");
FILE *printer;
SIGVAL (*oldsig) (int);
int bytes = 0;
char buf[ BUFSIZ ];
bool failed;
QString ret_val;
page->disableInterpreter();
// For SYSV, SVR4, USG printer variable="LPDEST", print command=lp
// Other systems printer variable="PRINTER", print command=lpr
// Why add double quotes ? It breaks setenv... David Faure.
// printerVariable.append("\"");
// printerVariable.prepend("\"");
if ( !printerName.isEmpty() ) {
if ( !printerVariable.isEmpty() ) {
setenv( printerVariable.data(), printerName.data(), true );
} else return( QString( i18n( "Set Environment variable (to PRINTER or LPDEST for instance)"
"for Printer name to be taken into account." ) ) );
}
oldsig = signal( SIGPIPE, SIG_IGN );
printer = popen( spoolerCommand.data(), "w" );
if ( toc_text && !allMode ) {
psCopyDoc( printer, ml );
} else {
FILE *tmpfile = ::fopen( filename, "r" );
while ( ( bytes = ::read( fileno(tmpfile), buf, BUFSIZ ) ) ) {
bytes = ::write( fileno(printer), buf, bytes);
}
::fclose( tmpfile );
}
failed = ( pclose( printer ) != 0 );
ret_val = failed?i18n("Print failure: %1").arg(spoolerCommand):QString::null;
signal( SIGPIPE, oldsig );
return( ret_val );
}
// length calculates string length at compile time
// can only be used with character constants
kghostview'KGVMiniWidget::psCopyDoc() (./kdegraphics/kghostview/kgv_miniwidget.cpp:727)
void KGVMiniWidget::psCopyDoc( FILE *fp, QStrList *ml )
{
// printf("KGVMiniWidget::pscopydoc\n");
FILE *psfile;
char text[ PSLINELENGTH ];
char *comment;
bool pages_written = false;
bool pages_atend = false;
int pages = 0;
int page = 1;
unsigned int i;
long here;
psfile = fopen( filename, "r" );
pages = ml->count();
if ( pages == 0 ) {
KMessageBox::error( 0,
i18n( "Printing failed because the list of\n"
"pages to be printed was empty.\n" ),
i18n( "Error printing" ));
return;
}
here = doc->beginheader;
while ( ( comment = pscopyuntil( psfile, fp, here,
doc->endheader, "%%Pages:" ) ) ) {
here = ftell( psfile );
if ( pages_written || pages_atend ) {
free( comment );
continue;
}
sscanf( comment + length("%%Pages:" ), "%s", text );
if ( strcmp( text, "(atend)" ) == 0 ) {
fputs( comment, fp );
pages_atend = true;
} else {
switch ( sscanf( comment + length( "%%Pages:" ), "%*d %d", &i ) ) {
case 1:
fprintf( fp, "%%%%Pages: %d %d\n", pages, i );
break;
default:
fprintf( fp, "%%%%Pages: %d\n", pages );
break;
}
pages_written = true;
}
free(comment);
}
pscopy( psfile, fp, doc->beginpreview, doc->endpreview );
pscopy( psfile, fp, doc->begindefaults, doc->enddefaults );
pscopy( psfile, fp, doc->beginprolog, doc->endprolog );
pscopy( psfile, fp, doc->beginsetup, doc->endsetup );
QStrListIterator it( *ml );
for(; it.current(); ++it ) {
i = QString( it.current() ).toInt() - 1;
comment = pscopyuntil( psfile, fp, doc->pages[i].begin,
doc->pages[i].end, "%%Page:" );
fprintf( fp, "%%%%Page: %s %d\n",
doc->pages[i].label, page++ );
free( comment );
pscopy( psfile, fp, -1, doc->pages[i].end );
}
here = doc->begintrailer;
while ( ( comment = pscopyuntil(psfile, fp, here,
doc->endtrailer, "%%Pages:" ) ) ) {
here = ftell( psfile );
if ( pages_written ) {
free( comment );
continue;
}
switch ( sscanf( comment + length( "%%Pages:" ), "%*d %d", &i ) ) {
case 1:
fprintf( fp, "%%%%Pages: %d %d\n", pages, i );
break;
default:
fprintf( fp, "%%%%Pages: %d\n", pages );
break;
}
pages_written = true;
free( comment );
}
fclose( psfile );
}
kghostview'KGVMiniWidget::same_document_media() (./kdegraphics/kghostview/kgv_miniwidget.cpp:829)
bool KGVMiniWidget::same_document_media()
{
//printf("KGVMiniWidget::same_document_media\n");
unsigned int j;
if (olddoc == 0 && doc == 0) {
//printf(" 0 olddoc and doc\n");
return true;
}
if (olddoc == 0 || doc == 0) return false;
if (olddoc->nummedia != doc->nummedia) return false;
// Exclusive OR old document was EPS and new document is EPS
if ((olddoc->epsf || doc->epsf) && !(olddoc->epsf && doc->epsf)) {
//fprintf(stderr, "Old document was EPS and this isn't or vice versa\n");
return false;
}
for (j = 0; j < doc->nummedia; j++)
if (strcmp(olddoc->media[j].name, doc->media[j].name)) return false;
return false;
}
kghostview'KGVMiniWidget::openFile() (./kdegraphics/kghostview/kgv_miniwidget.cpp:852)
void KGVMiniWidget::openFile( QString name )
{
// printf("KGVMiniWidget::openFile\n");
FILE *fp;
struct stat sbuf;
if ( name.isNull() ) {
KMessageBox::error(0,
i18n("No file name was specified.\n"
"No document was loaded.\n"),
i18n("Error opening file"));
return;
}
if (strcmp(name, "-")) {
if ( ( fp = fopen(name, "r") ) == 0 ) {
QString s;
s = i18n("The document could not be opened.\n"
"No document has been loaded.\n\n"
"%1\nError: %2")
.arg( name )
.arg( strerror(errno) );
KMessageBox::error(0, s, i18n("Error opening file"));
return ;
} else {
oldfilename = filename;
filename = name;
if ( psfile ) {
fclose( psfile );
}
psfile = fp;
stat( filename, &sbuf );
mtime = sbuf.st_mtime;
new_file( 0 );
setName();
//marklist->select(0);
//show_page(0);
return;
}
} else {
oldfilename = filename;
filename = name;
if ( psfile ) fclose( psfile );
psfile = 0;
new_file(0);
setName();
//marklist->select(0);
return;
}
}
kghostview'KGVMiniWidget::set_new_orientation() (./kdegraphics/kghostview/kgv_miniwidget.cpp:919)
bool KGVMiniWidget::set_new_orientation(int number)
{
//printf("KGVMiniWidget::set_new_orientation\n");
bool changed = false;
bool from_doc = false;
int new_orientation;
//printf("****** Set new orientation\n");
if (force_orientation) {
new_orientation = orientation;
} else {
if (doc) {
if (toc_text && doc->pages[number].orientation != NONE) {
new_orientation = doc->pages[number].orientation;
from_doc = true;
} else if (doc->default_page_orientation != NONE) {
new_orientation = doc->default_page_orientation;
from_doc = true;
} else if (doc->orientation != NONE) {
new_orientation = doc->orientation;
from_doc = true;
} else {
new_orientation = orientation;
}
} else {
new_orientation = orientation;
}
}
/* If orientation changed,
* stop interpreter and setup for new orientation. */
if (new_orientation != current_orientation) {
//printf("New orientation\n");
page->disableInterpreter();
page->orientation = new_orientation;
//printf(" NEW ORIENT %d\n", new_orientation);
/* if(new_orientation == XtPageOrientationPortrait) {
text=XmStringCreateLtoR("Portrait", XmFONTLIST_DEFAULT_TAG);
} else if (new_orientation == XtPageOrientationLandscape) {
text=XmStringCreateLtoR("Landscape", XmFONTLIST_DEFAULT_TAG);
} else if (new_orientation == XtPageOrientationSeascape) {
text=XmStringCreateLtoR("Seascape", XmFONTLIST_DEFAULT_TAG);
} else if (new_orientation == XtPageOrientationUpsideDown) {
text=XmStringCreateLtoR("Upside down", XmFONTLIST_DEFAULT_TAG);
} */
current_orientation = new_orientation;
changed = true;
} else {
//fprintf(stderr, "No new orientation\n");
}
return changed;
}
// Set new pagemedia
kghostview'KGVMiniWidget::set_new_pagemedia() (./kdegraphics/kghostview/kgv_miniwidget.cpp:977)
bool KGVMiniWidget::set_new_pagemedia( int number )
{
//printf("KGVMiniWidget::set_new_pagemedia\n");
int new_pagemedia=0;
int new_llx=0;
int new_lly=0;
int new_urx=0;
int new_ury=0;
bool changed = false;
bool from_doc = false;
//printf("****** Set new media\n");
if (0 /*force_document_media*/) {
new_pagemedia = document_media;
} else if (0 /*app_res.force_pagemedia*/) {
new_pagemedia = default_pagemedia;
} else {
if (doc) {
if (toc_text && doc->pages[number].media != 0) {
new_pagemedia = doc->pages[number].media - doc->media;
from_doc = true;
} else if (doc->default_page_media != 0) {
new_pagemedia = doc->default_page_media - doc->media;
from_doc = true;
} else {
new_pagemedia = default_pagemedia;
}
} else {
new_pagemedia = default_pagemedia;
}
}
// If pagemedia changed, remove the old marker.
if (new_pagemedia != current_pagemedia) {
//fprintf(stderr, "New media\n");
current_pagemedia = new_pagemedia;
} else {
//fprintf(stderr, "No new media\n");
}
// Compute bounding box
if ( 1 /*!force_document_media*/ &&
1 /*!app_res.force_pagemedia*/ &&
doc && doc->epsf &&
/* Ignore malformed bounding boxes */
(doc->boundingbox[URX] > doc->boundingbox[LLX]) &&
(doc->boundingbox[URY] > doc->boundingbox[LLY])
) {
new_llx = doc->boundingbox[LLX];
new_lly = doc->boundingbox[LLY];
new_urx = doc->boundingbox[URX];
new_ury = doc->boundingbox[URY];
//text=XmStringCreateLtoR("EPS box", XmFONTLIST_DEFAULT_TAG);
//printf("EPS box\n");
} else {
//printf("Trying to compute size ! base papersize = %d\n",
//base_papersize);
new_llx = new_lly = 0;
if (new_pagemedia < base_papersize) {
new_urx = doc->media[new_pagemedia].width;
new_ury = doc->media[new_pagemedia].height;
//printf("%s\n", doc->media[new_pagemedia].name);
// text=XmStringCreateLtoR(doc->media[new_pagemedia].name
// , XmFONTLIST_DEFAULT_TAG);
} else {
new_urx = papersizes[new_pagemedia-base_papersize].width;
new_ury = papersizes[new_pagemedia-base_papersize].height;
//printf("%s\n", papersizes[new_pagemedia-base_papersize].name);
// text=XmStringCreateLtoR(
// papersizes[new_pagemedia-base_papersize].name
// , XmFONTLIST_DEFAULT_TAG);
}
}
//printf("new width = %d, current width = %d\n", new_urx, current_urx);
//printf("new h = %d, current h = %d\n", new_ury, current_ury);
//printf("new x offset %d : new y offset %d\n", new_llx, new_lly);
// If bounding box changed, setup for new size.
if ((new_llx != current_llx) || (new_lly != current_lly) ||
(new_urx != current_urx) || (new_ury != current_ury)) {
//printf("Change media\n");
page->disableInterpreter();
changed = true;
current_llx = new_llx;
current_lly = new_lly;
current_urx = new_urx;
current_ury = new_ury;
page->llx = current_llx;
page->lly = current_lly;
page->urx = current_urx;
page->ury = current_ury;
}
/* XtSetArg(args[0], XmNselectedItem, text);
//XtSetValues(viewControlMediaCombo, args, ONE); */
return changed;
}
kghostview'KGVMiniWidget::build_pagemedia_menu() (./kdegraphics/kghostview/kgv_miniwidget.cpp:1082)
void KGVMiniWidget::build_pagemedia_menu()
{
//printf("KGVMiniWidget::build_pagemedia_menu\n");
unsigned int i;
int offset;
if (same_document_media()) {
//printf("Same document media\n");
return;
}
force_document_media = false;
/* Build the Page Media menu */
/* the Page media menu has two parts.
* - the document defined page medias
* - the standard page media defined from Adobe's PPD
*/
base_papersize = 0;
if (doc) base_papersize = doc->nummedia;
for (i = 0; papersizes[i].name; i++) {} // Count the standard entries
i += base_papersize;
// if you've got an eps file need bounding box in menu too
if(doc && doc->epsf) {
offset=2;
} else {
offset=1;
}
for (i = 0; papersizes[i].name; i++) {
if (i > 0) {
// Skip over same paper size with small imageable area
if ((papersizes[i].width == papersizes[i-1].width) &&
(papersizes[i].height == papersizes[i-1].height)) {
continue;
}
}
//printf("%s ", papersizes[i].name);
}
//printf("\n");
}
kghostview'KGVMiniWidget::setup() (./kdegraphics/kghostview/kgv_miniwidget.cpp:1132)
bool KGVMiniWidget::setup()
{
// printf("KGVMiniWidget::setup\n");
int oldtoc_entry_length;
int k;
int this_page, last_page=0;
if ( ! filename ) return false;
//printf("Gone into setup\n");
// Reset to a known state.
psfree( olddoc );
//printf("Freed olddoc\n");
olddoc = doc;
doc = 0;
current_page = -1;
toc_text = 0;
oldtoc_entry_length = toc_entry_length;
//printf("Next - pages in part\n");
for(k=0;k<10;k++) pages_in_part[k]=0;
num_parts=0;
marklist->setAutoUpdate( false );
//marklist->select(0);
marklist->clear();
//printf("Reset state\n");
// Scan document and start setting things up
if (psfile) {
//printf ("Scan file -");
//doc = psscan(psfile); // 18/3/98 Jake Hamby patch
// 18/3/98 Jake Hamby patch
char *filename_dscP = 0;
char *filename_uncP = 0;
const char *cmd_scan_pdf = "gs -dNODISPLAY -dQUIET -sPDFname=%s -sDSCname=%s pdf2dsc.ps -c quit";
const char *cmd_uncompress = "gzip -d -c %s > %s";
doc = psscan(&psfile, filename, _PATH_TMP"/kghostview", &filename_dscP,
cmd_scan_pdf, &filename_uncP, cmd_uncompress);
// UNIX won't delete these files until the last reference is closed,
// so we can unlink() them now
if(filename_dscP) {
unlink(filename_dscP);
free(filename_dscP);
}
if (filename_uncP) {
unlink(filename_uncP);
free(filename_uncP);
}
// end of patch
//if (doc == 0) //printf(" 0 FILE - ");
//printf ("scanned\n");
}
//
// Build table of contents
// Well, that's what it used to be called !!
//
if (doc && (!doc->epsf && doc->numpages > 0 ||
doc->epsf && doc->numpages > 1)) {
int maxlen = 0;
unsigned int i, j;
useful_pg_labels = false;
if (doc->numpages == 1) useful_pg_labels = true;
for (i = 1; i < doc->numpages; i++)
if ( (useful_pg_labels = (useful_pg_labels ||
strcmp(doc->pages[i-1].label, doc->pages[i].label)))) break;
if (useful_pg_labels) {
for (i = 0; i < doc->numpages; i++)
if((unsigned int)maxlen<strlen(doc->pages[i].label))
maxlen=strlen(doc->pages[i].label);
} else {
double x;
x = doc->numpages;
maxlen = (int)( log10(x) + 1 );
}
toc_entry_length = maxlen + 3;
toc_length = doc->numpages * toc_entry_length - 1;
toc_text = 1;
for (i = 0; i < doc->numpages;
i++) {
if (useful_pg_labels) {
if (doc->pageorder == DESCEND) {
j = (doc->numpages - 1) - i;
} else {
j = i;
}
this_page=atoi(doc->pages[j].label);
if(last_page>this_page) {
num_parts++;
}
if (num_parts<10) pages_in_part[num_parts]++;
last_page=this_page;
} else {
}
}
page->filename = QString::null;
//printf("Set 0 filename for gs -- use pipe\n");
QString s;
// finally set maked list
for ( i = 1; i <= doc->numpages;
i++) {
j = doc->numpages-i;
s = doc->pages[j].label;
marklist->insertItem( s, 0 );
}
} else {
toc_length = 0;
toc_entry_length = 3;
page->filename = filename;
//printf("Set filename -- gs will open this file\n");
QString s("1");
marklist->insertItem( s, 0 );
}
//printf("Parsed document structure\n");
marklist->setAutoUpdate( true );
//marklist->select(0);
marklist->update();
//printf("number of parts %d\n", num_parts);
if (doc) {
if (num_parts>10 || (unsigned int)num_parts==doc->numpages) {
num_parts=0;
pages_in_part[0]=doc->numpages;
}
if(num_parts==0) {
if(doc->numpages==0) {
sprintf(page_total_label, i18n("of 1 "));
} else if(doc->numpages>0 && doc->numpages<10) {
sprintf(page_total_label, i18n("of %d "), doc->numpages);
} else if (doc->numpages<100) {
sprintf(page_total_label, i18n("of %d "), doc->numpages);
} else if (doc) {
sprintf(page_total_label, i18n("of %d"), doc->numpages);
} else {
sprintf(page_total_label, " ");
}
} else {
if(pages_in_part[0]==0) {
sprintf(page_total_label, i18n("of 1 "));
} else if(pages_in_part[0]>0 && pages_in_part[0]<10) {
sprintf(page_total_label, i18n("of %d "), pages_in_part[0]);
} else if (pages_in_part[0]<100) {
sprintf(page_total_label, i18n("of %d "), pages_in_part[0]);
} else if (doc) {
sprintf(page_total_label, i18n("of %d"), pages_in_part[0]);
} else {
sprintf(page_total_label, " ");
}
sprintf(part_total_label, i18n("of %d"), num_parts+1);
}
}
//printf("Made table of contents\n");
build_pagemedia_menu();
//printf("Built pagemedia menu\n");
// Reset ghostscript and output messages popup
if (
!doc || !olddoc ||
strcmp(oldfilename, filename) ||
olddoc->beginprolog != doc->beginprolog ||
olddoc->endprolog != doc->endprolog ||
olddoc->beginsetup != doc->beginsetup ||
olddoc->endsetup != doc->endsetup
) {
//printf("reset messages\n");
page->disableInterpreter();
//printf("Disabled Interpreter\n");
/**************************************************************
* XtUnmanageChild(infopopup);
* XmTextReplace(infotext, 0, output_position, 0_string);
* info_up = false;
* XtSetArg(args[0], XmNcursorPosition, 0);
* XtSetValues(infotext, args, ONE);
* output_position=0;
**************************************************************/
}
if(current_page==-1) current_page=0;
marklist->setAutoUpdate( true );
marklist->update();
marklist->select(0);
//printf("Setup finished\n");
return oldtoc_entry_length != toc_entry_length;
}
kghostview'KGVMiniWidget::new_file() (./kdegraphics/kghostview/kgv_miniwidget.cpp:1340)
void KGVMiniWidget::new_file( int number )
{
//printf("KGVMiniWidget::new_file\n");
QString s;
if ( isNetFile ) {
KURL u( netFile );
if ( strcmp( u.protocol(), "file" ) == 0 )
s = u.path();
else s = netFile;
} else s = filename;
bool layout_changed = false;
//page->disableInterpreter();
if (setup()) layout_changed = true;
// Coerce page number to fall in range
if (toc_text) {
if ((unsigned int)number >= doc->numpages) number = doc->numpages - 1;
if (number < 0) number = 0;
}
if (set_new_orientation(number)) layout_changed = true;
if (set_new_pagemedia(number)) layout_changed = true;
if (layout_changed) {
//printf("Layout should change -- call KPS method\n");
page->layout();
shrinkWrap();
}
}
kghostview'KGVMiniWidget::show_page() (./kdegraphics/kghostview/kgv_miniwidget.cpp:1374)
void KGVMiniWidget::show_page(int number)
{
// printf("KGVMiniWidget::show_page\n");
struct stat sbuf;
bool new_orient = false, new_media = false;
if ( ! filename ) {
//printf("No file !\n");
return;
}
if (psfile) {
//printf("Oh does it go into psfile ?\n");
if (!stat(filename, &sbuf) && mtime != sbuf.st_mtime) {
fclose(psfile);
psfile = fopen(filename, "r");
mtime = sbuf.st_mtime;
oldfilename = filename;
new_file(number);
}
}
// Coerce page number to fall in range - Duh, what does that mean ?
if (toc_text) {
if ((unsigned int)number >= doc->numpages) number = doc->numpages - 1;
if (number < 0) number = 0;
}
//printf("Hmm shouldn't this whole thing be inside the if(psfile) ?\n");
new_orient=set_new_orientation(number);
new_media=set_new_pagemedia(number);
//printf("new_orient %d, new_media %d\n", new_orient, new_media);
if (new_orient || new_media)
{
page->layout();
};
if (toc_text) {
current_page = number;
if ( page->isInterpreterReady() ) {
//printf("Interpreter ready - Fire off next page\n");
page->nextPage();
} else {
//printf("Start interpreter and send preamble\n");
page->enableInterpreter();
page->sendPS(psfile, doc->beginprolog,
doc->lenprolog, false);
page->sendPS(psfile, doc->beginsetup,
doc->lensetup, false);
}
//printf("Send page %d\n", current_page);
page->sendPS(psfile, doc->pages[current_page].begin,
doc->pages[current_page].len, false);
} else {
if ( !page->isInterpreterRunning() ) {
//printf("This is not a structured document -- start int.\n");
page->enableInterpreter();
} else if ( page->isInterpreterReady() ) {
page->nextPage();
} else XBell(page->x11Display(), 0);
}
//
// Well that takes care of sending the postscript.
// Now update the page label on the status line
//
if(toc_text) {
if(num_parts==0) {
part_string = i18n("Sc.1 ");
sprintf(part_total_label, i18n("of 1 "));
if(number==-1)
page_string = i18n("P.1 ");
else
page_string = i18n("P.%1 ").arg(number+1);
} else {
int cumulative_pages=0;
int k, part;
for(k=0;k<10;k++) {
cumulative_pages+=pages_in_part[k];
if(cumulative_pages>number) break;
}
cumulative_pages-=pages_in_part[k];
part=k-1;
page_string = i18n("P.%1 ").arg(number+1-cumulative_pages);
part_string = i18n("Sc.%1 ").arg(part+2);
part=k;
if(pages_in_part[part]==0) {
sprintf(page_total_label, i18n("of 1 "));
} else if(pages_in_part[part]>0 && pages_in_part[part]<10) {
sprintf(page_total_label, i18n("of %d "), pages_in_part[part]);
} else if (pages_in_part[part]<100) {
sprintf(page_total_label, i18n("of %d "), pages_in_part[part]);
} else if (doc) {
sprintf(page_total_label, i18n("of %d"), pages_in_part[part]);
} else {
sprintf(page_total_label, " ");
}
sprintf(part_total_label, i18n("of %d "), num_parts+1);
}
part_label_text=operator+(part_string, part_total_label);
page_label_text=operator+(page_string, page_total_label);
position_label=operator+(part_label_text, page_label_text);
}
}
kghostview'KGVMiniWidget::set_magstep() (./kdegraphics/kghostview/kgv_miniwidget.cpp:1497)
void KGVMiniWidget::set_magstep(unsigned int new_magstep)
{
magstep = new_magstep;
if (set_new_magstep())
{
page->layout();
page->resize(page->width(), page->height());
page->repaint();
show_page(current_page);
shrinkWrap();
}
}
bool
kghostview'KGVMiniWidget::set_new_magstep() (./kdegraphics/kghostview/kgv_miniwidget.cpp:1512)
KGVMiniWidget::set_new_magstep()
{
unsigned int new_magstep;
bool changed = false;
float xdpi, ydpi;
new_magstep = magstep;
if (new_magstep != current_magstep)
{
//printf(" new_magstep != current_magstep\n");
page->disableInterpreter();
changed = true;
xdpi = default_xdpi;
ydpi = default_ydpi;
magnify(&xdpi, new_magstep);
magnify(&ydpi, new_magstep);
page->xdpi=xdpi;
page->ydpi=ydpi;
current_magstep = new_magstep;
}
return changed;
}
kghostview'KGVMiniWidget::magnify() (./kdegraphics/kghostview/kgv_miniwidget.cpp:1538)
void KGVMiniWidget::magnify(float *dpi, unsigned int magstep)
{
if (magstep < shrink_magsteps)
{
*dpi = (int)((* dpi)*magstep/(shrink_magsteps));
}
else
{
*dpi = (int)((* dpi)+2*(* dpi)*(magstep-shrink_magsteps)/(expand_magsteps));
}
}