[poppler] glib/poppler-annot.cc glib/poppler-page.cc poppler/Annot.h qt5/src qt6/src

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Mar 8 09:42:42 UTC 2022


 glib/poppler-annot.cc         |   22 ++++++++++------------
 glib/poppler-page.cc          |   11 +++++------
 poppler/Annot.h               |    2 +-
 qt5/src/poppler-annotation.cc |    8 ++++----
 qt6/src/poppler-annotation.cc |    8 ++++----
 5 files changed, 24 insertions(+), 27 deletions(-)

New commits:
commit b41c92c66885ad5849db8337c104ff1e7ee64b60
Author: Albert Astals Cid <aacid at kde.org>
Date:   Mon Mar 7 16:15:25 2022 +0100

    Annot::getRect: Return a const & instead of a pointer
    
    Makes it clear the result is never null

diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index a8bbd76f..08cd3633 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -924,7 +924,6 @@ const PDFRectangle *_poppler_annot_get_cropbox(PopplerAnnot *poppler_annot)
  */
 void poppler_annot_get_rectangle(PopplerAnnot *poppler_annot, PopplerRectangle *poppler_rect)
 {
-    PDFRectangle *annot_rect;
     const PDFRectangle *crop_box;
     PDFRectangle zerobox;
     Page *page = nullptr;
@@ -938,11 +937,11 @@ void poppler_annot_get_rectangle(PopplerAnnot *poppler_annot, PopplerRectangle *
         crop_box = &zerobox;
     }
 
-    annot_rect = poppler_annot->annot->getRect();
-    poppler_rect->x1 = annot_rect->x1 - crop_box->x1;
-    poppler_rect->x2 = annot_rect->x2 - crop_box->x1;
-    poppler_rect->y1 = annot_rect->y1 - crop_box->y1;
-    poppler_rect->y2 = annot_rect->y2 - crop_box->y1;
+    const PDFRectangle &annot_rect = poppler_annot->annot->getRect();
+    poppler_rect->x1 = annot_rect.x1 - crop_box->x1;
+    poppler_rect->x2 = annot_rect.x2 - crop_box->x1;
+    poppler_rect->y1 = annot_rect.y1 - crop_box->y1;
+    poppler_rect->y2 = annot_rect.y2 - crop_box->y1;
 }
 
 /**
@@ -1139,7 +1138,6 @@ gboolean poppler_annot_markup_get_popup_rectangle(PopplerAnnotMarkup *poppler_an
 {
     AnnotMarkup *annot;
     Annot *annot_popup;
-    PDFRectangle *annot_rect;
 
     g_return_val_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot), FALSE);
     g_return_val_if_fail(poppler_rect != nullptr, FALSE);
@@ -1149,11 +1147,11 @@ gboolean poppler_annot_markup_get_popup_rectangle(PopplerAnnotMarkup *poppler_an
     if (!annot_popup)
         return FALSE;
 
-    annot_rect = annot_popup->getRect();
-    poppler_rect->x1 = annot_rect->x1;
-    poppler_rect->x2 = annot_rect->x2;
-    poppler_rect->y1 = annot_rect->y1;
-    poppler_rect->y2 = annot_rect->y2;
+    const PDFRectangle &annot_rect = annot_popup->getRect();
+    poppler_rect->x1 = annot_rect.x1;
+    poppler_rect->x2 = annot_rect.x2;
+    poppler_rect->y1 = annot_rect.y1;
+    poppler_rect->y2 = annot_rect.y2;
 
     return TRUE;
 }
diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index a0efd6fa..98d253be 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -1289,7 +1289,6 @@ GList *poppler_page_get_annot_mapping(PopplerPage *page)
         PopplerAnnotMapping *mapping;
         PopplerRectangle rect;
         Annot *annot;
-        PDFRectangle *annot_rect;
         gboolean flag_no_rotate;
         gint rotation = 0;
 
@@ -1335,11 +1334,11 @@ GList *poppler_page_get_annot_mapping(PopplerPage *page)
             break;
         }
 
-        annot_rect = annot->getRect();
-        rect.x1 = annot_rect->x1 - crop_box->x1;
-        rect.y1 = annot_rect->y1 - crop_box->y1;
-        rect.x2 = annot_rect->x2 - crop_box->x1;
-        rect.y2 = annot_rect->y2 - crop_box->y1;
+        const PDFRectangle &annot_rect = annot->getRect();
+        rect.x1 = annot_rect.x1 - crop_box->x1;
+        rect.y1 = annot_rect.y1 - crop_box->y1;
+        rect.x2 = annot_rect.x2 - crop_box->x1;
+        rect.y2 = annot_rect.y2 - crop_box->y1;
 
         rotation = page->page->getRotate();
 
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 7bc08d4f..3a7b8e74 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -735,7 +735,7 @@ public:
     Ref getRef() const { return ref; }
     const Object &getAnnotObj() const { return annotObj; }
     AnnotSubtype getType() const { return type; }
-    PDFRectangle *getRect() const { return rect.get(); }
+    const PDFRectangle &getRect() const { return *rect; }
     void getRect(double *x1, double *y1, double *x2, double *y2) const;
     const GooString *getContents() const { return contents.get(); }
     int getPageNum() const { return page; }
diff --git a/qt5/src/poppler-annotation.cc b/qt5/src/poppler-annotation.cc
index 5f563ca4..cf14717d 100644
--- a/qt5/src/poppler-annotation.cc
+++ b/qt5/src/poppler-annotation.cc
@@ -1555,8 +1555,8 @@ QRectF Annotation::boundary() const
     if (!d->pdfAnnot)
         return d->boundary;
 
-    const PDFRectangle *rect = d->pdfAnnot->getRect();
-    return d->fromPdfRectangle(*rect);
+    const PDFRectangle &rect = d->pdfAnnot->getRect();
+    return d->fromPdfRectangle(rect);
 }
 
 void Annotation::setBoundary(const QRectF &boundary)
@@ -1670,8 +1670,8 @@ Annotation::Popup Annotation::popup() const
         if (!popup->getOpen())
             flags |= Annotation::Hidden;
 
-        const PDFRectangle *rect = popup->getRect();
-        w.setGeometry(d->fromPdfRectangle(*rect));
+        const PDFRectangle &rect = popup->getRect();
+        w.setGeometry(d->fromPdfRectangle(rect));
     }
 
     if (d->pdfAnnot->getType() == Annot::typeText) {
diff --git a/qt6/src/poppler-annotation.cc b/qt6/src/poppler-annotation.cc
index 1b9aa344..b3cb3777 100644
--- a/qt6/src/poppler-annotation.cc
+++ b/qt6/src/poppler-annotation.cc
@@ -1220,8 +1220,8 @@ QRectF Annotation::boundary() const
     if (!d->pdfAnnot)
         return d->boundary;
 
-    const PDFRectangle *rect = d->pdfAnnot->getRect();
-    return d->fromPdfRectangle(*rect);
+    const PDFRectangle &rect = d->pdfAnnot->getRect();
+    return d->fromPdfRectangle(rect);
 }
 
 void Annotation::setBoundary(const QRectF &boundary)
@@ -1335,8 +1335,8 @@ Annotation::Popup Annotation::popup() const
         if (!popup->getOpen())
             flags |= Annotation::Hidden;
 
-        const PDFRectangle *rect = popup->getRect();
-        w.setGeometry(d->fromPdfRectangle(*rect));
+        const PDFRectangle &rect = popup->getRect();
+        w.setGeometry(d->fromPdfRectangle(rect));
     }
 
     if (d->pdfAnnot->getType() == Annot::typeText) {


More information about the poppler mailing list