Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: core/fpdfdoc/cpdf_variabletext.cpp

Issue 2146503002: Remove RichText support from fpdfsdk/fxedit. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | core/fpdfdoc/include/cpdf_variabletext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 "core/fpdfdoc/include/cpdf_variabletext.h" 7 #include "core/fpdfdoc/include/cpdf_variabletext.h"
8 8
9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
10 #include "core/fpdfdoc/cpvt_wordinfo.h" 10 #include "core/fpdfdoc/cpvt_wordinfo.h"
11 #include "core/fpdfdoc/csection.h" 11 #include "core/fpdfdoc/csection.h"
12 #include "core/fpdfdoc/include/cpvt_section.h" 12 #include "core/fpdfdoc/include/cpvt_section.h"
13 #include "core/fpdfdoc/include/cpvt_word.h" 13 #include "core/fpdfdoc/include/cpvt_word.h"
14 #include "core/fpdfdoc/include/ipvt_fontmap.h" 14 #include "core/fpdfdoc/include/ipvt_fontmap.h"
15 15
16 namespace { 16 namespace {
17 17
18 const float kDefaultFontSize = 18.0f;
19 const float kFontScale = 0.001f; 18 const float kFontScale = 0.001f;
20 const uint8_t kReturnLength = 1; 19 const uint8_t kReturnLength = 1;
21 const float kScalePercent = 0.01f; 20 const float kScalePercent = 0.01f;
22 21
23 const uint8_t gFontSizeSteps[] = {4, 6, 8, 9, 10, 12, 14, 18, 20, 22 const uint8_t gFontSizeSteps[] = {4, 6, 8, 9, 10, 12, 14, 18, 20,
24 25, 30, 35, 40, 45, 50, 55, 60, 70, 23 25, 30, 35, 40, 45, 50, 55, 60, 70,
25 80, 90, 100, 110, 120, 130, 144}; 24 80, 90, 100, 110, 120, 130, 144};
26 25
27 } // namespace 26 } // namespace
28 27
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 m_bMultiLine(FALSE), 245 m_bMultiLine(FALSE),
247 m_bLimitWidth(FALSE), 246 m_bLimitWidth(FALSE),
248 m_bAutoFontSize(FALSE), 247 m_bAutoFontSize(FALSE),
249 m_nAlignment(0), 248 m_nAlignment(0),
250 m_fLineLeading(0.0f), 249 m_fLineLeading(0.0f),
251 m_fCharSpace(0.0f), 250 m_fCharSpace(0.0f),
252 m_nHorzScale(100), 251 m_nHorzScale(100),
253 m_wSubWord(0), 252 m_wSubWord(0),
254 m_fFontSize(0.0f), 253 m_fFontSize(0.0f),
255 m_bInitial(FALSE), 254 m_bInitial(FALSE),
256 m_bRichText(FALSE),
257 m_pVTProvider(nullptr) {} 255 m_pVTProvider(nullptr) {}
258 256
259 CPDF_VariableText::~CPDF_VariableText() { 257 CPDF_VariableText::~CPDF_VariableText() {
260 ResetAll(); 258 ResetAll();
261 } 259 }
262 260
263 void CPDF_VariableText::Initialize() { 261 void CPDF_VariableText::Initialize() {
264 if (!m_bInitial) { 262 if (!m_bInitial) {
265 CPVT_SectionInfo secinfo; 263 CPVT_SectionInfo secinfo;
266 if (m_bRichText) {
267 secinfo.pSecProps.reset(new CPVT_SecProps(0.0f, 0.0f, 0));
268 secinfo.pWordProps.reset(new CPVT_WordProps(
269 GetDefaultFontIndex(), kDefaultFontSize, 0, ScriptType::Normal, 0));
270 }
271 CPVT_WordPlace place; 264 CPVT_WordPlace place;
272 place.nSecIndex = 0; 265 place.nSecIndex = 0;
273 AddSection(place, secinfo); 266 AddSection(place, secinfo);
274 CPVT_LineInfo lineinfo; 267 CPVT_LineInfo lineinfo;
275 lineinfo.fLineAscent = GetFontAscent(GetDefaultFontIndex(), GetFontSize()); 268 lineinfo.fLineAscent = GetFontAscent(GetDefaultFontIndex(), GetFontSize());
276 lineinfo.fLineDescent = 269 lineinfo.fLineDescent =
277 GetFontDescent(GetDefaultFontIndex(), GetFontSize()); 270 GetFontDescent(GetDefaultFontIndex(), GetFontSize());
278 AddLine(place, lineinfo); 271 AddLine(place, lineinfo);
279 if (CSection* pSection = m_SectionArray.GetAt(0)) 272 if (CSection* pSection = m_SectionArray.GetAt(0))
280 pSection->ResetLinePlace(); 273 pSection->ResetLinePlace();
(...skipping 12 matching lines...) Expand all
293 int32_t charset, 286 int32_t charset,
294 const CPVT_WordProps* pWordProps) { 287 const CPVT_WordProps* pWordProps) {
295 int32_t nTotlaWords = GetTotalWords(); 288 int32_t nTotlaWords = GetTotalWords();
296 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) 289 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar)
297 return place; 290 return place;
298 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) 291 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray)
299 return place; 292 return place;
300 293
301 CPVT_WordPlace newplace = place; 294 CPVT_WordPlace newplace = place;
302 newplace.nWordIndex++; 295 newplace.nWordIndex++;
303 if (m_bRichText) {
304 CPVT_WordProps* pNewProps =
305 pWordProps ? new CPVT_WordProps(*pWordProps) : new CPVT_WordProps();
306 pNewProps->nFontIndex =
307 GetWordFontIndex(word, charset, pWordProps->nFontIndex);
308 return AddWord(newplace, CPVT_WordInfo(word, charset, -1, pNewProps));
309 }
310 int32_t nFontIndex = 296 int32_t nFontIndex =
311 GetSubWord() > 0 ? GetDefaultFontIndex() 297 GetSubWord() > 0 ? GetDefaultFontIndex()
312 : GetWordFontIndex(word, charset, GetDefaultFontIndex()); 298 : GetWordFontIndex(word, charset, GetDefaultFontIndex());
313 return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, nullptr)); 299 return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, nullptr));
314 } 300 }
315 301
316 CPVT_WordPlace CPDF_VariableText::InsertSection( 302 CPVT_WordPlace CPDF_VariableText::InsertSection(
317 const CPVT_WordPlace& place, 303 const CPVT_WordPlace& place,
318 const CPVT_SecProps* pSecProps, 304 const CPVT_SecProps* pSecProps,
319 const CPVT_WordProps* pWordProps) { 305 const CPVT_WordProps* pWordProps) {
320 int32_t nTotlaWords = GetTotalWords(); 306 int32_t nTotlaWords = GetTotalWords();
321 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) 307 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar)
322 return place; 308 return place;
323 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) 309 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray)
324 return place; 310 return place;
325 if (!m_bMultiLine) 311 if (!m_bMultiLine)
326 return place; 312 return place;
327 313
328 CPVT_WordPlace wordplace = place; 314 CPVT_WordPlace wordplace = place;
329 UpdateWordPlace(wordplace); 315 UpdateWordPlace(wordplace);
330 CPVT_WordPlace newplace = place; 316 CPVT_WordPlace newplace = place;
331 if (CSection* pSection = m_SectionArray.GetAt(wordplace.nSecIndex)) { 317 if (CSection* pSection = m_SectionArray.GetAt(wordplace.nSecIndex)) {
332 CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1); 318 CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1);
333 CPVT_SectionInfo secinfo; 319 CPVT_SectionInfo secinfo;
334 if (m_bRichText) {
335 if (pSecProps)
336 secinfo.pSecProps.reset(new CPVT_SecProps(*pSecProps));
337 if (pWordProps)
338 secinfo.pWordProps.reset(new CPVT_WordProps(*pWordProps));
339 }
340 AddSection(NewPlace, secinfo); 320 AddSection(NewPlace, secinfo);
341 newplace = NewPlace; 321 newplace = NewPlace;
342 if (CSection* pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) { 322 if (CSection* pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) {
343 for (int32_t w = wordplace.nWordIndex + 1, 323 for (int32_t w = wordplace.nWordIndex + 1,
344 sz = pSection->m_WordArray.GetSize(); 324 sz = pSection->m_WordArray.GetSize();
345 w < sz; w++) { 325 w < sz; w++) {
346 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(w)) { 326 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(w)) {
347 NewPlace.nWordIndex++; 327 NewPlace.nWordIndex++;
348 pNewSection->AddWord(NewPlace, *pWord); 328 pNewSection->AddWord(NewPlace, *pWord);
349 } 329 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 } 397 }
418 398
419 void CPDF_VariableText::SetText(const FX_WCHAR* text, 399 void CPDF_VariableText::SetText(const FX_WCHAR* text,
420 int32_t charset, 400 int32_t charset,
421 const CPVT_SecProps* pSecProps, 401 const CPVT_SecProps* pSecProps,
422 const CPVT_WordProps* pWordProps) { 402 const CPVT_WordProps* pWordProps) {
423 DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); 403 DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace()));
424 CFX_WideString swText = text; 404 CFX_WideString swText = text;
425 CPVT_WordPlace wp(0, 0, -1); 405 CPVT_WordPlace wp(0, 0, -1);
426 CPVT_SectionInfo secinfo; 406 CPVT_SectionInfo secinfo;
427 if (m_bRichText) {
428 if (pSecProps)
429 secinfo.pSecProps.reset(new CPVT_SecProps(*pSecProps));
430 if (pWordProps)
431 secinfo.pWordProps.reset(new CPVT_WordProps(*pWordProps));
432 }
433 if (CSection* pSection = m_SectionArray.GetAt(0)) 407 if (CSection* pSection = m_SectionArray.GetAt(0))
434 pSection->m_SecInfo = secinfo; 408 pSection->m_SecInfo = secinfo;
435 409
436 int32_t nCharCount = 0; 410 int32_t nCharCount = 0;
437 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { 411 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) {
438 if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) 412 if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar)
439 break; 413 break;
440 if (m_nCharArray > 0 && nCharCount >= m_nCharArray) 414 if (m_nCharArray > 0 && nCharCount >= m_nCharArray)
441 break; 415 break;
442 416
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 CFX_FloatRect CPDF_VariableText::GetContentRect() const { 768 CFX_FloatRect CPDF_VariableText::GetContentRect() const {
795 return InToOut(CPVT_FloatRect(CPDF_EditContainer::GetContentRect())); 769 return InToOut(CPVT_FloatRect(CPDF_EditContainer::GetContentRect()));
796 } 770 }
797 771
798 const CFX_FloatRect& CPDF_VariableText::GetPlateRect() const { 772 const CFX_FloatRect& CPDF_VariableText::GetPlateRect() const {
799 return CPDF_EditContainer::GetPlateRect(); 773 return CPDF_EditContainer::GetPlateRect();
800 } 774 }
801 775
802 FX_FLOAT CPDF_VariableText::GetWordFontSize(const CPVT_WordInfo& WordInfo, 776 FX_FLOAT CPDF_VariableText::GetWordFontSize(const CPVT_WordInfo& WordInfo,
803 FX_BOOL bFactFontSize) { 777 FX_BOOL bFactFontSize) {
804 return m_bRichText && WordInfo.pWordProps 778 return GetFontSize();
805 ? (WordInfo.pWordProps->nScriptType == ScriptType::Normal ||
806 bFactFontSize
807 ? WordInfo.pWordProps->fFontSize
808 : WordInfo.pWordProps->fFontSize * VARIABLETEXT_HALF)
809 : GetFontSize();
810 } 779 }
811 780
812 int32_t CPDF_VariableText::GetWordFontIndex(const CPVT_WordInfo& WordInfo) { 781 int32_t CPDF_VariableText::GetWordFontIndex(const CPVT_WordInfo& WordInfo) {
813 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nFontIndex 782 return WordInfo.nFontIndex;
814 : WordInfo.nFontIndex;
815 } 783 }
816 784
817 FX_FLOAT CPDF_VariableText::GetWordWidth(int32_t nFontIndex, 785 FX_FLOAT CPDF_VariableText::GetWordWidth(int32_t nFontIndex,
818 uint16_t Word, 786 uint16_t Word,
819 uint16_t SubWord, 787 uint16_t SubWord,
820 FX_FLOAT fCharSpace, 788 FX_FLOAT fCharSpace,
821 int32_t nHorzScale, 789 int32_t nHorzScale,
822 FX_FLOAT fFontSize, 790 FX_FLOAT fFontSize,
823 FX_FLOAT fWordTail, 791 FX_FLOAT fWordTail,
824 int32_t nWordStyle) { 792 int32_t nWordStyle) {
825 return (GetCharWidth(nFontIndex, Word, SubWord, nWordStyle) * fFontSize * 793 return (GetCharWidth(nFontIndex, Word, SubWord, nWordStyle) * fFontSize *
826 kFontScale + 794 kFontScale +
827 fCharSpace) * 795 fCharSpace) *
828 nHorzScale * kScalePercent + 796 nHorzScale * kScalePercent +
829 fWordTail; 797 fWordTail;
830 } 798 }
831 799
832 FX_FLOAT CPDF_VariableText::GetWordWidth(const CPVT_WordInfo& WordInfo) { 800 FX_FLOAT CPDF_VariableText::GetWordWidth(const CPVT_WordInfo& WordInfo) {
833 return GetWordWidth( 801 return GetWordWidth(
834 GetWordFontIndex(WordInfo), WordInfo.Word, GetSubWord(), 802 GetWordFontIndex(WordInfo), WordInfo.Word, GetSubWord(),
835 GetCharSpace(WordInfo), GetHorzScale(WordInfo), GetWordFontSize(WordInfo), 803 GetCharSpace(WordInfo), GetHorzScale(WordInfo), GetWordFontSize(WordInfo),
836 WordInfo.fWordTail, 804 WordInfo.fWordTail,
837 WordInfo.pWordProps ? WordInfo.pWordProps->nWordStyle : 0); 805 WordInfo.pWordProps ? WordInfo.pWordProps->nWordStyle : 0);
838 } 806 }
839 807
840 FX_FLOAT CPDF_VariableText::GetLineAscent(const CPVT_SectionInfo& SecInfo) { 808 FX_FLOAT CPDF_VariableText::GetLineAscent(const CPVT_SectionInfo& SecInfo) {
841 return m_bRichText && SecInfo.pWordProps 809 return GetFontAscent(GetDefaultFontIndex(), GetFontSize());
842 ? GetFontAscent(SecInfo.pWordProps->nFontIndex,
843 SecInfo.pWordProps->fFontSize)
844 : GetFontAscent(GetDefaultFontIndex(), GetFontSize());
845 } 810 }
846 811
847 FX_FLOAT CPDF_VariableText::GetLineDescent(const CPVT_SectionInfo& SecInfo) { 812 FX_FLOAT CPDF_VariableText::GetLineDescent(const CPVT_SectionInfo& SecInfo) {
848 return m_bRichText && SecInfo.pWordProps 813 return GetFontDescent(GetDefaultFontIndex(), GetFontSize());
849 ? GetFontDescent(SecInfo.pWordProps->nFontIndex,
850 SecInfo.pWordProps->fFontSize)
851 : GetFontDescent(GetDefaultFontIndex(), GetFontSize());
852 } 814 }
853 815
854 FX_FLOAT CPDF_VariableText::GetFontAscent(int32_t nFontIndex, 816 FX_FLOAT CPDF_VariableText::GetFontAscent(int32_t nFontIndex,
855 FX_FLOAT fFontSize) { 817 FX_FLOAT fFontSize) {
856 return (FX_FLOAT)GetTypeAscent(nFontIndex) * fFontSize * kFontScale; 818 return (FX_FLOAT)GetTypeAscent(nFontIndex) * fFontSize * kFontScale;
857 } 819 }
858 820
859 FX_FLOAT CPDF_VariableText::GetFontDescent(int32_t nFontIndex, 821 FX_FLOAT CPDF_VariableText::GetFontDescent(int32_t nFontIndex,
860 FX_FLOAT fFontSize) { 822 FX_FLOAT fFontSize) {
861 return (FX_FLOAT)GetTypeDescent(nFontIndex) * fFontSize * kFontScale; 823 return (FX_FLOAT)GetTypeDescent(nFontIndex) * fFontSize * kFontScale;
(...skipping 15 matching lines...) Expand all
877 GetWordFontSize(WordInfo, bFactFontSize)); 839 GetWordFontSize(WordInfo, bFactFontSize));
878 } 840 }
879 841
880 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo, 842 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo,
881 FX_BOOL bFactFontSize) { 843 FX_BOOL bFactFontSize) {
882 return GetFontDescent(GetWordFontIndex(WordInfo), 844 return GetFontDescent(GetWordFontIndex(WordInfo),
883 GetWordFontSize(WordInfo, bFactFontSize)); 845 GetWordFontSize(WordInfo, bFactFontSize));
884 } 846 }
885 847
886 FX_FLOAT CPDF_VariableText::GetLineLeading(const CPVT_SectionInfo& SecInfo) { 848 FX_FLOAT CPDF_VariableText::GetLineLeading(const CPVT_SectionInfo& SecInfo) {
887 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineLeading 849 return m_fLineLeading;
888 : m_fLineLeading;
889 } 850 }
890 851
891 FX_FLOAT CPDF_VariableText::GetLineIndent(const CPVT_SectionInfo& SecInfo) { 852 FX_FLOAT CPDF_VariableText::GetLineIndent(const CPVT_SectionInfo& SecInfo) {
892 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineIndent 853 return 0.0f;
893 : 0.0f;
894 } 854 }
895 855
896 int32_t CPDF_VariableText::GetAlignment(const CPVT_SectionInfo& SecInfo) { 856 int32_t CPDF_VariableText::GetAlignment(const CPVT_SectionInfo& SecInfo) {
897 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->nAlignment 857 return m_nAlignment;
898 : m_nAlignment;
899 } 858 }
900 859
901 FX_FLOAT CPDF_VariableText::GetCharSpace(const CPVT_WordInfo& WordInfo) { 860 FX_FLOAT CPDF_VariableText::GetCharSpace(const CPVT_WordInfo& WordInfo) {
902 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->fCharSpace 861 return m_fCharSpace;
903 : m_fCharSpace;
904 } 862 }
905 863
906 int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) { 864 int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) {
907 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nHorzScale 865 return m_nHorzScale;
908 : m_nHorzScale;
909 } 866 }
910 867
911 void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) { 868 void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) {
912 CPVT_WordPlace wordplace = AdjustLineHeader(place, TRUE); 869 CPVT_WordPlace wordplace = AdjustLineHeader(place, TRUE);
913 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 870 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
914 for (int32_t w = pSection->m_WordArray.GetSize() - 1; 871 for (int32_t w = pSection->m_WordArray.GetSize() - 1;
915 w > wordplace.nWordIndex; w--) { 872 w > wordplace.nWordIndex; w--) {
916 delete pSection->m_WordArray.GetAt(w); 873 delete pSection->m_WordArray.GetAt(w);
917 pSection->m_WordArray.RemoveAt(w); 874 pSection->m_WordArray.RemoveAt(w);
918 } 875 }
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 1107
1151 CPDF_VariableText::Iterator* CPDF_VariableText::GetIterator() { 1108 CPDF_VariableText::Iterator* CPDF_VariableText::GetIterator() {
1152 if (!m_pVTIterator) 1109 if (!m_pVTIterator)
1153 m_pVTIterator.reset(new CPDF_VariableText::Iterator(this)); 1110 m_pVTIterator.reset(new CPDF_VariableText::Iterator(this));
1154 return m_pVTIterator.get(); 1111 return m_pVTIterator.get();
1155 } 1112 }
1156 1113
1157 void CPDF_VariableText::SetProvider(CPDF_VariableText::Provider* pProvider) { 1114 void CPDF_VariableText::SetProvider(CPDF_VariableText::Provider* pProvider) {
1158 m_pVTProvider = pProvider; 1115 m_pVTProvider = pProvider;
1159 } 1116 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfdoc/include/cpdf_variabletext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698