[poppler] glib/poppler-annot.cc poppler/Annot.cc poppler/Annot.h poppler/Gfx.cc qt4/src

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Sun Dec 6 06:47:49 PST 2009


 glib/poppler-annot.cc         |    2 +-
 poppler/Annot.cc              |   24 +++++-------------------
 poppler/Annot.h               |    5 ++---
 poppler/Gfx.cc                |    2 +-
 qt4/src/poppler-annotation.cc |    2 +-
 5 files changed, 10 insertions(+), 25 deletions(-)

New commits:
commit 6798d3e52e36e91bceff3a1a96372e9d9c6f3813
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Sun Dec 6 15:34:36 2009 +0100

    Use fixed size array in AnnotColor

diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index e019eca..50496e7 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -391,7 +391,7 @@ poppler_annot_get_color (PopplerAnnot *poppler_annot)
   color = poppler_annot->annot->getColor ();
 
   if (color) {
-    double *values = color->getValues ();
+    const double *values = color->getValues ();
 
     switch (color->getSpace ())
       {
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index fb65ea6..dd360ec 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -607,19 +607,16 @@ AnnotBorderBS::AnnotBorderBS(Dict *dict) {
 
 AnnotColor::AnnotColor() {
   length = 0;
-  values = NULL;
 }
 
 AnnotColor::AnnotColor(double gray) {
   length = 1;
-  values = (double *) gmallocn (length, sizeof(double));
 
   values[0] = gray;
 }
 
 AnnotColor::AnnotColor(double r, double g, double b) {
   length = 3;
-  values = (double *) gmallocn (length, sizeof(double));
 
   values[0] = r;
   values[1] = g;
@@ -628,7 +625,6 @@ AnnotColor::AnnotColor(double r, double g, double b) {
 
 AnnotColor::AnnotColor(double c, double m, double y, double k) {
   length = 4;
-  values = (double *) gmallocn (length, sizeof(double));
 
   values[0] = c;
   values[1] = m;
@@ -637,12 +633,11 @@ AnnotColor::AnnotColor(double c, double m, double y, double k) {
 }
 
 AnnotColor::AnnotColor(Array *array) {
-  // TODO: check what Acrobat does in the case of having more than 5 numbers.
-  if (array->getLength() < 5) {
-    length = array->getLength();
-    values = (double *) gmallocn (length, sizeof(double));
+  length = array->getLength();
+  if (length > 4)
+    length = 4;
 
-    for(int i = 0; i < length; i++) {  
+  for (int i = 0; i < length; i++) {
       Object obj1;
 
       if (array->get(i, &obj1)->isNum()) {
@@ -654,18 +649,9 @@ AnnotColor::AnnotColor(Array *array) {
         values[i] = 0;
       }
       obj1.free();
-    }
-  } else {
-    values = NULL;
-    length = 0;
   }
 }
 
-AnnotColor::~AnnotColor() {
-  if (values)
-    gfree (values);
-}
-
 //------------------------------------------------------------------------
 // AnnotBorderStyle
 //------------------------------------------------------------------------
@@ -1076,7 +1062,7 @@ void Annot::setColor(AnnotColor *new_color) {
 
   if (new_color) {
     Object obj1, obj2;
-    double *values = new_color->getValues();
+    const double *values = new_color->getValues();
 
     obj1.initArray(xref);
     for (int i = 0; i < (int)new_color->getSpace(); i++)
diff --git a/poppler/Annot.h b/poppler/Annot.h
index cb0bc96..3f3ed70 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -291,14 +291,13 @@ public:
   AnnotColor(double r, double g, double b);
   AnnotColor(double c, double m, double y, double k);
   AnnotColor(Array *array);
-  ~AnnotColor();
 
   AnnotColorSpace getSpace() const { return (AnnotColorSpace) length; }
-  double *getValues() const { return values; }
+  const double *getValues() const { return values; }
 
 private:
 
-  double *values;
+  double values[4];
   int length;
 };
 
diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 2a4c9b8..401b52e 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -4675,7 +4675,7 @@ void Gfx::drawAnnot(Object *str, AnnotBorder *border, AnnotColor *aColor,
       out->updateStrokeColorSpace(state);
     }
     if (aColor && (aColor->getSpace() == AnnotColor::colorRGB)) {
-      double *values = aColor->getValues();
+      const double *values = aColor->getValues();
       r = values[0];
       g = values[1];
       b = values[2];
diff --git a/qt4/src/poppler-annotation.cc b/qt4/src/poppler-annotation.cc
index 22f1e6a..98573c0 100644
--- a/qt4/src/poppler-annotation.cc
+++ b/qt4/src/poppler-annotation.cc
@@ -2039,7 +2039,7 @@ QColor convertAnnotColor( AnnotColor *color )
         return QColor();
 
     QColor newcolor;
-    double *color_data = color->getValues();
+    const double *color_data = color->getValues();
     switch ( color->getSpace() )
     {
         case AnnotColor::colorTransparent: // = 0,


More information about the poppler mailing list