]> www.fi.muni.cz Git - evince.git/commitdiff
Auto*ify dvi and dvi/dvilib
authorSoeren Sandmann <sandmann@redhat.com>
Wed, 22 Dec 2004 16:04:45 +0000 (16:04 +0000)
committerSøren Sandmann Pedersen <ssp@src.gnome.org>
Wed, 22 Dec 2004 16:04:45 +0000 (16:04 +0000)
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.

20 files changed:
ChangeLog
Makefile.am
configure.ac
dvi/Makefile [deleted file]
dvi/dvilib/TODO
dvi/dvilib/dl-dvi-file.cc
dvi/dvilib/dl-dvi-file.hh
dvi/dvilib/dl-dvi-fontdefinition.cc
dvi/dvilib/dl-dvi-fontdefinition.hh
dvi/dvilib/dl-dvi-parser.cc
dvi/dvilib/dl-dvi-program.hh
dvi/dvilib/dl-dvi-runtime.hh
dvi/dvilib/dl-pkfont.cc
dvi/dvilib/dl-pkfont.hh
dvi/dvilib/dl-vffont.cc
dvi/dvilib/dl-vffont.hh
dvi/fest.tex
dvi/font.cc
dvi/painter.cc
dvi/painter.hh

index 432ad41bfa4f4d5780f441bf61e9b8e1c78f4bc4..f241e069021185f93d298118109e1bded03ae4d9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+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.
+       
 2004-12-22  Marco Pesenti Gritti  <marco@gnome.org>
 
        * ps/Makefile.am:
index a0cddce5ab0c54abc16c533642d8d12e999dc517..bc064af25205fa2192e5a9bc7a6884526fa28228 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = cut-n-paste data backend po pdf ps shell
+SUBDIRS = cut-n-paste data backend po pdf dvi ps shell
 
 intltool_extra = intltool-extract.in intltool-merge.in intltool-update.in
 
index ab87408889ae95bbcae5c7ff8b1e3b9374bb2fe2..bce7729f0ddfda5bbb4b962a1f26000036236285 100644 (file)
@@ -32,6 +32,7 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package.])
 PKG_CHECK_MODULES(LIBEVPRIVATE, gtk+-2.0 >= 2.4.0)
 PKG_CHECK_MODULES(RECENT_FILES, gtk+-2.0 >= 2.4.0 libgnomeui-2.0 >= 2.4.0)
 PKG_CHECK_MODULES(SHELL, gtk+-2.0 >= 2.5.0 libgnomeui-2.0 gnome-vfs-2.0 libgnomeprint-2.2 libgnomeprintui-2.2 libglade-2.0)
+PKG_CHECK_MODULES(DVI, gtk+-2.0 >= 2.6.0)
 PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.6.0)
 PKG_CHECK_MODULES(PS, gtk+-2.0 >= 2.6.0 gnome-vfs-2.0 libgnomeui-2.0)
 
@@ -373,4 +374,6 @@ ps/Makefile
 po/Makefile.in
 backend/Makefile
 shell/Makefile
+dvi/Makefile
+dvi/dvilib/Makefile
 ])
