summaryrefslogtreecommitdiff
path: root/core/src/fpdftext
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/fpdftext')
-rw-r--r--core/src/fpdftext/fpdf_text.cpp68
-rw-r--r--core/src/fpdftext/fpdf_text_int.cpp6
2 files changed, 41 insertions, 33 deletions
diff --git a/core/src/fpdftext/fpdf_text.cpp b/core/src/fpdftext/fpdf_text.cpp
index e58b50d182..a0b01042e1 100644
--- a/core/src/fpdftext/fpdf_text.cpp
+++ b/core/src/fpdftext/fpdf_text.cpp
@@ -223,42 +223,44 @@ void CTextPage::WriteOutput(CFX_WideStringArray& lines, int iMinWidth)
}
if (m_bAutoWidth) {
int* widths = FX_Alloc(int, m_BaseLines.GetSize());
- for (i = 0; i < m_BaseLines.GetSize(); i ++) {
- widths[i] = 0;
- CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i);
- int TotalChars = 0;
- FX_FLOAT TotalWidth = 0;
- int minchars;
- pBaseLine->CountChars(TotalChars, TotalWidth, minchars);
- if (TotalChars) {
- FX_FLOAT charwidth = TotalWidth / TotalChars;
- widths[i] = (int)((MaxRightX - MinLeftX) / charwidth);
- }
- if (widths[i] > 1000) {
- widths[i] = 1000;
- }
- if (widths[i] < minchars) {
- widths[i] = minchars;
+ if (widths) {
+ for (i = 0; i < m_BaseLines.GetSize(); i ++) {
+ widths[i] = 0;
+ CTextBaseLine* pBaseLine = (CTextBaseLine*)m_BaseLines.GetAt(i);
+ int TotalChars = 0;
+ FX_FLOAT TotalWidth = 0;
+ int minchars;
+ pBaseLine->CountChars(TotalChars, TotalWidth, minchars);
+ if (TotalChars) {
+ FX_FLOAT charwidth = TotalWidth / TotalChars;
+ widths[i] = (int)((MaxRightX - MinLeftX) / charwidth);
+ }
+ if (widths[i] > 1000) {
+ widths[i] = 1000;
+ }
+ if (widths[i] < minchars) {
+ widths[i] = minchars;
+ }
}
- }
- int AvgWidth = 0, widthcount = 0;
- for (i = 0; i < m_BaseLines.GetSize(); i ++)
- if (widths[i]) {
- AvgWidth += widths[i];
- widthcount ++;
+ int AvgWidth = 0, widthcount = 0;
+ for (i = 0; i < m_BaseLines.GetSize(); i ++)
+ if (widths[i]) {
+ AvgWidth += widths[i];
+ widthcount ++;
+ }
+ AvgWidth = int((FX_FLOAT)AvgWidth / widthcount + 0.5);
+ int MaxWidth = 0;
+ for (i = 0; i < m_BaseLines.GetSize(); i ++)
+ if (MaxWidth < widths[i]) {
+ MaxWidth = widths[i];
+ }
+ if (MaxWidth > AvgWidth * 6 / 5) {
+ MaxWidth = AvgWidth * 6 / 5;
}
- AvgWidth = int((FX_FLOAT)AvgWidth / widthcount + 0.5);
- int MaxWidth = 0;
- for (i = 0; i < m_BaseLines.GetSize(); i ++)
- if (MaxWidth < widths[i]) {
- MaxWidth = widths[i];
+ FX_Free(widths);
+ if (iMinWidth < MaxWidth) {
+ iMinWidth = MaxWidth;
}
- if (MaxWidth > AvgWidth * 6 / 5) {
- MaxWidth = AvgWidth * 6 / 5;
- }
- FX_Free(widths);
- if (iMinWidth < MaxWidth) {
- iMinWidth = MaxWidth;
}
}
for (i = 0; i < m_BaseLines.GetSize(); i ++) {
diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp
index 69d0bc574f..882b22ceec 100644
--- a/core/src/fpdftext/fpdf_text_int.cpp
+++ b/core/src/fpdftext/fpdf_text_int.cpp
@@ -1164,6 +1164,9 @@ void CPDF_TextPage::AddCharInfoByLRDirection(CFX_WideString& str, int i)
FX_STRSIZE nCount = FX_Unicode_GetNormalization(wChar, pDst);
if (nCount >= 1) {
pDst = FX_Alloc(FX_WCHAR, nCount);
+ if (!pDst) {
+ return;
+ }
FX_Unicode_GetNormalization(wChar, pDst);
for (int nIndex = 0; nIndex < nCount; nIndex++) {
PAGECHAR_INFO Info2 = Info;
@@ -1196,6 +1199,9 @@ void CPDF_TextPage::AddCharInfoByRLDirection(CFX_WideString& str, int i)
FX_STRSIZE nCount = FX_Unicode_GetNormalization(wChar, pDst);
if (nCount >= 1) {
pDst = FX_Alloc(FX_WCHAR, nCount);
+ if (!pDst) {
+ return;
+ }
FX_Unicode_GetNormalization(wChar, pDst);
for (int nIndex = 0; nIndex < nCount; nIndex++) {
PAGECHAR_INFO Info2 = Info;