Albert Astals Cid wrote:
A Diumenge, 15 de novembre de 2009, Luigi Toscano va escriure:
Hi all,
the attached patch removes Qt3 bits from generators/dvi/fontpool.* and
shows font information of DVI documents in the properties dialog.

There are some problems i already told you on IRC
Done (at least, I hope so).


I'd like to add some new values for FontInfo::FontType (and the
corresponding string in descriptionForFontType in propertiesdialog.cpp).
Can we still add new strings?

Yes we can!

Mail the list back when you have the final patch.
The attached patch fixes the previously found issues, and adds the new font types. I also removed a useless method (it was used for the document information dialog of kdvi).

Regards,
--
Luigi
Index: core/fontinfo.h
===================================================================
--- core/fontinfo.h	(revision 1052097)
+++ core/fontinfo.h	(working copy)
@@ -45,7 +45,11 @@
             CIDType0C,
             CIDType0COT,
             CIDTrueType,
-            CIDTrueTypeOT
+            CIDTrueTypeOT,
+            TeXPK,
+            TeXVirtual,
+            TeXFontMetric,
+            FreeTypeHandled
         };
 
         /**
Index: generators/dvi/TeXFontDefinition.h
===================================================================
--- generators/dvi/TeXFontDefinition.h	(revision 1052097)
+++ generators/dvi/TeXFontDefinition.h	(working copy)
@@ -64,6 +64,12 @@
     FONT_KPSE_NAME = 8
   };
 
+  enum font_type { 
+    TEX_PK,
+    TEX_VIRTUAL,
+    TEX_FONTMETRIC,
+    FREETYPE
+  };
 
   TeXFontDefinition(const QString &nfontname, double _displayResolution_in_dpi, quint32 chk, qint32 _scaled_size_in_DVI_units,
        class fontPool *pool, double _enlargement);
@@ -113,8 +119,9 @@
   const QString &getFullFontName() const {return fullFontName;}
   const QString &getFullEncodingName() const {return fullEncodingName;}
 #endif
-  const QString &getFontTypeName() const {return fontTypeName;}
 
+  const font_type &getFontType() const {return fontType;};
+
 #ifdef HAVE_FREETYPE
   /** For FREETYPE fonts, which use a map file, this field will
       contain the full name of the font (e.g. 'Computer Modern'). If
@@ -134,9 +141,7 @@
  private:
   quint32       checksum;
 
-  /** This will be set to a human-readable description of the font,
-      e.g. "virtual" or "TeX PK", or "Type 1" */
-  QString        fontTypeName;
+  font_type     fontType;
 
   // Functions related to virtual fonts
   void          read_VF_index(void );
Index: generators/dvi/generator_dvi.h
===================================================================
--- generators/dvi/generator_dvi.h	(revision 1052097)
+++ generators/dvi/generator_dvi.h	(working copy)
@@ -36,6 +36,9 @@
         // table of contents
         const Okular::DocumentSynopsis *generateDocumentSynopsis();
 
+        // list of fonts
+        Okular::FontInfo::List fontsForPage( int page );
+
         bool print( QPrinter &printer );
 
         QVariant metaData( const QString & key, const QVariant & option ) const;
@@ -45,8 +48,9 @@
         QImage image( Okular::PixmapRequest * request );
         Okular::TextPage* textPage( Okular::Page *page );
 
-   private:
+    private:
         double m_resolution;
+        bool m_fontExtracted;
 
         Okular::DocumentInfo *m_docInfo;
         Okular::DocumentSynopsis *m_docSynopsis;
Index: generators/dvi/fontpool.cpp
===================================================================
--- generators/dvi/fontpool.cpp	(revision 1052097)
+++ generators/dvi/fontpool.cpp	(working copy)
@@ -54,7 +54,6 @@
   useFontHints             = useFontHinting;
   CMperDVIunit             = 0;
   extraSearchPath.clear();
-  fontList.setAutoDelete(true);
 
 #ifdef HAVE_FREETYPE
   // Initialize the Freetype Library
@@ -109,6 +108,7 @@
 #endif
 
   // need to manually clear the fonts _before_ freetype gets unloaded
+  qDeleteAll(fontList);
   fontList.clear();
 
 #ifdef HAVE_FREETYPE
