Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(781)

Side by Side Diff: core/src/fpdfdoc/doc_annot.cpp

Issue 1648233002: Merge to XFA: Member function name refactoring (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: more xfa changes Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fpdfdoc/doc_action.cpp ('k') | core/src/fpdfdoc/doc_ap.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/include/fpdfapi/fpdf_pageobj.h" 7 #include "core/include/fpdfapi/fpdf_pageobj.h"
8 #include "core/include/fpdfdoc/fpdf_doc.h" 8 #include "core/include/fpdfdoc/fpdf_doc.h"
9 9
10 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) 10 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage)
11 : m_pDocument(pPage->m_pDocument) { 11 : m_pDocument(pPage->m_pDocument) {
12 if (!pPage->m_pFormDict) 12 if (!pPage->m_pFormDict)
13 return; 13 return;
14 14
15 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArray("Annots"); 15 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots");
16 if (!pAnnots) 16 if (!pAnnots)
17 return; 17 return;
18 18
19 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); 19 CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
20 CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm"); 20 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm");
21 FX_BOOL bRegenerateAP = pAcroForm && pAcroForm->GetBoolean("NeedAppearances"); 21 FX_BOOL bRegenerateAP =
22 pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances");
22 for (FX_DWORD i = 0; i < pAnnots->GetCount(); ++i) { 23 for (FX_DWORD i = 0; i < pAnnots->GetCount(); ++i) {
23 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetElementValue(i)); 24 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetElementValue(i));
24 if (!pDict) 25 if (!pDict)
25 continue; 26 continue;
26 27
27 FX_DWORD dwObjNum = pDict->GetObjNum(); 28 FX_DWORD dwObjNum = pDict->GetObjNum();
28 if (dwObjNum == 0) { 29 if (dwObjNum == 0) {
29 dwObjNum = m_pDocument->AddIndirectObject(pDict); 30 dwObjNum = m_pDocument->AddIndirectObject(pDict);
30 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum); 31 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum);
31 pAnnots->InsertAt(i, pAction); 32 pAnnots->InsertAt(i, pAction);
32 pAnnots->RemoveAt(i + 1); 33 pAnnots->RemoveAt(i + 1);
33 pDict = pAnnots->GetDict(i); 34 pDict = pAnnots->GetDictAt(i);
34 } 35 }
35 m_AnnotList.push_back(new CPDF_Annot(pDict, this)); 36 m_AnnotList.push_back(new CPDF_Annot(pDict, this));
36 if (bRegenerateAP && pDict->GetConstString("Subtype") == "Widget" && 37 if (bRegenerateAP && pDict->GetConstStringBy("Subtype") == "Widget" &&
37 CPDF_InterForm::UpdatingAPEnabled()) { 38 CPDF_InterForm::UpdatingAPEnabled()) {
38 FPDF_GenerateAP(m_pDocument, pDict); 39 FPDF_GenerateAP(m_pDocument, pDict);
39 } 40 }
40 } 41 }
41 } 42 }
42 43
43 CPDF_AnnotList::~CPDF_AnnotList() { 44 CPDF_AnnotList::~CPDF_AnnotList() {
44 for (CPDF_Annot* annot : m_AnnotList) 45 for (CPDF_Annot* annot : m_AnnotList)
45 delete annot; 46 delete annot;
46 } 47 }
(...skipping 18 matching lines...) Expand all
65 if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) 66 if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0)
66 continue; 67 continue;
67 68
68 if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) 69 if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW))
69 continue; 70 continue;
70 71
71 if (pOptions) { 72 if (pOptions) {
72 IPDF_OCContext* pOCContext = pOptions->m_pOCContext; 73 IPDF_OCContext* pOCContext = pOptions->m_pOCContext;
73 CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict(); 74 CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict();
74 if (pOCContext && pAnnotDict && 75 if (pOCContext && pAnnotDict &&
75 !pOCContext->CheckOCGVisible(pAnnotDict->GetDict("OC"))) { 76 !pOCContext->CheckOCGVisible(pAnnotDict->GetDictBy("OC"))) {
76 continue; 77 continue;
77 } 78 }
78 } 79 }
79 CPDF_Rect annot_rect_f; 80 CPDF_Rect annot_rect_f;
80 pAnnot->GetRect(annot_rect_f); 81 pAnnot->GetRect(annot_rect_f);
81 CFX_Matrix matrix = *pMatrix; 82 CFX_Matrix matrix = *pMatrix;
82 if (clip_rect) { 83 if (clip_rect) {
83 annot_rect_f.Transform(&matrix); 84 annot_rect_f.Transform(&matrix);
84 FX_RECT annot_rect = annot_rect_f.GetOutterRect(); 85 FX_RECT annot_rect = annot_rect_f.GetOutterRect();
85 annot_rect.Intersect(*clip_rect); 86 annot_rect.Intersect(*clip_rect);
(...skipping 24 matching lines...) Expand all
110 } 111 }
111 if (dwAnnotFlags & 0x02) { 112 if (dwAnnotFlags & 0x02) {
112 DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, TRUE, 113 DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, TRUE,
113 pOptions, pClipRect); 114 pOptions, pClipRect);
114 } 115 }
115 } 116 }
116 117
117 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_AnnotList* pList) 118 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_AnnotList* pList)
118 : m_pAnnotDict(pDict), 119 : m_pAnnotDict(pDict),
119 m_pList(pList), 120 m_pList(pList),
120 m_sSubtype(m_pAnnotDict->GetConstString("Subtype")) {} 121 m_sSubtype(m_pAnnotDict->GetConstStringBy("Subtype")) {}
121 CPDF_Annot::~CPDF_Annot() { 122 CPDF_Annot::~CPDF_Annot() {
122 ClearCachedAP(); 123 ClearCachedAP();
123 } 124 }
124 void CPDF_Annot::ClearCachedAP() { 125 void CPDF_Annot::ClearCachedAP() {
125 for (const auto& pair : m_APMap) { 126 for (const auto& pair : m_APMap) {
126 delete pair.second; 127 delete pair.second;
127 } 128 }
128 m_APMap.clear(); 129 m_APMap.clear();
129 } 130 }
130 CFX_ByteString CPDF_Annot::GetSubType() const { 131 CFX_ByteString CPDF_Annot::GetSubType() const {
131 return m_sSubtype; 132 return m_sSubtype;
132 } 133 }
133 134
134 void CPDF_Annot::GetRect(CPDF_Rect& rect) const { 135 void CPDF_Annot::GetRect(CPDF_Rect& rect) const {
135 if (!m_pAnnotDict) { 136 if (!m_pAnnotDict) {
136 return; 137 return;
137 } 138 }
138 rect = m_pAnnotDict->GetRect("Rect"); 139 rect = m_pAnnotDict->GetRectBy("Rect");
139 rect.Normalize(); 140 rect.Normalize();
140 } 141 }
141 142
142 FX_DWORD CPDF_Annot::GetFlags() const { 143 FX_DWORD CPDF_Annot::GetFlags() const {
143 return m_pAnnotDict->GetInteger("F"); 144 return m_pAnnotDict->GetIntegerBy("F");
144 } 145 }
145 146
146 CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, 147 CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict,
147 CPDF_Annot::AppearanceMode mode) { 148 CPDF_Annot::AppearanceMode mode) {
148 CPDF_Dictionary* pAP = pAnnotDict->GetDict("AP"); 149 CPDF_Dictionary* pAP = pAnnotDict->GetDictBy("AP");
149 if (!pAP) { 150 if (!pAP) {
150 return NULL; 151 return NULL;
151 } 152 }
152 const FX_CHAR* ap_entry = "N"; 153 const FX_CHAR* ap_entry = "N";
153 if (mode == CPDF_Annot::Down) 154 if (mode == CPDF_Annot::Down)
154 ap_entry = "D"; 155 ap_entry = "D";
155 else if (mode == CPDF_Annot::Rollover) 156 else if (mode == CPDF_Annot::Rollover)
156 ap_entry = "R"; 157 ap_entry = "R";
157 if (!pAP->KeyExist(ap_entry)) 158 if (!pAP->KeyExist(ap_entry))
158 ap_entry = "N"; 159 ap_entry = "N";
159 160
160 CPDF_Object* psub = pAP->GetElementValue(ap_entry); 161 CPDF_Object* psub = pAP->GetElementValue(ap_entry);
161 if (!psub) 162 if (!psub)
162 return nullptr; 163 return nullptr;
163 if (CPDF_Stream* pStream = psub->AsStream()) 164 if (CPDF_Stream* pStream = psub->AsStream())
164 return pStream; 165 return pStream;
165 166
166 if (CPDF_Dictionary* pDict = psub->AsDictionary()) { 167 if (CPDF_Dictionary* pDict = psub->AsDictionary()) {
167 CFX_ByteString as = pAnnotDict->GetString("AS"); 168 CFX_ByteString as = pAnnotDict->GetStringBy("AS");
168 if (as.IsEmpty()) { 169 if (as.IsEmpty()) {
169 CFX_ByteString value = pAnnotDict->GetString("V"); 170 CFX_ByteString value = pAnnotDict->GetStringBy("V");
170 if (value.IsEmpty()) { 171 if (value.IsEmpty()) {
171 CPDF_Dictionary* pDict = pAnnotDict->GetDict("Parent"); 172 CPDF_Dictionary* pDict = pAnnotDict->GetDictBy("Parent");
172 value = pDict ? pDict->GetString("V") : CFX_ByteString(); 173 value = pDict ? pDict->GetStringBy("V") : CFX_ByteString();
173 } 174 }
174 if (value.IsEmpty() || !pDict->KeyExist(value)) 175 if (value.IsEmpty() || !pDict->KeyExist(value))
175 as = "Off"; 176 as = "Off";
176 else 177 else
177 as = value; 178 as = value;
178 } 179 }
179 return pDict->GetStream(as); 180 return pDict->GetStreamBy(as);
180 } 181 }
181 return nullptr; 182 return nullptr;
182 } 183 }
183 184
184 CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) { 185 CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) {
185 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pAnnotDict, mode); 186 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pAnnotDict, mode);
186 if (!pStream) 187 if (!pStream)
187 return nullptr; 188 return nullptr;
188 189
189 auto it = m_APMap.find(pStream); 190 auto it = m_APMap.find(pStream);
190 if (it != m_APMap.end()) 191 if (it != m_APMap.end())
191 return it->second; 192 return it->second;
192 193
193 CPDF_Form* pNewForm = 194 CPDF_Form* pNewForm =
194 new CPDF_Form(m_pList->GetDocument(), pPage->m_pResources, pStream); 195 new CPDF_Form(m_pList->GetDocument(), pPage->m_pResources, pStream);
195 pNewForm->ParseContent(nullptr, nullptr, nullptr, nullptr); 196 pNewForm->ParseContent(nullptr, nullptr, nullptr, nullptr);
196 m_APMap[pStream] = pNewForm; 197 m_APMap[pStream] = pNewForm;
197 return pNewForm; 198 return pNewForm;
198 } 199 }
199 200
200 static CPDF_Form* FPDFDOC_Annot_GetMatrix(const CPDF_Page* pPage, 201 static CPDF_Form* FPDFDOC_Annot_GetMatrix(const CPDF_Page* pPage,
201 CPDF_Annot* pAnnot, 202 CPDF_Annot* pAnnot,
202 CPDF_Annot::AppearanceMode mode, 203 CPDF_Annot::AppearanceMode mode,
203 const CFX_Matrix* pUser2Device, 204 const CFX_Matrix* pUser2Device,
204 CFX_Matrix& matrix) { 205 CFX_Matrix& matrix) {
205 CPDF_Form* pForm = pAnnot->GetAPForm(pPage, mode); 206 CPDF_Form* pForm = pAnnot->GetAPForm(pPage, mode);
206 if (!pForm) { 207 if (!pForm) {
207 return NULL; 208 return NULL;
208 } 209 }
209 CFX_FloatRect form_bbox = pForm->m_pFormDict->GetRect("BBox"); 210 CFX_FloatRect form_bbox = pForm->m_pFormDict->GetRectBy("BBox");
210 CFX_Matrix form_matrix = pForm->m_pFormDict->GetMatrix("Matrix"); 211 CFX_Matrix form_matrix = pForm->m_pFormDict->GetMatrixBy("Matrix");
211 form_matrix.TransformRect(form_bbox); 212 form_matrix.TransformRect(form_bbox);
212 CPDF_Rect arect; 213 CPDF_Rect arect;
213 pAnnot->GetRect(arect); 214 pAnnot->GetRect(arect);
214 matrix.MatchRect(arect, form_bbox); 215 matrix.MatchRect(arect, form_bbox);
215 matrix.Concat(*pUser2Device); 216 matrix.Concat(*pUser2Device);
216 return pForm; 217 return pForm;
217 } 218 }
218 FX_BOOL CPDF_Annot::DrawAppearance(CPDF_Page* pPage, 219 FX_BOOL CPDF_Annot::DrawAppearance(CPDF_Page* pPage,
219 CFX_RenderDevice* pDevice, 220 CFX_RenderDevice* pDevice,
220 const CFX_Matrix* pUser2Device, 221 const CFX_Matrix* pUser2Device,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 return; 256 return;
256 } 257 }
257 FX_BOOL bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER || 258 FX_BOOL bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER ||
258 (pOptions && (pOptions->m_Flags & RENDER_PRINTPREVIEW)); 259 (pOptions && (pOptions->m_Flags & RENDER_PRINTPREVIEW));
259 if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) { 260 if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) {
260 return; 261 return;
261 } 262 }
262 if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) { 263 if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) {
263 return; 264 return;
264 } 265 }
265 CPDF_Dictionary* pBS = m_pAnnotDict->GetDict("BS"); 266 CPDF_Dictionary* pBS = m_pAnnotDict->GetDictBy("BS");
266 char style_char; 267 char style_char;
267 FX_FLOAT width; 268 FX_FLOAT width;
268 CPDF_Array* pDashArray = NULL; 269 CPDF_Array* pDashArray = NULL;
269 if (!pBS) { 270 if (!pBS) {
270 CPDF_Array* pBorderArray = m_pAnnotDict->GetArray("Border"); 271 CPDF_Array* pBorderArray = m_pAnnotDict->GetArrayBy("Border");
271 style_char = 'S'; 272 style_char = 'S';
272 if (pBorderArray) { 273 if (pBorderArray) {
273 width = pBorderArray->GetNumber(2); 274 width = pBorderArray->GetNumberAt(2);
274 if (pBorderArray->GetCount() == 4) { 275 if (pBorderArray->GetCount() == 4) {
275 pDashArray = pBorderArray->GetArray(3); 276 pDashArray = pBorderArray->GetArrayAt(3);
276 if (!pDashArray) { 277 if (!pDashArray) {
277 return; 278 return;
278 } 279 }
279 int nLen = pDashArray->GetCount(); 280 int nLen = pDashArray->GetCount();
280 int i = 0; 281 int i = 0;
281 for (; i < nLen; ++i) { 282 for (; i < nLen; ++i) {
282 CPDF_Object* pObj = pDashArray->GetElementValue(i); 283 CPDF_Object* pObj = pDashArray->GetElementValue(i);
283 if (pObj && pObj->GetInteger()) { 284 if (pObj && pObj->GetInteger()) {
284 break; 285 break;
285 } 286 }
286 } 287 }
287 if (i == nLen) { 288 if (i == nLen) {
288 return; 289 return;
289 } 290 }
290 style_char = 'D'; 291 style_char = 'D';
291 } 292 }
292 } else { 293 } else {
293 width = 1; 294 width = 1;
294 } 295 }
295 } else { 296 } else {
296 CFX_ByteString style = pBS->GetString("S"); 297 CFX_ByteString style = pBS->GetStringBy("S");
297 pDashArray = pBS->GetArray("D"); 298 pDashArray = pBS->GetArrayBy("D");
298 style_char = style[1]; 299 style_char = style[1];
299 width = pBS->GetNumber("W"); 300 width = pBS->GetNumberBy("W");
300 } 301 }
301 if (width <= 0) { 302 if (width <= 0) {
302 return; 303 return;
303 } 304 }
304 CPDF_Array* pColor = m_pAnnotDict->GetArray("C"); 305 CPDF_Array* pColor = m_pAnnotDict->GetArrayBy("C");
305 FX_DWORD argb = 0xff000000; 306 FX_DWORD argb = 0xff000000;
306 if (pColor) { 307 if (pColor) {
307 int R = (int32_t)(pColor->GetNumber(0) * 255); 308 int R = (int32_t)(pColor->GetNumberAt(0) * 255);
308 int G = (int32_t)(pColor->GetNumber(1) * 255); 309 int G = (int32_t)(pColor->GetNumberAt(1) * 255);
309 int B = (int32_t)(pColor->GetNumber(2) * 255); 310 int B = (int32_t)(pColor->GetNumberAt(2) * 255);
310 argb = ArgbEncode(0xff, R, G, B); 311 argb = ArgbEncode(0xff, R, G, B);
311 } 312 }
312 CPDF_GraphStateData graph_state; 313 CPDF_GraphStateData graph_state;
313 graph_state.m_LineWidth = width; 314 graph_state.m_LineWidth = width;
314 if (style_char == 'D') { 315 if (style_char == 'D') {
315 if (pDashArray) { 316 if (pDashArray) {
316 FX_DWORD dash_count = pDashArray->GetCount(); 317 FX_DWORD dash_count = pDashArray->GetCount();
317 if (dash_count % 2) { 318 if (dash_count % 2) {
318 dash_count++; 319 dash_count++;
319 } 320 }
320 graph_state.m_DashArray = FX_Alloc(FX_FLOAT, dash_count); 321 graph_state.m_DashArray = FX_Alloc(FX_FLOAT, dash_count);
321 graph_state.m_DashCount = dash_count; 322 graph_state.m_DashCount = dash_count;
322 FX_DWORD i; 323 FX_DWORD i;
323 for (i = 0; i < pDashArray->GetCount(); ++i) { 324 for (i = 0; i < pDashArray->GetCount(); ++i) {
324 graph_state.m_DashArray[i] = pDashArray->GetNumber(i); 325 graph_state.m_DashArray[i] = pDashArray->GetNumberAt(i);
325 } 326 }
326 if (i < dash_count) { 327 if (i < dash_count) {
327 graph_state.m_DashArray[i] = graph_state.m_DashArray[i - 1]; 328 graph_state.m_DashArray[i] = graph_state.m_DashArray[i - 1];
328 } 329 }
329 } else { 330 } else {
330 graph_state.m_DashArray = FX_Alloc(FX_FLOAT, 2); 331 graph_state.m_DashArray = FX_Alloc(FX_FLOAT, 2);
331 graph_state.m_DashCount = 2; 332 graph_state.m_DashCount = 2;
332 graph_state.m_DashArray[0] = graph_state.m_DashArray[1] = 3 * 1.0f; 333 graph_state.m_DashArray[0] = graph_state.m_DashArray[1] = 3 * 1.0f;
333 } 334 }
334 } 335 }
335 CFX_FloatRect rect; 336 CFX_FloatRect rect;
336 GetRect(rect); 337 GetRect(rect);
337 CPDF_PathData path; 338 CPDF_PathData path;
338 width /= 2; 339 width /= 2;
339 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, 340 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width,
340 rect.top - width); 341 rect.top - width);
341 int fill_type = 0; 342 int fill_type = 0;
342 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { 343 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) {
343 fill_type |= FXFILL_NOPATHSMOOTH; 344 fill_type |= FXFILL_NOPATHSMOOTH;
344 } 345 }
345 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); 346 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type);
346 } 347 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_action.cpp ('k') | core/src/fpdfdoc/doc_ap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698