diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2015-11-04 11:53:47 -0500 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2015-11-04 11:53:47 -0500 |
commit | 891c22686b90f4b23e741b5f1564f21831ee111c (patch) | |
tree | 48da027a599084d8d79acabf28b279837058cac0 /fpdfsdk/src/fsdk_baseannot.cpp | |
parent | 1488aac2e699a5dd31bc59c3d07fe591e2d38c20 (diff) | |
download | pdfium-891c22686b90f4b23e741b5f1564f21831ee111c.tar.xz |
Backport CPDFSDK_BAAnnot from XFA.
On the XFA branch the CPDFSDK_Annot class has been turned into a base class
with CPDFSDK_BAAnnot serving the purpose that was served by CPDFSDK_Annot.
This CL pulls those changes into master to put it more in line with the XFA
branch. (This removes ~600 lines from the fpdfsdk/ diff).
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1408073009 .
Diffstat (limited to 'fpdfsdk/src/fsdk_baseannot.cpp')
-rw-r--r-- | fpdfsdk/src/fsdk_baseannot.cpp | 141 |
1 files changed, 67 insertions, 74 deletions
diff --git a/fpdfsdk/src/fsdk_baseannot.cpp b/fpdfsdk/src/fsdk_baseannot.cpp index c6731e6f56..e9ef0fb2b6 100644 --- a/fpdfsdk/src/fsdk_baseannot.cpp +++ b/fpdfsdk/src/fsdk_baseannot.cpp @@ -505,33 +505,22 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::AddSeconds(int seconds) { //--------------------------------------------------------------------------- // CPDFSDK_Annot //--------------------------------------------------------------------------- -CPDFSDK_Annot::CPDFSDK_Annot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView) - : m_pAnnot(pAnnot), - m_pPageView(pPageView), - m_bSelected(FALSE), - m_nTabOrder(-1) {} - -CPDFSDK_Annot::~CPDFSDK_Annot() { - m_pAnnot = NULL; - m_pPageView = NULL; +CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView) + : m_pPageView(pPageView), m_bSelected(FALSE), m_nTabOrder(-1) { } -CPDF_Annot* CPDFSDK_Annot::GetPDFAnnot() { - return m_pAnnot; +// CPDFSDK_BAAnnot +CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, + CPDFSDK_PageView* pPageView) + : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) { } -FX_DWORD CPDFSDK_Annot::GetFlags() { - ASSERT(m_pAnnot != NULL); - - return m_pAnnot->GetFlags(); -} - -void CPDFSDK_Annot::SetPage(CPDFSDK_PageView* pPageView) { - m_pPageView = pPageView; +CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot() { + m_pAnnot = NULL; } -CPDFSDK_PageView* CPDFSDK_Annot::GetPageView() { - return m_pPageView; +CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() const { + return m_pAnnot; } FX_BOOL CPDFSDK_Annot::IsSelected() { @@ -551,20 +540,20 @@ void CPDFSDK_Annot::SetTabOrder(int iTabOrder) { m_nTabOrder = iTabOrder; } -CPDF_Dictionary* CPDFSDK_Annot::GetAnnotDict() const { +CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const { ASSERT(m_pAnnot != NULL); return m_pAnnot->GetAnnotDict(); } -void CPDFSDK_Annot::SetRect(const CPDF_Rect& rect) { +void CPDFSDK_BAAnnot::SetRect(const CPDF_Rect& rect) { ASSERT(rect.right - rect.left >= GetMinWidth()); ASSERT(rect.top - rect.bottom >= GetMinHeight()); m_pAnnot->GetAnnotDict()->SetAtRect("Rect", rect); } -CPDF_Rect CPDFSDK_Annot::GetRect() const { +CPDF_Rect CPDFSDK_BAAnnot::GetRect() const { ASSERT(m_pAnnot != NULL); CPDF_Rect rect; @@ -573,20 +562,20 @@ CPDF_Rect CPDFSDK_Annot::GetRect() const { return rect; } -CFX_ByteString CPDFSDK_Annot::GetType() const { +CFX_ByteString CPDFSDK_BAAnnot::GetType() const { ASSERT(m_pAnnot != NULL); return m_pAnnot->GetSubType(); } -CFX_ByteString CPDFSDK_Annot::GetSubType() const { +CFX_ByteString CPDFSDK_BAAnnot::GetSubType() const { return ""; } -void CPDFSDK_Annot::DrawAppearance(CFX_RenderDevice* pDevice, - const CPDF_Matrix* pUser2Device, - CPDF_Annot::AppearanceMode mode, - const CPDF_RenderOptions* pOptions) { +void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice, + const CPDF_Matrix* pUser2Device, + CPDF_Annot::AppearanceMode mode, + const CPDF_RenderOptions* pOptions) { ASSERT(m_pPageView != NULL); ASSERT(m_pAnnot != NULL); @@ -594,11 +583,11 @@ void CPDFSDK_Annot::DrawAppearance(CFX_RenderDevice* pDevice, mode, pOptions); } -FX_BOOL CPDFSDK_Annot::IsAppearanceValid() { +FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid() { return m_pAnnot->GetAnnotDict()->GetDict("AP") != NULL; } -FX_BOOL CPDFSDK_Annot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) { +FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) { CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP"); if (pAP == NULL) return FALSE; @@ -620,19 +609,19 @@ FX_BOOL CPDFSDK_Annot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) { return TRUE; } -void CPDFSDK_Annot::DrawBorder(CFX_RenderDevice* pDevice, - const CPDF_Matrix* pUser2Device, - const CPDF_RenderOptions* pOptions) { +void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice, + const CPDF_Matrix* pUser2Device, + const CPDF_RenderOptions* pOptions) { ASSERT(m_pAnnot != NULL); m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions); } -void CPDFSDK_Annot::ClearCachedAP() { +void CPDFSDK_BAAnnot::ClearCachedAP() { ASSERT(m_pAnnot != NULL); m_pAnnot->ClearCachedAP(); } -void CPDFSDK_Annot::SetContents(const CFX_WideString& sContents) { +void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) { if (sContents.IsEmpty()) m_pAnnot->GetAnnotDict()->RemoveAt("Contents"); else @@ -640,22 +629,22 @@ void CPDFSDK_Annot::SetContents(const CFX_WideString& sContents) { PDF_EncodeText(sContents)); } -CFX_WideString CPDFSDK_Annot::GetContents() const { +CFX_WideString CPDFSDK_BAAnnot::GetContents() const { return m_pAnnot->GetAnnotDict()->GetUnicodeText("Contents"); } -void CPDFSDK_Annot::SetAnnotName(const CFX_WideString& sName) { +void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) { if (sName.IsEmpty()) m_pAnnot->GetAnnotDict()->RemoveAt("NM"); else m_pAnnot->GetAnnotDict()->SetAtString("NM", PDF_EncodeText(sName)); } -CFX_WideString CPDFSDK_Annot::GetAnnotName() const { +CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const { return m_pAnnot->GetAnnotDict()->GetUnicodeText("NM"); } -void CPDFSDK_Annot::SetModifiedDate(const FX_SYSTEMTIME& st) { +void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) { CPDFSDK_DateTime dt(st); CFX_ByteString str = dt.ToPDFDateTimeString(); @@ -665,7 +654,7 @@ void CPDFSDK_Annot::SetModifiedDate(const FX_SYSTEMTIME& st) { m_pAnnot->GetAnnotDict()->SetAtString("M", str); } -FX_SYSTEMTIME CPDFSDK_Annot::GetModifiedDate() const { +FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const { FX_SYSTEMTIME systime; CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetString("M"); @@ -675,35 +664,35 @@ FX_SYSTEMTIME CPDFSDK_Annot::GetModifiedDate() const { return systime; } -void CPDFSDK_Annot::SetFlags(int nFlags) { +void CPDFSDK_BAAnnot::SetFlags(int nFlags) { m_pAnnot->GetAnnotDict()->SetAtInteger("F", nFlags); } -int CPDFSDK_Annot::GetFlags() const { +int CPDFSDK_BAAnnot::GetFlags() const { return m_pAnnot->GetAnnotDict()->GetInteger("F"); } -void CPDFSDK_Annot::SetAppState(const CFX_ByteString& str) { +void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) { if (str.IsEmpty()) m_pAnnot->GetAnnotDict()->RemoveAt("AS"); else m_pAnnot->GetAnnotDict()->SetAtString("AS", str); } -CFX_ByteString CPDFSDK_Annot::GetAppState() const { +CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const { return m_pAnnot->GetAnnotDict()->GetString("AS"); } -void CPDFSDK_Annot::SetStructParent(int key) { +void CPDFSDK_BAAnnot::SetStructParent(int key) { m_pAnnot->GetAnnotDict()->SetAtInteger("StructParent", key); } -int CPDFSDK_Annot::GetStructParent() const { +int CPDFSDK_BAAnnot::GetStructParent() const { return m_pAnnot->GetAnnotDict()->GetInteger("StructParent"); } // border -void CPDFSDK_Annot::SetBorderWidth(int nWidth) { +void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) { CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border"); if (pBorder) { @@ -720,7 +709,7 @@ void CPDFSDK_Annot::SetBorderWidth(int nWidth) { } } -int CPDFSDK_Annot::GetBorderWidth() const { +int CPDFSDK_BAAnnot::GetBorderWidth() const { if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border")) { return pBorder->GetInteger(2); } @@ -730,7 +719,7 @@ int CPDFSDK_Annot::GetBorderWidth() const { return 1; } -void CPDFSDK_Annot::SetBorderStyle(int nStyle) { +void CPDFSDK_BAAnnot::SetBorderStyle(int nStyle) { CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS"); if (!pBSDict) { pBSDict = new CPDF_Dictionary; @@ -756,7 +745,7 @@ void CPDFSDK_Annot::SetBorderStyle(int nStyle) { } } -int CPDFSDK_Annot::GetBorderStyle() const { +int CPDFSDK_BAAnnot::GetBorderStyle() const { CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS"); if (pBSDict) { CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S"); @@ -784,7 +773,7 @@ int CPDFSDK_Annot::GetBorderStyle() const { return BBS_SOLID; } -void CPDFSDK_Annot::SetBorderDash(const CFX_IntArray& array) { +void CPDFSDK_BAAnnot::SetBorderDash(const CFX_IntArray& array) { CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS"); if (!pBSDict) { pBSDict = new CPDF_Dictionary; @@ -799,7 +788,7 @@ void CPDFSDK_Annot::SetBorderDash(const CFX_IntArray& array) { pBSDict->SetAt("D", pArray); } -void CPDFSDK_Annot::GetBorderDash(CFX_IntArray& array) const { +void CPDFSDK_BAAnnot::GetBorderDash(CFX_IntArray& array) const { CPDF_Array* pDash = NULL; CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border"); @@ -819,7 +808,7 @@ void CPDFSDK_Annot::GetBorderDash(CFX_IntArray& array) const { } } -void CPDFSDK_Annot::SetColor(FX_COLORREF color) { +void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) { CPDF_Array* pArray = new CPDF_Array; pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f); pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f); @@ -827,11 +816,11 @@ void CPDFSDK_Annot::SetColor(FX_COLORREF color) { m_pAnnot->GetAnnotDict()->SetAt("C", pArray); } -void CPDFSDK_Annot::RemoveColor() { +void CPDFSDK_BAAnnot::RemoveColor() { m_pAnnot->GetAnnotDict()->RemoveAt("C"); } -FX_BOOL CPDFSDK_Annot::GetColor(FX_COLORREF& color) const { +FX_BOOL CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const { if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArray("C")) { int nCount = pEntry->GetCount(); if (nCount == 1) { @@ -867,11 +856,11 @@ FX_BOOL CPDFSDK_Annot::GetColor(FX_COLORREF& color) const { return FALSE; } -void CPDFSDK_Annot::WriteAppearance(const CFX_ByteString& sAPType, - const CPDF_Rect& rcBBox, - const CPDF_Matrix& matrix, - const CFX_ByteString& sContents, - const CFX_ByteString& sAPState) { +void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, + const CPDF_Rect& rcBBox, + const CPDF_Matrix& matrix, + const CFX_ByteString& sContents, + const CFX_ByteString& sAPState) { CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP"); if (!pAPDict) { @@ -897,13 +886,17 @@ void CPDFSDK_Annot::WriteAppearance(const CFX_ByteString& sAPType, } if (!pStream) { + ASSERT(m_pPageView != NULL); CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); + ASSERT(pDoc != NULL); + pStream = new CPDF_Stream(NULL, 0, NULL); int32_t objnum = pDoc->AddIndirectObject(pStream); pParentDict->SetAtReference(sAPType, pDoc, objnum); } CPDF_Dictionary* pStreamDict = pStream->GetDict(); + if (!pStreamDict) { pStreamDict = new CPDF_Dictionary; pStreamDict->SetAtName("Type", "XObject"); @@ -932,20 +925,20 @@ FX_FLOAT CPDFSDK_Annot::GetMinHeight() const { return BA_ANNOT_MINHEIGHT; } -FX_BOOL CPDFSDK_Annot::CreateFormFiller() { +FX_BOOL CPDFSDK_BAAnnot::CreateFormFiller() { return TRUE; } -FX_BOOL CPDFSDK_Annot::IsVisible() const { +FX_BOOL CPDFSDK_BAAnnot::IsVisible() const { int nFlags = GetFlags(); return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || (nFlags & ANNOTFLAG_NOVIEW)); } -CPDF_Action CPDFSDK_Annot::GetAction() const { +CPDF_Action CPDFSDK_BAAnnot::GetAction() const { return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A")); } -void CPDFSDK_Annot::SetAction(const CPDF_Action& action) { +void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) { ASSERT(action); if ((CPDF_Action&)action != CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"))) { @@ -958,26 +951,26 @@ void CPDFSDK_Annot::SetAction(const CPDF_Action& action) { } } -void CPDFSDK_Annot::RemoveAction() { +void CPDFSDK_BAAnnot::RemoveAction() { m_pAnnot->GetAnnotDict()->RemoveAt("A"); } -CPDF_AAction CPDFSDK_Annot::GetAAction() const { +CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const { return m_pAnnot->GetAnnotDict()->GetDict("AA"); } -void CPDFSDK_Annot::SetAAction(const CPDF_AAction& aa) { +void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) { ASSERT(aa != NULL); if ((CPDF_AAction&)aa != m_pAnnot->GetAnnotDict()->GetDict("AA")) m_pAnnot->GetAnnotDict()->SetAt("AA", (CPDF_AAction&)aa); } -void CPDFSDK_Annot::RemoveAAction() { +void CPDFSDK_BAAnnot::RemoveAAction() { m_pAnnot->GetAnnotDict()->RemoveAt("AA"); } -CPDF_Action CPDFSDK_Annot::GetAAction(CPDF_AAction::AActionType eAAT) { +CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) { CPDF_AAction AAction = GetAAction(); if (AAction.ActionExist(eAAT)) @@ -989,9 +982,9 @@ CPDF_Action CPDFSDK_Annot::GetAAction(CPDF_AAction::AActionType eAAT) { return CPDF_Action(); } -void CPDFSDK_Annot::Annot_OnDraw(CFX_RenderDevice* pDevice, - CPDF_Matrix* pUser2Device, - CPDF_RenderOptions* pOptions) { +void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice, + CPDF_Matrix* pUser2Device, + CPDF_RenderOptions* pOptions) { m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal); m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, CPDF_Annot::Normal, NULL); |