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

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

Issue 1142713005: Remove FX_Alloc() null checks now that it can't return NULL. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fix missing FX_Alloc2D, check overflow on add, remove unused enum. 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 if (widths) { 226 for (i = 0; i < m_BaseLines.GetSize(); i ++) {
227 for (i = 0; i < m_BaseLines.GetSize(); i ++) { 227 widths[i] = 0;
228 widths[i] = 0; 228 CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i);
229 CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i); 229 int TotalChars = 0;
230 int TotalChars = 0; 230 FX_FLOAT TotalWidth = 0;
231 FX_FLOAT TotalWidth = 0; 231 int minchars;
232 int minchars; 232 pBaseLine->CountChars(TotalChars, TotalWidth, minchars);
233 pBaseLine->CountChars(TotalChars, TotalWidth, minchars); 233 if (TotalChars) {
234 if (TotalChars) { 234 FX_FLOAT charwidth = TotalWidth / TotalChars;
235 FX_FLOAT charwidth = TotalWidth / TotalChars; 235 widths[i] = (int)((MaxRightX - MinLeftX) / charwidth);
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 }
244 } 236 }
245 int AvgWidth = 0, widthcount = 0; 237 if (widths[i] > 1000) {
246 for (i = 0; i < m_BaseLines.GetSize(); i ++) 238 widths[i] = 1000;
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;
259 } 239 }
260 FX_Free(widths); 240 if (widths[i] < minchars) {
261 if (iMinWidth < MaxWidth) { 241 widths[i] = minchars;
262 iMinWidth = MaxWidth;
263 } 242 }
264 } 243 }
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 }
265 } 263 }
266 for (i = 0; i < m_BaseLines.GetSize(); i ++) { 264 for (i = 0; i < m_BaseLines.GetSize(); i ++) {
267 CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i); 265 CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i);
268 pBaseLine->MergeBoxes(); 266 pBaseLine->MergeBoxes();
269 } 267 }
270 if (m_bKeepColumn) { 268 if (m_bKeepColumn) {
271 FindColumns(); 269 FindColumns();
272 } 270 }
273 for (i = 0; i < m_BaseLines.GetSize(); i ++) { 271 for (i = 0; i < m_BaseLines.GetSize(); i ++) {
274 CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i); 272 CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i);
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 { 769 {
772 buffer.EstimateSize(0, 10240); 770 buffer.EstimateSize(0, 10240);
773 CPDF_Page page; 771 CPDF_Page page;
774 page.Load(pDoc, pPage); 772 page.Load(pDoc, pPage);
775 CPDF_ParseOptions options; 773 CPDF_ParseOptions options;
776 options.m_bTextOnly = TRUE; 774 options.m_bTextOnly = TRUE;
777 options.m_bSeparateForm = FALSE; 775 options.m_bSeparateForm = FALSE;
778 page.ParseContent(&options); 776 page.ParseContent(&options);
779 _PDF_GetTextStream_Unicode(buffer, &page, TRUE, NULL); 777 _PDF_GetTextStream_Unicode(buffer, &page, TRUE, NULL);
780 } 778 }
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