@@ -123,10 +123,10 @@
   // Check if glyphs need to be cleared
   if (_useFontHints != useFontHints) {
     double displayResolution = displayResolution_in_dpi;
-    TeXFontDefinition *fontp = fontList.first();
-    while(fontp != 0 ) {
+    QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+    for (; it_fontp != fontList.end(); ++it_fontp) {
+      TeXFontDefinition *fontp = *it_fontp;
       fontp->setDisplayResolution(displayResolution * fontp->enlargement);
-      fontp=fontList.next();
     }
   }
 
@@ -139,21 +139,21 @@
   // Reuse font if possible: check if a font with that name and
   // natural resolution is already in the fontpool, and use that, if
   // possible.
-  TeXFontDefinition *fontp = fontList.first();
-  while( fontp != 0 ) {
+  QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+  for (; it_fontp != fontList.end(); ++it_fontp) {
+    TeXFontDefinition *fontp = *it_fontp;
     if ((fontname == fontp->fontname) && ( (int)(enlargement*1000.0+0.5)) == (int)(fontp->enlargement*1000.0+0.5)) {
       // if font is already in the list
       fontp->mark_as_used();
       return fontp;
     }
-    fontp=fontList.next();
   }
 
   // If font doesn't exist yet, we have to generate a new font.
 
   double displayResolution = displayResolution_in_dpi;
 
-  fontp = new TeXFontDefinition(fontname, displayResolution*enlargement, checksum, scale, this, enlargement);
+  TeXFontDefinition *fontp = new TeXFontDefinition(fontname, displayResolution*enlargement, checksum, scale, this, enlargement);
   if (fontp == 0) {
     kError(kvs::dvi) << "Could not allocate memory for a font structure";
     exit(0);
@@ -170,62 +170,6 @@
 }
 
 
-QString fontPool::status()
-{
-#ifdef DEBUG_FONTPOOL
-  kDebug(kvs::dvi) << "fontPool::status() called";
-#endif
-
-  QString       text;
-  QStringList   tmp;
-
-  if (fontList.isEmpty())
-    return i18n("The fontlist is currently empty.");
-
-  text.append("<table WIDTH=\"100%\" NOSAVE >");
-  text.append( QString("<tr><td><b>%1</b></td> <td><b>%2</b></td> <td><b>%3</b></td> <td><b>%4</b> <td><b>%5</b></td> <td><b>%6</b></td></tr>")
-               .arg(i18n("TeX Name"))
-               .arg(i18n("Family"))
-               .arg(i18n("Zoom"))
-               .arg(i18n("Type"))
-               .arg(i18n("Encoding"))
-               .arg(i18n("Comment")) );
-
- TeXFontDefinition *fontp = fontList.first();
-  while ( fontp != 0 ) {
-    QString errMsg, encoding;
-
-    if (!(fontp->flags & TeXFontDefinition::FONT_VIRTUAL)) {
-#ifdef HAVE_FREETYPE
-      encoding = fontp->getFullEncodingName();
-#endif
-      if (fontp->font != 0)
-        errMsg = fontp->font->errorMessage;
-      else
-        errMsg = i18n("Font file not found");
-    }
-
-#ifdef HAVE_FREETYPE
-    tmp << QString ("<tr><td>%1</td> <td>%2</td> <td>%3%</td> <td>%4</td> <td>%5</td> <td>%6</td></tr>")
-      .arg(fontp->fontname)
-      .arg(fontp->getFullFontName())
-      .arg((int)(fontp->enlargement*100 + 0.5))
-      .arg(fontp->getFontTypeName())
-      .arg(encoding)
-      .arg(errMsg);
-#endif
-
-    fontp=fontList.next();
-  }
-
-  tmp.sort();
-  text.append(tmp.join("\n"));
-  text.append("</table>");
-
-  return text;
-}
-
-
 bool fontPool::areFontsLocated()
 {
 #ifdef DEBUG_FONTPOOL
@@ -233,11 +177,11 @@
 #endif
 
   // Is there a font whose name we did not try to find out yet?
-  TeXFontDefinition *fontp = fontList.first();
-  while( fontp != 0 ) {
+  QList<TeXFontDefinition*>::const_iterator cit_fontp = fontList.constBegin();
+  for (; cit_fontp != fontList.constEnd(); ++cit_fontp) {
+    TeXFontDefinition *fontp = *cit_fontp;
     if ( !fontp->isLocated() )
       return false;
-    fontp=fontList.next();
   }
 
 #ifdef DEBUG_FONTPOOL
@@ -306,8 +250,9 @@
 
   // Names of fonts that shall be located
   quint16 numFontsInJob = 0;
-  TeXFontDefinition *fontp = fontList.first();
-  while ( fontp != 0 ) {
+  QList<TeXFontDefinition*>::const_iterator cit_fontp = fontList.constBegin();
+  for (; cit_fontp != fontList.constEnd(); ++cit_fontp) {
+    TeXFontDefinition *fontp = *cit_fontp;
     if (!fontp->isLocated()) {
       numFontsInJob++;
 
@@ -325,7 +270,6 @@
                        << QString("%1.1200pk").arg(fontp->fontname);
       }
     }
-    fontp=fontList.next();
   }
 
   if (numFontsInJob == 0)
@@ -396,8 +340,10 @@
     QString(kpsewhich_.readAll()).split('\n', QString::SkipEmptyParts);
 
   // Now associate the file names found with the fonts
-  fontp=fontList.first();
-  while ( fontp != 0 ) {
+  QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+  for (; it_fontp != fontList.end(); ++it_fontp) {
+    TeXFontDefinition *fontp = *it_fontp;
+
     if (fontp->filename.isEmpty() == true) {
       QStringList matchingFiles;
 #ifdef HAVE_FREETYPE
@@ -421,12 +367,11 @@
           // Constructing a virtual font will most likely insert other
           // fonts into the fontList. After that, fontList.next() will
           // no longer work. It is therefore safer to start over.
-          fontp=fontList.first();
+          it_fontp=fontList.begin();
           continue;
         }
       }
     } // of if (fontp->filename.isEmpty() == true)
-    fontp = fontList.next();
   }
 }
 
@@ -442,10 +387,10 @@
 
   CMperDVIunit = _CMperDVI;
 
-  TeXFontDefinition *fontp = fontList.first();
-  while(fontp != 0 ) {
+  QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+  for (; it_fontp != fontList.end(); ++it_fontp) {
+    TeXFontDefinition *fontp = *it_fontp;
     fontp->setDisplayResolution(displayResolution_in_dpi * fontp->enlargement);
-    fontp=fontList.next();
   }
 }
 
@@ -470,10 +415,10 @@
   displayResolution_in_dpi = _displayResolution_in_dpi;
   double displayResolution = displayResolution_in_dpi;
 
-  TeXFontDefinition *fontp = fontList.first();
-  while(fontp != 0 ) {
+  QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+  for (; it_fontp != fontList.end(); ++it_fontp) {
+    TeXFontDefinition *fontp = *it_fontp;
     fontp->setDisplayResolution(displayResolution * fontp->enlargement);
-    fontp=fontList.next();
   }
 
   // Do something that causes re-rendering of the dvi-window
@@ -485,10 +430,10 @@
 
 void fontPool::markFontsAsLocated()
 {
-  TeXFontDefinition *fontp=fontList.first();
-  while ( fontp != 0 ) {
+  QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+  for (; it_fontp != fontList.end(); ++it_fontp) {
+    TeXFontDefinition *fontp = *it_fontp;
     fontp->markAsLocated();
-    fontp = fontList.next();
   }
 }
 
@@ -500,10 +445,10 @@
   kDebug(kvs::dvi) << "fontPool::mark_fonts_as_unused() called";
 #endif
 
-  TeXFontDefinition  *fontp = fontList.first();
-  while ( fontp != 0 ) {
+  QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+  for (; it_fontp != fontList.end(); ++it_fontp) {
+    TeXFontDefinition *fontp = *it_fontp;
     fontp->flags &= ~TeXFontDefinition::FONT_IN_USE;
-    fontp=fontList.next();
   }
 }
 
@@ -514,13 +459,13 @@
   kDebug(kvs::dvi) << "Release_fonts";
 #endif
 
-  TeXFontDefinition  *fontp = fontList.first();
-  while(fontp != 0) {
+  QMutableListIterator<TeXFontDefinition*> it_fontp(fontList);
+  while (it_fontp.hasNext()) {
+    TeXFontDefinition *fontp = it_fontp.next();
     if ((fontp->flags & TeXFontDefinition::FONT_IN_USE) != TeXFontDefinition::FONT_IN_USE) {
-      fontList.removeRef(fontp);
-      fontp = fontList.first();
-    } else
-      fontp = fontList.next();
+      delete fontp;
+      it_fontp.remove();
+    }
   }
 }
 
Index: generators/dvi/TeXFontDefinition.cpp
===================================================================
--- generators/dvi/TeXFontDefinition.cpp	(revision 1052097)
+++ generators/dvi/TeXFontDefinition.cpp	(working copy)
@@ -121,7 +121,7 @@
       set_char_p = &dviRenderer::set_char;
       if ((checksum != 0) && (checksum != font->checksum))
         kWarning(kvs::dvi) << i18n("Checksum mismatch for font file %1", filename) ;
-      fontTypeName = "TeX PK";
+      fontType = TEX_PK;
       return;
     }
 
@@ -129,7 +129,7 @@
     if (magic == VF_MAGIC) {
       read_VF_index();
       set_char_p = &dviRenderer::set_vf_char;
-      fontTypeName = i18n("TeX virtual");
+      fontType = TEX_VIRTUAL;
       return;
     }
 
@@ -138,7 +138,7 @@
       file = 0;
       font = new TeXFont_TFM(this);
       set_char_p = &dviRenderer::set_char;
-      fontTypeName = i18n("TeX Font Metric");
+      fontType = TEX_FONTMETRIC;
       return;
   }
 
@@ -163,7 +163,7 @@
   }
 
   set_char_p = &dviRenderer::set_char;
