dvi2bitmap  dvi2bitmap1.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
DviFile Class Reference

Represents a DVI file. More...

#include <DviFile.h>

Classes

class  FontSet
 Represents the set of fonts in a DVI file. More...
 

Public Types

enum  DviUnits {
  unit_BAD, unit_pt, unit_pc, unit_in,
  unit_bp, unit_cm, unit_mm, unit_dd,
  unit_cc, unit_sp, unit_pixels, unit_dvi
}
 Units of length. More...
 

Public Member Functions

 DviFile (string &s, int resolution=0, double magmag=1.0, bool read_postamble=true, bool seekable=true) throw (DviError)
 Constructs a new DviFile object. More...
 
 ~DviFile ()
 
bool eof ()
 Indicates whether we are at the end of the DVI file. More...
 
DviFileEventgetEvent ()
 Gets an event from the DVI file. More...
 
DviFileEventgetEndOfPage ()
 Skips to the end of the page. More...
 
int currH (DviUnits units=unit_pixels) const throw (DviError)
 Obtains the current horizontal position. More...
 
int currV (DviUnits units=unit_pixels) const throw (DviError)
 Obtains the current vertical position. More...
 
int hSize ()
 Obtains the `width of the widest page'. More...
 
int vSize ()
 Obtains the `height plus depth of the tallest page'. More...
 
double magnification () const
 Return the net magnification factor for the DVI file. More...
 
int pt2px (double npt) const
 Converts a length in points to one in pixels, using the current magnifications and any other relevant parameters. More...
 
const string * filename () const
 Gets the name of this DVI file. More...
 
const PkFontgetFallbackFont (const PkFont *desired)
 Returns a fallback font, for use when a requested font is not available. More...
 
bool haveReadPostamble () const
 Reports whether the DVI file postamble was read when this file was opened. More...
 
const FontSetgetFontSet () const
 Obtains a representation of the set of fonts contained in this DVI file. More...
 

Static Public Member Functions

static DviUnits unitType (string unitString)
 Convert a string to a unit. More...
 
static string unitString (DviUnits unit)
 Gets the string representation of a DVI unit. More...
 
static double convertFromScaledPoints (int sp, DviUnits units, DviFile *dvif=0) throw (DviError)
 Convert a TeX scaled point to another unit. More...
 
static int convertToScaledPoints (double length, DviUnits units, DviFile *dvif=0) throw (DviError)
 Convert a length to TeX scaled points. More...
 
static double convertUnits (double length, DviUnits from_units, DviUnits to_units, DviFile *dvif=0) throw (DviError)
 Convert a length from one set of units to another. More...
 
static verbosities verbosity (const verbosities level)
 Sets the verbosity of this module. More...
 

Detailed Description

Represents a DVI file.

See the DVI Driver standard [driv-std] for details of the parameters here.

[driv-std] Level-0 DVI Driver Standard, available on-line on CTAN, in the directory dviware/driv-standard.

Member Enumeration Documentation

Units of length.

Used in currH and currV, and other conversions are available through method convertFromScaledPoints.

Enumerator
unit_BAD 

An invalid unit.

unit_pt 

Traditional printer's point.

There are 72.27pt in 1in.

unit_pc 

Pica; 1pc=12pt.

unit_in 

Inch; 1in=25.4mm.

unit_bp 

The big point; 72bp=1in.

Postscript points are bigpoints in this terminology.

unit_cm 

Centimetre; 1cm=10E-2m.

unit_mm 

Millimetre; 1mm=10E-3m.

One metre is the distance light travels, in vacuum, in a time 1/299792458 seconds.

Conversion factors: 1mm=2.84527559pt; 1pt=0.3515mm.

unit_dd 

Didot point; 1157dd=1238pt.

unit_cc 

Cicero; 1cc=12dd.

unit_sp 

