From 821d59e1d66b67af970c59b7681828b1b82858b6 Mon Sep 17 00:00:00 2001 From: thestig Date: Wed, 11 May 2016 12:59:22 -0700 Subject: CPDF_VariableText::GetIterator() never returns NULL. Same goes for CFX_Edit::GetIterator(). Review-Url: https://codereview.chromium.org/1967963002 --- core/fpdfdoc/cpvt_generateap.cpp | 119 +++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 61 deletions(-) (limited to 'core/fpdfdoc/cpvt_generateap.cpp') diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index 5ec9513e84..7fcd90969e 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -507,76 +507,73 @@ CFX_ByteString CPVT_GenerateAP::GenerateEditAP( CFX_ByteTextBuf sEditStream, sLineStream, sWords; CFX_FloatPoint ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f); int32_t nCurFontIndex = -1; - if (pIterator) { - pIterator->SetAt(0); - - CPVT_WordPlace oldplace; - while (pIterator->NextWord()) { - CPVT_WordPlace place = pIterator->GetAt(); - if (bContinuous) { - if (place.LineCmp(oldplace) != 0) { - if (sWords.GetSize() > 0) { - sLineStream << GetWordRenderString(sWords.AsStringC()); - sEditStream << sLineStream; - sLineStream.Clear(); - sWords.Clear(); - } - CPVT_Word word; - if (pIterator->GetWord(word)) { - ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, - word.ptWord.y + ptOffset.y); - } else { - CPVT_Line line; - pIterator->GetLine(line); - ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x, - line.ptLine.y + ptOffset.y); - } - if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { - sLineStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y - << " Td\n"; - ptOld = ptNew; - } + pIterator->SetAt(0); + + CPVT_WordPlace oldplace; + while (pIterator->NextWord()) { + CPVT_WordPlace place = pIterator->GetAt(); + if (bContinuous) { + if (place.LineCmp(oldplace) != 0) { + if (sWords.GetSize() > 0) { + sLineStream << GetWordRenderString(sWords.AsStringC()); + sEditStream << sLineStream; + sLineStream.Clear(); + sWords.Clear(); } - CPVT_Word word; - if (pIterator->GetWord(word)) { - if (word.nFontIndex != nCurFontIndex) { - if (sWords.GetSize() > 0) { - sLineStream << GetWordRenderString(sWords.AsStringC()); - sWords.Clear(); - } - sLineStream << GetFontSetString(pFontMap, word.nFontIndex, - word.fFontSize); - nCurFontIndex = word.nFontIndex; - } - sWords << GetPDFWordString(pFontMap, nCurFontIndex, word.Word, - SubWord); - } - oldplace = place; - } else { CPVT_Word word; if (pIterator->GetWord(word)) { ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, word.ptWord.y + ptOffset.y); - if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { - sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y - << " Td\n"; - ptOld = ptNew; - } - if (word.nFontIndex != nCurFontIndex) { - sEditStream << GetFontSetString(pFontMap, word.nFontIndex, - word.fFontSize); - nCurFontIndex = word.nFontIndex; + } else { + CPVT_Line line; + pIterator->GetLine(line); + ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x, + line.ptLine.y + ptOffset.y); + } + if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { + sLineStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y + << " Td\n"; + ptOld = ptNew; + } + } + CPVT_Word word; + if (pIterator->GetWord(word)) { + if (word.nFontIndex != nCurFontIndex) { + if (sWords.GetSize() > 0) { + sLineStream << GetWordRenderString(sWords.AsStringC()); + sWords.Clear(); } - sEditStream << GetWordRenderString( - GetPDFWordString(pFontMap, nCurFontIndex, word.Word, SubWord)); + sLineStream << GetFontSetString(pFontMap, word.nFontIndex, + word.fFontSize); + nCurFontIndex = word.nFontIndex; } + sWords << GetPDFWordString(pFontMap, nCurFontIndex, word.Word, SubWord); + } + oldplace = place; + } else { + CPVT_Word word; + if (pIterator->GetWord(word)) { + ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, + word.ptWord.y + ptOffset.y); + if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { + sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y + << " Td\n"; + ptOld = ptNew; + } + if (word.nFontIndex != nCurFontIndex) { + sEditStream << GetFontSetString(pFontMap, word.nFontIndex, + word.fFontSize); + nCurFontIndex = word.nFontIndex; + } + sEditStream << GetWordRenderString( + GetPDFWordString(pFontMap, nCurFontIndex, word.Word, SubWord)); } } - if (sWords.GetSize() > 0) { - sLineStream << GetWordRenderString(sWords.AsStringC()); - sEditStream << sLineStream; - sWords.Clear(); - } + } + if (sWords.GetSize() > 0) { + sLineStream << GetWordRenderString(sWords.AsStringC()); + sEditStream << sLineStream; + sWords.Clear(); } return sEditStream.AsStringC(); } -- cgit v1.2.3