Ok, in the end I've decided to no change the behaviour of widget
annotations since they are special case anyway. So I've updated the
patches to make them build with qt frontends (I left the annot border
type, but removed the unknown type) and I don't use a default border for
widget annotations. The only regression is the document with square
annots that we now render a border, but acroread doesn't.

Regards, 

Attachment: pgp_gozJm4Wmj.pgp
Description: PGP signature

>From 74b81e1307737b6e12db16338b8a9403fb6e4ff0 Mon Sep 17 00:00:00 2001
From: Carlos Garcia Campos <[email protected]>
Date: Tue, 26 Nov 2013 11:40:57 +0100
Subject: [PATCH 1/4] annots: Remove unused typeUnknown AnnotBorderType from
 AnnotBorder

Also make the AnnotBorder constructor protected to make sure it's not
possible to create AnnotBorder instances.
---
 poppler/Annot.cc |  3 ---
 poppler/Annot.h  | 12 ++++++++----
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 5b83db2..021a49d 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -520,7 +520,6 @@ AnnotQuadrilaterals::AnnotQuadrilateral::AnnotQuadrilateral(double x1, double y1
 // AnnotBorder
 //------------------------------------------------------------------------
 AnnotBorder::AnnotBorder() {
-  type = typeUnknown;
   width = 1;
   dashLength = 0;
   dash = NULL;
@@ -565,7 +564,6 @@ AnnotBorder::~AnnotBorder() {
 //------------------------------------------------------------------------
 
 AnnotBorderArray::AnnotBorderArray() {
-  type = typeArray;
   horizontalCorner = 0;
   verticalCorner = 0;
 }
@@ -627,7 +625,6 @@ void AnnotBorderArray::writeToObject(XRef *xref, Object *obj1) const {
 //------------------------------------------------------------------------
 
 AnnotBorderBS::AnnotBorderBS() {
-  type = typeBS;
 }
 
 AnnotBorderBS::AnnotBorderBS(Dict *dict) {
diff --git a/poppler/Annot.h b/poppler/Annot.h
index bd3ff80..e5eac45 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -216,7 +216,6 @@ protected:
 class AnnotBorder {
 public:
   enum AnnotBorderType {
-    typeUnknown,
     typeArray,
     typeBS
   };
@@ -229,18 +228,19 @@ public:
     borderUnderlined  // Underlined
   };
 
-  AnnotBorder();
   virtual ~AnnotBorder();
 
   virtual void setWidth(double new_width) { width = new_width; }
 
-  virtual AnnotBorderType getType() const { return type; }
+  virtual AnnotBorderType getType() const = 0;
   virtual double getWidth() const { return width; }
   virtual int getDashLength() const { return dashLength; }
   virtual double *getDash() const { return dash; }
   virtual AnnotBorderStyle getStyle() const { return style; }
 
 protected:
+  AnnotBorder();
+
   GBool parseDashArray(Object *dashObj);
 
   AnnotBorderType type;
@@ -268,7 +268,9 @@ public:
   double getHorizontalCorner() const { return horizontalCorner; }
   double getVerticalCorner() const { return verticalCorner; }
 
-protected:
+private:
+  virtual AnnotBorderType getType() const { return typeArray; }
+
   double horizontalCorner;          // (Default 0)
   double verticalCorner;            // (Default 0)
   // double width;                  // (Default 1)  (inherited from AnnotBorder)
@@ -285,6 +287,8 @@ public:
   AnnotBorderBS(Dict *dict);
 
 private:
+  virtual AnnotBorderType getType() const { return typeBS; }
+
   // double width;           // W  (Default 1)   (inherited from AnnotBorder)
   // AnnotBorderStyle style; // S  (Default S)   (inherited from AnnotBorder)
   // double *dash;           // D  (Default [3]) (inherited from AnnotBorder)
-- 
1.8.4.3

>From 4d2690bd5e46a4737ac0b4f5879203f54e97b3d2 Mon Sep 17 00:00:00 2001
From: Carlos Garcia Campos <[email protected]>
Date: Tue, 26 Nov 2013 14:07:21 +0100
Subject: [PATCH 2/4] annots: Add helper function Annot::setLineStyleForBorder

It sets the line dash and width based on the given AnnotBorder. Use it
only when the border width is greater than 0 for FreeText annotations
and always for annotations that use the border to set the line width and
dash, but don't draw a border.
---
 poppler/Annot.cc | 110 ++++++++++++++++---------------------------------------
 poppler/Annot.h  |   1 +
 2 files changed, 32 insertions(+), 79 deletions(-)

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 021a49d..0661fd2 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -1660,6 +1660,26 @@ void Annot::setColor(AnnotColor *color, GBool fill) {
   }
 }
 
+void Annot::setLineStyleForBorder(AnnotBorder *border) {
+  int i, dashLength;
+  double *dash;
+
+  switch (border->getStyle()) {
+  case AnnotBorder::borderDashed:
+    appearBuf->append("[");
+    dashLength = border->getDashLength();
+    dash = border->getDash();
+    for (i = 0; i < dashLength; ++i)
+      appearBuf->appendf(" {0:.2f}", dash[i]);
+    appearBuf->append(" ] 0 d\n");
+    break;
+  default:
+    appearBuf->append("[] 0 d\n");
+    break;
+  }
+  appearBuf->appendf("{0:.2f} w\n", border->getWidth());
+}
+
 // Draw an (approximate) circle of radius <r> centered at (<cx>, <cy>).
 // If <fill> is true, the circle is filled; otherwise it is stroked.
 void Annot::drawCircle(double cx, double cy, double r, GBool fill) {
@@ -2925,29 +2945,10 @@ void AnnotFreeText::generateFreeTextAppearance()
 
   appearBuf = new GooString ();
   appearBuf->append ("q\n");
-  
-  if (border) {
-    int i, dashLength;
-    double *dash;
-    borderWidth = border->getWidth();
 
-    switch (border->getStyle()) {
-    case AnnotBorder::borderDashed:
-      appearBuf->append("[");
-      dashLength = border->getDashLength();
-      dash = border->getDash();
-      for (i = 0; i < dashLength; ++i)
-        appearBuf->appendf(" {0:.2f}", dash[i]);
-      appearBuf->append(" ] 0 d\n");
-      break;
-    default:
-      appearBuf->append("[] 0 d\n");
-      break;
-    }
-    appearBuf->appendf("{0:.2f} w\n", borderWidth);
-  } else {
-    borderWidth = 0; // No border
-  }
+  borderWidth = border ? border->getWidth() : 0;
+  if (borderWidth > 0)
+    setLineStyleForBorder(border);
 
   // Box size
   const double width = rect->x2 - rect->x1;
@@ -3331,7 +3332,7 @@ void AnnotLine::setIntent(AnnotLineIntent new_intent) {
 
 void AnnotLine::generateLineAppearance()
 {
-  double borderWidth, ca = opacity;
+  double borderWidth = 0, ca = opacity;
 
   appearBBox = new AnnotAppearanceBBox(rect);
   appearBuf = new GooString ();
@@ -3341,28 +3342,10 @@ void AnnotLine::generateLineAppearance()
   }
 
   if (border) {
-    int i, dashLength;
-    double *dash;
-
-    switch (border->getStyle()) {
-    case AnnotBorder::borderDashed:
-      appearBuf->append("[");
-      dashLength = border->getDashLength();
-      dash = border->getDash();
-      for (i = 0; i < dashLength; ++i)
-        appearBuf->appendf(" {0:.2f}", dash[i]);
-      appearBuf->append(" ] 0 d\n");
-      break;
-    default:
-      appearBuf->append("[] 0 d\n");
-      break;
-    }
+    setLineStyleForBorder(border);
     borderWidth = border->getWidth();
-    appearBuf->appendf("{0:.2f} w\n", borderWidth);
-    appearBBox->setBorderWidth(borderWidth);
-  } else {
-    borderWidth = 0;
   }
+  appearBBox->setBorderWidth(std::max(1., borderWidth));
 
   const double x1 = coord1->getX();
   const double y1 = coord1->getY();
@@ -5508,24 +5491,9 @@ void AnnotGeometry::draw(Gfx *gfx, GBool printing) {
       setColor(color, gFalse);
 
     if (border) {
-      int i, dashLength;
-      double *dash;
       double borderWidth = border->getWidth();
 
-      switch (border->getStyle()) {
-      case AnnotBorder::borderDashed:
-        appearBuf->append("[");
-	dashLength = border->getDashLength();
-	dash = border->getDash();
-	for (i = 0; i < dashLength; ++i)
-	  appearBuf->appendf(" {0:.2f}", dash[i]);
-	appearBuf->append(" ] 0 d\n");
-	break;
-      default:
-        appearBuf->append("[] 0 d\n");
-        break;
-      }
-      appearBuf->appendf("{0:.2f} w\n", borderWidth);
+      setLineStyleForBorder(border);
 
       if (interiorColor)
         setColor(interiorColor, gTrue);
@@ -5832,24 +5800,8 @@ void AnnotPolygon::draw(Gfx *gfx, GBool printing) {
     }
 
     if (border) {
-      int i, dashLength;
-      double *dash;
-
-      switch (border->getStyle()) {
-      case AnnotBorder::borderDashed:
-        appearBuf->append("[");
-        dashLength = border->getDashLength();
-        dash = border->getDash();
-        for (i = 0; i < dashLength; ++i)
-          appearBuf->appendf(" {0:.2f}", dash[i]);
-        appearBuf->append(" ] 0 d\n");
-        break;
-      default:
-        appearBuf->append("[] 0 d\n");
-        break;
-      }
-      appearBuf->appendf("{0:.2f} w\n", border->getWidth());
-      appearBBox->setBorderWidth(border->getWidth());
+      setLineStyleForBorder(border);
+      appearBBox->setBorderWidth(std::max(1., border->getWidth()));
     }
 
     if (interiorColor) {
@@ -6075,8 +6027,8 @@ void AnnotInk::draw(Gfx *gfx, GBool printing) {
     }
 
     if (border) {
-      appearBuf->appendf("{0:.2f} w\n", border->getWidth());
-      appearBBox->setBorderWidth(border->getWidth());
+      setLineStyleForBorder(border);
+      appearBBox->setBorderWidth(std::max(1., border->getWidth()));
     }
 
     for (int i = 0; i < inkListLength; ++i) {
diff --git a/poppler/Annot.h b/poppler/Annot.h
index e5eac45..0ff5042 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -624,6 +624,7 @@ protected:
   virtual ~Annot();
   virtual void removeReferencedObjects(); // Called by Page::removeAnnot
   void setColor(AnnotColor *color, GBool fill);
+  void setLineStyleForBorder(AnnotBorder *border);
   void drawCircle(double cx, double cy, double r, GBool fill);
   void drawCircleTopLeft(double cx, double cy, double r);
   void drawCircleBottomRight(double cx, double cy, double r);
-- 
1.8.4.3

>From b3df9c3256672cbde2ba69e7517a14b7f25976dc Mon Sep 17 00:00:00 2001
From: Carlos Garcia Campos <[email protected]>
Date: Tue, 26 Nov 2013 14:44:57 +0100
Subject: [PATCH 3/4] annots: Use a default border for annots that can have a
 BS entry

According to the spec if neither the Border nor the BS entry is present,
the border shall be drawn as a solid line with a width of 1 point.
However, acroread seems to ignore the Border entry for annots that can't
have a BS entry.
---
 poppler/Annot.cc | 223 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 132 insertions(+), 91 deletions(-)

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 0661fd2..b94039f 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -1292,18 +1292,14 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) {
   }
 
   //----- parse the border style
-  if (dict->lookup("BS", &obj1)->isDict()) {
-    border = new AnnotBorderBS(obj1.getDict());
-  } else {
-    obj1.free();
-
-    if (dict->lookup("Border", &obj1)->isArray())
-      border = new AnnotBorderArray(obj1.getArray());
-    else
-      // Adobe draws no border at all if the last element is of
-      // the wrong type.
-      border = NULL;
-  }
+  // According to the spec if neither the Border nor the BS entry is present,
+  // the border shall be drawn as a solid line with a width of 1 point. But acroread
+  // seems to ignore the Border entry for annots that can't have a BS entry. So, we only
+  // follow this rule for annots tha can have a BS entry.
+  if (dict->lookup("Border", &obj1)->isArray())
+    border = new AnnotBorderArray(obj1.getArray());
+  else
+    border = NULL;
   obj1.free();
 
   if (dict->lookup("C", &obj1)->isArray()) {
@@ -2620,6 +2616,14 @@ void AnnotLink::initialize(PDFDoc *docA, Dict *dict) {
     quadrilaterals = NULL;
   }
   obj1.free();
+
+  if (dict->lookup("BS", &obj1)->isDict()) {
+    delete border;
+    border = new AnnotBorderBS(obj1.getDict());
+  } else if (!border) {
+    border = new AnnotBorderBS();
+  }
+  obj1.free();
 }
 
 void AnnotLink::draw(Gfx *gfx, GBool printing) {
@@ -2747,6 +2751,14 @@ void AnnotFreeText::initialize(PDFDoc *docA, Dict *dict) {
   }
   obj1.free();
 
+  if (dict->lookup("BS", &obj1)->isDict()) {
+    delete border;
+    border = new AnnotBorderBS(obj1.getDict());
+  } else if (!border) {
+    border = new AnnotBorderBS();
+  }
+  obj1.free();
+
   if (dict->lookup("BE", &obj1)->isDict()) {
     borderEffect = new AnnotBorderEffect(obj1.getDict());
   } else {
@@ -2946,7 +2958,7 @@ void AnnotFreeText::generateFreeTextAppearance()
   appearBuf = new GooString ();
   appearBuf->append ("q\n");
 
-  borderWidth = border ? border->getWidth() : 0;
+  borderWidth = border->getWidth();
   if (borderWidth > 0)
     setLineStyleForBorder(border);
 
@@ -3234,6 +3246,14 @@ void AnnotLine::initialize(PDFDoc *docA, Dict *dict) {
     captionTextHorizontal = captionTextVertical = 0;
   }
   obj1.free();
+
+  if (dict->lookup("BS", &obj1)->isDict()) {
+    delete border;
+    border = new AnnotBorderBS(obj1.getDict());
+  } else if (!border) {
+    border = new AnnotBorderBS();
+  }
+  obj1.free();
 }
 
 void AnnotLine::setContents(GooString *new_content) {
@@ -3332,7 +3352,7 @@ void AnnotLine::setIntent(AnnotLineIntent new_intent) {
 
 void AnnotLine::generateLineAppearance()
 {
-  double borderWidth = 0, ca = opacity;
+  double borderWidth, ca = opacity;
 
   appearBBox = new AnnotAppearanceBBox(rect);
   appearBuf = new GooString ();
@@ -3341,10 +3361,8 @@ void AnnotLine::generateLineAppearance()
     setColor(color, gFalse);
   }
 
-  if (border) {
-    setLineStyleForBorder(border);
-    borderWidth = border->getWidth();
-  }
+  setLineStyleForBorder(border);
+  borderWidth = border->getWidth();
   appearBBox->setBorderWidth(std::max(1., borderWidth));
 
   const double x1 = coord1->getX();
@@ -3906,6 +3924,12 @@ void AnnotWidget::initialize(PDFDoc *docA, Dict *dict) {
   }
   obj1.free();
 
+  if (dict->lookup("BS", &obj1)->isDict()) {
+    delete border;
+    border = new AnnotBorderBS(obj1.getDict());
+  }
+  obj1.free();
+
   updatedAppearanceStream.num = updatedAppearanceStream.gen = -1;
 }
 
@@ -5426,6 +5450,14 @@ void AnnotGeometry::initialize(PDFDoc *docA, Dict* dict) {
   }
   obj1.free();
 
+  if (dict->lookup("BS", &obj1)->isDict()) {
+    delete border;
+    border = new AnnotBorderBS(obj1.getDict());
+  } else if (!border) {
+    border = new AnnotBorderBS();
+  }
+  obj1.free();
+
   if (dict->lookup("BE", &obj1)->isDict()) {
     borderEffect = new AnnotBorderEffect(obj1.getDict());
   } else {
@@ -5490,73 +5522,70 @@ void AnnotGeometry::draw(Gfx *gfx, GBool printing) {
     if (color)
       setColor(color, gFalse);
 
-    if (border) {
-      double borderWidth = border->getWidth();
-
-      setLineStyleForBorder(border);
+    double borderWidth = border->getWidth();
+    setLineStyleForBorder(border);
 
-      if (interiorColor)
-        setColor(interiorColor, gTrue);
+    if (interiorColor)
+      setColor(interiorColor, gTrue);
 
-      if (type == typeSquare) {
-        appearBuf->appendf ("{0:.2f} {1:.2f} {2:.2f} {3:.2f} re\n",
-			    borderWidth / 2.0, borderWidth / 2.0,
-			    (rect->x2 - rect->x1) - borderWidth,
-			    (rect->y2 - rect->y1) - borderWidth);
-      } else {
-        double width, height;
-	double b;
-	double x1, y1, x2, y2, x3, y3;
-
-	width = rect->x2 - rect->x1;
-	height = rect->y2 - rect->y1;
-	b = borderWidth / 2.0;
-
-	x1 = b;
-	y1 = height / 2.0;
-	appearBuf->appendf ("{0:.2f} {1:.2f} m\n", x1, y1);
-
-	y1 += height / 4.0;
-	x2 = width / 4.0;
-	y2 = height - b;
-	x3 = width / 2.0;
-	y3 = y2;
-	appearBuf->appendf ("{0:.2f} {1:.2f} {2:.2f} {3:.2f} {4:.2f} {5:.2f} c\n",
-			    x1, y1, x2, y2, x3, y3);
-	x2 = width - b;
-	y2 = y1;
-	x1 = x3 + (width / 4.0);
-	y1 = y3;
-	x3 = x2;
-	y3 = height / 2.0;
-	appearBuf->appendf ("{0:.2f} {1:.2f} {2:.2f} {3:.2f} {4:.2f} {5:.2f} c\n",
-			    x1, y1, x2, y2, x3, y3);
-
-	x2 = x1;
-	y2 = b;
-	x1 = x3;
-	y1 = height / 4.0;
-	x3 = width / 2.0;
-	y3 = b;
-	appearBuf->appendf ("{0:.2f} {1:.2f} {2:.2f} {3:.2f} {4:.2f} {5:.2f} c\n",
-			    x1, y1, x2, y2, x3, y3);
-
-	x2 = b;
-	y2 = y1;
-	x1 = width / 4.0;
-	y1 = b;
-	x3 = b;
-	y3 = height / 2.0;
-	appearBuf->appendf ("{0:.2f} {1:.2f} {2:.2f} {3:.2f} {4:.2f} {5:.2f} c\n",
-			    x1, y1, x2, y2, x3, y3);
+    if (type == typeSquare) {
+      appearBuf->appendf ("{0:.2f} {1:.2f} {2:.2f} {3:.2f} re\n",
+                          borderWidth / 2.0, borderWidth / 2.0,
+                          (rect->x2 - rect->x1) - borderWidth,
+                          (rect->y2 - rect->y1) - borderWidth);
+    } else {
+      double width, height;
+      double b;
+      double x1, y1, x2, y2, x3, y3;
+
+      width = rect->x2 - rect->x1;
+      height = rect->y2 - rect->y1;
+      b = borderWidth / 2.0;
+
+      x1 = b;
+      y1 = height / 2.0;
+      appearBuf->appendf ("{0:.2f} {1:.2f} m\n", x1, y1);
+
+      y1 += height / 4.0;
+      x2 = width / 4.0;
+      y2 = height - b;
+      x3 = width / 2.0;
+      y3 = y2;
+      appearBuf->appendf ("{0:.2f} {1:.2f} {2:.2f} {3:.2f} {4:.2f} {5:.2f} c\n",
+                          x1, y1, x2, y2, x3, y3);
+      x2 = width - b;
+      y2 = y1;
+      x1 = x3 + (width / 4.0);
+      y1 = y3;
+      x3 = x2;
+      y3 = height / 2.0;
+      appearBuf->appendf ("{0:.2f} {1:.2f} {2:.2f} {3:.2f} {4:.2f} {5:.2f} c\n",
+                          x1, y1, x2, y2, x3, y3);
+
+      x2 = x1;
+      y2 = b;
+      x1 = x3;
+      y1 = height / 4.0;
+      x3 = width / 2.0;
+      y3 = b;
+      appearBuf->appendf ("{0:.2f} {1:.2f} {2:.2f} {3:.2f} {4:.2f} {5:.2f} c\n",
+                          x1, y1, x2, y2, x3, y3);
+
+      x2 = b;
+      y2 = y1;
+      x1 = width / 4.0;
+      y1 = b;
+      x3 = b;
+      y3 = height / 2.0;
+      appearBuf->appendf ("{0:.2f} {1:.2f} {2:.2f} {3:.2f} {4:.2f} {5:.2f} c\n",
+                          x1, y1, x2, y2, x3, y3);
+    }
 
-      }
+    if (interiorColor && interiorColor->getSpace() != AnnotColor::colorTransparent)
+      appearBuf->append ("b\n");
+    else
+      appearBuf->append ("S\n");
 
-      if (interiorColor && interiorColor->getSpace() != AnnotColor::colorTransparent)
-        appearBuf->append ("b\n");
-      else
-        appearBuf->append ("S\n");
-    }
     appearBuf->append ("Q\n");
 
     double bbox[4];
@@ -5680,6 +5709,14 @@ void AnnotPolygon::initialize(PDFDoc *docA, Dict* dict) {
   }
   obj1.free();
 
+  if (dict->lookup("BS", &obj1)->isDict()) {
+    delete border;
+    border = new AnnotBorderBS(obj1.getDict());
+  } else if (!border) {
+    border = new AnnotBorderBS();
+  }
+  obj1.free();
+
   if (dict->lookup("BE", &obj1)->isDict()) {
     borderEffect = new AnnotBorderEffect(obj1.getDict());
   } else {
@@ -5799,10 +5836,8 @@ void AnnotPolygon::draw(Gfx *gfx, GBool printing) {
       setColor(color, gFalse);
     }
 
-    if (border) {
-      setLineStyleForBorder(border);
-      appearBBox->setBorderWidth(std::max(1., border->getWidth()));
-    }
+    setLineStyleForBorder(border);
+    appearBBox->setBorderWidth(std::max(1., border->getWidth()));
 
     if (interiorColor) {
       setColor(interiorColor, gTrue);
@@ -5959,6 +5994,14 @@ void AnnotInk::initialize(PDFDoc *docA, Dict* dict) {
     ok = gFalse;
   }
   obj1.free();
+
+  if (dict->lookup("BS", &obj1)->isDict()) {
+    delete border;
+    border = new AnnotBorderBS(obj1.getDict());
+  } else if (!border) {
+    border = new AnnotBorderBS();
+  }
+  obj1.free();
 }
 
 void AnnotInk::writeInkList(AnnotPath **paths, int n_paths, Array *dest_array) {
@@ -6026,10 +6069,8 @@ void AnnotInk::draw(Gfx *gfx, GBool printing) {
       setColor(color, gFalse);
     }
 
-    if (border) {
-      setLineStyleForBorder(border);
-      appearBBox->setBorderWidth(std::max(1., border->getWidth()));
-    }
+    setLineStyleForBorder(border);
+    appearBBox->setBorderWidth(std::max(1., border->getWidth()));
 
     for (int i = 0; i < inkListLength; ++i) {
       const AnnotPath * path = inkList[i];
@@ -6290,7 +6331,7 @@ void AnnotFileAttachment::draw(Gfx *gfx, GBool printing) {
 
   // draw the appearance stream
   appearance.fetch(gfx->getXRef(), &obj);
-  gfx->drawAnnot(&obj, border, color,
+  gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
 		 rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
   obj.free();
 }
@@ -6452,7 +6493,7 @@ void AnnotSound::draw(Gfx *gfx, GBool printing) {
 
   // draw the appearance stream
   appearance.fetch(gfx->getXRef(), &obj);
-  gfx->drawAnnot(&obj, border, color,
+  gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
 		 rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
   obj.free();
 }
-- 
1.8.4.3

>From 50da1b629818cabbb722a889bea0c86b6cbfbdae Mon Sep 17 00:00:00 2001
From: Carlos Garcia Campos <[email protected]>
Date: Tue, 26 Nov 2013 20:12:22 +0100
Subject: [PATCH 4/4] annots: Make Annot::setBorder receive an AnnotBorder
 object

Instead of receiving AnnotBorderArray. Also implement writeToObject in
both AnnotBorderArray and AnnotBorderBS to make sure that
Annot::setBorder will work for both cases.
---
 poppler/Annot.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++------
 poppler/Annot.h  | 10 +++++++---
 2 files changed, 52 insertions(+), 9 deletions(-)

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index b94039f..90a6e5d 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -614,10 +614,17 @@ void AnnotBorderArray::writeToObject(XRef *xref, Object *obj1) const {
   Object obj2;
 
   obj1->initArray(xref);
-  obj1->arrayAdd(obj2.initReal( horizontalCorner ));
-  obj1->arrayAdd(obj2.initReal( verticalCorner ));
-  obj1->arrayAdd(obj2.initReal( width ));
-  // TODO: Dash array
+  obj1->arrayAdd(obj2.initReal(horizontalCorner));
+  obj1->arrayAdd(obj2.initReal(verticalCorner));
+  obj1->arrayAdd(obj2.initReal(width));
+
+  if (dashLength > 0) {
+    Object obj3;
+
+    obj1->arrayAdd(obj3.initArray(xref));
+    for (int i = 0; i < dashLength; i++)
+      obj3.arrayAdd(obj2.initReal(dash[i]));
+  }
 }
 
 //------------------------------------------------------------------------
@@ -675,6 +682,38 @@ AnnotBorderBS::AnnotBorderBS(Dict *dict) {
   }
 }
 
+const char *AnnotBorderBS::getStyleName() const {
+  switch (style) {
+  case borderSolid:
+    return "S";
+  case borderDashed:
+    return "D";
+  case borderBeveled:
+    return "B";
+  case borderInset:
+    return "I";
+  case borderUnderlined:
+    return "U";
+  }
+
+  return "S";
+}
+
+void AnnotBorderBS::writeToObject(XRef *xref, Object *obj1) const {
+  Object obj2;
+
+  obj1->initDict(xref);
+  obj1->dictSet("W", obj2.initReal(width));
+  obj1->dictSet("S", obj2.initName(getStyleName()));
+  if (style == borderDashed && dashLength > 0) {
+    Object obj3;
+
+    obj1->dictSet("D", obj3.initArray(xref));
+    for (int i = 0; i < dashLength; i++)
+      obj3.arrayAdd(obj2.initReal(dash[i]));
+  }
+}
+
 //------------------------------------------------------------------------
 // AnnotColor
 //------------------------------------------------------------------------
@@ -1441,14 +1480,14 @@ void Annot::setFlags(Guint new_flags) {
   update ("F", &obj1);
 }
 
-void Annot::setBorder(AnnotBorderArray *new_border) {
+void Annot::setBorder(AnnotBorder *new_border) {
   annotLocker();
   delete border;
 
   if (new_border) {
     Object obj1;
     new_border->writeToObject(xref, &obj1);
-    update ("Border", &obj1);
+    update(new_border->getType() == AnnotBorder::typeArray ? "Border" : "BS", &obj1);
     border = new_border;
   } else {
     border = NULL;
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 0ff5042..8fde6a6 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -238,6 +238,8 @@ public:
   virtual double *getDash() const { return dash; }
   virtual AnnotBorderStyle getStyle() const { return style; }
 
+  virtual void writeToObject(XRef *xref, Object *obj1) const = 0;
+
 protected:
   AnnotBorder();
 
@@ -260,8 +262,6 @@ public:
   AnnotBorderArray();
   AnnotBorderArray(Array *array);
 
-  void writeToObject(XRef *xref, Object *dest) const;
-
   void setHorizontalCorner(double hc) { horizontalCorner = hc; }
   void setVerticalCorner(double vc) { verticalCorner = vc; }
 
@@ -270,6 +270,7 @@ public:
 
 private:
   virtual AnnotBorderType getType() const { return typeArray; }
+  virtual void writeToObject(XRef *xref, Object *obj1) const;
 
   double horizontalCorner;          // (Default 0)
   double verticalCorner;            // (Default 0)
@@ -288,6 +289,9 @@ public:
 
 private:
   virtual AnnotBorderType getType() const { return typeBS; }
+  virtual void writeToObject(XRef *xref, Object *obj1) const;
+
+  const char *getStyleName() const;
 
   // double width;           // W  (Default 1)   (inherited from AnnotBorder)
   // AnnotBorderStyle style; // S  (Default S)   (inherited from AnnotBorder)
@@ -580,7 +584,7 @@ public:
   void setModified(GooString *new_date);
   void setFlags(Guint new_flags);
 
-  void setBorder(AnnotBorderArray *new_border); // Takes ownership
+  void setBorder(AnnotBorder *new_border); // Takes ownership
 
   // The annotation takes the ownership of
   // new_color. 
-- 
1.8.4.3

-- 
Carlos Garcia Campos
PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x523E6462
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to