File indexing completed on 2024-05-12 04:34:00

0001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-
0002 /*
0003  * The layout of a font information block.
0004  * There is one of these for every loaded font or magnification thereof.
0005  * Duplicates are eliminated:  this is necessary because of possible recursion
0006  * in virtual fonts.
0007  *
0008  * Also note the strange units.  The design size is in 1/2^20 point
0009  * units (also called micro-points), and the individual character widths
0010  * are in the TFM file in 1/2^20 ems units, i.e., relative to the design size.
0011  *
0012  * We then change the sizes to SPELL units (unshrunk pixel / 2^16).
0013  */
0014 
0015 #ifndef _FONT_H
0016 #define _FONT_H
0017 
0018 #include <QHash>
0019 #include <QString>
0020 
0021 class dviRenderer;
0022 class TeXFont;
0023 
0024 typedef void (dviRenderer::*set_char_proc)(unsigned int, unsigned int);
0025 
0026 // Per character information for virtual fonts
0027 
0028 class macro
0029 {
0030 public:
0031     macro();
0032     ~macro();
0033 
0034     macro(const macro &) = delete;
0035     macro &operator=(const macro &) = delete;
0036 
0037     // address of first byte of macro
0038     unsigned char *pos;
0039     // address of last+1 byte
0040     unsigned char *end;
0041     // DVI units to move reference point
0042     qint32 dvi_advance_in_units_of_design_size_by_2e20;
0043     // if memory at pos should be returned on destruction
0044     bool free_me;
0045 };
0046 
0047 class TeXFontDefinition
0048 {
0049 public:
0050     // Currently, kdvi supports fonts with at most 256 characters to
0051     // comply with "The DVI Driver Standard, Level 0". If you change
0052     // this value here, make sure to go through all the source and
0053     // ensure that character numbers are stored in ints rather than
0054     // unsigned chars.
0055     static const unsigned int max_num_of_chars_in_font = 256;
0056     enum font_flags {
0057         // used for housekeeping
0058         FONT_IN_USE = 1,
0059         // if font file has been read
0060         FONT_LOADED = 2,
0061         // if font is virtual
0062         FONT_VIRTUAL = 4,
0063         // if kpathsea has already tried to find the font name
0064         FONT_KPSE_NAME = 8
0065     };
0066 
0067     enum font_type { TEX_PK, TEX_VIRTUAL, TEX_FONTMETRIC, FREETYPE };
0068 
0069     TeXFontDefinition(const QString &nfontname, double _displayResolution_in_dpi, quint32 chk, qint32 _scaled_size_in_DVI_units, class fontPool *pool, double _enlargement);
0070     ~TeXFontDefinition();
0071 
0072     TeXFontDefinition(const TeXFontDefinition &) = delete;
0073     TeXFontDefinition &operator=(const TeXFontDefinition &) = delete;
0074 
0075     void reset();
0076     void fontNameReceiver(const QString &);
0077 
0078     // Members for character fonts
0079     void setDisplayResolution(double _displayResolution_in_dpi);
0080 
0081     bool isLocated() const
0082     {
0083         return ((flags & FONT_KPSE_NAME) != 0);
0084     }
0085     void markAsLocated()
0086     {
0087         flags |= FONT_KPSE_NAME;
0088     }
0089 
0090     void mark_as_used();
0091     // Pointer to the pool that contains this font.
0092     class fontPool *font_pool;
0093     // name of font, such as "cmr10"
0094     QString fontname;
0095     // flags byte (see values below)
0096     unsigned char flags;
0097     double enlargement;
0098     // Scaled size from the font definition command; in DVI units
0099     qint32 scaled_size_in_DVI_units;
0100     // proc used to set char
0101     set_char_proc set_char_p;
0102 
0103     // Resolution of the display device (resolution will usually be
0104     // scaled, according to the zoom)
0105     double displayResolution_in_dpi;
0106 
0107     // open font file or NULL
0108     FILE *file;
0109     // name of font file
0110     QString filename;
0111 
0112     TeXFont *font;
0113     // used by (loaded) virtual fonts
0114     macro *macrotable;
0115     // used by (loaded) virtual fonts, list of fonts used by this vf,
0116     QHash<int, TeXFontDefinition *> vf_table;
0117     // accessible by number
0118     // used by (loaded) virtual fonts, list of fonts used by this vf
0119     TeXFontDefinition *first_font;
0120 
0121 #ifdef HAVE_FREETYPE
0122     const QString &getFullFontName() const
0123     {
0124         return fullFontName;
0125     }
0126     const QString &getFullEncodingName() const
0127     {
0128         return fullEncodingName;
0129     }
0130 #endif
0131 
0132     const font_type &getFontType() const
0133     {
0134         return fontType;
0135     };
0136 
0137 #ifdef HAVE_FREETYPE
0138     /** For FREETYPE fonts, which use a map file, this field will
0139         contain the full name of the font (e.g. 'Computer Modern'). If
0140         the name does not exist, or cannot be found, this field will be
0141         QString(). Only subclasses of TeXFont should write into this
0142         field. */
0143     QString fullFontName;
0144 
0145     /** For FREETYPE fonts, which use a map file, this field will
0146         contain the full name of the font encoding (e.g. 'TexBase1'). If
0147         the encoding name does not exist, or cannot be found, this field
0148         will be QString(). Only subclasses of TeXFont should write
0149         into this field. */
0150     QString fullEncodingName;
0151 #endif
0152 
0153 private:
0154     quint32 checksum;
0155 
0156     font_type fontType;
0157 
0158     // Functions related to virtual fonts
0159     void read_VF_index();
0160 };
0161 
0162 #endif