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 "pageint.h" | 7 #include "pageint.h" |
8 | 8 |
9 #include <limits.h> | 9 #include <limits.h> |
10 | 10 |
11 #include "core/include/fpdfapi/fpdf_module.h" | 11 #include "core/include/fpdfapi/fpdf_module.h" |
12 #include "core/include/fpdfapi/fpdf_page.h" | 12 #include "core/include/fpdfapi/fpdf_page.h" |
13 #include "core/include/fxcodec/fx_codec.h" | 13 #include "core/include/fxcodec/fx_codec.h" |
| 14 #include "core/include/fxcrt/fx_ext.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 const char kPathOperatorSubpath = 'm'; | 18 const char kPathOperatorSubpath = 'm'; |
18 const char kPathOperatorLine = 'l'; | 19 const char kPathOperatorLine = 'l'; |
19 const char kPathOperatorCubicBezier1 = 'c'; | 20 const char kPathOperatorCubicBezier1 = 'c'; |
20 const char kPathOperatorCubicBezier2 = 'v'; | 21 const char kPathOperatorCubicBezier2 = 'v'; |
21 const char kPathOperatorCubicBezier3 = 'y'; | 22 const char kPathOperatorCubicBezier3 = 'y'; |
22 const char kPathOperatorClosePath = 'h'; | 23 const char kPathOperatorClosePath = 'h'; |
23 const char kPathOperatorRectangle[] = "re"; | 24 const char kPathOperatorRectangle[] = "re"; |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 parlevel++; | 785 parlevel++; |
785 buf.AppendChar('('); | 786 buf.AppendChar('('); |
786 } else if (ch == '\\') { | 787 } else if (ch == '\\') { |
787 status = 1; | 788 status = 1; |
788 } else { | 789 } else { |
789 buf.AppendChar((char)ch); | 790 buf.AppendChar((char)ch); |
790 } | 791 } |
791 break; | 792 break; |
792 case 1: | 793 case 1: |
793 if (ch >= '0' && ch <= '7') { | 794 if (ch >= '0' && ch <= '7') { |
794 iEscCode = ch - '0'; | 795 iEscCode = FXSYS_toDecimalDigit(ch); |
795 status = 2; | 796 status = 2; |
796 break; | 797 break; |
797 } | 798 } |
798 if (ch == 'n') { | 799 if (ch == 'n') { |
799 buf.AppendChar('\n'); | 800 buf.AppendChar('\n'); |
800 } else if (ch == 'r') { | 801 } else if (ch == 'r') { |
801 buf.AppendChar('\r'); | 802 buf.AppendChar('\r'); |
802 } else if (ch == 't') { | 803 } else if (ch == 't') { |
803 buf.AppendChar('\t'); | 804 buf.AppendChar('\t'); |
804 } else if (ch == 'b') { | 805 } else if (ch == 'b') { |
805 buf.AppendChar('\b'); | 806 buf.AppendChar('\b'); |
806 } else if (ch == 'f') { | 807 } else if (ch == 'f') { |
807 buf.AppendChar('\f'); | 808 buf.AppendChar('\f'); |
808 } else if (ch == '\r') { | 809 } else if (ch == '\r') { |
809 status = 4; | 810 status = 4; |
810 break; | 811 break; |
811 } else if (ch == '\n') { | 812 } else if (ch == '\n') { |
812 } else { | 813 } else { |
813 buf.AppendChar(ch); | 814 buf.AppendChar(ch); |
814 } | 815 } |
815 status = 0; | 816 status = 0; |
816 break; | 817 break; |
817 case 2: | 818 case 2: |
818 if (ch >= '0' && ch <= '7') { | 819 if (ch >= '0' && ch <= '7') { |
819 iEscCode = iEscCode * 8 + ch - '0'; | 820 iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch); |
820 status = 3; | 821 status = 3; |
821 } else { | 822 } else { |
822 buf.AppendChar(iEscCode); | 823 buf.AppendChar(iEscCode); |
823 status = 0; | 824 status = 0; |
824 continue; | 825 continue; |
825 } | 826 } |
826 break; | 827 break; |
827 case 3: | 828 case 3: |
828 if (ch >= '0' && ch <= '7') { | 829 if (ch >= '0' && ch <= '7') { |
829 iEscCode = iEscCode * 8 + ch - '0'; | 830 iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch); |
830 buf.AppendChar(iEscCode); | 831 buf.AppendChar(iEscCode); |
831 status = 0; | 832 status = 0; |
832 } else { | 833 } else { |
833 buf.AppendChar(iEscCode); | 834 buf.AppendChar(iEscCode); |
834 status = 0; | 835 status = 0; |
835 continue; | 836 continue; |
836 } | 837 } |
837 break; | 838 break; |
838 case 4: | 839 case 4: |
839 status = 0; | 840 status = 0; |
(...skipping 12 matching lines...) Expand all Loading... |
852 | 853 |
853 if (buf.GetLength() > MAX_STRING_LENGTH) { | 854 if (buf.GetLength() > MAX_STRING_LENGTH) { |
854 return CFX_ByteString(buf.GetBuffer(), MAX_STRING_LENGTH); | 855 return CFX_ByteString(buf.GetBuffer(), MAX_STRING_LENGTH); |
855 } | 856 } |
856 return buf.GetByteString(); | 857 return buf.GetByteString(); |
857 } | 858 } |
858 CFX_ByteString CPDF_StreamParser::ReadHexString() { | 859 CFX_ByteString CPDF_StreamParser::ReadHexString() { |
859 if (!PositionIsInBounds()) | 860 if (!PositionIsInBounds()) |
860 return CFX_ByteString(); | 861 return CFX_ByteString(); |
861 | 862 |
862 int ch = m_pBuf[m_Pos++]; | |
863 CFX_ByteTextBuf buf; | 863 CFX_ByteTextBuf buf; |
864 FX_BOOL bFirst = TRUE; | 864 bool bFirst = true; |
865 int code = 0; | 865 int code = 0; |
866 while (1) { | 866 while (PositionIsInBounds()) { |
867 if (ch == '>') { | 867 int ch = m_pBuf[m_Pos++]; |
868 break; | 868 |
869 } | 869 if (ch == '>') |
870 if (ch >= '0' && ch <= '9') { | |
871 if (bFirst) { | |
872 code = (ch - '0') * 16; | |
873 } else { | |
874 code += ch - '0'; | |
875 buf.AppendChar((char)code); | |
876 } | |
877 bFirst = !bFirst; | |
878 } else if (ch >= 'A' && ch <= 'F') { | |
879 if (bFirst) { | |
880 code = (ch - 'A' + 10) * 16; | |
881 } else { | |
882 code += ch - 'A' + 10; | |
883 buf.AppendChar((char)code); | |
884 } | |
885 bFirst = !bFirst; | |
886 } else if (ch >= 'a' && ch <= 'f') { | |
887 if (bFirst) { | |
888 code = (ch - 'a' + 10) * 16; | |
889 } else { | |
890 code += ch - 'a' + 10; | |
891 buf.AppendChar((char)code); | |
892 } | |
893 bFirst = !bFirst; | |
894 } | |
895 if (!PositionIsInBounds()) | |
896 break; | 870 break; |
897 | 871 |
898 ch = m_pBuf[m_Pos++]; | 872 if (!std::isxdigit(ch)) |
| 873 continue; |
| 874 |
| 875 int val = FXSYS_toHexDigit(ch); |
| 876 if (bFirst) { |
| 877 code = val * 16; |
| 878 } else { |
| 879 code += val; |
| 880 buf.AppendByte((uint8_t)code); |
| 881 } |
| 882 bFirst = !bFirst; |
899 } | 883 } |
900 if (!bFirst) { | 884 if (!bFirst) |
901 buf.AppendChar((char)code); | 885 buf.AppendChar((char)code); |
902 } | 886 |
903 if (buf.GetLength() > MAX_STRING_LENGTH) { | 887 if (buf.GetLength() > MAX_STRING_LENGTH) |
904 return CFX_ByteString(buf.GetBuffer(), MAX_STRING_LENGTH); | 888 return CFX_ByteString(buf.GetBuffer(), MAX_STRING_LENGTH); |
905 } | 889 |
906 return buf.GetByteString(); | 890 return buf.GetByteString(); |
907 } | 891 } |
908 | 892 |
909 bool CPDF_StreamParser::PositionIsInBounds() const { | 893 bool CPDF_StreamParser::PositionIsInBounds() const { |
910 return m_Pos < m_Size; | 894 return m_Pos < m_Size; |
911 } | 895 } |
912 | 896 |
913 #define PAGEPARSE_STAGE_GETCONTENT 1 | 897 #define PAGEPARSE_STAGE_GETCONTENT 1 |
914 #define PAGEPARSE_STAGE_PARSE 2 | 898 #define PAGEPARSE_STAGE_PARSE 2 |
915 #define PAGEPARSE_STAGE_CHECKCLIP 3 | 899 #define PAGEPARSE_STAGE_CHECKCLIP 3 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 } | 1125 } |
1142 m_Status = Done; | 1126 m_Status = Done; |
1143 return; | 1127 return; |
1144 } | 1128 } |
1145 steps++; | 1129 steps++; |
1146 if (pPause && pPause->NeedToPauseNow()) { | 1130 if (pPause && pPause->NeedToPauseNow()) { |
1147 break; | 1131 break; |
1148 } | 1132 } |
1149 } | 1133 } |
1150 } | 1134 } |
OLD | NEW |