FWIW this was reviewed by Fabio D'Urso that is sitting next to me as I write this.
Cheers, Albert El Diumenge, 11 de maig de 2014, a les 09:32:01, Albert Astals Cid va escriure: > qt4/src/poppler-annotation-private.h | 4 +- > qt4/src/poppler-annotation.cc | 48 > +++++++++++++++++++++++++++++++++-- qt4/src/poppler-page.cc | > 7 ++++- > qt4/src/poppler-qt4.h | 14 ++++++++++ > qt5/src/poppler-annotation-private.h | 4 +- > qt5/src/poppler-annotation.cc | 48 > +++++++++++++++++++++++++++++++++-- qt5/src/poppler-page.cc | > 7 ++++- > qt5/src/poppler-qt5.h | 15 ++++++++++ > 8 files changed, 137 insertions(+), 10 deletions(-) > > New commits: > commit 93373cd113d046b65538fe983b46842d689a2112 > Author: Albert Astals Cid <[email protected]> > Date: Sun May 11 18:31:10 2014 +0200 > > Qt: Add a new page->annotations() call that let's you specify subtypes > > This way we don't return annotations you may not be interested in > > diff --git a/qt4/src/poppler-annotation-private.h > b/qt4/src/poppler-annotation-private.h index c755eb3..4c263eb 100644 > --- a/qt4/src/poppler-annotation-private.h > +++ b/qt4/src/poppler-annotation-private.h > @@ -93,8 +93,8 @@ class AnnotationPrivate : public QSharedData > PDFRectangle boundaryToPdfRectangle(const QRectF &r, int flags) > const; AnnotPath * toAnnotPath(const QLinkedList<QPointF> &l) const; > > - /* Scan page for annotations, parentId=0 searches for root > annotations */ - static QList<Annotation*> findAnnotations(::Page > *pdfPage, DocumentData *doc, int parentId = 0); + /* Scan page for > annotations, parentId=0 searches for root annotations, subtypes empty means > all subtypes */ + static QList<Annotation*> findAnnotations(::Page > *pdfPage, DocumentData *doc, const QSet<Annotation::SubType> &subtypes, int > parentId = 0); > > /* Add given annotation to given page */ > static void addAnnotationToPage(::Page *pdfPage, DocumentData *doc, > const Annotation * ann); diff --git a/qt4/src/poppler-annotation.cc > b/qt4/src/poppler-annotation.cc index 70a5ea2..8375287 100644 > --- a/qt4/src/poppler-annotation.cc > +++ b/qt4/src/poppler-annotation.cc > @@ -366,7 +366,7 @@ AnnotPath * AnnotationPrivate::toAnnotPath(const > QLinkedList<QPointF> &list) con return new AnnotPath(ac, count); > } > > -QList<Annotation*> AnnotationPrivate::findAnnotations(::Page *pdfPage, > DocumentData *doc, int parentID) +QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentData *doc, > const QSet<Annotation::SubType> &subtypes, int parentID) { > Annots* annots = pdfPage->getAnnots(); > const uint numAnnotations = annots->getNumAnnots(); > @@ -375,6 +375,20 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD return > QList<Annotation*>(); > } > > + const bool wantTextAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AText); + const bool wantLineAnnotations = > subtypes.isEmpty() || subtypes.contains(Annotation::ALine); + const bool > wantGeomAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AGeom); + const bool > wantHighlightAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AHighlight); + const bool > wantStampAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AStamp); + const bool wantInkAnnotations = > subtypes.isEmpty() || subtypes.contains(Annotation::AInk); + const bool > wantLinkAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::ALink); + const bool wantCaretAnnotations > = subtypes.isEmpty() || subtypes.contains(Annotation::ACaret); + const > bool wantFileAttachmentAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AFileAttachment); + const bool > wantSoundAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::ASound); + const bool wantMovieAnnotations > = subtypes.isEmpty() || subtypes.contains(Annotation::AMovie); + const > bool wantScreenAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AScreen); + const bool > wantWidgetAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AWidget); + > // Create Annotation objects and tie to their native Annot > QList<Annotation*> res; > for ( uint j = 0; j < numAnnotations; j++ ) > @@ -405,36 +419,54 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD switch ( > subType ) > { > case Annot::typeText: > + if (!wantTextAnnotations) > + continue; > annotation = new TextAnnotation(TextAnnotation::Linked); > break; > case Annot::typeFreeText: > + if (!wantTextAnnotations) > + continue; > annotation = new TextAnnotation(TextAnnotation::InPlace); > break; > case Annot::typeLine: > + if (!wantLineAnnotations) > + continue; > annotation = new > LineAnnotation(LineAnnotation::StraightLine); break; > case Annot::typePolygon: > case Annot::typePolyLine: > + if (!wantLineAnnotations) > + continue; > annotation = new LineAnnotation(LineAnnotation::Polyline); > break; > case Annot::typeSquare: > case Annot::typeCircle: > + if (!wantGeomAnnotations) > + continue; > annotation = new GeomAnnotation(); > break; > case Annot::typeHighlight: > case Annot::typeUnderline: > case Annot::typeSquiggly: > case Annot::typeStrikeOut: > + if (!wantHighlightAnnotations) > + continue; > annotation = new HighlightAnnotation(); > break; > case Annot::typeStamp: > + if (!wantStampAnnotations) > + continue; > annotation = new StampAnnotation(); > break; > case Annot::typeInk: > + if (!wantInkAnnotations) > + continue; > annotation = new InkAnnotation(); > break; > case Annot::typeLink: /* TODO: Move logic to getters */ > { > + if (!wantLinkAnnotations) > + continue; > // parse Link params > AnnotLink * linkann = static_cast< AnnotLink * >( ann ); > LinkAnnotation * l = new LinkAnnotation(); > @@ -458,10 +490,14 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD break; > } > case Annot::typeCaret: > + if (!wantCaretAnnotations) > + continue; > annotation = new CaretAnnotation(); > break; > case Annot::typeFileAttachment: /* TODO: Move logic to getters > */ { > + if (!wantFileAttachmentAnnotations) > + continue; > AnnotFileAttachment * attachann = static_cast< > AnnotFileAttachment * >( ann ); FileAttachmentAnnotation * f = new > FileAttachmentAnnotation(); annotation = f; > @@ -474,6 +510,8 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD } > case Annot::typeSound: /* TODO: Move logic to getters */ > { > + if (!wantSoundAnnotations) > + continue; > AnnotSound * soundann = static_cast< AnnotSound * >( ann ); > SoundAnnotation * s = new SoundAnnotation(); > annotation = s; > @@ -486,6 +524,8 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD } > case Annot::typeMovie: /* TODO: Move logic to getters */ > { > + if (!wantMovieAnnotations) > + continue; > AnnotMovie * movieann = static_cast< AnnotMovie * >( ann ); > MovieAnnotation * m = new MovieAnnotation(); > annotation = m; > @@ -501,6 +541,8 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD } > case Annot::typeScreen: > { > + if (!wantScreenAnnotations) > + continue; > AnnotScreen * screenann = static_cast< AnnotScreen * >( ann > ); if (!screenann->getAction()) > continue; > @@ -522,6 +564,8 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD case > Annot::typeUnknown: > continue; // special case for ignoring unknown annotations > case Annot::typeWidget: > + if (!wantWidgetAnnotations) > + continue; > annotation = new WidgetAnnotation(); > break; > default: > @@ -1607,7 +1651,7 @@ QList<Annotation*> Annotation::revisions() const > if ( !d->pdfAnnot->getHasRef() ) > return QList<Annotation*>(); > > - return AnnotationPrivate::findAnnotations( d->pdfPage, d->parentDoc, > d->pdfAnnot->getId() ); + return AnnotationPrivate::findAnnotations( > d->pdfPage, d->parentDoc, QSet<Annotation::SubType>(), d->pdfAnnot->getId() > ); } > > //END Annotation implementation > diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc > index f7c2427..32f6d7e 100644 > --- a/qt4/src/poppler-page.cc > +++ b/qt4/src/poppler-page.cc > @@ -671,7 +671,12 @@ QList<Link*> Page::links() const > > QList<Annotation*> Page::annotations() const > { > - return AnnotationPrivate::findAnnotations(m_page->page, > m_page->parentDoc); + return > AnnotationPrivate::findAnnotations(m_page->page, m_page->parentDoc, > QSet<Annotation::SubType>()); +} > + > +QList<Annotation*> Page::annotations(const QSet<Annotation::SubType> > &subtypes) const +{ > + return AnnotationPrivate::findAnnotations(m_page->page, > m_page->parentDoc, subtypes); } > > void Page::addAnnotation( const Annotation *ann ) > diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h > index 30295cf..6c4a410 100644 > --- a/qt4/src/poppler-qt4.h > +++ b/qt4/src/poppler-qt4.h > @@ -701,6 +701,20 @@ delete it; > QList<Annotation*> annotations() const; > > /** > + Returns the annotations of the page > + > + \param subtypes the subtypes of annotations you are interested > in > + > + \note If you call this method twice, you get different objects > + pointing to the same annotations (see Annotation). > + The caller owns the returned objects and they should be > deleted > + when no longer required. > + > + \since 0.28 > + */ > + QList<Annotation*> annotations(const QSet<Annotation::SubType> > &subtypes) > const; + > + /** > Adds an annotation to the page > > \note Ownership of the annotation object stays with the caller, who can > diff --git a/qt5/src/poppler-annotation-private.h > b/qt5/src/poppler-annotation-private.h index c755eb3..4c263eb 100644 > --- a/qt5/src/poppler-annotation-private.h > +++ b/qt5/src/poppler-annotation-private.h > @@ -93,8 +93,8 @@ class AnnotationPrivate : public QSharedData > PDFRectangle boundaryToPdfRectangle(const QRectF &r, int flags) > const; AnnotPath * toAnnotPath(const QLinkedList<QPointF> &l) const; > > - /* Scan page for annotations, parentId=0 searches for root > annotations */ - static QList<Annotation*> findAnnotations(::Page > *pdfPage, DocumentData *doc, int parentId = 0); + /* Scan page for > annotations, parentId=0 searches for root annotations, subtypes empty means > all subtypes */ + static QList<Annotation*> findAnnotations(::Page > *pdfPage, DocumentData *doc, const QSet<Annotation::SubType> &subtypes, int > parentId = 0); > > /* Add given annotation to given page */ > static void addAnnotationToPage(::Page *pdfPage, DocumentData *doc, > const Annotation * ann); diff --git a/qt5/src/poppler-annotation.cc > b/qt5/src/poppler-annotation.cc index e6d331d..3654cb3 100644 > --- a/qt5/src/poppler-annotation.cc > +++ b/qt5/src/poppler-annotation.cc > @@ -366,7 +366,7 @@ AnnotPath * AnnotationPrivate::toAnnotPath(const > QLinkedList<QPointF> &list) con return new AnnotPath(ac, count); > } > > -QList<Annotation*> AnnotationPrivate::findAnnotations(::Page *pdfPage, > DocumentData *doc, int parentID) +QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentData *doc, > const QSet<Annotation::SubType> &subtypes, int parentID) { > Annots* annots = pdfPage->getAnnots(); > const uint numAnnotations = annots->getNumAnnots(); > @@ -375,6 +375,20 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD return > QList<Annotation*>(); > } > > + const bool wantTextAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AText); + const bool wantLineAnnotations = > subtypes.isEmpty() || subtypes.contains(Annotation::ALine); + const bool > wantGeomAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AGeom); + const bool > wantHighlightAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AHighlight); + const bool > wantStampAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AStamp); + const bool wantInkAnnotations = > subtypes.isEmpty() || subtypes.contains(Annotation::AInk); + const bool > wantLinkAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::ALink); + const bool wantCaretAnnotations > = subtypes.isEmpty() || subtypes.contains(Annotation::ACaret); + const > bool wantFileAttachmentAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AFileAttachment); + const bool > wantSoundAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::ASound); + const bool wantMovieAnnotations > = subtypes.isEmpty() || subtypes.contains(Annotation::AMovie); + const > bool wantScreenAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AScreen); + const bool > wantWidgetAnnotations = subtypes.isEmpty() || > subtypes.contains(Annotation::AWidget); + > // Create Annotation objects and tie to their native Annot > QList<Annotation*> res; > for ( uint j = 0; j < numAnnotations; j++ ) > @@ -405,36 +419,54 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD switch ( > subType ) > { > case Annot::typeText: > + if (!wantTextAnnotations) > + continue; > annotation = new TextAnnotation(TextAnnotation::Linked); > break; > case Annot::typeFreeText: > + if (!wantTextAnnotations) > + continue; > annotation = new TextAnnotation(TextAnnotation::InPlace); > break; > case Annot::typeLine: > + if (!wantLineAnnotations) > + continue; > annotation = new > LineAnnotation(LineAnnotation::StraightLine); break; > case Annot::typePolygon: > case Annot::typePolyLine: > + if (!wantLineAnnotations) > + continue; > annotation = new LineAnnotation(LineAnnotation::Polyline); > break; > case Annot::typeSquare: > case Annot::typeCircle: > + if (!wantGeomAnnotations) > + continue; > annotation = new GeomAnnotation(); > break; > case Annot::typeHighlight: > case Annot::typeUnderline: > case Annot::typeSquiggly: > case Annot::typeStrikeOut: > + if (!wantHighlightAnnotations) > + continue; > annotation = new HighlightAnnotation(); > break; > case Annot::typeStamp: > + if (!wantStampAnnotations) > + continue; > annotation = new StampAnnotation(); > break; > case Annot::typeInk: > + if (!wantInkAnnotations) > + continue; > annotation = new InkAnnotation(); > break; > case Annot::typeLink: /* TODO: Move logic to getters */ > { > + if (!wantLinkAnnotations) > + continue; > // parse Link params > AnnotLink * linkann = static_cast< AnnotLink * >( ann ); > LinkAnnotation * l = new LinkAnnotation(); > @@ -458,10 +490,14 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD break; > } > case Annot::typeCaret: > + if (!wantCaretAnnotations) > + continue; > annotation = new CaretAnnotation(); > break; > case Annot::typeFileAttachment: /* TODO: Move logic to getters > */ { > + if (!wantFileAttachmentAnnotations) > + continue; > AnnotFileAttachment * attachann = static_cast< > AnnotFileAttachment * >( ann ); FileAttachmentAnnotation * f = new > FileAttachmentAnnotation(); annotation = f; > @@ -474,6 +510,8 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD } > case Annot::typeSound: /* TODO: Move logic to getters */ > { > + if (!wantSoundAnnotations) > + continue; > AnnotSound * soundann = static_cast< AnnotSound * >( ann ); > SoundAnnotation * s = new SoundAnnotation(); > annotation = s; > @@ -486,6 +524,8 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD } > case Annot::typeMovie: /* TODO: Move logic to getters */ > { > + if (!wantMovieAnnotations) > + continue; > AnnotMovie * movieann = static_cast< AnnotMovie * >( ann ); > MovieAnnotation * m = new MovieAnnotation(); > annotation = m; > @@ -501,6 +541,8 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD } > case Annot::typeScreen: > { > + if (!wantScreenAnnotations) > + continue; > AnnotScreen * screenann = static_cast< AnnotScreen * >( ann > ); if (!screenann->getAction()) > continue; > @@ -522,6 +564,8 @@ QList<Annotation*> > AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD case > Annot::typeUnknown: > continue; // special case for ignoring unknown annotations > case Annot::typeWidget: > + if (!wantWidgetAnnotations) > + continue; > annotation = new WidgetAnnotation(); > break; > default: > @@ -1604,7 +1648,7 @@ QList<Annotation*> Annotation::revisions() const > if ( !d->pdfAnnot->getHasRef() ) > return QList<Annotation*>(); > > - return AnnotationPrivate::findAnnotations( d->pdfPage, d->parentDoc, > d->pdfAnnot->getId() ); + return AnnotationPrivate::findAnnotations( > d->pdfPage, d->parentDoc, QSet<Annotation::SubType>(), d->pdfAnnot->getId() > ); } > > //END Annotation implementation > diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc > index df2ef69..2977214 100644 > --- a/qt5/src/poppler-page.cc > +++ b/qt5/src/poppler-page.cc > @@ -653,7 +653,12 @@ QList<Link*> Page::links() const > > QList<Annotation*> Page::annotations() const > { > - return AnnotationPrivate::findAnnotations(m_page->page, > m_page->parentDoc); + return > AnnotationPrivate::findAnnotations(m_page->page, m_page->parentDoc, > QSet<Annotation::SubType>()); +} > + > +QList<Annotation*> Page::annotations(const QSet<Annotation::SubType> > &subtypes) const +{ > + return AnnotationPrivate::findAnnotations(m_page->page, > m_page->parentDoc, subtypes); } > > void Page::addAnnotation( const Annotation *ann ) > diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h > index 6f36088..d8f13ea 100644 > --- a/qt5/src/poppler-qt5.h > +++ b/qt5/src/poppler-qt5.h > @@ -689,6 +689,21 @@ delete it; > */ > QList<Annotation*> annotations() const; > > + > + /** > + Returns the annotations of the page > + > + \param subtypes the subtypes of annotations you are interested > in > + > + \note If you call this method twice, you get different objects > + pointing to the same annotations (see Annotation). > + The caller owns the returned objects and they should be > deleted > + when no longer required. > + > + \since 0.28 > + */ > + QList<Annotation*> annotations(const QSet<Annotation::SubType> > &subtypes) > const; + > /** > Adds an annotation to the page > > _______________________________________________ > poppler mailing list > [email protected] > http://lists.freedesktop.org/mailman/listinfo/poppler _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
