[poppler] poppler/Annot.cc poppler/Form.cc poppler/Gfx.cc poppler/GfxState.cc poppler/Link.cc poppler/Object.h poppler/PageTransition.cc poppler/ViewerPreferences.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Jan 5 23:50:42 UTC 2020


 poppler/Annot.cc             |   43 ++++++----------------------------------
 poppler/Form.cc              |    5 +---
 poppler/Gfx.cc               |   15 +++-----------
 poppler/GfxState.cc          |    7 ++----
 poppler/Link.cc              |    9 +-------
 poppler/Object.h             |    6 ++++-
 poppler/PageTransition.cc    |    8 +------
 poppler/ViewerPreferences.cc |   46 ++++++++-----------------------------------
 8 files changed, 34 insertions(+), 105 deletions(-)

New commits:
commit 63ca4951f85b1f9d4a66d24d761e9984327bb20f
Author: Albert Astals Cid <aacid at kde.org>
Date:   Wed Oct 30 23:36:35 2019 +0100

    Introduce Object::getBoolWithDefaultValue
    
    makes code slightly more readable

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 37165e38..98f9dfef 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -15,7 +15,7 @@
 //
 // Copyright (C) 2006 Scott Turner <scotty1024 at mac.com>
 // Copyright (C) 2007, 2008 Julien Rebetez <julienr at svn.gnome.org>
-// Copyright (C) 2007-2013, 2015-2019 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2007-2013, 2015-2020 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2007-2013, 2018 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright (C) 2007, 2008 Iñigo Martínez <inigomartinez at gmail.com>
 // Copyright (C) 2007 Jeff Muizelaar <jeff at infidigm.net>
@@ -855,12 +855,7 @@ AnnotIconFit::AnnotIconFit(Dict* dict) {
     left = bottom = 0.5;
   }
 
-  obj1 = dict->lookup("FB");
-  if (obj1.isBool()) {
-    fullyBounds = obj1.getBool();
-  } else {
-    fullyBounds = false;
-  }
+  fullyBounds = dict->lookup("FB").getBoolWithDefaultValue(false);
 }
 
 //------------------------------------------------------------------------
@@ -1929,12 +1924,7 @@ void AnnotPopup::initialize(PDFDoc *docA, Dict *dict) {
     parentRef = Ref::INVALID();
   }
 
