[poppler] qt5/src

Albert Astals Cid aacid at kemper.freedesktop.org
Sun Oct 22 21:23:32 UTC 2017


 qt5/src/ArthurOutputDev.cc |   48 ++++++++++++++++-----------------------------
 qt5/src/ArthurOutputDev.h  |    4 ---
 2 files changed, 18 insertions(+), 34 deletions(-)

New commits:
commit ebf6d1ca736fecad49fbf543875c794770bd4d57
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Fri Sep 15 11:18:58 2017 +0200

    Clean up the remaining Splash code in Arthur backend
    
    - remove some goto-style error handling
    - use nullptr
    - use std::unique_ptr (fixes a leak)
    - remove unused data member m_currentFont
    - remove some unused forward declarations
    
    Bug #103117

diff --git a/qt5/src/ArthurOutputDev.cc b/qt5/src/ArthurOutputDev.cc
index f31e6a5f..f199e656 100644
--- a/qt5/src/ArthurOutputDev.cc
+++ b/qt5/src/ArthurOutputDev.cc
@@ -296,14 +296,14 @@ void ArthurOutputDev::updateStrokeOpacity(GfxState *state)
 
 void ArthurOutputDev::updateFont(GfxState *state)
 {
-  GfxFont *font = state->getFont();
-  if (!font)
+  GfxFont *gfxFont = state->getFont();
+  if (!gfxFont)
   {
     return;
   }
 
   // is the font in the cache?
-  ArthurFontID fontID = {*font->getID(), state->getFontSize()};
+  ArthurFontID fontID = {*gfxFont->getID(), state->getFontSize()};
   auto cacheEntry = m_rawFontCache.find(fontID);
 
   if (cacheEntry!=m_rawFontCache.end()) {
@@ -316,14 +316,14 @@ void ArthurOutputDev::updateFont(GfxState *state)
     // New font: load it into the cache
     float fontSize = state->getFontSize();
 
-    GfxFontLoc* fontLoc = font->locateFont(xref, nullptr);
+    std::unique_ptr<GfxFontLoc> fontLoc(gfxFont->locateFont(xref, nullptr));
 
     if (fontLoc) {
       // load the font from respective location
       switch (fontLoc->locType) {
       case gfxFontLocEmbedded: {// if there is an embedded font, read it to memory
         int fontDataLen;
-        const char* fontData = font->readEmbFontFile(xref, &fontDataLen);
+        const char* fontData = gfxFont->readEmbFontFile(xref, &fontDataLen);
 
         m_rawFont = new QRawFont(QByteArray(fontData, fontDataLen), fontSize);
         m_rawFontCache.insert(std::make_pair(fontID,std::unique_ptr<QRawFont>(m_rawFont)));
@@ -362,12 +362,9 @@ void ArthurOutputDev::updateFont(GfxState *state)
   // *****************************************************************************
 
 #ifdef HAVE_SPLASH
-  GfxFont *gfxFont;
-  GfxFontLoc *fontLoc;
   GfxFontType fontType;
-  SplashOutFontFileID *id;
   SplashFontFile *fontFile;
-  SplashFontSrc *fontsrc = NULL;
+  SplashFontSrc *fontsrc = nullptr;
   FoFiTrueType *ff;
   Object refObj, strObj;
   GooString *fileName;
@@ -381,29 +378,26 @@ void ArthurOutputDev::updateFont(GfxState *state)
   SplashFTFontFile* ftFontFile;
 
   m_needFontUpdate = false;
-  fileName = NULL;
-  tmpBuf = NULL;
-  fontLoc = NULL;
+  fileName = nullptr;
+  tmpBuf = nullptr;
 
-  if (!(gfxFont = state->getFont())) {
-    goto err1;
-  }
   fontType = gfxFont->getType();
   if (fontType == fontType3) {
-    goto err1;
+    return;
   }
 
   // Default: no codeToGID table
   m_codeToGID = nullptr;
 
   // check the font file cache
-  id = new SplashOutFontFileID(gfxFont->getID());
+  SplashOutFontFileID *id = new SplashOutFontFileID(gfxFont->getID());
   if ((fontFile = m_fontEngine->getFontFile(id))) {
     delete id;
 
   } else {
 
-    if (!(fontLoc = gfxFont->locateFont(xref, NULL))) {
+    std::unique_ptr<GfxFontLoc> fontLoc(gfxFont->locateFont(xref, nullptr));
+    if (!fontLoc) {
       error(errSyntaxError, -1, "Couldn't find a font for '{0:s}'",
 	    gfxFont->getName() ? gfxFont->getName()->getCString()
 	                       : "(unnamed)");
@@ -475,7 +469,7 @@ void ArthurOutputDev::updateFont(GfxState *state)
 	n = 256;
 	delete ff;
       } else {
-	codeToGID = NULL;
+	codeToGID = nullptr;
 	n = 0;
       }
       if (!(fontFile = m_fontEngine->loadTrueTypeFont(
@@ -506,7 +500,7 @@ void ArthurOutputDev::updateFont(GfxState *state)
 	memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(),
 	       n * sizeof(int));
       } else {
-	codeToGID = NULL;
+	codeToGID = nullptr;
 	n = 0;
       }      
       if (!(fontFile = m_fontEngine->loadOpenTypeCFFFont(
@@ -521,7 +515,7 @@ void ArthurOutputDev::updateFont(GfxState *state)
       break;
     case fontCIDType2:
     case fontCIDType2OT:
-      codeToGID = NULL;
+      codeToGID = nullptr;
       n = 0;
       if (((GfxCIDFont *)gfxFont)->getCIDToGID()) {
 	n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen();
@@ -566,18 +560,12 @@ void ArthurOutputDev::updateFont(GfxState *state)
   // font in the Splash font cache.  Otherwise we'd load it again and again.
   m_fontEngine->getFont(fontFile, mat, matrix);
 
-  delete fontLoc;
   if (fontsrc && !fontsrc->isFile)
       fontsrc->unref();
   return;
 
  err2:
   delete id;
-  delete fontLoc;
- err1:
-  if (fontsrc && !fontsrc->isFile)
-      fontsrc->unref();
-  return;
 #endif
 }
 
@@ -753,7 +741,7 @@ void ArthurOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
 
   row_stride = (width + 3) & ~3;
   buffer = (unsigned char *) malloc (height * row_stride);
-  if (buffer == NULL) {
+  if (buffer == nullptr) {
     error(-1, "Unable to allocate memory for image.");
     return;
   }
@@ -778,10 +766,10 @@ void ArthurOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
 
   image = cairo_image_surface_create_for_data (buffer, CAIRO_FORMAT_A8,
 					  width, height, row_stride);
-  if (image == NULL)
+  if (image == nullptr)
     return;
   pattern = cairo_pattern_create_for_surface (image);
-  if (pattern == NULL)
+  if (pattern == nullptr)
     return;
 
   ctm = state->getCTM();
diff --git a/qt5/src/ArthurOutputDev.h b/qt5/src/ArthurOutputDev.h
index 9ebdcec1..496f5a72 100644
--- a/qt5/src/ArthurOutputDev.h
+++ b/qt5/src/ArthurOutputDev.h
@@ -44,9 +44,6 @@
 #include <QtGui/QPainter>
 
 class GfxState;
-class GfxPath;
-class Gfx8BitFont;
-struct GfxRGB;
 
 class SplashFontEngine;
 
@@ -175,7 +172,6 @@ public:
 private:
   QPainter *m_painter;
   FontHinting m_fontHinting;
-  QFont m_currentFont;
   QPen m_currentPen;
   QBrush m_currentBrush;
   GBool m_needFontUpdate;		// set when the font needs to be updated


More information about the poppler mailing list