⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fontpool.cpp

📁 okular
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{  // 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  // enabled globally.  emit setStatusBarText(i18n("Locating fonts..."));  // Now generate the command line for the kpsewhich  // program. Unfortunately, this can be rather long and involved...  QStringList kpsewhich_args;  kpsewhich_args << "--dpi" << "1200"                 << "--mode" << "lexmarks";  // Disable automatic pk-font generation.  kpsewhich_args << (makePK ? "--mktex" : "--no-mktex") << "pk";  // Names of fonts that shall be located  quint16 numFontsInJob = 0;  TeXFontDefinition *fontp = fontList.first();  while ( fontp != 0 ) {    if (!fontp->isLocated()) {      numFontsInJob++;      if (locateTFMonly == true)        kpsewhich_args << QString("%1.tfm").arg(fontp->fontname);      else {#ifdef HAVE_FREETYPE        if (FreeType_could_be_loaded == true) {          const QString &filename = fontsByTeXName.findFileName(fontp->fontname);          if (!filename.isEmpty())            kpsewhich_args << QString("%1").arg(filename);        }#endif        kpsewhich_args << QString("%1.vf").arg(fontp->fontname)                       << QString("%1.1200pk").arg(fontp->fontname);      }    }    fontp=fontList.next();  }  if (numFontsInJob == 0)    return;  progress.setTotalSteps(numFontsInJob, &kpsewhich_);  // Now run... kpsewhich. In case of error, kick up a fuss.  // This string is not going to be quoted, as it might be were it  // a real command line, but who cares?  const QString kpsewhich_exe = "kpsewhich";  kpsewhichOutput +=    "<p><b>" + kpsewhich_exe + " " + kpsewhich_args.join(" ") + "</b></p>";  const QString importanceOfKPSEWHICH =    i18n("<p>KDVI relies on the <b>kpsewhich</b> program to locate font files "         "on your hard disc and to generate PK fonts, if necessary.</p>");  kpsewhich_.start(kpsewhich_exe, kpsewhich_args,                   QIODevice::ReadOnly|QIODevice::Text);  if (!kpsewhich_.waitForStarted()) {    QApplication::restoreOverrideCursor();    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 TeTeX distribution (www.tetex.org). "           "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);    KMessageBox::detailedError(0,                               QString("<qt>%1%2</qt>").arg(importanceOfKPSEWHICH).arg(msg),                               details,                               i18n("Problem locating fonts - KDVI"));    // This makes sure the we don't try to run kpsewhich again    markFontsAsLocated();    return;  }  // 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();  // Handle fatal errors.  int const kpsewhich_exit_code = kpsewhich_.exitCode();  if (kpsewhich_exit_code < 0) {    KMessageBox::sorry(0,                       QString("<qt><p>The font generation by <b>kpsewhich</b> was aborted (exit code %1, error %2). As a result, "                               "some font files could not be located, and your document might be unreadable.</p></qt>").arg(kpsewhich_exit_code).arg(kpsewhich_.errorString()),                       i18n("Font generation aborted - KDVI") );    // This makes sure the we don't try to run kpsewhich again    if (makePK == false)      markFontsAsLocated();  }  // Create a list with all filenames found by the kpsewhich program.  const QStringList fileNameList =    QString(kpsewhich_.readAll()).split('\n', QString::SkipEmptyParts);  // Now associate the file names found with the fonts  fontp=fontList.first();  while ( fontp != 0 ) {    if (fontp->filename.isEmpty() == true) {      QStringList matchingFiles;#ifdef HAVE_FREETYPE      const QString &fn = fontsByTeXName.findFileName(fontp->fontname);      if (!fn.isEmpty())        matchingFiles = fileNameList.filter(fn);#endif      if (matchingFiles.isEmpty() == true)        matchingFiles += fileNameList.filter(fontp->fontname+".");      if (matchingFiles.isEmpty() != true) {#ifdef DEBUG_FONTPOOL        kDebug(kvs::dvi) << "Associated " << fontp->fontname << " to " << matchingFiles.first() << endl;#endif        QString fname = matchingFiles.first();        fontp->fontNameReceiver(fname);        fontp->flags |= TeXFontDefinition::FONT_KPSE_NAME;        if (fname.endsWith(".vf")) {          if (virtualFontsFound != 0)            *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.          fontp=fontList.first();          continue;        }      }    } // of if (fontp->filename.isEmpty() == true)    fontp = fontList.next();  }}void fontPool::setCMperDVIunit( double _CMperDVI ){#ifdef DEBUG_FONTPOOL  kDebug(kvs::dvi) << "fontPool::setCMperDVIunit( " << _CMperDVI << " )" << endl;#endif  if (CMperDVIunit == _CMperDVI)    return;  CMperDVIunit = _CMperDVI;  TeXFontDefinition *fontp = fontList.first();  while(fontp != 0 ) {    fontp->setDisplayResolution(displayResolution_in_dpi * fontp->enlargement);    fontp=fontList.next();  }}void fontPool::setDisplayResolution( double _displayResolution_in_dpi ){#ifdef DEBUG_FONTPOOL  kDebug(kvs::dvi) << "fontPool::setDisplayResolution( displayResolution_in_dpi=" << _displayResolution_in_dpi << " ) called" << endl;#endif  // Ignore minute changes by less than 2 DPI. The difference would  // hardly be visible anyway. That saves a lot of re-painting,  // e.g. when the user resizes the window, and a flickery mouse  // changes the window size by 1 pixel all the time.  if ( fabs(displayResolution_in_dpi - _displayResolution_in_dpi) <= 2.0 ) {#ifdef DEBUG_FONTPOOL    kDebug(kvs::dvi) << "fontPool::setDisplayResolution(...): resolution wasn't changed. Aborting." << endl;#endif    return;  }  displayResolution_in_dpi = _displayResolution_in_dpi;  double displayResolution = displayResolution_in_dpi;  TeXFontDefinition *fontp = fontList.first();  while(fontp != 0 ) {    fontp->setDisplayResolution(displayResolution * fontp->enlargement);    fontp=fontList.next();  }  // Do something that causes re-rendering of the dvi-window  /*@@@@  emit fonts_have_been_loaded(this);  */}void fontPool::markFontsAsLocated(){  TeXFontDefinition *fontp=fontList.first();  while ( fontp != 0 ) {    fontp->markAsLocated();    fontp = fontList.next();  }}void fontPool::mark_fonts_as_unused(){#ifdef DEBUG_FONTPOOL  kDebug(kvs::dvi) << "fontPool::mark_fonts_as_unused() called" << endl;#endif  TeXFontDefinition  *fontp = fontList.first();  while ( fontp != 0 ) {    fontp->flags &= ~TeXFontDefinition::FONT_IN_USE;    fontp=fontList.next();  }}void fontPool::release_fonts(){#ifdef DEBUG_FONTPOOL  kDebug(kvs::dvi) << "Release_fonts" << endl;#endif  TeXFontDefinition  *fontp = fontList.first();  while(fontp != 0) {    if ((fontp->flags & TeXFontDefinition::FONT_IN_USE) != TeXFontDefinition::FONT_IN_USE) {      fontList.removeRef(fontp);      fontp = fontList.first();    } else      fontp = fontList.next();  }}void fontPool::mf_output_receiver(){  const QString output_data =    QString::fromLocal8Bit(kpsewhich_.readAllStandardError());  kpsewhichOutput.append(output_data);  MetafontOutput.append(output_data);  // We'd like to print only full lines of text.  int numleft;  bool show_prog = false;  while( (numleft = MetafontOutput.indexOf('\n')) != -1) {    QString line = MetafontOutput.left(numleft+1);#ifdef DEBUG_FONTPOOL    kDebug(kvs::dvi) << "MF OUTPUT RECEIVED: " << line;#endif    // Search for a line which marks the beginning of a MetaFont run    // and show the progress dialog at the end of this method.    if (line.indexOf("kpathsea:") == 0)      show_prog = true;    // If the Output of the kpsewhich program contains a line starting    // with "kpathsea:", this means that a new MetaFont-run has been    // started. We filter these lines out and update the display    // accordingly.    int startlineindex = line.indexOf("kpathsea:");    if (startlineindex != -1) {      int endstartline  = line.indexOf("\n",startlineindex);      QString startLine = line.mid(startlineindex,endstartline-startlineindex);      // The last word in the startline is the name of the font which we      // are generating. The second-to-last word is the resolution in      // dots per inch. Display this info in the text label below the      // progress bar.      int lastblank     = startLine.lastIndexOf(' ');      QString fontName  = startLine.mid(lastblank+1);      int secondblank   = startLine.lastIndexOf(' ',lastblank-1);      QString dpi       = startLine.mid(secondblank+1,lastblank-secondblank-1);      progress.show();      progress.increaseNumSteps( i18n("Currently generating %1 at %2 dpi", fontName, dpi) );    }    MetafontOutput = MetafontOutput.remove(0,numleft+1);  }}#include "fontpool.moc"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -