<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -37,6 +37,7 @@
 
 #include &lt;stdlib.h&gt;
 #include &lt;math.h&gt;
+#include &lt;assert.h&gt;
 #include &quot;goo/gmem.h&quot;
 #include &quot;GooList.h&quot;
 #include &quot;Error.h&quot;
@@ -612,6 +613,32 @@ AnnotColor::AnnotColor() {
   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;
+  values[2] = 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;
+  values[2] = y;
+  values[3] = k;
+}
+
 AnnotColor::AnnotColor(Array *array) {
   // TODO: check what Acrobat does in the case of having more than 5 numbers.
   if (array-&gt;getLength() &lt; 5) {
@@ -814,10 +841,35 @@ AnnotAppearanceCharacs::~AnnotAppearanceCharacs() {
 // Annot
 //------------------------------------------------------------------------
 
+Annot::Annot(XRef *xrefA, PDFRectangle *rectA, Catalog *catalog) {
+  Object obj1;
+
+  flags = flagUnknown;
+  type = typeUnknown;
+
+  obj1.initArray (xrefA);
+  Object obj2;
+  obj1.arrayAdd (obj2.initReal (rectA-&gt;x1));
+  obj1.arrayAdd (obj2.initReal (rectA-&gt;y1));
+  obj1.arrayAdd (obj2.initReal (rectA-&gt;x2));
+  obj1.arrayAdd (obj2.initReal (rectA-&gt;y2));
+  obj2.free ();
+
+  annotObj.initDict (xrefA);
+  annotObj.dictSet (&quot;Type&quot;, obj2.initName (&quot;Annot&quot;));
+  annotObj.dictSet (&quot;Rect&quot;, &amp;obj1);
+  // obj1 is owned by the dict
+
+  ref = xrefA-&gt;addIndirectObject (&amp;annotObj);
+
+  initialize (xrefA, annotObj.getDict(), catalog);
+}
+
 Annot::Annot(XRef *xrefA, Dict *dict, Catalog* catalog) {
   hasRef = false;
   flags = flagUnknown;
   type = typeUnknown;
+  annotObj.initDict (dict);
   initialize (xrefA, dict, catalog);
 }
 
@@ -830,6 +882,7 @@ Annot::Annot(XRef *xrefA, Dict *dict, Catalog* catalog, Object *obj) {
   }
   flags = flagUnknown;
   type = typeUnknown;
+  annotObj.initDict (dict);
   initialize (xrefA, dict, catalog);
 }
 
@@ -842,7 +895,6 @@ void Annot::initialize(XRef *xrefA, Dict *dict, Catalog *catalog) {
   xref = xrefA;
   appearBuf = NULL;
   fontSize = 0;
-  annotObj.initDict (dict);
 
   //----- parse the rectangle
   rect = new PDFRectangle();
@@ -1018,7 +1070,24 @@ void Annot::setContents(GooString *new_content) {
   obj1.initString(contents-&gt;copy());
   update (&quot;Contents&quot;, &amp;obj1);
 }
-	
+
+void Annot::setColor(AnnotColor *new_color) {
+  delete color;
+
+  if (new_color) {
+    Object obj1, obj2;
+    double *values = new_color-&gt;getValues();
+
+    obj1.initArray(xref);
+    for (int i = 0; i &lt; (int)new_color-&gt;getSpace(); i++)
+      obj1.arrayAdd(obj2.initReal (values[i]));
+    update (&quot;C&quot;, &amp;obj1);
+    color = new_color;
+  } else {
+    color = NULL;
+  }
+}
+
 double Annot::getXMin() {
   return rect-&gt;x1;
 }
@@ -1220,6 +1289,16 @@ void Annot::draw(Gfx *gfx, GBool printing) {
 // AnnotPopup
 //------------------------------------------------------------------------
 
+AnnotPopup::AnnotPopup(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    Annot(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typePopup;
+
+  annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Popup&quot;));
+  initialize (xrefA, annotObj.getDict(), catalog);
+}
+
 AnnotPopup::AnnotPopup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
     Annot(xrefA, dict, catalog, obj) {
   type = typePopup;
@@ -1227,22 +1306,16 @@ AnnotPopup::AnnotPopup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
 }
 
 AnnotPopup::~AnnotPopup() {
-  /*
-  if (parent)
-    delete parent;
-  */
+  parent.free();
 }
 
 void AnnotPopup::initialize(XRef *xrefA, Dict *dict, Catalog *catalog) {
   Object obj1;
-  /*
-  if (dict-&gt;lookup(&quot;Parent&quot;, &amp;obj1)-&gt;isDict()) {
-    parent = NULL;
-  } else {
-    parent = NULL;
+
+  if (!dict-&gt;lookupNF(&quot;Parent&quot;, &amp;parent)-&gt;isRef()) {
+    parent.initNull();
   }
-  obj1.free();
-  */
+
   if (dict-&gt;lookup(&quot;Open&quot;, &amp;obj1)-&gt;isBool()) {
     open = obj1.getBool();
   } else {
@@ -1251,10 +1324,33 @@ void AnnotPopup::initialize(XRef *xrefA, Dict *dict, Catalog *catalog) {
   obj1.free();
 }
 
+void AnnotPopup::setParent(Object *parentA) {
+  parentA-&gt;copy(&amp;parent);
+  update (&quot;Parent&quot;, &amp;parent);
+}
+
+void AnnotPopup::setParent(Annot *parentA) {
+  Ref parentRef = parentA-&gt;getRef();
+  parent.initRef(parentRef.num, parentRef.gen);
+  update (&quot;Parent&quot;, &amp;parent);
+}
+
+void AnnotPopup::setOpen(GBool openA) {
+  Object obj1;
+
+  open = openA;
+  obj1.initBool(open);
+  update (&quot;Open&quot;, &amp;obj1);
+}
+
 //------------------------------------------------------------------------
 // AnnotMarkup
 //------------------------------------------------------------------------
- 
+AnnotMarkup::AnnotMarkup(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    Annot(xrefA, rect, catalog) {
+  initialize(xrefA, annotObj.getDict(), catalog, &amp;annotObj);
+}
+
 AnnotMarkup::AnnotMarkup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
     Annot(xrefA, dict, catalog, obj) {
   initialize(xrefA, dict, catalog, obj);
@@ -1344,10 +1440,57 @@ void AnnotMarkup::initialize(XRef *xrefA, Dict *dict, Catalog *catalog, Object *
   obj1.free();
 }
 
+void AnnotMarkup::setLabel(GooString *new_label) {
+  delete label;
+
+  if (new_label) {
+    label = new GooString(new_label);
+    //append the unicode marker &lt;FE FF&gt; if needed
+    if (!label-&gt;hasUnicodeMarker()) {
+      label-&gt;insert(0, 0xff);
+      label-&gt;insert(0, 0xfe);
+    }
+  } else {
+    label = new GooString();
+  }
+
+  Object obj1;
+  obj1.initString(label-&gt;copy());
+  update (&quot;T&quot;, &amp;obj1);
+}
+
+void AnnotMarkup::setPopup(AnnotPopup *new_popup) {
+  delete popup;
+
+  if (new_popup) {
+    Object obj1;
+    Ref popupRef = new_popup-&gt;getRef();
+
+    obj1.initRef (popupRef.num, popupRef.gen);
+    update (&quot;Popup&quot;, &amp;obj1);
+
+    new_popup-&gt;setParent(this);
+    popup = new_popup;
+  } else {
+    popup = NULL;
+  }
+}
+
 //------------------------------------------------------------------------
 // AnnotText
 //------------------------------------------------------------------------
 
+AnnotText::AnnotText(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeText;
+  flags |= flagNoZoom | flagNoRotate;
+
+  annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Text&quot;));
+  initialize (xrefA, catalog, annotObj.getDict());
+}
+
 AnnotText::AnnotText(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
     AnnotMarkup(xrefA, dict, catalog, obj) {
 
@@ -1441,9 +1584,42 @@ void AnnotText::initialize(XRef *xrefA, Catalog *catalog, Dict *dict) {
   obj1.free();
 }
 
+void AnnotText::setOpen(GBool openA) {
+  Object obj1;
+
+  open = openA;
+  obj1.initBool(open);
+  update (&quot;Open&quot;, &amp;obj1);
+}
+
+void AnnotText::setIcon(GooString *new_icon) {
+  if (new_icon &amp;&amp; icon-&gt;cmp(new_icon) == 0)
+    return;
+
+  delete icon;
+
+  if (new_icon) {
+    icon = new GooString (new_icon);
+  } else {
+    icon = new GooString(&quot;Note&quot;);
+  }
+
+  Object obj1;
+  obj1.initName (icon-&gt;getCString());
+  update(&quot;Name&quot;, &amp;obj1);
+}
+
 //------------------------------------------------------------------------
 // AnnotLink
 //------------------------------------------------------------------------
+AnnotLink::AnnotLink(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    Annot(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeLink;
+  annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Link&quot;));
+  initialize (xrefA, catalog, annotObj.getDict());
+}
 
 AnnotLink::AnnotLink(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
     Annot(xrefA, dict, catalog, obj) {
@@ -1532,6 +1708,20 @@ void AnnotLink::draw(Gfx *gfx, GBool printing) {
 //------------------------------------------------------------------------
 // AnnotFreeText
 //------------------------------------------------------------------------
+AnnotFreeText::AnnotFreeText(XRef *xrefA, PDFRectangle *rect, GooString *da, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeFreeText;
+
+  annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;FreeText&quot;));
+
+  Object obj2;
+  obj2.initString (da-&gt;copy());
+  annotObj.dictSet(&quot;DA&quot;, &amp;obj2);
+
+  initialize (xrefA, catalog, annotObj.getDict());
+}
 
 AnnotFreeText::AnnotFreeText(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
     AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -1655,6 +1845,24 @@ void AnnotFreeText::initialize(XRef *xrefA, Catalog *catalog, Dict *dict) {
 // AnnotLine
 //------------------------------------------------------------------------
 
+AnnotLine::AnnotLine(XRef *xrefA, PDFRectangle *rect, PDFRectangle *lRect, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeLine;
+  annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Line&quot;));
+
+  Object obj2, obj3;
+  obj2.initArray (xrefA);
+  obj2.arrayAdd (obj3.initReal (lRect-&gt;x1));
+  obj2.arrayAdd (obj3.initReal (lRect-&gt;y1));
+  obj2.arrayAdd (obj3.initReal (lRect-&gt;x2));
+  obj2.arrayAdd (obj3.initReal (lRect-&gt;y2));
+  annotObj.dictSet (&quot;L&quot;, &amp;obj2);
+
+  initialize (xrefA, catalog, annotObj.getDict());
+}
+
 AnnotLine::AnnotLine(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
     AnnotMarkup(xrefA, dict, catalog, obj) {
   type = typeLine;
@@ -1814,6 +2022,48 @@ void AnnotLine::initialize(XRef *xrefA, Catalog *catalog, Dict *dict) {
 //------------------------------------------------------------------------
 // AnnotTextMarkup
 //------------------------------------------------------------------------
+AnnotTextMarkup::AnnotTextMarkup(XRef *xrefA, PDFRectangle *rect, AnnotSubtype subType,
+				 AnnotQuadrilaterals *quadPoints, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  switch (subType) {
+    case typeHighlight:
+      annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Highlight&quot;));
+      break;
+    case typeUnderline:
+      annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Underline&quot;));
+      break;
+    case typeSquiggly:
+      annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Squiggly&quot;));
+      break;
+    case typeStrikeOut:
+      annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;StrikeOut&quot;));
+      break;
+    default:
+      assert (0 &amp;&amp; &quot;Invalid subtype for AnnotTextMarkup\n&quot;);
+  }
+
+  Object obj2;
+  obj2.initArray (xrefA);
+
+  for (int i = 0; i &lt; quadPoints-&gt;getQuadrilateralsLength(); ++i) {
+    Object obj3;
+
+    obj2.arrayAdd (obj3.initReal (quadPoints-&gt;getX1(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints-&gt;getY1(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints-&gt;getX2(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints-&gt;getY2(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints-&gt;getX3(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints-&gt;getY3(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints-&gt;getX4(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints-&gt;getY4(i)));
+  }
+
+  annotObj.dictSet (&quot;QuadPoints&quot;, &amp;obj2);
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotTextMarkup::AnnotTextMarkup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3208,7 +3458,19 @@ void AnnotWidget::draw(Gfx *gfx, GBool printing) {
 //------------------------------------------------------------------------
 // AnnotMovie
 //------------------------------------------------------------------------
- 
+AnnotMovie::AnnotMovie(XRef *xrefA, PDFRectangle *rect, Movie *movieA, Catalog *catalog) :
+    Annot(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeMovie;
+  annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Movie&quot;));
+
+  movie = movieA-&gt;copy();
+  // TODO: create movie dict from movieA
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
+
 AnnotMovie::AnnotMovie(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   Annot(xrefA, dict, catalog, obj) {
   type = typeMovie;
@@ -3473,7 +3735,16 @@ void AnnotMovie::getZoomFactor(int&amp; num, int&amp; denum) {
 //------------------------------------------------------------------------
 // AnnotScreen
 //------------------------------------------------------------------------
- 
+AnnotScreen::AnnotScreen(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    Annot(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeScreen;
+
+  annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Screen&quot;));
+  initialize(xrefA, catalog, annotObj.getDict());
+}
+
 AnnotScreen::AnnotScreen(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   Annot(xrefA, dict, catalog, obj) {
   type = typeScreen;
@@ -3514,7 +3785,15 @@ void AnnotScreen::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // AnnotStamp
 //------------------------------------------------------------------------
- 
+AnnotStamp::AnnotStamp(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+  AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeStamp;
+  annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Stamp&quot;));
+  initialize(xrefA, catalog, annotObj.getDict());
+}
+
 AnnotStamp::AnnotStamp(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
   type = typeStamp;
@@ -3540,6 +3819,23 @@ void AnnotStamp::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // AnnotGeometry
 //------------------------------------------------------------------------
+AnnotGeometry::AnnotGeometry(XRef *xrefA, PDFRectangle *rect, AnnotSubtype subType, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  switch (subType) {
+    case typeSquare:
+      annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Square&quot;));
+      break;
+    case typeCircle:
+      annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Circle&quot;));
+      break;
+    default:
+      assert (0 &amp;&amp; &quot;Invalid subtype for AnnotGeometry\n&quot;);
+  }
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotGeometry::AnnotGeometry(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3592,6 +3888,36 @@ void AnnotGeometry::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // AnnotPolygon
 //------------------------------------------------------------------------
+AnnotPolygon::AnnotPolygon(XRef *xrefA, PDFRectangle *rect, AnnotSubtype subType,
+			   AnnotPath *path, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  switch (subType) {
+    case typePolygon:
+      annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Polygon&quot;));
+      break;
+    case typePolyLine:
+      annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;PolyLine&quot;));
+      break;
+    default:
+      assert (0 &amp;&amp; &quot;Invalid subtype for AnnotGeometry\n&quot;);
+  }
+
+  Object obj2;
+  obj2.initArray (xrefA);
+
+  for (int i = 0; i &lt; path-&gt;getCoordsLength(); ++i) {
+    Object obj3;
+
+    obj2.arrayAdd (obj3.initReal (path-&gt;getX(i)));
+    obj2.arrayAdd (obj3.initReal (path-&gt;getY(i)));
+  }
+
+  annotObj.dictSet (&quot;Vertices&quot;, &amp;obj2);
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotPolygon::AnnotPolygon(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3686,6 +4012,15 @@ void AnnotPolygon::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // AnnotCaret
 //------------------------------------------------------------------------
+AnnotCaret::AnnotCaret(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeCaret;
+
+  annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Caret&quot;));
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotCaret::AnnotCaret(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3723,6 +4058,36 @@ void AnnotCaret::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // AnnotInk
 //------------------------------------------------------------------------
+AnnotInk::AnnotInk(XRef *xrefA, PDFRectangle *rect, AnnotPath **paths, int n_paths, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeInk;
+
+  annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Ink&quot;));
+
+  Object obj2;
+  obj2.initArray (xrefA);
+
+  for (int i = 0; i &lt; n_paths; ++i) {
+    AnnotPath *path = paths[i];
+    Object obj3;
+    obj3.initArray (xrefA);
+
+    for (int j = 0; j &lt; path-&gt;getCoordsLength(); ++j) {
+      Object obj4;
+
+      obj3.arrayAdd (obj4.initReal (path-&gt;getX(j)));
+      obj3.arrayAdd (obj4.initReal (path-&gt;getY(j)));
+    }
+
+    obj2.arrayAdd (&amp;obj3);
+  }
+
+  annotObj.dictSet (&quot;InkList&quot;, &amp;obj2);
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotInk::AnnotInk(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3764,6 +4129,20 @@ void AnnotInk::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // AnnotFileAttachment
 //------------------------------------------------------------------------
+AnnotFileAttachment::AnnotFileAttachment(XRef *xrefA, PDFRectangle *rect, GooString *filename, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeFileAttachment;
+
+  annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;FileAttachment&quot;));
+
+  Object obj2;
+  obj2.initString(filename-&gt;copy());
+  annotObj.dictSet (&quot;FS&quot;, &amp;obj2);
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotFileAttachment::AnnotFileAttachment(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3781,7 +4160,7 @@ AnnotFileAttachment::~AnnotFileAttachment() {
 void AnnotFileAttachment::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
   Object obj1;
 
-  if (dict-&gt;lookup(&quot;FS&quot;, &amp;obj1)-&gt;isDict()) {
+  if (dict-&gt;lookup(&quot;FS&quot;, &amp;obj1)-&gt;isDict() || dict-&gt;lookup(&quot;FS&quot;, &amp;obj1)-&gt;isString()) {
     obj1.copy(&amp;file);
   } else {
     error(-1, &quot;Bad Annot File Attachment&quot;);
@@ -3800,6 +4179,22 @@ void AnnotFileAttachment::initialize(XRef *xrefA, Catalog *catalog, Dict* dict)
 //------------------------------------------------------------------------
 // AnnotSound
 //------------------------------------------------------------------------
+AnnotSound::AnnotSound(XRef *xrefA, PDFRectangle *rect, Sound *soundA, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeSound;
+
+  annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;Sound&quot;));
+
+  Object obj2;
+  Stream *str = soundA-&gt;getStream();
+  obj2.initStream (str);
+  str-&gt;incRef(); //FIXME: initStream should do this?
+  annotObj.dictSet (&quot;Sound&quot;, &amp;obj2);
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotSound::AnnotSound(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3834,6 +4229,16 @@ void AnnotSound::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // Annot3D
 //------------------------------------------------------------------------
+Annot3D::Annot3D(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    Annot(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = type3D;
+
+  annotObj.dictSet (&quot;Subtype&quot;, obj1.initName (&quot;3D&quot;));
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 Annot3D::Annot3D(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   Annot(xrefA, dict, catalog, obj) {</diff>
      <filename>poppler/Annot.cc</filename>
    </modified>
    <modified>
      <diff>@@ -287,6 +287,9 @@ public:
   };
 
   AnnotColor();
+  AnnotColor(double gray);
+  AnnotColor(double r, double g, double b);
+  AnnotColor(double c, double m, double y, double k);
   AnnotColor(Array *array);
   ~AnnotColor();
 
@@ -480,7 +483,8 @@ public:
     type3D              // 3D             25
   };
 
-  Annot(XRef *xrefA, Dict *dict, Catalog* catalog);
+  Annot(XRef *xrefA, PDFRectangle *rectA, Catalog *catalog);
+  Annot(XRef *xrefA, Dict *dict, Catalog *catalog);
   Annot(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   virtual ~Annot();
   GBool isOk() { return ok; }
@@ -500,8 +504,13 @@ public:
   // Sets the annot contents to new_content
   // new_content should never be NULL
   void setContents(GooString *new_content);
-  
+
+  // The annotation takes the ownership of
+  // new_color. 
+  void setColor(AnnotColor *new_color);
+
   // getters
+  Ref getRef() const { return ref; }
   AnnotSubtype getType() const { return type; }
   PDFRectangle *getRect() const { return rect; }
   GooString *getContents() const { return contents; }
@@ -572,16 +581,21 @@ protected:
 
 class AnnotPopup: public Annot {
 public:
+  AnnotPopup(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotPopup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotPopup();
 
-  Dict *getParent() const { return parent; }
+  Object *getParent(Object *obj) { return parent.fetch (xref, obj); }
+  Object *getParentNF(Object *obj) { return &amp;parent; }
+  void setParent(Object *parentA);
+  void setParent(Annot *parentA);
   GBool getOpen() const { return open; }
+  void setOpen(GBool openA);
 
 protected:
   void initialize(XRef *xrefA, Dict *dict, Catalog *catalog);
 
-  Dict *parent; // Parent
+  Object parent; // Parent
   GBool open;   // Open
 };
 
@@ -596,6 +610,7 @@ public:
     replyTypeGroup  // Group
   };
 
+  AnnotMarkup(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotMarkup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   virtual ~AnnotMarkup();
 
@@ -610,6 +625,10 @@ public:
   AnnotMarkupReplyType getReplyTo() const { return replyTo; }
   AnnotExternalDataType getExData() const { return exData; }
 
+  // The annotation takes the ownership of new_popup
+  void setPopup(AnnotPopup *new_popup);
+  void setLabel(GooString *new_label);
+
 protected:
   GooString *label;             // T            (Default autor)
   AnnotPopup *popup;            // Popup
@@ -647,6 +666,7 @@ public:
     stateNone       // None
   };
 
+  AnnotText(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotText(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotText();
 
@@ -655,6 +675,9 @@ public:
   GooString *getIcon() const { return icon; }
   AnnotTextState getState() const { return state; }
 
+  void setOpen(GBool openA);
+  void setIcon(GooString *new_icon);
+
 private:
 
   void initialize(XRef *xrefA, Catalog *catalog, Dict *dict);
@@ -693,6 +716,7 @@ class AnnotMovie: public Annot {
     int units_per_second; // 0 : defined by movie
   };
 
+  AnnotMovie(XRef *xrefA, PDFRectangle *rect, Movie *movieA, Catalog *catalog);
   AnnotMovie(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotMovie();
 
@@ -766,6 +790,7 @@ class AnnotMovie: public Annot {
 class AnnotScreen: public Annot {
  public:
 
+  AnnotScreen(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotScreen(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotScreen();
 
@@ -801,6 +826,7 @@ public:
     effectPush      // P
   };
 
+  AnnotLink(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotLink(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   virtual ~AnnotLink();
 
@@ -844,6 +870,7 @@ public:
     intentFreeTextTypeWriter  // FreeTextTypeWriter
   };
 
+  AnnotFreeText(XRef *xrefA, PDFRectangle *rect, GooString *da, Catalog *catalog);
   AnnotFreeText(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotFreeText();
 
@@ -895,6 +922,7 @@ public:
     captionPosTop     // Top
   };
 
+  AnnotLine(XRef *xrefA, PDFRectangle *rect, PDFRectangle *lRect, Catalog *catalog);
   AnnotLine(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotLine();
 
@@ -947,6 +975,8 @@ protected:
 class AnnotTextMarkup: public AnnotMarkup {
 public:
 
+  AnnotTextMarkup(XRef *xrefA, PDFRectangle *rect, AnnotSubtype subType,
+		  AnnotQuadrilaterals *quadPoints, Catalog *catalog);
   AnnotTextMarkup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   virtual ~AnnotTextMarkup();
 
@@ -966,6 +996,7 @@ protected:
 class AnnotStamp: public AnnotMarkup {
 public:
 
+  AnnotStamp(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotStamp(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotStamp();
 
@@ -986,6 +1017,7 @@ private:
 class AnnotGeometry: public AnnotMarkup {
 public:
 
+  AnnotGeometry(XRef *xrefA, PDFRectangle *rect, AnnotSubtype subType, Catalog *catalog);
   AnnotGeometry(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotGeometry();
 
@@ -1016,6 +1048,8 @@ public:
     polygonDimension   // PolygonDimension
   };
 
+  AnnotPolygon(XRef *xrefA, PDFRectangle *rect, AnnotSubtype subType,
+	       AnnotPath *path, Catalog *catalog);
   AnnotPolygon(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotPolygon();
 
@@ -1057,6 +1091,7 @@ public:
     symbolP         // P
   };
 
+  AnnotCaret(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotCaret(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotCaret();
 
@@ -1079,6 +1114,7 @@ private:
 class AnnotInk: public AnnotMarkup {
 public:
 
+  AnnotInk(XRef *xrefA, PDFRectangle *rect, AnnotPath **paths, int n_paths, Catalog *catalog);
   AnnotInk(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotInk();
 
@@ -1106,6 +1142,7 @@ private:
 class AnnotFileAttachment: public AnnotMarkup {
 public:
 
+  AnnotFileAttachment(XRef *xrefA, PDFRectangle *rect, GooString *filename, Catalog *catalog);
   AnnotFileAttachment(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotFileAttachment();
 
@@ -1131,6 +1168,7 @@ private:
 class AnnotSound: public AnnotMarkup {
 public:
 
+  AnnotSound(XRef *xrefA, PDFRectangle *rect, Sound *soundA, Catalog *catalog);
   AnnotSound(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotSound();
 
@@ -1251,6 +1289,7 @@ class Annot3D: public Annot {
   };
 public:
 
+  Annot3D(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   Annot3D(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~Annot3D();
 </diff>
      <filename>poppler/Annot.h</filename>
    </modified>
    <modified>
      <diff>@@ -309,7 +309,7 @@ int Catalog::readPageTree(Dict *pagesDict, PageAttrs *attrs, int start,
     kids.arrayGet(i, &amp;kid);
     if (kid.isDict(&quot;Page&quot;)) {
       attrs2 = new PageAttrs(attrs1, kid.getDict());
-      page = new Page(xref, start+1, kid.getDict(), attrs2, form);
+      page = new Page(xref, start+1, kid.getDict(), kidRef.getRef(), attrs2, form);
       if (!page-&gt;isOk()) {
 	++start;
 	goto err3;</diff>
      <filename>poppler/Catalog.cc</filename>
    </modified>
    <modified>
      <diff>@@ -1024,6 +1024,16 @@ class PostScriptFunctionKey : public PopplerCacheKey
   public:
     PostScriptFunctionKey(int sizeA, double *inA, bool copyA)
     {
+      init(sizeA, inA, copyA);
+    }
+    
+    PostScriptFunctionKey(const PostScriptFunctionKey &amp;key)
+    {
+      init(key.size, key.in, key.copied);
+    }
+    
+    void init(int sizeA, double *inA, bool copyA)
+    {
       copied = copyA;
       size = sizeA;
       if (copied) {
@@ -1063,6 +1073,16 @@ class PostScriptFunctionItem : public PopplerCacheItem
   public:
     PostScriptFunctionItem(int sizeA, double *outA)
     {
+      init(sizeA, outA);
+    }
+    
+    PostScriptFunctionItem(const PostScriptFunctionItem &amp;item)
+    {
+      init(item.size, item.out);
+    }
+    
+    void init(int sizeA, double *outA)
+    {
       size = sizeA;
       out = new double[size];
       for (int i = 0; i &lt; size; ++i) out[i] = outA[i];
@@ -1138,6 +1158,14 @@ PostScriptFunction::PostScriptFunction(PostScriptFunction *func) {
   codeString = func-&gt;codeString-&gt;copy();
   stack = new PSStack();
   memcpy(stack, func-&gt;stack, sizeof(PSStack));
+  
+  cache = new PopplerCache(func-&gt;cache-&gt;size());
+  for (int i = 0; i &lt; func-&gt;cache-&gt;numberOfItems(); ++i)
+  {
+    PostScriptFunctionKey *key = new PostScriptFunctionKey(*(PostScriptFunctionKey*)func-&gt;cache-&gt;key(i));
+    PostScriptFunctionItem *item = new PostScriptFunctionItem(*(PostScriptFunctionItem*)func-&gt;cache-&gt;item(i));
+    cache-&gt;put(key, item);
+  }
 }
 
 PostScriptFunction::~PostScriptFunction() {</diff>
      <filename>poppler/Function.cc</filename>
    </modified>
    <modified>
      <diff>@@ -1824,6 +1824,7 @@ void Gfx::doTilingPatternFill(GfxTilingPattern *tPat,
 			      GBool stroke, GBool eoFill) {
   GfxPatternColorSpace *patCS;
   GfxColorSpace *cs;
+  GfxColor color;
   GfxPath *savedPath;
   double xMin, yMin, xMax, yMax, x, y, x1, y1;
   double cxMin, cyMin, cxMax, cyMax;
@@ -1886,21 +1887,25 @@ void Gfx::doTilingPatternFill(GfxTilingPattern *tPat,
     out-&gt;updateFillColorSpace(state);
     state-&gt;setStrokeColorSpace(cs-&gt;copy());
     out-&gt;updateStrokeColorSpace(state);
-    state-&gt;setStrokeColor(state-&gt;getFillColor());
+    if (stroke) {
+	state-&gt;setFillColor(state-&gt;getStrokeColor());
+    } else {
+	state-&gt;setStrokeColor(state-&gt;getFillColor());
+    }
   } else {
-    state-&gt;setFillColorSpace(new GfxDeviceGrayColorSpace());
+    cs = new GfxDeviceGrayColorSpace();
+    state-&gt;setFillColorSpace(cs);
+    cs-&gt;getDefaultColor(&amp;color);
+    state-&gt;setFillColor(&amp;color);
     out-&gt;updateFillColorSpace(state);
     state-&gt;setStrokeColorSpace(new GfxDeviceGrayColorSpace());
+    state-&gt;setStrokeColor(&amp;color);
     out-&gt;updateStrokeColorSpace(state);
   }
   state-&gt;setFillPattern(NULL);
   out-&gt;updateFillColor(state);
   state-&gt;setStrokePattern(NULL);
   out-&gt;updateStrokeColor(state);
-  if (!stroke) {
-    state-&gt;setLineWidth(0);
-    out-&gt;updateLineWidth(state);
-  }
 
   // clip to current path
   if (stroke) {
@@ -1915,6 +1920,8 @@ void Gfx::doTilingPatternFill(GfxTilingPattern *tPat,
     }
   }
   state-&gt;clearPath();
+  state-&gt;setLineWidth(0);
+  out-&gt;updateLineWidth(state);
 
   // get the clip region, check for empty
   state-&gt;getClipBBox(&amp;cxMin, &amp;cyMin, &amp;cxMax, &amp;cyMax);</diff>
      <filename>poppler/Gfx.cc</filename>
    </modified>
    <modified>
      <diff>@@ -252,7 +252,7 @@ GBool PageAttrs::readBox(Dict *dict, char *key, PDFRectangle *box) {
 // Page
 //------------------------------------------------------------------------
 
-Page::Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA, Form *form) {
+Page::Page(XRef *xrefA, int numA, Dict *pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form) {
   Object tmp;
 	
   ok = gTrue;
@@ -261,6 +261,9 @@ Page::Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA, Form *form)
   duration = -1;
   pageWidgets = NULL;
 
+  pageObj.initDict(pageDict);
+  pageRef = pageRefA;
+
   // get attributes
   attrs = attrsA;
 
@@ -334,6 +337,7 @@ Page::Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA, Form *form)
 Page::~Page() {
   delete pageWidgets;
   delete attrs;
+  pageObj.free();
   annots.free();
   contents.free();
   trans.free();
@@ -350,6 +354,34 @@ Annots *Page::getAnnots(Catalog *catalog) {
   return annots;
 }
 
+void Page::addAnnot(Annot *annot) {
+  Object obj1;
+  Object tmp;
+  Ref annotRef = annot-&gt;getRef ();
+
+  if (annots.isNull()) {
+    Ref annotsRef;
+    // page doesn't have annots array,
+    // we have to create it
+
+    obj1.initArray(xref);
+    obj1.arrayAdd(tmp.initRef (annotRef.num, annotRef.gen));
+    tmp.free();
+
+    annotsRef = xref-&gt;addIndirectObject (&amp;obj1);
+    annots.initRef(annotsRef.num, annotsRef.gen);
+    pageObj.dictSet (&quot;Annots&quot;, &amp;annots);
+    xref-&gt;setModifiedObject (&amp;pageObj, pageRef);
+  } else {
+    getAnnots(&amp;obj1);
+    if (obj1.isArray()) {
+      obj1.arrayAdd (tmp.initRef (annotRef.num, annotRef.gen));
+      xref-&gt;setModifiedObject (&amp;obj1, annots.getRef());
+    }
+    obj1.free();
+  }
+}
+
 Links *Page::getLinks(Catalog *catalog) {
   Links *links;
   Object obj;</diff>
      <filename>poppler/Page.cc</filename>
    </modified>
    <modified>
      <diff>@@ -126,7 +126,7 @@ class Page {
 public:
 
   // Constructor.
-  Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA, Form *form);
+  Page(XRef *xrefA, int numA, Dict *pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form);
 
   // Destructor.
   ~Page();
@@ -163,6 +163,8 @@ public:
 
   // Get annotations array.
   Object *getAnnots(Object *obj) { return annots.fetch(xref, obj); }
+  // Add a new annotation to the page
+  void addAnnot(Annot *annot);
 
   // Return a list of links.
   Links *getLinks(Catalog *catalog);
@@ -235,6 +237,8 @@ public:
 private:
 
   XRef *xref;			// the xref table for this PDF file
+  Object pageObj;               // page dictionary
+  Ref pageRef;                  // page reference
   int num;			// page number
   PageAttrs *attrs;		// page attributes
   Object annots;		// annotations array</diff>
      <filename>poppler/Page.h</filename>
    </modified>
    <modified>
      <diff>@@ -80,3 +80,23 @@ void PopplerCache::put(PopplerCacheKey *key, PopplerCacheItem *item)
   keys[0] = key;
   items[0] = item;
 }
+
+int PopplerCache::size()
+{
+  return cacheSize;
+}
+
+int PopplerCache::numberOfItems()
+{
+  return lastValidCacheIndex + 1;
+}
+    
+PopplerCacheItem *PopplerCache::item(int index)
+{
+  return items[index];
+}
+    
+PopplerCacheKey *PopplerCache::key(int index)
+{
+  return keys[index];
+}</diff>
      <filename>poppler/PopplerCache.cc</filename>
    </modified>
    <modified>
      <diff>@@ -36,8 +36,22 @@ class PopplerCache
     
     /* The key and item pointers ownership is taken by the cache */
     void put(PopplerCacheKey *key, PopplerCacheItem *item);
+    
+    /* The max size of the cache */
+    int size();
+    
+    /* The number of items in the cache */
+    int numberOfItems();
+    
+    /* The n-th item in the cache */
+    PopplerCacheItem *item(int index);
+    
+    /* The n-th key in the cache */
+    PopplerCacheKey *key(int index);
   
   private:
+    PopplerCache(const PopplerCache &amp;cache); // not allowed
+  
     PopplerCacheKey **keys;
     PopplerCacheItem **items;
     int lastValidCacheIndex;</diff>
      <filename>poppler/PopplerCache.h</filename>
    </modified>
    <modified>
      <diff>@@ -214,6 +214,8 @@ PdfInspector::analyze_page (int page)
   void *p;
   GtkWidget *label;
   char *text;
+  cairo_t *cr;
+  cairo_surface_t *surface;
 
   label = glade_xml_get_widget (xml, &quot;pdf_total_label&quot;);
 
@@ -221,7 +223,15 @@ PdfInspector::analyze_page (int page)
   gtk_list_store_clear (GTK_LIST_STORE (model));
 
   GooTimer timer;
+  surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
+					doc-&gt;getPageCropWidth(page + 1),
+					doc-&gt;getPageCropHeight(page + 1));
+  cr = cairo_create (surface);
+  cairo_surface_destroy (surface);
+  output-&gt;setCairo (cr);
+  cairo_destroy (cr);
   doc-&gt;displayPage (output, page + 1, 72, 72, 0, gFalse, gTrue, gTrue);
+  output-&gt;setCairo (NULL);
 
   // Total time;
   text = g_strdup_printf (&quot;%g&quot;, timer.getElapsed ());
@@ -331,6 +341,7 @@ main (int argc, char *argv [])
   
   globalParams = new GlobalParams();
   globalParams-&gt;setProfileCommands (true);
+  globalParams-&gt;setPrintCommands (true);
 
   if (argc == 2)
     file_name = argv[1];</diff>
      <filename>test/pdf-inspector.cc</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>946e714e2c7b21852753a8acd5a6b50406c5214c</id>
    </parent>
    <parent>
      <id>d30b1013ea3ce45b5ea942fe7357c0fd07ff47f4</id>
    </parent>
  </parents>
  <author>
    <name>Kouhei Sutou</name>
    <email>kou@cozmixng.org</email>
  </author>
  <url>http://github.com/kou/poppler-test/commit/4ced9418b86d64fdfca7c15e78d30813c115aa3e</url>
  <id>4ced9418b86d64fdfca7c15e78d30813c115aa3e</id>
  <committed-date>2009-06-16T08:40:49-07:00</committed-date>
  <authored-date>2009-06-16T08:40:49-07:00</authored-date>
  <message>Merge branch 'master' of ssh://git.freedesktop.org/git/poppler/poppler</message>
  <tree>7affef3363b51c7fa39a5e6db777f550bb8c2b14</tree>
  <committer>
    <name>Kouhei Sutou</name>
    <email>kou@cozmixng.org</email>
  </committer>
</commit>
