The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

dvi2bitmap  dvi2bitmap1.0
PkFont.h
Go to the documentation of this file.
1 /* This file is part of dvi2bitmap; see README for copyrights and licence */
2 
3 #ifndef PK_FONT_HEADER_READ
4 #define PK_FONT_HEADER_READ 1
5 
6 #include <config.h>
7 
8 #include <string>
9 // We only need to include <ostream> here, but <iostream> is on more machines
10 #include <iostream>
11 #include <FileByteStream.h>
12 #include <Byte.h>
13 #include <DviError.h>
14 #include <verbosity.h>
15 
17 class PkFont;
18 
19 class PkError : public DviError {
20  public:
21  PkError(string s) : DviError(s) { }
22 };
23 
24 class PkRasterdata {
25  public:
26  PkRasterdata(Byte opcode,
27  const Byte *rasterdata, unsigned int len,
28  unsigned int w, unsigned int h);
34  const Byte *bitmap()
35  { if (bitmap_ == 0) construct_bitmap(); return bitmap_; }
41  static verbosities verbosity (const verbosities level) {
42  enum verbosities oldv = verbosity_;
43  verbosity_ = level;
44  return oldv;
45  }
46  private:
47  Byte *rasterdata_, *eob_;
48  const unsigned int len_, w_, h_;
49  Byte dyn_f_;
50  bool start_black_;
51  Byte *bitmap_;
52  bool highnybble_;
53  unsigned int repeatcount_;
54  unsigned int unpackpk();
55  Byte nybble();
56  void construct_bitmap ();
57  static verbosities verbosity_;
58 };
59 
60 class PkGlyph {
61  public:
62  PkGlyph(unsigned int cc,
63  unsigned int tfmwidth, unsigned int dm,
64  unsigned int w, unsigned int h,
65  int hoff, int voff,
66  PkRasterdata *rasterdata, PkFont *f);
67  PkGlyph(unsigned int cc,
68  unsigned int tfmwidth, unsigned int dx, unsigned int dy,
69  unsigned int w, unsigned int h,
70  int hoff, int voff,
71  PkRasterdata *rasterdata, PkFont *f);
72  PkGlyph(int resolution, PkFont *f);
76  inline unsigned int characterCode() const { return cc_; }
82  inline char characterChar() const
83  { return (cc_ >= ' ' && cc_ < 127
84  ? static_cast<char>(cc_) : '?'); }
85 
86  const Byte *bitmap();
92  inline unsigned int w() const { return w_; }
98  inline unsigned int h() const { return h_; }
109  inline int hoff() const { return -hoff_; }
122  inline int voff() const { return -voff_; }
127  double tfmWidth() const { return tfmwidth_; }
132  int hEscapement() const { return dx_; }
137  int vEscapement() const { return dy_; }
143  static verbosities verbosity (const verbosities level) {
144  enum verbosities oldv = verbosity_;
145  verbosity_ = level;
146  return oldv;
147  }
148 
149  private:
150  unsigned int cc_, dx_, dy_, w_, h_;
151  double tfmwidth_;
152  int hoff_, voff_;
153  PkFont *font_;
154  PkRasterdata *rasterdata_;
155  bool longform_;
156  const Byte *bitmap_;
157  static verbosities verbosity_;
158  static const int two20_ = 1048576; // 2^20
159  static const int two16_ = 65536; // 2^16
160 };
161 
162 class PkFont {
163  public:
164  PkFont (double fontmag,
165  unsigned int c,
166  unsigned int s,
167  unsigned int d,
168  string name);
169  ~PkFont();
175  PkGlyph *glyph (unsigned int i) const {
176  if (font_loaded_)
177  {
178  if (i > nglyphs_)
179  throw DviBug ("requested out-of-range glyph");
180  return glyphs_[i];
181  }
182  else
183  return glyphs_[0]; // dummy glyph
184  }
185  static verbosities verbosity (const verbosities level);
186  // setFontPath: specify path to search for fonts. If argument is
187  // null or zero length, simple enable this.
188  static void setFontSearchPath(string fp);
189  static void setFontSearchPath(char *fp);
190  static void setFontSearchPath(bool yesno);
191  // setFontSearchCommand: set the command to use to search for
192  // fonts. If argument is null or zero length, simply enable this,
193  // using the compiled-in default.
194  static void setFontSearchCommand(string cmd);
195  static void setFontSearchCommand(char* cmd);
196  static void setFontSearchCommand(bool yesno);
197  static void setFontSearchKpse(bool yesno);
205  static void setResolution(int res) { resolution_ = res; }
212  static void setMissingFontMode(string mode) { missingFontMode_ = mode; }
213  // Ought I to rationalise setMakeFonts, so that this looks more
214  // like the interface of setFontSearchCommand()? Not really,
215  // since it's possible in principle that there could be more than
216  // just this command-based way of making fonts.
217  static void setFontgen(bool doit);
218  static void setFontgenCommand(string command_template);
219  string fontgenCommand() const;
224  string name() const { return name_; }
229  string fontFilename() const { return path_; }
230  double magnification(bool includeDviMag=true) const;
239  static int dpiBase() { return resolution_; }
245  int dpiScaled() const {
246  return static_cast<int>(resolution_
247  * magnification()
248  + 0.5);
249  }
262  double scale() const {
263  return (double)font_header_.s / (double)font_header_.d;
264  }
271  bool seenInDoc(void) const { return seen_in_doc_; }
272  void setSeenInDoc(void) { seen_in_doc_ = true; }
273 
279  double wordSpace() const { return word_space_; }
285  double backSpace() const { return back_space_; }
291  double quad() const { return quad_; }
292 
293  // No need to check font_loaded_ in these next three, since these
294  // are never called between the font being created and preamble_
295  // being filled in.
301  double designSize() const { return preamble_.designSize; }
307  double hppp() const { return preamble_.hppp; }
313  double vppp() const { return preamble_.vppp; }
318  unsigned int checksum() const { return preamble_.cs; }
325  bool loaded() const { return font_loaded_; }
326 
327  static string& substitute_font_string (const string fmt,
328  const string mode,
329  const string fontname,
330  const int dpi,
331  const int basedpi,
332  const double magnification)
333  throw (PkError);
334 
335 
336  private:
337  static const unsigned int nglyphs_ = 256;
338  static const unsigned int two20_ = 1048576; // 2^20
339  static const unsigned int two16_ = 65536; // 2^16
340 
341  string name_;
342  string path_; /* name of (tbd) file containing font */
343  FileByteStream *pkf_;
344  bool font_loaded_; /* font loaded successfully */
345  struct {
346  unsigned int c; /* font checksum */
347  unsigned int s; /* fixed-point scale factor, in DVI units */
348  unsigned int d; /* `design size', in DVI units */
349  } font_header_; /* this is the information retrieved
350  from the font declaration */
351  double dvimag_; /* Magnification imposed by DVI file (1.0 = no mag) */
352  struct {
353  unsigned int id, cs;
354  double designSize, hppp, vppp;
355  string comment;
356  } preamble_;
357  //double fontscale_;
358  // following are in DVI units
359  double quad_, word_space_, back_space_;
360  PkGlyph *glyphs_[nglyphs_];
361  bool find_font (string&);
362  void read_font(InputByteStream&);
363 
364  /* Search the given path for a font. Not static, so that it can
365  see the current font's parameters. */
366  string& search_pkpath (string path,
367  string name, double resolution);
368 
369  bool seen_in_doc_; // true once the font_def command has been
370  // seen in the document, as well as the
371  // postamble
372  static verbosities verbosity_;
373  static string fontSearchPath_; // colon-separated list of directories
374  static string fontSearchCommandTemplate_; // command to find fonts
375  static string fontgenCommandTemplate_; // command to generate fonts
376  static void setFontSearchStrategy_(unsigned int, bool);
377  static unsigned int fontSearchStrategies_; // ways to find fonts: flags:
378  static const unsigned int fontSearchStrategyPath_ = 1;
379  static const unsigned int fontSearchStrategyKpse_ = 2;
380  static const unsigned int fontSearchStrategyCommand_ = 4;
381 
382  static int resolution_; // base resolution for MF mode
383  static bool makeMissingFonts_; // automatically make fonts
384  static string missingFontMode_;
385 };
386 
387 #endif // #ifndef PK_FONT_HEADER_READ
388 

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.