diff --git a/dvi/Makefile b/dvi/Makefile
deleted file mode 100644 (file)
index 3ba3611..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-binary = dviviewer
-
-sources =                                      \
-       main.cc                                 \
-                                               \
-       painter.cc                              \
-       font.cc                                 \
-       view.cc                                 \
-       model.cc                                \
-                                               \
-       dvilib/dl-dvi-file.cc                   \
-       dvilib/dl-dvi-fontdefinition.cc         \
-       dvilib/dl-dvi-parser.cc                 \
-       dvilib/dl-dvi-program.cc                \
-       dvilib/dl-dvi-runtime.cc                \
-       dvilib/dl-loader.cc                     \
-       dvilib/dl-pkfont.cc                     \
-       dvilib/dl-vffont.cc
-
-headers =                                      \
-       painter.hh                              \
-       font.hh                                 \
-       view.hh                                 \
-       model.hh                                \
-                                               \
-       dvilib/dl-dvi-file.hh                   \
-       dvilib/dl-dvi-fontdefinition.hh         \
-       dvilib/dl-dvi-parser.hh                 \
-       dvilib/dl-dvi-runtime.hh                \
-       dvilib/dl-font.hh                       \
-       dvilib/dl-loader.hh                     \
-       dvilib/dl-pkfont.hh                     \
-       dvilib/dl-vffont.hh
-
-CFLAGS = -Idvilib -Wall -W -ansi -pedantic -g -O0 `pkg-config --cflags gtk+-2.0`
-
-$(binary): $(sources) $(headers)
-       c++ $(CFLAGS) $(sources) -o$(binary) -lfl `pkg-config --libs gtk+-2.0`
index fb58cb3018014116de337e47eea0d5dfb674b427..dc86f1db574c703824077dcf2c8d517e377e1ea9 100644 (file)
@@ -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
index 1739be9d57b2c9c9a0bec2ca1dba0448fca83446..46a206ee081071bc5e11a6e5fba5fb232ad4ffcb 100755 (executable)
@@ -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;
index d6c0201cd60ff7a1ae491dffa79212b530a5d5ee..bcc90aa1c310560d4eb5aae2f94032d370d9fc31 100755 (executable)
@@ -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; }
index 553ea28768f1753ee30e4072a6b40f390a71b558..6a4979b3c823a80beea068beea21b6fbc721677b 100755 (executable)
@@ -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();
+    }
+}
index e6bb0d636758f8c18d175851ff6d4ec6ae138d9b..cc6bfd26032b91ddfeb7e09470594a8c454291aa 100755 (executable)
@@ -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__
index 7caac026676c603d209bf443c3ea4be22504b51d..e43726169cdb0dcd964a7692a6361a8df9157918 100755 (executable)
@@ -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
        {
index afe5fdbfc0737842ae8fe3c7e3f0720613da87f1..1424b0ae701e97168ab5fe2c1dd07fae0a067edb 100755 (executable)
@@ -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; }
index abb8c71cf0e2534a6eca779efe0b4361809c31ae..ff9df5e9b9dcf64281e781607cf474de7648e90c 100755 (executable)
@@ -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
        
index 2544e35da3b9534bf8470952c9858ac8592059d4..409d531a69ff1b7cbe0fb1688ce875be7ee88453 100755 (executable)
@@ -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;
index 66cd69b3e0daf8368bb10d7b894018d795bc5d6f..ec0914878b91d34ec2d6d3b1e92c4fe8e3441bb1 100755 (executable)
@@ -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);
index 91109d8843f4224633804f088a3b601a72ab30e7..36d570f9c51935637db7b2fe46a9d4571ebcaa4f 100755 (executable)
@@ -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);
 }
 
index 185e4a98c78ba810599046a1029f72755b2dc4d4..fff490b5300b2034f9a5a83b8dbdebe7ca5602ab 100755 (executable)
@@ -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 () {}
index 1ae5083d07b848309c8fbec64f729be0d9b6e8a4..92d41bd5591887a794913ac70cc9fd64d21d5c74 100644 (file)
@@ -1,10 +1,13 @@
 \documentclass[a4paper, danish]{article}
 
-\usepackage{times}
-\usepackage[T1]{fontenc}
+\usepackage{charter}
+%\usepackage[T1]{fontenc}
 \usepackage{babel}
 
 \begin{document}
+Hej verden
+
+%\end{document}
 
 \section{Title}
 
 
 \subsection {Subtitle}
 
-Math: $\sum_{i=0}^\infty \frac{1}{i^2} = \frac{\pi^2}{6}$
+Math: $6\sum_{i=0}^\infty \frac{1}{i^2} = \frac{\pi^2}{666i}$
+
+abcdefghijklmnopqrstuvwxyz
+
+ABCDEFGHIJKLMNOPQRSTUVWXYZ
+
 
 {\large\bf Big, bold\par}
 
