diff options
author | dsinclair <dsinclair@chromium.org> | 2016-10-04 11:29:35 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-10-04 11:29:36 -0700 |
commit | 41872fa5ac7448a50f66ad56d7bde8d1aa77db4b (patch) | |
tree | 49f8162a8ed05ace693d7164f9ba116286427919 /core/fpdfapi/page/cpdf_imageobject.cpp | |
parent | bc5e6d289ed40efec2b0e03427e8fc2947bf53e3 (diff) | |
download | pdfium-41872fa5ac7448a50f66ad56d7bde8d1aa77db4b.tar.xz |
Move core/fpdfapi/fpdf_page to core/fpdfapi/page
BUG=pdfium:603
Review-Url: https://codereview.chromium.org/2386423004
Diffstat (limited to 'core/fpdfapi/page/cpdf_imageobject.cpp')
-rw-r--r-- | core/fpdfapi/page/cpdf_imageobject.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/core/fpdfapi/page/cpdf_imageobject.cpp b/core/fpdfapi/page/cpdf_imageobject.cpp new file mode 100644 index 0000000000..8be2cf3c76 --- /dev/null +++ b/core/fpdfapi/page/cpdf_imageobject.cpp @@ -0,0 +1,84 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/page/cpdf_imageobject.h" + +#include <memory> + +#include "core/fpdfapi/fpdf_parser/cpdf_document.h" +#include "core/fpdfapi/page/cpdf_image.h" +#include "core/fpdfapi/page/pageint.h" + +CPDF_ImageObject::CPDF_ImageObject() + : m_pImage(nullptr), m_pImageOwned(false) {} + +CPDF_ImageObject::~CPDF_ImageObject() { + Release(); +} + +CPDF_ImageObject* CPDF_ImageObject::Clone() const { + CPDF_ImageObject* obj = new CPDF_ImageObject; + obj->CopyData(this); + + obj->m_pImage = m_pImage->Clone(); + obj->m_Matrix = m_Matrix; + return obj; +} + +CPDF_PageObject::Type CPDF_ImageObject::GetType() const { + return IMAGE; +} + +void CPDF_ImageObject::Transform(const CFX_Matrix& matrix) { + m_Matrix.Concat(matrix); + CalcBoundingBox(); +} + +bool CPDF_ImageObject::IsImage() const { + return true; +} + +CPDF_ImageObject* CPDF_ImageObject::AsImage() { + return this; +} + +const CPDF_ImageObject* CPDF_ImageObject::AsImage() const { + return this; +} + +void CPDF_ImageObject::CalcBoundingBox() { + m_Left = m_Bottom = 0; + m_Right = m_Top = 1.0f; + m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); +} + +void CPDF_ImageObject::SetOwnedImage(std::unique_ptr<CPDF_Image> pImage) { + Release(); + m_pImage = pImage.release(); + m_pImageOwned = true; +} + +void CPDF_ImageObject::SetUnownedImage(CPDF_Image* pImage) { + Release(); + m_pImage = pImage; + m_pImageOwned = false; +} + +void CPDF_ImageObject::Release() { + if (m_pImageOwned) { + delete m_pImage; + m_pImage = nullptr; + m_pImageOwned = false; + return; + } + + if (!m_pImage) + return; + + CPDF_DocPageData* pPageData = m_pImage->GetDocument()->GetPageData(); + pPageData->ReleaseImage(m_pImage->GetStream()); + m_pImage = nullptr; +} |