summaryrefslogtreecommitdiff
path: root/fpdfsdk/cpdf_annotcontext.cpp
blob: 20c5fc343efca90c6eaf312d00fba165db7ac08c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2018 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 "fpdfsdk/cpdf_annotcontext.h"

#include "core/fpdfapi/page/cpdf_form.h"
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "third_party/base/ptr_util.h"

CPDF_AnnotContext::CPDF_AnnotContext(CPDF_Dictionary* pAnnotDict,
                                     CPDF_Page* pPage,
                                     CPDF_Stream* pStream)
    : m_pAnnotDict(pAnnotDict), m_pPage(pPage) {
  SetForm(pStream);
}

CPDF_AnnotContext::~CPDF_AnnotContext() = default;

void CPDF_AnnotContext::SetForm(CPDF_Stream* pStream) {
  if (!pStream)
    return;

  // Reset the annotation matrix to be the identity matrix, since the
  // appearance stream already takes matrix into account.
  pStream->GetDict()->SetMatrixFor("Matrix", CFX_Matrix());

  m_pAnnotForm = pdfium::MakeUnique<CPDF_Form>(
      m_pPage->GetDocument(), m_pPage->m_pResources.Get(), pStream);
  m_pAnnotForm->ParseContent();
}