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

📄 fontpool.cpp

📁 okular
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-//// fontpool.cpp//// (C) 2001-2005 Stefan Kebekus// Distributed under the GPL#include <config.h>#include "fontpool.h"#include "kvs_debug.h"#include "TeXFont.h"#include <klocale.h>#include <kmessagebox.h>#include <QApplication>#include <QPainter>#include <cmath>//#define DEBUG_FONTPOOL// List of permissible MetaFontModes which are supported by kdvi.//const char *MFModes[]       = { "cx", "ljfour", "lexmarks" };//const char *MFModenames[]   = { "Canon CX", "LaserJet 4", "Lexmark S" };//const int   MFResolutions[] = { 300, 600, 1200 };#ifdef PERFORMANCE_MEASUREMENTQTime fontPoolTimer;bool fontPoolTimerFlag;#endiffontPool::fontPool()  :  progress("fontgen",  // Chapter in the documentation for help.              i18n("KDVI is currently generating bitmap fonts..."),              i18n("Aborts the font generation. Don't do this."),              i18n("KDVI is currently generating bitmap fonts which are needed to display your document. "                   "For this, KDVI uses a number of external programs, such as MetaFont. You can find "                   "the output of these programs later in the document info dialog."),              i18n("KDVI is generating fonts. Please wait."),              0){#ifdef DEBUG_FONTPOOL  kDebug(kvs::dvi) << "fontPool::fontPool() called" << endl;#endif  setObjectName("Font Pool");  displayResolution_in_dpi = 100.0; // A not-too-bad-default  useFontHints             = true;  CMperDVIunit             = 0;  extraSearchPath          = QString::null;  fontList.setAutoDelete(true);#ifdef HAVE_FREETYPE  // Initialize the Freetype Library  if ( FT_Init_FreeType( &FreeType_library ) != 0 ) {    kError(kvs::dvi) << "Cannot load the FreeType library. KDVI proceeds without FreeType support." << endl;    FreeType_could_be_loaded = false;  } else    FreeType_could_be_loaded = true;#endif  // If PK fonts are generated, the kpsewhich command will re-route  // the output of MetaFont into its stderr. Here we make sure this  // output is intercepted and parsed.  connect(&kpsewhich_, SIGNAL(readyReadStandardError()),          this, SLOT(mf_output_receiver()));  // Check if the QT library supports the alpha channel of  // QImages. Experiments show that --depending of the configuration  // of QT at compile and runtime or the availability of the XFt  // extension, alpha channels are either supported, or silently  // ignored.  QImage start(1, 1, QImage::Format_ARGB32); // Generate a 1x1 image, black with alpha=0x10  quint32 *destScanLine = (quint32 *)start.scanLine(0);  *destScanLine = 0x80000000;  QPixmap intermediate = QPixmap::fromImage(start);  QPixmap dest(1,1);  dest.fill(Qt::white);  QPainter paint( &dest );  paint.drawPixmap(0, 0, intermediate);  paint.end();  start = dest.toImage().convertToFormat(QImage::Format_ARGB32);  quint8 result = *(start.scanLine(0)) & 0xff;  if ((result == 0xff) || (result == 0x00)) {#ifdef DEBUG_FONTPOOL    kDebug(kvs::dvi) << "fontPool::fontPool(): QPixmap does not support the alpha channel" << endl;#endif    QPixmapSupportsAlpha = false;  } else {#ifdef DEBUG_FONTPOOL    kDebug(kvs::dvi) << "fontPool::fontPool(): QPixmap supports the alpha channel" << endl;#endif    QPixmapSupportsAlpha = true;  }}fontPool::~fontPool(){#ifdef DEBUG_FONTPOOL  kDebug(kvs::dvi) << "fontPool::~fontPool() called" << endl;#endif#ifdef HAVE_FREETYPE  if (FreeType_could_be_loaded == true)    FT_Done_FreeType( FreeType_library );#endif}void fontPool::setParameters( bool _useFontHints ){  // Check if glyphs need to be cleared  if (_useFontHints != useFontHints) {    double displayResolution = displayResolution_in_dpi;    TeXFontDefinition *fontp = fontList.first();    while(fontp != 0 ) {      fontp->setDisplayResolution(displayResolution * fontp->enlargement);      fontp=fontList.next();    }  }  useFontHints = _useFontHints;}TeXFontDefinition* fontPool::appendx(const QString& fontname, quint32 checksum, quint32 scale, double enlargement){  // 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 ) {    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);  if (fontp == 0) {    kError(kvs::dvi) << i18n("Could not allocate memory for a font structure") << endl;    exit(0);  }  fontList.append(fontp);#ifdef PERFORMANCE_MEASUREMENT  fontPoolTimer.start();  fontPoolTimerFlag = false;#endif  // Now start kpsewhich/MetaFont, etc. if necessary  return fontp;}QString fontPool::status(){#ifdef DEBUG_FONTPOOL  kDebug(kvs::dvi) << "fontPool::status() called" << endl;#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  kDebug(kvs::dvi) << "fontPool::areFontsLocated() called" << endl;#endif  // Is there a font whose name we did not try to find out yet?  TeXFontDefinition *fontp = fontList.first();  while( fontp != 0 ) {    if ( !fontp->isLocated() )      return false;    fontp=fontList.next();  }#ifdef DEBUG_FONTPOOL  kDebug(kvs::dvi) << "... yes, all fonts are located (but not necessarily loaded)." << endl;#endif  return true; // That says that all fonts are located.}void fontPool::locateFonts(){  kpsewhichOutput = QString::null;  // 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);  // If still not all fonts are found, look again, this time with  // on-demand generation of PK fonts enabled.  if (!areFontsLocated())    locateFonts(true, false);  // 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);  // 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>KDVI 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") );  }}void fontPool::locateFonts(bool makePK, bool locateTFMonly, bool *virtualFontsFound)

⌨️ 快捷键说明

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