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

Side by Side Diff: xfa/fde/css/fde_csssyntax.cpp

Issue 2559763002: Refcount IFGAS_ streams all the time, too (Closed)
Patch Set: more Created 4 years 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 | « xfa/fde/css/fde_csssyntax.h ('k') | xfa/fde/xml/fde_xml_imp.h » ('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 "xfa/fde/css/fde_csssyntax.h" 7 #include "xfa/fde/css/fde_csssyntax.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 17 matching lines...) Expand all
28 m_dwCheck((uint32_t)-1), 28 m_dwCheck((uint32_t)-1),
29 m_eMode(FDE_CSSSYNTAXMODE_RuleSet), 29 m_eMode(FDE_CSSSYNTAXMODE_RuleSet),
30 m_eStatus(FDE_CSSSYNTAXSTATUS_None), 30 m_eStatus(FDE_CSSSYNTAXSTATUS_None),
31 m_ModeStack(100) {} 31 m_ModeStack(100) {}
32 32
33 CFDE_CSSSyntaxParser::~CFDE_CSSSyntaxParser() { 33 CFDE_CSSSyntaxParser::~CFDE_CSSSyntaxParser() {
34 m_TextData.Reset(); 34 m_TextData.Reset();
35 m_TextPlane.Reset(); 35 m_TextPlane.Reset();
36 } 36 }
37 37
38 bool CFDE_CSSSyntaxParser::Init(IFGAS_Stream* pStream, 38 bool CFDE_CSSSyntaxParser::Init(const CFX_RetainPtr<IFGAS_Stream>& pStream,
39 int32_t iCSSPlaneSize, 39 int32_t iCSSPlaneSize,
40 int32_t iTextDataSize, 40 int32_t iTextDataSize,
41 bool bOnlyDeclaration) { 41 bool bOnlyDeclaration) {
42 ASSERT(pStream && iCSSPlaneSize > 0 && iTextDataSize > 0); 42 ASSERT(pStream && iCSSPlaneSize > 0 && iTextDataSize > 0);
43 Reset(bOnlyDeclaration); 43 Reset(bOnlyDeclaration);
44 if (!m_TextData.EstimateSize(iTextDataSize)) { 44 if (!m_TextData.EstimateSize(iTextDataSize)) {
45 return false; 45 return false;
46 } 46 }
47 uint8_t bom[4]; 47 uint8_t bom[4];
48 m_pStream = pStream; 48 m_pStream = pStream;
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 m_pBuffer = const_cast<FX_WCHAR*>(pBuffer); 426 m_pBuffer = const_cast<FX_WCHAR*>(pBuffer);
427 m_iDatLen = m_iBufLen = iBufLen; 427 m_iDatLen = m_iBufLen = iBufLen;
428 return m_bExtBuf = true; 428 return m_bExtBuf = true;
429 } 429 }
430 bool CFDE_CSSTextBuf::EstimateSize(int32_t iAllocSize) { 430 bool CFDE_CSSTextBuf::EstimateSize(int32_t iAllocSize) {
431 ASSERT(iAllocSize > 0); 431 ASSERT(iAllocSize > 0);
432 Clear(); 432 Clear();
433 m_bExtBuf = false; 433 m_bExtBuf = false;
434 return ExpandBuf(iAllocSize); 434 return ExpandBuf(iAllocSize);
435 } 435 }
436 int32_t CFDE_CSSTextBuf::LoadFromStream(IFGAS_Stream* pTxtStream, 436
437 int32_t iStreamOffset, 437 int32_t CFDE_CSSTextBuf::LoadFromStream(
438 int32_t iMaxChars, 438 const CFX_RetainPtr<IFGAS_Stream>& pTxtStream,
439 bool& bEOS) { 439 int32_t iStreamOffset,
440 int32_t iMaxChars,
441 bool& bEOS) {
440 ASSERT(iStreamOffset >= 0 && iMaxChars > 0); 442 ASSERT(iStreamOffset >= 0 && iMaxChars > 0);
441 Clear(); 443 Clear();
442 m_bExtBuf = false; 444 m_bExtBuf = false;
443 if (!ExpandBuf(iMaxChars)) { 445 if (!ExpandBuf(iMaxChars))
444 return 0; 446 return 0;
445 } 447
446 if (pTxtStream->GetPosition() != iStreamOffset) { 448 if (pTxtStream->GetPosition() != iStreamOffset)
447 pTxtStream->Seek(FX_STREAMSEEK_Begin, iStreamOffset); 449 pTxtStream->Seek(FX_STREAMSEEK_Begin, iStreamOffset);
448 } 450
449 m_iDatLen = pTxtStream->ReadString(m_pBuffer, iMaxChars, bEOS); 451 m_iDatLen = pTxtStream->ReadString(m_pBuffer, iMaxChars, bEOS);
450 return m_iDatLen; 452 return m_iDatLen;
451 } 453 }
454
452 bool CFDE_CSSTextBuf::ExpandBuf(int32_t iDesiredSize) { 455 bool CFDE_CSSTextBuf::ExpandBuf(int32_t iDesiredSize) {
453 if (m_bExtBuf) { 456 if (m_bExtBuf) {
454 return false; 457 return false;
455 } 458 }
456 if (!m_pBuffer) { 459 if (!m_pBuffer) {
457 m_pBuffer = FX_Alloc(FX_WCHAR, iDesiredSize); 460 m_pBuffer = FX_Alloc(FX_WCHAR, iDesiredSize);
458 } else if (m_iBufLen != iDesiredSize) { 461 } else if (m_iBufLen != iDesiredSize) {
459 m_pBuffer = FX_Realloc(FX_WCHAR, m_pBuffer, iDesiredSize); 462 m_pBuffer = FX_Realloc(FX_WCHAR, m_pBuffer, iDesiredSize);
460 } else { 463 } else {
461 return true; 464 return true;
462 } 465 }
463 if (!m_pBuffer) { 466 if (!m_pBuffer) {
464 m_iBufLen = 0; 467 m_iBufLen = 0;
465 return false; 468 return false;
466 } 469 }
467 m_iBufLen = iDesiredSize; 470 m_iBufLen = iDesiredSize;
468 return true; 471 return true;
469 } 472 }
470 473
471 void CFDE_CSSTextBuf::Subtract(int32_t iStart, int32_t iLength) { 474 void CFDE_CSSTextBuf::Subtract(int32_t iStart, int32_t iLength) {
472 ASSERT(iStart >= 0 && iLength >= 0); 475 ASSERT(iStart >= 0 && iLength >= 0);
473 iLength = std::max(std::min(iLength, m_iDatLen - iStart), 0); 476 iLength = std::max(std::min(iLength, m_iDatLen - iStart), 0);
474 FXSYS_memmove(m_pBuffer, m_pBuffer + iStart, iLength * sizeof(FX_WCHAR)); 477 FXSYS_memmove(m_pBuffer, m_pBuffer + iStart, iLength * sizeof(FX_WCHAR));
475 m_iDatLen = iLength; 478 m_iDatLen = iLength;
476 } 479 }
OLDNEW
« no previous file with comments | « xfa/fde/css/fde_csssyntax.h ('k') | xfa/fde/xml/fde_xml_imp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698