File indexing completed on 2024-05-12 04:33:56
0001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*- 0002 // 0003 // Class: dviFile 0004 // 0005 // Class that represents a DVI file. Part of KDVI - A DVI previewing 0006 // plugin for kviewshell. 0007 // 0008 // SPDX-FileCopyrightText: 2004-2005 Stefan Kebekus 0009 // SPDX-License-Identifier: GPL-2.0-or-later 0010 0011 #ifndef _DVIFILE_H 0012 #define _DVIFILE_H 0013 0014 #include "bigEndianByteReader.h" 0015 0016 #include <QHash> 0017 #include <QMap> 0018 #include <QString> 0019 #include <QVector> 0020 0021 class fontPool; 0022 class pageSize; 0023 class TeXFontDefinition; 0024 0025 class dvifile : public bigEndianByteReader 0026 { 0027 public: 0028 /** Makes a deep copy of the old DVI file. */ 0029 dvifile(const dvifile *old, fontPool *fp); 0030 dvifile(const QString &fname, class fontPool *pool); 0031 0032 ~dvifile(); 0033 0034 dvifile(const dvifile &) = delete; 0035 dvifile &operator=(const dvifile &) = delete; 0036 0037 fontPool *font_pool; 0038 QString filename; 0039 QString generatorString; 0040 quint16 total_pages; 0041 QVector<quint32> page_offset; 0042 0043 /** Saves the DVI file. Returns true on success. */ 0044 bool saveAs(const QString &filename); 0045 0046 // Returns a pointer to the DVI file's data, or 0 if no data has yet 0047 // been allocated. 0048 quint8 *dvi_Data() 0049 { 0050 return dviData.data(); 0051 } 0052 0053 qint64 size_of_file; 0054 QString errorMsg; 0055 0056 /** This field is set to zero when the DVI file is constructed, and 0057 will be modified during the prescan phase (at this time the 0058 prescan code still resides in the dviRenderer class) */ 0059 quint16 numberOfExternalPSFiles; 0060 0061 /** This field is set to zero when the DVI file is constructed, and 0062 will be modified during the prescan phase (at this time the 0063 prescan code still resides in the dviRenderer class) */ 0064 quint16 numberOfExternalNONPSFiles; 0065 0066 quint32 beginning_of_postamble; 0067 0068 /** This flag is set to "true" during the construction of the 0069 dvifile, and is never changed afterwards by the dvifile 0070 class. It is used in kdvi in conjunction with source-specials: 0071 the first time a page with source specials is rendered, KDVI 0072 shows an info dialog, and the flag is set to false. That way 0073 KDVI ensures that the user is only informed once. */ 0074 bool sourceSpecialMarker; 0075 0076 QHash<int, TeXFontDefinition *> tn_table; 0077 0078 /** Returns the number of centimeters per DVI unit in this DVI 0079 file. */ 0080 double getCmPerDVIunit() const 0081 { 0082 return cmPerDVIunit; 0083 } 0084 0085 /** Returns the magnification of the DVI file, as described in the 0086 DVI Standard. */ 0087 quint32 getMagnification() const 0088 { 0089 return _magnification; 0090 } 0091 0092 /** This member is set to zero on construction and can be used by 0093 other software to count error messages that were printed when 0094 the DVI-file was processed. Suggested application: limit the 0095 number of error messages to, say, 25. */ 0096 quint8 errorCounter; 0097 0098 /** Papersize information read from the dvi-File */ 0099 pageSize *suggestedPageSize; 0100 0101 /** Sets new DVI data; all old data is erased. EXPERIMENTAL, use 0102 with care. */ 0103 void setNewData(const QVector<quint8> &newData) 0104 { 0105 dviData = newData; 0106 } 0107 0108 /** Page numbers that appear in a DVI document need not be 0109 ordered. Worse, page numbers need not be unique. This method 0110 renumbers the pages. */ 0111 void renumber(); 0112 0113 /** PDF to PS file conversion 0114 0115 This utility method takes the name of a PDF-file, and attempts to 0116 convert it to a PS file. The dvifile internally keeps a list of 0117 converted files, to do two things: 0118 0119 - convert files only once. 0120 0121 - delete all converted files on destruction 0122 0123 @warning The internal buffer can lead to difficulties if filenames 0124 of PDF-files are not unique: if the content of a PDF file is 0125 changed and this method is called a second time with the same file 0126 name, the method will then NOT convert the file, but simply return 0127 the name from the buffer 0128 0129 @returns The name of the PS file, or QString() on failure. 0130 */ 0131 QString convertPDFtoPS(const QString &PDFFilename, QString *converrorms = nullptr); 0132 0133 private: 0134 void pdf2psNotFound(const QString &PDFFilename, QString *converrorms); 0135 0136 /** process_preamble reads the information in the preamble and 0137 stores it into global variables for later use. */ 0138 void process_preamble(); 0139 void find_postamble(); 0140 /** read_postamble reads the information in the postamble, storing 0141 it into global variables. It also takes care of reading in all 0142 of the pixel files for the fonts used in the job. */ 0143 void read_postamble(); 0144 void prepare_pages(); 0145 0146 /** Offset in DVI file of last page, set in read_postamble(). */ 0147 quint32 last_page_offset; 0148 quint32 _magnification; 0149 0150 double cmPerDVIunit; 0151 0152 QVector<quint8> dviData; 0153 0154 /** Map of filenames for converted PDF files 0155 0156 This map contains names of PDF files that were converted to 0157 PostScript. The key is the name of the PDF file, the data the name 0158 of the associated PS file, or QString(), if the file could not 0159 be converted. The PS files are deleted when the DVI-file is 0160 destructed. */ 0161 QMap<QString, QString> convertedFiles; 0162 0163 /** Flag, used so that KDVI complains only once about a missing 0164 "PDF2PS" utility. Set to "false" in the constructor. */ 0165 bool have_complainedAboutMissingPDF2PS; 0166 }; 0167 0168 #endif // ifndef _DVIFILE_H