Hello,

I fixed the issues in the last patch and also removed a bug
in case a font specified in dvi was not found on the system.

Thanks,
Igor

-- 
:wq
Index: fontpool.cpp
===================================================================
--- fontpool.cpp	(revision 1041324)
+++ fontpool.cpp	(working copy)
@@ -70,6 +70,10 @@
   // output is intercepted and parsed.
   connect(&kpsewhich_, SIGNAL(readyReadStandardError()),
           this, SLOT(mf_output_receiver()));
+  connect(&kpsewhich_, SIGNAL(error(QProcess::ProcessError)), this,
+		  SLOT(locateFontsError (QProcess::ProcessError)));
+  connect(&kpsewhich_, SIGNAL(finished(int, QProcess::ExitStatus)), this,
+		  SLOT(locateFontsFinished ( int, QProcess::ExitStatus )));
 
   // Check if the QT library supports the alpha channel of
   // QImages. Experiments show that --depending of the configuration
@@ -250,45 +254,95 @@
 void fontPool::locateFonts()
 {
   kpsewhichOutput.clear();
+#ifdef DEBUG_FONTPOOL
+  kDebug(kvs::dvi) << "locateFonts()";
+#endif
 
+  m_locateState = LOCATE_FONT_FIRST;
+  locateFontsProcess();
+}
+
+void fontPool::locateFontsProcess()
+{
+#ifdef DEBUG_FONTPOOL
+  kDebug(kvs::dvi) << "locateFontsProcess(), state: " << m_locateState;
+#endif
+
   // First, we try and find those fonts which exist on disk
   // already. If virtual fonts are found, they will add new fonts to
   // the list of fonts whose font files need to be located, so that we
   // repeat the lookup.
-  bool vffound;
-  do {
-    vffound = false;
-    locateFonts(false, false, &vffound);
-  } while(vffound);
+  switch (m_locateState) {
 
-  // If still not all fonts are found, look again, this time with
-  // on-demand generation of PK fonts enabled.
-  if (!areFontsLocated())
-    locateFonts(true, false);
+    case LOCATE_FONT_FIRST:
+      m_locateState = LOCATE_FONT_VIRT;
+      m_makePK = false;
+      m_locateTFMonly = false;
+      m_virtualFontsFound = false;
+      break;
 
-  // If still not all fonts are found, we look for TFM files as a last
-  // resort, so that we can at least draw filled rectangles for
-  // characters.
-  if (!areFontsLocated())
-    locateFonts(false, true);
+    case LOCATE_FONT_VIRT:
+#ifdef DEBUG_FONTPOOL
+      kDebug(kvs::dvi) << "locateFontsProcess(), m_virtualFontsFound: " << m_virtualFontsFound;
+#endif
+      if (m_virtualFontsFound == true) {
+        if (areFontsLocated()) {
+          return;
+        }
+#ifdef DEBUG_FONTPOOL
+        kDebug(kvs::dvi) << "locateFontsProcess(), VIRT not all fonts found";
+#endif
+        // If still not all fonts are found, look again, this time with
+        // on-demand generation of PK fonts enabled.
+        m_locateState = LOCATE_FONT_PK;
+        m_makePK = true;
+        m_locateTFMonly = false;
+        break;
+      }
+      break;
 
-  // If still not all fonts are found, we give up. We mark all fonts
-  // as 'located', so that we won't look for them any more, and
-  // present an error message to the user.
-  if (!areFontsLocated()) {
-    markFontsAsLocated();
-    QString details = QString("<qt><p><b>PATH:</b> %1</p>%2</qt>").arg(getenv("PATH")).arg(kpsewhichOutput);
-    KMessageBox::detailedError( 0, i18n("<qt><p>Okular was not able to locate all the font files "
-                                        "which are necessary to display the current DVI file. "
-                                        "Your document might be unreadable.</p></qt>"),
-                                details,
-                                i18n("Not All Font Files Found") );
+    case LOCATE_FONT_PK:
+      if (areFontsLocated()) {
+        return;
+      }
+#ifdef DEBUG_FONTPOOL
+      kDebug(kvs::dvi) << "locateFontsProcess(), PK not all fonts found";
+#endif
+      // If still not all fonts are found, we look for TFM files as a last
+      // resort, so that we can at least draw filled rectangles for
+      // characters.
+      m_locateState = LOCATE_FONT_TFM;
+      m_makePK = false;
+      m_locateTFMonly = true;
+      break;
+
+    case LOCATE_FONT_TFM:
+    default:
+      // If still not all fonts are found, we give up. We mark all fonts
+      // as 'located', so that we won't look for them any more, and
+      // present an error message to the user.
+      if (!areFontsLocated()) {
+        markFontsAsLocated();
+        QString details = QString("<qt><p><b>PATH:</b> %1</p>%2</qt>").arg(getenv("PATH")).arg(kpsewhichOutput);
+        KMessageBox::detailedError( 0, i18n("<qt><p>Okular was not able to locate all the font files "
+              "which are necessary to display the current DVI file. "
+              "Your document might be unreadable.</p></qt>"),
+            details,
+            i18n("Not All Font Files Found") );
+      }
+      return;
+      break;
   }
+
+  locateFontsStart();
 }
 
 
-void fontPool::locateFonts(bool makePK, bool locateTFMonly, bool *virtualFontsFound)
+void fontPool::locateFontsStart()
 {
+#ifdef DEBUG_FONTPOOL
+  kDebug(kvs::dvi) << "locateFontsStart()";
+#endif
   // Set up the kpsewhich process. If pass == 0, look for vf-fonts and
   // disable automatic font generation as vf-fonts can't be
   // generated. If pass == 0, ennable font generation, if it was
@@ -302,7 +356,7 @@
                  << "--mode" << "lexmarks";
 
   // Disable automatic pk-font generation.
-  kpsewhich_args << (makePK ? "--mktex" : "--no-mktex") << "pk";
+  kpsewhich_args << (m_makePK ? "--mktex" : "--no-mktex") << "pk";
 
   // Names of fonts that shall be located
   quint16 numFontsInJob = 0;
@@ -311,7 +365,7 @@
     if (!fontp->isLocated()) {
       numFontsInJob++;
 
-      if (locateTFMonly == true)
+      if (m_locateTFMonly == true)
         kpsewhich_args << QString("%1.tfm").arg(fontp->fontname);
       else {
 #ifdef HAVE_FREETYPE
@@ -328,6 +382,9 @@
     fontp=fontList.next();
   }
 
+#ifdef DEBUG_FONTPOOL
+  kDebug(kvs::dvi) << "locateFontsStart() numFontsInJob: " << numFontsInJob;
+#endif
   if (numFontsInJob == 0)
     return;
 
@@ -340,43 +397,49 @@
   kpsewhichOutput +=
     "<p><b>" + kpsewhich_exe + ' ' + kpsewhich_args.join(" ") + "</b></p>";
 
-  const QString importanceOfKPSEWHICH =
-    i18n("<p>Okular relies on the <b>kpsewhich</b> program to locate font files "
-         "on your hard disk and to generate PK fonts, if necessary.</p>");
-
+#ifdef DEBUG_FONTPOOL
+  kDebug(kvs::dvi) << "locateFontsStart() command line:" << kpsewhich_exe << kpsewhich_args.join(" ");
+#endif
   kpsewhich_.start(kpsewhich_exe, kpsewhich_args,
                    QIODevice::ReadOnly|QIODevice::Text);
-  if (!kpsewhich_.waitForStarted()) {
+}
+
+void fontPool::locateFontsError(QProcess::ProcessError error) {
+#ifdef DEBUG_FONTPOOL
+  kDebug(kvs::dvi) << "locateFontsError";
+#endif
+  if (error == QProcess::FailedToStart || error == QProcess::Timedout || error == -1) {
     QApplication::restoreOverrideCursor();
+    const QString importanceOfKPSEWHICH =
+      i18n("<p>Okular relies on the <b>kpsewhich</b> program to locate font files "
+          "on your hard disk and to generate PK fonts, if necessary.</p>");
     const QString msg =
       i18n("<p>There were problems running <b>kpsewhich</b>. As a result, "
-           "some font files could not be located, and your document might be unreadable.</p>"
-           "<p><b>Possible reason:</b> The kpsewhich program is perhaps not installed on your system, or it "
-           "cannot be found in the current search path.</p>"
-           "<p><b>What you can do:</b> The kpsewhich program is normally contained in distributions of the TeX "
-           "typesetting system. If TeX is not installed on your system, you could install the TeX Live distribution (www.tug.org/texlive). "
-           "If you are sure that TeX is installed, please try to use the kpsewhich program from the command line to check if it "
-           "really works.</p>");
+          "some font files could not be located, and your document might be unreadable.</p>"
+          "<p><b>Possible reason:</b> The kpsewhich program is perhaps not installed on your system, or it "
+          "cannot be found in the current search path.</p>"
+          "<p><b>What you can do:</b> The kpsewhich program is normally contained in distributions of the TeX "
+          "typesetting system. If TeX is not installed on your system, you could install the TeX Live distribution (www.tug.org/texlive). "
+          "If you are sure that TeX is installed, please try to use the kpsewhich program from the command line to check if it "
+          "really works.</p>");
     const QString details =
-      QString("<qt><p><b>PATH:</b> %1</p>%2</qt>").arg(getenv("PATH")).arg(kpsewhichOutput);
+      QString("<qt><p><b>PATH:</b> %1</p>%2<p>Process Error: %3</p></qt>")
+      .arg(getenv("PATH")).arg(kpsewhichOutput).arg(error);
 
     KMessageBox::detailedError(0,
-                               QString("<qt>%1%2</qt>").arg(importanceOfKPSEWHICH).arg(msg),
-                               details,
-                               i18n("Problem locating fonts"));
-
-    // This makes sure the we don't try to run kpsewhich again
-    markFontsAsLocated();
-    return;
+        QString("<qt>%1%2</qt>").arg(importanceOfKPSEWHICH).arg(msg),
+        details,
+        i18n("Problem locating fonts"));
   }
+  // This makes sure the we don't try to run kpsewhich again
+  markFontsAsLocated();
+}
 
-  // We wait here while the external program runs concurrently.
-  // Every 200ms we call processEvents() to keep the GUI updated.
-  // This is important, e.g. for the progress dialog that is
-  // shown when PK fonts are generated by MetaFont.
-  while(!kpsewhich_.waitForFinished(200))
-    qApp->processEvents();
-  progress.hide();
+void fontPool::locateFontsFinished(int exitCode, QProcess::ExitStatus exitStatus)
+{
+#ifdef DEBUG_FONTPOOL
+  kDebug(kvs::dvi) << "locateFontsFinished";
+#endif
 
   // Handle fatal errors.
   int const kpsewhich_exit_code = kpsewhich_.exitCode();
@@ -387,7 +450,7 @@
                        i18n("Font generation aborted") );
 
     // This makes sure the we don't try to run kpsewhich again
-    if (makePK == false)
+    if (m_makePK == false)
       markFontsAsLocated();
   }
 