index 512370e96c276cf5eb159fee61b0c700dafc0a09..4494b5299fb116751cddad6076afdde197ef53c4 100755 (executable)
@@ -120,6 +120,8 @@ run_mktexpk (int dpi, string name)
     char *namestr = g_strdup (name.c_str());
     char *result;
 
+    cout << "mktexpk " << bdpistr << " " << dpistr << " " << " " << namestr << " " << endl;
+    
     result = run_program ("mktexpk", NULL, bdpistr, dpistr, namestr, NULL);
     if (result)
        g_free (result);
@@ -136,6 +138,8 @@ FontFactory::create_font (std::string name,
 {
     char *filename;
 
+    cout << "at size: " << at_size << endl;
+    
     /* Find VF */
     filename = run_kpsewhich (dpi, "vf", name);
 
index a1bb7587992abcf0b6cc7c0d3187f569ce298adc..2dc57e2c46abae2f8b48e2eb478d2fb3b0cd90b0 100755 (executable)
@@ -2,6 +2,7 @@
 #include "dl-dvi-fontdefinition.hh"
 
 using DviLib::DviFontdefinition;
+using DviLib::DviFontMap;
 using DviLib::AbstractCharacter;
 
 // paint a bitmap
@@ -41,13 +42,11 @@ DviPainter::paint_bitmap (const unsigned char *data,
 void 
 DviPainter::set_char (int ch)
 {
-    g_assert (current_font);
-    
-    AbstractCharacter *character = current_font->get_char (ch);
+    AbstractCharacter *character = current_frame->font->get_char (ch);
     character->paint (* this);
     
     int tfm_width = character->get_tfm_width ();
-    int at_size = current_font->get_at_size ();
+    int at_size = current_frame->font->get_at_size ();
     int dvi_width = tfm_to_dvi (tfm_width, at_size);
     
     current_frame->h += dvi_width;
@@ -57,7 +56,7 @@ DviPainter::set_char (int ch)
 void 
 DviPainter::put_char (int ch)
 {
-    AbstractCharacter *character = current_font->get_char (ch);
+    AbstractCharacter *character = current_frame->font->get_char (ch);
     character->paint (* this);
 }
 
@@ -71,7 +70,9 @@ DviPainter::set_rule (int height,
     int x = dvi_to_pixels (current_frame->h);
     int y = dvi_to_pixels (current_frame->v);
     
+#if 0
     cout << "BIRNAN\n" << endl;
+#endif
     
     gdk_draw_rectangle (pixmap,        gc, TRUE, 
                        x, y, 
@@ -108,22 +109,40 @@ DviFrame::copy (void)
 {
     DviFrame *frame = new DviFrame ();
 
+    frame->fontmap = this->fontmap;
+    if (frame->fontmap)
+       frame->fontmap->ref();
     frame->h = this->h;
     frame->v = this->v;
     frame->w = this->w;
     frame->x = this->x;
     frame->y = this->y;
     frame->z = this->z;
-
+    frame->font = this->font;
+    if (frame->font)
+       frame->font->ref();
+    
     return frame;
 }
 
+DviFrame::~DviFrame()
+{
+    if (this->fontmap)
+       this->fontmap->unref();
+    if (this->font)
+       this->font->unref();
+}
+
 void 
 DviPainter::push (void)
 {
     DviFrame *new_frame = current_frame->copy();
     new_frame->next = current_frame;
     current_frame = new_frame;
+    if (current_frame->font)
+       cout << "push: there is a font" << endl;
+    else
+       cout << "push: there is not a font" << endl;
 }
 
 // pop ccontext
@@ -132,8 +151,18 @@ DviPainter::pop (void)
 {
     DviFrame *old_frame = current_frame;
 
+    // FIXME: dvi assumes that fonts survive pops
+    // FIXME: however, do they also survive the final pop of a vfchar?
+    
     current_frame = current_frame->next;
 
+    if (current_frame && current_frame->font)
+       cout << "pop: there is a font" << endl;
+    else if (current_frame)
+       cout << "pop: there is not font" << endl;
+    else
+       cout << "no current" << endl;
+    
     old_frame->unref();
 }
 
@@ -215,9 +244,8 @@ DviPainter::z_rep ()
 void 
 DviPainter::font_num (int font_num)
 {
-    cout << "get fno " << font_num << endl;
-    DviFontdefinition *fd = dvi_file->get_fontdefinition (font_num);
-    
+    DviFontdefinition *fd = current_frame->fontmap->get_fontdefinition (font_num);
+
     g_assert (fd);
     if (fd)
     {
@@ -225,10 +253,18 @@ DviPainter::font_num (int font_num)
        int dpi = (int)floor( 0.5 + 1.0 * base_dpi * 
                              dvi_file->get_magnification() * fd->at_size /
                              ( 1000.0 * fd->design_size));
-       cout << "fno: " << fd->fontnum << endl;
-       cout << fd->name << endl;
-       current_font = 
+
+       cout << fd->name << " design size: " << fd->design_size << " at size " << fd->at_size << endl;
+       
+       if (current_frame->font)
+           current_frame->font->unref();
+       
+       current_frame->font = 
            font_factory->create_font (fd->name, dpi, fd->at_size);
+
+       g_assert (current_frame->font);
+       cout << "there is now a font"<< endl;
+    
     }
 }
 
@@ -302,8 +338,6 @@ DviPainter::DviPainter (GdkPixmap              *pixmap_arg,
     dvi_file->ref();
     font_factory->ref();
     
-    current_font = 0;
-    
     current_frame = new DviFrame;
     current_frame->h = 0;
     current_frame->v = 0;
@@ -311,6 +345,8 @@ DviPainter::DviPainter (GdkPixmap              *pixmap_arg,
     current_frame->x = 0;
     current_frame->y = 0;
     current_frame->z = 0;
+    current_frame->fontmap = NULL;
+    current_frame->font = NULL;
     
     // from gtkdvi:
     scale =  dvi_file->get_numerator() / 254000.0;
@@ -329,6 +365,12 @@ DviPainter::~DviPainter ()
 }
 
 void
-DviPainter::push_fontmap (std::map<int, DviFontdefinition *> fontmap)
+DviPainter::fontmap (DviFontMap *fontmap)
 {
+    fontmap->ref();
+
+    if (current_frame->fontmap)
+       current_frame->fontmap->unref();
+
+    current_frame->fontmap = fontmap;
 }
index cbb968bf49d821ad046ee98ed1c04f61f3599e08..4d6fdda11ba7627a94b9e2f9e2e6859649e34e46 100755 (executable)
@@ -23,9 +23,12 @@ public:
 class DviFrame : public DviLib::RefCounted
 {
 public:
+    DviLib::DviFontMap *fontmap;
     int h, v, w, x, y, z;              // in dvi units
     DviFrame *next;
     DviFrame *copy ();
+    DviLib::AbstractFont *font;
+    ~DviFrame();
 };
 
 class DviPainter : public AbstractDviPainter
@@ -49,7 +52,7 @@ public:
     virtual void y_rep ();                     // move down y
     virtual void z (int len);                  // move down len, set z = len
     virtual void z_rep ();                     // move down z
-    virtual void push_fontmap (std::map<int, DviLib::DviFontdefinition *> fontmap);
+    virtual void fontmap (DviLib::DviFontMap *fontmap); // set fontmap
     virtual void font_num (int font_num);      // current_font = fd
     virtual void special (string spc);         // do something special
     virtual void paint_bitmap (const unsigned char *data, 
@@ -65,7 +68,6 @@ private:
     AbstractFontFactory *font_factory;
 
     // runtime
-    DviLib::AbstractFont *current_font;
     DviFrame *current_frame;           // stack of DVI frames
 
     double scale;              // convert dvi units to pixels