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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
// 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 "fxjs/cjs_annot.h"
#include "fpdfsdk/cpdfsdk_baannot.h"
#include "fxjs/cjs_event_context.h"
#include "fxjs/cjs_object.h"
#include "fxjs/js_define.h"
#include "fxjs/js_resources.h"
const JSPropertySpec CJS_Annot::PropertySpecs[] = {
{"hidden", get_hidden_static, set_hidden_static},
{"name", get_name_static, set_name_static},
{"type", get_type_static, set_type_static}};
int CJS_Annot::ObjDefnID = -1;
const char CJS_Annot::kName[] = "Annot";
// static
int CJS_Annot::GetObjDefnID() {
return ObjDefnID;
}
// static
void CJS_Annot::DefineJSObjects(CFXJS_Engine* pEngine) {
ObjDefnID = pEngine->DefineObj(CJS_Annot::kName, FXJSOBJTYPE_DYNAMIC,
JSConstructor<CJS_Annot>, JSDestructor);
DefineProps(pEngine, ObjDefnID, PropertySpecs);
}
CJS_Annot::CJS_Annot(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
: CJS_Object(pObject, pRuntime) {}
CJS_Annot::~CJS_Annot() = default;
void CJS_Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) {
m_pAnnot.Reset(annot);
}
CJS_Result CJS_Annot::get_hidden(CJS_Runtime* pRuntime) {
if (!m_pAnnot)
return CJS_Result::Failure(JSMessage::kBadObjectError);
CPDF_Annot* pPDFAnnot = m_pAnnot->AsBAAnnot()->GetPDFAnnot();
return CJS_Result::Success(pRuntime->NewBoolean(
CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict())));
}
CJS_Result CJS_Annot::set_hidden(CJS_Runtime* pRuntime,
v8::Local<v8::Value> vp) {
// May invalidate m_pAnnot.
bool bHidden = pRuntime->ToBoolean(vp);
CPDFSDK_BAAnnot* pBAAnnot = ToBAAnnot(m_pAnnot.Get());
if (!pBAAnnot)
return CJS_Result::Failure(JSMessage::kBadObjectError);
uint32_t flags = pBAAnnot->GetFlags();
if (bHidden) {
flags |= ANNOTFLAG_HIDDEN;
flags |= ANNOTFLAG_INVISIBLE;
flags |= ANNOTFLAG_NOVIEW;
flags &= ~ANNOTFLAG_PRINT;
} else {
flags &= ~ANNOTFLAG_HIDDEN;
flags &= ~ANNOTFLAG_INVISIBLE;
flags &= ~ANNOTFLAG_NOVIEW;
flags |= ANNOTFLAG_PRINT;
}
pBAAnnot->SetFlags(flags);
return CJS_Result::Success();
}
CJS_Result CJS_Annot::get_name(CJS_Runtime* pRuntime) {
CPDFSDK_BAAnnot* pBAAnnot = ToBAAnnot(m_pAnnot.Get());
if (!pBAAnnot)
return CJS_Result::Failure(JSMessage::kBadObjectError);
return CJS_Result::Success(
pRuntime->NewString(pBAAnnot->GetAnnotName().AsStringView()));
}
CJS_Result CJS_Annot::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
// May invalidate m_pAnnot.
WideString annotName = pRuntime->ToWideString(vp);
CPDFSDK_BAAnnot* pBAAnnot = ToBAAnnot(m_pAnnot.Get());
if (!pBAAnnot)
return CJS_Result::Failure(JSMessage::kBadObjectError);
pBAAnnot->SetAnnotName(annotName);
return CJS_Result::Success();
}
CJS_Result CJS_Annot::get_type(CJS_Runtime* pRuntime) {
CPDFSDK_BAAnnot* pBAAnnot = ToBAAnnot(m_pAnnot.Get());
if (!pBAAnnot)
return CJS_Result::Failure(JSMessage::kBadObjectError);
return CJS_Result::Success(pRuntime->NewString(
WideString::FromLocal(
CPDF_Annot::AnnotSubtypeToString(pBAAnnot->GetAnnotSubtype())
.AsStringView())
.AsStringView()));
}
CJS_Result CJS_Annot::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
return CJS_Result::Failure(JSMessage::kReadOnlyError);
}
|