File indexing completed on 2024-05-12 16:06:37

0001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-
0002 // fontMap.h
0003 //
0004 // Part of KDVI - A DVI previewer for the KDE desktop environment
0005 //
0006 // SPDX-FileCopyrightText: 2003 Stefan Kebekus
0007 // SPDX-License-Identifier: GPL-2.0-or-later
0008 
0009 #ifndef _FONTMAP_H
0010 #define _FONTMAP_H
0011 
0012 #include <QMap>
0013 #include <QString>
0014 
0015 /**
0016  * This class represents one line of a font map file, and contains
0017  * three pieces of information about a font: its file name, the full
0018  * name of the font, and the encoding.
0019  *
0020  * @author Stefan Kebekus   <kebekus@kde.org>
0021  **/
0022 
0023 class fontMapEntry
0024 {
0025 public:
0026     // File name of the font WITHOUT the path. The full path name must
0027     // be looked by using the kpathsea library, e.g. by means of the
0028     // kpsewhich command. A valid entry would be 'ubkd8a.pfb'
0029     QString fontFileName;
0030 
0031     // This string contains the full name of the font,
0032     // e.g. 'URWBookmanL-DemiBold'
0033     QString fullFontName;
0034 
0035     // If the font requires an encoding (see fontEncoding.h for an
0036     // explanation), this string is not empty and contains the name of
0037     // the encoding, e.g. '8r'. The path of the associated encoding file
0038     // (on the author's machine: /usr/share/texmf/dvips/psnfss/8r.enc)
0039     // must be looked up using the kpsewhich command.
0040     QString fontEncoding;
0041 
0042     // Some fonts need to be slanted, and the font map file defines by
0043     // how much. This field is set to 0.0 if no slanting is specified in
0044     // the map file.
0045     double slant;
0046 };
0047 
0048 /**
0049  * This class represents the contents of the font map file "ps2pk.map"
0050  *
0051  * A font map file is part of the machinery that make it possible to
0052  * access PostScript (and possibly also TrueType and OpenType) fonts
0053  * from a DVI file.
0054  *
0055  * Long time ago, when TeX was only used with MetaFont fonts, the DVI
0056  * file would specify a font by giving an 8-character name, such as
0057  * 'cmr10'. The DVI previewer would then locate the associated PK font
0058  * file, load it, and retrieve the character shaped. Happy times, they
0059  * were.
0060  *
0061  * Today TeX is also used to access Type1 and TrueType fonts, which do
0062  * not fit well into the TeX naming scheme. Like in earlier times, the
0063  * DVI file specifies the name of a font, e.g. 'rpbkd', but nowadays
0064  * the DVI previewer cannot just go and find a file 'rpbkd.pk'. No,
0065  * no. Instead, the DVI previewr needs to look up the meaning of
0066  * 'rpbkd' in a map-file. There it finds that 'rpbkd' refers to a font
0067  * called 'URWBookmanL-DemiBold', to be found under the file name
0068  * 'ubkd8a.pfb' whose glyphs are to be encoded using the '8a' encoding
0069  * file (see the header file 'fontEncoding.h' for more information
0070  * about encodings)
0071  *
0072  * Such map files exists for all dvi output drivers that are part of
0073  * the TeX distribution that is installed on your
0074  * computer. Unfortunately, KDVI is not part of a TeX distribution,
0075  * and therefore does not have its own map file. As a workaround, KDVI
0076  * uses the map file of the program ps2pk which is similar to KDVI in
0077  * that the ps2pk driver does not have built-in fonts, unlike the
0078  * PostScript printers for which dvips is used.
0079  *
0080  * @author Stefan Kebekus   <kebekus@kde.org>
0081  *
0082  **/
0083 
0084 class fontMap
0085 {
0086 public:
0087     /** The default constructor will try to locate the file 'ps2pk.map',
0088         and read its contents. If the file 'ps2pk.map' cannot be found
0089         using the kpsewhich command, or if it cannot be read, or is
0090         (partially) in an improper format, an error message is printed
0091         to stderr using the kDebug() stream. */
0092     fontMap();
0093 
0094     /** find the name of a font file (e.g. 'ubkd8a.pfb') from a TeX font
0095         name (e.g. 'rpbkd'). This method return a reference to
0096         QString() if the font could not be found. */
0097     const QString &findFileName(const QString &TeXName);
0098 
0099     /** find the name of a font (e.g. 'URWBookmanL-DemiBold') from a TeX
0100         font name (e.g. 'rpbkd'). This method return a reference to
0101         QString() if the font could not be found. */
0102     const QString &findFontName(const QString &TeXName);
0103 
0104     /** find the name of an encoding file for a font (e.g. '8r') from a
0105         TeX font name (e.g. 'rpbkd'). This method return a reference to
0106         QString() if the font could not be found. */
0107     const QString &findEncoding(const QString &TeXName);
0108 
0109     /** This method finds the slant of a font. Returns 0.0 if no slant
0110         was defined. */
0111     double findSlant(const QString &TeXName);
0112 
0113 private:
0114     /** This member maps TeX font names mapEntry classes that contain
0115         the font's filenames, full font names and encodings. */
0116     QMap<QString, fontMapEntry> fontMapEntries;
0117 };
0118 
0119 #endif // ifndef _FONTMAP_H