Returns found apperance object in the owner dictionary
---
src/doc/PdfAnnotation.cpp | 37 ++++++++++++++++++++++++++++++++++++-
src/doc/PdfAnnotation.h | 10 +++++++++-
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/src/doc/PdfAnnotation.cpp b/src/doc/PdfAnnotation.cpp
index 765da2f..712ec7f 100644
--- a/src/doc/PdfAnnotation.cpp
+++ b/src/doc/PdfAnnotation.cpp
@@ -246,9 +246,29 @@ void PdfAnnotation::SetAppearanceStream( PdfObject*
pObject, EPdfAnnotationAppea
bool PdfAnnotation::HasAppearanceStream() const
{
return this->GetObject()->GetDictionary().HasKey( "AP" );
+}
+
+PdfObject * PdfAnnotation::GetAppearanceStream(EPdfAnnotationAppearance
eAppearance) const
+{
+ PdfObject *apObj;
+ if (!this->GetObject()->GetDictionary().TryGetKey("AP", apObj))
+ return nullptr;
+
+ if (apObj->GetDataType() != ePdfDataType_Dictionary)
+ PODOFO_RAISE_ERROR(ePdfError_InvalidDataType);
+
+ PdfName apName = GetAppearanceName(eAppearance);
+ PdfObject *apObjInn;
+ if (!apObj->GetDictionary().TryGetKey(apName, apObjInn))
+ return nullptr;
+
+ if (apObjInn->GetDataType() != ePdfDataType_Reference)
+ PODOFO_RAISE_ERROR(ePdfError_InvalidDataType);
+
+ PdfReference reference = apObjInn->GetReference();
+ return GetObject()->GetOwner()->GetObject(reference);
}
-
void PdfAnnotation::SetFlags( pdf_uint32 uiFlags )
{
this->GetObject()->GetDictionary().AddKey( "F", PdfVariant(
static_cast<pdf_int64>(uiFlags) ) );
@@ -434,6 +454,21 @@ void PdfAnnotation::SetColor()
{
PdfArray c;
this->GetObject()->GetDictionary().AddKey( "C", c );
+}
+
+PdfName PdfAnnotation::GetAppearanceName(EPdfAnnotationAppearance eAppearance)
const
+{
+ switch (eAppearance)
+ {
+ case PoDoFo::ePdfAnnotationAppearance_Normal:
+ return PdfName("N");
+ case PoDoFo::ePdfAnnotationAppearance_Rollover:
+ return PdfName("R");
+ case PoDoFo::ePdfAnnotationAppearance_Down:
+ return PdfName("D");
+ default:
+ PODOFO_RAISE_ERROR_INFO(ePdfError_InternalLogic, "Invalid appearance
type");
+ }
}
};
diff --git a/src/doc/PdfAnnotation.h b/src/doc/PdfAnnotation.h
index ccbd504..739b7cf 100644
--- a/src/doc/PdfAnnotation.h
+++ b/src/doc/PdfAnnotation.h
@@ -164,7 +164,12 @@ class PODOFO_DOC_API PdfAnnotation : public PdfElement {
/**
* \returns true if this annotation has an appearance stream
*/
- bool HasAppearanceStream() const;
+ bool HasAppearanceStream() const;
+
+ /**
+ * \returns the appearance stream for this object
+ */
+ PdfObject * GetAppearanceStream(EPdfAnnotationAppearance eAppearance =
ePdfAnnotationAppearance_Normal) const;
/** Get the rectangle of this annotation
* \returns a rectangle
@@ -402,6 +407,9 @@ class PODOFO_DOC_API PdfAnnotation : public PdfElement {
* \returns the page of this PdfField
*/
inline PdfPage* GetPage() const;
+
+ private:
+ PdfName GetAppearanceName(EPdfAnnotationAppearance eAppearance) const;
private:
/** Convert an annotation enum to its string representation
--
2.16.1.windows.1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users