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

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

Issue 1090693002: Replace FX_NEW with new, remove tests in fpdfdoc. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 8 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 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 "../../include/fpdfdoc/fpdf_doc.h" 7 #include "../../include/fpdfdoc/fpdf_doc.h"
8 #include "../../include/fpdfdoc/fpdf_vt.h" 8 #include "../../include/fpdfdoc/fpdf_vt.h"
9 #include "pdf_vt.h" 9 #include "pdf_vt.h"
10 const FX_BYTE gFontSizeSteps[] = { 4, 6, 8, 9, 10, 12, 14, 18, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, 90, 100, 110, 120, 130, 144}; 10 const FX_BYTE gFontSizeSteps[] = { 4, 6, 8, 9, 10, 12, 14, 18, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, 90, 100, 110, 120, 130, 144};
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 void CSection::ResetLinePlace() 70 void CSection::ResetLinePlace()
71 { 71 {
72 for (FX_INT32 i = 0, sz = m_LineArray.GetSize(); i < sz; i++) { 72 for (FX_INT32 i = 0, sz = m_LineArray.GetSize(); i < sz; i++) {
73 if (CLine * pLine = m_LineArray.GetAt(i)) { 73 if (CLine * pLine = m_LineArray.GetAt(i)) {
74 pLine->LinePlace = CPVT_WordPlace(SecPlace.nSecIndex, i, -1); 74 pLine->LinePlace = CPVT_WordPlace(SecPlace.nSecIndex, i, -1);
75 } 75 }
76 } 76 }
77 } 77 }
78 CPVT_WordPlace CSection::AddWord(const CPVT_WordPlace & place, const CPVT_WordIn fo & wordinfo) 78 CPVT_WordPlace CSection::AddWord(const CPVT_WordPlace & place, const CPVT_WordIn fo & wordinfo)
79 { 79 {
80 if (CPVT_WordInfo * pWord = FX_NEW CPVT_WordInfo(wordinfo)) { 80 CPVT_WordInfo * pWord = new CPVT_WordInfo(wordinfo);
81 FX_INT32 nWordIndex = FPDF_MAX(FPDF_MIN(place.nWordIndex, this->m_WordAr ray.GetSize()), 0); 81 FX_INT32 nWordIndex = FPDF_MAX(FPDF_MIN(place.nWordIndex, this->m_WordArray. GetSize()), 0);
82 if (nWordIndex == m_WordArray.GetSize()) { 82 if (nWordIndex == m_WordArray.GetSize()) {
83 m_WordArray.Add(pWord); 83 m_WordArray.Add(pWord);
84 } else { 84 } else {
85 m_WordArray.InsertAt(nWordIndex, pWord); 85 m_WordArray.InsertAt(nWordIndex, pWord);
86 }
87 } 86 }
88 return place; 87 return place;
89 } 88 }
90 CPVT_WordPlace CSection::AddLine(const CPVT_LineInfo & lineinfo) 89 CPVT_WordPlace CSection::AddLine(const CPVT_LineInfo & lineinfo)
91 { 90 {
92 return CPVT_WordPlace(SecPlace.nSecIndex, m_LineArray.Add(lineinfo), -1); 91 return CPVT_WordPlace(SecPlace.nSecIndex, m_LineArray.Add(lineinfo), -1);
93 } 92 }
94 CPVT_FloatRect CSection::Rearrange() 93 CPVT_FloatRect CSection::Rearrange()
95 { 94 {
96 ASSERT(m_pVT != NULL); 95 ASSERT(m_pVT != NULL);
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 delete m_pVTIterator; 826 delete m_pVTIterator;
828 m_pVTIterator = NULL; 827 m_pVTIterator = NULL;
829 } 828 }
830 ResetAll(); 829 ResetAll();
831 } 830 }
832 void CPDF_VariableText::Initialize() 831 void CPDF_VariableText::Initialize()
833 { 832 {
834 if (!m_bInitial) { 833 if (!m_bInitial) {
835 CPVT_SectionInfo secinfo; 834 CPVT_SectionInfo secinfo;
836 if (m_bRichText) { 835 if (m_bRichText) {
837 secinfo.pSecProps = FX_NEW CPVT_SecProps(0.0f, 0.0f, 0); 836 secinfo.pSecProps = new CPVT_SecProps(0.0f, 0.0f, 0);
838 secinfo.pWordProps = FX_NEW CPVT_WordProps(GetDefaultFontIndex(), PV T_DEFAULT_FONTSIZE, 0, 0, 0); 837 secinfo.pWordProps = new CPVT_WordProps(GetDefaultFontIndex(), PVT_D EFAULT_FONTSIZE, 0, 0, 0);
839 } 838 }
840 CPVT_WordPlace place; 839 CPVT_WordPlace place;
841 place.nSecIndex = 0; 840 place.nSecIndex = 0;
842 AddSection(place, secinfo); 841 AddSection(place, secinfo);
843 CPVT_LineInfo lineinfo; 842 CPVT_LineInfo lineinfo;
844 lineinfo.fLineAscent = GetFontAscent(GetDefaultFontIndex(), GetFontSize( )); 843 lineinfo.fLineAscent = GetFontAscent(GetDefaultFontIndex(), GetFontSize( ));
845 lineinfo.fLineDescent = GetFontDescent(GetDefaultFontIndex(), GetFontSiz e()); 844 lineinfo.fLineDescent = GetFontDescent(GetDefaultFontIndex(), GetFontSiz e());
846 AddLine(place, lineinfo); 845 AddLine(place, lineinfo);
847 if (CSection * pSection = m_SectionArray.GetAt(0)) { 846 if (CSection * pSection = m_SectionArray.GetAt(0)) {
848 pSection->ResetLinePlace(); 847 pSection->ResetLinePlace();
(...skipping 12 matching lines...) Expand all
861 FX_INT32 nTotlaWords = this->GetTotalWords(); 860 FX_INT32 nTotlaWords = this->GetTotalWords();
862 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) { 861 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) {
863 return place; 862 return place;
864 } 863 }
865 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) { 864 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) {
866 return place; 865 return place;
867 } 866 }
868 CPVT_WordPlace newplace = place; 867 CPVT_WordPlace newplace = place;
869 newplace.nWordIndex ++; 868 newplace.nWordIndex ++;
870 if (m_bRichText) { 869 if (m_bRichText) {
871 CPVT_WordProps * pNewProps = pWordProps ? FX_NEW CPVT_WordProps(*pWordPr ops) : FX_NEW CPVT_WordProps(); 870 CPVT_WordProps * pNewProps = pWordProps ? new CPVT_WordProps(*pWordProps ) : new CPVT_WordProps();
872 if (pNewProps) { 871 pNewProps->nFontIndex = GetWordFontIndex(word, charset, pWordProps->nFon tIndex);
873 pNewProps->nFontIndex = GetWordFontIndex(word, charset, pWordProps-> nFontIndex); 872 return AddWord(newplace, CPVT_WordInfo(word, charset, -1, pNewProps));
874 return AddWord(newplace, CPVT_WordInfo(word, charset, -1, pNewProps) );
875 }
876 } else { 873 } else {
877 FX_INT32 nFontIndex = GetSubWord() > 0 ? GetDefaultFontIndex() : GetWord FontIndex(word, charset, GetDefaultFontIndex()); 874 FX_INT32 nFontIndex = GetSubWord() > 0 ? GetDefaultFontIndex() : GetWord FontIndex(word, charset, GetDefaultFontIndex());
878 return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, NULL)) ; 875 return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, NULL)) ;
879 } 876 }
880 return place; 877 return place;
881 } 878 }
882 CPVT_WordPlace CPDF_VariableText::InsertSection(const CPVT_WordPlace & place, co nst CPVT_SecProps * pSecProps, 879 CPVT_WordPlace CPDF_VariableText::InsertSection(const CPVT_WordPlace & place, co nst CPVT_SecProps * pSecProps,
883 const CPVT_WordProps * pWordProps) 880 const CPVT_WordProps * pWordProps)
884 { 881 {
885 FX_INT32 nTotlaWords = this->GetTotalWords(); 882 FX_INT32 nTotlaWords = this->GetTotalWords();
886 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) { 883 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) {
887 return place; 884 return place;
888 } 885 }
889 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) { 886 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) {
890 return place; 887 return place;
891 } 888 }
892 if (!m_bMultiLine) { 889 if (!m_bMultiLine) {
893 return place; 890 return place;
894 } 891 }
895 CPVT_WordPlace wordplace = place; 892 CPVT_WordPlace wordplace = place;
896 UpdateWordPlace(wordplace); 893 UpdateWordPlace(wordplace);
897 CPVT_WordPlace newplace = place; 894 CPVT_WordPlace newplace = place;
898 if (CSection * pSection = m_SectionArray.GetAt(wordplace.nSecIndex)) { 895 if (CSection * pSection = m_SectionArray.GetAt(wordplace.nSecIndex)) {
899 CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1); 896 CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1);
900 CPVT_SectionInfo secinfo; 897 CPVT_SectionInfo secinfo;
901 if (m_bRichText) { 898 if (m_bRichText) {
902 if (pSecProps) { 899 if (pSecProps) {
903 secinfo.pSecProps = FX_NEW CPVT_SecProps(*pSecProps); 900 secinfo.pSecProps = new CPVT_SecProps(*pSecProps);
904 } 901 }
905 if (pWordProps) { 902 if (pWordProps) {
906 secinfo.pWordProps = FX_NEW CPVT_WordProps(*pWordProps); 903 secinfo.pWordProps = new CPVT_WordProps(*pWordProps);
907 } 904 }
908 } 905 }
909 AddSection(NewPlace, secinfo); 906 AddSection(NewPlace, secinfo);
910 newplace = NewPlace; 907 newplace = NewPlace;
911 if (CSection * pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) { 908 if (CSection * pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) {
912 for (FX_INT32 w = wordplace.nWordIndex + 1, sz = pSection->m_WordArr ay.GetSize(); w < sz; w++) { 909 for (FX_INT32 w = wordplace.nWordIndex + 1, sz = pSection->m_WordArr ay.GetSize(); w < sz; w++) {
913 if (CPVT_WordInfo * pWord = pSection->m_WordArray.GetAt(w)) { 910 if (CPVT_WordInfo * pWord = pSection->m_WordArray.GetAt(w)) {
914 NewPlace.nWordIndex++; 911 NewPlace.nWordIndex++;
915 pNewSection->AddWord(NewPlace, *pWord); 912 pNewSection->AddWord(NewPlace, *pWord);
916 } 913 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 } 979 }
983 void CPDF_VariableText::SetText(FX_LPCWSTR text, FX_INT32 charset, const CPVT_Se cProps * pSecProps, 980 void CPDF_VariableText::SetText(FX_LPCWSTR text, FX_INT32 charset, const CPVT_Se cProps * pSecProps,
984 const CPVT_WordProps * pWordProps) 981 const CPVT_WordProps * pWordProps)
985 { 982 {
986 DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); 983 DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace()));
987 CFX_WideString swText = text; 984 CFX_WideString swText = text;
988 CPVT_WordPlace wp(0, 0, -1); 985 CPVT_WordPlace wp(0, 0, -1);
989 CPVT_SectionInfo secinfo; 986 CPVT_SectionInfo secinfo;
990 if (m_bRichText) { 987 if (m_bRichText) {
991 if (pSecProps) { 988 if (pSecProps) {
992 secinfo.pSecProps = FX_NEW CPVT_SecProps(*pSecProps); 989 secinfo.pSecProps = new CPVT_SecProps(*pSecProps);
993 } 990 }
994 if (pWordProps) { 991 if (pWordProps) {
995 secinfo.pWordProps = FX_NEW CPVT_WordProps(*pWordProps); 992 secinfo.pWordProps = new CPVT_WordProps(*pWordProps);
996 } 993 }
997 } 994 }
998 if (CSection * pSection = m_SectionArray.GetAt(0)) { 995 if (CSection * pSection = m_SectionArray.GetAt(0)) {
999 pSection->m_SecInfo = secinfo; 996 pSection->m_SecInfo = secinfo;
1000 } 997 }
1001 FX_INT32 nCharCount = 0; 998 FX_INT32 nCharCount = 0;
1002 for (FX_INT32 i = 0, sz = swText.GetLength(); i < sz; i++) { 999 for (FX_INT32 i = 0, sz = swText.GetLength(); i < sz; i++) {
1003 if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) { 1000 if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) {
1004 break; 1001 break;
1005 } 1002 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 delete m_SectionArray.GetAt(s); 1270 delete m_SectionArray.GetAt(s);
1274 } 1271 }
1275 m_SectionArray.RemoveAll(); 1272 m_SectionArray.RemoveAll();
1276 } 1273 }
1277 CPVT_WordPlace CPDF_VariableText::AddSection(const CPVT_WordPlace & place, const CPVT_SectionInfo & secinfo) 1274 CPVT_WordPlace CPDF_VariableText::AddSection(const CPVT_WordPlace & place, const CPVT_SectionInfo & secinfo)
1278 { 1275 {
1279 if (IsValid() && !m_bMultiLine) { 1276 if (IsValid() && !m_bMultiLine) {
1280 return place; 1277 return place;
1281 } 1278 }
1282 FX_INT32 nSecIndex = FPDF_MAX(FPDF_MIN(place.nSecIndex, m_SectionArray.GetSi ze()), 0); 1279 FX_INT32 nSecIndex = FPDF_MAX(FPDF_MIN(place.nSecIndex, m_SectionArray.GetSi ze()), 0);
1283 CSection * pSection = FX_NEW CSection(this); 1280 CSection * pSection = new CSection(this);
1284 if (!pSection) {
1285 return place;
1286 }
1287 pSection->m_SecInfo = secinfo; 1281 pSection->m_SecInfo = secinfo;
1288 pSection->SecPlace.nSecIndex = nSecIndex; 1282 pSection->SecPlace.nSecIndex = nSecIndex;
1289 if (nSecIndex == m_SectionArray.GetSize()) { 1283 if (nSecIndex == m_SectionArray.GetSize()) {
1290 m_SectionArray.Add(pSection); 1284 m_SectionArray.Add(pSection);
1291 } else { 1285 } else {
1292 m_SectionArray.InsertAt(nSecIndex, pSection); 1286 m_SectionArray.InsertAt(nSecIndex, pSection);
1293 } 1287 }
1294 return place; 1288 return place;
1295 } 1289 }
1296 CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace & place, const CP VT_LineInfo & lineinfo) 1290 CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace & place, const CP VT_LineInfo & lineinfo)
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 { 1663 {
1670 return m_pVTProvider ? m_pVTProvider->GetDefaultFontIndex() : -1; 1664 return m_pVTProvider ? m_pVTProvider->GetDefaultFontIndex() : -1;
1671 } 1665 }
1672 FX_BOOL CPDF_VariableText::IsLatinWord(FX_WORD word) 1666 FX_BOOL CPDF_VariableText::IsLatinWord(FX_WORD word)
1673 { 1667 {
1674 return m_pVTProvider ? m_pVTProvider->IsLatinWord(word) : FALSE; 1668 return m_pVTProvider ? m_pVTProvider->IsLatinWord(word) : FALSE;
1675 } 1669 }
1676 IPDF_VariableText_Iterator * CPDF_VariableText::GetIterator() 1670 IPDF_VariableText_Iterator * CPDF_VariableText::GetIterator()
1677 { 1671 {
1678 if (!m_pVTIterator) { 1672 if (!m_pVTIterator) {
1679 return m_pVTIterator = FX_NEW CPDF_VariableText_Iterator(this); 1673 m_pVTIterator = new CPDF_VariableText_Iterator(this);
1680 } 1674 }
1681 return m_pVTIterator; 1675 return m_pVTIterator;
1682 } 1676 }
1683 IPDF_VariableText_Provider* CPDF_VariableText::SetProvider(IPDF_VariableText _Provider * pProvider) 1677 IPDF_VariableText_Provider* CPDF_VariableText::SetProvider(IPDF_VariableText _Provider * pProvider)
1684 { 1678 {
1685 IPDF_VariableText_Provider* pOld = m_pVTProvider; 1679 IPDF_VariableText_Provider* pOld = m_pVTProvider;
1686 m_pVTProvider = pProvider; 1680 m_pVTProvider = pProvider;
1687 return pOld; 1681 return pOld;
1688 } 1682 }
1689 CPDF_VariableText_Iterator::CPDF_VariableText_Iterator(CPDF_VariableText * pVT): 1683 CPDF_VariableText_Iterator::CPDF_VariableText_Iterator(CPDF_VariableText * pVT):
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1854 if (pSection->m_SecInfo.pSecProps) { 1848 if (pSection->m_SecInfo.pSecProps) {
1855 *pSection->m_SecInfo.pSecProps = section.SecProps; 1849 *pSection->m_SecInfo.pSecProps = section.SecProps;
1856 } 1850 }
1857 if (pSection->m_SecInfo.pWordProps) { 1851 if (pSection->m_SecInfo.pWordProps) {
1858 *pSection->m_SecInfo.pWordProps = section.WordProps; 1852 *pSection->m_SecInfo.pWordProps = section.WordProps;
1859 } 1853 }
1860 return TRUE; 1854 return TRUE;
1861 } 1855 }
1862 return FALSE; 1856 return FALSE;
1863 } 1857 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698