TeX `scaled points'.

These are the dimensions which TeX itself works in, where 65536sp=1pt, or 1sp=5.36434×10-9 metres. Light at that wavelength is classed as soft X-rays, and is a health-hazard (so don't examine your scaled points too closely); it's about the size of 50 atoms.

unit_pixels 

Pixel units.

The DVI standard calls these `device units', and refers to them with the notation hh.

unit_dvi 

DVI units.

All dimensions within the DVI file are expressed in these units, written as h in the standard. The conversion of DVI units to physical units is governed by the values in the preamble. DVI files written by TeX (that is, essentially all of them, except those written by converters such as dtl, which write compatible ones) have a preamble which ensures that the DVI units are scaled points, times the overall magnification factor.

Constructor & Destructor Documentation

DviFile::DviFile ( string &  fn,
int  res = 0,
double  externalmag = 1.0,
bool  read_post = true,
bool  seekable = true 
)
throw (DviError
)

Constructs a new DviFile object.

Once the DVI file has been opened in this way, its contents can be processed in an event-based fashion, by repeatedly calling getEvent and handling the returned object.

The DVI file may be specified as "-", in which case the DVI file will be read from stdin. In fact, this is just a synonym for the expression, <osfd>0, as understood by InputByteStream (qv). In this case, the postamble is not read, irrespective of the value of parameter read_post, and this is known not to be seekable, so the value of parameter seekable is ignored.

After the DVI file has been opened using this constructor, the preamble may or may not be read (this may be specified in future versions). If you need to ensure that the preamble is read (for example if you wish to call convertUnits), then you should call getEvent once to retrieve the DviFilePreamble event which it returns the first time it is called.

Parameters
fnthe name of the DVI file. The given name is searched for both as-is, and with an extension .dvi added.
resthe base DPI to be used for processing the file, in pixels-per-inch. If given as zero, default to the resolution returned by PkFont#dpiBase.
externalmagthe factor by which the DVI file's internal magnification factor should itself be magnified, specified externally to the DVI file (on a command line, for example); default is 1.0
read_postif true, then the DVI postamble will be read; if false, it will be skipped. This is false by default, but if the postamble is read, then the font declarations there will be read and acted on, which may speed things up.
seekableif true, the input file is seekable; if false, it is not seekable, the value of read_post is ignored (taken to be false), and the file is opened without attempting to add any .dvi extension.
Exceptions
DviErrorif the DVI file cannot be opened

References DviError::problem(), and PkFont::setResolution().

DviFile::~DviFile ( )

Member Function Documentation

double DviFile::convertFromScaledPoints ( int  sp,
DviUnits  units,
DviFile dvif = 0 
)
throw (DviError
)
static

Convert a TeX scaled point to another unit.

It is possible to convert to pixel units with this method; however it is generally better to either get pixel positions directly (through currH or currV for example).

The conversions to DVIunits and pixels are not universal, but are instead dependent on a particular DVI file; if you wish to convert to either of these units, you must supply a reference to a DVI file. If not, any argument here is ignored, and may be zero (the default).

Parameters
spthe length in scaled points
unitsthe unit to convert it to
dvifa DVI file, if pixels or DVIunits are requested
Returns
the converted unit
Exceptions
DviErrorif pixels or DVIunits were requested and no dvif parameter was supplied
See Also
convertToScaledPoints
convertUnits

Referenced by DviFilePosition::DviFilePosition(), DviFilePosition::getX(), DviFilePosition::getY(), DviFilePosition::scale(), and DviFilePosition::shift().

int DviFile::convertToScaledPoints ( double  length,
DviUnits  units,
DviFile dvif = 0 
)
throw (DviError
)
static

Convert a length to TeX scaled points.

The conversions from DVIunits and pixels are not universal, but are instead dependent on a particular DVI file; if you wish to convert from either of these units, you must supply a reference to a DVI file. If not, any argument here is ignored, and may be zero (the default).

