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 "fpdfsdk/fxedit/fxet_edit.h" | 7 #include "fpdfsdk/fxedit/fxet_edit.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 pDevice, CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | 929 pDevice, CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
930 pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device, | 930 pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device, |
931 sTextBuf.MakeString(), crOldFill, crTextStroke, nHorzScale); | 931 sTextBuf.MakeString(), crOldFill, crTextStroke, nHorzScale); |
932 } | 932 } |
933 } | 933 } |
934 | 934 |
935 pDevice->RestoreState(false); | 935 pDevice->RestoreState(false); |
936 } | 936 } |
937 | 937 |
938 // static | 938 // static |
939 void CFX_Edit::GeneratePageObjects( | 939 void CFX_Edit::GeneratePageObjects(CPDF_PageObjectHolder* pObjectHolder, |
940 CPDF_PageObjectHolder* pObjectHolder, | 940 CFX_Edit* pEdit, |
941 CFX_Edit* pEdit, | 941 const CFX_FloatPoint& ptOffset, |
942 const CFX_FloatPoint& ptOffset, | 942 const CPVT_WordRange* pRange, |
943 const CPVT_WordRange* pRange, | 943 FX_COLORREF crText, |
944 FX_COLORREF crText, | 944 std::vector<CPDF_TextObject*>* ObjArray) { |
945 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { | 945 ObjArray->clear(); |
| 946 |
| 947 IPVT_FontMap* pFontMap = pEdit->GetFontMap(); |
| 948 if (!pFontMap) |
| 949 return; |
| 950 |
946 FX_FLOAT fFontSize = pEdit->GetFontSize(); | 951 FX_FLOAT fFontSize = pEdit->GetFontSize(); |
| 952 int32_t nOldFontIndex = -1; |
| 953 CFX_ByteTextBuf sTextBuf; |
| 954 CPVT_WordPlace oldplace; |
| 955 CFX_FloatPoint ptBT(0.0f, 0.0f); |
| 956 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); |
| 957 if (pRange) |
| 958 pIterator->SetAt(pRange->BeginPos); |
| 959 else |
| 960 pIterator->SetAt(0); |
947 | 961 |
948 int32_t nOldFontIndex = -1; | 962 while (pIterator->NextWord()) { |
| 963 CPVT_WordPlace place = pIterator->GetAt(); |
| 964 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 965 break; |
949 | 966 |
950 CFX_ByteTextBuf sTextBuf; | 967 CPVT_Word word; |
951 CFX_FloatPoint ptBT(0.0f, 0.0f); | 968 if (!pIterator->GetWord(word)) |
| 969 continue; |
952 | 970 |
953 ObjArray.RemoveAll(); | 971 if (place.LineCmp(oldplace) != 0 || nOldFontIndex != word.nFontIndex) { |
| 972 if (sTextBuf.GetLength() > 0) { |
| 973 ObjArray->push_back(AddTextObjToPageObjects( |
| 974 pObjectHolder, crText, pFontMap->GetPDFFont(nOldFontIndex), |
| 975 fFontSize, 0.0f, 100, |
| 976 CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 977 sTextBuf.MakeString())); |
954 | 978 |
955 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); | 979 sTextBuf.Clear(); |
956 if (IPVT_FontMap* pFontMap = pEdit->GetFontMap()) { | |
957 if (pRange) | |
958 pIterator->SetAt(pRange->BeginPos); | |
959 else | |
960 pIterator->SetAt(0); | |
961 | |
962 CPVT_WordPlace oldplace; | |
963 | |
964 while (pIterator->NextWord()) { | |
965 CPVT_WordPlace place = pIterator->GetAt(); | |
966 if (pRange && place.WordCmp(pRange->EndPos) > 0) | |
967 break; | |
968 | |
969 CPVT_Word word; | |
970 if (pIterator->GetWord(word)) { | |
971 if (place.LineCmp(oldplace) != 0 || nOldFontIndex != word.nFontIndex) { | |
972 if (sTextBuf.GetLength() > 0) { | |
973 ObjArray.Add(AddTextObjToPageObjects( | |
974 pObjectHolder, crText, pFontMap->GetPDFFont(nOldFontIndex), | |
975 fFontSize, 0.0f, 100, | |
976 CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | |
977 sTextBuf.MakeString())); | |
978 | |
979 sTextBuf.Clear(); | |
980 } | |
981 | |
982 ptBT = word.ptWord; | |
983 nOldFontIndex = word.nFontIndex; | |
984 } | |
985 | |
986 sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, 0) | |
987 .AsStringC(); | |
988 oldplace = place; | |
989 } | 980 } |
| 981 ptBT = word.ptWord; |
| 982 nOldFontIndex = word.nFontIndex; |
990 } | 983 } |
991 | 984 sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, 0) |
992 if (sTextBuf.GetLength() > 0) { | 985 .AsStringC(); |
993 ObjArray.Add(AddTextObjToPageObjects( | 986 oldplace = place; |
994 pObjectHolder, crText, pFontMap->GetPDFFont(nOldFontIndex), fFontSize, | 987 } |
995 0.0f, 100, CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | 988 if (sTextBuf.GetLength() > 0) { |
996 sTextBuf.MakeString())); | 989 ObjArray->push_back(AddTextObjToPageObjects( |
997 } | 990 pObjectHolder, crText, pFontMap->GetPDFFont(nOldFontIndex), fFontSize, |
| 991 0.0f, 100, CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 992 sTextBuf.MakeString())); |
998 } | 993 } |
999 } | 994 } |
1000 | 995 |
1001 CFX_Edit::CFX_Edit() | 996 CFX_Edit::CFX_Edit() |
1002 : m_pVT(new CPDF_VariableText), | 997 : m_pVT(new CPDF_VariableText), |
1003 m_pNotify(nullptr), | 998 m_pNotify(nullptr), |
1004 m_pOprNotify(nullptr), | 999 m_pOprNotify(nullptr), |
1005 m_wpCaret(-1, -1, -1), | 1000 m_wpCaret(-1, -1, -1), |
1006 m_wpOldCaret(-1, -1, -1), | 1001 m_wpOldCaret(-1, -1, -1), |
1007 m_SelState(), | 1002 m_SelState(), |
(...skipping 1518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2526 int32_t CFX_Edit_RectArray::GetSize() const { | 2521 int32_t CFX_Edit_RectArray::GetSize() const { |
2527 return m_Rects.GetSize(); | 2522 return m_Rects.GetSize(); |
2528 } | 2523 } |
2529 | 2524 |
2530 CFX_FloatRect* CFX_Edit_RectArray::GetAt(int32_t nIndex) const { | 2525 CFX_FloatRect* CFX_Edit_RectArray::GetAt(int32_t nIndex) const { |
2531 if (nIndex < 0 || nIndex >= m_Rects.GetSize()) | 2526 if (nIndex < 0 || nIndex >= m_Rects.GetSize()) |
2532 return nullptr; | 2527 return nullptr; |
2533 | 2528 |
2534 return m_Rects.GetAt(nIndex); | 2529 return m_Rects.GetAt(nIndex); |
2535 } | 2530 } |
OLD | NEW |