-  Object obj1 = dict->lookup("Open");
-  if (obj1.isBool()) {
-    open = obj1.getBool();
-  } else {
-    open = false;
-  }
+  open = dict->lookup("Open").getBoolWithDefaultValue(false);
 }
 
 void AnnotPopup::setParent(Annot *parentA) {
@@ -2117,11 +2107,7 @@ AnnotText::~AnnotText() = default;
 void AnnotText::initialize(PDFDoc *docA, Dict *dict) {
   Object obj1;
 
-  obj1 = dict->lookup("Open");
-  if (obj1.isBool())
-    open = obj1.getBool();
-  else
-    open = false;
+  open = dict->lookup("Open").getBoolWithDefaultValue(false);
 
   obj1 = dict->lookup("Name");
   if (obj1.isName()) {
@@ -3036,12 +3022,7 @@ void AnnotLine::initialize(PDFDoc *docA, Dict *dict) {
   if (leaderLineExtension < 0)
     leaderLineExtension = 0;
 
-  obj1 = dict->lookup("Cap");
-  if (obj1.isBool()) {
-    caption = obj1.getBool();
-  } else {
-    caption = false;
-  }
+  caption = dict->lookup("Cap").getBoolWithDefaultValue(false);
 
   obj1 = dict->lookup("IT");
   if (obj1.isName()) {
@@ -6376,19 +6357,9 @@ Annot3D::Activation::Activation(Dict *dict) {
     dState = dStateUnknown;
   }
 
-  obj1 = dict->lookup("TB");
-  if (obj1.isBool()) {
-    displayToolbar = obj1.getBool();
-  } else {
-    displayToolbar = true;
-  }
+  displayToolbar = dict->lookup("TB").getBoolWithDefaultValue(true);
 
-  obj1 = dict->lookup("NP");
-  if (obj1.isBool()) {
-    displayNavigation = obj1.getBool();
-  } else {
-    displayNavigation = false;
-  }
+  displayNavigation = dict->lookup("NP").getBoolWithDefaultValue(false);
 }
 
 //------------------------------------------------------------------------
diff --git a/poppler/Form.cc b/poppler/Form.cc
index c9ce7b78..2a8d5df6 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -5,7 +5,7 @@
 // This file is licensed under the GPLv2 or later
 //
 // Copyright 2006-2008 Julien Rebetez <julienr at svn.gnome.org>
-// Copyright 2007-2012, 2015-2019 Albert Astals Cid <aacid at kde.org>
+// Copyright 2007-2012, 2015-2020 Albert Astals Cid <aacid at kde.org>
 // Copyright 2007-2008, 2011 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright 2007, 2013, 2016 Adrian Johnson <ajohnson at redneon.com>
 // Copyright 2007 Iñigo Martínez <inigomartinez at gmail.com>
@@ -1831,8 +1831,7 @@ Form::Form(PDFDoc *docA, Object* acroFormA)
   defaultAppearance = nullptr;
   defaultResources = nullptr;
 
-  obj1 = acroForm->dictLookup("NeedAppearances");
-  needAppearances = (obj1.isBool() && obj1.getBool());
+  needAppearances = acroForm->dictLookup("NeedAppearances").getBoolWithDefaultValue(false);
 
   obj1 = acroForm->dictLookup("DA");
   if (obj1.isString())
diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 58c36fcb..9773b60c 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -14,7 +14,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2005 Jonathan Blandford <jrb at redhat.com>
-// Copyright (C) 2005-2013, 2015-2019 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005-2013, 2015-2020 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2006 Thorkild Stray <thorkild at ifi.uio.no>
 // Copyright (C) 2006 Kristian Høgsberg <krh at redhat.com>
 // Copyright (C) 2006-2011 Carlos Garcia Campos <carlosgc at gnome.org>
@@ -986,7 +986,7 @@ void Gfx::opSetExtGState(Object args[], int numArgs) {
   Function *funcs[4];
   GfxColor backdropColor;
   bool haveBackdropColor;
-  bool alpha, isolated, knockout;
+  bool alpha;
   double opac;
   int i;
 
@@ -1193,19 +1193,12 @@ void Gfx::opSetExtGState(Object args[], int numArgs) {
 	Object obj4 = obj3.streamGetDict()->lookup("Group");
 	if (obj4.isDict()) {
 	  GfxColorSpace *blendingColorSpace = nullptr;
-	  isolated = knockout = false;
 	  Object obj5 = obj4.dictLookup("CS");
 	  if (!obj5.isNull()) {
 	    blendingColorSpace = GfxColorSpace::parse(res, &obj5, out, state);
 	  }
-	  obj5 = obj4.dictLookup("I");
-	  if (obj5.isBool()) {
-	    isolated = obj5.getBool();
-	  }
-	  obj5 = obj4.dictLookup("K");
-	  if (obj5.isBool()) {
-	    knockout = obj5.getBool();
-	  }
+	  const bool isolated = obj4.dictLookup("I").getBoolWithDefaultValue(false);
+	  const bool knockout = obj4.dictLookup("K").getBoolWithDefaultValue(false);
 	  if (!haveBackdropColor) {
 	    if (blendingColorSpace) {
 	      blendingColorSpace->getDefaultColor(&backdropColor);
diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc
index 9aca67b3..f52603be 100644
--- a/poppler/GfxState.cc
+++ b/poppler/GfxState.cc
@@ -16,7 +16,7 @@
 // Copyright (C) 2005 Kristian Høgsberg <krh at redhat.com>
 // Copyright (C) 2006, 2007 Jeff Muizelaar <jeff at infidigm.net>
 // Copyright (C) 2006, 2010 Carlos Garcia Campos <carlosgc at gnome.org>
-// Copyright (C) 2006-2019 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2006-2020 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2009, 2012 Koji Otani <sho at bbr.jp>
 // Copyright (C) 2009, 2011-2016 Thomas Freitag <Thomas.Freitag at alfa.de>
 // Copyright (C) 2009, 2019 Christian Persch <chpe at gnome.org>
@@ -4200,9 +4200,8 @@ GfxRadialShading *GfxRadialShading::parse(GfxResources *res, Dict *dict, OutputD
   extend0A = extend1A = false;
   obj1 = dict->lookup("Extend");
   if (obj1.isArray() && obj1.arrayGetLength() == 2) {
-    Object obj2;
-    extend0A = (obj2 = obj1.arrayGet(0), obj2.isBool() ? obj2.getBool() : false);
-    extend1A = (obj2 = obj1.arrayGet(1), obj2.isBool() ? obj2.getBool() : false);
+    extend0A = obj1.arrayGet(0).getBoolWithDefaultValue(false);
+    extend1A = obj1.arrayGet(1).getBoolWithDefaultValue(false);
   }
 
   shading = new GfxRadialShading(x0A, y0A, r0A, x1A, y1A, r1A, t0A, t1A,
diff --git a/poppler/Link.cc b/poppler/Link.cc
index c9af4033..8d823919 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -16,7 +16,7 @@
 // Copyright (C) 2006, 2008 Pino Toscano <pino at kde.org>
 // Copyright (C) 2007, 2010, 2011 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright (C) 2008 Hugo Mercier <hmercier31 at gmail.com>
-// Copyright (C) 2008-2010, 2012-2014, 2016-2019 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2008-2010, 2012-2014, 2016-2020 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2009 Kovid Goyal <kovid at kovidgoyal.net>
 // Copyright (C) 2009 Ilya Gorenbein <igorenbein at finjan.com>
 // Copyright (C) 2012 Tobias Koening <tobias.koenig at kdab.com>
@@ -827,8 +827,6 @@ Object LinkJavaScript::createObject(XRef *xref, const GooString &js)
 LinkOCGState::LinkOCGState(const Object *obj)
 : isValid(true)
 {
-  preserveRB = true;
-
   Object obj1 = obj->dictLookup("State");
   if (obj1.isArray()) {
     StateList stList;
@@ -866,10 +864,7 @@ LinkOCGState::LinkOCGState(const Object *obj)
     isValid = false;
   }
 
-  obj1 = obj->dictLookup("PreserveRB");
-  if (obj1.isBool()) {
-    preserveRB = obj1.getBool();
-  }
+  preserveRB = obj->dictLookup("PreserveRB").getBoolWithDefaultValue(true);
 }
 
 //------------------------------------------------------------------------
diff --git a/poppler/Object.h b/poppler/Object.h
index 1b7a0e60..ecc0b640 100644
--- a/poppler/Object.h
+++ b/poppler/Object.h
@@ -15,7 +15,7 @@
 //
 // Copyright (C) 2007 Julien Rebetez <julienr at svn.gnome.org>
 // Copyright (C) 2008 Kees Cook <kees at outflux.net>
-// Copyright (C) 2008, 2010, 2017-2019 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2008, 2010, 2017-2020 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2009 Jakub Wilk <jwilk at jwilk.net>
 // Copyright (C) 2012 Fabio D'Urso <fabiodurso at hotmail.it>
 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag at alfa.de>
@@ -309,6 +309,10 @@ public:
     return type == objInt ? (double)intg : type == objInt64 ? (double)int64g : real;
   }
 
+  bool getBoolWithDefaultValue(bool defaultValue) const {
+    return (type == objBool) ? booln : defaultValue;
+  }
+
 private:
   // Free object contents.
   void free();
diff --git a/poppler/PageTransition.cc b/poppler/PageTransition.cc
index 97226868..65b27d99 100644
--- a/poppler/PageTransition.cc
+++ b/poppler/PageTransition.cc
@@ -1,6 +1,6 @@
 /* PageTransition.cc
  * Copyright (C) 2005, Net Integration Technologies, Inc.
- * Copyright (C) 2010, 2017, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2010, 2017, 2020, Albert Astals Cid <aacid at kde.org>
  * Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
  * Copyright (C) 2015, Arseniy Lartsev <arseniy at alumni.chalmers.se>
  *
@@ -35,7 +35,6 @@ PageTransition::PageTransition (Object *trans) {
   direction = transitionInward;
   angle = 0;
   scale = 1.0;
-  rectangular = false;
   ok = true;
 
   if (!trans || !trans->isDict ()) {
@@ -123,10 +122,7 @@ PageTransition::PageTransition (Object *trans) {
   }
 
   // get rectangular
-  obj = dict->lookup("B");
-  if (obj.isBool()) {
-    rectangular = obj.getBool();
-  }
+  rectangular = dict->lookup("B").getBoolWithDefaultValue(false);
 }
 
 PageTransition::~PageTransition()
diff --git a/poppler/ViewerPreferences.cc b/poppler/ViewerPreferences.cc
index 3e96283f..5d3a6ae2 100644
--- a/poppler/ViewerPreferences.cc
+++ b/poppler/ViewerPreferences.cc
@@ -5,7 +5,7 @@
 // This file is licensed under the GPLv2 or later
 //
 // Copyright 2011 Pino Toscano <pino at kde.org>
-// Copyright 2017 Albert Astals Cid <aacid at kde.org>
+// Copyright 2017, 2020 Albert Astals Cid <aacid at kde.org>
 // Copyright 2019 Marek Kasik <mkasik at redhat.com>
 //
 //========================================================================
@@ -21,37 +21,19 @@ ViewerPreferences::ViewerPreferences(Dict *prefDict)
 {
   init();
 
-  Object obj = prefDict->lookup("HideToolbar");
-  if (obj.isBool()) {
-    hideToolbar = obj.getBool();
-  }
+  hideToolbar = prefDict->lookup("HideToolbar").getBoolWithDefaultValue(false);
 
-  obj = prefDict->lookup("HideMenubar");
-  if (obj.isBool()) {
-    hideMenubar = obj.getBool();
-  }
+  hideMenubar = prefDict->lookup("HideMenubar").getBoolWithDefaultValue(false);
 
-  obj = prefDict->lookup("HideWindowUI");
-  if (obj.isBool()) {
-    hideWindowUI = obj.getBool();
-  }
+  hideWindowUI = prefDict->lookup("HideWindowUI").getBoolWithDefaultValue(false);
 
-  obj = prefDict->lookup("FitWindow");
-  if (obj.isBool()) {
-    fitWindow = obj.getBool();
-  }
+  fitWindow = prefDict->lookup("FitWindow").getBoolWithDefaultValue(false);
 
-  obj = prefDict->lookup("CenterWindow");
-  if (obj.isBool()) {
-    centerWindow = obj.getBool();
-  }
+  centerWindow = prefDict->lookup("CenterWindow").getBoolWithDefaultValue(false);
 
-  obj = prefDict->lookup("DisplayDocTitle");
-  if (obj.isBool()) {
-    displayDocTitle = obj.getBool();
-  }
+  displayDocTitle = prefDict->lookup("DisplayDocTitle").getBoolWithDefaultValue(false);
 
-  obj = prefDict->lookup("NonFullScreenPageMode");
+  Object obj = prefDict->lookup("NonFullScreenPageMode");
   if (obj.isName()) {
     const char *mode = obj.getName();
     if (!strcmp(mode, "UseNone")) {
@@ -97,10 +79,7 @@ ViewerPreferences::ViewerPreferences(Dict *prefDict)
     }
   }
 
-  obj = prefDict->lookup("PickTrayByPDFSize");
-  if (obj.isBool()) {
-    pickTrayByPDFSize = obj.getBool();
-  }
+  pickTrayByPDFSize = prefDict->lookup("PickTrayByPDFSize").getBoolWithDefaultValue(false);
 
   obj = prefDict->lookup("NumCopies");
   if (obj.isInt()) {
@@ -140,16 +119,9 @@ ViewerPreferences::~ViewerPreferences()
 
 void ViewerPreferences::init()
 {
-  hideToolbar = false;
-  hideMenubar = false;
-  hideWindowUI = false;
-  fitWindow = false;
-  centerWindow = false;
-  displayDocTitle = false;
   nonFullScreenPageMode = nfpmUseNone;
   direction = directionL2R;
   printScaling = printScalingAppDefault;
   duplex = duplexNone;
-  pickTrayByPDFSize = false;
   numCopies = 1;
 }


More information about the poppler mailing list