-  fontTypeName = i18n("FreeType");
+  fontType = FREETYPE;
   return;
 #else
   // If we don't have the FreeType library, we should never have
@@ -232,7 +232,6 @@
   }
 }
 
-
 macro::macro()
 {
   pos     = 0;                /* address of first byte of macro */
Index: generators/dvi/fontpool.h
===================================================================
--- generators/dvi/fontpool.h	(revision 1052097)
+++ generators/dvi/fontpool.h	(working copy)
@@ -12,7 +12,7 @@
 #include "fontprogress.h"
 #include "TeXFontDefinition.h"
 
-#include <Q3PtrList>
+#include <QList>
 #include <QObject>
 #include <QProcess>
 
@@ -78,12 +78,8 @@
  // the method returns.
  TeXFontDefinition* appendx(const QString& fontname, quint32 checksum, quint32 scale, double enlargement);
 
- // Returns a string in a very basic HTML format which describes the
- // fonts in the pool.
- QString status();
-
   // This is the list which actually holds pointers to the fonts
-  Q3PtrList<TeXFontDefinition> fontList;
+  QList<TeXFontDefinition*> fontList;
 
   // This method marks all fonts in the fontpool as "not in use". The
   // fonts are, however, not removed from memory until the method
Index: generators/dvi/generator_dvi.cpp
===================================================================
--- generators/dvi/generator_dvi.cpp	(revision 1052097)
+++ generators/dvi/generator_dvi.cpp	(working copy)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Luigi Toscano <luigi.tosc...@tiscali.it>        *
+ *   Copyright (C) 2006-2009 by Luigi Toscano <luigi.tosc...@tiscali.it>   *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
@@ -21,6 +21,7 @@
 #include "dviRenderer.h"
 #include "pageSize.h"
 #include "dviexport.h"
+#include "TeXFont.h"
 
 #include <qapplication.h>
 #include <qstring.h>
@@ -62,10 +63,11 @@
 OKULAR_EXPORT_PLUGIN( DviGenerator, createAboutData() )
 
 DviGenerator::DviGenerator( QObject *parent, const QVariantList &args ) : Okular::Generator( parent, args ),
-  m_docInfo( 0 ), m_docSynopsis( 0 ), m_dviRenderer( 0 )
+  m_fontExtracted( false ), m_docInfo( 0 ), m_docSynopsis( 0 ), m_dviRenderer( 0 )
 {
     setFeature( Threaded );
     setFeature( TextExtraction );
+    setFeature( FontInfo );
     setFeature( PrintPostscript );
     if ( Okular::FilePrinter::ps2pdfAvailable() )
         setFeature( PrintToFile );
@@ -135,6 +137,7 @@
     m_dviRenderer = 0;
 
     m_linkGenerated.clear();
+    m_fontExtracted = false;
 
     return true;
 }
@@ -402,6 +405,86 @@
     return m_docSynopsis;
 }
 
