further cleanup

svn path=/trunk/kdegraphics/kdvi/; revision=50834
This commit is contained in:
Stefan Kebekus 2000-05-27 05:05:03 +00:00
parent 9ae8f959de
commit a387bfaad7
12 changed files with 533 additions and 966 deletions

View file

@ -19,7 +19,7 @@ libkdvi_la_SOURCES = kdvi_multipage.cpp \
printData.cpp printSetup.cpp printSetupData.cpp\
optiondialog.cpp \
psheader.c dviwin_draw.cpp dvi_init.cpp\
font.cpp gf.cpp pk.cpp psgs.cpp\
font.cpp pk.cpp psgs.cpp\
special.cpp util.cpp vf.cpp glyph.cpp
libkdvi_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN)

7
TODO
View file

@ -3,6 +3,8 @@ TODO:
URGENT:
- Release unsued fonts after reloading a file.
- Update Manual.
- Useful Zooms
@ -26,8 +28,3 @@ NOT SO URGENT:
- Hyperlinks to click on
- Search option
- SOURCE CLEANUP
Anything else? Feel free to make suggestions and report any problems you have.
Markku Hihnala
mah@ee.oulu.fi

View file

@ -70,7 +70,7 @@ extern "C" {
#include "oconfig.h"
extern char *xmalloc (unsigned, _Xconst char *);
extern FILE *font_open (char *font, char **font_ret, double dpi, int *dpi_ret, int dummy, char **filename_ret);
#define PK_PRE 247
#define PK_ID 89
@ -108,14 +108,13 @@ extern void reset_fonts(void)
{
kDebugInfo(DEBUG, 4300, "Reset Fonts");
register struct font *f;
register struct glyph *g;
struct font *f;
struct glyph *g;
for (f = font_head; f != NULL; f = f->next)
if ((f->flags & FONT_LOADED) && !(f->flags & FONT_VIRTUAL))
for (g = f->glyph; g <= f->glyph + f->fmaxchar; ++g) {
if ((f->flags & font::FONT_LOADED) && !(f->flags & font::FONT_VIRTUAL))
for (g = f->glyphtable; g < f->glyphtable + font::max_num_of_chars_in_font; ++g)
g->clearShrunkCharacter();
}
}
@ -216,7 +215,7 @@ font *define_font(FILE *file, unsigned int cmnd, font *vfparent, QIntDict<struct
// Insert font in dictionary and make sure the dictionary is big
// enough
if (TeXNumberTable->size() >= TeXNumberTable->count()-2)
if (TeXNumberTable->size()-2 <= TeXNumberTable->count())
// Not quite optimal. The size of the dict. should be a prime. I
// don't care
TeXNumberTable->resize(TeXNumberTable->size()*2);
@ -332,7 +331,7 @@ static void read_postamble()
// free up fonts no longer in use
fontpp = &font_head;
while ((fontp = *fontpp) != NULL)
if (fontp->flags & FONT_IN_USE) // Question: Is this ever false?
if (fontp->flags & font::FONT_IN_USE) // Question: Is this ever false?
fontpp = &fontp->next;
else
delete fontp;

View file

@ -206,46 +206,24 @@ static void xskip(long offset)
(void) lseek(fileno(dvi_file), (long) (currinf.pos - currinf.end), SEEK_CUR);
}
#if NeedVarargsPrototypes
static NORETURN void tell_oops(_Xconst char *message, ...)
#else
/* VARARGS */
static NORETURN void tell_oops(va_alist)
va_dcl
#endif
{
#if !NeedVarargsPrototypes
_Xconst char *message;
#endif
va_list args;
kDebugError("%s: ", prog);
#if NeedVarargsPrototypes
va_start(args, message);
#else
va_start(args);
message = va_arg(args, _Xconst char *);
#endif
(void) vfprintf(stderr, message, args);
va_end(args);
if (currinf._virtual)
kDebugError(" in virtual font %s", currinf._virtual->fontname);
kDebugError(" in virtual font %s", currinf._virtual->fontname);
else
kDebugError(", offset %ld", xtell(currinf.pos - 1));
kDebugError(", offset %ld", xtell(currinf.pos - 1));
dvi_oops_msg = (message), longjmp(dvi_env, 1); /* dvi_oops */
exit(1);
}
static _Xconst char *dvi_table1[] = {
"SET1", NULL, NULL, NULL, "SETRULE", "PUT1", NULL, NULL,
NULL, "PUTRULE", "NOP", "BOP", "EOP", "PUSH", "POP", "RIGHT1",
"RIGHT2", "RIGHT3", "RIGHT4", "W0", "W1", "W2", "W3", "W4",
"X0", "X1", "X2", "X3", "X4", "DOWN1", "DOWN2", "DOWN3",
"DOWN4", "Y0", "Y1", "Y2", "Y3", "Y4", "Z0", "Z1",
"Z2", "Z3", "Z4"};
static _Xconst char *dvi_table2[] = {
"FNT1", "FNT2", "FNT3", "FNT4", "XXX1", "XXX2", "XXX3", "XXX4",
"FNTDEF1", "FNTDEF2", "FNTDEF3", "FNTDEF4", "PRE", "POST", "POSTPOST",
@ -261,56 +239,22 @@ static void change_font(unsigned long n)
currinf.fontp = currinf.fonttable[n];
if (currinf.fontp == NULL)
tell_oops("non-existent font #%d", n);
maxchar = currinf.fontp->fmaxchar;
currinf.set_char_p = currinf.fontp->set_char_p;
}
/*
* Open a font file.
*/
static void open_font_file(struct font *fontp)
{
if (fontp->file == NULL) {
fontp->file = xfopen(fontp->filename, OPEN_MODE);
if (fontp->file == NULL)
oops("Font file disappeared: %s", fontp->filename);
}
}
/*
* Routines to print characters.
*/
#define ERRVAL
/** Routine to print characters. */
void set_char(unsigned int cmd, unsigned int ch)
{
kDebugInfo(DEBUG, 4300, "set_char");
register struct glyph *g;
long dvi_h_sav;
glyph *g = currinf.fontp->glyphptr(ch);
if (g == NULL)
return;
if (ch > maxchar)
currinf.fontp->realloc_font(WIDENINT ch);
if ((g = &currinf.fontp->glyph[ch])->bitmap.bits == NULL) {
if (g->addr == 0) {
if (!hush_chars)
kDebugError(1,4300,"Character %d not defined in font %s", ch, currinf.fontp->fontname);
g->addr = -1;
return ERRVAL;
}
if (g->addr == -1)
return ERRVAL; /* previously flagged missing char */
open_font_file(currinf.fontp);
Fseek(currinf.fontp->file, g->addr, 0);
(*currinf.fontp->read_char)(currinf.fontp, ch);
currinf.fontp->timestamp = ++current_timestamp;
}
dvi_h_sav = DVI_H;
long dvi_h_sav = DVI_H;
if (currinf.dir < 0)
DVI_H -= g->dvi_adv;
if (scan_frame == NULL)
@ -338,7 +282,6 @@ void load_n_set_char(unsigned int cmd, unsigned int ch)
currinf.set_char_p = currinf.fontp->set_char_p = set_empty_char;
return;
}
maxchar = currinf.fontp->fmaxchar;
currinf.set_char_p = currinf.fontp->set_char_p;
(*currinf.set_char_p)(cmd, ch);
return;
@ -349,19 +292,16 @@ void set_vf_char(unsigned int cmd, unsigned int ch)
{
kDebugInfo(DEBUG, 4300, "set_vf_char");
register struct macro *m;
macro *m;
struct drawinf oldinfo;
unsigned char oldmaxchar;
static unsigned char c;
long dvi_h_sav;
if (ch > maxchar)
currinf.fontp->realloc_font(ch);
if ((m = &currinf.fontp->macro[ch])->pos == NULL) {
if ((m = &currinf.fontp->macrotable[ch])->pos == NULL) {
if (!hush_chars)
kDebugError(1, 4300, "Character %d not defined in font %s\n", ch, currinf.fontp->fontname);
m->pos = m->end = &c;
return ERRVAL;
return;
}
dvi_h_sav = DVI_H;
@ -369,7 +309,6 @@ void set_vf_char(unsigned int cmd, unsigned int ch)
DVI_H -= m->dvi_adv;
if (scan_frame == NULL) {
oldinfo = currinf;
oldmaxchar = maxchar;
WW = 0;
XX = 0;
YY = 0;
@ -383,7 +322,6 @@ void set_vf_char(unsigned int cmd, unsigned int ch)
if (currinf.pos != currinf.end + 1)
tell_oops("virtual character macro does not end correctly");
currinf = oldinfo;
maxchar = oldmaxchar;
}
if (cmd == PUT1)
DVI_H = dvi_h_sav;
@ -400,7 +338,6 @@ static void set_no_char(unsigned int cmd, unsigned int ch)
if (currinf._virtual) {
currinf.fontp = currinf._virtual->first_font;
if (currinf.fontp != NULL) {
maxchar = currinf.fontp->fmaxchar;
currinf.set_char_p = currinf.fontp->set_char_p;
(*currinf.set_char_p)(cmd, ch);
return;
@ -458,7 +395,6 @@ static void draw_part(struct frame *minframe, double current_dimconv)
unsigned char ch;
struct drawinf oldinfo;
unsigned char oldmaxchar;
off_t file_pos;
int refl_count;
@ -541,7 +477,6 @@ static void draw_part(struct frame *minframe, double current_dimconv)
if (scan_frame == NULL) {
/* we're not scanning: save some info. */
oldinfo = currinf;
oldmaxchar = maxchar;
if (!currinf._virtual)
file_pos = xtell(currinf.pos);
scan_frame = current_frame; /* now we're scanning */
@ -580,7 +515,6 @@ static void draw_part(struct frame *minframe, double current_dimconv)
}
}
currinf = oldinfo;
maxchar = oldmaxchar;
/* and then: recover position info. */
DVI_H = current_frame->data.dvi_h;
DVI_V = current_frame->data.dvi_v;

126
font.cpp
View file

@ -1,8 +1,7 @@
#define DEBUG 1
#define DEBUG 0
#include <malloc.h>
#include <kdebug.h>
#include "font.h"
@ -20,12 +19,12 @@ extern "C" {
#include <stdio.h>
#include "oconfig.h"
extern FILE *xfopen(char *filename, char *type);
extern FILE *xfopen(const char *filename, const char *type);
/** We try for a VF first because that's what dvips does. Also, it's
* easier to avoid running MakeTeXPK if we have a VF this way. */
FILE *font_open (char *font, char **font_ret, double dpi, int *dpi_ret, int dummy, char **filename_ret)
FILE *font::font_open (char *font, char **font_ret, double dpi, int *dpi_ret, char **filename_ret)
{
FILE *ret;
char *name = kpse_find_vf (font);
@ -50,7 +49,7 @@ FILE *font_open (char *font, char **font_ret, double dpi, int *dpi_ret, int dumm
}
// If we found a name, return the stream.
ret = name ? xfopen (name, FOPEN_R_MODE) : NULL;
ret = name ? xfopen(name, FOPEN_R_MODE) : NULL;
*filename_ret = name;
return ret;
@ -68,7 +67,7 @@ font::font(char *nfontname, float nfsize, long chk, int mag, double dconv)
fsize = nfsize;
checksum = chk;
magstepval = mag;
flags = FONT_IN_USE;
flags = font::FONT_IN_USE;
file = NULL;
filename = NULL;
dimconv = dconv;
@ -88,20 +87,15 @@ font::~font()
free(filename);
if (flags & FONT_VIRTUAL) {
register struct macro *m;
for (m = macro; m <= macro + maxchar; ++m)
for (macro *m = macrotable; m < macrotable + max_num_of_chars_in_font; ++m)
if (m->free_me)
free((char *) m->pos);
free((char *) macro);
free((char *) macrotable);
vf_table.clear();
} else {
struct glyph *g;
for (g = glyph; g <= glyph + maxchar; ++g)
for (glyph *g = glyphtable; g < glyphtable + max_num_of_chars_in_font; ++g)
delete g;
free((char *) glyph);
free((char *) glyphtable);
}
}
}
@ -118,14 +112,13 @@ font::~font()
#define VF_MAGIC (VF_PRE << 8) + VF_ID_BYTE
/** load_font locates the raster file and reads the index of
* characters, plus whatever other preprocessing is done (depending on
* the format). */
characters, plus whatever other preprocessing is done (depending
on the format). */
unsigned char font::load_font(void)
{
kDebugInfo(DEBUG, 4300, "loading font %s at %d dpi", fontname, (int) (fsize + 0.5));
double n_fsize = fsize;
int dpi = (int)(fsize + 0.5);
char *font_found;
int size_found;
@ -133,8 +126,8 @@ unsigned char font::load_font(void)
Boolean hushcs = hush_chk;
flags |= FONT_LOADED;
file = font_open(fontname, &font_found, fsize, &size_found, magstepval, &filename);
flags |= font::FONT_LOADED;
file = font_open(fontname, &font_found, (double)fsize, &size_found, &filename);
if (file == NULL) {
kDebugError("Can't find font %s.", fontname);
return True;
@ -151,84 +144,79 @@ unsigned char font::load_font(void)
kDebugError("Can't find font %s at %d dpi; using %d dpi instead.", fontname, dpi, size_found);
fsize = size_found;
timestamp = ++current_timestamp;
fmaxchar = maxchar = 255;
set_char_p = set_char;
magic = two(file);
if (magic == PK_MAGIC)
read_PK_index(this, WIDENINT hushcs);
read_PK_index(WIDENINT hushcs);
else
if (magic == GF_MAGIC)
read_GF_index(this, WIDENINT hushcs);
oops("The GF format for font file %s is no longer supported", filename);
else
if (magic == VF_MAGIC)
read_VF_index(this, WIDENINT hushcs);
read_VF_index(WIDENINT hushcs);
else
oops("Cannot recognize format for font file %s", filename);
if (flags & FONT_VIRTUAL) {
while (maxchar > 0 && macro[maxchar].pos == NULL)
--maxchar;
if (maxchar < 255)
realloc_font(WIDENINT maxchar);
} else {
while (maxchar > 0 && glyph[maxchar].addr == 0)
--maxchar;
if (maxchar < 255)
realloc_font(WIDENINT maxchar);
}
return False;
}
/** realloc_font allocates the font structure to contain (newsize + 1)
* characters (or macros, if the font is a virtual font). */
void font::realloc_font(unsigned int newsize)
{
kDebugInfo(DEBUG, 4300, "Realloc font");
if (flags & FONT_VIRTUAL) {
struct macro *macrop;
macrop = macro = (struct macro *) realloc((char *) macro,
((unsigned int) newsize + 1) * sizeof(struct macro));
if (macrop == NULL)
oops("! Cannot reallocate space for macro array.");
if (newsize > fmaxchar)
bzero((char *) (macro + fmaxchar + 1), (int) (newsize - fmaxchar) * sizeof(struct macro));
} else {
struct glyph *glyphp;
glyphp = glyph = (struct glyph *)realloc((char *) glyph,
((unsigned int) newsize + 1) * sizeof(struct glyph));
if (glyph == NULL)
oops("! Cannot reallocate space for glyph array.");
if (newsize > fmaxchar)
bzero((char *) (glyph + fmaxchar + 1), (int) (newsize - fmaxchar) * sizeof(struct glyph));
}
fmaxchar = newsize;
}
/** mark_as_used marks the font, and all the fonts it referrs to, as
* used, i.e. their FONT_IN_USE-flag is set. */
used, i.e. their FONT_IN_USE-flag is set. */
void font::mark_as_used(void)
{
if (flags & FONT_IN_USE)
if (flags & font::FONT_IN_USE)
return;
kDebugInfo(DEBUG, 4300, "marking font %s at %d dpi as used", fontname, (int) (fsize + 0.5));
flags |= FONT_IN_USE;
flags |= font::FONT_IN_USE;
// For virtual fonts, also go through the list of referred fonts
if (flags & FONT_VIRTUAL) {
if (flags & font::FONT_VIRTUAL) {
QIntDictIterator<font> it(vf_table);
while( it.current() ) {
it.current()->flags |= FONT_IN_USE;
it.current()->flags |= font::FONT_IN_USE;
++it;
}
}
}
/** Returns a pointer to glyph number ch in the font, or NULL, if this
number does not exist. This function first reads the bitmap of the
character from the PK-file, if necessary */
struct glyph *font::glyphptr(unsigned int ch) {
struct glyph *g = glyphtable+ch;
if (g->bitmap.bits == NULL) {
if (g->addr == 0) {
kDebugError(1,4300,"Character %d not defined in font %s", ch, fontname);
g->addr = -1;
return NULL;
}
if (g->addr == -1)
return NULL; /* previously flagged missing char */
if (file == NULL) {
file = xfopen(filename, OPEN_MODE);
if (file == NULL) {
oops("Font file disappeared: %s", filename);
return NULL;
}
}
Fseek(file, g->addr, 0);
read_PK_char(ch);
timestamp = ++current_timestamp;
if (g->bitmap.bits == NULL) {
g->addr = -1;
return NULL;
}
}
return g;
}

74
font.h
View file

@ -34,47 +34,63 @@ struct macro {
#define FONT_IN_USE 1 /* used for housekeeping */
#define FONT_LOADED 2 /* if font file has been read */
#define FONT_VIRTUAL 4 /* if font is virtual */
typedef void (*read_char_proc)(register struct font *, unsigned int);
typedef void (*set_char_proc)(unsigned int, unsigned int);
struct font {
struct font *next; /* link to next font info block */
char *fontname; /* name of font */
float fsize; /* size information (dots per inch) */
// Currently, kdvi supports fonts with at most 256 characters to
// comply with "The DVI Driver Standard, Level 0". If you change
// this value here, make sure to go through all the source and
// ensure that character numbers are stored in ints rather than
// unsigned chars.
static const int max_num_of_chars_in_font = 256;
enum font_flags {
FONT_IN_USE = 1, // used for housekeeping
FONT_LOADED = 2, // if font file has been read
FONT_VIRTUAL = 4 // if font is virtual
};
public:
font(char *nfontname, float nfsize, long chk, int mag, double dconv);
~font();
glyph *glyphptr(unsigned int ch);
void mark_as_used(void);
unsigned char load_font(void);
struct font *next; // link to next font info block
char *fontname; // name of font
unsigned char flags; // flags byte (see values below)
double dimconv; // size conversion factor
set_char_proc set_char_p; // proc used to set char
float fsize; // size information (dots per inch)
unsigned short timestamp; // for LRU management of fonts
FILE *file; // open font file or NULL
glyph *glyphtable; // used by (loaded) raster fonts
macro *macrotable; // used by (loaded) virtual fonts
QIntDict<font> vf_table; // used by (loaded) virtual fonts, list of fonts used by this vf,
// acessible by number
font *first_font; // used by (loaded) virtual fonts, list of fonts used by this vf
private:
int magstepval; /* magstep number * two, or NOMAGSTP */
FILE *file; /* open font file or NULL */
char *filename; /* name of font file */
long checksum; /* checksum */
unsigned short timestamp; /* for LRU management of fonts */
unsigned char flags; /* flags byte (see values below) */
unsigned char fmaxchar; /* largest character code */
double dimconv; /* size conversion factor */
set_char_proc set_char_p; /* proc used to set char */
/* these fields are used by (loaded) raster fonts */
read_char_proc read_char; /* function to read bitmap */
struct glyph *glyph;
/* these fields are used by (loaded) virtual fonts */
QIntDict<struct font> vf_table; /* list of fonts used by this vf */
struct font *first_font; /* first font defined */
struct macro *macro;
FILE *font_open (char *font, char **font_ret, double dpi, int *dpi_ret, char **filename_ret);
/* I suppose the above could be put into a union, but we */
/* wouldn't save all that much space. */
// Functions related to virtual fonts
void read_VF_index(unsigned int hushcs);
font(char *nfontname, float nfsize, long chk, int mag, double dconv);
~font();
void realloc_font(unsigned int newsize);
void mark_as_used(void);
unsigned char load_font(void);
// Functions for pk fonts
int PK_get_nyb(FILE *fp);
int PK_packed_num(FILE *fp);
void PK_skip_specials(void);
void read_PK_char(unsigned int ch);
void read_PK_index(unsigned int hushcs);
};

330
gf.cpp
View file

@ -1,330 +0,0 @@
/*
* Copyright (c) 1994 Paul Vojta. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "dviwin.h"
#include <stdio.h>
#include "glyph.h"
#include "oconfig.h"
extern char *xmalloc (unsigned, _Xconst char *);
/***
*** GF font reading routines.
*** Public routines are read_GF_index and read_GF_char.
***/
#define PAINT_0 0
#define PAINT1 64
#define PAINT2 65
#define PAINT3 66
#define BOC 67
#define BOC1 68
#define EOC 69
#define SKIP0 70
#define SKIP1 71
#define SKIP2 72
#define SKIP3 73
#define NEW_ROW_0 74
#define NEW_ROW_MAX 238
#define XXX1 239
#define XXX2 240
#define XXX3 241
#define XXX4 242
#define YYY 243
#define NO_OP 244
#define CHAR_LOC 245
#define CHAR_LOC0 246
#define PRE 247
#define POST 248
#define POST_POST 249
#define GF_ID_BYTE 131
#define TRAILER 223 /* Trailing bytes at end of file */
static FILE *GF_file;
static void expect(unsigned char ch)
{
unsigned char ch1 = one(GF_file);
if (ch1 != ch)
oops("Bad GF file: %d expected, %d received.", ch, ch1);
}
static void too_many_bits(unsigned char ch)
{
oops("Too many bits found when loading character %d", ch);
}
/*
* Public routines
*/
static void
#if NeedFunctionPrototypes
read_GF_char(register struct font *fontp, unsigned int ch)
#else /* !NeedFunctionPrototypes */
read_GF_char(font *fontp, unsigned char ch)
#endif /* NeedFunctionPrototypes */
{
register struct glyph *g;
unsigned char cmnd;
int min_m, max_m, min_n, max_n;
BMUNIT *cp, *basep, *maxp;
int bytes_wide;
Boolean paint_switch;
#define White False
#define Black True
Boolean new_row;
int count;
int word_weight;
g = &fontp->glyph[ch];
GF_file = fontp->file;
if(_debug & DBG_PK)
Printf("Loading gf char %d", ch);
for (;;) {
switch (cmnd = one(GF_file)) {
case XXX1:
case XXX2:
case XXX3:
case XXX4:
Fseek(GF_file, (long) num(GF_file,
WIDENINT cmnd - XXX1 + 1), 1);
continue;
case YYY:
(void) four(GF_file);
continue;
case BOC:
(void) four(GF_file); /* skip character code */
(void) four(GF_file); /* skip pointer to prev char */
min_m = sfour(GF_file);
max_m = sfour(GF_file);
g->x = -min_m;
min_n = sfour(GF_file);
g->y = max_n = sfour(GF_file);
g->bitmap.w = max_m - min_m + 1;
g->bitmap.h = max_n - min_n + 1;
break;
case BOC1:
(void) one(GF_file); /* skip character code */
g->bitmap.w = one(GF_file); /* max_m - min_m */
g->x = g->bitmap.w - one(GF_file); /* ditto - max_m */
++g->bitmap.w;
g->bitmap.h = one(GF_file) + 1;
g->y = one(GF_file);
break;
default:
oops("Bad BOC code: %d", cmnd);
}
break;
}
paint_switch = White;
if (_debug & DBG_PK)
Printf(", size=%dx%d, dvi_adv=%ld\n", g->bitmap.w, g->bitmap.h,
g->dvi_adv);
alloc_bitmap(&g->bitmap);
cp = basep = (BMUNIT *) g->bitmap.bits;
/*
* Read character data into *basep
*/
bytes_wide = ROUNDUP((int) g->bitmap.w, BITS_PER_BMUNIT)
* BYTES_PER_BMUNIT;
maxp = ADD(basep, g->bitmap.h * bytes_wide);
bzero(g->bitmap.bits, g->bitmap.h * bytes_wide);
new_row = False;
word_weight = BITS_PER_BMUNIT;
for (;;) {
count = -1;
cmnd = one(GF_file);
if (cmnd < 64) count = cmnd;
else if (cmnd >= NEW_ROW_0 && cmnd <= NEW_ROW_MAX) {
count = cmnd - NEW_ROW_0;
paint_switch = White; /* it'll be complemented later */
new_row = True;
}
else switch (cmnd) {
case PAINT1:
case PAINT2:
case PAINT3:
count = num(GF_file, WIDENINT cmnd - PAINT1 + 1);
break;
case EOC:
if (cp >= ADD(basep, bytes_wide)) too_many_bits(ch);
return;
case SKIP1:
case SKIP2:
case SKIP3:
*((char **) &basep) +=
num(GF_file, WIDENINT cmnd - SKIP0) * bytes_wide;
case SKIP0:
new_row = True;
paint_switch = White;
break;
case XXX1:
case XXX2:
case XXX3:
case XXX4:
Fseek(GF_file, (long) num(GF_file,
WIDENINT cmnd - XXX1 + 1), 1);
break;
case YYY:
(void) four(GF_file);
break;
case NO_OP:
break;
default:
oops("Bad command in GF file: %d", cmnd);
} /* end switch */
if (new_row) {
*((char **) &basep) += bytes_wide;
if (basep >= maxp || cp >= basep) too_many_bits(ch);
cp = basep;
word_weight = BITS_PER_BMUNIT;
new_row = False;
}
if (count >= 0) {
while (count)
if (count <= word_weight) {
#ifndef MSBITFIRST
if (paint_switch)
*cp |= bit_masks[count] <<
(BITS_PER_BMUNIT - word_weight);
#endif
word_weight -= count;
#ifdef MSBITFIRST
if (paint_switch)
*cp |= bit_masks[count] << word_weight;
#endif
break;
}
else {
if (paint_switch)
#ifndef MSBITFIRST
*cp |= bit_masks[word_weight] <<
(BITS_PER_BMUNIT - word_weight);
#else
*cp |= bit_masks[word_weight];
#endif
cp++;
count -= word_weight;
word_weight = BITS_PER_BMUNIT;
}
paint_switch = 1 - paint_switch;
}
} /* end for */
}
void read_GF_index(font *fontp, wide_bool hushcs)
{
int hppp, vppp;
unsigned char ch, cmnd;
register struct glyph *g;
long checksum;
fontp->read_char = read_GF_char;
GF_file = fontp->file;
if (_debug & DBG_PK)
Printf("Reading GF pixel file %s\n", fontp->filename);
/*
* Find postamble.
*/
Fseek(GF_file, (long) -4, 2);
while (four(GF_file) != ((unsigned long) TRAILER << 24 | TRAILER << 16
| TRAILER << 8 | TRAILER))
Fseek(GF_file, (long) -5, 1);
Fseek(GF_file, (long) -5, 1);
for (;;) {
ch = one(GF_file);
if (ch != TRAILER) break;
Fseek(GF_file, (long) -2, 1);
}
if (ch != GF_ID_BYTE) oops("Bad end of font file %s", fontp->fontname);
Fseek(GF_file, (long) -6, 1);
expect(POST_POST);
Fseek(GF_file, sfour(GF_file), 0); /* move to postamble */
/*
* Read postamble.
*/
expect(POST);
(void) four(GF_file); /* pointer to last eoc + 1 */
(void) four(GF_file); /* skip design size */
checksum = four(GF_file);
if (!hushcs && checksum && fontp->checksum
&& checksum != fontp->checksum)
Fprintf(stderr,
"Checksum mismatch (dvi = %lu, gf = %lu) in font file %s\n",
fontp->checksum, checksum, fontp->filename);
hppp = sfour(GF_file);
vppp = sfour(GF_file);
if (hppp != vppp && (_debug & DBG_PK))
Printf("Font has non-square aspect ratio %d:%d\n", vppp, hppp);
(void) four(GF_file); /* skip min_m */
(void) four(GF_file); /* skip max_m */
(void) four(GF_file); /* skip min_n */
(void) four(GF_file); /* skip max_n */
/*
* Prepare glyph array.
*/
fontp->glyph = (struct glyph *) xmalloc(256 * sizeof(struct glyph),
"glyph array");
bzero((char *) fontp->glyph, 256 * sizeof(struct glyph));
/*
* Read glyph directory.
*/
while ((cmnd = one(GF_file)) != POST_POST) {
int addr;
ch = one(GF_file); /* character code */
g = &fontp->glyph[ch];
switch (cmnd) {
case CHAR_LOC:
/* g->pxl_adv = sfour(GF_file); */
(void) four(GF_file);
(void) four(GF_file); /* skip dy */
break;
case CHAR_LOC0:
/* g->pxl_adv = one(GF_file) << 16; */
(void) one(GF_file);
break;
default:
oops("Non-char_loc command found in GF preamble: %d",
cmnd);
}
g->dvi_adv = fontp->dimconv * sfour(GF_file);
addr = four(GF_file);
if (addr != -1) g->addr = addr;
if (_debug & DBG_PK)
Printf("Read GF glyph for character %d; dy = %ld, addr = %x\n",
ch, g->dvi_adv, addr);
}
}

468
pk.cpp
View file

@ -49,6 +49,11 @@
* and Luis Miguel Silveira, MIT RLE.
*/
#define DEBUG 0
#include <kdebug.h>
#include "font.h"
#include "dviwin.h"
#include <stdio.h>
@ -78,8 +83,10 @@ static int PK_bitpos;
static int PK_dyn_f;
static int PK_repeat_count;
static int PK_get_nyb(FILE *fp)
int font::PK_get_nyb(FILE *fp)
{
kDebugInfo(DEBUG, 4300, "PK_get_nyb");
unsigned temp;
if (PK_bitpos < 0) {
PK_input_byte = one(fp);
@ -91,8 +98,10 @@ static int PK_get_nyb(FILE *fp)
}
static int PK_packed_num(FILE *fp)
int font::PK_packed_num(FILE *fp)
{
kDebugInfo(DEBUG, 4300, "PK_packed_num");
int i,j;
if ((i = PK_get_nyb(fp)) == 0) {
@ -119,273 +128,254 @@ static int PK_packed_num(FILE *fp)
}
static void PK_skip_specials(font *fontp)
void font::PK_skip_specials(void)
{
int i,j;
register FILE *fp = fontp->file;
kDebugInfo(DEBUG, 4300, "PK_skip_specials");
do {
PK_flag_byte = one(fp);
if (PK_flag_byte >= PK_CMD_START) {
switch (PK_flag_byte) {
case PK_X1 :
case PK_X2 :
case PK_X3 :
case PK_X4 :
i = 0;
for (j = PK_CMD_START; j <= PK_flag_byte; ++j)
i = (i << 8) | one(fp);
while (i--) (void) one(fp);
break;
case PK_Y :
(void) four(fp);
case PK_POST :
case PK_NOOP :
break;
default :
oops("Unexpected %d in PK file %s", PK_flag_byte,
fontp->filename);
break;
}
}
}
while (PK_flag_byte != PK_POST && PK_flag_byte >= PK_CMD_START);
int i,j;
register FILE *fp = file;
do {
PK_flag_byte = one(fp);
if (PK_flag_byte >= PK_CMD_START) {
switch (PK_flag_byte) {
case PK_X1 :
case PK_X2 :
case PK_X3 :
case PK_X4 :
i = 0;
for (j = PK_CMD_START; j <= PK_flag_byte; ++j)
i = (i << 8) | one(fp);
while (i--) (void) one(fp);
break;
case PK_Y :
(void) four(fp);
case PK_POST :
case PK_NOOP :
break;
default :
oops("Unexpected %d in PK file %s", PK_flag_byte, filename);
break;
}
}
}
while (PK_flag_byte != PK_POST && PK_flag_byte >= PK_CMD_START)
;
}
/*
* Public routines
*/
static void read_PK_char(struct font *fontp, unsigned int ch)
void font::read_PK_char(unsigned int ch)
{
int i, j;
int n;
int row_bit_pos;
Boolean paint_switch;
BMUNIT *cp;
register struct glyph *g;
register FILE *fp = fontp->file;
long fpwidth;
BMUNIT word;
int word_weight, bytes_wide;
int rows_left, h_bit, count;
kDebugInfo(DEBUG, 4300, "read_PK_char");
g = &fontp->glyph[ch];
PK_flag_byte = g->x2;
PK_dyn_f = PK_flag_byte >> 4;
paint_switch = ((PK_flag_byte & 8) != 0);
PK_flag_byte &= 0x7;
if (PK_flag_byte == 7) n = 4;
else if (PK_flag_byte > 3) n = 2;
else n = 1;
int i, j;
int n;
int row_bit_pos;
Boolean paint_switch;
BMUNIT *cp;
register struct glyph *g;
register FILE *fp = file;
long fpwidth;
BMUNIT word = 0;
int word_weight, bytes_wide;
int rows_left, h_bit, count;
if (_debug & DBG_PK) Printf("loading pk char %d, char type %d ", ch, n);
g = glyphtable + ch;
PK_flag_byte = g->x2;
PK_dyn_f = PK_flag_byte >> 4;
paint_switch = ((PK_flag_byte & 8) != 0);
PK_flag_byte &= 0x7;
if (PK_flag_byte == 7)
n = 4;
else
if (PK_flag_byte > 3)
n = 2;
else
n = 1;
kDebugInfo(DEBUG, 4300, "loading pk char %d, char type %d ", ch, n);
/*
* now read rest of character preamble
*/
if (n != 4) fpwidth = num(fp, 3);
else {
fpwidth = sfour(fp);
(void) four(fp); /* horizontal escapement */
}
(void) num(fp, n); /* vertical escapement */
{
unsigned long w, h;
/*
* now read rest of character preamble
*/
if (n != 4)
fpwidth = num(fp, 3);
else {
fpwidth = sfour(fp);
(void) four(fp); /* horizontal escapement */
}
(void) num(fp, n); /* vertical escapement */
{
unsigned long w, h;
w = num(fp, n);
h = num(fp, n);
if (w > 0x7fff || h > 0x7fff)
oops("Character %d too large in file %s", ch, fontp->fontname);
g->bitmap.w = w;
g->bitmap.h = h;
}
g->x = snum(fp, n);
g->y = snum(fp, n);
w = num(fp, n);
h = num(fp, n);
if (w > 0x7fff || h > 0x7fff)
oops("Character %d too large in file %s", ch, fontname);
g->bitmap.w = w;
g->bitmap.h = h;
}
g->x = snum(fp, n);
g->y = snum(fp, n);
g->dvi_adv = fontp->dimconv * fpwidth;
g->dvi_adv = (int)(dimconv * fpwidth + 0.5);
if (DEBUG && g->bitmap.w != 0)
kDebugInfo(DEBUG, 4300, ", size=%dx%d, dvi_adv=%ld", g->bitmap.w, g->bitmap.h, g->dvi_adv);
if (_debug & DBG_PK) {
if (g->bitmap.w != 0)
Printf(", size=%dx%d, dvi_adv=%ld", g->bitmap.w, g->bitmap.h,
g->dvi_adv);
Putchar('\n');
}
alloc_bitmap(&g->bitmap);
cp = (BMUNIT *) g->bitmap.bits;
alloc_bitmap(&g->bitmap);
cp = (BMUNIT *) g->bitmap.bits;
/*
* read character data into *cp
*/
bytes_wide = ROUNDUP((int) g->bitmap.w, BITS_PER_BMUNIT)
* BYTES_PER_BMUNIT;
PK_bitpos = -1;
if (PK_dyn_f == 14) { /* get raster by bits */
bzero(g->bitmap.bits, (int) g->bitmap.h * bytes_wide);
for (i = 0; i < (int) g->bitmap.h; i++) { /* get all rows */
cp = ADD(g->bitmap.bits, i * bytes_wide);
/*
* read character data into *cp
*/
bytes_wide = ROUNDUP((int) g->bitmap.w, BITS_PER_BMUNIT)
* BYTES_PER_BMUNIT;
PK_bitpos = -1;
if (PK_dyn_f == 14) { /* get raster by bits */
bzero(g->bitmap.bits, (int) g->bitmap.h * bytes_wide);
for (i = 0; i < (int) g->bitmap.h; i++) { /* get all rows */
cp = ADD(g->bitmap.bits, i * bytes_wide);
#ifndef MSBITFIRST
row_bit_pos = -1;
row_bit_pos = -1;
#else
row_bit_pos = BITS_PER_BMUNIT;
row_bit_pos = BITS_PER_BMUNIT;
#endif
for (j = 0; j < (int) g->bitmap.w; j++) { /* get one row */
if (--PK_bitpos < 0) {
word = one(fp);
PK_bitpos = 7;
}
#ifndef MSBITFIRST
if (++row_bit_pos >= BITS_PER_BMUNIT) {
cp++;
row_bit_pos = 0;
}
#else
if (--row_bit_pos < 0) {
cp++;
row_bit_pos = BITS_PER_BMUNIT - 1;
}
#endif
if (word & (1 << PK_bitpos)) *cp |= 1 << row_bit_pos;
}
}
for (j = 0; j < (int) g->bitmap.w; j++) { /* get one row */
if (--PK_bitpos < 0) {
word = one(fp);
PK_bitpos = 7;
}
else { /* get packed raster */
rows_left = g->bitmap.h;
h_bit = g->bitmap.w;
PK_repeat_count = 0;
word_weight = BITS_PER_BMUNIT;
word = 0;
while (rows_left > 0) {
count = PK_packed_num(fp);
while (count > 0) {
if (count < word_weight && count < h_bit) {
#ifndef MSBITFIRST
if (paint_switch)
word |= bit_masks[count] <<
(BITS_PER_BMUNIT - word_weight);
if (++row_bit_pos >= BITS_PER_BMUNIT) {
cp++;
row_bit_pos = 0;
}
#else
if (--row_bit_pos < 0) {
cp++;
row_bit_pos = BITS_PER_BMUNIT - 1;
}
#endif
h_bit -= count;
word_weight -= count;
if (word & (1 << PK_bitpos)) *cp |= 1 << row_bit_pos;
}
}
} else { /* get packed raster */
rows_left = g->bitmap.h;
h_bit = g->bitmap.w;
PK_repeat_count = 0;
word_weight = BITS_PER_BMUNIT;
word = 0;
while (rows_left > 0) {
count = PK_packed_num(fp);
while (count > 0) {
if (count < word_weight && count < h_bit) {
#ifndef MSBITFIRST
if (paint_switch)
word |= bit_masks[count] <<
(BITS_PER_BMUNIT - word_weight);
#endif
h_bit -= count;
word_weight -= count;
#ifdef MSBITFIRST
if (paint_switch)
word |= bit_masks[count] << word_weight;
if (paint_switch)
word |= bit_masks[count] << word_weight;
#endif
count = 0;
}
else if (count >= h_bit && h_bit <= word_weight) {
if (paint_switch)
word |= bit_masks[h_bit] <<
count = 0;
} else
if (count >= h_bit && h_bit <= word_weight) {
if (paint_switch)
word |= bit_masks[h_bit] <<
#ifndef MSBITFIRST
(BITS_PER_BMUNIT - word_weight);
(BITS_PER_BMUNIT - word_weight);
#else
(word_weight - h_bit);
(word_weight - h_bit);
#endif
*cp++ = word;
/* "output" row(s) */
for (i = PK_repeat_count * bytes_wide /
BYTES_PER_BMUNIT; i > 0; --i) {
*cp = *SUB(cp, bytes_wide);
++cp;
}
rows_left -= PK_repeat_count + 1;
PK_repeat_count = 0;
word = 0;
word_weight = BITS_PER_BMUNIT;
count -= h_bit;
h_bit = g->bitmap.w;
}
else {
if (paint_switch)
#ifndef MSBITFIRST
word |= bit_masks[word_weight] <<
(BITS_PER_BMUNIT - word_weight);
#else
word |= bit_masks[word_weight];
#endif
*cp++ = word;
word = 0;
count -= word_weight;
h_bit -= word_weight;
word_weight = BITS_PER_BMUNIT;
}
}
paint_switch = 1 - paint_switch;
*cp++ = word;
/* "output" row(s) */
for (i = PK_repeat_count * bytes_wide /
BYTES_PER_BMUNIT; i > 0; --i) {
*cp = *SUB(cp, bytes_wide);
++cp;
}
if (cp != ((BMUNIT *) (g->bitmap.bits + bytes_wide * g->bitmap.h)))
oops("Wrong number of bits stored: char. %d, font %s", ch,
fontp->fontname);
if (rows_left != 0 || h_bit != g->bitmap.w)
oops("Bad pk file (%s), too many bits", fontp->fontname);
}
rows_left -= PK_repeat_count + 1;
PK_repeat_count = 0;
word = 0;
word_weight = BITS_PER_BMUNIT;
count -= h_bit;
h_bit = g->bitmap.w;
} else {
if (paint_switch)
#ifndef MSBITFIRST
word |= bit_masks[word_weight] <<
(BITS_PER_BMUNIT - word_weight);
#else
word |= bit_masks[word_weight];
#endif
*cp++ = word;
word = 0;
count -= word_weight;
h_bit -= word_weight;
word_weight = BITS_PER_BMUNIT;
}
}
paint_switch = 1 - paint_switch;
}
if (cp != ((BMUNIT *) (g->bitmap.bits + bytes_wide * g->bitmap.h)))
oops("Wrong number of bits stored: char. %d, font %s", ch, fontname);
if (rows_left != 0 || h_bit != g->bitmap.w)
oops("Bad pk file (%s), too many bits", fontname);
}
}
void read_PK_index(font *fontp, wide_bool hushcs)
void font::read_PK_index(unsigned int hushcs)
{
int hppp, vppp;
long checksum;
kDebugInfo(DEBUG, 4300, "Reading PK pixel file %s", filename);
Fseek(file, (long) one(file), 1); /* skip comment */
fontp->read_char = read_PK_char;
if (_debug & DBG_PK)
Printf("Reading PK pixel file %s\n", fontp->filename);
Fseek(fontp->file, (long) one(fontp->file), 1); /* skip comment */
(void) four(fontp->file); /* skip design size */
checksum = four(fontp->file);
if (!hushcs && checksum && fontp->checksum
&& checksum != fontp->checksum)
Fprintf(stderr,
"Checksum mismatch (dvi = %lu, pk = %lu) in font file %s\n",
fontp->checksum, checksum, fontp->filename);
hppp = sfour(fontp->file);
vppp = sfour(fontp->file);
if (hppp != vppp && (_debug & DBG_PK))
Printf("Font has non-square aspect ratio %d:%d\n", vppp, hppp);
/*
* Prepare glyph array.
*/
fontp->glyph = (struct glyph *) xmalloc(256 * sizeof(struct glyph),
"glyph array");
bzero((char *) fontp->glyph, 256 * sizeof(struct glyph));
/*
* Read glyph directory (really a whole pass over the file).
*/
for (;;) {
int bytes_left, flag_low_bits;
unsigned int ch;
PK_skip_specials(fontp);
if (PK_flag_byte == PK_POST) break;
flag_low_bits = PK_flag_byte & 0x7;
if (flag_low_bits == 7) {
bytes_left = four(fontp->file);
ch = four(fontp->file);
} else if (flag_low_bits > 3) {
bytes_left = ((flag_low_bits - 4) << 16) + two(fontp->file);
ch = one(fontp->file);
} else {
bytes_left = (flag_low_bits << 8) + one(fontp->file);
ch = one(fontp->file);
}
fontp->glyph[ch].addr = ftell(fontp->file);
fontp->glyph[ch].x2 = PK_flag_byte;
#ifdef linux
#ifndef SHORTSEEK
#define SHORTSEEK 1024
#endif
/* A bug in Linux libc (as of 18oct94) makes a short read faster
than a short forward seek. Totally non-intuitive. */
if (bytes_left > 0 && bytes_left < SHORTSEEK) {
char *dummy = xmalloc (bytes_left, "shortseek");
Fread (dummy, 1, bytes_left, fontp->file);
free (dummy);
} else
/* seek backward, or long forward */
#endif /* linux */
Fseek(fontp->file, (long) bytes_left, 1);
if (_debug & DBG_PK)
Printf("Scanning pk char %u, at %ld.\n", ch,
fontp->glyph[ch].addr);
}
(void) four(file); /* skip design size */
long file_checksum = four(file);
if (!hushcs && checksum && checksum && file_checksum != checksum)
kDebugError(1, 4300, "Checksum mismatch (dvi = %lu, pk = %lu) in font file %s",
checksum, file_checksum, filename);
int hppp = sfour(file);
int vppp = sfour(file);
if (DEBUG && hppp != vppp)
kDebugInfo(DEBUG, 4300, "Font has non-square aspect ratio %d:%d", vppp, hppp);
/*
* Prepare glyph array.
*/
glyphtable = (struct glyph *) xmalloc(max_num_of_chars_in_font * sizeof(struct glyph), "glyph array");
bzero((char *) glyphtable, max_num_of_chars_in_font * sizeof(struct glyph));
/*
* Read glyph directory (really a whole pass over the file).
*/
for (;;) {
int bytes_left, flag_low_bits;
unsigned int ch;
PK_skip_specials();
if (PK_flag_byte == PK_POST)
break;
flag_low_bits = PK_flag_byte & 0x7;
if (flag_low_bits == 7) {
bytes_left = four(file);
ch = four(file);
} else
if (flag_low_bits > 3) {
bytes_left = ((flag_low_bits - 4) << 16) + two(file);
ch = one(file);
} else {
bytes_left = (flag_low_bits << 8) + one(file);
ch = one(file);
}
glyphtable[ch].addr = ftell(file);
glyphtable[ch].x2 = PK_flag_byte;
Fseek(file, (long) bytes_left, 1);
kDebugInfo(DEBUG, 4300, "Scanning pk char %u, at %ld.", ch, glyphtable[ch].addr);
}
}

View file

@ -55,6 +55,10 @@
* it's worth it.
*/
#define DEBUG 1
#include <kdebug.h>
#include "dviwin.h"
#include <stdio.h>
@ -73,20 +77,6 @@ extern "C" {
#include <kpathsea/line.h>
}
/*
extern "C" {
#include <kpathsea/config.h>
#include <kpathsea/c-stat.h>
#include <kpathsea/magstep.h>
#include <kpathsea/tex-glyph.h>
#include "dvi.h"
}
*/
#define MAXPOINTS 300 /* Max points in a path */
#define TWOPI (3.14159265359*2.0)
#define MAX_PEN_SIZE 7 /* Max pixels of pen width */
@ -680,125 +670,129 @@ static const char *keytab[] = {"clip",
static void epsf_special(char *cp)
{
char *filename, *name;
int decompress;
static char *buffer;
static unsigned int buflen = 0;
unsigned int len;
char *p;
char *q;
int flags = 0;
double keyval[6];
char *filename, *name;
int decompress;
static char *buffer;
static unsigned int buflen = 0;
unsigned int len;
char *p;
char *q;
int flags = 0;
double keyval[6];
if (memcmp(cp, "ile=", 4) != 0) {
if (!hush_spec_now)
Fprintf(stderr, "epsf special PSf%s is unknown\n", cp);
return;
}
if (memcmp(cp, "ile=", 4) != 0) {
kDebugError(1, 4300, "epsf special PSf%s is unknown", cp);
return;
}
p = cp + 4;
filename = p;
if (*p == '\'' || *p == '"') {
do ++p;
while (*p != '\0' && *p != *filename);
++filename;
}
else
while (*p != '\0' && *p != ' ' && *p != '\t') ++p;
if (*p != '\0') *p++ = '\0';
name = find_fig_file (filename, &decompress);
while (*p == ' ' || *p == '\t') ++p;
len = strlen(p) + NKEYS + 30;
if (buflen < len) {
if (buflen != 0) free(buffer);
buflen = len;
buffer = xmalloc(buflen, "epsf buffer");
}
Strcpy(buffer, "@beginspecial");
q = buffer + strlen(buffer);
while (*p != '\0') {
char *p1 = p;
int keyno;
p = cp + 4;
filename = p;
if (*p == '\'' || *p == '"') {
do
++p;
while (*p != '\0' && *p != *filename);
++filename;
}
else
while (*p != '\0' && *p != ' ' && *p != '\t')
++p;
if (*p != '\0')
*p++ = '\0';
name = find_fig_file (filename, &decompress);
while (*p == ' ' || *p == '\t')
++p;
len = strlen(p) + NKEYS + 30;
if (buflen < len) {
if (buflen != 0)
free(buffer);
buflen = len;
buffer = xmalloc(buflen, "epsf buffer");
}
Strcpy(buffer, "@beginspecial");
q = buffer + strlen(buffer);
while (*p != '\0') {
char *p1 = p;
int keyno;
while (*p1 != '=' && !isspace(*p1) && *p1 != '\0') ++p1;
for (keyno = 0;; ++keyno) {
if (keyno >= NKEYS) {
if (!hush_spec_now)
Fprintf(stderr,
"unknown keyword (%*s) in \\special will be ignored\n",
(int) (p1 - p), p);
break;
}
if (memcmp(p, keytab[keyno], p1 - p) == 0) {
if (keyno >= N_ARGLESS_KEYS) {
if (*p1 == '=') ++p1;
if (keyno < N_ARGLESS_KEYS + 6) {
keyval[keyno - N_ARGLESS_KEYS] = atof(p1);
flags |= (1 << (keyno - N_ARGLESS_KEYS));
}
*q++ = ' ';
while (!isspace(*p1) && *p1 != '\0') *q++ = *p1++;
}
*q++ = ' ';
*q++ = '@';
Strcpy(q, keytab[keyno]);
q += strlen(q);
break;
}
}
p = p1;
while (!isspace(*p) && *p != '\0') ++p;
while (isspace(*p)) ++p;
while (*p1 != '=' && !isspace(*p1) && *p1 != '\0')
++p1;
for (keyno = 0;; ++keyno) {
if (keyno >= NKEYS) {
kDebugError(4300, 1, "unknown keyword (%*s) in \\special will be ignored\n", (int) (p1 - p), p);
break;
}
if (memcmp(p, keytab[keyno], p1 - p) == 0) {
if (keyno >= N_ARGLESS_KEYS) {
if (*p1 == '=')
++p1;
if (keyno < N_ARGLESS_KEYS + 6) {
keyval[keyno - N_ARGLESS_KEYS] = atof(p1);
flags |= (1 << (keyno - N_ARGLESS_KEYS));
}
*q++ = ' ';
while (!isspace(*p1) && *p1 != '\0')
*q++ = *p1++;
}
Strcpy(q, " @setspecial\n");
*q++ = ' ';
*q++ = '@';
Strcpy(q, keytab[keyno]);
q += strlen(q);
break;
}
}
p = p1;
while (!isspace(*p) && *p != '\0')
++p;
while (isspace(*p))
++p;
}
Strcpy(q, " @setspecial\n");
bbox_valid = False;
if ((flags & 0x30) == 0x30 || ((flags & 0x30) && (flags & 0xf) == 0xf)){
bbox_valid = True;
bbox_width = 0.1 * ((flags & 0x10) ? KEY_RWI
: KEY_RHI * (KEY_URX - KEY_LLX) / (KEY_URY - KEY_LLY))
* dimconv / shrink_factor + 0.5;
bbox_voffset = bbox_height = 0.1 * ((flags & 0x20) ? KEY_RHI
: KEY_RWI * (KEY_URY - KEY_LLY) / (KEY_URX - KEY_LLX))
* dimconv / shrink_factor + 0.5;
}
bbox_valid = False;
if ((flags & 0x30) == 0x30 || ((flags & 0x30) && (flags & 0xf) == 0xf)){
bbox_valid = True;
bbox_width = 0.1 * ((flags & 0x10) ? KEY_RWI
: KEY_RHI * (KEY_URX - KEY_LLX) / (KEY_URY - KEY_LLY))
* dimconv / shrink_factor + 0.5;
bbox_voffset = bbox_height = 0.1 * ((flags & 0x20) ? KEY_RHI
: KEY_RWI * (KEY_URY - KEY_LLY) / (KEY_URX - KEY_LLX))
* dimconv / shrink_factor + 0.5;
}
if (name && currwin.win == mane.win) {
psp.drawbegin(PXL_H - currwin.base_x, PXL_V - currwin.base_y,
buffer);
draw_file(psp, name, decompress);
psp.drawend(" @endspecial");
if (!decompress && name != filename)
free (name);
}
bbox_valid = False;
if (name && currwin.win == mane.win) {
psp.drawbegin(PXL_H - currwin.base_x, PXL_V - currwin.base_y, buffer);
draw_file(psp, name, decompress);
psp.drawend(" @endspecial");
if (!decompress && name != filename)
free (name);
}
bbox_valid = False;
}
static void bang_special(char *cp)
{
bbox_valid = False;
if (currwin.win == mane.win) {
psp.drawbegin(PXL_H - currwin.base_x, PXL_V - currwin.base_y,
"@defspecial ");
/* talk directly with the DPSHandler here */
psp.drawraw(cp);
psp.drawend(" @fedspecial");
}
// kDebugInfo(DEBUG, 4300, "bang %s", cp);
bbox_valid = False;
if (currwin.win == mane.win) {
psp.drawbegin(PXL_H - currwin.base_x, PXL_V - currwin.base_y, "@defspecial ");
/* talk directly with the DPSHandler here */
psp.drawraw(cp);
psp.drawend(" @fedspecial");
}
}
static void quote_special(char *cp)
{
bbox_valid = False;
bbox_valid = False;
if (currwin.win == mane.win) {
psp.drawbegin(PXL_H - currwin.base_x, PXL_V - currwin.base_y,
"@beginspecial @setspecial ");
/* talk directly with the DPSHandler here */
psp.drawraw(cp);
psp.drawend(" @endspecial");
}
if (currwin.win == mane.win) {
psp.drawbegin(PXL_H - currwin.base_x, PXL_V - currwin.base_y, "@beginspecial @setspecial ");
/* talk directly with the DPSHandler here */
psp.drawraw(cp);
psp.drawend(" @endspecial");
}
}

View file

@ -49,6 +49,9 @@
* and Luis Miguel Silveira, MIT RLE.
*/
#define DEBUG 0
#include <kdebug.h>
#include "dviwin.h"
extern "C" {
@ -57,6 +60,7 @@ extern "C" {
#include <kpathsea/c-fopen.h>
#include <kpathsea/c-vararg.h>
}
#include "oconfig.h"
#include "dvi.h"
@ -107,19 +111,19 @@ oops(va_alist)
exit(1);
}
/*
* Either allocate storage or fail with explanation.
*/
/** Either allocate storage or fail with explanation. */
char * xmalloc(unsigned size, _Xconst char *why)
{
/* Avoid malloc(0), though it's not clear if it ever actually
happens any more. */
char *mem = (char *)malloc(size ? size : 1);
kDebugInfo(DEBUG, 4300, "Allocating %d bytes for %s", size, why);
if (mem == NULL)
oops("! Cannot allocate %u bytes for %s.\n", size, why);
return mem;
/* Avoid malloc(0), though it's not clear if it ever actually
happens any more. */
char *mem = (char *)malloc(size ? size : 1);
if (mem == NULL)
oops("! Cannot allocate %u bytes for %s.\n", size, why);
return mem;
}
/*
@ -128,13 +132,12 @@ char * xmalloc(unsigned size, _Xconst char *why)
void alloc_bitmap(bitmap *bitmap)
{
register unsigned int size;
register unsigned int size;
/* width must be multiple of 16 bits for raster_op */
bitmap->bytes_wide = ROUNDUP((int) bitmap->w, BITS_PER_BMUNIT) *
BYTES_PER_BMUNIT;
size = bitmap->bytes_wide * bitmap->h;
bitmap->bits = xmalloc(size != 0 ? size : 1, "character bitmap");
/* width must be multiple of 16 bits for raster_op */
bitmap->bytes_wide = ROUNDUP((int) bitmap->w, BITS_PER_BMUNIT) * BYTES_PER_BMUNIT;
size = bitmap->bytes_wide * bitmap->h;
bitmap->bits = xmalloc(size != 0 ? size : 1, "character bitmap");
}
@ -144,46 +147,43 @@ void alloc_bitmap(bitmap *bitmap)
static void close_a_file()
{
register struct font *fontp;
unsigned short oldest = ~0;
struct font *f = NULL;
register struct font *fontp;
unsigned short oldest = ~0;
struct font *f = NULL;
for (fontp = font_head; fontp != NULL; fontp = fontp->next)
if (fontp->file != NULL && fontp->timestamp <= oldest) {
f = fontp;
oldest = fontp->timestamp;
}
if (f == NULL)
oops("Can't find an open pixel file to close");
Fclose(f->file);
f->file = NULL;
++n_files_left;
for (fontp = font_head; fontp != NULL; fontp = fontp->next)
if (fontp->file != NULL && fontp->timestamp <= oldest) {
f = fontp;
oldest = fontp->timestamp;
}
if (f == NULL)
oops("Can't find an open pixel file to close");
Fclose(f->file);
f->file = NULL;
++n_files_left;
}
/*
* Open a file in the given mode.
*/
FILE *xfopen(char *filename, char *type)
FILE *xfopen(const char *filename, const char *type)
#define TYPE type
{
FILE *f;
/* Try not to let the file table fill up completely. */
if (n_files_left <= 5)
close_a_file();
f = fopen(filename, OPEN_MODE);
/* If the open failed, try closing a file unconditionally.
Interactive Unix 2.2.1, at least, doesn't set errno to EMFILE
or ENFILE even when it should. In any case, it doesn't hurt
much to always try. */
if (f == NULL)
{
n_files_left = 0;
close_a_file();
f = fopen(filename, TYPE);
}
return f;
/* Try not to let the file table fill up completely. */
if (n_files_left <= 5)
close_a_file();
FILE *f = fopen(filename, OPEN_MODE);
/* If the open failed, try closing a file unconditionally.
Interactive Unix 2.2.1, at least, doesn't set errno to EMFILE
or ENFILE even when it should. In any case, it doesn't hurt
much to always try. */
if (f == NULL) {
n_files_left = 0;
close_a_file();
f = fopen(filename, TYPE);
}
return f;
}
#undef TYPE

55
vf.cpp
View file

@ -32,7 +32,7 @@
#include "oconfig.h"
#include "dvi.h"
extern char *xmalloc (unsigned, _Xconst char *);
extern char *xmalloc (unsigned, _Xconst char *);
extern font *define_font(FILE *file, unsigned int cmnd, font *vfparent, QIntDict<struct font> *TeXNumberTable);
/***
@ -61,49 +61,42 @@ extern font *define_font(FILE *file, unsigned int cmnd, font *vfparent, QIntDict
* The main routine
*/
void read_VF_index(font *fontp, wide_bool hushcs)
void font::read_VF_index(unsigned int hushcs)
{
FILE *VF_file = fontp->file;
kDebugInfo(DEBUG, 4300, "read_VF_index");
FILE *VF_file = file;
unsigned char cmnd;
unsigned char *avail, *availend; /* available space for macros */
long checksum;
fontp->read_char = NULL;
fontp->flags |= FONT_VIRTUAL;
fontp->set_char_p = set_vf_char;
//@@@ if (_debug & DBG_PK)
kDebugInfo("Reading VF pixel file %s", fontp->filename);
flags |= FONT_VIRTUAL;
set_char_p = set_vf_char;
kDebugInfo(DEBUG, 4300, "Reading VF pixel file %s", filename);
// Read preamble.
Fseek(VF_file, (long) one(VF_file), 1); /* skip comment */
checksum = four(VF_file);
if (!hushcs && checksum && fontp->checksum && checksum != fontp->checksum)
long file_checksum = four(VF_file);
if (!hushcs && file_checksum && checksum && file_checksum != checksum)
kDebugError("Checksum mismatch (dvi = %lu, vf = %lu) in font file %s",
fontp->checksum, checksum, fontp->filename);
checksum, file_checksum, filename);
(void) four(VF_file); /* skip design size */
// Read the fonts.
/*@@@
fontp->vf_table = (struct font **)xmalloc(VFTABLELEN * sizeof(struct font *), "table of VF TeXnumbers");
bzero((char *) fontp->vf_table, VFTABLELEN * sizeof(struct font *));
fontp->vf_chain = NULL;
*/
fontp->first_font = NULL;
first_font = NULL;
while ((cmnd = one(VF_file)) >= FNTDEF1 && cmnd <= FNTDEF4) {
struct font *newfontp = define_font(VF_file, cmnd, fontp, &(fontp->vf_table));
if (fontp->first_font == NULL)
fontp->first_font = newfontp;
struct font *newfontp = define_font(VF_file, cmnd, this, &(vf_table));
if (first_font == NULL)
first_font = newfontp;
}
// Prepare macro array.
fontp->macro = (struct macro *) xmalloc(256 * sizeof(struct macro),"macro array");
bzero((char *) fontp->macro, 256 * sizeof(struct macro));
macrotable = (macro *)xmalloc(max_num_of_chars_in_font*sizeof(macro),"macro table");
bzero((char *) macrotable, max_num_of_chars_in_font*sizeof(macro));
// Read macros.
avail = availend = NULL;
for (; cmnd <= LONG_CHAR; cmnd = one(VF_file)) {
register struct macro *m;
macro *m;
int len;
unsigned long cc;
long width;
@ -113,7 +106,7 @@ void read_VF_index(font *fontp, wide_bool hushcs)
cc = four(VF_file);
width = four(VF_file);
if (cc >= 256) {
kDebugError(TRUE,4300,"Virtual character %lu in font %s ignored.", cc, fontp->fontname);
kDebugError(TRUE,4300,"Virtual character %lu in font %s ignored.", cc, fontname);
Fseek(VF_file, (long) len, 1);
continue;
}
@ -122,8 +115,8 @@ void read_VF_index(font *fontp, wide_bool hushcs)
cc = one(VF_file);
width = num(VF_file, 3);
}
m = &fontp->macro[cc];
m->dvi_adv = width * fontp->dimconv;
m = &macrotable[cc];
m->dvi_adv = (int)(width * dimconv + 0.5);
if (len > 0) {
if (len <= availend - avail) {
m->pos = avail;
@ -131,11 +124,11 @@ void read_VF_index(font *fontp, wide_bool hushcs)
} else {
m->free_me = True;
if (len <= VF_PARM_1) {
m->pos = avail = (unsigned char *) xmalloc(VF_PARM_2, "macro array");
m->pos = avail = (unsigned char *)xmalloc(VF_PARM_2*sizeof(unsigned char ),"unknown");
availend = avail + VF_PARM_2;
avail += len;
} else
m->pos = (unsigned char *) xmalloc((unsigned) len, "macro array");
m->pos = (unsigned char *)xmalloc(len*sizeof(unsigned char),"unknown");
}
Fread((char *) m->pos, 1, len, VF_file);
m->end = m->pos + len;
@ -147,5 +140,5 @@ void read_VF_index(font *fontp, wide_bool hushcs)
Fclose (VF_file);
n_files_left++;
fontp->file = NULL;
file = NULL;
}

14
xdvi.h
View file

@ -224,17 +224,7 @@ extern long *page_offset;
extern Boolean hush_spec_now;
#define FONT_IN_USE 1 /* used for housekeeping */
#define FONT_LOADED 2 /* if font file has been read */
#define FONT_VIRTUAL 4 /* if font is virtual */
//#define TNTABLELEN 30 /* length of TeXnumber array (dvi file) */
//#define VFTABLELEN 5 /* length of TeXnumber array (virtual fonts) */
extern QIntDict<struct font> tn_table;
//@@@extern struct font *tn_table[TNTABLELEN];
//extern struct tn *tn_head INIT(NULL);
extern struct font *font_head INIT(NULL);
extern unsigned char maxchar;
@ -371,16 +361,12 @@ extern void put_border ARGS((int, int, unsigned int, unsigned int));
extern void set_char ARGS((unsigned int, unsigned int));
extern void load_n_set_char ARGS((unsigned int, unsigned int));
extern void set_vf_char ARGS((unsigned int, unsigned int));
extern void init_font_open ARGS((void));
extern void applicationDoSpecial ARGS((char *));
extern NORETURN void oops(_Xconst char *, ...);
extern void alloc_bitmap ARGS((struct bitmap *));
extern int xpipe ARGS((int *));
extern unsigned long num ARGS((FILE *, int));
extern long snum ARGS((FILE *, int));
extern void read_PK_index ARGS((struct font *, wide_bool));
extern void read_GF_index ARGS((struct font *, wide_bool));
extern void read_VF_index ARGS((struct font *, wide_bool));
extern void drawbegin_none ARGS((int, int, char *));