OLD | NEW |
---|---|
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/fpdfdoc/fpdf_ap.h" | 7 #include "core/include/fpdfdoc/fpdf_ap.h" |
8 #include "core/include/fpdfdoc/fpdf_doc.h" | 8 #include "core/include/fpdfdoc/fpdf_doc.h" |
9 #include "core/include/fpdfdoc/fpdf_vt.h" | 9 #include "core/include/fpdfdoc/fpdf_vt.h" |
10 #include "doc_utils.h" | 10 #include "doc_utils.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 CFX_ByteString sFontName = syntax.GetWord(); | 285 CFX_ByteString sFontName = syntax.GetWord(); |
286 sFontName = PDF_NameDecode(sFontName); | 286 sFontName = PDF_NameDecode(sFontName); |
287 if (sFontName.IsEmpty()) { | 287 if (sFontName.IsEmpty()) { |
288 return FALSE; | 288 return FALSE; |
289 } | 289 } |
290 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); | 290 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); |
291 CPVT_Color crText = ParseColor(DA); | 291 CPVT_Color crText = ParseColor(DA); |
292 FX_BOOL bUseFormRes = FALSE; | 292 FX_BOOL bUseFormRes = FALSE; |
293 CPDF_Dictionary* pFontDict = NULL; | 293 CPDF_Dictionary* pFontDict = NULL; |
294 CPDF_Dictionary* pDRDict = pAnnotDict->GetDict("DR"); | 294 CPDF_Dictionary* pDRDict = pAnnotDict->GetDict("DR"); |
295 if (pDRDict == NULL) { | 295 if (!pDRDict) { |
296 pDRDict = pFormDict->GetDict("DR"); | 296 pDRDict = pFormDict->GetDict("DR"); |
297 bUseFormRes = TRUE; | 297 bUseFormRes = TRUE; |
298 } | 298 } |
299 CPDF_Dictionary* pDRFontDict = NULL; | 299 CPDF_Dictionary* pDRFontDict = NULL; |
300 if (pDRDict && (pDRFontDict = pDRDict->GetDict("Font"))) { | 300 if (pDRDict && (pDRFontDict = pDRDict->GetDict("Font"))) { |
301 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); | 301 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); |
302 if (!pFontDict && !bUseFormRes) { | 302 if (!pFontDict && !bUseFormRes) { |
303 pDRDict = pFormDict->GetDict("DR"); | 303 pDRDict = pFormDict->GetDict("DR"); |
304 pDRFontDict = pDRDict->GetDict("Font"); | 304 pDRFontDict = pDRDict->GetDict("Font"); |
305 if (pDRFontDict) { | 305 if (pDRFontDict) { |
306 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); | 306 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); |
307 } | 307 } |
308 } | 308 } |
309 } | 309 } |
310 if (!pDRFontDict) { | 310 if (!pDRFontDict) { |
311 return FALSE; | 311 return FALSE; |
312 } | 312 } |
313 if (!pFontDict) { | 313 if (!pFontDict) { |
314 pFontDict = CPDF_Dictionary::Create(); | 314 pFontDict = CPDF_Dictionary::Create(); |
315 if (pFontDict == NULL) { | 315 if (!pFontDict) { |
316 return FALSE; | 316 return FALSE; |
317 } | 317 } |
318 pFontDict->SetAtName("Type", "Font"); | 318 pFontDict->SetAtName("Type", "Font"); |
319 pFontDict->SetAtName("Subtype", "Type1"); | 319 pFontDict->SetAtName("Subtype", "Type1"); |
320 pFontDict->SetAtName("BaseFont", "Helvetica"); | 320 pFontDict->SetAtName("BaseFont", "Helvetica"); |
321 pFontDict->SetAtName("Encoding", "WinAnsiEncoding"); | 321 pFontDict->SetAtName("Encoding", "WinAnsiEncoding"); |
322 pDoc->AddIndirectObject(pFontDict); | 322 pDoc->AddIndirectObject(pFontDict); |
323 pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict); | 323 pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict); |
324 } | 324 } |
325 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); | 325 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 rcBBox, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, | 411 rcBBox, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, |
412 dsBorder); | 412 dsBorder); |
413 if (sBorderStream.GetLength() > 0) { | 413 if (sBorderStream.GetLength() > 0) { |
414 sAppStream << "q\n" << sBorderStream << "Q\n"; | 414 sAppStream << "q\n" << sBorderStream << "Q\n"; |
415 } | 415 } |
416 CPDF_Rect rcBody = | 416 CPDF_Rect rcBody = |
417 CPDF_Rect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth, | 417 CPDF_Rect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth, |
418 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth); | 418 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth); |
419 rcBody.Normalize(); | 419 rcBody.Normalize(); |
420 CPDF_Dictionary* pAPDict = pAnnotDict->GetDict("AP"); | 420 CPDF_Dictionary* pAPDict = pAnnotDict->GetDict("AP"); |
421 if (pAPDict == NULL) { | 421 if (!pAPDict) { |
422 pAPDict = CPDF_Dictionary::Create(); | 422 pAPDict = CPDF_Dictionary::Create(); |
423 if (pAPDict == NULL) { | 423 if (!pAPDict) { |
Tom Sepez
2015/12/14 18:27:00
nit: can this fail? I though I fixed these. hmmm.
Lei Zhang
2015/12/15 01:58:35
I thought I fixed these too.
| |
424 return FALSE; | 424 return FALSE; |
425 } | 425 } |
426 pAnnotDict->SetAt("AP", pAPDict); | 426 pAnnotDict->SetAt("AP", pAPDict); |
427 } | 427 } |
428 CPDF_Stream* pNormalStream = pAPDict->GetStream("N"); | 428 CPDF_Stream* pNormalStream = pAPDict->GetStream("N"); |
429 if (!pNormalStream) { | 429 if (!pNormalStream) { |
430 pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); | 430 pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); |
431 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); | 431 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); |
432 pAnnotDict->GetDict("AP")->SetAtReference("N", pDoc, objnum); | 432 pAnnotDict->GetDict("AP")->SetAtReference("N", pDoc, objnum); |
433 } | 433 } |
434 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); | 434 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
435 if (pStreamDict) { | 435 if (pStreamDict) { |
436 pStreamDict->SetAtMatrix("Matrix", matrix); | 436 pStreamDict->SetAtMatrix("Matrix", matrix); |
437 pStreamDict->SetAtRect("BBox", rcBBox); | 437 pStreamDict->SetAtRect("BBox", rcBBox); |
438 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); | 438 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); |
439 if (pStreamResList) { | 439 if (pStreamResList) { |
440 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"); | 440 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"); |
441 if (!pStreamResFontList) { | 441 if (!pStreamResFontList) { |
442 pStreamResFontList = CPDF_Dictionary::Create(); | 442 pStreamResFontList = CPDF_Dictionary::Create(); |
443 if (pStreamResFontList == NULL) { | 443 if (!pStreamResFontList) { |
444 return FALSE; | 444 return FALSE; |
445 } | 445 } |
446 pStreamResList->SetAt("Font", pStreamResFontList); | 446 pStreamResList->SetAt("Font", pStreamResFontList); |
447 } | 447 } |
448 if (!pStreamResFontList->KeyExist(sFontName)) { | 448 if (!pStreamResFontList->KeyExist(sFontName)) { |
449 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); | 449 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); |
450 } | 450 } |
451 } else { | 451 } else { |
452 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone()); | 452 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone()); |
453 pStreamResList = pStreamDict->GetDict("Resources"); | 453 pStreamResList = pStreamDict->GetDict("Resources"); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 sAppStream.GetSize(), FALSE, FALSE); | 681 sAppStream.GetSize(), FALSE, FALSE); |
682 pStreamDict = pNormalStream->GetDict(); | 682 pStreamDict = pNormalStream->GetDict(); |
683 if (pStreamDict) { | 683 if (pStreamDict) { |
684 pStreamDict->SetAtMatrix("Matrix", matrix); | 684 pStreamDict->SetAtMatrix("Matrix", matrix); |
685 pStreamDict->SetAtRect("BBox", rcBBox); | 685 pStreamDict->SetAtRect("BBox", rcBBox); |
686 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); | 686 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); |
687 if (pStreamResList) { | 687 if (pStreamResList) { |
688 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"); | 688 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"); |
689 if (!pStreamResFontList) { | 689 if (!pStreamResFontList) { |
690 pStreamResFontList = CPDF_Dictionary::Create(); | 690 pStreamResFontList = CPDF_Dictionary::Create(); |
691 if (pStreamResFontList == NULL) { | 691 if (!pStreamResFontList) { |
692 return FALSE; | 692 return FALSE; |
693 } | 693 } |
694 pStreamResList->SetAt("Font", pStreamResFontList); | 694 pStreamResList->SetAt("Font", pStreamResFontList); |
695 } | 695 } |
696 if (!pStreamResFontList->KeyExist(sFontName)) { | 696 if (!pStreamResFontList->KeyExist(sFontName)) { |
697 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); | 697 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); |
698 } | 698 } |
699 } else { | 699 } else { |
700 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone()); | 700 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone()); |
701 pStreamResList = pStreamDict->GetDict("Resources"); | 701 pStreamResList = pStreamDict->GetDict("Resources"); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
925 << "\n"; | 925 << "\n"; |
926 break; | 926 break; |
927 case CT_CMYK: | 927 case CT_CMYK: |
928 sColorStream << color.fColor1 << " " << color.fColor2 << " " | 928 sColorStream << color.fColor1 << " " << color.fColor2 << " " |
929 << color.fColor3 << " " << color.fColor4 << " " | 929 << color.fColor3 << " " << color.fColor4 << " " |
930 << (bFillOrStroke ? "k" : "K") << "\n"; | 930 << (bFillOrStroke ? "k" : "K") << "\n"; |
931 break; | 931 break; |
932 } | 932 } |
933 return sColorStream.GetByteString(); | 933 return sColorStream.GetByteString(); |
934 } | 934 } |
OLD | NEW |