Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/dvi/dvilib
diff options
context:
space:
mode:
authorSoeren Sandmann <sandmann@redhat.com>2004-12-22 16:04:45 (GMT)
committer Søren Sandmann Pedersen <ssp@src.gnome.org>2004-12-22 16:04:45 (GMT)
commit08d37ab642e8cb80774a87270fd6a3f9fab783fb (patch)
tree1c05b53c93197c3ae3cf6350aea587f0b30a28b6 /dvi/dvilib
parent08dc4040951ec1e3945e07107d008a4ce7c928c9 (diff)
Auto*ify dvi and dvi/dvilib
Tue Dec 21 21:45:43 2004 Soeren Sandmann <sandmann@redhat.com> * Makefile.am: * dvi/dvilib/Makefile.am: * dvi/Makefile.am: * configure.ac: Auto*ify dvi and dvi/dvilib * dvi/Makefile: Remove from CVS * dvi/dvilib/dl-pkfont.cc (unpack_bitmap): Fix uchar/uint confusion. * dvi/dvilib/dl-fontdefinition.{cc,hh}: New DviFontMap class * dvi/dvilib/dl-vffont.{cc,hh}: Many bugfixes to VF code.
Diffstat (limited to 'dvi/dvilib')
-rw-r--r--dvi/dvilib/TODO6
-rwxr-xr-xdvi/dvilib/dl-dvi-file.cc2
-rwxr-xr-xdvi/dvilib/dl-dvi-file.hh43
-rwxr-xr-xdvi/dvilib/dl-dvi-fontdefinition.cc37
-rwxr-xr-xdvi/dvilib/dl-dvi-fontdefinition.hh14
-rwxr-xr-xdvi/dvilib/dl-dvi-parser.cc19
-rwxr-xr-xdvi/dvilib/dl-dvi-program.hh2
-rwxr-xr-xdvi/dvilib/dl-dvi-runtime.hh2
-rwxr-xr-xdvi/dvilib/dl-pkfont.cc44
-rwxr-xr-xdvi/dvilib/dl-pkfont.hh4
-rwxr-xr-xdvi/dvilib/dl-vffont.cc35
-rwxr-xr-xdvi/dvilib/dl-vffont.hh17
12 files changed, 178 insertions, 47 deletions
diff --git a/dvi/dvilib/TODO b/dvi/dvilib/TODO
index fb58cb3..dc86f1d 100644
--- a/dvi/dvilib/TODO
+++ b/dvi/dvilib/TODO
@@ -1,2 +1,8 @@
- Add a cache so we don't call kpsewhich for each font
- possibly make cache persistent so we don't have to call kpsewhich on startup
+- Why doesn't '6' get rendered in fest.dvi
+- Get rid of exceptions
+- Get rid of "blah (blah)" initializations
+- Get rid of references
+- Audit for memory leaks
+- Move stuff out of header files
diff --git a/dvi/dvilib/dl-dvi-file.cc b/dvi/dvilib/dl-dvi-file.cc
index 1739be9..46a206e 100755
--- a/dvi/dvilib/dl-dvi-file.cc
+++ b/dvi/dvilib/dl-dvi-file.cc
@@ -43,7 +43,7 @@ DviFile::get_page (uint n)
loader.goto_from_start (header->address + 45);
program = parser.parse_program ();
- page = new DviPage (*header, *program);
+ page = new DviPage (*program, header->count, postamble->fontmap);
}
return page;
diff --git a/dvi/dvilib/dl-dvi-file.hh b/dvi/dvilib/dl-dvi-file.hh
index d6c0201..bcc90aa 100755
--- a/dvi/dvilib/dl-dvi-file.hh
+++ b/dvi/dvilib/dl-dvi-file.hh
@@ -8,44 +8,50 @@
#include "dl-dvi-fontdefinition.hh"
#include "dl-loader.hh"
-namespace DviLib {
+namespace DviLib
+{
const uint N_PAGE_COUNTERS = 10; // \count0 ... \count9
- class DviPageHeader : public RefCounted {
+ class DviPageHeader : public RefCounted
+ {
public:
int count[N_PAGE_COUNTERS];
uint address; // address of this page, not the preceding
};
- class DviPage : public AbstractDviProgram {
+ class DviPage : public AbstractDviProgram
+ {
DviProgram& program;
+ DviFontMap *fontmap;
int count[N_PAGE_COUNTERS]; // \count0 ... \count9
public:
- DviPage (DviProgram& p, int c[N_PAGE_COUNTERS]) :
+ DviPage (DviProgram& p, int c[N_PAGE_COUNTERS], DviFontMap *fontmap) :
program (p)
{
- for (uint i=0; i<N_PAGE_COUNTERS; ++i)
+ this->fontmap = fontmap;
+ this->fontmap->ref();
+ for (uint i = 0; i < N_PAGE_COUNTERS; ++i)
count[i] = c[i];
}
- DviPage (DviPageHeader& h, DviProgram& p) :
- program (p)
- {
- for (uint i=0; i<N_PAGE_COUNTERS; ++i)
- count[i] = h.count[i];
- }
virtual void execute (DviRuntime& runtime)
{
+ runtime.push();
+ runtime.fontmap (fontmap);
+ cout << "page " << (int)fontmap << endl;
program.execute (runtime);
+ runtime.pop();
}
int get_page_count (int i) { return count[i]; }
};
- enum DviType {
+ enum DviType
+ {
NORMAL_DVI = 2, // FIXME: this should be 2
TEX_XET_DVI = 2 // FIXME: is this correct?
};
- class DviFilePreamble : public RefCounted {
+ class DviFilePreamble : public RefCounted
+ {
public:
// preamble
DviType type;
@@ -55,7 +61,8 @@ namespace DviLib {
string comment;
};
- class DviFilePostamble : public RefCounted {
+ class DviFilePostamble : public RefCounted
+ {
public:
// postamble
DviType type;
@@ -67,10 +74,12 @@ namespace DviLib {
uint max_height;
uint max_width;
uint stack_height;
- map <uint, DviFontdefinition *> fontdefinitions;
+
+ DviFontMap *fontmap;
};
- class DviFile : public RefCounted {
+ class DviFile : public RefCounted
+ {
AbstractLoader &loader;
DviFilePreamble *preamble;
@@ -87,7 +96,7 @@ namespace DviLib {
uint get_n_pages () { return n_pages; }
DviFontdefinition *get_fontdefinition (uint n)
{
- return postamble->fontdefinitions[n];
+ return postamble->fontmap->get_fontdefinition (n);
}
uint get_numerator () { return postamble->numerator; }
uint get_denominator () { return postamble->denominator; }
diff --git a/dvi/dvilib/dl-dvi-fontdefinition.cc b/dvi/dvilib/dl-dvi-fontdefinition.cc
index 553ea28..6a4979b 100755
--- a/dvi/dvilib/dl-dvi-fontdefinition.cc
+++ b/dvi/dvilib/dl-dvi-fontdefinition.cc
@@ -1,3 +1,40 @@
#include "dl-dvi-fontdefinition.hh"
+#include <iostream>
+
using namespace DviLib;
+
+DviFontdefinition *
+DviFontMap::get_fontdefinition (int fontnum)
+{
+ cout << "getting fontnum " << fontnum << endl;
+ return fontmap[fontnum];
+}
+
+void
+DviFontMap::set_fontdefinition (int fontnum,
+ DviFontdefinition *fd)
+{
+ fd->ref();
+
+
+ cout << "froot " << fontnum << (int)this << endl;
+
+ if (fontmap[fontnum])
+ {
+ cout << "blah" << endl;
+ fontmap[fontnum]->unref();
+ }
+
+ fontmap[fontnum] = fd;
+}
+
+DviFontMap::~DviFontMap ()
+{
+ typedef map <int, DviFontdefinition *>::iterator It;
+
+ for (It i = fontmap.begin(); i != fontmap.end(); ++i)
+ {
+ (*i).second->unref();
+ }
+}
diff --git a/dvi/dvilib/dl-dvi-fontdefinition.hh b/dvi/dvilib/dl-dvi-fontdefinition.hh
index e6bb0d6..cc6bfd2 100755
--- a/dvi/dvilib/dl-dvi-fontdefinition.hh
+++ b/dvi/dvilib/dl-dvi-fontdefinition.hh
@@ -2,12 +2,14 @@
#define DL_FONT_DEFINITION_HH__
#include <string>
+#include <map>
#include "dl-refcounted.hh"
namespace DviLib {
-
- class DviFontdefinition : public RefCounted {
+
+ class DviFontdefinition : public RefCounted
+ {
public:
uint fontnum;
uint checksum;
@@ -18,5 +20,13 @@ namespace DviLib {
string name;
};
+ class DviFontMap : public RefCounted
+ {
+ public:
+ std::map <int, DviFontdefinition *> fontmap;
+ DviFontdefinition *get_fontdefinition (int fontnum);
+ void set_fontdefinition (int fontnum, DviFontdefinition *fd);
+ DviFontMap::~DviFontMap ();
+ };
}
#endif // DL_FONT_DEFINITION_HH__
diff --git a/dvi/dvilib/dl-dvi-parser.cc b/dvi/dvilib/dl-dvi-parser.cc
index 7caac02..e437261 100755
--- a/dvi/dvilib/dl-dvi-parser.cc
+++ b/dvi/dvilib/dl-dvi-parser.cc
@@ -358,7 +358,9 @@ DviParser::parse_program (uint n_bytes)
cmd = parse_command (loader, &count, &opcode);
if (cmd)
{
+#if 0
cout << opcode << endl;
+#endif
program->add_command (cmd);
cmd->unref();
}
@@ -420,12 +422,14 @@ DviParser::parse_fontdefinition (void)
fontdef->directory = "";
fontdef->name = "";
- for (uint i=0; i<dirlength; ++i)
+ for (uint i=0; i < dirlength; ++i)
fontdef->directory += loader.get_uint8();
- for (uint i=0; i<namelength; ++i)
+ for (uint i=0; i < namelength; ++i)
fontdef->name += loader.get_uint8();
+#if 0
cout << "parsed fd: " << fontdef->name << " " << fontdef->fontnum << endl;
+#endif
return fontdef;
}
@@ -462,6 +466,8 @@ DviFilePostamble *
DviParser::parse_postamble (void)
{
DviFilePostamble *postamble = new DviFilePostamble;
+
+ postamble->fontmap = new DviFontMap;
loader.goto_from_end (-5);
@@ -497,9 +503,9 @@ DviParser::parse_postamble (void)
loader.goto_from_current (-1);
DviFontdefinition *fd = parse_fontdefinition ();
- postamble->fontdefinitions[fd->fontnum] = fd;
+ postamble->fontmap->set_fontdefinition (fd->fontnum, fd);
cout << fd->name << endl;
- cout << postamble->fontdefinitions[fd->fontnum]->name;
+ cout << postamble->fontmap->get_fontdefinition(fd->fontnum)->name;
}
else
{
@@ -515,6 +521,8 @@ DviParser::parse_vf_font_preamble (void)
{
DviOpcode c;
VfFontPreamble *preamble = new VfFontPreamble;
+
+ preamble->fontmap = new DviFontMap;
c = (DviOpcode)loader.get_uint8 ();
if (c != DVI_PRE)
@@ -527,6 +535,7 @@ DviParser::parse_vf_font_preamble (void)
preamble->checksum = loader.get_uint32 ();
preamble->design_size = loader.get_uint32 ();
+ int i = 0;
while (true)
{
DviOpcode c = (DviOpcode)loader.get_uint8 ();
@@ -536,7 +545,7 @@ DviParser::parse_vf_font_preamble (void)
loader.goto_from_current (-1);
DviFontdefinition *fd = parse_fontdefinition ();
- preamble->fontdefinitions.push_back (fd);
+ preamble->fontmap->set_fontdefinition (i++, fd);
}
else
{
diff --git a/dvi/dvilib/dl-dvi-program.hh b/dvi/dvilib/dl-dvi-program.hh
index afe5fdb..1424b0a 100755
--- a/dvi/dvilib/dl-dvi-program.hh
+++ b/dvi/dvilib/dl-dvi-program.hh
@@ -77,7 +77,9 @@ namespace DviLib
public:
DviRuleCommand (int h_arg, int w_arg) : h(h_arg), w(w_arg)
{
+#if 0
std::cout << "rule cmd " << h << " " << w << std::endl;
+#endif
}
int get_h (void) const { return h; }
int get_w (void) const { return w; }
diff --git a/dvi/dvilib/dl-dvi-runtime.hh b/dvi/dvilib/dl-dvi-runtime.hh
index abb8c71..ff9df5e 100755
--- a/dvi/dvilib/dl-dvi-runtime.hh
+++ b/dvi/dvilib/dl-dvi-runtime.hh
@@ -28,7 +28,7 @@ namespace DviLib {
virtual void y_rep () = 0; // move down y
virtual void z (int len) = 0; // move down len, set z = len
virtual void z_rep () = 0; // move down z
- virtual void push_fontmap (std::map<int, DviFontdefinition *> fontmap) = 0;
+ virtual void fontmap (DviFontMap *fontmap) = 0; // set fontmap
virtual void font_num (int num) = 0; // f = num
virtual void special (std::string spc) = 0; // do something special
diff --git a/dvi/dvilib/dl-pkfont.cc b/dvi/dvilib/dl-pkfont.cc
index 2544e35..409d531 100755
--- a/dvi/dvilib/dl-pkfont.cc
+++ b/dvi/dvilib/dl-pkfont.cc
@@ -189,21 +189,31 @@ PkChar::unpack_bitmap (void)
{
uint i, weight;
- uchar *bitmap
- = new uchar [4 * width * height];
- fill (bitmap, bitmap + 4 * width * height, 0xFF);
+ uint *bitmap
+ = new uint [width * height];
+ fill (bitmap, bitmap + width * height, 0x00000000);
weight = 128;
- for (i=0; i < height * width; i+=4)
+ for (i=0; i < height * width; i++)
{
if ((*data.packed & weight) != 0)
- bitmap[i] = bitmap[i+1] =
- bitmap[i+2] = bitmap[i+3] = 0x00;
- weight = (weight == 1)?
- (data.packed++, 128) : weight >> 1;
+ {
+ bitmap[i] = 0xff000000;
+ }
+
+ if (weight == 1)
+ {
+ weight = 128;
+ data.packed++;
+ }
+ else
+ {
+ weight >>= 1;
+ }
}
- data.bitmap = bitmap;
+
+ data.bitmap = (uchar *)bitmap;
}
void
@@ -213,7 +223,9 @@ PkChar::unpack (void)
return;
if (dyn_f == 14)
+ {
unpack_bitmap();
+ }
else
{
Bitmap bitmap (width, height);
@@ -222,9 +234,17 @@ PkChar::unpack (void)
first_is_black? BLACK : WHITE,
bitmap);
unpack_rle (nr);
- unpacked = true;
data.bitmap = bitmap.steal_pixels ();
+
+#if 0
+ if (character_code == '6')
+ cout << "HERER" << endl;
+ else
+ cout << '[' << character_code << " not " << (int)'6' << ']' << endl;
+#endif
}
+
+ unpacked = true;
}
PkChar::PkChar (AbstractLoader &loader)
@@ -257,9 +277,13 @@ PkChar::PkChar (AbstractLoader &loader)
case 4: case 5: case 6:
/* extended short preamble */
length = loader.get_uint16 () + ((flag_byte & 3) << 16) - 13;
+#if 0
cout << length;
+#endif
character_code = loader.get_uint8 ();
+#if 0
cout << ',' << character_code;
+#endif
tfm_width = loader.get_uint24 ();
dx = loader.get_uint16 () << 16;
dy = 0;
diff --git a/dvi/dvilib/dl-pkfont.hh b/dvi/dvilib/dl-pkfont.hh
index 66cd69b..ec09148 100755
--- a/dvi/dvilib/dl-pkfont.hh
+++ b/dvi/dvilib/dl-pkfont.hh
@@ -17,7 +17,8 @@ namespace DviLib {
REPEAT_COUNT
};
- class PkChar : public AbstractCharacter {
+ class PkChar : public AbstractCharacter
+ {
uint dyn_f;
bool first_is_black; // if first run count is black or white
int character_code;
@@ -39,6 +40,7 @@ namespace DviLib {
void unpack_rle (RleContext& nr);
void unpack_bitmap (void);
void unpack (void);
+
public:
PkChar (AbstractLoader &l);
virtual void paint (DviRuntime &runtime);
diff --git a/dvi/dvilib/dl-vffont.cc b/dvi/dvilib/dl-vffont.cc
index 91109d8..36d570f 100755
--- a/dvi/dvilib/dl-vffont.cc
+++ b/dvi/dvilib/dl-vffont.cc
@@ -3,14 +3,39 @@
using namespace DviLib;
-VfFont::VfFont (AbstractLoader &l, int at_size_arg) :
- at_size (at_size_arg)
+void
+VfFont::fixup_fontmap (DviFontMap *fontmap)
{
- DviParser parser (l);
- preamble = parser.parse_vf_font_preamble ();
+ typedef std::map<int, DviFontdefinition *>::iterator It;
+ for (It i = fontmap->fontmap.begin(); i != fontmap->fontmap.end(); ++i)
+ {
+ (*i).second->at_size = ((*i).second->at_size / 1048576.0) * preamble->design_size;
+#if 0
+ (*i).second->design_size = 1048576;
+#endif
+ }
+}
+VfFont::VfFont (AbstractLoader &l,
+ int at_size_arg)
+{
+ at_size = at_size_arg;
+ DviParser parser (l);
+ preamble = parser.parse_vf_font_preamble();
+
VfChar *ch;
- while ((ch = parser.parse_vf_char ()) != NULL)
+ while ((ch = parser.parse_vf_char()) != NULL)
+ {
chars[ch->character_code] = ch;
+ ch->fontmap = preamble->fontmap;
+ }
+
+ /* fixup fontmap
+ *
+ * FIXME: I don't think this is correct, but vftovp.web isn't
+ * totally clear on the issue
+ */
+
+ fixup_fontmap (preamble->fontmap);
}
diff --git a/dvi/dvilib/dl-vffont.hh b/dvi/dvilib/dl-vffont.hh
index 185e4a9..fff490b 100755
--- a/dvi/dvilib/dl-vffont.hh
+++ b/dvi/dvilib/dl-vffont.hh
@@ -7,33 +7,41 @@
namespace DviLib {
- class VfChar : public AbstractCharacter {
+ class VfChar : public AbstractCharacter
+ {
public:
int tfm_width;
DviProgram *program;
+ DviFontMap *fontmap;
int character_code;
virtual void paint (DviRuntime& runtime)
{
runtime.push();
+ runtime.fontmap (fontmap);
+ runtime.font_num (0);
+ cout << "vfchar (" << (int)fontmap << ')' << " " << character_code << endl;
program->execute (runtime); // FIXME push, pop, etc.
runtime.pop();
}
virtual int get_tfm_width () { return tfm_width; }
};
- class VfFontPreamble : public RefCounted {
+ class VfFontPreamble : public RefCounted
+ {
public:
string comment;
uint checksum;
uint design_size;
- vector <DviFontdefinition *> fontdefinitions;
+ DviFontMap *fontmap;
};
- class VfFont : public AbstractFont {
+ class VfFont : public AbstractFont
+ {
VfFontPreamble *preamble;
map <int, VfChar *> chars;
int at_size;
+ void fixup_fontmap (DviFontMap *fontmap);
public:
VfFont (AbstractLoader& l, int at_size);
virtual VfChar *get_char (int ccode)
@@ -46,7 +54,6 @@ namespace DviLib {
}
virtual int get_at_size ()
{
- /* FIXME (what is the correct thing to do here?) */
return at_size;
}
virtual ~VfFont () {}