00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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;
00183
static const int two16_ = 65536;
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];
00208 }
00209
static verbosities verbosity (
const verbosities level);
00210
00211
00212
static void setFontSearchPath(string fp);
00213
static void setFontSearchPath(
char *fp);
00214
static void setFontSearchPath(
bool yesno);
00215
00216
00217
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
00238
00239
00240
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
00318
00319
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;
00363
static const unsigned int two16_ = 65536;
00364
00365 string name_;
00366 string path_;
00367
FileByteStream *pkf_;
00368
bool font_loaded_;
00369
struct {
00370
unsigned int c;
00371
unsigned int s;
00372
unsigned int d;
00373 } font_header_;
00374
00375
double dvimag_;
00376
struct {
00377
unsigned int id, cs;
00378
double designSize, hppp, vppp;
00379 string comment;
00380 } preamble_;
00381
00382
00383
double quad_, word_space_, back_space_;
00384
PkGlyph *glyphs_[nglyphs_];
00385
bool find_font (string&);
00386
void read_font(
InputByteStream&);
00387
00388
00389
00390 string& search_pkpath (string path,
00391 string name,
double resolution);
00392
00393
bool seen_in_doc_;
00394
00395
00396
static verbosities verbosity_;
00397
static string fontSearchPath_;
00398
static string fontSearchCommandTemplate_;
00399
static string fontgenCommandTemplate_;
00400
static void setFontSearchStrategy_(
unsigned int,
bool);
00401
static unsigned int fontSearchStrategies_;
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_;
00407
static bool makeMissingFonts_;
00408
static string missingFontMode_;
00409 };
00410
00411
#endif // #ifndef PK_FONT_HEADER_READ
00412