Parameters
lengththe length to be converted
unitsthe units in which the length is currently
dvifa DVI file, if pixels or DVIunits are requested
Returns
the input length as a multiple of the TeX scaled-point
Exceptions
DviErrorif pixels or DVIunits were requested and no dvif parameter was supplied
See Also
convertFromScaledPoints
convertUnits

Referenced by DviFilePosition::DviFilePosition(), and DviFilePosition::shift().

double DviFile::convertUnits ( double  length,
DviUnits  from_units,
DviUnits  to_units,
DviFile dvif = 0 
)
throw (DviError
)
static

Convert a length from one set of units to another.

The conversions to DVIunits and pixels are not universal, but are instead dependent on a particular DVI file; if you wish to convert to either of these units, you must supply a reference to a DVI file. If not, any argument here is ignored, and may be zero (the default).

Parameters
lengththe length to be converted
from_unitsthe units in which length is currently expressed
to_unitsthe target units
dvifa DVI file, if pixels or DVIunits are requested
Returns
the length expressed as a multiple of the target unit
Exceptions
DviErrorif pixels or DVIunits were requested and no dvif parameter was supplied
See Also
convertFromScaledPoints
convertToScaledPoints

Referenced by main().

int DviFile::currH ( DviUnits  units = unit_pixels) const
throw (DviError
)
inline

Obtains the current horizontal position.

The position can be reported in any of unit_pixels, unit_dvi or unit_sp; it is an error to call this function with any other of the defined units.

The conversion to pixel units includes any drift correction, and is correctly rounded. Scaled points are calculated as DVI units times the overall magnification (that is, we ignore the general case of DVI files with odd preamble scalings).

Returns
the horizontal position, in the chosen units
Exceptions
DviErrorif we are invoked with an inappropriate unit argument

References unit_dvi, unit_pixels, and unit_sp.

Referenced by main(), and show_position().

int DviFile::currV ( DviUnits  units = unit_pixels) const
throw (DviError
)
inline

Obtains the current vertical position.

See currH, to which this is precisely analogous.

References unit_dvi, unit_pixels, and unit_sp.

Referenced by main(), and show_position().

bool DviFile::eof ( )

Indicates whether we are at the end of the DVI file.

This is true if the underlying file is closed, or if we have read all the pages and getEvent has returned a DviFilePostamble event.

Returns
true if we are at EOF

References InputByteStream::eof().

Referenced by getEvent(), and main().

const string* DviFile::filename ( ) const
inline

Gets the name of this DVI file.

Returns
the open file name as a string

Referenced by main().

DviFileEvent * DviFile::getEndOfPage ( )

Skips to the end of the page.

This reads the DVI file at high speed until it finds the next end-of-page event, which it returns, leaving the DVI file positioned appropriately. If there are in fact no more pages – if the last end-of-page event has already been returned – then return either a DviFilePostamble event or zero, just like getEvent.

Returns
the next end-of-page event

References getEvent().

Referenced by main().

DviFileEvent * DviFile::getEvent ( )

Gets an event from the DVI file.

This is the routine which does most of the actual work. It scans through the file reading opcodes. Most of these it handles itself, but certain ones it handles by returning an event to the calling routine.

The first event this method will return is the DviFilePreamble event, and the last one is a DviFilePostamble event, after which eof() will be true, and this method will return only zero.

The events which can be returned are all of the subclasses of DviFileEvent, qv.

When you are finished with the returned event, you should release it by a call to the event's release method, after which you should make no further reference to it.

Returns
the next event from the DVI file, or zero if eof() is true

References DviFilePreamble::comment, DviFilePage::count, DviFilePreamble::den, DviFilePreamble::dviType, eof(), i, DviFilePreamble::mag, normal, DviFilePreamble::num, and DviFilePage::previous.

Referenced by getEndOfPage(), and main().

const PkFont * DviFile::getFallbackFont ( const PkFont desired)

Returns a fallback font, for use when a requested font is not available.

