diff --git a/poppler/Annot.cc b/poppler/Annot.cc index b5a77d64..5f393efa 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -1297,10 +1297,12 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) { // 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. obj1 = dict->lookup("Border"); - if (obj1.isArray()) - border = new AnnotBorderArray(obj1.getArray()); - else - border = NULL; + if (obj1.isArray()) { + borderArray = new AnnotBorderArray(obj1.getArray()); + } else { + borderArray = NULL; + } + borderBS = NULL; obj1 = dict->lookup("C"); if (obj1.isArray()) { @@ -1430,14 +1432,20 @@ void Annot::setFlags(Guint new_flags) { void Annot::setBorder(AnnotBorder *new_border) { annotLocker(); - delete border; + delete borderArray; + borderArray = NULL; + delete borderBS; + borderBS = NULL; if (new_border) { Object obj1 = new_border->writeToObject(xref); - update(new_border->getType() == AnnotBorder::typeArray ? "Border" : "BS", std::move(obj1)); - border = new_border; - } else { - border = NULL; + if (new_border->getType() == AnnotBorder::typeArray) { + update("Border", std::move(obj1)); + borderArray = dynamic_cast(new_border); + } else { + update("BS", std::move(obj1)); + borderBS = dynamic_cast(new_border); + } } invalidateAppearance(); } @@ -1588,8 +1596,8 @@ Annot::~Annot() { if (appearState) delete appearState; - if (border) - delete border; + delete borderArray; + delete borderBS; if (color) delete color; @@ -1628,11 +1636,11 @@ void Annot::setLineStyleForBorder(AnnotBorder *border) { int i, dashLength; double *dash; - switch (border->getStyle()) { + switch (getBorder()->getStyle()) { case AnnotBorder::borderDashed: appearBuf->append("["); - dashLength = border->getDashLength(); - dash = border->getDash(); + dashLength = getBorder()->getDashLength(); + dash = getBorder()->getDash(); for (i = 0; i < dashLength; ++i) appearBuf->appendf(" {0:.2f}", dash[i]); appearBuf->append(" ] 0 d\n"); @@ -1641,7 +1649,7 @@ void Annot::setLineStyleForBorder(AnnotBorder *border) { appearBuf->append("[] 0 d\n"); break; } - appearBuf->appendf("{0:.2f} w\n", border->getWidth()); + appearBuf->appendf("{0:.2f} w\n", getBorder()->getWidth()); } // Draw an (approximate) circle of radius centered at (, ). @@ -2569,10 +2577,9 @@ void AnnotLink::initialize(PDFDoc *docA, Dict *dict) { obj1 = dict->lookup("BS"); if (obj1.isDict()) { - delete border; - border = new AnnotBorderBS(obj1.getDict()); - } else if (!border) { - border = new AnnotBorderBS(); + borderBS = new AnnotBorderBS(obj1.getDict()); + } else if (!borderArray) { + borderBS = new AnnotBorderBS(); } } @@ -2583,7 +2590,7 @@ void AnnotLink::draw(Gfx *gfx, GBool printing) { annotLocker(); // draw the appearance stream Object obj = appearance.fetch(gfx->getXRef()); - gfx->drawAnnot(&obj, border, color, + gfx->drawAnnot(&obj, getBorder(), color, rect->x1, rect->y1, rect->x2, rect->y2, getRotation()); } @@ -2691,10 +2698,9 @@ void AnnotFreeText::initialize(PDFDoc *docA, Dict *dict) { obj1 = dict->lookup("BS"); if (obj1.isDict()) { - delete border; - border = new AnnotBorderBS(obj1.getDict()); - } else if (!border) { - border = new AnnotBorderBS(); + borderBS = new AnnotBorderBS(obj1.getDict()); + } else if (!borderArray) { + borderBS = new AnnotBorderBS(); } obj1 = dict->lookup("BE"); @@ -2861,9 +2867,9 @@ void AnnotFreeText::generateFreeTextAppearance() appearBuf = new GooString (); appearBuf->append ("q\n"); - borderWidth = border->getWidth(); + borderWidth = getBorder()->getWidth(); if (borderWidth > 0) - setLineStyleForBorder(border); + setLineStyleForBorder(getBorder()); // Box size const double width = rect->x2 - rect->x1; @@ -3143,10 +3149,9 @@ void AnnotLine::initialize(PDFDoc *docA, Dict *dict) { obj1 = dict->lookup("BS"); if (obj1.isDict()) { - delete border; - border = new AnnotBorderBS(obj1.getDict()); - } else if (!border) { - border = new AnnotBorderBS(); + borderBS = new AnnotBorderBS(obj1.getDict()); + } else if (!borderArray) { + borderBS = new AnnotBorderBS(); } } @@ -3240,8 +3245,8 @@ void AnnotLine::generateLineAppearance() setColor(color, gFalse); } - setLineStyleForBorder(border); - borderWidth = border->getWidth(); + setLineStyleForBorder(getBorder()); + borderWidth = getBorder()->getWidth(); appearBBox->setBorderWidth(std::max(1., borderWidth)); const double x1 = coord1->getX(); @@ -3791,8 +3796,9 @@ void AnnotWidget::initialize(PDFDoc *docA, Dict *dict) { obj1 = dict->lookup("BS"); if (obj1.isDict()) { - delete border; - border = new AnnotBorderBS(obj1.getDict()); + borderBS = new AnnotBorderBS(obj1.getDict()); + } else { + borderBS = new AnnotBorderBS(); // TODO Test this case } updatedAppearanceStream.num = updatedAppearanceStream.gen = -1; @@ -4145,7 +4151,7 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resourc } // get the border width - borderWidth = border ? border->getWidth() : 0; + borderWidth = getBorder() ? getBorder()->getWidth() : 0; // for a password field, replace all characters with asterisks if (password) { @@ -4528,7 +4534,7 @@ void AnnotWidget::drawListBox(FormFieldChoice *fieldChoice, convertedText = new GooString; // get the border width - borderWidth = border ? border->getWidth() : 0; + borderWidth = getBorder() ? getBorder()->getWidth() : 0; // compute font autosize if (fontSize == 0) { @@ -4646,7 +4652,7 @@ void AnnotWidget::drawBorder() { int dashLength; double *dash; AnnotColor adjustedColor; - double w = border->getWidth(); + double w = getBorder()->getWidth(); AnnotColor *aColor = appearCharacs->getBorderColor(); if (!aColor) @@ -4662,11 +4668,11 @@ void AnnotWidget::drawBorder() { if (field->getType() == formButton && static_cast(field)->getButtonType() == formButtonRadio && !hasCaption) { double r = 0.5 * (dx < dy ? dx : dy); - switch (border->getStyle()) { + switch (getBorder()->getStyle()) { case AnnotBorder::borderDashed: appearBuf->append("["); - dashLength = border->getDashLength(); - dash = border->getDash(); + dashLength = getBorder()->getDashLength(); + dash = getBorder()->getDash(); for (int i = 0; i < dashLength; ++i) { appearBuf->appendf(" {0:.2f}", dash[i]); } @@ -4684,21 +4690,21 @@ void AnnotWidget::drawBorder() { setColor(aColor, gFalse); drawCircle(0.5 * dx, 0.5 * dy, r - 0.25 * w, gFalse); adjustedColor = AnnotColor(*aColor); - adjustedColor.adjustColor(border->getStyle() == AnnotBorder::borderBeveled ? 1 : -1); + adjustedColor.adjustColor(getBorder()->getStyle() == AnnotBorder::borderBeveled ? 1 : -1); setColor(&adjustedColor, gFalse); drawCircleTopLeft(0.5 * dx, 0.5 * dy, r - 0.75 * w); adjustedColor = AnnotColor(*aColor); - adjustedColor.adjustColor(border->getStyle() == AnnotBorder::borderBeveled ? -1 : 1); + adjustedColor.adjustColor(getBorder()->getStyle() == AnnotBorder::borderBeveled ? -1 : 1); setColor(&adjustedColor, gFalse); drawCircleBottomRight(0.5 * dx, 0.5 * dy, r - 0.75 * w); break; } } else { - switch (border->getStyle()) { + switch (getBorder()->getStyle()) { case AnnotBorder::borderDashed: appearBuf->append("["); - dashLength = border->getDashLength(); - dash = border->getDash(); + dashLength = getBorder()->getDashLength(); + dash = getBorder()->getDash(); for (int i = 0; i < dashLength; ++i) { appearBuf->appendf(" {0:.2f}", dash[i]); } @@ -4713,7 +4719,7 @@ void AnnotWidget::drawBorder() { case AnnotBorder::borderBeveled: case AnnotBorder::borderInset: adjustedColor = AnnotColor(*aColor); - adjustedColor.adjustColor(border->getStyle() == AnnotBorder::borderBeveled ? 1 : -1); + adjustedColor.adjustColor(getBorder()->getStyle() == AnnotBorder::borderBeveled ? 1 : -1); setColor(&adjustedColor, gTrue); appearBuf->append("0 0 m\n"); appearBuf->appendf("0 {0:.2f} l\n", dy); @@ -4723,7 +4729,7 @@ void AnnotWidget::drawBorder() { appearBuf->appendf("{0:.2f} {0:.2f} l\n", w); appearBuf->append("f\n"); adjustedColor = AnnotColor(*aColor); - adjustedColor.adjustColor(border->getStyle() == AnnotBorder::borderBeveled ? -1 : 1); + adjustedColor.adjustColor(getBorder()->getStyle() == AnnotBorder::borderBeveled ? -1 : 1); setColor(&adjustedColor, gTrue); appearBuf->append("0 0 m\n"); appearBuf->appendf("{0:.2f} 0 l\n", dx); @@ -4842,7 +4848,7 @@ void AnnotWidget::generateFieldAppearance() { } // draw the border - if (appearCharacs && border && border->getWidth() > 0) + if (appearCharacs && getBorder() && getBorder()->getWidth() > 0) drawBorder(); da = field->getDefaultAppearance(); @@ -5276,10 +5282,9 @@ void AnnotGeometry::initialize(PDFDoc *docA, Dict* dict) { obj1 = dict->lookup("BS"); if (obj1.isDict()) { - delete border; - border = new AnnotBorderBS(obj1.getDict()); - } else if (!border) { - border = new AnnotBorderBS(); + borderBS = new AnnotBorderBS(obj1.getDict()); + } else if (!borderArray) { + borderBS = new AnnotBorderBS(); } obj1 = dict->lookup("BE"); @@ -5343,8 +5348,8 @@ void AnnotGeometry::draw(Gfx *gfx, GBool printing) { if (color) setColor(color, gFalse); - double borderWidth = border->getWidth(); - setLineStyleForBorder(border); + double borderWidth = getBorder()->getWidth(); + setLineStyleForBorder(getBorder()); if (interiorColor) setColor(interiorColor, gTrue); @@ -5525,10 +5530,9 @@ void AnnotPolygon::initialize(PDFDoc *docA, Dict* dict) { obj1 = dict->lookup("BS"); if (obj1.isDict()) { - delete border; - border = new AnnotBorderBS(obj1.getDict()); - } else if (!border) { - border = new AnnotBorderBS(); + borderBS = new AnnotBorderBS(obj1.getDict()); + } else if (!borderArray) { + borderBS = new AnnotBorderBS(); } obj1 = dict->lookup("BE"); @@ -5644,8 +5648,8 @@ void AnnotPolygon::draw(Gfx *gfx, GBool printing) { setColor(color, gFalse); } - setLineStyleForBorder(border); - appearBBox->setBorderWidth(std::max(1., border->getWidth())); + setLineStyleForBorder(getBorder()); + appearBBox->setBorderWidth(std::max(1., getBorder()->getWidth())); if (interiorColor) { setColor(interiorColor, gTrue); @@ -5800,10 +5804,9 @@ void AnnotInk::initialize(PDFDoc *docA, Dict* dict) { obj1 = dict->lookup("BS"); if (obj1.isDict()) { - delete border; - border = new AnnotBorderBS(obj1.getDict()); - } else if (!border) { - border = new AnnotBorderBS(); + borderBS = new AnnotBorderBS(obj1.getDict()); + } else if (!borderArray) { + borderBS = new AnnotBorderBS(); } } @@ -5867,8 +5870,8 @@ void AnnotInk::draw(Gfx *gfx, GBool printing) { setColor(color, gFalse); } - setLineStyleForBorder(border); - appearBBox->setBorderWidth(std::max(1., border->getWidth())); + setLineStyleForBorder(getBorder()); + appearBBox->setBorderWidth(std::max(1., getBorder()->getWidth())); for (int i = 0; i < inkListLength; ++i) { const AnnotPath * path = inkList[i]; diff --git a/poppler/Annot.h b/poppler/Annot.h index 171494a9..df520235 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -609,7 +609,12 @@ public: Guint getFlags() const { return flags; } AnnotAppearance *getAppearStreams() const { return appearStreams; } GooString *getAppearState() const { return appearState; } - AnnotBorder *getBorder() const { return border; } + AnnotBorder *getBorder() const { + if (borderBS) return borderBS; + else return borderArray; + } + AnnotBorderArray *getBorderArray() const { return borderArray; } + AnnotBorderBS *getBorderBS() const { return borderBS; } AnnotColor *getColor() const { return color; } int getTreeKey() const { return treeKey; } @@ -677,7 +682,8 @@ protected: XRef *xref; // the xref table for this PDF file Ref ref; // object ref identifying this annotation GooString *appearBuf; - AnnotBorder *border; // Border, BS + AnnotBorderArray *borderArray; // Border + AnnotBorderBS* borderBS; // BS AnnotColor *color; // C double fontSize; GBool ok;