OLD | NEW |
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_module.h" | 8 #include "../../../include/fpdfapi/fpdf_module.h" |
9 #include "../../../include/fpdfapi/fpdf_serial.h" | 9 #include "../../../include/fpdfapi/fpdf_serial.h" |
10 #include "pageint.h" | 10 #include "pageint.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 #endif | 133 #endif |
134 } | 134 } |
135 int CPDF_StreamContentParser::GetNextParamPos() | 135 int CPDF_StreamContentParser::GetNextParamPos() |
136 { | 136 { |
137 if (m_ParamCount == PARAM_BUF_SIZE) { | 137 if (m_ParamCount == PARAM_BUF_SIZE) { |
138 m_ParamStartPos ++; | 138 m_ParamStartPos ++; |
139 if (m_ParamStartPos == PARAM_BUF_SIZE) { | 139 if (m_ParamStartPos == PARAM_BUF_SIZE) { |
140 m_ParamStartPos = 0; | 140 m_ParamStartPos = 0; |
141 } | 141 } |
142 if (m_ParamBuf1[m_ParamStartPos].m_Type == 0) { | 142 if (m_ParamBuf1[m_ParamStartPos].m_Type == 0) { |
143 m_ParamBuf1[m_ParamStartPos].m_pObject->Release(); | 143 if (CPDF_Object* pObject = m_ParamBuf1[m_ParamStartPos].m_pObject) |
| 144 pObject->Release(); |
144 } | 145 } |
145 return m_ParamStartPos; | 146 return m_ParamStartPos; |
146 } | 147 } |
147 int index = m_ParamStartPos + m_ParamCount; | 148 int index = m_ParamStartPos + m_ParamCount; |
148 if (index >= PARAM_BUF_SIZE) { | 149 if (index >= PARAM_BUF_SIZE) { |
149 index -= PARAM_BUF_SIZE; | 150 index -= PARAM_BUF_SIZE; |
150 } | 151 } |
151 m_ParamCount ++; | 152 m_ParamCount ++; |
152 return index; | 153 return index; |
153 } | 154 } |
(...skipping 26 matching lines...) Expand all Loading... |
180 { | 181 { |
181 int index = GetNextParamPos(); | 182 int index = GetNextParamPos(); |
182 m_ParamBuf1[index].m_Type = 0; | 183 m_ParamBuf1[index].m_Type = 0; |
183 m_ParamBuf1[index].m_pObject = pObj; | 184 m_ParamBuf1[index].m_pObject = pObj; |
184 } | 185 } |
185 void CPDF_StreamContentParser::ClearAllParams() | 186 void CPDF_StreamContentParser::ClearAllParams() |
186 { | 187 { |
187 FX_DWORD index = m_ParamStartPos; | 188 FX_DWORD index = m_ParamStartPos; |
188 for (FX_DWORD i = 0; i < m_ParamCount; i ++) { | 189 for (FX_DWORD i = 0; i < m_ParamCount; i ++) { |
189 if (m_ParamBuf1[index].m_Type == 0) { | 190 if (m_ParamBuf1[index].m_Type == 0) { |
190 m_ParamBuf1[index].m_pObject->Release(); | 191 if (CPDF_Object* pObject = m_ParamBuf1[index].m_pObject) |
| 192 pObject->Release(); |
191 } | 193 } |
192 index ++; | 194 index ++; |
193 if (index == PARAM_BUF_SIZE) { | 195 if (index == PARAM_BUF_SIZE) { |
194 index = 0; | 196 index = 0; |
195 } | 197 } |
196 } | 198 } |
197 m_ParamStartPos = 0; | 199 m_ParamStartPos = 0; |
198 m_ParamCount = 0; | 200 m_ParamCount = 0; |
199 } | 201 } |
200 CPDF_Object* CPDF_StreamContentParser::GetObject(FX_DWORD index) | 202 CPDF_Object* CPDF_StreamContentParser::GetObject(FX_DWORD index) |
(...skipping 30 matching lines...) Expand all Loading... |
231 return CFX_ByteString(); | 233 return CFX_ByteString(); |
232 } | 234 } |
233 int real_index = m_ParamStartPos + m_ParamCount - index - 1; | 235 int real_index = m_ParamStartPos + m_ParamCount - index - 1; |
234 if (real_index >= PARAM_BUF_SIZE) { | 236 if (real_index >= PARAM_BUF_SIZE) { |
235 real_index -= PARAM_BUF_SIZE; | 237 real_index -= PARAM_BUF_SIZE; |
236 } | 238 } |
237 _ContentParam& param = m_ParamBuf1[real_index]; | 239 _ContentParam& param = m_ParamBuf1[real_index]; |
238 if (param.m_Type == PDFOBJ_NAME) { | 240 if (param.m_Type == PDFOBJ_NAME) { |
239 return CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len); | 241 return CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len); |
240 } | 242 } |
241 if (param.m_Type == 0) { | 243 if (param.m_Type == 0 && param.m_pObject) { |
242 return param.m_pObject->GetString(); | 244 return param.m_pObject->GetString(); |
243 } | 245 } |
244 return CFX_ByteString(); | 246 return CFX_ByteString(); |
245 } | 247 } |
246 FX_FLOAT CPDF_StreamContentParser::GetNumber(FX_DWORD index) | 248 FX_FLOAT CPDF_StreamContentParser::GetNumber(FX_DWORD index) |
247 { | 249 { |
248 if (index >= m_ParamCount) { | 250 if (index >= m_ParamCount) { |
249 return 0; | 251 return 0; |
250 } | 252 } |
251 int real_index = m_ParamStartPos + m_ParamCount - index - 1; | 253 int real_index = m_ParamStartPos + m_ParamCount - index - 1; |
252 if (real_index >= PARAM_BUF_SIZE) { | 254 if (real_index >= PARAM_BUF_SIZE) { |
253 real_index -= PARAM_BUF_SIZE; | 255 real_index -= PARAM_BUF_SIZE; |
254 } | 256 } |
255 _ContentParam& param = m_ParamBuf1[real_index]; | 257 _ContentParam& param = m_ParamBuf1[real_index]; |
256 if (param.m_Type == PDFOBJ_NUMBER) { | 258 if (param.m_Type == PDFOBJ_NUMBER) { |
257 return param.m_Number.m_bInteger ? (FX_FLOAT)param.m_Number.m_Integer :
param.m_Number.m_Float; | 259 return param.m_Number.m_bInteger ? (FX_FLOAT)param.m_Number.m_Integer :
param.m_Number.m_Float; |
258 } | 260 } |
259 if (param.m_Type == 0) { | 261 if (param.m_Type == 0 && param.m_pObject) { |
260 return param.m_pObject->GetNumber(); | 262 return param.m_pObject->GetNumber(); |
261 } | 263 } |
262 return 0; | 264 return 0; |
263 } | 265 } |
264 FX_FLOAT CPDF_StreamContentParser::GetNumber16(FX_DWORD index) | 266 FX_FLOAT CPDF_StreamContentParser::GetNumber16(FX_DWORD index) |
265 { | 267 { |
266 return GetNumber(index); | 268 return GetNumber(index); |
267 } | 269 } |
268 void CPDF_StreamContentParser::SetGraphicStates(CPDF_PageObject* pObj, FX_BOOL b
Color, FX_BOOL bText, FX_BOOL bGraph) | 270 void CPDF_StreamContentParser::SetGraphicStates(CPDF_PageObject* pObj, FX_BOOL b
Color, FX_BOOL bText, FX_BOOL bGraph) |
269 { | 271 { |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 if (pCS == NULL) { | 648 if (pCS == NULL) { |
647 return; | 649 return; |
648 } | 650 } |
649 m_pCurStates->m_ColorState.GetModify()->m_StrokeColor.SetColorSpace(pCS); | 651 m_pCurStates->m_ColorState.GetModify()->m_StrokeColor.SetColorSpace(pCS); |
650 } | 652 } |
651 void CPDF_StreamContentParser::Handle_SetDash() | 653 void CPDF_StreamContentParser::Handle_SetDash() |
652 { | 654 { |
653 if (m_Options.m_bTextOnly) { | 655 if (m_Options.m_bTextOnly) { |
654 return; | 656 return; |
655 } | 657 } |
656 CPDF_Array* pArray = GetObject(1)->GetArray(); | 658 CPDF_Array* pArray = GetObject(1) ? GetObject(1)->GetArray() : NULL; |
657 if (pArray == NULL) { | 659 if (pArray == NULL) { |
658 return; | 660 return; |
659 } | 661 } |
660 m_pCurStates->SetLineDash(pArray, GetNumber(0), 1.0f); | 662 m_pCurStates->SetLineDash(pArray, GetNumber(0), 1.0f); |
661 } | 663 } |
662 void CPDF_StreamContentParser::Handle_SetCharWidth() | 664 void CPDF_StreamContentParser::Handle_SetCharWidth() |
663 { | 665 { |
664 m_Type3Data[0] = GetNumber(1); | 666 m_Type3Data[0] = GetNumber(1); |
665 m_Type3Data[1] = GetNumber(0); | 667 m_Type3Data[1] = GetNumber(0); |
666 m_bColored = TRUE; | 668 m_bColored = TRUE; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 FX_BOOL bForm; | 723 FX_BOOL bForm; |
722 if (m_pDocument->IsFormStream(((CPDF_Reference*)pRes)->GetRefObjNum(), b
Form) && !bForm) { | 724 if (m_pDocument->IsFormStream(((CPDF_Reference*)pRes)->GetRefObjNum(), b
Form) && !bForm) { |
723 return; | 725 return; |
724 } | 726 } |
725 } | 727 } |
726 CPDF_Stream* pXObject = (CPDF_Stream*)FindResourceObj(FX_BSTRC("XObject"), n
ame); | 728 CPDF_Stream* pXObject = (CPDF_Stream*)FindResourceObj(FX_BSTRC("XObject"), n
ame); |
727 if (pXObject == NULL || pXObject->GetType() != PDFOBJ_STREAM) { | 729 if (pXObject == NULL || pXObject->GetType() != PDFOBJ_STREAM) { |
728 m_bResourceMissing = TRUE; | 730 m_bResourceMissing = TRUE; |
729 return; | 731 return; |
730 } | 732 } |
731 CFX_ByteStringC type = pXObject->GetDict()->GetConstString(FX_BSTRC("Subtype
")); | 733 CFX_ByteStringC type = pXObject->GetDict() ? pXObject->GetDict()->GetConstSt
ring(FX_BSTRC("Subtype")) : CFX_ByteStringC(); |
732 if (type == FX_BSTRC("Image")) { | 734 if (type == FX_BSTRC("Image")) { |
733 if (m_Options.m_bTextOnly) { | 735 if (m_Options.m_bTextOnly) { |
734 return; | 736 return; |
735 } | 737 } |
736 CPDF_ImageObject* pObj = AddImage(pXObject, NULL, FALSE); | 738 CPDF_ImageObject* pObj = AddImage(pXObject, NULL, FALSE); |
737 m_LastImageName = name; | 739 m_LastImageName = name; |
738 m_pLastImage = pObj->m_pImage; | 740 m_pLastImage = pObj->m_pImage; |
739 } else if (type == FX_BSTRC("Form")) { | 741 } else if (type == FX_BSTRC("Form")) { |
740 AddForm(pXObject); | 742 AddForm(pXObject); |
741 } else { | 743 } else { |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 void CPDF_StreamContentParser::Handle_ShowText() | 1420 void CPDF_StreamContentParser::Handle_ShowText() |
1419 { | 1421 { |
1420 CFX_ByteString str = GetString(0); | 1422 CFX_ByteString str = GetString(0); |
1421 if (str.IsEmpty()) { | 1423 if (str.IsEmpty()) { |
1422 return; | 1424 return; |
1423 } | 1425 } |
1424 AddTextObject(&str, 0, NULL, 1); | 1426 AddTextObject(&str, 0, NULL, 1); |
1425 } | 1427 } |
1426 void CPDF_StreamContentParser::Handle_ShowText_Positioning() | 1428 void CPDF_StreamContentParser::Handle_ShowText_Positioning() |
1427 { | 1429 { |
1428 CPDF_Array* pArray = GetObject(0)->GetArray(); | 1430 CPDF_Array* pArray = GetObject(0) ? GetObject(0)->GetArray() : NULL; |
1429 if (pArray == NULL) { | 1431 if (pArray == NULL) { |
1430 return; | 1432 return; |
1431 } | 1433 } |
1432 int n = pArray->GetCount(), nsegs = 0, i; | 1434 int n = pArray->GetCount(), nsegs = 0, i; |
1433 for (i = 0; i < n; i ++) { | 1435 for (i = 0; i < n; i ++) { |
1434 CPDF_Object* pObj = pArray->GetElementValue(i); | 1436 CPDF_Object* pObj = pArray->GetElementValue(i); |
1435 if (pObj->GetType() == PDFOBJ_STRING) { | 1437 if (pObj->GetType() == PDFOBJ_STRING) { |
1436 nsegs ++; | 1438 nsegs ++; |
1437 } | 1439 } |
1438 } | 1440 } |
(...skipping 11 matching lines...) Expand all Loading... |
1450 for (i = 0; i < n; i ++) { | 1452 for (i = 0; i < n; i ++) { |
1451 CPDF_Object* pObj = pArray->GetElementValue(i); | 1453 CPDF_Object* pObj = pArray->GetElementValue(i); |
1452 if (pObj->GetType() == PDFOBJ_STRING) { | 1454 if (pObj->GetType() == PDFOBJ_STRING) { |
1453 CFX_ByteString str = pObj->GetString(); | 1455 CFX_ByteString str = pObj->GetString(); |
1454 if (str.IsEmpty()) { | 1456 if (str.IsEmpty()) { |
1455 continue; | 1457 continue; |
1456 } | 1458 } |
1457 pStrs[iSegment] = str; | 1459 pStrs[iSegment] = str; |
1458 pKerning[iSegment ++] = 0; | 1460 pKerning[iSegment ++] = 0; |
1459 } else { | 1461 } else { |
| 1462 FX_FLOAT num = pObj ? pObj->GetNumber() : 0; |
1460 if (iSegment == 0) { | 1463 if (iSegment == 0) { |
1461 fInitKerning += pObj->GetNumber(); | 1464 fInitKerning += num; |
1462 } else { | 1465 } else { |
1463 pKerning[iSegment - 1] += pObj->GetNumber(); | 1466 pKerning[iSegment - 1] += num; |
1464 } | 1467 } |
1465 } | 1468 } |
1466 } | 1469 } |
1467 AddTextObject(pStrs, fInitKerning, pKerning, iSegment); | 1470 AddTextObject(pStrs, fInitKerning, pKerning, iSegment); |
1468 FX_DELETE_VECTOR(pStrs, CFX_ByteString, nsegs); | 1471 FX_DELETE_VECTOR(pStrs, CFX_ByteString, nsegs); |
1469 FX_Free(pKerning); | 1472 FX_Free(pKerning); |
1470 } | 1473 } |
1471 void CPDF_StreamContentParser::Handle_SetTextLeading() | 1474 void CPDF_StreamContentParser::Handle_SetTextLeading() |
1472 { | 1475 { |
1473 m_pCurStates->m_TextLeading = GetNumber(0); | 1476 m_pCurStates->m_TextLeading = GetNumber(0); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 buf.AppendChar((char)code); | 1675 buf.AppendChar((char)code); |
1673 } | 1676 } |
1674 bFirst = !bFirst; | 1677 bFirst = !bFirst; |
1675 } | 1678 } |
1676 } | 1679 } |
1677 if (!bFirst) { | 1680 if (!bFirst) { |
1678 buf.AppendChar((char)code); | 1681 buf.AppendChar((char)code); |
1679 } | 1682 } |
1680 return buf.GetByteString(); | 1683 return buf.GetByteString(); |
1681 } | 1684 } |
OLD | NEW |