+Okular::FontInfo::List DviGenerator::fontsForPage( int page )
+{
+    Q_UNUSED( page );
+
+    Okular::FontInfo::List list;
+
+    // the list of the fonts is extracted once 
+    if ( m_fontExtracted )
+        return list;
+
+    if ( m_dviRenderer && m_dviRenderer->dviFile &&
+         m_dviRenderer->dviFile->font_pool )
+    {
+        QList<TeXFontDefinition*> fonts = m_dviRenderer->dviFile->font_pool->fontList;
+
+        foreach (const TeXFontDefinition* font, fonts)
+        {
+            Okular::FontInfo of;
+            QString name;
+            int zoom = (int)(font->enlargement*100 + 0.5);
+            if ( font->getFullFontName().isEmpty() ) 
+            {
+                name = QString( "%1, %2%" )
+                        .arg( font->fontname )
+                        .arg( zoom );
+            }
+            else
+            {
+                name = QString( "%1 (%2), %3%" ) 
+                        .arg( font->fontname )
+                        .arg( font->getFullFontName() ) 
+                        .arg( zoom ); 
+            }
+            of.setName( name );
+
+            QString fontFileName;
+            if (!(font->flags & TeXFontDefinition::FONT_VIRTUAL)) {
+                if ( font->font != 0 )
+                    fontFileName = font->font->errorMessage;
+                else
+                    fontFileName = i18n("Font file not found");
+
+                if ( fontFileName.isEmpty() )
+                    fontFileName = font->filename;
+            }
+
+            of.setFile( fontFileName );
+
+            Okular::FontInfo::FontType ft;
+            switch ( font->getFontType() )
+            {
+                case TeXFontDefinition::TEX_PK:
+                    ft = Okular::FontInfo::TeXPK;
+                    break;
+                case TeXFontDefinition::TEX_VIRTUAL:
+                    ft = Okular::FontInfo::TeXVirtual;
+                    break;
+                case TeXFontDefinition::TEX_FONTMETRIC:
+                    ft = Okular::FontInfo::TeXFontMetric;
+                    break;
+                case TeXFontDefinition::FREETYPE:
+                    ft = Okular::FontInfo::FreeTypeHandled;
+                    break;
+            }
+            of.setType( ft );
+
+            // DVI has not the concept of "font embedding"
+            of.setEmbedType( Okular::FontInfo::NotEmbedded );
+            of.setCanBeExtracted( false );
+
+            list.append( of );
+        }
+
+        m_fontExtracted = true;
+
+    }
+
+    return list;
+}
+
 void DviGenerator::loadPages( QVector< Okular::Page * > &pagesVector )
 {
     QSize pageRequiredSize;
Index: ui/propertiesdialog.cpp
===================================================================
--- ui/propertiesdialog.cpp	(revision 1052097)
+++ ui/propertiesdialog.cpp	(working copy)
@@ -340,6 +340,18 @@
         case Okular::FontInfo::CIDTrueTypeOT:
             return i18nc("OT means OpenType", "CID TrueType (OT)");
             break;
+        case Okular::FontInfo::TeXPK:
+            return i18n("TeX PK");
+            break;
+        case Okular::FontInfo::TeXVirtual:
+            return i18n("TeX virtual");
+            break;
+        case Okular::FontInfo::TeXFontMetric:
+            return i18n("TeX Font Metric");
+            break;
+        case Okular::FontInfo::FreeTypeHandled:
+            return i18n("FreeType-handled");
+            break;
         case Okular::FontInfo::Unknown:
             return i18nc("Unknown font type", "Unknown");
             break;
_______________________________________________
Okular-devel mailing list
Okular-devel@kde.org
https://mail.kde.org/mailman/listinfo/okular-devel

Reply via email to