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

Side by Side Diff: core/fpdfdoc/cpvt_generateap.cpp

Issue 2347993002: Clean up CPDF_Stream. (Closed)
Patch Set: ctor Created 4 years, 3 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
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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/fpdfdoc/cpvt_generateap.h" 7 #include "core/fpdfdoc/cpvt_generateap.h"
8 8
9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 CFX_FloatRect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth, 159 CFX_FloatRect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth,
160 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth); 160 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth);
161 rcBody.Normalize(); 161 rcBody.Normalize();
162 CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP"); 162 CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP");
163 if (!pAPDict) { 163 if (!pAPDict) {
164 pAPDict = new CPDF_Dictionary; 164 pAPDict = new CPDF_Dictionary;
165 pAnnotDict->SetFor("AP", pAPDict); 165 pAnnotDict->SetFor("AP", pAPDict);
166 } 166 }
167 CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N"); 167 CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N");
168 if (!pNormalStream) { 168 if (!pNormalStream) {
169 pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); 169 pNormalStream = new CPDF_Stream;
170 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); 170 int32_t objnum = pDoc->AddIndirectObject(pNormalStream);
171 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum); 171 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum);
172 } 172 }
173 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); 173 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
174 if (pStreamDict) { 174 if (pStreamDict) {
175 pStreamDict->SetMatrixFor("Matrix", matrix); 175 pStreamDict->SetMatrixFor("Matrix", matrix);
176 pStreamDict->SetRectFor("BBox", rcBBox); 176 pStreamDict->SetRectFor("BBox", rcBBox);
177 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); 177 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
178 if (pStreamResList) { 178 if (pStreamResList) {
179 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); 179 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font");
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 411 }
412 if (sBody.GetSize() > 0) { 412 if (sBody.GetSize() > 0) {
413 sAppStream << "/Tx BMC\nq\n" 413 sAppStream << "/Tx BMC\nq\n"
414 << rcBody.left << " " << rcBody.bottom << " " 414 << rcBody.left << " " << rcBody.bottom << " "
415 << rcBody.Width() << " " << rcBody.Height() << " re\nW\nn\n" 415 << rcBody.Width() << " " << rcBody.Height() << " re\nW\nn\n"
416 << sBody.AsStringC() << "Q\nEMC\n"; 416 << sBody.AsStringC() << "Q\nEMC\n";
417 } 417 }
418 } break; 418 } break;
419 } 419 }
420 if (pNormalStream) { 420 if (pNormalStream) {
421 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE, 421 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize());
422 FALSE);
423 pStreamDict = pNormalStream->GetDict(); 422 pStreamDict = pNormalStream->GetDict();
424 if (pStreamDict) { 423 if (pStreamDict) {
425 pStreamDict->SetMatrixFor("Matrix", matrix); 424 pStreamDict->SetMatrixFor("Matrix", matrix);
426 pStreamDict->SetRectFor("BBox", rcBBox); 425 pStreamDict->SetRectFor("BBox", rcBBox);
427 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); 426 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
428 if (pStreamResList) { 427 if (pStreamResList) {
429 CPDF_Dictionary* pStreamResFontList = 428 CPDF_Dictionary* pStreamResFontList =
430 pStreamResList->GetDictFor("Font"); 429 pStreamResList->GetDictFor("Font");
431 if (!pStreamResFontList) { 430 if (!pStreamResFontList) {
432 pStreamResFontList = new CPDF_Dictionary; 431 pStreamResFontList = new CPDF_Dictionary;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 583
585 // Takes ownership of |pResourceDict|. 584 // Takes ownership of |pResourceDict|.
586 void GenerateAndSetAPDict(CPDF_Document* pDoc, 585 void GenerateAndSetAPDict(CPDF_Document* pDoc,
587 CPDF_Dictionary* pAnnotDict, 586 CPDF_Dictionary* pAnnotDict,
588 const CFX_ByteTextBuf& sAppStream, 587 const CFX_ByteTextBuf& sAppStream,
589 CPDF_Dictionary* pResourceDict, 588 CPDF_Dictionary* pResourceDict,
590 bool bIsTextMarkupAnnotation) { 589 bool bIsTextMarkupAnnotation) {
591 CPDF_Dictionary* pAPDict = new CPDF_Dictionary; 590 CPDF_Dictionary* pAPDict = new CPDF_Dictionary;
592 pAnnotDict->SetFor("AP", pAPDict); 591 pAnnotDict->SetFor("AP", pAPDict);
593 592
594 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); 593 CPDF_Stream* pNormalStream = new CPDF_Stream;
595 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); 594 int32_t objnum = pDoc->AddIndirectObject(pNormalStream);
596 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum); 595 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum);
597 596 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize());
598 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE,
599 FALSE);
600 597
601 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); 598 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
602 pStreamDict->SetIntegerFor("FormType", 1); 599 pStreamDict->SetIntegerFor("FormType", 1);
603 pStreamDict->SetStringFor("Subtype", "Form"); 600 pStreamDict->SetStringFor("Subtype", "Form");
604 pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); 601 pStreamDict->SetMatrixFor("Matrix", CFX_Matrix());
605 602
606 CFX_FloatRect rect = bIsTextMarkupAnnotation 603 CFX_FloatRect rect = bIsTextMarkupAnnotation
607 ? CPDF_Annot::RectFromQuadPoints(pAnnotDict) 604 ? CPDF_Annot::RectFromQuadPoints(pAnnotDict)
608 : pAnnotDict->GetRectFor("Rect"); 605 : pAnnotDict->GetRectFor("Rect");
609 pStreamDict->SetRectFor("BBox", rect); 606 pStreamDict->SetRectFor("BBox", rect);
610
611 pStreamDict->SetFor("Resources", pResourceDict); 607 pStreamDict->SetFor("Resources", pResourceDict);
612 } 608 }
613 609
614 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { 610 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) {
615 if (bIsStrokeRect) 611 if (bIsStrokeRect)
616 return bIsFillRect ? "b" : "s"; 612 return bIsFillRect ? "b" : "s";
617 return bIsFillRect ? "f" : "n"; 613 return bIsFillRect ? "f" : "n";
618 } 614 }
619 615
620 CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) { 616 CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) {
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 int32_t nFontIndex, 1342 int32_t nFontIndex,
1347 FX_FLOAT fFontSize) { 1343 FX_FLOAT fFontSize) {
1348 CFX_ByteTextBuf sRet; 1344 CFX_ByteTextBuf sRet;
1349 if (pFontMap) { 1345 if (pFontMap) {
1350 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); 1346 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
1351 if (sFontAlias.GetLength() > 0 && fFontSize > 0) 1347 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
1352 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 1348 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
1353 } 1349 }
1354 return sRet.MakeString(); 1350 return sRet.MakeString();
1355 } 1351 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698