Chromium Code Reviews| 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 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 763 m_pEdit->SetWordProps(m_eProps, m_wpPlace, &m_OldWordProps, m_wrPlace, | 932 m_pEdit->SetWordProps(m_eProps, m_wpPlace, &m_OldWordProps, m_wrPlace, |
| 764 FALSE); | 933 FALSE); |
| 765 if (IsFirst()) { | 934 if (IsFirst()) { |
| 766 m_pEdit->SelectNone(); | 935 m_pEdit->SelectNone(); |
| 767 m_pEdit->PaintSetProps(m_eProps, m_wrPlace); | 936 m_pEdit->PaintSetProps(m_eProps, m_wrPlace); |
| 768 m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos); | 937 m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos); |
| 769 } | 938 } |
| 770 } | 939 } |
| 771 } | 940 } |
| 772 | 941 |
| 773 CFX_Edit::CFX_Edit(CPDF_VariableText* pVT) | 942 // static |
| 774 : m_pVT(pVT), | 943 CFX_ByteString CFX_Edit::GetEditAppearanceStream(CFX_Edit* pEdit, |
| 944 const CFX_FloatPoint& ptOffset, | |
| 945 const CPVT_WordRange* pRange, | |
| 946 FX_BOOL bContinuous, | |
| 947 uint16_t SubWord) { | |
| 948 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); | |
| 949 if (pRange) | |
| 950 pIterator->SetAt(pRange->BeginPos); | |
| 951 else | |
| 952 pIterator->SetAt(0); | |
| 953 | |
| 954 CFX_ByteTextBuf sEditStream; | |
| 955 CFX_ByteTextBuf sWords; | |
| 956 int32_t nCurFontIndex = -1; | |
| 957 CFX_FloatPoint ptOld(0.0f, 0.0f); | |
| 958 CFX_FloatPoint ptNew(0.0f, 0.0f); | |
| 959 CPVT_WordPlace oldplace; | |
| 960 while (pIterator->NextWord()) { | |
| 961 CPVT_WordPlace place = pIterator->GetAt(); | |
| 962 | |
| 963 if (pRange && place.WordCmp(pRange->EndPos) > 0) | |
| 964 break; | |
| 965 | |
| 966 if (bContinuous) { | |
| 967 if (place.LineCmp(oldplace) != 0) { | |
| 968 if (sWords.GetSize() > 0) { | |
| 969 sEditStream << GetWordRenderString(sWords.MakeString()); | |
| 970 sWords.Clear(); | |
| 971 } | |
| 972 | |
| 973 CPVT_Word word; | |
| 974 if (pIterator->GetWord(word)) { | |
| 975 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, | |
| 976 word.ptWord.y + ptOffset.y); | |
| 977 } else { | |
| 978 CPVT_Line line; | |
| 979 pIterator->GetLine(line); | |
| 980 ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x, | |
| 981 line.ptLine.y + ptOffset.y); | |
| 982 } | |
| 983 | |
| 984 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { | |
| 985 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y | |
| 986 << " Td\n"; | |
| 987 | |
| 988 ptOld = ptNew; | |
| 989 } | |
| 990 } | |
| 991 | |
| 992 CPVT_Word word; | |
| 993 if (pIterator->GetWord(word)) { | |
| 994 if (word.nFontIndex != nCurFontIndex) { | |
| 995 if (sWords.GetSize() > 0) { | |
| 996 sEditStream << GetWordRenderString(sWords.MakeString()); | |
| 997 sWords.Clear(); | |
| 998 } | |
| 999 sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex, | |
| 1000 word.fFontSize); | |
| 1001 nCurFontIndex = word.nFontIndex; | |
| 1002 } | |
| 1003 | |
| 1004 sWords << GetPDFWordString(pEdit->GetFontMap(), nCurFontIndex, | |
| 1005 word.Word, SubWord); | |
| 1006 } | |
| 1007 | |
| 1008 oldplace = place; | |
| 1009 } else { | |
| 1010 CPVT_Word word; | |
| 1011 if (pIterator->GetWord(word)) { | |
| 1012 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, | |
| 1013 word.ptWord.y + ptOffset.y); | |
| 1014 | |
| 1015 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { | |
| 1016 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y | |
| 1017 << " Td\n"; | |
| 1018 ptOld = ptNew; | |
| 1019 } | |
| 1020 | |
| 1021 if (word.nFontIndex != nCurFontIndex) { | |
| 1022 sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex, | |
| 1023 word.fFontSize); | |
| 1024 nCurFontIndex = word.nFontIndex; | |
| 1025 } | |
| 1026 | |
| 1027 sEditStream << GetWordRenderString(GetPDFWordString( | |
| 1028 pEdit->GetFontMap(), nCurFontIndex, word.Word, SubWord)); | |
| 1029 } | |
| 1030 } | |
| 1031 } | |
| 1032 | |
| 1033 if (sWords.GetSize() > 0) { | |
| 1034 sEditStream << GetWordRenderString(sWords.MakeString()); | |
| 1035 sWords.Clear(); | |
| 1036 } | |
| 1037 | |
| 1038 CFX_ByteTextBuf sAppStream; | |
| 1039 if (sEditStream.GetSize() > 0) { | |
| 1040 int32_t nHorzScale = pEdit->GetHorzScale(); | |
| 1041 if (nHorzScale != 100) { | |
| 1042 sAppStream << nHorzScale << " Tz\n"; | |
| 1043 } | |
| 1044 | |
| 1045 FX_FLOAT fCharSpace = pEdit->GetCharSpace(); | |
| 1046 if (!FX_EDIT_IsFloatZero(fCharSpace)) { | |
| 1047 sAppStream << fCharSpace << " Tc\n"; | |
| 1048 } | |
| 1049 | |
| 1050 sAppStream << sEditStream; | |
| 1051 } | |
| 1052 | |
| 1053 return sAppStream.MakeString(); | |
| 1054 } | |
| 1055 | |
| 1056 // static | |
| 1057 CFX_ByteString CFX_Edit::GetSelectAppearanceStream( | |
| 1058 CFX_Edit* pEdit, | |
| 1059 const CFX_FloatPoint& ptOffset, | |
| 1060 const CPVT_WordRange* pRange) { | |
| 1061 if (!pRange || !pRange->IsExist()) | |
| 1062 return CFX_ByteString(); | |
| 1063 | |
| 1064 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); | |
| 1065 pIterator->SetAt(pRange->BeginPos); | |
| 1066 | |
| 1067 CFX_ByteTextBuf sRet; | |
| 1068 while (pIterator->NextWord()) { | |
| 1069 CPVT_WordPlace place = pIterator->GetAt(); | |
| 1070 if (place.WordCmp(pRange->EndPos) > 0) | |
| 1071 break; | |
| 1072 | |
| 1073 CPVT_Word word; | |
| 1074 CPVT_Line line; | |
| 1075 if (pIterator->GetWord(word) && pIterator->GetLine(line)) { | |
| 1076 sRet << word.ptWord.x + ptOffset.x << " " | |
| 1077 << line.ptLine.y + line.fLineDescent << " " << word.fWidth << " " | |
| 1078 << line.fLineAscent - line.fLineDescent << " re\nf\n"; | |
| 1079 } | |
| 1080 } | |
| 1081 | |
| 1082 return sRet.MakeString(); | |
| 1083 } | |
| 1084 | |
| 1085 // static | |
| 1086 void CFX_Edit::DrawUnderline(CFX_RenderDevice* pDevice, | |
| 1087 CFX_Matrix* pUser2Device, | |
| 1088 CFX_Edit* pEdit, | |
| 1089 FX_COLORREF color, | |
| 1090 const CFX_FloatRect& rcClip, | |
| 1091 const CFX_FloatPoint& ptOffset, | |
| 1092 const CPVT_WordRange* pRange) { | |
| 1093 pDevice->SaveState(); | |
| 1094 | |
| 1095 if (!rcClip.IsEmpty()) { | |
| 1096 CFX_FloatRect rcTemp = rcClip; | |
| 1097 pUser2Device->TransformRect(rcTemp); | |
| 1098 pDevice->SetClip_Rect(rcTemp.ToFxRect()); | |
| 1099 } | |
| 1100 | |
| 1101 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); | |
| 1102 if (pEdit->GetFontMap()) { | |
| 1103 if (pRange) | |
| 1104 pIterator->SetAt(pRange->BeginPos); | |
| 1105 else | |
| 1106 pIterator->SetAt(0); | |
| 1107 | |
| 1108 while (pIterator->NextWord()) { | |
| 1109 CPVT_WordPlace place = pIterator->GetAt(); | |
| 1110 if (pRange && place.WordCmp(pRange->EndPos) > 0) | |
| 1111 break; | |
| 1112 | |
| 1113 CPVT_Word word; | |
| 1114 if (pIterator->GetWord(word)) { | |
| 1115 CFX_PathData pathUnderline; | |
| 1116 CFX_FloatRect rcUnderline = GetUnderLineRect(word); | |
| 1117 rcUnderline.left += ptOffset.x; | |
| 1118 rcUnderline.right += ptOffset.x; | |
| 1119 rcUnderline.top += ptOffset.y; | |
| 1120 rcUnderline.bottom += ptOffset.y; | |
| 1121 pathUnderline.AppendRect(rcUnderline.left, rcUnderline.bottom, | |
| 1122 rcUnderline.right, rcUnderline.top); | |
| 1123 | |
| 1124 pDevice->DrawPath(&pathUnderline, pUser2Device, nullptr, color, 0, | |
| 1125 FXFILL_WINDING); | |
| 1126 } | |
| 1127 } | |
| 1128 } | |
| 1129 | |
| 1130 pDevice->RestoreState(false); | |
| 1131 } | |
| 1132 | |
| 1133 // static | |
| 1134 void CFX_Edit::DrawEdit(CFX_RenderDevice* pDevice, | |
| 1135 CFX_Matrix* pUser2Device, | |
| 1136 CFX_Edit* pEdit, | |
| 1137 FX_COLORREF crTextFill, | |
| 1138 FX_COLORREF crTextStroke, | |
| 1139 const CFX_FloatRect& rcClip, | |
| 1140 const CFX_FloatPoint& ptOffset, | |
| 1141 const CPVT_WordRange* pRange, | |
| 1142 CFX_SystemHandler* pSystemHandler, | |
| 1143 void* pFFLData) { | |
| 1144 const bool bContinuous = | |
| 1145 pEdit->GetCharArray() == 0 && pEdit->GetCharSpace() <= 0.0f; | |
| 1146 uint16_t SubWord = pEdit->GetPasswordChar(); | |
| 1147 FX_FLOAT fFontSize = pEdit->GetFontSize(); | |
| 1148 CPVT_WordRange wrSelect = pEdit->GetSelectWordRange(); | |
| 1149 int32_t nHorzScale = pEdit->GetHorzScale(); | |
| 1150 | |
| 1151 FX_COLORREF crCurFill = crTextFill; | |
| 1152 FX_COLORREF crOldFill = crCurFill; | |
| 1153 | |
| 1154 FX_BOOL bSelect = FALSE; | |
| 1155 const FX_COLORREF crWhite = ArgbEncode(255, 255, 255, 255); | |
| 1156 const FX_COLORREF crSelBK = ArgbEncode(255, 0, 51, 113); | |
| 1157 | |
| 1158 CFX_ByteTextBuf sTextBuf; | |
| 1159 int32_t nFontIndex = -1; | |
| 1160 CFX_FloatPoint ptBT(0.0f, 0.0f); | |
| 1161 | |
| 1162 pDevice->SaveState(); | |
| 1163 | |
| 1164 if (!rcClip.IsEmpty()) { | |
| 1165 CFX_FloatRect rcTemp = rcClip; | |
| 1166 pUser2Device->TransformRect(rcTemp); | |
| 1167 pDevice->SetClip_Rect(rcTemp.ToFxRect()); | |
| 1168 } | |
| 1169 | |
| 1170 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); | |
| 1171 if (IPVT_FontMap* pFontMap = pEdit->GetFontMap()) { | |
| 1172 if (pRange) | |
| 1173 pIterator->SetAt(pRange->BeginPos); | |
| 1174 else | |
| 1175 pIterator->SetAt(0); | |
| 1176 | |
| 1177 CPVT_WordPlace oldplace; | |
| 1178 while (pIterator->NextWord()) { | |
| 1179 CPVT_WordPlace place = pIterator->GetAt(); | |
| 1180 if (pRange && place.WordCmp(pRange->EndPos) > 0) | |
| 1181 break; | |
| 1182 | |
| 1183 if (wrSelect.IsExist()) { | |
| 1184 bSelect = place.WordCmp(wrSelect.BeginPos) > 0 && | |
| 1185 place.WordCmp(wrSelect.EndPos) <= 0; | |
| 1186 crCurFill = bSelect ? crWhite : crTextFill; | |
| 1187 } | |
| 1188 if (pSystemHandler && pSystemHandler->IsSelectionImplemented()) { | |
| 1189 crCurFill = crTextFill; | |
| 1190 crOldFill = crCurFill; | |
| 1191 } | |
| 1192 CPVT_Word word; | |
| 1193 if (pIterator->GetWord(word)) { | |
| 1194 if (bSelect) { | |
| 1195 CPVT_Line line; | |
| 1196 pIterator->GetLine(line); | |
| 1197 | |
| 1198 if (pSystemHandler && pSystemHandler->IsSelectionImplemented()) { | |
| 1199 CFX_FloatRect rc(word.ptWord.x, line.ptLine.y + line.fLineDescent, | |
| 1200 word.ptWord.x + word.fWidth, | |
| 1201 line.ptLine.y + line.fLineAscent); | |
| 1202 rc.Intersect(rcClip); | |
| 1203 pSystemHandler->OutputSelectedRect(pFFLData, rc); | |
| 1204 } else { | |
| 1205 CFX_PathData pathSelBK; | |
| 1206 pathSelBK.AppendRect( | |
| 1207 word.ptWord.x, line.ptLine.y + line.fLineDescent, | |
| 1208 word.ptWord.x + word.fWidth, line.ptLine.y + line.fLineAscent); | |
| 1209 | |
| 1210 pDevice->DrawPath(&pathSelBK, pUser2Device, nullptr, crSelBK, 0, | |
| 1211 FXFILL_WINDING); | |
| 1212 } | |
| 1213 } | |
| 1214 | |
| 1215 if (bContinuous) { | |
| 1216 if (place.LineCmp(oldplace) != 0 || word.nFontIndex != nFontIndex || | |
| 1217 crOldFill != crCurFill) { | |
| 1218 if (sTextBuf.GetLength() > 0) { | |
| 1219 DrawTextString( | |
| 1220 pDevice, | |
| 1221 CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | |
| 1222 pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device, | |
| 1223 sTextBuf.MakeString(), crOldFill, crTextStroke, nHorzScale); | |
| 1224 | |
| 1225 sTextBuf.Clear(); | |
| 1226 } | |
| 1227 nFontIndex = word.nFontIndex; | |
| 1228 ptBT = word.ptWord; | |
| 1229 crOldFill = crCurFill; | |
| 1230 } | |
| 1231 | |
| 1232 sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, | |
| 1233 SubWord) | |
| 1234 .AsStringC(); | |
| 1235 } else { | |
| 1236 DrawTextString( | |
| 1237 pDevice, CFX_FloatPoint(word.ptWord.x + ptOffset.x, | |
| 1238 word.ptWord.y + ptOffset.y), | |
| 1239 pFontMap->GetPDFFont(word.nFontIndex), fFontSize, pUser2Device, | |
| 1240 GetPDFWordString(pFontMap, word.nFontIndex, word.Word, SubWord), | |
| 1241 crCurFill, crTextStroke, nHorzScale); | |
| 1242 } | |
| 1243 oldplace = place; | |
| 1244 } | |
| 1245 } | |
| 1246 | |
| 1247 if (sTextBuf.GetLength() > 0) { | |
| 1248 DrawTextString( | |
| 1249 pDevice, CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | |
| 1250 pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device, | |
| 1251 sTextBuf.MakeString(), crOldFill, crTextStroke, nHorzScale); | |
| 1252 } | |
| 1253 } | |
| 1254 | |
| 1255 pDevice->RestoreState(false); | |
| 1256 } | |
| 1257 | |
| 1258 // static | |
| 1259 void CFX_Edit::DrawRichEdit(CFX_RenderDevice* pDevice, | |
| 1260 CFX_Matrix* pUser2Device, | |
| 1261 CFX_Edit* pEdit, | |
| 1262 const CFX_FloatRect& rcClip, | |
| 1263 const CFX_FloatPoint& ptOffset, | |
| 1264 const CPVT_WordRange* pRange) { | |
| 1265 CPVT_WordRange wrSelect = pEdit->GetSelectWordRange(); | |
| 1266 | |
| 1267 FX_COLORREF crCurText = ArgbEncode(255, 0, 0, 0); | |
| 1268 FX_COLORREF crOld = crCurText; | |
| 1269 FX_BOOL bSelect = FALSE; | |
| 1270 const FX_COLORREF crWhite = ArgbEncode(255, 255, 255, 255); | |
| 1271 const FX_COLORREF crSelBK = ArgbEncode(255, 0, 51, 113); | |
| 1272 | |
| 1273 CFX_ByteTextBuf sTextBuf; | |
| 1274 CPVT_WordProps wp; | |
| 1275 CFX_FloatPoint ptBT(0.0f, 0.0f); | |
| 1276 | |
| 1277 pDevice->SaveState(); | |
| 1278 | |
| 1279 if (!rcClip.IsEmpty()) { | |
| 1280 CFX_FloatRect rcTemp = rcClip; | |
| 1281 pUser2Device->TransformRect(rcTemp); | |
| 1282 pDevice->SetClip_Rect(rcTemp.ToFxRect()); | |
| 1283 } | |
| 1284 | |
| 1285 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); | |
| 1286 if (IPVT_FontMap* pFontMap = pEdit->GetFontMap()) { | |
| 1287 if (pRange) | |
| 1288 pIterator->SetAt(pRange->BeginPos); | |
| 1289 else | |
| 1290 pIterator->SetAt(0); | |
| 1291 | |
| 1292 CPVT_WordPlace oldplace; | |
| 1293 | |
| 1294 while (pIterator->NextWord()) { | |
| 1295 CPVT_WordPlace place = pIterator->GetAt(); | |
| 1296 if (pRange && place.WordCmp(pRange->EndPos) > 0) | |
| 1297 break; | |
| 1298 | |
| 1299 CPVT_Word word; | |
| 1300 if (pIterator->GetWord(word)) { | |
| 1301 word.WordProps.fFontSize = word.fFontSize; | |
| 1302 | |
| 1303 crCurText = ArgbEncode(255, word.WordProps.dwWordColor); | |
| 1304 | |
| 1305 if (wrSelect.IsExist()) { | |
| 1306 bSelect = place.WordCmp(wrSelect.BeginPos) > 0 && | |
| 1307 place.WordCmp(wrSelect.EndPos) <= 0; | |
| 1308 if (bSelect) { | |
| 1309 crCurText = crWhite; | |
| 1310 } | |
| 1311 } | |
| 1312 | |
| 1313 if (bSelect) { | |
| 1314 CPVT_Line line; | |
| 1315 pIterator->GetLine(line); | |
| 1316 | |
| 1317 CFX_PathData pathSelBK; | |
| 1318 pathSelBK.AppendRect(word.ptWord.x + ptOffset.x, | |
| 1319 line.ptLine.y + line.fLineDescent + ptOffset.y, | |
| 1320 word.ptWord.x + word.fWidth + ptOffset.x, | |
| 1321 line.ptLine.y + line.fLineAscent + ptOffset.y); | |
| 1322 | |
| 1323 pDevice->DrawPath(&pathSelBK, pUser2Device, nullptr, crSelBK, 0, | |
| 1324 FXFILL_WINDING); | |
| 1325 } | |
| 1326 | |
| 1327 if (place.LineCmp(oldplace) != 0 || word.WordProps.fCharSpace > 0.0f || | |
| 1328 word.WordProps.nHorzScale != 100 || | |
| 1329 FXSYS_memcmp(&word.WordProps, &wp, sizeof(CPVT_WordProps)) != 0 || | |
| 1330 crOld != crCurText) { | |
| 1331 if (sTextBuf.GetLength() > 0) { | |
| 1332 DrawTextString( | |
| 1333 pDevice, | |
| 1334 CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | |
| 1335 pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, pUser2Device, | |
| 1336 sTextBuf.MakeString(), crOld, 0, wp.nHorzScale); | |
| 1337 | |
| 1338 sTextBuf.Clear(); | |
| 1339 } | |
| 1340 wp = word.WordProps; | |
| 1341 ptBT = word.ptWord; | |
| 1342 crOld = crCurText; | |
| 1343 } | |
| 1344 | |
| 1345 sTextBuf << GetPDFWordString(pFontMap, word.WordProps.nFontIndex, | |
| 1346 word.Word, 0) | |
| 1347 .AsStringC(); | |
| 1348 | |
| 1349 if (word.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) { | |
| 1350 CFX_PathData pathUnderline; | |
| 1351 CFX_FloatRect rcUnderline = GetUnderLineRect(word); | |
| 1352 pathUnderline.AppendRect(rcUnderline.left, rcUnderline.bottom, | |
| 1353 rcUnderline.right, rcUnderline.top); | |
| 1354 | |
| 1355 pDevice->DrawPath(&pathUnderline, pUser2Device, nullptr, crCurText, 0, | |
| 1356 FXFILL_WINDING); | |
| 1357 } | |
| 1358 | |
| 1359 if (word.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) { | |
| 1360 CFX_PathData pathCrossout; | |
| 1361 CFX_FloatRect rcCrossout = GetCrossoutRect(word); | |
| 1362 pathCrossout.AppendRect(rcCrossout.left, rcCrossout.bottom, | |
| 1363 rcCrossout.right, rcCrossout.top); | |
| 1364 | |
| 1365 pDevice->DrawPath(&pathCrossout, pUser2Device, nullptr, crCurText, 0, | |
| 1366 FXFILL_WINDING); | |
| 1367 } | |
| 1368 | |
| 1369 oldplace = place; | |
| 1370 } | |
| 1371 } | |
| 1372 | |
| 1373 if (sTextBuf.GetLength() > 0) { | |
| 1374 DrawTextString( | |
| 1375 pDevice, CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | |
| 1376 pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, pUser2Device, | |
| 1377 sTextBuf.MakeString(), crOld, 0, wp.nHorzScale); | |
| 1378 } | |
| 1379 } | |
| 1380 | |
| 1381 pDevice->RestoreState(false); | |
| 1382 } | |
| 1383 | |
| 1384 // static | |
| 1385 void CFX_Edit::GeneratePageObjects( | |
| 1386 CPDF_PageObjectHolder* pObjectHolder, | |
| 1387 CFX_Edit* pEdit, | |
| 1388 const CFX_FloatPoint& ptOffset, | |
| 1389 const CPVT_WordRange* pRange, | |
| 1390 FX_COLORREF crText, | |
| 1391 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { | |
| 1392 FX_FLOAT fFontSize = pEdit->GetFontSize(); | |
| 1393 | |
| 1394 int32_t nOldFontIndex = -1; | |
| 1395 | |
| 1396 CFX_ByteTextBuf sTextBuf; | |
| 1397 CFX_FloatPoint ptBT(0.0f, 0.0f); | |
| 1398 | |
| 1399 ObjArray.RemoveAll(); | |
| 1400 | |
| 1401 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); | |
| 1402 if (IPVT_FontMap* pFontMap = pEdit->GetFontMap()) { | |
| 1403 if (pRange) | |
| 1404 pIterator->SetAt(pRange->BeginPos); | |
| 1405 else | |
| 1406 pIterator->SetAt(0); | |
| 1407 | |
| 1408 CPVT_WordPlace oldplace; | |
| 1409 | |
| 1410 while (pIterator->NextWord()) { | |
| 1411 CPVT_WordPlace place = pIterator->GetAt(); | |
| 1412 if (pRange && place.WordCmp(pRange->EndPos) > 0) | |
| 1413 break; | |
| 1414 | |
| 1415 CPVT_Word word; | |
| 1416 if (pIterator->GetWord(word)) { | |
| 1417 if (place.LineCmp(oldplace) != 0 || nOldFontIndex != word.nFontIndex) { | |
| 1418 if (sTextBuf.GetLength() > 0) { | |
| 1419 ObjArray.Add(AddTextObjToPageObjects( | |
| 1420 pObjectHolder, crText, pFontMap->GetPDFFont(nOldFontIndex), | |
| 1421 fFontSize, 0.0f, 100, | |
| 1422 CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | |
| 1423 sTextBuf.MakeString())); | |
| 1424 | |
| 1425 sTextBuf.Clear(); | |
| 1426 } | |
| 1427 | |
| 1428 ptBT = word.ptWord; | |
| 1429 nOldFontIndex = word.nFontIndex; | |
| 1430 } | |
| 1431 | |
| 1432 sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, 0) | |
| 1433 .AsStringC(); | |
| 1434 oldplace = place; | |
| 1435 } | |
| 1436 } | |
| 1437 | |
| 1438 if (sTextBuf.GetLength() > 0) { | |
| 1439 ObjArray.Add(AddTextObjToPageObjects( | |
| 1440 pObjectHolder, crText, pFontMap->GetPDFFont(nOldFontIndex), fFontSize, | |
| 1441 0.0f, 100, CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | |
| 1442 sTextBuf.MakeString())); | |
| 1443 } | |
| 1444 } | |
| 1445 } | |
| 1446 | |
| 1447 // static | |
| 1448 void CFX_Edit::GenerateRichPageObjects( | |
| 1449 CPDF_PageObjectHolder* pObjectHolder, | |
| 1450 CFX_Edit* pEdit, | |
| 1451 const CFX_FloatPoint& ptOffset, | |
| 1452 const CPVT_WordRange* pRange, | |
| 1453 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { | |
| 1454 FX_COLORREF crCurText = ArgbEncode(255, 0, 0, 0); | |
| 1455 FX_COLORREF crOld = crCurText; | |
| 1456 | |
| 1457 CFX_ByteTextBuf sTextBuf; | |
| 1458 CPVT_WordProps wp; | |
| 1459 CFX_FloatPoint ptBT(0.0f, 0.0f); | |
| 1460 | |
| 1461 ObjArray.RemoveAll(); | |
| 1462 | |
| 1463 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); | |
| 1464 if (IPVT_FontMap* pFontMap = pEdit->GetFontMap()) { | |
| 1465 if (pRange) | |
| 1466 pIterator->SetAt(pRange->BeginPos); | |
| 1467 else | |
| 1468 pIterator->SetAt(0); | |
| 1469 | |
| 1470 CPVT_WordPlace oldplace; | |
| 1471 | |
| 1472 while (pIterator->NextWord()) { | |
| 1473 CPVT_WordPlace place = pIterator->GetAt(); | |
| 1474 if (pRange && place.WordCmp(pRange->EndPos) > 0) | |
| 1475 break; | |
| 1476 | |
| 1477 CPVT_Word word; | |
| 1478 if (pIterator->GetWord(word)) { | |
| 1479 word.WordProps.fFontSize = word.fFontSize; | |
| 1480 | |
| 1481 crCurText = ArgbEncode(255, word.WordProps.dwWordColor); | |
| 1482 | |
| 1483 if (place.LineCmp(oldplace) != 0 || word.WordProps.fCharSpace > 0.0f || | |
| 1484 word.WordProps.nHorzScale != 100 || | |
| 1485 FXSYS_memcmp(&word.WordProps, &wp, sizeof(CPVT_WordProps)) != 0 || | |
| 1486 crOld != crCurText) { | |
| 1487 if (sTextBuf.GetLength() > 0) { | |
| 1488 ObjArray.Add(AddTextObjToPageObjects( | |
| 1489 pObjectHolder, crOld, pFontMap->GetPDFFont(wp.nFontIndex), | |
| 1490 wp.fFontSize, wp.fCharSpace, wp.nHorzScale, | |
| 1491 CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | |
| 1492 sTextBuf.MakeString())); | |
| 1493 | |
| 1494 sTextBuf.Clear(); | |
| 1495 } | |
| 1496 | |
| 1497 wp = word.WordProps; | |
| 1498 ptBT = word.ptWord; | |
| 1499 crOld = crCurText; | |
| 1500 } | |
| 1501 | |
| 1502 sTextBuf << GetPDFWordString(pFontMap, word.WordProps.nFontIndex, | |
| 1503 word.Word, 0) | |
| 1504 .AsStringC(); | |
| 1505 | |
| 1506 if (word.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) { | |
| 1507 CFX_FloatRect rcUnderline = GetUnderLineRect(word); | |
| 1508 rcUnderline.left += ptOffset.x; | |
| 1509 rcUnderline.right += ptOffset.x; | |
| 1510 rcUnderline.top += ptOffset.y; | |
| 1511 rcUnderline.bottom += ptOffset.y; | |
| 1512 | |
| 1513 AddRectToPageObjects(pObjectHolder, crCurText, rcUnderline); | |
| 1514 } | |
| 1515 | |
| 1516 if (word.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) { | |
| 1517 CFX_FloatRect rcCrossout = GetCrossoutRect(word); | |
| 1518 rcCrossout.left += ptOffset.x; | |
| 1519 rcCrossout.right += ptOffset.x; | |
| 1520 rcCrossout.top += ptOffset.y; | |
| 1521 rcCrossout.bottom += ptOffset.y; | |
| 1522 | |
| 1523 AddRectToPageObjects(pObjectHolder, crCurText, rcCrossout); | |
| 1524 } | |
| 1525 | |
| 1526 oldplace = place; | |
| 1527 } | |
| 1528 } | |
| 1529 | |
| 1530 if (sTextBuf.GetLength() > 0) { | |
| 1531 ObjArray.Add(AddTextObjToPageObjects( | |
| 1532 pObjectHolder, crOld, pFontMap->GetPDFFont(wp.nFontIndex), | |
| 1533 wp.fFontSize, wp.fCharSpace, wp.nHorzScale, | |
| 1534 CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | |
| 1535 sTextBuf.MakeString())); | |
| 1536 } | |
| 1537 } | |
| 1538 } | |
| 1539 | |
| 1540 // static | |
| 1541 void CFX_Edit::GenerateUnderlineObjects(CPDF_PageObjectHolder* pObjectHolder, | |
| 1542 CFX_Edit* pEdit, | |
| 1543 const CFX_FloatPoint& ptOffset, | |
| 1544 const CPVT_WordRange* pRange, | |
| 1545 FX_COLORREF color) { | |
| 1546 CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); | |
| 1547 if (pEdit->GetFontMap()) { | |
| 1548 if (pRange) | |
| 1549 pIterator->SetAt(pRange->BeginPos); | |
| 1550 else | |
| 1551 pIterator->SetAt(0); | |
| 1552 | |
| 1553 CPVT_WordPlace oldplace; | |
| 1554 | |
| 1555 while (pIterator->NextWord()) { | |
| 1556 CPVT_WordPlace place = pIterator->GetAt(); | |
| 1557 if (pRange && place.WordCmp(pRange->EndPos) > 0) | |
| 1558 break; | |
| 1559 | |
| 1560 CPVT_Word word; | |
| 1561 if (pIterator->GetWord(word)) { | |
| 1562 CFX_FloatRect rcUnderline = GetUnderLineRect(word); | |
| 1563 rcUnderline.left += ptOffset.x; | |
| 1564 rcUnderline.right += ptOffset.x; | |
| 1565 rcUnderline.top += ptOffset.y; | |
| 1566 rcUnderline.bottom += ptOffset.y; | |
| 1567 AddRectToPageObjects(pObjectHolder, color, rcUnderline); | |
| 1568 } | |
| 1569 } | |
| 1570 } | |
| 1571 } | |
| 1572 | |
| 1573 CFX_Edit::CFX_Edit() | |
| 1574 : m_pVT(new CPDF_VariableText), | |
| 775 m_pNotify(nullptr), | 1575 m_pNotify(nullptr), |
| 776 m_pOprNotify(nullptr), | 1576 m_pOprNotify(nullptr), |
| 777 m_wpCaret(-1, -1, -1), | 1577 m_wpCaret(-1, -1, -1), |
| 778 m_wpOldCaret(-1, -1, -1), | 1578 m_wpOldCaret(-1, -1, -1), |
| 779 m_SelState(), | 1579 m_SelState(), |
| 780 m_ptScrollPos(0, 0), | 1580 m_ptScrollPos(0, 0), |
| 781 m_ptRefreshScrollPos(0, 0), | 1581 m_ptRefreshScrollPos(0, 0), |
| 782 m_bEnableScroll(FALSE), | 1582 m_bEnableScroll(FALSE), |
| 783 m_ptCaret(0.0f, 0.0f), | 1583 m_ptCaret(0.0f, 0.0f), |
| 784 m_Undo(kEditUndoMaxItems), | 1584 m_Undo(kEditUndoMaxItems), |
| 785 m_nAlignment(0), | 1585 m_nAlignment(0), |
| 786 m_bNotifyFlag(FALSE), | 1586 m_bNotifyFlag(FALSE), |
| 787 m_bEnableOverflow(FALSE), | 1587 m_bEnableOverflow(FALSE), |
| 788 m_bEnableRefresh(TRUE), | 1588 m_bEnableRefresh(TRUE), |
| 789 m_rcOldContent(0.0f, 0.0f, 0.0f, 0.0f), | 1589 m_rcOldContent(0.0f, 0.0f, 0.0f, 0.0f), |
| 790 m_bEnableUndo(TRUE), | 1590 m_bEnableUndo(TRUE), |
| 791 m_bNotify(TRUE), | 1591 m_bNotify(TRUE), |
| 792 m_bOprNotify(FALSE), | 1592 m_bOprNotify(FALSE), |
| 793 m_pGroupUndoItem(nullptr) { | 1593 m_pGroupUndoItem(nullptr) {} |
| 794 ASSERT(pVT); | |
| 795 } | |
| 796 | 1594 |
| 797 CFX_Edit::~CFX_Edit() { | 1595 CFX_Edit::~CFX_Edit() { |
| 798 ASSERT(!m_pGroupUndoItem); | 1596 ASSERT(!m_pGroupUndoItem); |
| 799 } | 1597 } |
| 800 | 1598 |
| 801 void CFX_Edit::Initialize() { | 1599 void CFX_Edit::Initialize() { |
| 802 m_pVT->Initialize(); | 1600 m_pVT->Initialize(); |
| 803 SetCaret(m_pVT->GetBeginWordPlace()); | 1601 SetCaret(m_pVT->GetBeginWordPlace()); |
| 804 SetCaretOrigin(); | 1602 SetCaretOrigin(); |
| 805 } | 1603 } |
| 806 | 1604 |
| 807 void CFX_Edit::SetFontMap(IPVT_FontMap* pFontMap) { | 1605 void CFX_Edit::SetFontMap(IPVT_FontMap* pFontMap) { |
| 808 m_pVTProvider.reset(new CFX_Edit_Provider(pFontMap)); | 1606 m_pVTProvider.reset(new CFX_Edit_Provider(pFontMap)); |
| 809 m_pVT->SetProvider(m_pVTProvider.get()); | 1607 m_pVT->SetProvider(m_pVTProvider.get()); |
| 810 } | 1608 } |
| 811 | 1609 |
| 812 void CFX_Edit::SetNotify(IFX_Edit_Notify* pNotify) { | 1610 void CFX_Edit::SetNotify(CPWL_EditCtrl* pNotify) { |
| 813 m_pNotify = pNotify; | 1611 m_pNotify = pNotify; |
| 814 } | 1612 } |
| 815 | 1613 |
| 816 void CFX_Edit::SetOprNotify(IFX_Edit_OprNotify* pOprNotify) { | 1614 void CFX_Edit::SetOprNotify(CPWL_Edit* pOprNotify) { |
| 817 m_pOprNotify = pOprNotify; | 1615 m_pOprNotify = pOprNotify; |
| 818 } | 1616 } |
| 819 | 1617 |
| 820 IFX_Edit_Iterator* CFX_Edit::GetIterator() { | 1618 CFX_Edit_Iterator* CFX_Edit::GetIterator() { |
| 821 if (!m_pIterator) | 1619 if (!m_pIterator) |
| 822 m_pIterator.reset(new CFX_Edit_Iterator(this, m_pVT->GetIterator())); | 1620 m_pIterator.reset(new CFX_Edit_Iterator(this, m_pVT->GetIterator())); |
| 823 return m_pIterator.get(); | 1621 return m_pIterator.get(); |
| 824 } | 1622 } |
| 825 | 1623 |
| 826 CPDF_VariableText* CFX_Edit::GetVariableText() { | 1624 CPDF_VariableText* CFX_Edit::GetVariableText() { |
| 827 return m_pVT; | 1625 return m_pVT.get(); |
| 828 } | 1626 } |
| 829 | 1627 |
| 830 IPVT_FontMap* CFX_Edit::GetFontMap() { | 1628 IPVT_FontMap* CFX_Edit::GetFontMap() { |
| 831 return m_pVTProvider ? m_pVTProvider->GetFontMap() : nullptr; | 1629 return m_pVTProvider ? m_pVTProvider->GetFontMap() : nullptr; |
| 832 } | 1630 } |
| 833 | 1631 |
| 834 void CFX_Edit::SetPlateRect(const CFX_FloatRect& rect, FX_BOOL bPaint) { | 1632 void CFX_Edit::SetPlateRect(const CFX_FloatRect& rect, FX_BOOL bPaint) { |
| 835 m_pVT->SetPlateRect(rect); | 1633 m_pVT->SetPlateRect(rect); |
| 836 m_ptScrollPos = CFX_FloatPoint(rect.left, rect.top); | 1634 m_ptScrollPos = CFX_FloatPoint(rect.left, rect.top); |
| 837 if (bPaint) | 1635 if (bPaint) |
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1796 ptRightTop.y); | 2594 ptRightTop.y); |
| 1797 } | 2595 } |
| 1798 | 2596 |
| 1799 void CFX_Edit::SetScrollInfo() { | 2597 void CFX_Edit::SetScrollInfo() { |
| 1800 if (m_bNotify && m_pNotify) { | 2598 if (m_bNotify && m_pNotify) { |
| 1801 CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); | 2599 CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
| 1802 CFX_FloatRect rcContent = m_pVT->GetContentRect(); | 2600 CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
| 1803 | 2601 |
| 1804 if (!m_bNotifyFlag) { | 2602 if (!m_bNotifyFlag) { |
| 1805 m_bNotifyFlag = TRUE; | 2603 m_bNotifyFlag = TRUE; |
| 1806 m_pNotify->IOnSetScrollInfoX(rcPlate.left, rcPlate.right, rcContent.left, | |
| 1807 rcContent.right, rcPlate.Width() / 3, | |
| 1808 rcPlate.Width()); | |
| 1809 | |
| 1810 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top, | 2604 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top, |
| 1811 rcContent.bottom, rcContent.top, | 2605 rcContent.bottom, rcContent.top, |
| 1812 rcPlate.Height() / 3, rcPlate.Height()); | 2606 rcPlate.Height() / 3, rcPlate.Height()); |
| 1813 m_bNotifyFlag = FALSE; | 2607 m_bNotifyFlag = FALSE; |
| 1814 } | 2608 } |
| 1815 } | 2609 } |
| 1816 } | 2610 } |
| 1817 | 2611 |
| 1818 void CFX_Edit::SetScrollPosX(FX_FLOAT fx) { | 2612 void CFX_Edit::SetScrollPosX(FX_FLOAT fx) { |
| 1819 if (!m_bEnableScroll) | 2613 if (!m_bEnableScroll) |
| 1820 return; | 2614 return; |
| 1821 | 2615 |
| 1822 if (m_pVT->IsValid()) { | 2616 if (m_pVT->IsValid()) { |
| 1823 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.x, fx)) { | 2617 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.x, fx)) { |
| 1824 m_ptScrollPos.x = fx; | 2618 m_ptScrollPos.x = fx; |
| 1825 Refresh(RP_NOANALYSE); | 2619 Refresh(RP_NOANALYSE); |
| 1826 | |
| 1827 if (m_bNotify && m_pNotify) { | |
|
Lei Zhang
2016/07/12 21:36:46
Why is this removed?
dsinclair
2016/07/13 14:05:45
Because IOnSetScrollPosX() did nothing and was rem
| |
| 1828 if (!m_bNotifyFlag) { | |
| 1829 m_bNotifyFlag = TRUE; | |
| 1830 m_pNotify->IOnSetScrollPosX(fx); | |
| 1831 m_bNotifyFlag = FALSE; | |
| 1832 } | |
| 1833 } | |
| 1834 } | 2620 } |
| 1835 } | 2621 } |
| 1836 } | 2622 } |
| 1837 | 2623 |
| 1838 void CFX_Edit::SetScrollPosY(FX_FLOAT fy) { | 2624 void CFX_Edit::SetScrollPosY(FX_FLOAT fy) { |
| 1839 if (!m_bEnableScroll) | 2625 if (!m_bEnableScroll) |
| 1840 return; | 2626 return; |
| 1841 | 2627 |
| 1842 if (m_pVT->IsValid()) { | 2628 if (m_pVT->IsValid()) { |
| 1843 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y, fy)) { | 2629 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y, fy)) { |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2436 void CFX_Edit::SetText(const FX_WCHAR* text, | 3222 void CFX_Edit::SetText(const FX_WCHAR* text, |
| 2437 int32_t charset, | 3223 int32_t charset, |
| 2438 const CPVT_SecProps* pSecProps, | 3224 const CPVT_SecProps* pSecProps, |
| 2439 const CPVT_WordProps* pWordProps, | 3225 const CPVT_WordProps* pWordProps, |
| 2440 FX_BOOL bAddUndo, | 3226 FX_BOOL bAddUndo, |
| 2441 FX_BOOL bPaint) { | 3227 FX_BOOL bPaint) { |
| 2442 Empty(); | 3228 Empty(); |
| 2443 DoInsertText(CPVT_WordPlace(0, 0, -1), text, charset, pSecProps, pWordProps); | 3229 DoInsertText(CPVT_WordPlace(0, 0, -1), text, charset, pSecProps, pWordProps); |
| 2444 if (bPaint) | 3230 if (bPaint) |
| 2445 Paint(); | 3231 Paint(); |
| 2446 if (m_bOprNotify && m_pOprNotify) | |
| 2447 m_pOprNotify->OnSetText(m_wpCaret, m_wpOldCaret); | |
| 2448 } | 3232 } |
| 2449 | 3233 |
| 2450 FX_BOOL CFX_Edit::InsertWord(uint16_t word, | 3234 FX_BOOL CFX_Edit::InsertWord(uint16_t word, |
| 2451 int32_t charset, | 3235 int32_t charset, |
| 2452 const CPVT_WordProps* pWordProps, | 3236 const CPVT_WordProps* pWordProps, |
| 2453 FX_BOOL bAddUndo, | 3237 FX_BOOL bAddUndo, |
| 2454 FX_BOOL bPaint) { | 3238 FX_BOOL bPaint) { |
| 2455 if (IsTextOverflow()) | 3239 if (IsTextOverflow()) |
| 2456 return FALSE; | 3240 return FALSE; |
| 2457 | 3241 |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3114 int32_t CFX_Edit_RectArray::GetSize() const { | 3898 int32_t CFX_Edit_RectArray::GetSize() const { |
| 3115 return m_Rects.GetSize(); | 3899 return m_Rects.GetSize(); |
| 3116 } | 3900 } |
| 3117 | 3901 |
| 3118 CFX_FloatRect* CFX_Edit_RectArray::GetAt(int32_t nIndex) const { | 3902 CFX_FloatRect* CFX_Edit_RectArray::GetAt(int32_t nIndex) const { |
| 3119 if (nIndex < 0 || nIndex >= m_Rects.GetSize()) | 3903 if (nIndex < 0 || nIndex >= m_Rects.GetSize()) |
| 3120 return nullptr; | 3904 return nullptr; |
| 3121 | 3905 |
| 3122 return m_Rects.GetAt(nIndex); | 3906 return m_Rects.GetAt(nIndex); |
| 3123 } | 3907 } |
| OLD | NEW |