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/include/fxet_edit.h" | 7 #include "fpdfsdk/fxedit/include/fxet_edit.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 11 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| 12 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" |
| 13 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h" |
| 14 #include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h" |
| 15 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" |
| 16 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" |
| 17 #include "core/fpdfapi/fpdf_render/include/cpdf_textrenderer.h" |
12 #include "core/fpdfdoc/include/cpvt_section.h" | 18 #include "core/fpdfdoc/include/cpvt_section.h" |
13 #include "core/fpdfdoc/include/cpvt_word.h" | 19 #include "core/fpdfdoc/include/cpvt_word.h" |
14 #include "core/fpdfdoc/include/ipvt_fontmap.h" | 20 #include "core/fpdfdoc/include/ipvt_fontmap.h" |
| 21 #include "core/fxge/include/fx_ge.h" |
| 22 #include "fpdfsdk/cfx_systemhandler.h" |
| 23 #include "fpdfsdk/fxedit/include/fx_edit.h" |
| 24 #include "fpdfsdk/fxedit/include/fxet_edit.h" |
| 25 #include "fpdfsdk/pdfwindow/PWL_Edit.h" |
| 26 #include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" |
| 27 |
| 28 #define PVTWORD_STYLE_UNDERLINE 0x0002L |
| 29 #define PVTWORD_STYLE_CROSSOUT 0x0004L |
| 30 #define PVTWORD_STYLE_BOLD 0x0020L |
| 31 #define PVTWORD_STYLE_ITALIC 0x0040L |
15 | 32 |
16 namespace { | 33 namespace { |
17 | 34 |
18 const int kEditUndoMaxItems = 10000; | 35 const int kEditUndoMaxItems = 10000; |
19 | 36 |
| 37 CFX_ByteString GetWordRenderString(const CFX_ByteString& strWords) { |
| 38 if (strWords.GetLength() > 0) |
| 39 return PDF_EncodeString(strWords) + " Tj\n"; |
| 40 return CFX_ByteString(); |
| 41 } |
| 42 |
| 43 CFX_ByteString GetFontSetString(IPVT_FontMap* pFontMap, |
| 44 int32_t nFontIndex, |
| 45 FX_FLOAT fFontSize) { |
| 46 if (!pFontMap) |
| 47 return CFX_ByteString(); |
| 48 |
| 49 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
| 50 if (sFontAlias.GetLength() <= 0 || fFontSize <= 0) |
| 51 return CFX_ByteString(); |
| 52 |
| 53 CFX_ByteTextBuf sRet; |
| 54 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
| 55 return sRet.MakeString(); |
| 56 } |
| 57 |
| 58 CFX_FloatRect GetUnderLineRect(const CPVT_Word& word) { |
| 59 return CFX_FloatRect(word.ptWord.x, word.ptWord.y + word.fDescent * 0.5f, |
| 60 word.ptWord.x + word.fWidth, |
| 61 word.ptWord.y + word.fDescent * 0.25f); |
| 62 } |
| 63 |
| 64 CFX_FloatRect GetCrossoutRect(const CPVT_Word& word) { |
| 65 return CFX_FloatRect(word.ptWord.x, |
| 66 word.ptWord.y + (word.fAscent + word.fDescent) * 0.5f + |
| 67 word.fDescent * 0.25f, |
| 68 word.ptWord.x + word.fWidth, |
| 69 word.ptWord.y + (word.fAscent + word.fDescent) * 0.5f); |
| 70 } |
| 71 |
| 72 void DrawTextString(CFX_RenderDevice* pDevice, |
| 73 const CFX_FloatPoint& pt, |
| 74 CPDF_Font* pFont, |
| 75 FX_FLOAT fFontSize, |
| 76 CFX_Matrix* pUser2Device, |
| 77 const CFX_ByteString& str, |
| 78 FX_ARGB crTextFill, |
| 79 FX_ARGB crTextStroke, |
| 80 int32_t nHorzScale) { |
| 81 FX_FLOAT x = pt.x, y = pt.y; |
| 82 pUser2Device->Transform(x, y); |
| 83 |
| 84 if (pFont) { |
| 85 if (nHorzScale != 100) { |
| 86 CFX_Matrix mt(nHorzScale / 100.0f, 0, 0, 1, 0, 0); |
| 87 mt.Concat(*pUser2Device); |
| 88 |
| 89 CPDF_RenderOptions ro; |
| 90 ro.m_Flags = RENDER_CLEARTYPE; |
| 91 ro.m_ColorMode = RENDER_COLOR_NORMAL; |
| 92 |
| 93 if (crTextStroke != 0) { |
| 94 CFX_FloatPoint pt1(0, 0), pt2(1, 0); |
| 95 pUser2Device->Transform(pt1.x, pt1.y); |
| 96 pUser2Device->Transform(pt2.x, pt2.y); |
| 97 CFX_GraphStateData gsd; |
| 98 gsd.m_LineWidth = |
| 99 (FX_FLOAT)FXSYS_fabs((pt2.x + pt2.y) - (pt1.x + pt1.y)); |
| 100 |
| 101 CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, &mt, |
| 102 str, crTextFill, crTextStroke, &gsd, |
| 103 &ro); |
| 104 } else { |
| 105 CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, &mt, |
| 106 str, crTextFill, 0, nullptr, &ro); |
| 107 } |
| 108 } else { |
| 109 CPDF_RenderOptions ro; |
| 110 ro.m_Flags = RENDER_CLEARTYPE; |
| 111 ro.m_ColorMode = RENDER_COLOR_NORMAL; |
| 112 |
| 113 if (crTextStroke != 0) { |
| 114 CFX_FloatPoint pt1(0, 0), pt2(1, 0); |
| 115 pUser2Device->Transform(pt1.x, pt1.y); |
| 116 pUser2Device->Transform(pt2.x, pt2.y); |
| 117 CFX_GraphStateData gsd; |
| 118 gsd.m_LineWidth = |
| 119 (FX_FLOAT)FXSYS_fabs((pt2.x + pt2.y) - (pt1.x + pt1.y)); |
| 120 |
| 121 CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, |
| 122 pUser2Device, str, crTextFill, |
| 123 crTextStroke, &gsd, &ro); |
| 124 } else { |
| 125 CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, |
| 126 pUser2Device, str, crTextFill, 0, |
| 127 nullptr, &ro); |
| 128 } |
| 129 } |
| 130 } |
| 131 } |
| 132 |
| 133 void AddRectToPageObjects(CPDF_PageObjectHolder* pObjectHolder, |
| 134 FX_COLORREF crFill, |
| 135 const CFX_FloatRect& rcFill) { |
| 136 std::unique_ptr<CPDF_PathObject> pPathObj(new CPDF_PathObject); |
| 137 CFX_PathData* pPathData = pPathObj->m_Path.GetModify(); |
| 138 pPathData->AppendRect(rcFill.left, rcFill.bottom, rcFill.right, rcFill.top); |
| 139 |
| 140 FX_FLOAT rgb[3]; |
| 141 rgb[0] = FXARGB_R(crFill) / 255.0f; |
| 142 rgb[1] = FXARGB_G(crFill) / 255.0f; |
| 143 rgb[2] = FXARGB_B(crFill) / 255.0f; |
| 144 pPathObj->m_ColorState.SetFillColor( |
| 145 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); |
| 146 |
| 147 pPathObj->m_FillType = FXFILL_ALTERNATE; |
| 148 pPathObj->m_bStroke = FALSE; |
| 149 pObjectHolder->GetPageObjectList()->push_back(std::move(pPathObj)); |
| 150 } |
| 151 |
| 152 CPDF_TextObject* AddTextObjToPageObjects(CPDF_PageObjectHolder* pObjectHolder, |
| 153 FX_COLORREF crText, |
| 154 CPDF_Font* pFont, |
| 155 FX_FLOAT fFontSize, |
| 156 FX_FLOAT fCharSpace, |
| 157 int32_t nHorzScale, |
| 158 const CFX_FloatPoint& point, |
| 159 const CFX_ByteString& text) { |
| 160 std::unique_ptr<CPDF_TextObject> pTxtObj(new CPDF_TextObject); |
| 161 CPDF_TextStateData* pTextStateData = pTxtObj->m_TextState.GetModify(); |
| 162 pTextStateData->m_pFont = pFont; |
| 163 pTextStateData->m_FontSize = fFontSize; |
| 164 pTextStateData->m_CharSpace = fCharSpace; |
| 165 pTextStateData->m_WordSpace = 0; |
| 166 pTextStateData->m_TextMode = TextRenderingMode::MODE_FILL; |
| 167 pTextStateData->m_Matrix[0] = nHorzScale / 100.0f; |
| 168 pTextStateData->m_Matrix[1] = 0; |
| 169 pTextStateData->m_Matrix[2] = 0; |
| 170 pTextStateData->m_Matrix[3] = 1; |
| 171 |
| 172 FX_FLOAT rgb[3]; |
| 173 rgb[0] = FXARGB_R(crText) / 255.0f; |
| 174 rgb[1] = FXARGB_G(crText) / 255.0f; |
| 175 rgb[2] = FXARGB_B(crText) / 255.0f; |
| 176 pTxtObj->m_ColorState.SetFillColor( |
| 177 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); |
| 178 pTxtObj->m_ColorState.SetStrokeColor( |
| 179 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); |
| 180 |
| 181 pTxtObj->SetPosition(point.x, point.y); |
| 182 pTxtObj->SetText(text); |
| 183 |
| 184 CPDF_TextObject* pRet = pTxtObj.get(); |
| 185 pObjectHolder->GetPageObjectList()->push_back(std::move(pTxtObj)); |
| 186 return pRet; |
| 187 } |
| 188 |
20 } // namespace | 189 } // namespace |
21 | 190 |
22 CFX_Edit_Iterator::CFX_Edit_Iterator(CFX_Edit* pEdit, | 191 CFX_Edit_Iterator::CFX_Edit_Iterator(CFX_Edit* pEdit, |
23 CPDF_VariableText::Iterator* pVTIterator) | 192 CPDF_VariableText::Iterator* pVTIterator) |
24 : m_pEdit(pEdit), m_pVTIterator(pVTIterator) {} | 193 : m_pEdit(pEdit), m_pVTIterator(pVTIterator) {} |
25 | 194 |
26 CFX_Edit_Iterator::~CFX_Edit_Iterator() {} | 195 CFX_Edit_Iterator::~CFX_Edit_Iterator() {} |
27 | 196 |
28 FX_BOOL CFX_Edit_Iterator::NextWord() { | 197 FX_BOOL CFX_Edit_Iterator::NextWord() { |
29 return m_pVTIterator->NextWord(); | 198 return m_pVTIterator->NextWord(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 253 } |
85 | 254 |
86 void CFX_Edit_Iterator::SetAt(const CPVT_WordPlace& place) { | 255 void CFX_Edit_Iterator::SetAt(const CPVT_WordPlace& place) { |
87 m_pVTIterator->SetAt(place); | 256 m_pVTIterator->SetAt(place); |
88 } | 257 } |
89 | 258 |
90 const CPVT_WordPlace& CFX_Edit_Iterator::GetAt() const { | 259 const CPVT_WordPlace& CFX_Edit_Iterator::GetAt() const { |
91 return m_pVTIterator->GetAt(); | 260 return m_pVTIterator->GetAt(); |
92 } | 261 } |
93 | 262 |
94 IFX_Edit* CFX_Edit_Iterator::GetEdit() const { | 263 CFX_Edit* CFX_Edit_Iterator::GetEdit() const { |
95 return m_pEdit; | 264 return m_pEdit; |
96 } | 265 } |
97 | 266 |
98 CFX_Edit_Provider::CFX_Edit_Provider(IPVT_FontMap* pFontMap) | 267 CFX_Edit_Provider::CFX_Edit_Provider(IPVT_FontMap* pFontMap) |
99 : CPDF_VariableText::Provider(pFontMap), m_pFontMap(pFontMap) { | 268 : CPDF_VariableText::Provider(pFontMap), m_pFontMap(pFontMap) { |
100 ASSERT(m_pFontMap); | 269 ASSERT(m_pFontMap); |
101 } | 270 } |
102 | 271 |
103 CFX_Edit_Provider::~CFX_Edit_Provider() {} | 272 CFX_Edit_Provider::~CFX_Edit_Provider() {} |
104 | 273 |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 } | 807 } |
639 | 808 |
640 void CFXEU_InsertText::Undo() { | 809 void CFXEU_InsertText::Undo() { |
641 if (m_pEdit) { | 810 if (m_pEdit) { |
642 m_pEdit->SelectNone(); | 811 m_pEdit->SelectNone(); |
643 m_pEdit->SetSel(m_wpOld, m_wpNew); | 812 m_pEdit->SetSel(m_wpOld, m_wpNew); |
644 m_pEdit->Clear(FALSE, TRUE); | 813 m_pEdit->Clear(FALSE, TRUE); |
645 } | 814 } |
646 } | 815 } |
647 | 816 |
648 CFX_Edit::CFX_Edit(CPDF_VariableText* pVT) | 817 // static |
649 : m_pVT(pVT), | 818 CFX_ByteString CFX_Edit::GetEditAppearanceStream(CFX_Edit* pEdit, |
| 819 const CFX_FloatPoint& ptOffset, |
| 820 const CPVT_WordRange* pRange, |
| 821 FX_BOOL bContinuous, |
| 822 uint16_t SubWord) { |
| 823 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); |
| 824 if (pRange) |
| 825 pIterator->SetAt(pRange->BeginPos); |
| 826 else |
| 827 pIterator->SetAt(0); |
| 828 |
| 829 CFX_ByteTextBuf sEditStream; |
| 830 CFX_ByteTextBuf sWords; |
| 831 int32_t nCurFontIndex = -1; |
| 832 CFX_FloatPoint ptOld(0.0f, 0.0f); |
| 833 CFX_FloatPoint ptNew(0.0f, 0.0f); |
| 834 CPVT_WordPlace oldplace; |
| 835 while (pIterator->NextWord()) { |
| 836 CPVT_WordPlace place = pIterator->GetAt(); |
| 837 |
| 838 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 839 break; |
| 840 |
| 841 if (bContinuous) { |
| 842 if (place.LineCmp(oldplace) != 0) { |
| 843 if (sWords.GetSize() > 0) { |
| 844 sEditStream << GetWordRenderString(sWords.MakeString()); |
| 845 sWords.Clear(); |
| 846 } |
| 847 |
| 848 CPVT_Word word; |
| 849 if (pIterator->GetWord(word)) { |
| 850 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, |
| 851 word.ptWord.y + ptOffset.y); |
| 852 } else { |
| 853 CPVT_Line line; |
| 854 pIterator->GetLine(line); |
| 855 ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x, |
| 856 line.ptLine.y + ptOffset.y); |
| 857 } |
| 858 |
| 859 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { |
| 860 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
| 861 << " Td\n"; |
| 862 |
| 863 ptOld = ptNew; |
| 864 } |
| 865 } |
| 866 |
| 867 CPVT_Word word; |
| 868 if (pIterator->GetWord(word)) { |
| 869 if (word.nFontIndex != nCurFontIndex) { |
| 870 if (sWords.GetSize() > 0) { |
| 871 sEditStream << GetWordRenderString(sWords.MakeString()); |
| 872 sWords.Clear(); |
| 873 } |
| 874 sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex, |
| 875 word.fFontSize); |
| 876 nCurFontIndex = word.nFontIndex; |
| 877 } |
| 878 |
| 879 sWords << GetPDFWordString(pEdit->GetFontMap(), nCurFontIndex, |
| 880 word.Word, SubWord); |
| 881 } |
| 882 |
| 883 oldplace = place; |
| 884 } else { |
| 885 CPVT_Word word; |
| 886 if (pIterator->GetWord(word)) { |
| 887 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, |
| 888 word.ptWord.y + ptOffset.y); |
| 889 |
| 890 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { |
| 891 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
| 892 << " Td\n"; |
| 893 ptOld = ptNew; |
| 894 } |
| 895 |
| 896 if (word.nFontIndex != nCurFontIndex) { |
| 897 sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex, |
| 898 word.fFontSize); |
| 899 nCurFontIndex = word.nFontIndex; |
| 900 } |
| 901 |
| 902 sEditStream << GetWordRenderString(GetPDFWordString( |
| 903 pEdit->GetFontMap(), nCurFontIndex, word.Word, SubWord)); |
| 904 } |
| 905 } |
| 906 } |
| 907 |
| 908 if (sWords.GetSize() > 0) { |
| 909 sEditStream << GetWordRenderString(sWords.MakeString()); |
| 910 sWords.Clear(); |
| 911 } |
| 912 |
| 913 CFX_ByteTextBuf sAppStream; |
| 914 if (sEditStream.GetSize() > 0) { |
| 915 int32_t nHorzScale = pEdit->GetHorzScale(); |
| 916 if (nHorzScale != 100) { |
| 917 sAppStream << nHorzScale << " Tz\n"; |
| 918 } |
| 919 |
| 920 FX_FLOAT fCharSpace = pEdit->GetCharSpace(); |
| 921 if (!FX_EDIT_IsFloatZero(fCharSpace)) { |
| 922 sAppStream << fCharSpace << " Tc\n"; |
| 923 } |
| 924 |
| 925 sAppStream << sEditStream; |
| 926 } |
| 927 |
| 928 return sAppStream.MakeString(); |
| 929 } |
| 930 |
| 931 // static |
| 932 CFX_ByteString CFX_Edit::GetSelectAppearanceStream( |
| 933 CFX_Edit* pEdit, |
| 934 const CFX_FloatPoint& ptOffset, |
| 935 const CPVT_WordRange* pRange) { |
| 936 if (!pRange || !pRange->IsExist()) |
| 937 return CFX_ByteString(); |
| 938 |
| 939 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); |
| 940 pIterator->SetAt(pRange->BeginPos); |
| 941 |
| 942 CFX_ByteTextBuf sRet; |
| 943 while (pIterator->NextWord()) { |
| 944 CPVT_WordPlace place = pIterator->GetAt(); |
| 945 if (place.WordCmp(pRange->EndPos) > 0) |
| 946 break; |
| 947 |
| 948 CPVT_Word word; |
| 949 CPVT_Line line; |
| 950 if (pIterator->GetWord(word) && pIterator->GetLine(line)) { |
| 951 sRet << word.ptWord.x + ptOffset.x << " " |
| 952 << line.ptLine.y + line.fLineDescent << " " << word.fWidth << " " |
| 953 << line.fLineAscent - line.fLineDescent << " re\nf\n"; |
| 954 } |
| 955 } |
| 956 |
| 957 return sRet.MakeString(); |
| 958 } |
| 959 |
| 960 // static |
| 961 void CFX_Edit::DrawUnderline(CFX_RenderDevice* pDevice, |
| 962 CFX_Matrix* pUser2Device, |
| 963 CFX_Edit* pEdit, |
| 964 FX_COLORREF color, |
| 965 const CFX_FloatRect& rcClip, |
| 966 const CFX_FloatPoint& ptOffset, |
| 967 const CPVT_WordRange* pRange) { |
| 968 pDevice->SaveState(); |
| 969 |
| 970 if (!rcClip.IsEmpty()) { |
| 971 CFX_FloatRect rcTemp = rcClip; |
| 972 pUser2Device->TransformRect(rcTemp); |
| 973 pDevice->SetClip_Rect(rcTemp.ToFxRect()); |
| 974 } |
| 975 |
| 976 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); |
| 977 if (pEdit->GetFontMap()) { |
| 978 if (pRange) |
| 979 pIterator->SetAt(pRange->BeginPos); |
| 980 else |
| 981 pIterator->SetAt(0); |
| 982 |
| 983 while (pIterator->NextWord()) { |
| 984 CPVT_WordPlace place = pIterator->GetAt(); |
| 985 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 986 break; |
| 987 |
| 988 CPVT_Word word; |
| 989 if (pIterator->GetWord(word)) { |
| 990 CFX_PathData pathUnderline; |
| 991 CFX_FloatRect rcUnderline = GetUnderLineRect(word); |
| 992 rcUnderline.left += ptOffset.x; |
| 993 rcUnderline.right += ptOffset.x; |
| 994 rcUnderline.top += ptOffset.y; |
| 995 rcUnderline.bottom += ptOffset.y; |
| 996 pathUnderline.AppendRect(rcUnderline.left, rcUnderline.bottom, |
| 997 rcUnderline.right, rcUnderline.top); |
| 998 |
| 999 pDevice->DrawPath(&pathUnderline, pUser2Device, nullptr, color, 0, |
| 1000 FXFILL_WINDING); |
| 1001 } |
| 1002 } |
| 1003 } |
| 1004 |
| 1005 pDevice->RestoreState(false); |
| 1006 } |
| 1007 |
| 1008 // static |
| 1009 void CFX_Edit::DrawEdit(CFX_RenderDevice* pDevice, |
| 1010 CFX_Matrix* pUser2Device, |
| 1011 CFX_Edit* pEdit, |
| 1012 FX_COLORREF crTextFill, |
| 1013 FX_COLORREF crTextStroke, |
| 1014 const CFX_FloatRect& rcClip, |
| 1015 const CFX_FloatPoint& ptOffset, |
| 1016 const CPVT_WordRange* pRange, |
| 1017 CFX_SystemHandler* pSystemHandler, |
| 1018 void* pFFLData) { |
| 1019 const bool bContinuous = |
| 1020 pEdit->GetCharArray() == 0 && pEdit->GetCharSpace() <= 0.0f; |
| 1021 uint16_t SubWord = pEdit->GetPasswordChar(); |
| 1022 FX_FLOAT fFontSize = pEdit->GetFontSize(); |
| 1023 CPVT_WordRange wrSelect = pEdit->GetSelectWordRange(); |
| 1024 int32_t nHorzScale = pEdit->GetHorzScale(); |
| 1025 |
| 1026 FX_COLORREF crCurFill = crTextFill; |
| 1027 FX_COLORREF crOldFill = crCurFill; |
| 1028 |
| 1029 FX_BOOL bSelect = FALSE; |
| 1030 const FX_COLORREF crWhite = ArgbEncode(255, 255, 255, 255); |
| 1031 const FX_COLORREF crSelBK = ArgbEncode(255, 0, 51, 113); |
| 1032 |
| 1033 CFX_ByteTextBuf sTextBuf; |
| 1034 int32_t nFontIndex = -1; |
| 1035 CFX_FloatPoint ptBT(0.0f, 0.0f); |
| 1036 |
| 1037 pDevice->SaveState(); |
| 1038 |
| 1039 if (!rcClip.IsEmpty()) { |
| 1040 CFX_FloatRect rcTemp = rcClip; |
| 1041 pUser2Device->TransformRect(rcTemp); |
| 1042 pDevice->SetClip_Rect(rcTemp.ToFxRect()); |
| 1043 } |
| 1044 |
| 1045 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); |
| 1046 if (IPVT_FontMap* pFontMap = pEdit->GetFontMap()) { |
| 1047 if (pRange) |
| 1048 pIterator->SetAt(pRange->BeginPos); |
| 1049 else |
| 1050 pIterator->SetAt(0); |
| 1051 |
| 1052 CPVT_WordPlace oldplace; |
| 1053 while (pIterator->NextWord()) { |
| 1054 CPVT_WordPlace place = pIterator->GetAt(); |
| 1055 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 1056 break; |
| 1057 |
| 1058 if (wrSelect.IsExist()) { |
| 1059 bSelect = place.WordCmp(wrSelect.BeginPos) > 0 && |
| 1060 place.WordCmp(wrSelect.EndPos) <= 0; |
| 1061 crCurFill = bSelect ? crWhite : crTextFill; |
| 1062 } |
| 1063 if (pSystemHandler && pSystemHandler->IsSelectionImplemented()) { |
| 1064 crCurFill = crTextFill; |
| 1065 crOldFill = crCurFill; |
| 1066 } |
| 1067 CPVT_Word word; |
| 1068 if (pIterator->GetWord(word)) { |
| 1069 if (bSelect) { |
| 1070 CPVT_Line line; |
| 1071 pIterator->GetLine(line); |
| 1072 |
| 1073 if (pSystemHandler && pSystemHandler->IsSelectionImplemented()) { |
| 1074 CFX_FloatRect rc(word.ptWord.x, line.ptLine.y + line.fLineDescent, |
| 1075 word.ptWord.x + word.fWidth, |
| 1076 line.ptLine.y + line.fLineAscent); |
| 1077 rc.Intersect(rcClip); |
| 1078 pSystemHandler->OutputSelectedRect(pFFLData, rc); |
| 1079 } else { |
| 1080 CFX_PathData pathSelBK; |
| 1081 pathSelBK.AppendRect( |
| 1082 word.ptWord.x, line.ptLine.y + line.fLineDescent, |
| 1083 word.ptWord.x + word.fWidth, line.ptLine.y + line.fLineAscent); |
| 1084 |
| 1085 pDevice->DrawPath(&pathSelBK, pUser2Device, nullptr, crSelBK, 0, |
| 1086 FXFILL_WINDING); |
| 1087 } |
| 1088 } |
| 1089 |
| 1090 if (bContinuous) { |
| 1091 if (place.LineCmp(oldplace) != 0 || word.nFontIndex != nFontIndex || |
| 1092 crOldFill != crCurFill) { |
| 1093 if (sTextBuf.GetLength() > 0) { |
| 1094 DrawTextString( |
| 1095 pDevice, |
| 1096 CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 1097 pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device, |
| 1098 sTextBuf.MakeString(), crOldFill, crTextStroke, nHorzScale); |
| 1099 |
| 1100 sTextBuf.Clear(); |
| 1101 } |
| 1102 nFontIndex = word.nFontIndex; |
| 1103 ptBT = word.ptWord; |
| 1104 crOldFill = crCurFill; |
| 1105 } |
| 1106 |
| 1107 sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, |
| 1108 SubWord) |
| 1109 .AsStringC(); |
| 1110 } else { |
| 1111 DrawTextString( |
| 1112 pDevice, CFX_FloatPoint(word.ptWord.x + ptOffset.x, |
| 1113 word.ptWord.y + ptOffset.y), |
| 1114 pFontMap->GetPDFFont(word.nFontIndex), fFontSize, pUser2Device, |
| 1115 GetPDFWordString(pFontMap, word.nFontIndex, word.Word, SubWord), |
| 1116 crCurFill, crTextStroke, nHorzScale); |
| 1117 } |
| 1118 oldplace = place; |
| 1119 } |
| 1120 } |
| 1121 |
| 1122 if (sTextBuf.GetLength() > 0) { |
| 1123 DrawTextString( |
| 1124 pDevice, CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 1125 pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device, |
| 1126 sTextBuf.MakeString(), crOldFill, crTextStroke, nHorzScale); |
| 1127 } |
| 1128 } |
| 1129 |
| 1130 pDevice->RestoreState(false); |
| 1131 } |
| 1132 |
| 1133 // static |
| 1134 void CFX_Edit::DrawRichEdit(CFX_RenderDevice* pDevice, |
| 1135 CFX_Matrix* pUser2Device, |
| 1136 CFX_Edit* pEdit, |
| 1137 const CFX_FloatRect& rcClip, |
| 1138 const CFX_FloatPoint& ptOffset, |
| 1139 const CPVT_WordRange* pRange) { |
| 1140 CPVT_WordRange wrSelect = pEdit->GetSelectWordRange(); |
| 1141 |
| 1142 FX_COLORREF crCurText = ArgbEncode(255, 0, 0, 0); |
| 1143 FX_COLORREF crOld = crCurText; |
| 1144 FX_BOOL bSelect = FALSE; |
| 1145 const FX_COLORREF crWhite = ArgbEncode(255, 255, 255, 255); |
| 1146 const FX_COLORREF crSelBK = ArgbEncode(255, 0, 51, 113); |
| 1147 |
| 1148 CFX_ByteTextBuf sTextBuf; |
| 1149 CPVT_WordProps wp; |
| 1150 CFX_FloatPoint ptBT(0.0f, 0.0f); |
| 1151 |
| 1152 pDevice->SaveState(); |
| 1153 |
| 1154 if (!rcClip.IsEmpty()) { |
| 1155 CFX_FloatRect rcTemp = rcClip; |
| 1156 pUser2Device->TransformRect(rcTemp); |
| 1157 pDevice->SetClip_Rect(rcTemp.ToFxRect()); |
| 1158 } |
| 1159 |
| 1160 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); |
| 1161 if (IPVT_FontMap* pFontMap = pEdit->GetFontMap()) { |
| 1162 if (pRange) |
| 1163 pIterator->SetAt(pRange->BeginPos); |
| 1164 else |
| 1165 pIterator->SetAt(0); |
| 1166 |
| 1167 CPVT_WordPlace oldplace; |
| 1168 |
| 1169 while (pIterator->NextWord()) { |
| 1170 CPVT_WordPlace place = pIterator->GetAt(); |
| 1171 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 1172 break; |
| 1173 |
| 1174 CPVT_Word word; |
| 1175 if (pIterator->GetWord(word)) { |
| 1176 word.WordProps.fFontSize = word.fFontSize; |
| 1177 |
| 1178 crCurText = ArgbEncode(255, word.WordProps.dwWordColor); |
| 1179 |
| 1180 if (wrSelect.IsExist()) { |
| 1181 bSelect = place.WordCmp(wrSelect.BeginPos) > 0 && |
| 1182 place.WordCmp(wrSelect.EndPos) <= 0; |
| 1183 if (bSelect) { |
| 1184 crCurText = crWhite; |
| 1185 } |
| 1186 } |
| 1187 |
| 1188 if (bSelect) { |
| 1189 CPVT_Line line; |
| 1190 pIterator->GetLine(line); |
| 1191 |
| 1192 CFX_PathData pathSelBK; |
| 1193 pathSelBK.AppendRect(word.ptWord.x + ptOffset.x, |
| 1194 line.ptLine.y + line.fLineDescent + ptOffset.y, |
| 1195 word.ptWord.x + word.fWidth + ptOffset.x, |
| 1196 line.ptLine.y + line.fLineAscent + ptOffset.y); |
| 1197 |
| 1198 pDevice->DrawPath(&pathSelBK, pUser2Device, nullptr, crSelBK, 0, |
| 1199 FXFILL_WINDING); |
| 1200 } |
| 1201 |
| 1202 if (place.LineCmp(oldplace) != 0 || word.WordProps.fCharSpace > 0.0f || |
| 1203 word.WordProps.nHorzScale != 100 || |
| 1204 FXSYS_memcmp(&word.WordProps, &wp, sizeof(CPVT_WordProps)) != 0 || |
| 1205 crOld != crCurText) { |
| 1206 if (sTextBuf.GetLength() > 0) { |
| 1207 DrawTextString( |
| 1208 pDevice, |
| 1209 CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 1210 pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, pUser2Device, |
| 1211 sTextBuf.MakeString(), crOld, 0, wp.nHorzScale); |
| 1212 |
| 1213 sTextBuf.Clear(); |
| 1214 } |
| 1215 wp = word.WordProps; |
| 1216 ptBT = word.ptWord; |
| 1217 crOld = crCurText; |
| 1218 } |
| 1219 |
| 1220 sTextBuf << GetPDFWordString(pFontMap, word.WordProps.nFontIndex, |
| 1221 word.Word, 0) |
| 1222 .AsStringC(); |
| 1223 |
| 1224 if (word.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) { |
| 1225 CFX_PathData pathUnderline; |
| 1226 CFX_FloatRect rcUnderline = GetUnderLineRect(word); |
| 1227 pathUnderline.AppendRect(rcUnderline.left, rcUnderline.bottom, |
| 1228 rcUnderline.right, rcUnderline.top); |
| 1229 |
| 1230 pDevice->DrawPath(&pathUnderline, pUser2Device, nullptr, crCurText, 0, |
| 1231 FXFILL_WINDING); |
| 1232 } |
| 1233 |
| 1234 if (word.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) { |
| 1235 CFX_PathData pathCrossout; |
| 1236 CFX_FloatRect rcCrossout = GetCrossoutRect(word); |
| 1237 pathCrossout.AppendRect(rcCrossout.left, rcCrossout.bottom, |
| 1238 rcCrossout.right, rcCrossout.top); |
| 1239 |
| 1240 pDevice->DrawPath(&pathCrossout, pUser2Device, nullptr, crCurText, 0, |
| 1241 FXFILL_WINDING); |
| 1242 } |
| 1243 |
| 1244 oldplace = place; |
| 1245 } |
| 1246 } |
| 1247 |
| 1248 if (sTextBuf.GetLength() > 0) { |
| 1249 DrawTextString( |
| 1250 pDevice, CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 1251 pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, pUser2Device, |
| 1252 sTextBuf.MakeString(), crOld, 0, wp.nHorzScale); |
| 1253 } |
| 1254 } |
| 1255 |
| 1256 pDevice->RestoreState(false); |
| 1257 } |
| 1258 |
| 1259 // static |
| 1260 void CFX_Edit::GeneratePageObjects( |
| 1261 CPDF_PageObjectHolder* pObjectHolder, |
| 1262 CFX_Edit* pEdit, |
| 1263 const CFX_FloatPoint& ptOffset, |
| 1264 const CPVT_WordRange* pRange, |
| 1265 FX_COLORREF crText, |
| 1266 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { |
| 1267 FX_FLOAT fFontSize = pEdit->GetFontSize(); |
| 1268 |
| 1269 int32_t nOldFontIndex = -1; |
| 1270 |
| 1271 CFX_ByteTextBuf sTextBuf; |
| 1272 CFX_FloatPoint ptBT(0.0f, 0.0f); |
| 1273 |
| 1274 ObjArray.RemoveAll(); |
| 1275 |
| 1276 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); |
| 1277 if (IPVT_FontMap* pFontMap = pEdit->GetFontMap()) { |
| 1278 if (pRange) |
| 1279 pIterator->SetAt(pRange->BeginPos); |
| 1280 else |
| 1281 pIterator->SetAt(0); |
| 1282 |
| 1283 CPVT_WordPlace oldplace; |
| 1284 |
| 1285 while (pIterator->NextWord()) { |
| 1286 CPVT_WordPlace place = pIterator->GetAt(); |
| 1287 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 1288 break; |
| 1289 |
| 1290 CPVT_Word word; |
| 1291 if (pIterator->GetWord(word)) { |
| 1292 if (place.LineCmp(oldplace) != 0 || nOldFontIndex != word.nFontIndex) { |
| 1293 if (sTextBuf.GetLength() > 0) { |
| 1294 ObjArray.Add(AddTextObjToPageObjects( |
| 1295 pObjectHolder, crText, pFontMap->GetPDFFont(nOldFontIndex), |
| 1296 fFontSize, 0.0f, 100, |
| 1297 CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 1298 sTextBuf.MakeString())); |
| 1299 |
| 1300 sTextBuf.Clear(); |
| 1301 } |
| 1302 |
| 1303 ptBT = word.ptWord; |
| 1304 nOldFontIndex = word.nFontIndex; |
| 1305 } |
| 1306 |
| 1307 sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, 0) |
| 1308 .AsStringC(); |
| 1309 oldplace = place; |
| 1310 } |
| 1311 } |
| 1312 |
| 1313 if (sTextBuf.GetLength() > 0) { |
| 1314 ObjArray.Add(AddTextObjToPageObjects( |
| 1315 pObjectHolder, crText, pFontMap->GetPDFFont(nOldFontIndex), fFontSize, |
| 1316 0.0f, 100, CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 1317 sTextBuf.MakeString())); |
| 1318 } |
| 1319 } |
| 1320 } |
| 1321 |
| 1322 // static |
| 1323 void CFX_Edit::GenerateRichPageObjects( |
| 1324 CPDF_PageObjectHolder* pObjectHolder, |
| 1325 CFX_Edit* pEdit, |
| 1326 const CFX_FloatPoint& ptOffset, |
| 1327 const CPVT_WordRange* pRange, |
| 1328 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { |
| 1329 FX_COLORREF crCurText = ArgbEncode(255, 0, 0, 0); |
| 1330 FX_COLORREF crOld = crCurText; |
| 1331 |
| 1332 CFX_ByteTextBuf sTextBuf; |
| 1333 CPVT_WordProps wp; |
| 1334 CFX_FloatPoint ptBT(0.0f, 0.0f); |
| 1335 |
| 1336 ObjArray.RemoveAll(); |
| 1337 |
| 1338 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); |
| 1339 if (IPVT_FontMap* pFontMap = pEdit->GetFontMap()) { |
| 1340 if (pRange) |
| 1341 pIterator->SetAt(pRange->BeginPos); |
| 1342 else |
| 1343 pIterator->SetAt(0); |
| 1344 |
| 1345 CPVT_WordPlace oldplace; |
| 1346 |
| 1347 while (pIterator->NextWord()) { |
| 1348 CPVT_WordPlace place = pIterator->GetAt(); |
| 1349 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 1350 break; |
| 1351 |
| 1352 CPVT_Word word; |
| 1353 if (pIterator->GetWord(word)) { |
| 1354 word.WordProps.fFontSize = word.fFontSize; |
| 1355 |
| 1356 crCurText = ArgbEncode(255, word.WordProps.dwWordColor); |
| 1357 |
| 1358 if (place.LineCmp(oldplace) != 0 || word.WordProps.fCharSpace > 0.0f || |
| 1359 word.WordProps.nHorzScale != 100 || |
| 1360 FXSYS_memcmp(&word.WordProps, &wp, sizeof(CPVT_WordProps)) != 0 || |
| 1361 crOld != crCurText) { |
| 1362 if (sTextBuf.GetLength() > 0) { |
| 1363 ObjArray.Add(AddTextObjToPageObjects( |
| 1364 pObjectHolder, crOld, pFontMap->GetPDFFont(wp.nFontIndex), |
| 1365 wp.fFontSize, wp.fCharSpace, wp.nHorzScale, |
| 1366 CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 1367 sTextBuf.MakeString())); |
| 1368 |
| 1369 sTextBuf.Clear(); |
| 1370 } |
| 1371 |
| 1372 wp = word.WordProps; |
| 1373 ptBT = word.ptWord; |
| 1374 crOld = crCurText; |
| 1375 } |
| 1376 |
| 1377 sTextBuf << GetPDFWordString(pFontMap, word.WordProps.nFontIndex, |
| 1378 word.Word, 0) |
| 1379 .AsStringC(); |
| 1380 |
| 1381 if (word.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) { |
| 1382 CFX_FloatRect rcUnderline = GetUnderLineRect(word); |
| 1383 rcUnderline.left += ptOffset.x; |
| 1384 rcUnderline.right += ptOffset.x; |
| 1385 rcUnderline.top += ptOffset.y; |
| 1386 rcUnderline.bottom += ptOffset.y; |
| 1387 |
| 1388 AddRectToPageObjects(pObjectHolder, crCurText, rcUnderline); |
| 1389 } |
| 1390 |
| 1391 if (word.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) { |
| 1392 CFX_FloatRect rcCrossout = GetCrossoutRect(word); |
| 1393 rcCrossout.left += ptOffset.x; |
| 1394 rcCrossout.right += ptOffset.x; |
| 1395 rcCrossout.top += ptOffset.y; |
| 1396 rcCrossout.bottom += ptOffset.y; |
| 1397 |
| 1398 AddRectToPageObjects(pObjectHolder, crCurText, rcCrossout); |
| 1399 } |
| 1400 |
| 1401 oldplace = place; |
| 1402 } |
| 1403 } |
| 1404 |
| 1405 if (sTextBuf.GetLength() > 0) { |
| 1406 ObjArray.Add(AddTextObjToPageObjects( |
| 1407 pObjectHolder, crOld, pFontMap->GetPDFFont(wp.nFontIndex), |
| 1408 wp.fFontSize, wp.fCharSpace, wp.nHorzScale, |
| 1409 CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 1410 sTextBuf.MakeString())); |
| 1411 } |
| 1412 } |
| 1413 } |
| 1414 |
| 1415 // static |
| 1416 void CFX_Edit::GenerateUnderlineObjects(CPDF_PageObjectHolder* pObjectHolder, |
| 1417 CFX_Edit* pEdit, |
| 1418 const CFX_FloatPoint& ptOffset, |
| 1419 const CPVT_WordRange* pRange, |
| 1420 FX_COLORREF color) { |
| 1421 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); |
| 1422 if (pEdit->GetFontMap()) { |
| 1423 if (pRange) |
| 1424 pIterator->SetAt(pRange->BeginPos); |
| 1425 else |
| 1426 pIterator->SetAt(0); |
| 1427 |
| 1428 CPVT_WordPlace oldplace; |
| 1429 |
| 1430 while (pIterator->NextWord()) { |
| 1431 CPVT_WordPlace place = pIterator->GetAt(); |
| 1432 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 1433 break; |
| 1434 |
| 1435 CPVT_Word word; |
| 1436 if (pIterator->GetWord(word)) { |
| 1437 CFX_FloatRect rcUnderline = GetUnderLineRect(word); |
| 1438 rcUnderline.left += ptOffset.x; |
| 1439 rcUnderline.right += ptOffset.x; |
| 1440 rcUnderline.top += ptOffset.y; |
| 1441 rcUnderline.bottom += ptOffset.y; |
| 1442 AddRectToPageObjects(pObjectHolder, color, rcUnderline); |
| 1443 } |
| 1444 } |
| 1445 } |
| 1446 } |
| 1447 |
| 1448 CFX_Edit::CFX_Edit() |
| 1449 : m_pVT(new CPDF_VariableText), |
650 m_pNotify(nullptr), | 1450 m_pNotify(nullptr), |
651 m_pOprNotify(nullptr), | 1451 m_pOprNotify(nullptr), |
652 m_wpCaret(-1, -1, -1), | 1452 m_wpCaret(-1, -1, -1), |
653 m_wpOldCaret(-1, -1, -1), | 1453 m_wpOldCaret(-1, -1, -1), |
654 m_SelState(), | 1454 m_SelState(), |
655 m_ptScrollPos(0, 0), | 1455 m_ptScrollPos(0, 0), |
656 m_ptRefreshScrollPos(0, 0), | 1456 m_ptRefreshScrollPos(0, 0), |
657 m_bEnableScroll(FALSE), | 1457 m_bEnableScroll(FALSE), |
658 m_ptCaret(0.0f, 0.0f), | 1458 m_ptCaret(0.0f, 0.0f), |
659 m_Undo(kEditUndoMaxItems), | 1459 m_Undo(kEditUndoMaxItems), |
660 m_nAlignment(0), | 1460 m_nAlignment(0), |
661 m_bNotifyFlag(FALSE), | 1461 m_bNotifyFlag(FALSE), |
662 m_bEnableOverflow(FALSE), | 1462 m_bEnableOverflow(FALSE), |
663 m_bEnableRefresh(TRUE), | 1463 m_bEnableRefresh(TRUE), |
664 m_rcOldContent(0.0f, 0.0f, 0.0f, 0.0f), | 1464 m_rcOldContent(0.0f, 0.0f, 0.0f, 0.0f), |
665 m_bEnableUndo(TRUE), | 1465 m_bEnableUndo(TRUE), |
666 m_bOprNotify(FALSE), | 1466 m_bOprNotify(FALSE), |
667 m_pGroupUndoItem(nullptr) { | 1467 m_pGroupUndoItem(nullptr) {} |
668 ASSERT(pVT); | |
669 } | |
670 | 1468 |
671 CFX_Edit::~CFX_Edit() { | 1469 CFX_Edit::~CFX_Edit() { |
672 ASSERT(!m_pGroupUndoItem); | 1470 ASSERT(!m_pGroupUndoItem); |
673 } | 1471 } |
674 | 1472 |
675 void CFX_Edit::Initialize() { | 1473 void CFX_Edit::Initialize() { |
676 m_pVT->Initialize(); | 1474 m_pVT->Initialize(); |
677 SetCaret(m_pVT->GetBeginWordPlace()); | 1475 SetCaret(m_pVT->GetBeginWordPlace()); |
678 SetCaretOrigin(); | 1476 SetCaretOrigin(); |
679 } | 1477 } |
680 | 1478 |
681 void CFX_Edit::SetFontMap(IPVT_FontMap* pFontMap) { | 1479 void CFX_Edit::SetFontMap(IPVT_FontMap* pFontMap) { |
682 m_pVTProvider.reset(new CFX_Edit_Provider(pFontMap)); | 1480 m_pVTProvider.reset(new CFX_Edit_Provider(pFontMap)); |
683 m_pVT->SetProvider(m_pVTProvider.get()); | 1481 m_pVT->SetProvider(m_pVTProvider.get()); |
684 } | 1482 } |
685 | 1483 |
686 void CFX_Edit::SetNotify(IFX_Edit_Notify* pNotify) { | 1484 void CFX_Edit::SetNotify(CPWL_EditCtrl* pNotify) { |
687 m_pNotify = pNotify; | 1485 m_pNotify = pNotify; |
688 } | 1486 } |
689 | 1487 |
690 void CFX_Edit::SetOprNotify(IFX_Edit_OprNotify* pOprNotify) { | 1488 void CFX_Edit::SetOprNotify(CPWL_Edit* pOprNotify) { |
691 m_pOprNotify = pOprNotify; | 1489 m_pOprNotify = pOprNotify; |
692 } | 1490 } |
693 | 1491 |
694 IFX_Edit_Iterator* CFX_Edit::GetIterator() { | 1492 CFX_Edit_Iterator* CFX_Edit::GetIterator() { |
695 if (!m_pIterator) | 1493 if (!m_pIterator) |
696 m_pIterator.reset(new CFX_Edit_Iterator(this, m_pVT->GetIterator())); | 1494 m_pIterator.reset(new CFX_Edit_Iterator(this, m_pVT->GetIterator())); |
697 return m_pIterator.get(); | 1495 return m_pIterator.get(); |
698 } | 1496 } |
699 | 1497 |
700 CPDF_VariableText* CFX_Edit::GetVariableText() { | 1498 CPDF_VariableText* CFX_Edit::GetVariableText() { |
701 return m_pVT; | 1499 return m_pVT.get(); |
702 } | 1500 } |
703 | 1501 |
704 IPVT_FontMap* CFX_Edit::GetFontMap() { | 1502 IPVT_FontMap* CFX_Edit::GetFontMap() { |
705 return m_pVTProvider ? m_pVTProvider->GetFontMap() : nullptr; | 1503 return m_pVTProvider ? m_pVTProvider->GetFontMap() : nullptr; |
706 } | 1504 } |
707 | 1505 |
708 void CFX_Edit::SetPlateRect(const CFX_FloatRect& rect, FX_BOOL bPaint) { | 1506 void CFX_Edit::SetPlateRect(const CFX_FloatRect& rect, FX_BOOL bPaint) { |
709 m_pVT->SetPlateRect(rect); | 1507 m_pVT->SetPlateRect(rect); |
710 m_ptScrollPos = CFX_FloatPoint(rect.left, rect.top); | 1508 m_ptScrollPos = CFX_FloatPoint(rect.left, rect.top); |
711 if (bPaint) | 1509 if (bPaint) |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 ptRightTop.y); | 1993 ptRightTop.y); |
1196 } | 1994 } |
1197 | 1995 |
1198 void CFX_Edit::SetScrollInfo() { | 1996 void CFX_Edit::SetScrollInfo() { |
1199 if (m_pNotify) { | 1997 if (m_pNotify) { |
1200 CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); | 1998 CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
1201 CFX_FloatRect rcContent = m_pVT->GetContentRect(); | 1999 CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
1202 | 2000 |
1203 if (!m_bNotifyFlag) { | 2001 if (!m_bNotifyFlag) { |
1204 m_bNotifyFlag = TRUE; | 2002 m_bNotifyFlag = TRUE; |
1205 m_pNotify->IOnSetScrollInfoX(rcPlate.left, rcPlate.right, rcContent.left, | |
1206 rcContent.right, rcPlate.Width() / 3, | |
1207 rcPlate.Width()); | |
1208 | |
1209 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top, | 2003 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top, |
1210 rcContent.bottom, rcContent.top, | 2004 rcContent.bottom, rcContent.top, |
1211 rcPlate.Height() / 3, rcPlate.Height()); | 2005 rcPlate.Height() / 3, rcPlate.Height()); |
1212 m_bNotifyFlag = FALSE; | 2006 m_bNotifyFlag = FALSE; |
1213 } | 2007 } |
1214 } | 2008 } |
1215 } | 2009 } |
1216 | 2010 |
1217 void CFX_Edit::SetScrollPosX(FX_FLOAT fx) { | 2011 void CFX_Edit::SetScrollPosX(FX_FLOAT fx) { |
1218 if (!m_bEnableScroll) | 2012 if (!m_bEnableScroll) |
1219 return; | 2013 return; |
1220 | 2014 |
1221 if (m_pVT->IsValid()) { | 2015 if (m_pVT->IsValid()) { |
1222 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.x, fx)) { | 2016 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.x, fx)) { |
1223 m_ptScrollPos.x = fx; | 2017 m_ptScrollPos.x = fx; |
1224 Refresh(RP_NOANALYSE); | 2018 Refresh(RP_NOANALYSE); |
1225 | |
1226 if (m_pNotify) { | |
1227 if (!m_bNotifyFlag) { | |
1228 m_bNotifyFlag = TRUE; | |
1229 m_pNotify->IOnSetScrollPosX(fx); | |
1230 m_bNotifyFlag = FALSE; | |
1231 } | |
1232 } | |
1233 } | 2019 } |
1234 } | 2020 } |
1235 } | 2021 } |
1236 | 2022 |
1237 void CFX_Edit::SetScrollPosY(FX_FLOAT fy) { | 2023 void CFX_Edit::SetScrollPosY(FX_FLOAT fy) { |
1238 if (!m_bEnableScroll) | 2024 if (!m_bEnableScroll) |
1239 return; | 2025 return; |
1240 | 2026 |
1241 if (m_pVT->IsValid()) { | 2027 if (m_pVT->IsValid()) { |
1242 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y, fy)) { | 2028 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y, fy)) { |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1803 void CFX_Edit::SetText(const FX_WCHAR* text, | 2589 void CFX_Edit::SetText(const FX_WCHAR* text, |
1804 int32_t charset, | 2590 int32_t charset, |
1805 const CPVT_SecProps* pSecProps, | 2591 const CPVT_SecProps* pSecProps, |
1806 const CPVT_WordProps* pWordProps, | 2592 const CPVT_WordProps* pWordProps, |
1807 FX_BOOL bAddUndo, | 2593 FX_BOOL bAddUndo, |
1808 FX_BOOL bPaint) { | 2594 FX_BOOL bPaint) { |
1809 Empty(); | 2595 Empty(); |
1810 DoInsertText(CPVT_WordPlace(0, 0, -1), text, charset, pSecProps, pWordProps); | 2596 DoInsertText(CPVT_WordPlace(0, 0, -1), text, charset, pSecProps, pWordProps); |
1811 if (bPaint) | 2597 if (bPaint) |
1812 Paint(); | 2598 Paint(); |
1813 if (m_bOprNotify && m_pOprNotify) | |
1814 m_pOprNotify->OnSetText(m_wpCaret, m_wpOldCaret); | |
1815 } | 2599 } |
1816 | 2600 |
1817 FX_BOOL CFX_Edit::InsertWord(uint16_t word, | 2601 FX_BOOL CFX_Edit::InsertWord(uint16_t word, |
1818 int32_t charset, | 2602 int32_t charset, |
1819 const CPVT_WordProps* pWordProps, | 2603 const CPVT_WordProps* pWordProps, |
1820 FX_BOOL bAddUndo, | 2604 FX_BOOL bAddUndo, |
1821 FX_BOOL bPaint) { | 2605 FX_BOOL bPaint) { |
1822 if (IsTextOverflow()) | 2606 if (IsTextOverflow()) |
1823 return FALSE; | 2607 return FALSE; |
1824 | 2608 |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2441 int32_t CFX_Edit_RectArray::GetSize() const { | 3225 int32_t CFX_Edit_RectArray::GetSize() const { |
2442 return m_Rects.GetSize(); | 3226 return m_Rects.GetSize(); |
2443 } | 3227 } |
2444 | 3228 |
2445 CFX_FloatRect* CFX_Edit_RectArray::GetAt(int32_t nIndex) const { | 3229 CFX_FloatRect* CFX_Edit_RectArray::GetAt(int32_t nIndex) const { |
2446 if (nIndex < 0 || nIndex >= m_Rects.GetSize()) | 3230 if (nIndex < 0 || nIndex >= m_Rects.GetSize()) |
2447 return nullptr; | 3231 return nullptr; |
2448 | 3232 |
2449 return m_Rects.GetAt(nIndex); | 3233 return m_Rects.GetAt(nIndex); |
2450 } | 3234 } |
OLD | NEW |