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 // fontpool.h 0003 // 0004 // SPDX-FileCopyrightText: 2001-2004 Stefan Kebekus 0005 // SPDX-License-Identifier: GPL-2.0-or-later 0006 0007 #ifndef _FONTPOOL_H 0008 #define _FONTPOOL_H 0009 0010 #include "TeXFontDefinition.h" 0011 #include "fontEncodingPool.h" 0012 #include "fontMap.h" 0013 0014 #include <QList> 0015 #include <QObject> 0016 #include <QProcess> 0017 0018 #ifdef HAVE_FREETYPE 0019 #include <ft2build.h> 0020 #include FT_FREETYPE_H 0021 #endif 0022 0023 /** 0024 * A list of fonts and a compilation of utility functions 0025 * 0026 * This class holds a list of fonts and is able to perform a number of 0027 * functions on each of the fonts. The main use of this class is that 0028 * it is able to control a concurrently running "kpsewhich" program 0029 * which is used to locate and load the fonts. 0030 * 0031 * @author Stefan Kebekus <kebekus@kde.org> 0032 * 0033 **/ 0034 0035 class fontPool : public QObject 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 // Default constructor. 0041 explicit fontPool(bool useFontHinting); 0042 0043 // Default destructor. 0044 ~fontPool() override; 0045 0046 /** Method used to set the MetafontMode for the PK font files. This 0047 data is used when loading fonts. Currently, a change here will be 0048 applied only to those font which were not yet loaded ---expect 0049 funny results when changing the data in the mid-work. */ 0050 void setParameters(bool useFontHints); 0051 0052 /** Sets the DVI file's path. This information is used to set the 0053 current working directory for the kpsewhich command, so that 0054 kpsewhich will find fonts that are stored in the DVI file's 0055 directory. */ 0056 void setExtraSearchPath(const QString &path) 0057 { 0058 extraSearchPath = path; 0059 } 0060 0061 /** Returns the path that is set as the current working directory 0062 for the kpsewhich command, so that kpsewhich will find fonts 0063 that are stored in the DVI file's directory. */ 0064 QString getExtraSearchPath() const 0065 { 0066 return extraSearchPath; 0067 } 0068 0069 /** Sets the resolution of the output device. */ 0070 void setDisplayResolution(double _displayResolution_in_dpi); 0071 0072 /** Sets the number of centimeters per DVI unit. */ 0073 void setCMperDVIunit(double CMperDVI); 0074 double getCMperDVIunit() const 0075 { 0076 return CMperDVIunit; 0077 } 0078 0079 // If return value is true, font hinting should be used if possible 0080 bool getUseFontHints() const 0081 { 0082 return useFontHints; 0083 } 0084 0085 // This method adds a font to the list. If the font is not currently 0086 // loaded, it's file will be located and font::load_font will be 0087 // called. Since this is done using a concurrently running process, 0088 // there is no guarantee that the loading is already performed when 0089 // the method returns. 0090 TeXFontDefinition *appendx(const QString &fontname, quint32 checksum, quint32 scale, double enlargement); 0091 0092 // This is the list which actually holds pointers to the fonts 0093 QList<TeXFontDefinition *> fontList; 0094 0095 // This method marks all fonts in the fontpool as "not in use". The 0096 // fonts are, however, not removed from memory until the method 0097 // release_fonts is called. The method is called when the dvi-file 0098 // is closed. Because the next dvi-file which will be loaded is 0099 // likely to use most of the fonts again, this method implements a 0100 // convenient way of re-using fonts without loading them repeatedly. 0101 void mark_fonts_as_unused(); 0102 0103 /** This methods removes all fonts from the fontpool (and thus from 0104 memory) which are labeled "not in use". For explanation, see the 0105 mark_fonts_as_unused method. */ 0106 void release_fonts(); 0107 0108 #ifdef HAVE_FREETYPE 0109 /** A handle to the FreeType library, which is used by TeXFont_PFM 0110 font objects, if KDVI is compiled with FreeType support. */ 0111 FT_Library FreeType_library; 0112 0113 /** Simple marker. Set to 'true', if the FreeType library was loaded 0114 successfully */ 0115 bool FreeType_could_be_loaded; 0116 0117 /** This maps TeX font names to font file names, full font names and 0118 encodings. See the file 'fontMap.h' for a detailed 0119 description. */ 0120 fontMap fontsByTeXName; 0121 0122 /** This is a list of known font encodings which can be conveniently 0123 accessed by name. */ 0124 fontEncodingPool encodingPool; 0125 #endif 0126 0127 /** This flag is set during the construction of the fontPool 0128 object. It indicates if the QT library supports the alpha 0129 channel of pixmaps. Experiments show that --depending of the 0130 configuration of QT at compile and runtime or the availability 0131 of the XFt extension, alpha channels are either supported, or 0132 silently converted to 1-bit masks. The rendering routines in the 0133 TeXFont implementation use this flag to choose the appropriated 0134 drawing routines for the different setups. */ 0135 bool QPixmapSupportsAlpha; 0136 0137 Q_SIGNALS: 0138 /** Passed through to the top-level kpart. */ 0139 void error(const QString &message, int duration); 0140 void warning(const QString &message, int duration); 0141 void notice(const QString &message, int duration); 0142 0143 public Q_SLOTS: 0144 // Locates font files on the disk using the kpsewhich program. If 0145 // 'locateTFMonly' is true, the method does not look for PFB- or 0146 // PK-fonts. Instead, only TFM-files are searched. This option can be 0147 // used as a 'last resort': if a found cannot be found, one can at 0148 // least use the TFM file to draw filled rectangles for the 0149 // characters. If not null, the bool pointed at by virtualFontsFound 0150 // is set to true if one of the fonts found is a virtual font. If no 0151 // virtual font is found, the variable remains untouched. 0152 void locateFonts(); 0153 0154 private: 0155 // This method goes through the list of fonts, and marks each of them 0156 // as 'located'. Used, e.g. after a fatal error in the font lookup 0157 // process to ensure that the problematic kpsewhich is not used again 0158 void markFontsAsLocated(); 0159 0160 // Checks if all the fonts file names have been located, and returns 0161 // true if that is so. 0162 bool areFontsLocated(); 0163 0164 // This flag is used by PFB fonts to determine if the FREETYPE engine 0165 // should use hinted fonts or not 0166 bool useFontHints; 0167 0168 // Resolution of the output device. 0169 double displayResolution_in_dpi; 0170 0171 // Number of centimeters per DVI unit 0172 double CMperDVIunit; 0173 0174 /** Members used for font location */ 0175 0176 // Locates font files on the disk using the kpsewhich program. If 0177 // 'locateTFMonly' is true, the method does not look for PFB- or 0178 // PK-fonts. Instead, only TFM-files are searched. This option can be 0179 // used as a 'last resort': if a found cannot be found, one can at 0180 // least use the TFM file to draw filled rectangles for the 0181 // characters. If not null, the bool pointed at by virtualFontsFound 0182 // is set to true if one of the fonts found is a virtual font. If no 0183 // virtual font is found, the variable remains untouched. 0184 void locateFonts(bool makePK, bool locateTFMonly, bool *virtualFontsFound = nullptr); 0185 0186 // This QString is used internally by the mf_output_receiver() 0187 // method. This string is set to QString() in locateFonts(bool, 0188 // bool, bool *). Values are set and read by the 0189 // mf_output_receiver(...) method 0190 QString MetafontOutput; 0191 0192 // This QString is used to collect the output of kpsewhich and 0193 // MetaFont. The string is set to QString() in the 0194 // locateFonts()-method, and content is gathered by the 0195 // mf_output_receiver(). This string is used by locateFonts() and 0196 // locateFonts(bool, bool, bool *) to display error messages. 0197 QString kpsewhichOutput; 0198 0199 // This string is set to the DVI file's path. It is used to set the 0200 // current working directory for the kpsewhich command, so that 0201 // kpsewhich will find fonts that are stored in the DVI file's 0202 // directory. Used by the locateFonts() and the locateFonts(bool, 0203 // bool, bool *) method. Values are set by the 0204 // setExtraSearchPath(...) method 0205 QString extraSearchPath; 0206 0207 // The handle on the external process. 0208 std::unique_ptr<QProcess> kpsewhich_; 0209 0210 private Q_SLOTS: 0211 // This slot is called when MetaFont is run via the kpsewhich program. 0212 // The MetaFont output is transmitted to the fontpool via the @c kpsewhich_ 0213 // member variable. This method passes on progress information to the 0214 // fontProgress Dialog and collects the output of MetaFont in the 0215 // @c MetafontOutput member variable. 0216 void mf_output_receiver(); 0217 }; 0218 0219 #endif // ifndef _FONTPOOL_H