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

Side by Side Diff: core/src/fpdftext/fpdf_text_int.cpp

Issue 1423103002: XFA: Manual merge of Clean up IFX_BidiChar (Closed) Base URL: https://pdfium.googlesource.com/pdfium@xfa
Patch Set: address comments Created 5 years, 1 month 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/src/fpdftext/fpdf_text.cpp ('k') | core/src/fpdftext/text_int.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 <ctype.h> 7 #include <ctype.h>
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "../../../third_party/base/nonstd_unique_ptr.h" 10 #include "../../../third_party/base/nonstd_unique_ptr.h"
11 #include "../../include/fpdfapi/fpdf_module.h" 11 #include "../../include/fpdfapi/fpdf_module.h"
12 #include "../../include/fpdfapi/fpdf_page.h" 12 #include "../../include/fpdfapi/fpdf_page.h"
13 #include "../../include/fpdfapi/fpdf_pageobj.h" 13 #include "../../include/fpdfapi/fpdf_pageobj.h"
14 #include "../../include/fpdfapi/fpdf_resource.h" 14 #include "../../include/fpdfapi/fpdf_resource.h"
15 #include "../../include/fpdftext/fpdf_text.h" 15 #include "../../include/fpdftext/fpdf_text.h"
16 #include "../../include/fxcrt/fx_arb.h" 16 #include "../../include/fxcrt/fx_bidi.h"
17 #include "../../include/fxcrt/fx_ucd.h" 17 #include "../../include/fxcrt/fx_ucd.h"
18 #include "text_int.h" 18 #include "text_int.h"
19 19
20 namespace { 20 namespace {
21 21
22 FX_BOOL _IsIgnoreSpaceCharacter(FX_WCHAR curChar) { 22 FX_BOOL _IsIgnoreSpaceCharacter(FX_WCHAR curChar) {
23 if (curChar < 255) { 23 if (curChar < 255) {
24 return FALSE; 24 return FALSE;
25 } 25 }
26 if ((curChar >= 0x0600 && curChar <= 0x06FF) || 26 if ((curChar >= 0x0600 && curChar <= 0x06FF) ||
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 pFont->AppendChar(str, charCode); 994 pFont->AppendChar(str, charCode);
995 w = pFont->GetStringWidth(str, 1); 995 w = pFont->GetStringWidth(str, 1);
996 if (w == 0) { 996 if (w == 0) {
997 FX_RECT BBox; 997 FX_RECT BBox;
998 pFont->GetCharBBox(charCode, BBox); 998 pFont->GetCharBBox(charCode, BBox);
999 w = BBox.right - BBox.left; 999 w = BBox.right - BBox.left;
1000 } 1000 }
1001 } 1001 }
1002 return w; 1002 return w;
1003 } 1003 }
1004 void CPDF_TextPage::OnPiece(IFX_BidiChar* pBidi, CFX_WideString& str) { 1004 void CPDF_TextPage::OnPiece(CFX_BidiChar* pBidi, CFX_WideString& str) {
1005 int32_t start, count; 1005 int32_t start, count;
1006 int32_t ret = pBidi->GetBidiInfo(start, count); 1006 CFX_BidiChar::Direction ret = pBidi->GetBidiInfo(&start, &count);
1007 if (ret == 2) { 1007 if (ret == CFX_BidiChar::RIGHT) {
1008 for (int i = start + count - 1; i >= start; i--) { 1008 for (int i = start + count - 1; i >= start; i--) {
1009 m_TextBuf.AppendChar(str.GetAt(i)); 1009 m_TextBuf.AppendChar(str.GetAt(i));
1010 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); 1010 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i));
1011 } 1011 }
1012 } else { 1012 } else {
1013 int end = start + count; 1013 int end = start + count;
1014 for (int i = start; i < end; i++) { 1014 for (int i = start; i < end; i++) {
1015 m_TextBuf.AppendChar(str.GetAt(i)); 1015 m_TextBuf.AppendChar(str.GetAt(i));
1016 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); 1016 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i));
1017 } 1017 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 } 1078 }
1079 if (!m_ParseOptions.m_bGetCharCodeOnly) { 1079 if (!m_ParseOptions.m_bGetCharCodeOnly) {
1080 m_charList.Add(Info); 1080 m_charList.Add(Info);
1081 } 1081 }
1082 } 1082 }
1083 void CPDF_TextPage::CloseTempLine() { 1083 void CPDF_TextPage::CloseTempLine() {
1084 int count1 = m_TempCharList.GetSize(); 1084 int count1 = m_TempCharList.GetSize();
1085 if (count1 <= 0) { 1085 if (count1 <= 0) {
1086 return; 1086 return;
1087 } 1087 }
1088 nonstd::unique_ptr<IFX_BidiChar> pBidiChar(IFX_BidiChar::Create()); 1088 nonstd::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar);
1089 CFX_WideString str = m_TempTextBuf.GetWideString(); 1089 CFX_WideString str = m_TempTextBuf.GetWideString();
1090 CFX_WordArray order; 1090 CFX_WordArray order;
1091 FX_BOOL bR2L = FALSE; 1091 FX_BOOL bR2L = FALSE;
1092 int32_t start = 0, count = 0; 1092 int32_t start = 0, count = 0;
1093 int nR2L = 0, nL2R = 0; 1093 int nR2L = 0, nL2R = 0;
1094 FX_BOOL bPrevSpace = FALSE; 1094 FX_BOOL bPrevSpace = FALSE;
1095 for (int i = 0; i < str.GetLength(); i++) { 1095 for (int i = 0; i < str.GetLength(); i++) {
1096 if (str.GetAt(i) == 32) { 1096 if (str.GetAt(i) == 32) {
1097 if (bPrevSpace) { 1097 if (bPrevSpace) {
1098 m_TempTextBuf.Delete(i, 1); 1098 m_TempTextBuf.Delete(i, 1);
1099 m_TempCharList.Delete(i); 1099 m_TempCharList.Delete(i);
1100 str.Delete(i); 1100 str.Delete(i);
1101 count1--; 1101 count1--;
1102 i--; 1102 i--;
1103 continue; 1103 continue;
1104 } 1104 }
1105 bPrevSpace = TRUE; 1105 bPrevSpace = TRUE;
1106 } else { 1106 } else {
1107 bPrevSpace = FALSE; 1107 bPrevSpace = FALSE;
1108 } 1108 }
1109 if (pBidiChar->AppendChar(str.GetAt(i))) { 1109 if (pBidiChar->AppendChar(str.GetAt(i))) {
1110 int32_t ret = pBidiChar->GetBidiInfo(start, count); 1110 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count);
1111 order.Add(start); 1111 order.Add(start);
1112 order.Add(count); 1112 order.Add(count);
1113 order.Add(ret); 1113 order.Add(ret);
1114 if (!bR2L) { 1114 if (!bR2L) {
1115 if (ret == 2) { 1115 if (ret == CFX_BidiChar::RIGHT) {
1116 nR2L++; 1116 nR2L++;
1117 } else if (ret == 1) { 1117 } else if (ret == CFX_BidiChar::LEFT) {
1118 nL2R++; 1118 nL2R++;
1119 } 1119 }
1120 } 1120 }
1121 } 1121 }
1122 } 1122 }
1123 if (pBidiChar->EndChar()) { 1123 if (pBidiChar->EndChar()) {
1124 int32_t ret = pBidiChar->GetBidiInfo(start, count); 1124 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count);
1125 order.Add(start); 1125 order.Add(start);
1126 order.Add(count); 1126 order.Add(count);
1127 order.Add(ret); 1127 order.Add(ret);
1128 if (!bR2L) { 1128 if (!bR2L) {
1129 if (ret == 2) { 1129 if (ret == CFX_BidiChar::RIGHT) {
1130 nR2L++; 1130 nR2L++;
1131 } else if (ret == 1) { 1131 } else if (ret == CFX_BidiChar::LEFT) {
1132 nL2R++; 1132 nL2R++;
1133 } 1133 }
1134 } 1134 }
1135 } 1135 }
1136 if (nR2L > 0 && nR2L >= nL2R) { 1136 if (nR2L > 0 && nR2L >= nL2R) {
1137 bR2L = TRUE; 1137 bR2L = TRUE;
1138 } 1138 }
1139 if (m_parserflag == FPDFTEXT_RLTB || bR2L) { 1139 if (m_parserflag == FPDFTEXT_RLTB || bR2L) {
1140 int count = order.GetSize(); 1140 int count = order.GetSize();
1141 for (int i = count - 1; i > 0; i -= 3) { 1141 for (int i = count - 1; i > 0; i -= 3) {
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 m_pPreTextObj = pTextObj; 1553 m_pPreTextObj = pTextObj;
1554 m_perMatrix.Copy(formMatrix); 1554 m_perMatrix.Copy(formMatrix);
1555 return; 1555 return;
1556 } 1556 }
1557 m_pPreTextObj = pTextObj; 1557 m_pPreTextObj = pTextObj;
1558 m_perMatrix.Copy(formMatrix); 1558 m_perMatrix.Copy(formMatrix);
1559 int nItems = pTextObj->CountItems(); 1559 int nItems = pTextObj->CountItems();
1560 FX_FLOAT baseSpace = _CalculateBaseSpace(pTextObj, matrix); 1560 FX_FLOAT baseSpace = _CalculateBaseSpace(pTextObj, matrix);
1561 1561
1562 FX_BOOL bIsBidiAndMirrosInverse = FALSE; 1562 FX_BOOL bIsBidiAndMirrosInverse = FALSE;
1563 IFX_BidiChar* BidiChar = IFX_BidiChar::Create(); 1563 CFX_BidiChar* BidiChar = new CFX_BidiChar;
1564 int32_t nR2L = 0; 1564 int32_t nR2L = 0;
1565 int32_t nL2R = 0; 1565 int32_t nL2R = 0;
1566 int32_t start = 0, count = 0; 1566 int32_t start = 0, count = 0;
1567 CPDF_TextObjectItem item; 1567 CPDF_TextObjectItem item;
1568 for (int32_t i = 0; i < nItems; i++) { 1568 for (int32_t i = 0; i < nItems; i++) {
1569 pTextObj->GetItemInfo(i, &item); 1569 pTextObj->GetItemInfo(i, &item);
1570 if (item.m_CharCode == (FX_DWORD)-1) { 1570 if (item.m_CharCode == (FX_DWORD)-1) {
1571 continue; 1571 continue;
1572 } 1572 }
1573 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); 1573 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode);
1574 FX_WCHAR wChar = wstrItem.GetAt(0); 1574 FX_WCHAR wChar = wstrItem.GetAt(0);
1575 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { 1575 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) {
1576 wChar = (FX_WCHAR)item.m_CharCode; 1576 wChar = (FX_WCHAR)item.m_CharCode;
1577 } 1577 }
1578 if (!wChar) { 1578 if (!wChar) {
1579 continue; 1579 continue;
1580 } 1580 }
1581 if (BidiChar && BidiChar->AppendChar(wChar)) { 1581 if (BidiChar && BidiChar->AppendChar(wChar)) {
1582 int32_t ret = BidiChar->GetBidiInfo(start, count); 1582 CFX_BidiChar::Direction ret = BidiChar->GetBidiInfo(&start, &count);
1583 if (ret == 2) { 1583 if (ret == CFX_BidiChar::RIGHT) {
1584 nR2L++; 1584 nR2L++;
1585 } else if (ret == 1) { 1585 } else if (ret == CFX_BidiChar::LEFT) {
1586 nL2R++; 1586 nL2R++;
1587 } 1587 }
1588 } 1588 }
1589 } 1589 }
1590 if (BidiChar && BidiChar->EndChar()) { 1590 if (BidiChar && BidiChar->EndChar()) {
1591 int32_t ret = BidiChar->GetBidiInfo(start, count); 1591 CFX_BidiChar::Direction ret = BidiChar->GetBidiInfo(&start, &count);
1592 if (ret == 2) { 1592 if (ret == CFX_BidiChar::RIGHT) {
1593 nR2L++; 1593 nR2L++;
1594 } else if (ret == 1) { 1594 } else if (ret == CFX_BidiChar::LEFT) {
1595 nL2R++; 1595 nL2R++;
1596 } 1596 }
1597 } 1597 }
1598 FX_BOOL bR2L = FALSE; 1598 FX_BOOL bR2L = FALSE;
1599 if (nR2L > 0 && nR2L >= nL2R) { 1599 if (nR2L > 0 && nR2L >= nL2R) {
1600 bR2L = TRUE; 1600 bR2L = TRUE;
1601 } 1601 }
1602 bIsBidiAndMirrosInverse = 1602 bIsBidiAndMirrosInverse =
1603 bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0; 1603 bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0;
1604 int32_t iBufStartAppend = m_TempTextBuf.GetLength(); 1604 int32_t iBufStartAppend = m_TempTextBuf.GetLength();
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2756 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { 2756 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) {
2757 return; 2757 return;
2758 } 2758 }
2759 CPDF_LinkExt* link = NULL; 2759 CPDF_LinkExt* link = NULL;
2760 link = m_LinkList.GetAt(index); 2760 link = m_LinkList.GetAt(index);
2761 if (!link) { 2761 if (!link) {
2762 return; 2762 return;
2763 } 2763 }
2764 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); 2764 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects);
2765 } 2765 }
OLDNEW
« no previous file with comments | « core/src/fpdftext/fpdf_text.cpp ('k') | core/src/fpdftext/text_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698