summaryrefslogtreecommitdiffstats
path: root/kdvi/dviFile.h
blob: 5f6dd671924836a5a8353ae12a1c921b5f016398 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// Class: dviFile
//
// Class that represents a DVI file. Part of KDVI - A DVI previewing
// plugin for kviewshell.
//
// (C) 2004--2005 Stefan Kebekus. Distributed under the GPL.
//

#ifndef _DVIFILE_H
#define _DVIFILE_H

#include "bigEndianByteReader.h"

#include <tqintdict.h>
#include <tqiodevice.h>
#include <tqmemarray.h>
#include <tqstring.h>

class fontPool;
class pageSize;
class TeXFontDefinition;


class dvifile : public bigEndianByteReader
{
 public:
  /** Makes a deep copy of the old DVI file. */
  dvifile(const dvifile *old, fontPool *fp );
  dvifile(const TQString& fname, class fontPool* pool);

  ~dvifile();

  fontPool     * font_pool;
  TQString        filename;
  TQString        generatorString;
  TQ_UINT16       total_pages;
  TQMemArray<TQ_UINT32> page_offset;

  /** Saves the DVI file. Returns true on success. */
  bool           saveAs(const TQString &filename);

  // Returns a pointer to the DVI file's data, or 0 if no data has yet
  // been allocated.
  TQ_UINT8      * dvi_Data() {return dviData.data();}

  TQIODevice::Offset size_of_file;
  TQString        errorMsg;

  /** This field is set to zero when the DVI file is constructed, and
      will be modified during the prescan phase (at this time the
      prescan code still resides in the dviRenderer class) */
  TQ_UINT16       numberOfExternalPSFiles;
  
  /** This field is set to zero when the DVI file is constructed, and
      will be modified during the prescan phase (at this time the
      prescan code still resides in the dviRenderer class) */
  TQ_UINT16       numberOfExternalNONPSFiles;

  TQ_UINT32       beginning_of_postamble;
  
  /** 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;
  
  TQIntDict<TeXFontDefinition> tn_table;

  /** Returns the number of centimeters per DVI unit in this DVI
      file. */
  double         getCmPerDVIunit() const {return cmPerDVIunit;}

  /** Returns the magnification of the DVI file, as described in the
      DVI Standard. */
  TQ_UINT32        getMagnification() const {return _magnification;}

  /** 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. */
  TQ_UINT8        errorCounter;

  /** Papersize information read from the dvi-File */
  pageSize       *suggestedPageSize;
  
  /** Sets new DVI data; all old data is erased. EXPERIMENTAL, use
      with care. */
  void           setNewData(const TQMemArray<TQ_UINT8>& newData) {dviData = newData;}

  /** 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();
  
  /** PDF to PS file conversion 

  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:

  - convert files only once.

  - delete all converted files on destruction

  @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

  @returns The name of the PS file, or TQString() on failure.
  */
  TQString convertPDFtoPS(const TQString &PDFFilename);

 private:
  /** process_preamble reads the information in the preamble and
      stores it into global variables for later use. */
  void           process_preamble();
  void           find_postamble();
  /** 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. */
  void           read_postamble();
  void           prepare_pages();


  /** Offset in DVI file of last page, set in read_postamble(). */
  TQ_UINT32       last_page_offset;
  TQ_UINT32       _magnification;

  double         cmPerDVIunit;

  TQMemArray<TQ_UINT8>  dviData;


  /** 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
  of the associated PS file, or TQString(), if the file could not
  be converted. The PS files are deleted when the DVI-file is
  destructed. */
  TQMap<TQString, TQString> convertedFiles;
};

#endif //ifndef _DVIFILE_H