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

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

Issue 1821043003: Remove FX_WORD in favor of uint16_t. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Use stdint.h directly, bitfield minefield. Created 4 years, 9 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 | « core/fpdfdoc/doc_form.cpp ('k') | core/fpdfdoc/pdf_vt.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 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "core/fpdfdoc/pdf_vt.h" 9 #include "core/fpdfdoc/pdf_vt.h"
10 #include "core/include/fpdfdoc/fpdf_doc.h" 10 #include "core/include/fpdfdoc/fpdf_doc.h"
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 0x10, 0x00, 0x00, 0x28, 0x0C, 0x08, 0x00, 0x00, 0x28, 0x28, 0x28, 0x28, 403 0x10, 0x00, 0x00, 0x28, 0x0C, 0x08, 0x00, 0x00, 0x28, 0x28, 0x28, 0x28,
404 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x08, 0x08, 404 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x08, 0x08,
405 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 405 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
406 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 406 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
407 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0C, 0x00, 0x08, 0x00, 0x00, 407 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0C, 0x00, 0x08, 0x00, 0x00,
408 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 408 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
409 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 409 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
410 0x01, 0x01, 0x01, 0x0C, 0x00, 0x08, 0x00, 0x00, 410 0x01, 0x01, 0x01, 0x0C, 0x00, 0x08, 0x00, 0x00,
411 }; 411 };
412 412
413 static bool IsLatin(FX_WORD word) { 413 static bool IsLatin(uint16_t word) {
414 if (word <= 0x007F) 414 if (word <= 0x007F)
415 return !!(special_chars[word] & 0x01); 415 return !!(special_chars[word] & 0x01);
416 416
417 return ((word >= 0x00C0 && word <= 0x00FF) || 417 return ((word >= 0x00C0 && word <= 0x00FF) ||
418 (word >= 0x0100 && word <= 0x024F) || 418 (word >= 0x0100 && word <= 0x024F) ||
419 (word >= 0x1E00 && word <= 0x1EFF) || 419 (word >= 0x1E00 && word <= 0x1EFF) ||
420 (word >= 0x2C60 && word <= 0x2C7F) || 420 (word >= 0x2C60 && word <= 0x2C7F) ||
421 (word >= 0xA720 && word <= 0xA7FF) || 421 (word >= 0xA720 && word <= 0xA7FF) ||
422 (word >= 0xFF21 && word <= 0xFF3A) || 422 (word >= 0xFF21 && word <= 0xFF3A) ||
423 (word >= 0xFF41 && word <= 0xFF5A)); 423 (word >= 0xFF41 && word <= 0xFF5A));
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 static bool IsOpenStylePunctuation(FX_DWORD word) { 502 static bool IsOpenStylePunctuation(FX_DWORD word) {
503 if (word <= 0x007F) 503 if (word <= 0x007F)
504 return !!(special_chars[word] & 0x04); 504 return !!(special_chars[word] & 0x04);
505 505
506 return (word == 0x300A || word == 0x300C || word == 0x300E || 506 return (word == 0x300A || word == 0x300C || word == 0x300E ||
507 word == 0x3010 || word == 0x3014 || word == 0x3016 || 507 word == 0x3010 || word == 0x3014 || word == 0x3016 ||
508 word == 0x3018 || word == 0x301A || word == 0xFF08 || 508 word == 0x3018 || word == 0x301A || word == 0xFF08 ||
509 word == 0xFF3B || word == 0xFF5B || word == 0xFF62); 509 word == 0xFF3B || word == 0xFF5B || word == 0xFF62);
510 } 510 }
511 511
512 static bool IsCurrencySymbol(FX_WORD word) { 512 static bool IsCurrencySymbol(uint16_t word) {
513 return (word == 0x0024 || word == 0x0080 || word == 0x00A2 || 513 return (word == 0x0024 || word == 0x0080 || word == 0x00A2 ||
514 word == 0x00A3 || word == 0x00A4 || word == 0x00A5 || 514 word == 0x00A3 || word == 0x00A4 || word == 0x00A5 ||
515 (word >= 0x20A0 && word <= 0x20CF) || word == 0xFE69 || 515 (word >= 0x20A0 && word <= 0x20CF) || word == 0xFE69 ||
516 word == 0xFF04 || word == 0xFFE0 || word == 0xFFE1 || 516 word == 0xFF04 || word == 0xFFE0 || word == 0xFFE1 ||
517 word == 0xFFE5 || word == 0xFFE6); 517 word == 0xFFE5 || word == 0xFFE6);
518 } 518 }
519 519
520 static bool IsPrefixSymbol(FX_WORD word) { 520 static bool IsPrefixSymbol(uint16_t word) {
521 return IsCurrencySymbol(word) || word == 0x2116; 521 return IsCurrencySymbol(word) || word == 0x2116;
522 } 522 }
523 523
524 static bool IsSpace(FX_WORD word) { 524 static bool IsSpace(uint16_t word) {
525 return word == 0x0020 || word == 0x3000; 525 return word == 0x0020 || word == 0x3000;
526 } 526 }
527 527
528 static bool NeedDivision(FX_WORD prevWord, FX_WORD curWord) { 528 static bool NeedDivision(uint16_t prevWord, uint16_t curWord) {
529 if ((IsLatin(prevWord) || IsDigit(prevWord)) && 529 if ((IsLatin(prevWord) || IsDigit(prevWord)) &&
530 (IsLatin(curWord) || IsDigit(curWord))) { 530 (IsLatin(curWord) || IsDigit(curWord))) {
531 return false; 531 return false;
532 } 532 }
533 if (IsSpace(curWord) || IsPunctuation(curWord)) { 533 if (IsSpace(curWord) || IsPunctuation(curWord)) {
534 return false; 534 return false;
535 } 535 }
536 if (IsConnectiveSymbol(prevWord) || IsConnectiveSymbol(curWord)) { 536 if (IsConnectiveSymbol(prevWord) || IsConnectiveSymbol(curWord)) {
537 return false; 537 return false;
538 } 538 }
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 pSection->ResetLinePlace(); 812 pSection->ResetLinePlace();
813 } 813 }
814 m_bInitial = TRUE; 814 m_bInitial = TRUE;
815 } 815 }
816 } 816 }
817 void CPDF_VariableText::ResetAll() { 817 void CPDF_VariableText::ResetAll() {
818 m_bInitial = FALSE; 818 m_bInitial = FALSE;
819 ResetSectionArray(); 819 ResetSectionArray();
820 } 820 }
821 CPVT_WordPlace CPDF_VariableText::InsertWord(const CPVT_WordPlace& place, 821 CPVT_WordPlace CPDF_VariableText::InsertWord(const CPVT_WordPlace& place,
822 FX_WORD word, 822 uint16_t word,
823 int32_t charset, 823 int32_t charset,
824 const CPVT_WordProps* pWordProps) { 824 const CPVT_WordProps* pWordProps) {
825 int32_t nTotlaWords = GetTotalWords(); 825 int32_t nTotlaWords = GetTotalWords();
826 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) { 826 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) {
827 return place; 827 return place;
828 } 828 }
829 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) { 829 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) {
830 return place; 830 return place;
831 } 831 }
832 CPVT_WordPlace newplace = place; 832 CPVT_WordPlace newplace = place;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 } 889 }
890 CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace& place, 890 CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace& place,
891 const FX_WCHAR* text, 891 const FX_WCHAR* text,
892 int32_t charset, 892 int32_t charset,
893 const CPVT_SecProps* pSecProps, 893 const CPVT_SecProps* pSecProps,
894 const CPVT_WordProps* pProps) { 894 const CPVT_WordProps* pProps) {
895 CFX_WideString swText = text; 895 CFX_WideString swText = text;
896 CPVT_WordPlace wp = place; 896 CPVT_WordPlace wp = place;
897 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { 897 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) {
898 CPVT_WordPlace oldwp = wp; 898 CPVT_WordPlace oldwp = wp;
899 FX_WORD word = swText.GetAt(i); 899 uint16_t word = swText.GetAt(i);
900 switch (word) { 900 switch (word) {
901 case 0x0D: 901 case 0x0D:
902 if (m_bMultiLine) { 902 if (m_bMultiLine) {
903 if (swText.GetAt(i + 1) == 0x0A) { 903 if (swText.GetAt(i + 1) == 0x0A) {
904 i += 1; 904 i += 1;
905 } 905 }
906 wp = InsertSection(wp, pSecProps, pProps); 906 wp = InsertSection(wp, pSecProps, pProps);
907 } 907 }
908 break; 908 break;
909 case 0x0A: 909 case 0x0A:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 pSection->m_SecInfo = secinfo; 967 pSection->m_SecInfo = secinfo;
968 } 968 }
969 int32_t nCharCount = 0; 969 int32_t nCharCount = 0;
970 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { 970 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) {
971 if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) { 971 if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) {
972 break; 972 break;
973 } 973 }
974 if (m_nCharArray > 0 && nCharCount >= m_nCharArray) { 974 if (m_nCharArray > 0 && nCharCount >= m_nCharArray) {
975 break; 975 break;
976 } 976 }
977 FX_WORD word = swText.GetAt(i); 977 uint16_t word = swText.GetAt(i);
978 switch (word) { 978 switch (word) {
979 case 0x0D: 979 case 0x0D:
980 if (m_bMultiLine) { 980 if (m_bMultiLine) {
981 if (swText.GetAt(i + 1) == 0x0A) { 981 if (swText.GetAt(i + 1) == 0x0A) {
982 i += 1; 982 i += 1;
983 } 983 }
984 wp.nSecIndex++; 984 wp.nSecIndex++;
985 wp.nLineIndex = 0; 985 wp.nLineIndex = 0;
986 wp.nWordIndex = -1; 986 wp.nWordIndex = -1;
987 AddSection(wp, secinfo); 987 AddSection(wp, secinfo);
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 bFactFontSize 1325 bFactFontSize
1326 ? WordInfo.pWordProps->fFontSize 1326 ? WordInfo.pWordProps->fFontSize
1327 : WordInfo.pWordProps->fFontSize * PVT_HALF) 1327 : WordInfo.pWordProps->fFontSize * PVT_HALF)
1328 : GetFontSize(); 1328 : GetFontSize();
1329 } 1329 }
1330 int32_t CPDF_VariableText::GetWordFontIndex(const CPVT_WordInfo& WordInfo) { 1330 int32_t CPDF_VariableText::GetWordFontIndex(const CPVT_WordInfo& WordInfo) {
1331 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nFontIndex 1331 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nFontIndex
1332 : WordInfo.nFontIndex; 1332 : WordInfo.nFontIndex;
1333 } 1333 }
1334 FX_FLOAT CPDF_VariableText::GetWordWidth(int32_t nFontIndex, 1334 FX_FLOAT CPDF_VariableText::GetWordWidth(int32_t nFontIndex,
1335 FX_WORD Word, 1335 uint16_t Word,
1336 FX_WORD SubWord, 1336 uint16_t SubWord,
1337 FX_FLOAT fCharSpace, 1337 FX_FLOAT fCharSpace,
1338 int32_t nHorzScale, 1338 int32_t nHorzScale,
1339 FX_FLOAT fFontSize, 1339 FX_FLOAT fFontSize,
1340 FX_FLOAT fWordTail, 1340 FX_FLOAT fWordTail,
1341 int32_t nWordStyle) { 1341 int32_t nWordStyle) {
1342 return (GetCharWidth(nFontIndex, Word, SubWord, nWordStyle) * fFontSize * 1342 return (GetCharWidth(nFontIndex, Word, SubWord, nWordStyle) * fFontSize *
1343 PVT_FONTSCALE + 1343 PVT_FONTSCALE +
1344 fCharSpace) * 1344 fCharSpace) *
1345 nHorzScale * PVT_PERCENT + 1345 nHorzScale * PVT_PERCENT +
1346 fWordTail; 1346 fWordTail;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 rcRet.top = std::min(rcSec.top, rcRet.top); 1605 rcRet.top = std::min(rcSec.top, rcRet.top);
1606 rcRet.right = std::max(rcSec.right, rcRet.right); 1606 rcRet.right = std::max(rcSec.right, rcRet.right);
1607 rcRet.bottom = std::max(rcSec.bottom, rcRet.bottom); 1607 rcRet.bottom = std::max(rcSec.bottom, rcRet.bottom);
1608 } 1608 }
1609 fPosY += rcSec.Height(); 1609 fPosY += rcSec.Height();
1610 } 1610 }
1611 } 1611 }
1612 return rcRet; 1612 return rcRet;
1613 } 1613 }
1614 int32_t CPDF_VariableText::GetCharWidth(int32_t nFontIndex, 1614 int32_t CPDF_VariableText::GetCharWidth(int32_t nFontIndex,
1615 FX_WORD Word, 1615 uint16_t Word,
1616 FX_WORD SubWord, 1616 uint16_t SubWord,
1617 int32_t nWordStyle) { 1617 int32_t nWordStyle) {
1618 if (!m_pVTProvider) { 1618 if (!m_pVTProvider) {
1619 return 0; 1619 return 0;
1620 } 1620 }
1621 if (SubWord > 0) { 1621 if (SubWord > 0) {
1622 return m_pVTProvider->GetCharWidth(nFontIndex, SubWord, nWordStyle); 1622 return m_pVTProvider->GetCharWidth(nFontIndex, SubWord, nWordStyle);
1623 } 1623 }
1624 return m_pVTProvider->GetCharWidth(nFontIndex, Word, nWordStyle); 1624 return m_pVTProvider->GetCharWidth(nFontIndex, Word, nWordStyle);
1625 } 1625 }
1626 int32_t CPDF_VariableText::GetTypeAscent(int32_t nFontIndex) { 1626 int32_t CPDF_VariableText::GetTypeAscent(int32_t nFontIndex) {
1627 return m_pVTProvider ? m_pVTProvider->GetTypeAscent(nFontIndex) : 0; 1627 return m_pVTProvider ? m_pVTProvider->GetTypeAscent(nFontIndex) : 0;
1628 } 1628 }
1629 int32_t CPDF_VariableText::GetTypeDescent(int32_t nFontIndex) { 1629 int32_t CPDF_VariableText::GetTypeDescent(int32_t nFontIndex) {
1630 return m_pVTProvider ? m_pVTProvider->GetTypeDescent(nFontIndex) : 0; 1630 return m_pVTProvider ? m_pVTProvider->GetTypeDescent(nFontIndex) : 0;
1631 } 1631 }
1632 int32_t CPDF_VariableText::GetWordFontIndex(FX_WORD word, 1632 int32_t CPDF_VariableText::GetWordFontIndex(uint16_t word,
1633 int32_t charset, 1633 int32_t charset,
1634 int32_t nFontIndex) { 1634 int32_t nFontIndex) {
1635 return m_pVTProvider 1635 return m_pVTProvider
1636 ? m_pVTProvider->GetWordFontIndex(word, charset, nFontIndex) 1636 ? m_pVTProvider->GetWordFontIndex(word, charset, nFontIndex)
1637 : -1; 1637 : -1;
1638 } 1638 }
1639 int32_t CPDF_VariableText::GetDefaultFontIndex() { 1639 int32_t CPDF_VariableText::GetDefaultFontIndex() {
1640 return m_pVTProvider ? m_pVTProvider->GetDefaultFontIndex() : -1; 1640 return m_pVTProvider ? m_pVTProvider->GetDefaultFontIndex() : -1;
1641 } 1641 }
1642 FX_BOOL CPDF_VariableText::IsLatinWord(FX_WORD word) { 1642 FX_BOOL CPDF_VariableText::IsLatinWord(uint16_t word) {
1643 return m_pVTProvider ? m_pVTProvider->IsLatinWord(word) : FALSE; 1643 return m_pVTProvider ? m_pVTProvider->IsLatinWord(word) : FALSE;
1644 } 1644 }
1645 IPDF_VariableText_Iterator* CPDF_VariableText::GetIterator() { 1645 IPDF_VariableText_Iterator* CPDF_VariableText::GetIterator() {
1646 if (!m_pVTIterator) { 1646 if (!m_pVTIterator) {
1647 m_pVTIterator = new CPDF_VariableText_Iterator(this); 1647 m_pVTIterator = new CPDF_VariableText_Iterator(this);
1648 } 1648 }
1649 return m_pVTIterator; 1649 return m_pVTIterator;
1650 } 1650 }
1651 IPDF_VariableText_Provider* CPDF_VariableText::SetProvider( 1651 IPDF_VariableText_Provider* CPDF_VariableText::SetProvider(
1652 IPDF_VariableText_Provider* pProvider) { 1652 IPDF_VariableText_Provider* pProvider) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 if (pSection->m_SecInfo.pSecProps) { 1798 if (pSection->m_SecInfo.pSecProps) {
1799 *pSection->m_SecInfo.pSecProps = section.SecProps; 1799 *pSection->m_SecInfo.pSecProps = section.SecProps;
1800 } 1800 }
1801 if (pSection->m_SecInfo.pWordProps) { 1801 if (pSection->m_SecInfo.pWordProps) {
1802 *pSection->m_SecInfo.pWordProps = section.WordProps; 1802 *pSection->m_SecInfo.pWordProps = section.WordProps;
1803 } 1803 }
1804 return TRUE; 1804 return TRUE;
1805 } 1805 }
1806 return FALSE; 1806 return FALSE;
1807 } 1807 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/doc_form.cpp ('k') | core/fpdfdoc/pdf_vt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698