File indexing completed on 2024-05-12 04:33:57

0001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-
0002 // fontEncoding.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 _FONTENCODING_H
0010 #define _FONTENCODING_H
0011 
0012 #include <QString>
0013 
0014 /**
0015  * This class represents the contents of a font encoding file,
0016  * e.g. "8r.enc"
0017  *
0018  * Explanation of font encodings: TeX was designed to only use
0019  * MetaFont fonts. A DVI file refers to a MetaFont font by giving an
0020  * at-most-8-character name, such as 'cmr10'. The DVI previewer would
0021  * then locate the associated PK font file (e.g. cmr10.600pk), load
0022  * it, and retrieve the character shaped.
0023  *
0024  * Today TeX is also used to access Type1 and TrueType fonts, which it
0025  * was never designed to do. As in the case of MetaFont font, the DVI
0026  * file specifies the name of a font, e.g. 'rpbkd', and the DVI
0027  * previewer finds the associated font file 'ubkd8a.pfb' by means of a
0028  * map file (see fontMap.h). The font map file also specifies an
0029  * encoding (e.g. '8r', to be found in a file '8r.enc'). Font
0030  * encodings are necessary because TeX can only use the first 256
0031  * characters of a font, while modern PostScript fonts often contain
0032  * more.
0033  *
0034  * In a PostScript font, glyphs can often be accessed in two ways:
0035  *
0036  * (a) by an integer, the 'glyph index', which need not be
0037  * positive. Glyph indices can be found in every font.
0038  *
0039  * (b) by the name of the glyph, such as 'A', 'plusminus' or
0040  * 'ogonek'. Note: Not all fonts contain glyph names, and if a font
0041  * contains glyph names, they are not always reliable.
0042  *
0043  * An encoding file is essentially a list of 256 names of glyphs that
0044  * TeX wishes to use from a certain font. If the font contains more
0045  * than 256 glyphs, TeX is still limited to use at most 256 glyphs. If
0046  * more glyphs are required, TeX can probably use the same font under
0047  * a different name and with a different encoding ---the map file
0048  * (fontMap.h) can probably see to that.
0049  *
0050  * Summing up: this class contains 256 glyph names read from an
0051  * encoding file during the construction of this class.
0052  *
0053  * @author Stefan Kebekus   <kebekus@kde.org>
0054  *
0055  **/
0056 
0057 class fontEncoding
0058 {
0059 public:
0060     // The constructor takes the name of an encoding file, such as
0061     // '8r.enc', locate the file on the hard disk using the 'kpsewhich'
0062     // command, reads it in and parses it. If the file cannot be
0063     // located, opened or parsed, errors are printed using the kError()
0064     // channel, and the array glyphNameVector will contain empty
0065     // strings.
0066     explicit fontEncoding(const QString &encName);
0067 
0068     // Full name of the encoding, as read from the encoding file
0069     QString encodingFullName;
0070 
0071     // List of 256 glyph names. The name can be '.notdef' to indicate
0072     // that a certain position is left open, or empty, if the encoding
0073     // file did not contain 256 characters or could not be properly read
0074     QString glyphNameVector[256];
0075 
0076     // Returns 'true' if the encoding file was found and could
0077     // successfully be loaded.
0078     bool isValid()
0079     {
0080         return _isValid;
0081     }
0082 
0083 private:
0084     // Set by the constructor to 'true', if the encoding file was found
0085     // and could be loaded successfully.
0086     bool _isValid;
0087 };
0088 
0089 #endif