2005-12-15 21:34:10 +00:00
|
|
|
// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-
|
2004-12-27 09:02:20 +00:00
|
|
|
//
|
|
|
|
// Class: dviFile
|
|
|
|
//
|
|
|
|
// Class that represents a DVI file. Part of KDVI - A DVI previewing
|
|
|
|
// plugin for kviewshell.
|
|
|
|
//
|
2005-09-16 12:18:31 +00:00
|
|
|
// (C) 2004-2005 Stefan Kebekus. Distributed under the GPL.
|
2004-12-27 09:02:20 +00:00
|
|
|
//
|
2000-06-23 00:22:44 +00:00
|
|
|
|
|
|
|
#ifndef _DVIFILE_H
|
|
|
|
#define _DVIFILE_H
|
|
|
|
|
2005-10-03 20:01:17 +00:00
|
|
|
#include "bigEndianByteReader.h"
|
|
|
|
|
2005-09-21 18:10:56 +00:00
|
|
|
#include <Q3IntDict>
|
2005-06-07 10:36:52 +00:00
|
|
|
#include <Q3MemArray>
|
2005-09-21 18:10:56 +00:00
|
|
|
#include <QIODevice>
|
2005-10-13 22:41:50 +00:00
|
|
|
#include <QMap>
|
2007-04-22 12:03:30 +00:00
|
|
|
|
2000-06-23 00:22:44 +00:00
|
|
|
|
2001-08-08 12:50:03 +00:00
|
|
|
class fontPool;
|
2003-09-05 08:57:37 +00:00
|
|
|
class pageSize;
|
2003-03-07 11:54:35 +00:00
|
|
|
class TeXFontDefinition;
|
2000-06-23 00:22:44 +00:00
|
|
|
|
2005-10-03 20:01:17 +00:00
|
|
|
|
2001-10-18 16:40:34 +00:00
|
|
|
class dvifile : public bigEndianByteReader
|
|
|
|
{
|
2000-06-23 00:22:44 +00:00
|
|
|
public:
|
2004-08-22 17:39:15 +00:00
|
|
|
/** Makes a deep copy of the old DVI file. */
|
|
|
|
dvifile(const dvifile *old, fontPool *fp );
|
2005-10-03 20:01:17 +00:00
|
|
|
dvifile(const QString& fname, class fontPool* pool);
|
2004-08-22 17:39:15 +00:00
|
|
|
|
2000-06-23 00:22:44 +00:00
|
|
|
~dvifile();
|
|
|
|
|
2001-03-02 21:02:45 +00:00
|
|
|
fontPool * font_pool;
|
2000-06-23 00:22:44 +00:00
|
|
|
QString filename;
|
2001-03-28 10:16:48 +00:00
|
|
|
QString generatorString;
|
2005-11-14 10:23:21 +00:00
|
|
|
quint16 total_pages;
|
|
|
|
Q3MemArray<quint32> page_offset;
|
2004-08-22 17:39:15 +00:00
|
|
|
|
|
|
|
/** Saves the DVI file. Returns true on success. */
|
|
|
|
bool saveAs(const QString &filename);
|
|
|
|
|
|
|
|
// Returns a pointer to the DVI file's data, or 0 if no data has yet
|
|
|
|
// been allocated.
|
2005-11-14 10:23:21 +00:00
|
|
|
quint8 * dvi_Data() {return dviData.data();}
|
2001-10-12 01:32:07 +00:00
|
|
|
|
|
|
|
QIODevice::Offset size_of_file;
|
2001-11-01 09:53:31 +00:00
|
|
|
QString errorMsg;
|
2003-09-05 08:57:37 +00:00
|
|
|
|
2003-09-07 12:12:29 +00:00
|
|
|
/** This field is set to zero when the DVI file is constructed, and
|
|
|
|
will be modified during the prescan phase (at this time the
|
2005-06-02 10:05:50 +00:00
|
|
|
prescan code still resides in the dviRenderer class) */
|
2005-11-14 10:23:21 +00:00
|
|
|
quint16 numberOfExternalPSFiles;
|
2005-10-14 22:46:01 +00:00
|
|
|
|
2004-12-21 06:06:43 +00:00
|
|
|
/** This field is set to zero when the DVI file is constructed, and
|
|
|
|
will be modified during the prescan phase (at this time the
|
2005-06-02 10:05:50 +00:00
|
|
|
prescan code still resides in the dviRenderer class) */
|
2005-11-14 10:23:21 +00:00
|
|
|
quint16 numberOfExternalNONPSFiles;
|
2003-09-07 12:12:29 +00:00
|
|
|
|
2005-11-14 10:23:21 +00:00
|
|
|
quint32 beginning_of_postamble;
|
2005-10-14 22:46:01 +00:00
|
|
|
|
2001-09-03 08:57:03 +00:00
|
|
|
/** This flag is set to "true" during the construction of the
|
|
|
|
dvifile, and is never changed afterwards by the dvifile
|
|
|
|
class. It is used in kdvi in conjuction with source-specials:
|
|
|
|
the first time a page with source specials is rendered, KDVI
|
|
|
|
shows an info dialog, and the flag is set to false. That way
|
|
|
|
KDVI ensures that the user is only informed once. */
|
|
|
|
bool sourceSpecialMarker;
|
2005-10-14 22:46:01 +00:00
|
|
|
|
2005-06-07 10:36:52 +00:00
|
|
|
Q3IntDict<TeXFontDefinition> tn_table;
|
2001-08-08 12:50:03 +00:00
|
|
|
|
2003-07-26 12:55:53 +00:00
|
|
|
/** Returns the number of centimeters per DVI unit in this DVI
|
|
|
|
file. */
|
2005-08-26 18:18:29 +00:00
|
|
|
double getCmPerDVIunit() const {return cmPerDVIunit;}
|
2004-12-27 09:02:20 +00:00
|
|
|
|
|
|
|
/** Returns the magnification of the DVI file, as described in the
|
|
|
|
DVI Standard. */
|
2005-11-14 10:23:21 +00:00
|
|
|
quint32 getMagnification() const {return _magnification;}
|
2001-08-08 12:50:03 +00:00
|
|
|
|
2003-04-01 11:09:15 +00:00
|
|
|
/** This member is set to zero on construction and can be used by
|
|
|
|
other software to count error messages that were printed when
|
|
|
|
the DVI-file was processed. Suggested application: limit the
|
|
|
|
number of error messages to, say, 25. */
|
2005-11-14 10:23:21 +00:00
|
|
|
quint8 errorCounter;
|
2003-04-01 11:09:15 +00:00
|
|
|
|
2003-07-10 07:13:15 +00:00
|
|
|
/** Papersize information read from the dvi-File */
|
2003-09-05 08:57:37 +00:00
|
|
|
pageSize *suggestedPageSize;
|
2005-10-14 22:46:01 +00:00
|
|
|
|
2004-08-22 17:39:15 +00:00
|
|
|
/** Sets new DVI data; all old data is erased. EXPERIMENTAL, use
|
|
|
|
with care. */
|
2005-11-14 10:23:21 +00:00
|
|
|
void setNewData(const Q3MemArray<quint8>& newData) {dviData = newData;}
|
2003-07-10 07:13:15 +00:00
|
|
|
|
2004-08-22 17:39:15 +00:00
|
|
|
/** Page numbers that appear in a DVI document need not be
|
|
|
|
ordered. Worse, page numbers need not be unique. This method
|
|
|
|
renumbers the pages. */
|
|
|
|
void renumber();
|
2003-07-10 07:13:15 +00:00
|
|
|
|
2005-09-16 12:18:31 +00:00
|
|
|
/** PDF to PS file conversion
|
2005-10-14 22:46:01 +00:00
|
|
|
|
2005-09-16 12:18:31 +00:00
|
|
|
This utility method takes the name of a PDF-file, and attempts to
|
|
|
|
convert it to a PS file. The dvifile internally keeps a list of
|
|
|
|
converted files, to do two thigs:
|
2005-10-14 22:46:01 +00:00
|
|
|
|
2005-09-16 12:18:31 +00:00
|
|
|
- convert files only once.
|
2005-10-14 22:46:01 +00:00
|
|
|
|
2005-09-16 12:18:31 +00:00
|
|
|
- delete all converted files on destruction
|
2005-10-14 22:46:01 +00:00
|
|
|
|
2005-09-16 12:18:31 +00:00
|
|
|
@warning The internal buffer can lead to difficulties if filenames
|
|
|
|
of PDF-files are not unique: if the content of a PDF file is
|
|
|
|
changed and this method is called a second time with the same file
|
|
|
|
name, the method will then NOT convert the file, but simply return
|
|
|
|
the name from the buffer
|
|
|
|
|
2007-08-16 15:28:21 +00:00
|
|
|
@returns The name of the PS file, or QString() on failure.
|
2005-09-16 12:18:31 +00:00
|
|
|
*/
|
|
|
|
QString convertPDFtoPS(const QString &PDFFilename, QString *converrorms=0);
|
|
|
|
|
2001-10-12 01:32:07 +00:00
|
|
|
private:
|
|
|
|
/** process_preamble reads the information in the preamble and
|
|
|
|
stores it into global variables for later use. */
|
2005-08-26 18:18:29 +00:00
|
|
|
void process_preamble();
|
|
|
|
void find_postamble();
|
2001-03-02 21:02:45 +00:00
|
|
|
/** read_postamble reads the information in the postamble, storing
|
|
|
|
it into global variables. It also takes care of reading in all
|
|
|
|
of the pixel files for the fonts used in the job. */
|
2005-08-26 18:18:29 +00:00
|
|
|
void read_postamble();
|
|
|
|
void prepare_pages();
|
2001-10-18 16:40:34 +00:00
|
|
|
|
2003-02-13 21:28:22 +00:00
|
|
|
|
2001-10-18 16:40:34 +00:00
|
|
|
/** Offset in DVI file of last page, set in read_postamble(). */
|
2005-11-14 10:23:21 +00:00
|
|
|
quint32 last_page_offset;
|
|
|
|
quint32 _magnification;
|
2003-07-26 12:55:53 +00:00
|
|
|
|
|
|
|
double cmPerDVIunit;
|
2004-08-22 17:39:15 +00:00
|
|
|
|
2005-11-14 10:23:21 +00:00
|
|
|
Q3MemArray<quint8> dviData;
|
2005-09-16 12:18:31 +00:00
|
|
|
|
|
|
|
/** Map of filenames for converted PDF files
|
|
|
|
|
|
|
|
This map contains names of PDF files that were converted to
|
|
|
|
PostScript. The key is the name of the PDF file, the data the name
|
2007-08-16 15:28:21 +00:00
|
|
|
of the associated PS file, or QString(), if the file could not
|
2005-09-16 12:18:31 +00:00
|
|
|
be converted. The PS files are deleted when the DVI-file is
|
|
|
|
destructed. */
|
|
|
|
QMap<QString, QString> convertedFiles;
|
|
|
|
|
|
|
|
/** Flag, used so that KDVI complains only once about a missing
|
|
|
|
"PDF2PS" utility. Set to "false" in the constructor. */
|
|
|
|
bool have_complainedAboutMissingPDF2PS;
|
2000-06-23 00:22:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //ifndef _DVIFILE_H
|