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 <algorithm> | 7 #include <algorithm> |
8 #include <cctype> | 8 #include <cctype> |
9 #include <cwctype> | 9 #include <cwctype> |
10 #include <memory> | 10 #include <memory> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 return (FX_STRSIZE)wFind; | 143 return (FX_STRSIZE)wFind; |
144 } | 144 } |
145 | 145 |
146 } // namespace | 146 } // namespace |
147 | 147 |
148 CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, FPDFText_Direction flags) | 148 CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, FPDFText_Direction flags) |
149 : m_pPage(pPage), | 149 : m_pPage(pPage), |
150 m_parserflag(flags), | 150 m_parserflag(flags), |
151 m_pPreTextObj(nullptr), | 151 m_pPreTextObj(nullptr), |
152 m_bIsParsed(false), | 152 m_bIsParsed(false), |
153 m_TextlineDir(-1), | 153 m_TextlineDir(TextOrientation::Unknown), |
154 m_CurlineRect(0, 0, 0, 0) { | 154 m_CurlineRect(0, 0, 0, 0) { |
155 m_TextBuf.EstimateSize(0, 10240); | 155 m_TextBuf.EstimateSize(0, 10240); |
156 pPage->GetDisplayMatrix(m_DisplayMatrix, 0, 0, (int)pPage->GetPageWidth(), | 156 pPage->GetDisplayMatrix(m_DisplayMatrix, 0, 0, (int)pPage->GetPageWidth(), |
157 (int)pPage->GetPageHeight(), 0); | 157 (int)pPage->GetPageHeight(), 0); |
158 } | 158 } |
159 | 159 |
160 bool CPDF_TextPage::IsControlChar(const PAGECHAR_INFO& charInfo) { | 160 bool CPDF_TextPage::IsControlChar(const PAGECHAR_INFO& charInfo) { |
161 switch (charInfo.m_Unicode) { | 161 switch (charInfo.m_Unicode) { |
162 case 0x2: | 162 case 0x2: |
163 case 0x3: | 163 case 0x3: |
(...skipping 12 matching lines...) Expand all Loading... | |
176 void CPDF_TextPage::ParseTextPage() { | 176 void CPDF_TextPage::ParseTextPage() { |
177 m_bIsParsed = false; | 177 m_bIsParsed = false; |
178 m_TextBuf.Clear(); | 178 m_TextBuf.Clear(); |
179 m_CharList.clear(); | 179 m_CharList.clear(); |
180 m_pPreTextObj = nullptr; | 180 m_pPreTextObj = nullptr; |
181 ProcessObject(); | 181 ProcessObject(); |
182 | 182 |
183 m_bIsParsed = true; | 183 m_bIsParsed = true; |
184 m_CharIndex.clear(); | 184 m_CharIndex.clear(); |
185 int nCount = pdfium::CollectionSize<int>(m_CharList); | 185 int nCount = pdfium::CollectionSize<int>(m_CharList); |
186 if (nCount) { | 186 if (nCount) |
187 m_CharIndex.push_back(0); | 187 m_CharIndex.push_back(0); |
188 } | 188 |
189 for (int i = 0; i < nCount; i++) { | 189 for (int i = 0; i < nCount; i++) { |
190 int indexSize = pdfium::CollectionSize<int>(m_CharIndex); | 190 int indexSize = pdfium::CollectionSize<int>(m_CharIndex); |
191 FX_BOOL bNormal = FALSE; | |
192 const PAGECHAR_INFO& charinfo = m_CharList[i]; | 191 const PAGECHAR_INFO& charinfo = m_CharList[i]; |
193 if (charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) { | 192 if (charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED || |
194 bNormal = TRUE; | 193 (charinfo.m_Unicode != 0 && !IsControlChar(charinfo))) { |
195 } else if (charinfo.m_Unicode == 0 || IsControlChar(charinfo)) { | |
196 bNormal = FALSE; | |
197 } else { | |
198 bNormal = TRUE; | |
199 } | |
200 if (bNormal) { | |
201 if (indexSize % 2) { | 194 if (indexSize % 2) { |
202 m_CharIndex.push_back(1); | 195 m_CharIndex.push_back(1); |
203 } else { | 196 } else { |
204 if (indexSize <= 0) { | 197 if (indexSize <= 0) |
205 continue; | 198 continue; |
206 } | |
207 m_CharIndex[indexSize - 1] += 1; | 199 m_CharIndex[indexSize - 1] += 1; |
208 } | 200 } |
209 } else { | 201 } else { |
210 if (indexSize % 2) { | 202 if (indexSize % 2) { |
211 if (indexSize <= 0) { | 203 if (indexSize <= 0) |
212 continue; | 204 continue; |
213 } | |
214 m_CharIndex[indexSize - 1] = i + 1; | 205 m_CharIndex[indexSize - 1] = i + 1; |
215 } else { | 206 } else { |
216 m_CharIndex.push_back(i + 1); | 207 m_CharIndex.push_back(i + 1); |
217 } | 208 } |
218 } | 209 } |
219 } | 210 } |
220 int indexSize = pdfium::CollectionSize<int>(m_CharIndex); | 211 int indexSize = pdfium::CollectionSize<int>(m_CharIndex); |
221 if (indexSize % 2) { | 212 if (indexSize % 2) |
222 m_CharIndex.erase(m_CharIndex.begin() + indexSize - 1); | 213 m_CharIndex.erase(m_CharIndex.begin() + indexSize - 1); |
223 } | |
224 } | 214 } |
225 | 215 |
226 int CPDF_TextPage::CountChars() const { | 216 int CPDF_TextPage::CountChars() const { |
227 return pdfium::CollectionSize<int>(m_CharList); | 217 return pdfium::CollectionSize<int>(m_CharList); |
228 } | 218 } |
229 | 219 |
230 int CPDF_TextPage::CharIndexFromTextIndex(int TextIndex) const { | 220 int CPDF_TextPage::CharIndexFromTextIndex(int TextIndex) const { |
231 int indexSize = pdfium::CollectionSize<int>(m_CharIndex); | 221 int indexSize = pdfium::CollectionSize<int>(m_CharIndex); |
232 int count = 0; | 222 int count = 0; |
233 for (int i = 0; i < indexSize; i += 2) { | 223 for (int i = 0; i < indexSize; i += 2) { |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 } | 668 } |
679 if (segmentStatus == 1) { | 669 if (segmentStatus == 1) { |
680 segmentStatus = 2; | 670 segmentStatus = 2; |
681 m_Segments.Add(segment); | 671 m_Segments.Add(segment); |
682 segment.m_Start = 0; | 672 segment.m_Start = 0; |
683 segment.m_nCount = 0; | 673 segment.m_nCount = 0; |
684 } | 674 } |
685 return m_Segments.GetSize(); | 675 return m_Segments.GetSize(); |
686 } | 676 } |
687 | 677 |
688 int32_t CPDF_TextPage::FindTextlineFlowDirection() { | 678 CPDF_TextPage::TextOrientation CPDF_TextPage::FindTextlineFlowOrientation() |
dsinclair
2016/06/14 19:40:13
Is the CPDF_TextPage:: needed here?
Lei Zhang
2016/06/14 20:01:15
Yes
| |
679 const { | |
689 const int32_t nPageWidth = static_cast<int32_t>(m_pPage->GetPageWidth()); | 680 const int32_t nPageWidth = static_cast<int32_t>(m_pPage->GetPageWidth()); |
690 const int32_t nPageHeight = static_cast<int32_t>(m_pPage->GetPageHeight()); | 681 const int32_t nPageHeight = static_cast<int32_t>(m_pPage->GetPageHeight()); |
691 std::vector<uint8_t> nHorizontalMask(nPageWidth); | 682 std::vector<uint8_t> nHorizontalMask(nPageWidth); |
692 std::vector<uint8_t> nVerticalMask(nPageHeight); | 683 std::vector<uint8_t> nVerticalMask(nPageHeight); |
693 uint8_t* pDataH = nHorizontalMask.data(); | 684 uint8_t* pDataH = nHorizontalMask.data(); |
694 uint8_t* pDataV = nVerticalMask.data(); | 685 uint8_t* pDataV = nVerticalMask.data(); |
695 int32_t index = 0; | 686 int32_t index = 0; |
696 FX_FLOAT fLineHeight = 0.0f; | 687 FX_FLOAT fLineHeight = 0.0f; |
697 if (m_pPage->GetPageObjectList()->empty()) | 688 if (m_pPage->GetPageObjectList()->empty()) |
698 return -1; | 689 return TextOrientation::Unknown; |
699 | 690 |
700 for (auto& pPageObj : *m_pPage->GetPageObjectList()) { | 691 for (auto& pPageObj : *m_pPage->GetPageObjectList()) { |
701 if (!pPageObj || !pPageObj->IsText()) | 692 if (!pPageObj || !pPageObj->IsText()) |
702 continue; | 693 continue; |
703 | 694 |
704 int32_t minH = | 695 int32_t minH = |
705 (int32_t)pPageObj->m_Left < 0 ? 0 : (int32_t)pPageObj->m_Left; | 696 (int32_t)pPageObj->m_Left < 0 ? 0 : (int32_t)pPageObj->m_Left; |
706 int32_t maxH = (int32_t)pPageObj->m_Right > nPageWidth | 697 int32_t maxH = (int32_t)pPageObj->m_Right > nPageWidth |
707 ? nPageWidth | 698 ? nPageWidth |
708 : (int32_t)pPageObj->m_Right; | 699 : (int32_t)pPageObj->m_Right; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
742 for (index = 0; index < nPageHeight; index++) { | 733 for (index = 0; index < nPageHeight; index++) { |
743 if (1 == nVerticalMask[index]) | 734 if (1 == nVerticalMask[index]) |
744 break; | 735 break; |
745 } | 736 } |
746 nStartV = index; | 737 nStartV = index; |
747 for (index = nPageHeight; index > 0; index--) { | 738 for (index = nPageHeight; index > 0; index--) { |
748 if (1 == nVerticalMask[index - 1]) | 739 if (1 == nVerticalMask[index - 1]) |
749 break; | 740 break; |
750 } | 741 } |
751 nEndV = index; | 742 nEndV = index; |
752 for (index = nStartV; index < nEndV; index++) { | 743 for (index = nStartV; index < nEndV; index++) |
753 nSumV += nVerticalMask[index]; | 744 nSumV += nVerticalMask[index]; |
745 nSumV /= nEndV - nStartV; | |
746 | |
747 if ((nEndV - nStartV) < (int32_t)(2 * fLineHeight)) | |
748 return TextOrientation::Horizontal; | |
749 if ((nEndH - nStartH) < (int32_t)(2 * fLineHeight)) | |
750 return TextOrientation::Vertical; | |
751 | |
752 if (nSumH > 0.8f) | |
753 return TextOrientation::Horizontal; | |
754 | |
755 if (nSumH > nSumV) | |
756 return TextOrientation::Horizontal; | |
757 if (nSumH < nSumV) | |
758 return TextOrientation::Vertical; | |
759 return TextOrientation::Unknown; | |
760 } | |
761 | |
762 void CPDF_TextPage::AppendGeneratedCharacter(FX_WCHAR unicode, | |
763 const CFX_Matrix& formMatrix) { | |
764 PAGECHAR_INFO generateChar; | |
765 if (GenerateCharInfo(unicode, generateChar)) { | |
dsinclair
2016/06/14 19:40:12
if (!GenerateCharInfo(unicode, generateChar))
re
Lei Zhang
2016/06/14 20:01:16
Done.
| |
766 if (!formMatrix.IsIdentity()) | |
767 generateChar.m_Matrix.Copy(formMatrix); | |
768 m_TempTextBuf.AppendChar(unicode); | |
769 m_TempCharList.push_back(generateChar); | |
754 } | 770 } |
755 nSumV /= nEndV - nStartV; | |
756 if ((nEndV - nStartV) < (int32_t)(2 * fLineHeight)) { | |
757 return 0; | |
758 } | |
759 if ((nEndH - nStartH) < (int32_t)(2 * fLineHeight)) { | |
760 return 1; | |
761 } | |
762 if (nSumH > 0.8f) { | |
763 return 0; | |
764 } | |
765 if (nSumH - nSumV > 0.0f) { | |
766 return 0; | |
767 } | |
768 if (nSumV - nSumH > 0.0f) { | |
769 return 1; | |
770 } | |
771 return -1; | |
772 } | 771 } |
773 | 772 |
774 void CPDF_TextPage::ProcessObject() { | 773 void CPDF_TextPage::ProcessObject() { |
775 if (m_pPage->GetPageObjectList()->empty()) | 774 if (m_pPage->GetPageObjectList()->empty()) |
776 return; | 775 return; |
777 | 776 |
778 m_TextlineDir = FindTextlineFlowDirection(); | 777 m_TextlineDir = FindTextlineFlowOrientation(); |
779 const CPDF_PageObjectList* pObjList = m_pPage->GetPageObjectList(); | 778 const CPDF_PageObjectList* pObjList = m_pPage->GetPageObjectList(); |
780 for (auto it = pObjList->begin(); it != pObjList->end(); ++it) { | 779 for (auto it = pObjList->begin(); it != pObjList->end(); ++it) { |
781 if (CPDF_PageObject* pObj = it->get()) { | 780 if (CPDF_PageObject* pObj = it->get()) { |
782 if (pObj->IsText()) { | 781 if (pObj->IsText()) { |
783 CFX_Matrix matrix; | 782 CFX_Matrix matrix; |
784 ProcessTextObject(pObj->AsText(), matrix, pObjList, it); | 783 ProcessTextObject(pObj->AsText(), matrix, pObjList, it); |
785 } else if (pObj->IsForm()) { | 784 } else if (pObj->IsForm()) { |
786 CFX_Matrix formMatrix(1, 0, 0, 1, 0, 0); | 785 CFX_Matrix formMatrix(1, 0, 0, 1, 0, 0); |
787 ProcessFormObject(pObj->AsForm(), formMatrix); | 786 ProcessFormObject(pObj->AsForm(), formMatrix); |
788 } | 787 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
826 CFX_ByteString str; | 825 CFX_ByteString str; |
827 pFont->AppendChar(str, charCode); | 826 pFont->AppendChar(str, charCode); |
828 if (int w = pFont->GetStringWidth(str.c_str(), 1)) | 827 if (int w = pFont->GetStringWidth(str.c_str(), 1)) |
829 return w; | 828 return w; |
830 | 829 |
831 return pFont->GetCharBBox(charCode).Width(); | 830 return pFont->GetCharBBox(charCode).Width(); |
832 } | 831 } |
833 | 832 |
834 void CPDF_TextPage::AddCharInfoByLRDirection(FX_WCHAR wChar, | 833 void CPDF_TextPage::AddCharInfoByLRDirection(FX_WCHAR wChar, |
835 PAGECHAR_INFO info) { | 834 PAGECHAR_INFO info) { |
836 if (!IsControlChar(info)) { | 835 if (IsControlChar(info)) { |
837 info.m_Index = m_TextBuf.GetLength(); | |
838 if (wChar >= 0xFB00 && wChar <= 0xFB06) { | |
839 FX_WCHAR* pDst = nullptr; | |
840 FX_STRSIZE nCount = Unicode_GetNormalization(wChar, pDst); | |
841 if (nCount >= 1) { | |
842 pDst = FX_Alloc(FX_WCHAR, nCount); | |
843 Unicode_GetNormalization(wChar, pDst); | |
844 for (int nIndex = 0; nIndex < nCount; nIndex++) { | |
845 PAGECHAR_INFO info2 = info; | |
846 info2.m_Unicode = pDst[nIndex]; | |
847 info2.m_Flag = FPDFTEXT_CHAR_PIECE; | |
848 m_TextBuf.AppendChar(info2.m_Unicode); | |
849 m_CharList.push_back(info2); | |
850 } | |
851 FX_Free(pDst); | |
852 return; | |
853 } | |
854 } | |
855 m_TextBuf.AppendChar(wChar); | |
856 } else { | |
857 info.m_Index = -1; | 836 info.m_Index = -1; |
837 m_CharList.push_back(info); | |
838 return; | |
858 } | 839 } |
859 m_CharList.push_back(info); | |
860 } | |
861 | 840 |
862 void CPDF_TextPage::AddCharInfoByRLDirection(FX_WCHAR wChar, | 841 info.m_Index = m_TextBuf.GetLength(); |
863 PAGECHAR_INFO info) { | 842 if (wChar >= 0xFB00 && wChar <= 0xFB06) { |
864 if (!IsControlChar(info)) { | |
865 info.m_Index = m_TextBuf.GetLength(); | |
866 wChar = FX_GetMirrorChar(wChar, TRUE, FALSE); | |
867 FX_WCHAR* pDst = nullptr; | 843 FX_WCHAR* pDst = nullptr; |
868 FX_STRSIZE nCount = Unicode_GetNormalization(wChar, pDst); | 844 FX_STRSIZE nCount = Unicode_GetNormalization(wChar, pDst); |
869 if (nCount >= 1) { | 845 if (nCount >= 1) { |
870 pDst = FX_Alloc(FX_WCHAR, nCount); | 846 pDst = FX_Alloc(FX_WCHAR, nCount); |
871 Unicode_GetNormalization(wChar, pDst); | 847 Unicode_GetNormalization(wChar, pDst); |
872 for (int nIndex = 0; nIndex < nCount; nIndex++) { | 848 for (int nIndex = 0; nIndex < nCount; nIndex++) { |
873 PAGECHAR_INFO info2 = info; | 849 PAGECHAR_INFO info2 = info; |
874 info2.m_Unicode = pDst[nIndex]; | 850 info2.m_Unicode = pDst[nIndex]; |
875 info2.m_Flag = FPDFTEXT_CHAR_PIECE; | 851 info2.m_Flag = FPDFTEXT_CHAR_PIECE; |
876 m_TextBuf.AppendChar(info2.m_Unicode); | 852 m_TextBuf.AppendChar(info2.m_Unicode); |
877 m_CharList.push_back(info2); | 853 m_CharList.push_back(info2); |
878 } | 854 } |
879 FX_Free(pDst); | 855 FX_Free(pDst); |
880 return; | 856 return; |
881 } | 857 } |
882 info.m_Unicode = wChar; | |
883 m_TextBuf.AppendChar(info.m_Unicode); | |
884 } else { | |
885 info.m_Index = -1; | |
886 } | 858 } |
859 m_TextBuf.AppendChar(wChar); | |
887 m_CharList.push_back(info); | 860 m_CharList.push_back(info); |
888 } | 861 } |
889 | 862 |
863 void CPDF_TextPage::AddCharInfoByRLDirection(FX_WCHAR wChar, | |
864 PAGECHAR_INFO info) { | |
865 if (IsControlChar(info)) { | |
866 info.m_Index = -1; | |
867 m_CharList.push_back(info); | |
868 return; | |
869 } | |
870 | |
871 info.m_Index = m_TextBuf.GetLength(); | |
872 wChar = FX_GetMirrorChar(wChar, TRUE, FALSE); | |
873 FX_WCHAR* pDst = nullptr; | |
874 FX_STRSIZE nCount = Unicode_GetNormalization(wChar, pDst); | |
875 if (nCount >= 1) { | |
876 pDst = FX_Alloc(FX_WCHAR, nCount); | |
877 Unicode_GetNormalization(wChar, pDst); | |
878 for (int nIndex = 0; nIndex < nCount; nIndex++) { | |
879 PAGECHAR_INFO info2 = info; | |
880 info2.m_Unicode = pDst[nIndex]; | |
881 info2.m_Flag = FPDFTEXT_CHAR_PIECE; | |
882 m_TextBuf.AppendChar(info2.m_Unicode); | |
883 m_CharList.push_back(info2); | |
884 } | |
885 FX_Free(pDst); | |
886 return; | |
887 } | |
888 info.m_Unicode = wChar; | |
889 m_TextBuf.AppendChar(info.m_Unicode); | |
890 m_CharList.push_back(info); | |
891 } | |
892 | |
890 void CPDF_TextPage::CloseTempLine() { | 893 void CPDF_TextPage::CloseTempLine() { |
891 if (m_TempCharList.empty()) | 894 if (m_TempCharList.empty()) |
892 return; | 895 return; |
893 | 896 |
894 CFX_WideString str = m_TempTextBuf.MakeString(); | 897 CFX_WideString str = m_TempTextBuf.MakeString(); |
895 FX_BOOL bPrevSpace = FALSE; | 898 FX_BOOL bPrevSpace = FALSE; |
896 for (int i = 0; i < str.GetLength(); i++) { | 899 for (int i = 0; i < str.GetLength(); i++) { |
897 if (str.GetAt(i) != ' ') { | 900 if (str.GetAt(i) != ' ') { |
898 bPrevSpace = FALSE; | 901 bPrevSpace = FALSE; |
899 continue; | 902 continue; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 void CPDF_TextPage::FindPreviousTextObject() { | 1141 void CPDF_TextPage::FindPreviousTextObject() { |
1139 if (m_TempCharList.empty() && m_CharList.empty()) | 1142 if (m_TempCharList.empty() && m_CharList.empty()) |
1140 return; | 1143 return; |
1141 | 1144 |
1142 PAGECHAR_INFO preChar = | 1145 PAGECHAR_INFO preChar = |
1143 m_TempCharList.empty() ? m_CharList.back() : m_TempCharList.back(); | 1146 m_TempCharList.empty() ? m_CharList.back() : m_TempCharList.back(); |
1144 | 1147 |
1145 if (preChar.m_pTextObj) | 1148 if (preChar.m_pTextObj) |
1146 m_pPreTextObj = preChar.m_pTextObj; | 1149 m_pPreTextObj = preChar.m_pTextObj; |
1147 } | 1150 } |
1151 | |
1148 void CPDF_TextPage::SwapTempTextBuf(int32_t iCharListStartAppend, | 1152 void CPDF_TextPage::SwapTempTextBuf(int32_t iCharListStartAppend, |
1149 int32_t iBufStartAppend) { | 1153 int32_t iBufStartAppend) { |
1150 int32_t i = iCharListStartAppend; | 1154 int32_t i = iCharListStartAppend; |
1151 int32_t j = pdfium::CollectionSize<int32_t>(m_TempCharList) - 1; | 1155 int32_t j = pdfium::CollectionSize<int32_t>(m_TempCharList) - 1; |
1152 for (; i < j; i++, j--) { | 1156 for (; i < j; i++, j--) { |
1153 std::swap(m_TempCharList[i], m_TempCharList[j]); | 1157 std::swap(m_TempCharList[i], m_TempCharList[j]); |
1154 std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index); | 1158 std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index); |
1155 } | 1159 } |
1156 FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer(); | 1160 FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer(); |
1157 i = iBufStartAppend; | 1161 i = iBufStartAppend; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1191 CPDF_Font* pFont = pTextObj->GetFont(); | 1195 CPDF_Font* pFont = pTextObj->GetFont(); |
1192 CFX_Matrix matrix; | 1196 CFX_Matrix matrix; |
1193 pTextObj->GetTextMatrix(&matrix); | 1197 pTextObj->GetTextMatrix(&matrix); |
1194 matrix.Concat(formMatrix); | 1198 matrix.Concat(formMatrix); |
1195 FPDFText_MarkedContent ePreMKC = PreMarkedContent(Obj); | 1199 FPDFText_MarkedContent ePreMKC = PreMarkedContent(Obj); |
1196 if (ePreMKC == FPDFText_MarkedContent::Done) { | 1200 if (ePreMKC == FPDFText_MarkedContent::Done) { |
1197 m_pPreTextObj = pTextObj; | 1201 m_pPreTextObj = pTextObj; |
1198 m_perMatrix.Copy(formMatrix); | 1202 m_perMatrix.Copy(formMatrix); |
1199 return; | 1203 return; |
1200 } | 1204 } |
1201 int result = 0; | 1205 GenerateCharacter result = GenerateCharacter::None; |
1202 if (m_pPreTextObj) { | 1206 if (m_pPreTextObj) { |
1203 result = ProcessInsertObject(pTextObj, formMatrix); | 1207 result = ProcessInsertObject(pTextObj, formMatrix); |
1204 if (2 == result) { | 1208 if (result == GenerateCharacter::LineBreak) { |
1205 m_CurlineRect = | 1209 m_CurlineRect = |
1206 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, | 1210 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, |
1207 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top); | 1211 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top); |
1208 } else { | 1212 } else { |
1209 m_CurlineRect.Union( | 1213 m_CurlineRect.Union( |
1210 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, | 1214 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, |
1211 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top)); | 1215 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top)); |
1212 } | 1216 } |
1213 PAGECHAR_INFO generateChar; | 1217 switch (result) { |
1214 if (result == 1) { | 1218 case GenerateCharacter::None: |
1215 if (GenerateCharInfo(TEXT_BLANK_CHAR, generateChar)) { | 1219 break; |
1216 if (!formMatrix.IsIdentity()) { | 1220 case GenerateCharacter::Blank: |
1217 generateChar.m_Matrix.Copy(formMatrix); | 1221 AppendGeneratedCharacter(TEXT_BLANK_CHAR, formMatrix); |
1222 break; | |
1223 case GenerateCharacter::LineBreak: | |
1224 CloseTempLine(); | |
1225 if (m_TextBuf.GetSize()) { | |
1226 AppendGeneratedCharacter(TEXT_RETURN_CHAR, formMatrix); | |
1227 AppendGeneratedCharacter(TEXT_LINEFEED_CHAR, formMatrix); | |
1218 } | 1228 } |
1219 m_TempTextBuf.AppendChar(TEXT_BLANK_CHAR); | 1229 case GenerateCharacter::Hyphen: |
1220 m_TempCharList.push_back(generateChar); | 1230 if (pTextObj->CountChars() == 1) { |
1221 } | 1231 CPDF_TextObjectItem item; |
1222 } else if (result == 2) { | 1232 pTextObj->GetCharInfo(0, &item); |
1223 CloseTempLine(); | 1233 CFX_WideString wstrItem = |
1224 if (m_TextBuf.GetSize()) { | 1234 pTextObj->GetFont()->UnicodeFromCharCode(item.m_CharCode); |
1225 if (GenerateCharInfo(TEXT_RETURN_CHAR, generateChar)) { | 1235 if (wstrItem.IsEmpty()) { |
1226 m_TextBuf.AppendChar(TEXT_RETURN_CHAR); | 1236 wstrItem += (FX_WCHAR)item.m_CharCode; |
dsinclair
2016/06/14 19:40:13
This is different now. Previously it would append
Lei Zhang
2016/06/14 20:01:16
Whoops, bad refactoring.
| |
1227 if (!formMatrix.IsIdentity()) { | |
1228 generateChar.m_Matrix.Copy(formMatrix); | |
1229 } | 1237 } |
1230 m_CharList.push_back(generateChar); | 1238 FX_WCHAR curChar = wstrItem.GetAt(0); |
1239 if (0x2D == curChar || 0xAD == curChar) { | |
dsinclair
2016/06/14 19:40:13
nit: {}'s not needed
Lei Zhang
2016/06/14 20:01:15
Done.
| |
1240 return; | |
1241 } | |
1231 } | 1242 } |
1232 if (GenerateCharInfo(TEXT_LINEFEED_CHAR, generateChar)) { | 1243 while (m_TempTextBuf.GetSize() > 0 && |
1233 m_TextBuf.AppendChar(TEXT_LINEFEED_CHAR); | 1244 m_TempTextBuf.AsStringC().GetAt(m_TempTextBuf.GetLength() - 1) == |
1234 if (!formMatrix.IsIdentity()) { | 1245 0x20) { |
1235 generateChar.m_Matrix.Copy(formMatrix); | 1246 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); |
1236 } | 1247 m_TempCharList.pop_back(); |
1237 m_CharList.push_back(generateChar); | |
1238 } | 1248 } |
1239 } | 1249 PAGECHAR_INFO* charinfo = &m_TempCharList.back(); |
1240 } else if (result == 3) { | |
1241 int32_t nChars = pTextObj->CountChars(); | |
1242 if (nChars == 1) { | |
1243 CPDF_TextObjectItem item; | |
1244 pTextObj->GetCharInfo(0, &item); | |
1245 CFX_WideString wstrItem = | |
1246 pTextObj->GetFont()->UnicodeFromCharCode(item.m_CharCode); | |
1247 if (wstrItem.IsEmpty()) { | |
1248 wstrItem += (FX_WCHAR)item.m_CharCode; | |
1249 } | |
1250 FX_WCHAR curChar = wstrItem.GetAt(0); | |
1251 if (0x2D == curChar || 0xAD == curChar) { | |
1252 return; | |
1253 } | |
1254 } | |
1255 while (m_TempTextBuf.GetSize() > 0 && | |
1256 m_TempTextBuf.AsStringC().GetAt(m_TempTextBuf.GetLength() - 1) == | |
1257 0x20) { | |
1258 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); | 1250 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); |
1259 m_TempCharList.pop_back(); | 1251 charinfo->m_Unicode = 0x2; |
1260 } | 1252 charinfo->m_Flag = FPDFTEXT_CHAR_HYPHEN; |
1261 PAGECHAR_INFO* charinfo = &m_TempCharList.back(); | 1253 m_TempTextBuf.AppendChar(0xfffe); |
1262 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); | |
1263 charinfo->m_Unicode = 0x2; | |
1264 charinfo->m_Flag = FPDFTEXT_CHAR_HYPHEN; | |
1265 m_TempTextBuf.AppendChar(0xfffe); | |
1266 } | 1254 } |
1267 } else { | 1255 } else { |
1268 m_CurlineRect = | 1256 m_CurlineRect = |
1269 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, | 1257 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, |
1270 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top); | 1258 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top); |
1271 } | 1259 } |
1272 if (ePreMKC == FPDFText_MarkedContent::Delay) { | 1260 if (ePreMKC == FPDFText_MarkedContent::Delay) { |
1273 ProcessMarkedContent(Obj); | 1261 ProcessMarkedContent(Obj); |
1274 m_pPreTextObj = pTextObj; | 1262 m_pPreTextObj = pTextObj; |
1275 m_perMatrix.Copy(formMatrix); | 1263 m_perMatrix.Copy(formMatrix); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1438 m_TempCharList.pop_back(); | 1426 m_TempCharList.pop_back(); |
1439 } | 1427 } |
1440 } | 1428 } |
1441 } | 1429 } |
1442 } | 1430 } |
1443 if (bIsBidiAndMirrorInverse) { | 1431 if (bIsBidiAndMirrorInverse) { |
1444 SwapTempTextBuf(iCharListStartAppend, iBufStartAppend); | 1432 SwapTempTextBuf(iCharListStartAppend, iBufStartAppend); |
1445 } | 1433 } |
1446 } | 1434 } |
1447 | 1435 |
1448 int32_t CPDF_TextPage::GetTextObjectWritingMode( | 1436 CPDF_TextPage::TextOrientation CPDF_TextPage::GetTextObjectWritingMode( |
dsinclair
2016/06/14 19:40:13
nit: CPDF_TextPage:: needed?
Lei Zhang
2016/06/14 20:01:15
Yes
| |
1449 const CPDF_TextObject* pTextObj) { | 1437 const CPDF_TextObject* pTextObj) const { |
1450 int32_t nChars = pTextObj->CountChars(); | 1438 int32_t nChars = pTextObj->CountChars(); |
1451 if (nChars == 1) { | 1439 if (nChars == 1) |
1452 return m_TextlineDir; | 1440 return m_TextlineDir; |
1453 } | 1441 |
1454 CPDF_TextObjectItem first, last; | 1442 CPDF_TextObjectItem first, last; |
1455 pTextObj->GetCharInfo(0, &first); | 1443 pTextObj->GetCharInfo(0, &first); |
1456 pTextObj->GetCharInfo(nChars - 1, &last); | 1444 pTextObj->GetCharInfo(nChars - 1, &last); |
1457 CFX_Matrix textMatrix; | 1445 CFX_Matrix textMatrix; |
1458 pTextObj->GetTextMatrix(&textMatrix); | 1446 pTextObj->GetTextMatrix(&textMatrix); |
1459 textMatrix.TransformPoint(first.m_OriginX, first.m_OriginY); | 1447 textMatrix.TransformPoint(first.m_OriginX, first.m_OriginY); |
1460 textMatrix.TransformPoint(last.m_OriginX, last.m_OriginY); | 1448 textMatrix.TransformPoint(last.m_OriginX, last.m_OriginY); |
1461 FX_FLOAT dX = FXSYS_fabs(last.m_OriginX - first.m_OriginX); | 1449 FX_FLOAT dX = FXSYS_fabs(last.m_OriginX - first.m_OriginX); |
1462 FX_FLOAT dY = FXSYS_fabs(last.m_OriginY - first.m_OriginY); | 1450 FX_FLOAT dY = FXSYS_fabs(last.m_OriginY - first.m_OriginY); |
1463 if (dX <= 0.0001f && dY <= 0.0001f) { | 1451 if (dX <= 0.0001f && dY <= 0.0001f) |
1464 return -1; | 1452 return TextOrientation::Unknown; |
1465 } | 1453 |
1466 CFX_VectorF v(dX, dY); | 1454 CFX_VectorF v(dX, dY); |
1467 v.Normalize(); | 1455 v.Normalize(); |
1468 if (v.y <= 0.0872f) { | 1456 if (v.y <= 0.0872f) |
1469 return v.x <= 0.0872f ? m_TextlineDir : 0; | 1457 return v.x <= 0.0872f ? m_TextlineDir : TextOrientation::Horizontal; |
1470 } | 1458 |
1471 if (v.x <= 0.0872f) { | 1459 if (v.x <= 0.0872f) |
1472 return 1; | 1460 return TextOrientation::Vertical; |
1473 } | 1461 |
1474 return m_TextlineDir; | 1462 return m_TextlineDir; |
1475 } | 1463 } |
1464 | |
1476 FX_BOOL CPDF_TextPage::IsHyphen(FX_WCHAR curChar) { | 1465 FX_BOOL CPDF_TextPage::IsHyphen(FX_WCHAR curChar) { |
1477 CFX_WideString strCurText = m_TempTextBuf.MakeString(); | 1466 CFX_WideString strCurText = m_TempTextBuf.MakeString(); |
1478 if (strCurText.GetLength() == 0) { | 1467 if (strCurText.GetLength() == 0) { |
1479 strCurText = m_TextBuf.AsStringC(); | 1468 strCurText = m_TextBuf.AsStringC(); |
1480 } | 1469 } |
1481 FX_STRSIZE nCount = strCurText.GetLength(); | 1470 FX_STRSIZE nCount = strCurText.GetLength(); |
1482 int nIndex = nCount - 1; | 1471 int nIndex = nCount - 1; |
1483 FX_WCHAR wcTmp = strCurText.GetAt(nIndex); | 1472 FX_WCHAR wcTmp = strCurText.GetAt(nIndex); |
1484 while (wcTmp == 0x20 && nIndex <= nCount - 1 && nIndex >= 0) { | 1473 while (wcTmp == 0x20 && nIndex <= nCount - 1 && nIndex >= 0) { |
1485 wcTmp = strCurText.GetAt(--nIndex); | 1474 wcTmp = strCurText.GetAt(--nIndex); |
(...skipping 17 matching lines...) Expand all Loading... | |
1503 return FALSE; | 1492 return FALSE; |
1504 } | 1493 } |
1505 if (FPDFTEXT_CHAR_PIECE == preInfo->m_Flag && | 1494 if (FPDFTEXT_CHAR_PIECE == preInfo->m_Flag && |
1506 (0xAD == preInfo->m_Unicode || 0x2D == preInfo->m_Unicode)) { | 1495 (0xAD == preInfo->m_Unicode || 0x2D == preInfo->m_Unicode)) { |
1507 return TRUE; | 1496 return TRUE; |
1508 } | 1497 } |
1509 } | 1498 } |
1510 return FALSE; | 1499 return FALSE; |
1511 } | 1500 } |
1512 | 1501 |
1513 int CPDF_TextPage::ProcessInsertObject(const CPDF_TextObject* pObj, | 1502 CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject( |
dsinclair
2016/06/14 19:40:13
ditto
Lei Zhang
2016/06/14 20:01:15
ditto ditto
| |
1514 const CFX_Matrix& formMatrix) { | 1503 const CPDF_TextObject* pObj, |
1504 const CFX_Matrix& formMatrix) { | |
1515 FindPreviousTextObject(); | 1505 FindPreviousTextObject(); |
1516 FX_BOOL bNewline = FALSE; | 1506 FX_BOOL bNewline = FALSE; |
1517 int WritingMode = GetTextObjectWritingMode(pObj); | 1507 TextOrientation WritingMode = GetTextObjectWritingMode(pObj); |
1518 if (WritingMode == -1) { | 1508 if (WritingMode == TextOrientation::Unknown) |
1519 WritingMode = GetTextObjectWritingMode(m_pPreTextObj); | 1509 WritingMode = GetTextObjectWritingMode(m_pPreTextObj); |
1520 } | 1510 |
1521 CFX_FloatRect this_rect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right, | 1511 CFX_FloatRect this_rect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right, |
1522 pObj->m_Top); | 1512 pObj->m_Top); |
1523 CFX_FloatRect prev_rect(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom, | 1513 CFX_FloatRect prev_rect(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom, |
1524 m_pPreTextObj->m_Right, m_pPreTextObj->m_Top); | 1514 m_pPreTextObj->m_Right, m_pPreTextObj->m_Top); |
1525 CPDF_TextObjectItem PrevItem, item; | 1515 CPDF_TextObjectItem PrevItem, item; |
1526 int nItem = m_pPreTextObj->CountItems(); | 1516 int nItem = m_pPreTextObj->CountItems(); |
1527 m_pPreTextObj->GetItemInfo(nItem - 1, &PrevItem); | 1517 m_pPreTextObj->GetItemInfo(nItem - 1, &PrevItem); |
1528 pObj->GetItemInfo(0, &item); | 1518 pObj->GetItemInfo(0, &item); |
1529 CFX_WideString wstrItem = | 1519 CFX_WideString wstrItem = |
1530 pObj->GetFont()->UnicodeFromCharCode(item.m_CharCode); | 1520 pObj->GetFont()->UnicodeFromCharCode(item.m_CharCode); |
1531 if (wstrItem.IsEmpty()) { | 1521 if (wstrItem.IsEmpty()) { |
1532 wstrItem += (FX_WCHAR)item.m_CharCode; | 1522 wstrItem += (FX_WCHAR)item.m_CharCode; |
1533 } | 1523 } |
1534 FX_WCHAR curChar = wstrItem.GetAt(0); | 1524 FX_WCHAR curChar = wstrItem.GetAt(0); |
1535 if (WritingMode == 0) { | 1525 if (WritingMode == TextOrientation::Horizontal) { |
1536 if (this_rect.Height() > 4.5 && prev_rect.Height() > 4.5) { | 1526 if (this_rect.Height() > 4.5 && prev_rect.Height() > 4.5) { |
1537 FX_FLOAT top = | 1527 FX_FLOAT top = |
1538 this_rect.top < prev_rect.top ? this_rect.top : prev_rect.top; | 1528 this_rect.top < prev_rect.top ? this_rect.top : prev_rect.top; |
1539 FX_FLOAT bottom = this_rect.bottom > prev_rect.bottom ? this_rect.bottom | 1529 FX_FLOAT bottom = this_rect.bottom > prev_rect.bottom ? this_rect.bottom |
1540 : prev_rect.bottom; | 1530 : prev_rect.bottom; |
1541 if (bottom >= top) { | 1531 if (bottom >= top) { |
1542 if (IsHyphen(curChar)) { | 1532 return IsHyphen(curChar) ? GenerateCharacter::Hyphen |
1543 return 3; | 1533 : GenerateCharacter::LineBreak; |
1544 } | |
1545 return 2; | |
1546 } | 1534 } |
1547 } | 1535 } |
1548 } else if (WritingMode == 1) { | 1536 } else if (WritingMode == TextOrientation::Vertical) { |
1549 if (this_rect.Width() > pObj->GetFontSize() * 0.1f && | 1537 if (this_rect.Width() > pObj->GetFontSize() * 0.1f && |
1550 prev_rect.Width() > m_pPreTextObj->GetFontSize() * 0.1f) { | 1538 prev_rect.Width() > m_pPreTextObj->GetFontSize() * 0.1f) { |
1551 FX_FLOAT left = this_rect.left > m_CurlineRect.left ? this_rect.left | 1539 FX_FLOAT left = this_rect.left > m_CurlineRect.left ? this_rect.left |
1552 : m_CurlineRect.left; | 1540 : m_CurlineRect.left; |
1553 FX_FLOAT right = this_rect.right < m_CurlineRect.right | 1541 FX_FLOAT right = this_rect.right < m_CurlineRect.right |
1554 ? this_rect.right | 1542 ? this_rect.right |
1555 : m_CurlineRect.right; | 1543 : m_CurlineRect.right; |
1556 if (right <= left) { | 1544 if (right <= left) { |
1557 if (IsHyphen(curChar)) { | 1545 return IsHyphen(curChar) ? GenerateCharacter::Hyphen |
1558 return 3; | 1546 : GenerateCharacter::LineBreak; |
1559 } | |
1560 return 2; | |
1561 } | 1547 } |
1562 } | 1548 } |
1563 } | 1549 } |
1564 FX_FLOAT last_pos = PrevItem.m_OriginX; | 1550 FX_FLOAT last_pos = PrevItem.m_OriginX; |
1565 int nLastWidth = GetCharWidth(PrevItem.m_CharCode, m_pPreTextObj->GetFont()); | 1551 int nLastWidth = GetCharWidth(PrevItem.m_CharCode, m_pPreTextObj->GetFont()); |
1566 FX_FLOAT last_width = nLastWidth * m_pPreTextObj->GetFontSize() / 1000; | 1552 FX_FLOAT last_width = nLastWidth * m_pPreTextObj->GetFontSize() / 1000; |
1567 last_width = FXSYS_fabs(last_width); | 1553 last_width = FXSYS_fabs(last_width); |
1568 int nThisWidth = GetCharWidth(item.m_CharCode, pObj->GetFont()); | 1554 int nThisWidth = GetCharWidth(item.m_CharCode, pObj->GetFont()); |
1569 FX_FLOAT this_width = nThisWidth * pObj->GetFontSize() / 1000; | 1555 FX_FLOAT this_width = nThisWidth * pObj->GetFontSize() / 1000; |
1570 this_width = FXSYS_fabs(this_width); | 1556 this_width = FXSYS_fabs(this_width); |
1571 FX_FLOAT threshold = | 1557 FX_FLOAT threshold = |
1572 last_width > this_width ? last_width / 4 : this_width / 4; | 1558 last_width > this_width ? last_width / 4 : this_width / 4; |
1573 CFX_Matrix prev_matrix, prev_reverse; | 1559 CFX_Matrix prev_matrix, prev_reverse; |
1574 m_pPreTextObj->GetTextMatrix(&prev_matrix); | 1560 m_pPreTextObj->GetTextMatrix(&prev_matrix); |
1575 prev_matrix.Concat(m_perMatrix); | 1561 prev_matrix.Concat(m_perMatrix); |
1576 prev_reverse.SetReverse(prev_matrix); | 1562 prev_reverse.SetReverse(prev_matrix); |
1577 FX_FLOAT x = pObj->GetPosX(); | 1563 FX_FLOAT x = pObj->GetPosX(); |
1578 FX_FLOAT y = pObj->GetPosY(); | 1564 FX_FLOAT y = pObj->GetPosY(); |
1579 formMatrix.Transform(x, y); | 1565 formMatrix.Transform(x, y); |
1580 prev_reverse.Transform(x, y); | 1566 prev_reverse.Transform(x, y); |
1581 if (last_width < this_width) { | 1567 if (last_width < this_width) { |
1582 threshold = prev_reverse.TransformDistance(threshold); | 1568 threshold = prev_reverse.TransformDistance(threshold); |
1583 } | 1569 } |
1584 CFX_FloatRect rect1(m_pPreTextObj->m_Left, pObj->m_Bottom, | 1570 CFX_FloatRect rect1(m_pPreTextObj->m_Left, pObj->m_Bottom, |
1585 m_pPreTextObj->m_Right, pObj->m_Top); | 1571 m_pPreTextObj->m_Right, pObj->m_Top); |
1586 CFX_FloatRect rect2(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom, | 1572 CFX_FloatRect rect2(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom, |
1587 m_pPreTextObj->m_Right, m_pPreTextObj->m_Top); | 1573 m_pPreTextObj->m_Right, m_pPreTextObj->m_Top); |
1588 CFX_FloatRect rect3 = rect1; | 1574 CFX_FloatRect rect3 = rect1; |
1589 rect1.Intersect(rect2); | 1575 rect1.Intersect(rect2); |
1590 if (WritingMode == 0) { | 1576 if (WritingMode == TextOrientation::Horizontal) { |
1591 if ((rect1.IsEmpty() && rect2.Height() > 5 && rect3.Height() > 5) || | 1577 if ((rect1.IsEmpty() && rect2.Height() > 5 && rect3.Height() > 5) || |
1592 ((y > threshold * 2 || y < threshold * -3) && | 1578 ((y > threshold * 2 || y < threshold * -3) && |
1593 (FXSYS_fabs(y) < 1 ? FXSYS_fabs(x) < FXSYS_fabs(y) : TRUE))) { | 1579 (FXSYS_fabs(y) < 1 ? FXSYS_fabs(x) < FXSYS_fabs(y) : TRUE))) { |
1594 bNewline = TRUE; | 1580 bNewline = TRUE; |
1595 if (nItem > 1) { | 1581 if (nItem > 1) { |
1596 CPDF_TextObjectItem tempItem; | 1582 CPDF_TextObjectItem tempItem; |
1597 m_pPreTextObj->GetItemInfo(0, &tempItem); | 1583 m_pPreTextObj->GetItemInfo(0, &tempItem); |
1598 CFX_Matrix m; | 1584 CFX_Matrix m; |
1599 m_pPreTextObj->GetTextMatrix(&m); | 1585 m_pPreTextObj->GetTextMatrix(&m); |
1600 if (PrevItem.m_OriginX > tempItem.m_OriginX && | 1586 if (PrevItem.m_OriginX > tempItem.m_OriginX && |
1601 m_DisplayMatrix.a > 0.9 && m_DisplayMatrix.b < 0.1 && | 1587 m_DisplayMatrix.a > 0.9 && m_DisplayMatrix.b < 0.1 && |
1602 m_DisplayMatrix.c < 0.1 && m_DisplayMatrix.d < -0.9 && m.b < 0.1 && | 1588 m_DisplayMatrix.c < 0.1 && m_DisplayMatrix.d < -0.9 && m.b < 0.1 && |
1603 m.c < 0.1) { | 1589 m.c < 0.1) { |
1604 CFX_FloatRect re(0, m_pPreTextObj->m_Bottom, 1000, | 1590 CFX_FloatRect re(0, m_pPreTextObj->m_Bottom, 1000, |
1605 m_pPreTextObj->m_Top); | 1591 m_pPreTextObj->m_Top); |
1606 if (re.Contains(pObj->GetPosX(), pObj->GetPosY())) { | 1592 if (re.Contains(pObj->GetPosX(), pObj->GetPosY())) { |
1607 bNewline = FALSE; | 1593 bNewline = FALSE; |
1608 } else { | 1594 } else { |
1609 CFX_FloatRect rect(0, pObj->m_Bottom, 1000, pObj->m_Top); | 1595 CFX_FloatRect rect(0, pObj->m_Bottom, 1000, pObj->m_Top); |
1610 if (rect.Contains(m_pPreTextObj->GetPosX(), | 1596 if (rect.Contains(m_pPreTextObj->GetPosX(), |
1611 m_pPreTextObj->GetPosY())) { | 1597 m_pPreTextObj->GetPosY())) { |
1612 bNewline = FALSE; | 1598 bNewline = FALSE; |
1613 } | 1599 } |
1614 } | 1600 } |
1615 } | 1601 } |
1616 } | 1602 } |
1617 } | 1603 } |
1618 } | 1604 } |
1619 if (bNewline) | 1605 if (bNewline) { |
1620 return IsHyphen(curChar) ? 3 : 2; | 1606 return IsHyphen(curChar) ? GenerateCharacter::Hyphen |
1607 : GenerateCharacter::LineBreak; | |
1608 } | |
1621 | 1609 |
1622 int32_t nChars = pObj->CountChars(); | 1610 int32_t nChars = pObj->CountChars(); |
1623 if (nChars == 1 && (0x2D == curChar || 0xAD == curChar) && | 1611 if (nChars == 1 && (0x2D == curChar || 0xAD == curChar) && |
1624 IsHyphen(curChar)) { | 1612 IsHyphen(curChar)) { |
1625 return 3; | 1613 return GenerateCharacter::Hyphen; |
1626 } | 1614 } |
1627 CFX_WideString PrevStr = | 1615 CFX_WideString PrevStr = |
1628 m_pPreTextObj->GetFont()->UnicodeFromCharCode(PrevItem.m_CharCode); | 1616 m_pPreTextObj->GetFont()->UnicodeFromCharCode(PrevItem.m_CharCode); |
1629 FX_WCHAR preChar = PrevStr.GetAt(PrevStr.GetLength() - 1); | 1617 FX_WCHAR preChar = PrevStr.GetAt(PrevStr.GetLength() - 1); |
1630 CFX_Matrix matrix; | 1618 CFX_Matrix matrix; |
1631 pObj->GetTextMatrix(&matrix); | 1619 pObj->GetTextMatrix(&matrix); |
1632 matrix.Concat(formMatrix); | 1620 matrix.Concat(formMatrix); |
1633 threshold = (FX_FLOAT)(nLastWidth > nThisWidth ? nLastWidth : nThisWidth); | 1621 threshold = (FX_FLOAT)(nLastWidth > nThisWidth ? nLastWidth : nThisWidth); |
1634 threshold = threshold > 400 | 1622 threshold = threshold > 400 |
1635 ? (threshold < 700 | 1623 ? (threshold < 700 |
(...skipping 10 matching lines...) Expand all Loading... | |
1646 threshold /= 1000; | 1634 threshold /= 1000; |
1647 if ((threshold < 1.4881 && threshold > 1.4879) || | 1635 if ((threshold < 1.4881 && threshold > 1.4879) || |
1648 (threshold < 1.39001 && threshold > 1.38999)) { | 1636 (threshold < 1.39001 && threshold > 1.38999)) { |
1649 threshold *= 1.5; | 1637 threshold *= 1.5; |
1650 } | 1638 } |
1651 if (FXSYS_fabs(last_pos + last_width - x) > threshold && curChar != L' ' && | 1639 if (FXSYS_fabs(last_pos + last_width - x) > threshold && curChar != L' ' && |
1652 preChar != L' ') { | 1640 preChar != L' ') { |
1653 if (curChar != L' ' && preChar != L' ') { | 1641 if (curChar != L' ' && preChar != L' ') { |
1654 if ((x - last_pos - last_width) > threshold || | 1642 if ((x - last_pos - last_width) > threshold || |
1655 (last_pos - x - last_width) > threshold) { | 1643 (last_pos - x - last_width) > threshold) { |
1656 return 1; | 1644 return GenerateCharacter::Blank; |
dsinclair
2016/06/14 19:40:13
Does blank mean '' or ' '? If the latter, would Sp
Lei Zhang
2016/06/14 20:01:15
I was going along with TEXT_BLANK_FOO. Renamed the
| |
1657 } | 1645 } |
1658 if (x < 0 && (last_pos - x - last_width) > threshold) { | 1646 if (x < 0 && (last_pos - x - last_width) > threshold) { |
1659 return 1; | 1647 return GenerateCharacter::Blank; |
1660 } | 1648 } |
1661 if ((x - last_pos - last_width) > this_width || | 1649 if ((x - last_pos - last_width) > this_width || |
1662 (x - last_pos - this_width) > last_width) { | 1650 (x - last_pos - this_width) > last_width) { |
1663 return 1; | 1651 return GenerateCharacter::Blank; |
1664 } | 1652 } |
1665 } | 1653 } |
1666 } | 1654 } |
1667 return 0; | 1655 return GenerateCharacter::None; |
1668 } | 1656 } |
1669 | 1657 |
1670 FX_BOOL CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1, | 1658 FX_BOOL CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1, |
1671 CPDF_TextObject* pTextObj2) { | 1659 CPDF_TextObject* pTextObj2) { |
1672 if (!pTextObj1 || !pTextObj2) { | 1660 if (!pTextObj1 || !pTextObj2) { |
1673 return FALSE; | 1661 return FALSE; |
1674 } | 1662 } |
1675 CFX_FloatRect rcPreObj(pTextObj2->m_Left, pTextObj2->m_Bottom, | 1663 CFX_FloatRect rcPreObj(pTextObj2->m_Left, pTextObj2->m_Bottom, |
1676 pTextObj2->m_Right, pTextObj2->m_Top); | 1664 pTextObj2->m_Right, pTextObj2->m_Top); |
1677 CFX_FloatRect rcCurObj(pTextObj1->m_Left, pTextObj1->m_Bottom, | 1665 CFX_FloatRect rcCurObj(pTextObj1->m_Left, pTextObj1->m_Bottom, |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2336 return index < m_LinkArray.size() ? m_LinkArray[index].m_strUrl : L""; | 2324 return index < m_LinkArray.size() ? m_LinkArray[index].m_strUrl : L""; |
2337 } | 2325 } |
2338 | 2326 |
2339 std::vector<CFX_FloatRect> CPDF_LinkExtract::GetRects(size_t index) const { | 2327 std::vector<CFX_FloatRect> CPDF_LinkExtract::GetRects(size_t index) const { |
2340 if (index >= m_LinkArray.size()) | 2328 if (index >= m_LinkArray.size()) |
2341 return std::vector<CFX_FloatRect>(); | 2329 return std::vector<CFX_FloatRect>(); |
2342 | 2330 |
2343 return m_pTextPage->GetRectArray(m_LinkArray[index].m_Start, | 2331 return m_pTextPage->GetRectArray(m_LinkArray[index].m_Start, |
2344 m_LinkArray[index].m_Count); | 2332 m_LinkArray[index].m_Count); |
2345 } | 2333 } |
OLD | NEW |