The font returned depends on whether the DVI postamble was read or not, on what fonts have already been seen in the file, and on the font desired. This flexibility will not, however, stray beyond the liberty given by section 4.4, `Missing fonts', in the DVI standard.

Parameters
desireda pointer to the font which was requested (but not, presumably, loaded), or 0 if this information is not available
Returns
a pointer to a fallback font, or zero if absolutely no fonts are available

References DviFile::FontSet::begin(), PkFont::designSize, DviFile::FontSet::end(), and getFontSet().

Referenced by main().

const FontSet* DviFile::getFontSet ( ) const
inline

Obtains a representation of the set of fonts contained in this DVI file.

If the postamble was read, then the FontSet returned by this method will be complete; if not, it will simply represent the set of fonts read so far in the file.

Returns
a pointer to the FontSet for this file

Referenced by getFallbackFont(), and main().

bool DviFile::haveReadPostamble ( ) const
inline

Reports whether the DVI file postamble was read when this file was opened.

This affects the semantics of such methods as getFontSet. Note that this only reports whether the postamble was read at the start of processing, and it does not become true when the postamble is discovered at the end; it is not an end-of-file indicator. For that, see the eof method.

Returns
true if the postamble was (successfully) read

Referenced by main().

int DviFile::hSize ( )

Obtains the `width of the widest page'.

This is either the value obtained from the postamble of the DVI file, if that was read, or else the maximum value of the horizontal position (as returned by currH()), if that is larger. If the postamble has not been read, then this is initialised to -1. Note that this isn't the same as the maximum value of currH, any more than 0 is the minimum, but if the origin is set `appropriately' (ie, at (1in,1in)), then everything should fit on. It's not a precise figure, but can be useful as a scale for initialising bitmap sizes, for example.

Returns
the horizontal size of the largest `page', in pixels

Referenced by main().

double DviFile::magnification ( ) const
inline

Return the net magnification factor for the DVI file.

Returns
the overall magnification factor applied to lengths in the DVI file. A value of 1.0 implies no magnification at all.

Referenced by main().

int DviFile::pt2px ( double  npt) const
inline

Converts a length in points to one in pixels, using the current magnifications and any other relevant parameters.

Parameters
npta length in points
Returns
the given length, in pixels
string DviFile::unitString ( DviFile::DviUnits  unit)
static

Gets the string representation of a DVI unit.

Parameters
unitthe unit in question
Returns
a string representing the unit

References MAP.

Referenced by main().

DviFile::DviUnits DviFile::unitType ( string  unitString)
static

Convert a string to a unit.

Parameters
unitStringone of the strings representing a DVI unit
Returns
the appropriate member of the DviUnits enum, or unit_BAD if the unit string is not recognised

References i, MAP, u, unit_BAD, unit_dvi, and unit_pixels.

Referenced by main().

verbosities DviFile::verbosity ( const verbosities  level)
static

Sets the verbosity of this module.

Parameters
levelthe required verbosity
Returns
the previous verbosity level

References DviFileEvent::verbosity().

Referenced by main().

int DviFile::vSize ( )

Obtains the `height plus depth of the tallest page'.

This is either the

value obtained from the postamble of the DVI file, if that was read, or else the maximum value of the vertical position (as returned by currV()), if that is larger. If the postamble has not been read, then this is initialised to -1. Note that this isn't the same as the maximum value of currV, any more than 0 is the minimum, but if the origin is set `appropriately' (ie, at (1in,1in)), then everything should fit on. It's not a precise figure, but can be useful as a scale for initialising bitmap sizes, for example.

Returns
the vertical size of the largest `page', in pixels

Referenced by main().

Member Data Documentation

string DviFile::comment
unsigned int DviFile::den
unsigned int DviFile::i

Referenced by getEvent(), and unitType().

unsigned int DviFile::l
unsigned int DviFile::mag
unsigned int DviFile::num
unsigned int DviFile::s
unsigned int DviFile::t
unsigned int DviFile::u

Referenced by unitType().


The documentation for this class was generated from the following files: