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

Side by Side Diff: core/src/fpdftext/fpdf_text.cpp

Issue 1145843005: Revert "Remove FX_Alloc() null checks now that it can't return NULL." (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « core/src/fpdfdoc/doc_annot.cpp ('k') | core/src/fpdftext/fpdf_text_int.cpp » ('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 "../../include/fpdfapi/fpdf_page.h" 7 #include "../../include/fpdfapi/fpdf_page.h"
8 #include "../../include/fpdfapi/fpdf_pageobj.h" 8 #include "../../include/fpdfapi/fpdf_pageobj.h"
9 #include "../../include/fpdftext/fpdf_text.h" 9 #include "../../include/fpdftext/fpdf_text.h"
10 #include "txtproc.h" 10 #include "txtproc.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 CTextBaseLine* pPrevLine = (CTextBaseLine*)m_BaseLines.GetAt(i - 1); 216 CTextBaseLine* pPrevLine = (CTextBaseLine*)m_BaseLines.GetAt(i - 1);
217 if (pBaseLine->CanMerge(pPrevLine)) { 217 if (pBaseLine->CanMerge(pPrevLine)) {
218 pPrevLine->Merge(pBaseLine); 218 pPrevLine->Merge(pBaseLine);
219 delete pBaseLine; 219 delete pBaseLine;
220 m_BaseLines.RemoveAt(i); 220 m_BaseLines.RemoveAt(i);
221 i --; 221 i --;
222 } 222 }
223 } 223 }
224 if (m_bAutoWidth) { 224 if (m_bAutoWidth) {
225 int* widths = FX_Alloc(int, m_BaseLines.GetSize()); 225 int* widths = FX_Alloc(int, m_BaseLines.GetSize());
226 for (i = 0; i < m_BaseLines.GetSize(); i ++) { 226 if (widths) {
227 widths[i] = 0; 227 for (i = 0; i < m_BaseLines.GetSize(); i ++) {
228 CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i); 228 widths[i] = 0;
229 int TotalChars = 0; 229 CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i);
230 FX_FLOAT TotalWidth = 0; 230 int TotalChars = 0;
231 int minchars; 231 FX_FLOAT TotalWidth = 0;
232 pBaseLine->CountChars(TotalChars, TotalWidth, minchars); 232 int minchars;
233 if (TotalChars) { 233 pBaseLine->CountChars(TotalChars, TotalWidth, minchars);
234 FX_FLOAT charwidth = TotalWidth / TotalChars; 234 if (TotalChars) {
235 widths[i] = (int)((MaxRightX - MinLeftX) / charwidth); 235 FX_FLOAT charwidth = TotalWidth / TotalChars;
236 widths[i] = (int)((MaxRightX - MinLeftX) / charwidth);
237 }
238 if (widths[i] > 1000) {
239 widths[i] = 1000;
240 }
241 if (widths[i] < minchars) {
242 widths[i] = minchars;
243 }
236 } 244 }
237 if (widths[i] > 1000) { 245 int AvgWidth = 0, widthcount = 0;
238 widths[i] = 1000; 246 for (i = 0; i < m_BaseLines.GetSize(); i ++)
247 if (widths[i]) {
248 AvgWidth += widths[i];
249 widthcount ++;
250 }
251 AvgWidth = int((FX_FLOAT)AvgWidth / widthcount + 0.5);
252 int MaxWidth = 0;
253 for (i = 0; i < m_BaseLines.GetSize(); i ++)
254 if (MaxWidth < widths[i]) {
255 MaxWidth = widths[i];
256 }
257 if (MaxWidth > AvgWidth * 6 / 5) {
258 MaxWidth = AvgWidth * 6 / 5;
239 } 259 }
240 if (widths[i] < minchars) { 260 FX_Free(widths);
241 widths[i] = minchars; 261 if (iMinWidth < MaxWidth) {
262 iMinWidth = MaxWidth;
242 } 263 }
243 } 264 }
244 int AvgWidth = 0, widthcount = 0;
245 for (i = 0; i < m_BaseLines.GetSize(); i ++)
246 if (widths[i]) {
247 AvgWidth += widths[i];
248 widthcount ++;
249 }
250 AvgWidth = int((FX_FLOAT)AvgWidth / widthcount + 0.5);
251 int MaxWidth = 0;
252 for (i = 0; i < m_BaseLines.GetSize(); i ++)
253 if (MaxWidth < widths[i]) {
254 MaxWidth = widths[i];
255 }
256 if (MaxWidth > AvgWidth * 6 / 5) {
257 MaxWidth = AvgWidth * 6 / 5;
258 }
259 FX_Free(widths);
260 if (iMinWidth < MaxWidth) {
261 iMinWidth = MaxWidth;
262 }
263 } 265 }
264 for (i = 0; i < m_BaseLines.GetSize(); i ++) { 266 for (i = 0; i < m_BaseLines.GetSize(); i ++) {
265 CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i); 267 CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i);
266 pBaseLine->MergeBoxes(); 268 pBaseLine->MergeBoxes();
267 } 269 }
268 if (m_bKeepColumn) { 270 if (m_bKeepColumn) {
269 FindColumns(); 271 FindColumns();
270 } 272 }
271 for (i = 0; i < m_BaseLines.GetSize(); i ++) { 273 for (i = 0; i < m_BaseLines.GetSize(); i ++) {
272 CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i); 274 CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i);
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 { 771 {
770 buffer.EstimateSize(0, 10240); 772 buffer.EstimateSize(0, 10240);
771 CPDF_Page page; 773 CPDF_Page page;
772 page.Load(pDoc, pPage); 774 page.Load(pDoc, pPage);
773 CPDF_ParseOptions options; 775 CPDF_ParseOptions options;
774 options.m_bTextOnly = TRUE; 776 options.m_bTextOnly = TRUE;
775 options.m_bSeparateForm = FALSE; 777 options.m_bSeparateForm = FALSE;
776 page.ParseContent(&options); 778 page.ParseContent(&options);
777 _PDF_GetTextStream_Unicode(buffer, &page, TRUE, NULL); 779 _PDF_GetTextStream_Unicode(buffer, &page, TRUE, NULL);
778 } 780 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_annot.cpp ('k') | core/src/fpdftext/fpdf_text_int.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698