blob: dbb2cb23f200e9416a3fe95d2ddb1cf471d0d0fa (
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
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
115
116
117
|
// 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 "fpdfsdk/javascript/Annot.h"
#include "fpdfsdk/javascript/JS_Define.h"
#include "fpdfsdk/javascript/JS_Object.h"
#include "fpdfsdk/javascript/JS_Value.h"
#include "fpdfsdk/javascript/cjs_event_context.h"
namespace {
CPDFSDK_BAAnnot* ToBAAnnot(CPDFSDK_Annot* annot) {
return static_cast<CPDFSDK_BAAnnot*>(annot);
}
} // namespace
BEGIN_JS_STATIC_CONST(CJS_Annot)
END_JS_STATIC_CONST()
BEGIN_JS_STATIC_PROP(CJS_Annot)
JS_STATIC_PROP_ENTRY(hidden)
JS_STATIC_PROP_ENTRY(name)
JS_STATIC_PROP_ENTRY(type)
END_JS_STATIC_PROP()
BEGIN_JS_STATIC_METHOD(CJS_Annot)
END_JS_STATIC_METHOD()
IMPLEMENT_JS_CLASS(CJS_Annot, Annot)
Annot::Annot(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {}
Annot::~Annot() {}
bool Annot::hidden(CJS_Runtime* pRuntime,
CJS_PropValue& vp,
CFX_WideString& sError) {
if (vp.IsGetting()) {
if (!m_pAnnot) {
sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
return false;
}
CPDF_Annot* pPDFAnnot = ToBAAnnot(m_pAnnot.Get())->GetPDFAnnot();
vp << CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict());
return true;
}
bool bHidden;
vp >> bHidden; // May invalidate m_pAnnot.
if (!m_pAnnot) {
sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
return false;
}
uint32_t flags = ToBAAnnot(m_pAnnot.Get())->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;
}
ToBAAnnot(m_pAnnot.Get())->SetFlags(flags);
return true;
}
bool Annot::name(CJS_Runtime* pRuntime,
CJS_PropValue& vp,
CFX_WideString& sError) {
if (vp.IsGetting()) {
if (!m_pAnnot) {
sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
return false;
}
vp << ToBAAnnot(m_pAnnot.Get())->GetAnnotName();
return true;
}
CFX_WideString annotName;
vp >> annotName; // May invalidate m_pAnnot.
if (!m_pAnnot) {
sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
return false;
}
ToBAAnnot(m_pAnnot.Get())->SetAnnotName(annotName);
return true;
}
bool Annot::type(CJS_Runtime* pRuntime,
CJS_PropValue& vp,
CFX_WideString& sError) {
if (vp.IsSetting()) {
sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
return false;
}
if (!m_pAnnot) {
sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
return false;
}
vp << CPDF_Annot::AnnotSubtypeToString(
ToBAAnnot(m_pAnnot.Get())->GetAnnotSubtype());
return true;
}
void Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) {
m_pAnnot.Reset(annot);
}
|