Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

PkFont.h

Go to the documentation of this file.
00001 // This file is part of dvi2bitmap. 00002 // Copyright 1999--2002, Council for the Central Laboratory of the Research Councils 00003 // 00004 // This program is part of the Starlink Software Distribution: see 00005 // http://www.starlink.ac.uk 00006 // 00007 // dvi2bitmap is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 2 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // dvi2bitmap is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with dvi2bitmap; if not, write to the Free Software 00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 // 00021 // The General Public License is distributed along with this 00022 // program in the file LICENCE. 00023 // 00024 // Author: Norman Gray <norman@astro.gla.ac.uk> 00025 // $Id: PkFont.h,v 1.49 2003/10/03 13:26:13 norman Exp $ 00026 00027 00028 #ifndef PK_FONT_HEADER_READ 00029 #define PK_FONT_HEADER_READ 1 00030 00031 #include <config.h> 00032 00033 #include <string> 00034 // We only need to include <ostream> here, but <iostream> is on more machines 00035 #include <iostream> 00036 #include <FileByteStream.h> 00037 #include <Byte.h> 00038 #include <DviError.h> 00039 #include <verbosity.h> 00040 00041 class PkFont; 00042 00043 class PkError : public DviError { 00044 public: 00045 PkError(string s) : DviError(s) { } 00046 }; 00047 00048 class PkRasterdata { 00049 public: 00050 PkRasterdata(Byte opcode, 00051 const Byte *rasterdata, unsigned int len, 00052 unsigned int w, unsigned int h); 00058 const Byte *bitmap() 00059 { if (bitmap_ == 0) construct_bitmap(); return bitmap_; } 00065 static verbosities verbosity (const verbosities level) { 00066 enum verbosities oldv = verbosity_; 00067 verbosity_ = level; 00068 return oldv; 00069 } 00070 private: 00071 Byte *rasterdata_, *eob_; 00072 const unsigned int len_, w_, h_; 00073 Byte dyn_f_; 00074 bool start_black_; 00075 Byte *bitmap_; 00076 bool highnybble_; 00077 unsigned int repeatcount_; 00078 unsigned int unpackpk(); 00079 Byte nybble(); 00080 void construct_bitmap (); 00081 static verbosities verbosity_; 00082 }; 00083 00084 class PkGlyph { 00085 public: 00086 PkGlyph(unsigned int cc, 00087 unsigned int tfmwidth, unsigned int dm, 00088 unsigned int w, unsigned int h, 00089 int hoff, int voff, 00090 PkRasterdata *rasterdata, PkFont *f); 00091 PkGlyph(unsigned int cc, 00092 unsigned int tfmwidth, unsigned int dx, unsigned int dy, 00093 unsigned int w, unsigned int h, 00094 int hoff, int voff, 00095 PkRasterdata *rasterdata, PkFont *f); 00096 PkGlyph(int resolution, PkFont *f); 00100 inline unsigned int characterCode() const { return cc_; } 00106 inline char characterChar() const 00107 { return (cc_ >= ' ' && cc_ < 127 00108 ? static_cast<char>(cc_) : '?'); } 00109 00110 const Byte *bitmap(); 00116 inline unsigned int w() const { return w_; } 00122 inline unsigned int h() const { return h_; } 00133 inline int hoff() const { return -hoff_; } 00146 inline int voff() const { return -voff_; } 00151 double tfmWidth() const { return tfmwidth_; } 00156 int hEscapement() const { return dx_; } 00161 int vEscapement() const { return dy_; } 00167 static verbosities verbosity (const verbosities level) { 00168 enum verbosities oldv = verbosity_; 00169 verbosity_ = level; 00170 return oldv; 00171 } 00172 00173 private: 00174 unsigned int cc_, dx_, dy_, w_, h_; 00175 double tfmwidth_; 00176 int hoff_, voff_; 00177 PkFont *font_; 00178 PkRasterdata *rasterdata_; 00179 bool longform_; 00180 const Byte *bitmap_; 00181 static verbosities verbosity_; 00182 static const int two20_ = 1048576; // 2^20 00183 static const int two16_ = 65536; // 2^16 00184 }; 00185 00186 class PkFont { 00187 public: 00188 PkFont (double fontmag, 00189 unsigned int c, 00190 unsigned int s, 00191 unsigned int d, 00192 string name); 00193 ~PkFont(); 00199 PkGlyph *glyph (unsigned int i) const { 00200 if (font_loaded_) 00201 { 00202 if (i > nglyphs_) 00203 throw DviBug ("requested out-of-range glyph"); 00204 return glyphs_[i]; 00205 } 00206 else 00207 return glyphs_[0]; // dummy glyph 00208 } 00209 static verbosities verbosity (const verbosities level); 00210 // setFontPath: specify path to search for fonts. If argument is 00211 // null or zero length, simple enable this. 00212 static void setFontSearchPath(string fp); 00213 static void setFontSearchPath(char *fp); 00214 static void setFontSearchPath(bool yesno); 00215 // setFontSearchCommand: set the command to use to search for 00216 // fonts. If argument is null or zero length, simply enable this, 00217 // using the compiled-in default. 00218 static void setFontSearchCommand(string cmd); 00219 static void setFontSearchCommand(char* cmd); 00220 static void setFontSearchCommand(bool yesno); 00221 static void setFontSearchKpse(bool yesno); 00229 static void setResolution(int res) { resolution_ = res; } 00236 static void setMissingFontMode(string mode) { missingFontMode_ = mode; } 00237 // Ought I to rationalise setMakeFonts, so that this looks more 00238 // like the interface of setFontSearchCommand()? Not really, 00239 // since it's possible in principle that there could be more than 00240 // just this command-based way of making fonts. 00241 static void setFontgen(bool doit); 00242 static void setFontgenCommand(string command_template); 00243 string fontgenCommand() const; 00248 string name() const { return name_; } 00253 string fontFilename() const { return path_; } 00254 double magnification(bool includeDviMag=true) const; 00263 static int dpiBase() { return resolution_; } 00269 int dpiScaled() const { 00270 return static_cast<int>(resolution_ 00271 * magnification() 00272 + 0.5); 00273 } 00286 double scale() const { 00287 return (double)font_header_.s / (double)font_header_.d; 00288 } 00295 bool seenInDoc(void) const { return seen_in_doc_; } 00296 void setSeenInDoc(void) { seen_in_doc_ = true; } 00297 00303 double wordSpace() const { return word_space_; } 00309 double backSpace() const { return back_space_; } 00315 double quad() const { return quad_; } 00316 00317 // No need to check font_loaded_ in these next three, since these 00318 // are never called between the font being created and preamble_ 00319 // being filled in. 00325 double designSize() const { return preamble_.designSize; } 00331 double hppp() const { return preamble_.hppp; } 00337 double vppp() const { return preamble_.vppp; } 00342 unsigned int checksum() const { return preamble_.cs; } 00349 bool loaded() const { return font_loaded_; } 00350 00351 static string& substitute_font_string (const string fmt, 00352 const string mode, 00353 const string fontname, 00354 const int dpi, 00355 const int basedpi, 00356 const double magnification) 00357 throw (PkError); 00358 00359 00360 private: 00361 static const unsigned int nglyphs_ = 256; 00362 static const unsigned int two20_ = 1048576; // 2^20 00363 static const unsigned int two16_ = 65536; // 2^16 00364 00365 string name_; 00366 string path_; /* name of (tbd) file containing font */ 00367 FileByteStream *pkf_; 00368 bool font_loaded_; /* font loaded successfully */ 00369 struct { 00370 unsigned int c; /* font checksum */ 00371 unsigned int s; /* fixed-point scale factor, in DVI units */ 00372 unsigned int d; /* `design size', in DVI units */ 00373 } font_header_; /* this is the information retrieved 00374 from the font declaration */ 00375 double dvimag_; /* Magnification imposed by DVI file (1.0 = no mag) */ 00376 struct { 00377 unsigned int id, cs; 00378 double designSize, hppp, vppp; 00379 string comment; 00380 } preamble_; 00381 //double fontscale_; 00382 // following are in DVI units 00383 double quad_, word_space_, back_space_; 00384 PkGlyph *glyphs_[nglyphs_]; 00385 bool find_font (string&); 00386 void read_font(InputByteStream&); 00387 00388 /* Search the given path for a font. Not static, so that it can 00389 see the current font's parameters. */ 00390 string& search_pkpath (string path, 00391 string name, double resolution); 00392 00393 bool seen_in_doc_; // true once the font_def command has been 00394 // seen in the document, as well as the 00395 // postamble 00396 static verbosities verbosity_; 00397 static string fontSearchPath_; // colon-separated list of directories 00398 static string fontSearchCommandTemplate_; // command to find fonts 00399 static string fontgenCommandTemplate_; // command to generate fonts 00400 static void setFontSearchStrategy_(unsigned int, bool); 00401 static unsigned int fontSearchStrategies_; // ways to find fonts: flags: 00402 static const unsigned int fontSearchStrategyPath_ = 1; 00403 static const unsigned int fontSearchStrategyKpse_ = 2; 00404 static const unsigned int fontSearchStrategyCommand_ = 4; 00405 00406 static int resolution_; // base resolution for MF mode 00407 static bool makeMissingFonts_; // automatically make fonts 00408 static string missingFontMode_; 00409 }; 00410 00411 #endif // #ifndef PK_FONT_HEADER_READ 00412

Generated on Sun Aug 21 18:21:02 2005 for dvi2bitmap by doxygen 1.3.8