Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cjs_annot.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "fxjs/cjs_annot.h"
8
9#include "constants/annotation_flags.h"
10#include "fxjs/cjs_event_context.h"
11#include "fxjs/cjs_object.h"
12#include "fxjs/js_define.h"
13#include "fxjs/js_resources.h"
14
15const JSPropertySpec CJS_Annot::PropertySpecs[] = {
16 {"hidden", get_hidden_static, set_hidden_static},
17 {"name", get_name_static, set_name_static},
18 {"type", get_type_static, set_type_static}};
19
20uint32_t CJS_Annot::ObjDefnID = 0;
21
22const char CJS_Annot::kName[] = "Annot";
23
24// static
25uint32_t CJS_Annot::GetObjDefnID() {
26 return ObjDefnID;
27}
28
29// static
30void CJS_Annot::DefineJSObjects(CFXJS_Engine* pEngine) {
31 ObjDefnID = pEngine->DefineObj(CJS_Annot::kName, FXJSOBJTYPE_DYNAMIC,
32 JSConstructor<CJS_Annot>, JSDestructor);
33 DefineProps(pEngine, ObjDefnID, PropertySpecs);
34}
35
36CJS_Annot::CJS_Annot(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
37 : CJS_Object(pObject, pRuntime) {}
38
39CJS_Annot::~CJS_Annot() = default;
40
41void CJS_Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) {
42 m_pAnnot.Reset(annot);
43}
44
45CJS_Result CJS_Annot::get_hidden(CJS_Runtime* pRuntime) {
46 if (!m_pAnnot)
48
49 CPDF_Annot* pPDFAnnot = m_pAnnot->GetPDFAnnot();
50 return CJS_Result::Success(pRuntime->NewBoolean(pPDFAnnot->IsHidden()));
51}
52
53CJS_Result CJS_Annot::set_hidden(CJS_Runtime* pRuntime,
54 v8::Local<v8::Value> vp) {
55 // May invalidate m_pAnnot.
56 bool bHidden = pRuntime->ToBoolean(vp);
57
58 CPDFSDK_BAAnnot* pBAAnnot = m_pAnnot.Get();
59 if (!pBAAnnot)
61
62 uint32_t flags = pBAAnnot->GetFlags();
63 if (bHidden) {
64 flags |= pdfium::annotation_flags::kHidden;
65 flags |= pdfium::annotation_flags::kInvisible;
66 flags |= pdfium::annotation_flags::kNoView;
67 flags &= ~pdfium::annotation_flags::kPrint;
68 } else {
69 flags &= ~pdfium::annotation_flags::kHidden;
70 flags &= ~pdfium::annotation_flags::kInvisible;
71 flags &= ~pdfium::annotation_flags::kNoView;
72 flags |= pdfium::annotation_flags::kPrint;
73 }
74 pBAAnnot->SetFlags(flags);
76}
77
78CJS_Result CJS_Annot::get_name(CJS_Runtime* pRuntime) {
79 CPDFSDK_BAAnnot* pBAAnnot = m_pAnnot.Get();
80 if (!pBAAnnot)
82
84 pRuntime->NewString(pBAAnnot->GetAnnotName().AsStringView()));
85}
86
87CJS_Result CJS_Annot::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
88 // May invalidate m_pAnnot.
89 WideString annotName = pRuntime->ToWideString(vp);
90
91 CPDFSDK_BAAnnot* pBAAnnot = m_pAnnot.Get();
92 if (!pBAAnnot)
94
95 pBAAnnot->SetAnnotName(annotName);
97}
98
99CJS_Result CJS_Annot::get_type(CJS_Runtime* pRuntime) {
100 CPDFSDK_BAAnnot* pBAAnnot = m_pAnnot.Get();
101 if (!pBAAnnot)
103
104 return CJS_Result::Success(pRuntime->NewString(
106 .AsStringView()));
107}
108
109CJS_Result CJS_Annot::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
111}
@ FXJSOBJTYPE_DYNAMIC
static uint32_t GetObjDefnID()
Definition cjs_annot.cpp:25
~CJS_Annot() override
static void DefineJSObjects(CFXJS_Engine *pEngine)
Definition cjs_annot.cpp:30
void SetSDKAnnot(CPDFSDK_BAAnnot *annot)
Definition cjs_annot.cpp:41
CJS_Annot(v8::Local< v8::Object > pObject, CJS_Runtime *pRuntime)
Definition cjs_annot.cpp:36
static void DefineProps(CFXJS_Engine *pEngine, uint32_t nObjDefnID, pdfium::span< const JSPropertySpec > consts)
static CJS_Result Success()
Definition cjs_result.h:27
static CJS_Result Failure(JSMessage id)
Definition cjs_result.h:34
WideString GetAnnotName() const
void SetAnnotName(const WideString &sName)
CPDF_Annot::Subtype GetAnnotSubtype() const override
void SetFlags(uint32_t nFlags)
uint32_t GetFlags() const
static ByteString AnnotSubtypeToString(Subtype nSubtype)
bool IsHidden() const
JSMessage
constexpr uint32_t kNoView
constexpr uint32_t kHidden
constexpr uint32_t kPrint
constexpr uint32_t kInvisible