@@ -395,8 +458,16 @@
   const QStringList fileNameList =
     QString(kpsewhich_.readAll()).split('\n', QString::SkipEmptyParts);
 
+#ifdef DEBUG_FONTPOOL
+  kDebug(kvs::dvi) << "locateFontsFinished, fileNameList:" << fileNameList.length() << fileNameList.join(" ");
+#endif
+  if (fileNameList.length() == 0) {
+    locateFontsError((QProcess::ProcessError)-1);
+    return;
+  }
+
   // Now associate the file names found with the fonts
-  fontp=fontList.first();
+  TeXFontDefinition *fontp = fontList.first();
   while ( fontp != 0 ) {
     if (fontp->filename.isEmpty() == true) {
       QStringList matchingFiles;
@@ -416,8 +487,7 @@
         fontp->fontNameReceiver(fname);
         fontp->flags |= TeXFontDefinition::FONT_KPSE_NAME;
         if (fname.endsWith(".vf")) {
-          if (virtualFontsFound != 0)
-            *virtualFontsFound = true;
+            m_virtualFontsFound = true;
           // 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.
@@ -428,6 +498,8 @@
     } // of if (fontp->filename.isEmpty() == true)
     fontp = fontList.next();
   }
+  
+  locateFontsProcess();
 }
 
 
