2000-05-26 00:00:15 +00:00
|
|
|
|
|
|
|
|
2000-11-25 15:31:29 +00:00
|
|
|
|
|
|
|
#include <kdebug.h>
|
2000-07-08 11:10:43 +00:00
|
|
|
#include <klocale.h>
|
2000-05-26 00:00:15 +00:00
|
|
|
#include <malloc.h>
|
2000-11-25 15:31:29 +00:00
|
|
|
#include <qapplication.h>
|
2001-11-08 09:40:14 +00:00
|
|
|
#include <qfile.h>
|
2000-11-25 15:31:29 +00:00
|
|
|
#include <stdio.h>
|
2001-02-11 16:38:10 +00:00
|
|
|
#include <stdlib.h>
|
2000-05-26 00:00:15 +00:00
|
|
|
|
2000-11-26 12:33:45 +00:00
|
|
|
#include "dviwin.h"
|
2000-05-26 00:00:15 +00:00
|
|
|
#include "font.h"
|
2000-11-25 15:31:29 +00:00
|
|
|
#include "kdvi.h"
|
2000-05-26 00:00:15 +00:00
|
|
|
|
|
|
|
#include "oconfig.h"
|
|
|
|
|
2000-06-14 04:15:22 +00:00
|
|
|
extern void oops(QString message);
|
2001-03-28 10:16:48 +00:00
|
|
|
|
2000-05-26 00:00:15 +00:00
|
|
|
|
2000-11-25 15:31:29 +00:00
|
|
|
#define PK_PRE 247
|
|
|
|
#define PK_ID 89
|
|
|
|
#define PK_MAGIC (PK_PRE << 8) + PK_ID
|
|
|
|
#define GF_PRE 247
|
|
|
|
#define GF_ID 131
|
|
|
|
#define GF_MAGIC (GF_PRE << 8) + GF_ID
|
|
|
|
#define VF_PRE 247
|
|
|
|
#define VF_ID_BYTE 202
|
|
|
|
#define VF_MAGIC (VF_PRE << 8) + VF_ID_BYTE
|
2000-05-26 00:00:15 +00:00
|
|
|
|
2002-04-22 18:47:09 +00:00
|
|
|
const int font::max_num_of_chars_in_font = 256;
|
|
|
|
|
2002-08-05 16:21:06 +00:00
|
|
|
macro::macro()
|
|
|
|
{
|
2002-08-07 15:28:21 +00:00
|
|
|
pos = 0L; /* address of first byte of macro */
|
|
|
|
end = 0L; /* address of last+1 byte */
|
2002-08-05 16:21:06 +00:00
|
|
|
dvi_adv = 0; /* DVI units to move reference point */
|
2002-08-07 15:28:21 +00:00
|
|
|
free_me = false;
|
2002-08-05 16:21:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
macro::~macro()
|
|
|
|
{
|
|
|
|
if ((pos != 0L) && (free_me == true))
|
|
|
|
delete [] pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-15 15:11:36 +00:00
|
|
|
void font::fontNameReceiver(QString fname)
|
2000-05-26 00:00:15 +00:00
|
|
|
{
|
2000-11-25 15:31:29 +00:00
|
|
|
flags |= font::FONT_LOADED;
|
2000-05-26 00:00:15 +00:00
|
|
|
|
2001-03-15 15:11:36 +00:00
|
|
|
filename = fname;
|
2000-05-26 00:00:15 +00:00
|
|
|
|
2001-03-02 21:02:45 +00:00
|
|
|
#ifdef DEBUG_FONT
|
2000-11-25 15:31:29 +00:00
|
|
|
kdDebug() << "FONT NAME RECEIVED:" << filename << endl;
|
2001-03-02 21:02:45 +00:00
|
|
|
#endif
|
2000-11-25 15:31:29 +00:00
|
|
|
|
2001-11-14 16:18:22 +00:00
|
|
|
file = fopen(QFile::encodeName(filename), "r");
|
2000-11-25 15:31:29 +00:00
|
|
|
if (file == NULL) {
|
|
|
|
kdError() << i18n("Can't find font ") << fontname << "." << endl;
|
2000-11-25 19:06:22 +00:00
|
|
|
return;
|
2000-11-25 15:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_char_p = &dviWindow::set_char;
|
|
|
|
int magic = two(file);
|
|
|
|
|
2000-11-26 12:33:45 +00:00
|
|
|
if (magic == PK_MAGIC) {
|
|
|
|
// Achtung! Read_PK_index kann auch schiefgehen!
|
2000-11-25 15:31:29 +00:00
|
|
|
read_PK_index();
|
2000-11-26 12:33:45 +00:00
|
|
|
set_char_p = &dviWindow::set_char;
|
|
|
|
} else
|
2000-11-25 15:31:29 +00:00
|
|
|
if (magic == GF_MAGIC)
|
2002-06-19 21:50:01 +00:00
|
|
|
oops(QString(i18n("The GF format for font file %1 is no longer supported")).arg(filename) );
|
2000-11-25 15:31:29 +00:00
|
|
|
else
|
2000-11-26 12:33:45 +00:00
|
|
|
if (magic == VF_MAGIC) {
|
2000-11-25 15:31:29 +00:00
|
|
|
read_VF_index();
|
2000-11-26 12:33:45 +00:00
|
|
|
set_char_p = &dviWindow::set_vf_char;
|
|
|
|
} else
|
2002-06-19 21:50:01 +00:00
|
|
|
oops(QString(i18n("Cannot recognize format for font file %1")).arg(filename) );
|
2000-11-25 15:31:29 +00:00
|
|
|
}
|
2000-05-26 00:00:15 +00:00
|
|
|
|
|
|
|
|
2001-10-27 11:38:16 +00:00
|
|
|
font::font(char *nfontname, float nfsize, long chk, Q_INT32 scale, double dconv, class fontPool *pool)
|
2000-05-26 00:00:15 +00:00
|
|
|
{
|
2000-06-09 05:31:11 +00:00
|
|
|
#ifdef DEBUG_FONT
|
2000-06-05 10:49:44 +00:00
|
|
|
kdDebug() << "constructing font " << nfontname << " at " << (int) (nfsize + 0.5) << " dpi" << endl;
|
2000-06-09 05:31:11 +00:00
|
|
|
#endif
|
2000-05-26 00:00:15 +00:00
|
|
|
|
2001-10-27 11:38:16 +00:00
|
|
|
font_pool = pool;
|
|
|
|
fontname = nfontname;
|
|
|
|
fsize = nfsize;
|
|
|
|
checksum = chk;
|
|
|
|
flags = font::FONT_IN_USE;
|
|
|
|
file = NULL;
|
|
|
|
filename = "";
|
|
|
|
dimconv = dconv;
|
|
|
|
scaled_size = scale;
|
2000-11-26 12:33:45 +00:00
|
|
|
|
2001-10-27 11:38:16 +00:00
|
|
|
glyphtable = 0;
|
|
|
|
macrotable = 0;
|
2001-03-02 21:02:45 +00:00
|
|
|
|
2000-11-26 12:33:45 +00:00
|
|
|
// By default, this font contains only empty characters. After the
|
2001-03-02 21:02:45 +00:00
|
|
|
// font has been loaded, this function pointer will be replaced by
|
|
|
|
// another one.
|
2001-10-27 11:38:16 +00:00
|
|
|
set_char_p = &dviWindow::set_empty_char;
|
2000-05-26 00:00:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
font::~font()
|
|
|
|
{
|
2000-06-09 05:31:11 +00:00
|
|
|
#ifdef DEBUG_FONT
|
2000-06-05 10:49:44 +00:00
|
|
|
kdDebug() << "discarding font " << fontname << " at " << (int)(fsize + 0.5) << " dpi" << endl;
|
2000-06-09 05:31:11 +00:00
|
|
|
#endif
|
2000-05-26 00:00:15 +00:00
|
|
|
|
2001-03-02 21:02:45 +00:00
|
|
|
if (fontname != 0)
|
2002-07-31 16:39:39 +00:00
|
|
|
delete [] fontname;
|
|
|
|
if (glyphtable != 0)
|
|
|
|
delete [] glyphtable;
|
|
|
|
if (macrotable != 0)
|
|
|
|
delete [] macrotable;
|
2000-05-26 00:00:15 +00:00
|
|
|
|
|
|
|
if (flags & FONT_LOADED) {
|
2001-03-28 10:16:48 +00:00
|
|
|
if (file != NULL)
|
2000-05-26 00:00:15 +00:00
|
|
|
fclose(file);
|
2002-07-31 16:39:39 +00:00
|
|
|
if (flags & FONT_VIRTUAL)
|
2000-05-26 00:00:15 +00:00
|
|
|
vf_table.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** mark_as_used marks the font, and all the fonts it referrs to, as
|
2000-05-27 05:05:03 +00:00
|
|
|
used, i.e. their FONT_IN_USE-flag is set. */
|
2000-05-26 00:00:15 +00:00
|
|
|
|
|
|
|
void font::mark_as_used(void)
|
|
|
|
{
|
2000-06-09 05:31:11 +00:00
|
|
|
#ifdef DEBUG_FONT
|
|
|
|
kdDebug() << "marking font " << fontname << " at " << (int) (fsize + 0.5) << " dpi" << endl;
|
|
|
|
#endif
|
|
|
|
|
2000-11-25 15:31:29 +00:00
|
|
|
if (flags & font::FONT_IN_USE)
|
2000-05-26 00:00:15 +00:00
|
|
|
return;
|
|
|
|
|
2000-05-27 05:05:03 +00:00
|
|
|
flags |= font::FONT_IN_USE;
|
2000-05-26 00:00:15 +00:00
|
|
|
|
|
|
|
// For virtual fonts, also go through the list of referred fonts
|
2000-05-27 05:05:03 +00:00
|
|
|
if (flags & font::FONT_VIRTUAL) {
|
2000-05-26 00:00:15 +00:00
|
|
|
QIntDictIterator<font> it(vf_table);
|
|
|
|
while( it.current() ) {
|
2000-05-27 05:05:03 +00:00
|
|
|
it.current()->flags |= font::FONT_IN_USE;
|
2000-05-26 00:00:15 +00:00
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-05-27 05:05:03 +00:00
|
|
|
|
|
|
|
/** 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) {
|
2000-07-13 15:50:19 +00:00
|
|
|
kdError() << i18n("Character %1 not defined in font %2").arg(ch).arg(fontname) << endl;
|
2000-05-27 05:05:03 +00:00
|
|
|
g->addr = -1;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (g->addr == -1)
|
|
|
|
return NULL; /* previously flagged missing char */
|
|
|
|
|
|
|
|
if (file == NULL) {
|
2001-11-14 16:18:22 +00:00
|
|
|
file = fopen(QFile::encodeName(filename), "r");
|
2000-05-27 05:05:03 +00:00
|
|
|
if (file == NULL) {
|
2000-07-08 11:10:43 +00:00
|
|
|
oops(QString(i18n("Font file disappeared: %1")).arg(filename) );
|
2000-05-27 05:05:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2001-11-14 16:18:22 +00:00
|
|
|
fseek(file, g->addr, 0);
|
2000-05-27 05:05:03 +00:00
|
|
|
read_PK_char(ch);
|
|
|
|
|
|
|
|
if (g->bitmap.bits == NULL) {
|
|
|
|
g->addr = -1;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return g;
|
|
|
|
}
|
2001-05-04 01:40:07 +00:00
|
|
|
#include "font.moc"
|