Index: fontpool.h
===================================================================
--- fontpool.h	(revision 1041324)
+++ fontpool.h	(working copy)
@@ -21,7 +21,6 @@
 #include FT_FREETYPE_H
 #endif
 
-
 /**
  *  A list of fonts and a compilation of utility functions
  *
@@ -37,6 +36,14 @@
 class fontPool : public QObject {
  Q_OBJECT
 
+enum LocateFontsState {
+ LOCATE_FONT_FIRST,
+ LOCATE_FONT_VIRT,
+ LOCATE_FONT_PK,
+ LOCATE_FONT_TFM,
+ LOCATE_FONT_LAST,
+};
+
 public:
  // Default constructor.
  fontPool(bool useFontHinting);
@@ -141,6 +148,8 @@
   // is set to true if one of the fonts found is a virtual font. If no
   // virtual font is found, the variable remains untouched.
   void locateFonts();
+  void locateFontsError(QProcess::ProcessError error);
+  void locateFontsFinished(int exitCode, QProcess::ExitStatus exitStatus);
 
 private:
   // This method goes through the list of fonts, and marks each of them
@@ -173,8 +182,13 @@
   // characters. If not null, the bool pointed at by virtualFontsFound
   // is set to true if one of the fonts found is a virtual font. If no
   // virtual font is found, the variable remains untouched.
-  void locateFonts(bool makePK, bool locateTFMonly, bool *virtualFontsFound=0);
 
+  LocateFontsState m_locateState;
+  bool m_makePK, m_locateTFMonly;
+  bool m_virtualFontsFound;
+  void locateFontsProcess();
+  void locateFontsStart();
+
   // This QString is used internally by the mf_output_receiver()
   // method.  This string is set to QString() in locateFonts(bool,
   // bool, bool *). Values are set and read by the
_______________________________________________
Okular-devel mailing list
Okular-devel@kde.org
https://mail.kde.org/mailman/listinfo/okular-devel

Reply via email to