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 "core/fpdftext/fpdf_text_int.h" | 7 #include "core/fpdftext/fpdf_text_int.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cctype> | 10 #include <cctype> |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 FX_FLOAT baseSpace = 0.0; | 73 FX_FLOAT baseSpace = 0.0; |
74 const int nItems = pTextObj->CountItems(); | 74 const int nItems = pTextObj->CountItems(); |
75 if (pTextObj->m_TextState.GetObject()->m_CharSpace && nItems >= 3) { | 75 if (pTextObj->m_TextState.GetObject()->m_CharSpace && nItems >= 3) { |
76 FX_BOOL bAllChar = TRUE; | 76 FX_BOOL bAllChar = TRUE; |
77 FX_FLOAT spacing = matrix.TransformDistance( | 77 FX_FLOAT spacing = matrix.TransformDistance( |
78 pTextObj->m_TextState.GetObject()->m_CharSpace); | 78 pTextObj->m_TextState.GetObject()->m_CharSpace); |
79 baseSpace = spacing; | 79 baseSpace = spacing; |
80 for (int i = 0; i < nItems; i++) { | 80 for (int i = 0; i < nItems; i++) { |
81 CPDF_TextObjectItem item; | 81 CPDF_TextObjectItem item; |
82 pTextObj->GetItemInfo(i, &item); | 82 pTextObj->GetItemInfo(i, &item); |
83 if (item.m_CharCode == (FX_DWORD)-1) { | 83 if (item.m_CharCode == (uint32_t)-1) { |
84 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); | 84 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); |
85 FX_FLOAT kerning = -fontsize_h * item.m_OriginX / 1000; | 85 FX_FLOAT kerning = -fontsize_h * item.m_OriginX / 1000; |
86 baseSpace = std::min(baseSpace, kerning + spacing); | 86 baseSpace = std::min(baseSpace, kerning + spacing); |
87 bAllChar = FALSE; | 87 bAllChar = FALSE; |
88 } | 88 } |
89 } | 89 } |
90 if (baseSpace < 0.0 || (nItems == 3 && !bAllChar)) { | 90 if (baseSpace < 0.0 || (nItems == 3 && !bAllChar)) { |
91 baseSpace = 0.0; | 91 baseSpace = 0.0; |
92 } | 92 } |
93 } | 93 } |
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 if (CPDF_PageObject* pPageObj = it->get()) { | 890 if (CPDF_PageObject* pPageObj = it->get()) { |
891 if (pPageObj->IsText()) { | 891 if (pPageObj->IsText()) { |
892 ProcessTextObject(pPageObj->AsText(), curFormMatrix, pObjectList, it); | 892 ProcessTextObject(pPageObj->AsText(), curFormMatrix, pObjectList, it); |
893 } else if (pPageObj->IsForm()) { | 893 } else if (pPageObj->IsForm()) { |
894 ProcessFormObject(pPageObj->AsForm(), curFormMatrix); | 894 ProcessFormObject(pPageObj->AsForm(), curFormMatrix); |
895 } | 895 } |
896 } | 896 } |
897 } | 897 } |
898 } | 898 } |
899 | 899 |
900 int CPDF_TextPage::GetCharWidth(FX_DWORD charCode, CPDF_Font* pFont) const { | 900 int CPDF_TextPage::GetCharWidth(uint32_t charCode, CPDF_Font* pFont) const { |
901 if (charCode == -1) | 901 if (charCode == -1) |
902 return 0; | 902 return 0; |
903 | 903 |
904 if (int w = pFont->GetCharWidthF(charCode)) | 904 if (int w = pFont->GetCharWidthF(charCode)) |
905 return w; | 905 return w; |
906 | 906 |
907 CFX_ByteString str; | 907 CFX_ByteString str; |
908 pFont->AppendChar(str, charCode); | 908 pFont->AppendChar(str, charCode); |
909 if (int w = pFont->GetStringWidth(str, 1)) | 909 if (int w = pFont->GetStringWidth(str, 1)) |
910 return w; | 910 return w; |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 } | 1260 } |
1261 } | 1261 } |
1262 | 1262 |
1263 FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, | 1263 FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, |
1264 const CPDF_Font* pFont, | 1264 const CPDF_Font* pFont, |
1265 int nItems) const { | 1265 int nItems) const { |
1266 CFX_WideString str; | 1266 CFX_WideString str; |
1267 for (int32_t i = 0; i < nItems; i++) { | 1267 for (int32_t i = 0; i < nItems; i++) { |
1268 CPDF_TextObjectItem item; | 1268 CPDF_TextObjectItem item; |
1269 pTextObj->GetItemInfo(i, &item); | 1269 pTextObj->GetItemInfo(i, &item); |
1270 if (item.m_CharCode == (FX_DWORD)-1) { | 1270 if (item.m_CharCode == (uint32_t)-1) { |
1271 continue; | 1271 continue; |
1272 } | 1272 } |
1273 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); | 1273 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); |
1274 FX_WCHAR wChar = wstrItem.GetAt(0); | 1274 FX_WCHAR wChar = wstrItem.GetAt(0); |
1275 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { | 1275 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { |
1276 wChar = (FX_WCHAR)item.m_CharCode; | 1276 wChar = (FX_WCHAR)item.m_CharCode; |
1277 } | 1277 } |
1278 if (wChar) | 1278 if (wChar) |
1279 str += wChar; | 1279 str += wChar; |
1280 } | 1280 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 int32_t iCharListStartAppend = | 1386 int32_t iCharListStartAppend = |
1387 pdfium::CollectionSize<int32_t>(m_TempCharList); | 1387 pdfium::CollectionSize<int32_t>(m_TempCharList); |
1388 | 1388 |
1389 FX_FLOAT spacing = 0; | 1389 FX_FLOAT spacing = 0; |
1390 for (int i = 0; i < nItems; i++) { | 1390 for (int i = 0; i < nItems; i++) { |
1391 CPDF_TextObjectItem item; | 1391 CPDF_TextObjectItem item; |
1392 PAGECHAR_INFO charinfo; | 1392 PAGECHAR_INFO charinfo; |
1393 charinfo.m_OriginX = 0; | 1393 charinfo.m_OriginX = 0; |
1394 charinfo.m_OriginY = 0; | 1394 charinfo.m_OriginY = 0; |
1395 pTextObj->GetItemInfo(i, &item); | 1395 pTextObj->GetItemInfo(i, &item); |
1396 if (item.m_CharCode == (FX_DWORD)-1) { | 1396 if (item.m_CharCode == (uint32_t)-1) { |
1397 CFX_WideString str = m_TempTextBuf.GetWideString(); | 1397 CFX_WideString str = m_TempTextBuf.GetWideString(); |
1398 if (str.IsEmpty()) { | 1398 if (str.IsEmpty()) { |
1399 str = m_TextBuf.GetWideString(); | 1399 str = m_TextBuf.GetWideString(); |
1400 } | 1400 } |
1401 if (str.IsEmpty() || str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) { | 1401 if (str.IsEmpty() || str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) { |
1402 continue; | 1402 continue; |
1403 } | 1403 } |
1404 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); | 1404 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); |
1405 spacing = -fontsize_h * item.m_OriginX / 1000; | 1405 spacing = -fontsize_h * item.m_OriginX / 1000; |
1406 continue; | 1406 continue; |
1407 } | 1407 } |
1408 FX_FLOAT charSpace = pTextObj->m_TextState.GetObject()->m_CharSpace; | 1408 FX_FLOAT charSpace = pTextObj->m_TextState.GetObject()->m_CharSpace; |
1409 if (charSpace > 0.001) { | 1409 if (charSpace > 0.001) { |
1410 spacing += matrix.TransformDistance(charSpace); | 1410 spacing += matrix.TransformDistance(charSpace); |
1411 } else if (charSpace < -0.001) { | 1411 } else if (charSpace < -0.001) { |
1412 spacing -= matrix.TransformDistance(FXSYS_fabs(charSpace)); | 1412 spacing -= matrix.TransformDistance(FXSYS_fabs(charSpace)); |
1413 } | 1413 } |
1414 spacing -= baseSpace; | 1414 spacing -= baseSpace; |
1415 if (spacing && i > 0) { | 1415 if (spacing && i > 0) { |
1416 int last_width = 0; | 1416 int last_width = 0; |
1417 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); | 1417 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); |
1418 FX_DWORD space_charcode = pFont->CharCodeFromUnicode(' '); | 1418 uint32_t space_charcode = pFont->CharCodeFromUnicode(' '); |
1419 FX_FLOAT threshold = 0; | 1419 FX_FLOAT threshold = 0; |
1420 if (space_charcode != -1) { | 1420 if (space_charcode != -1) { |
1421 threshold = fontsize_h * pFont->GetCharWidthF(space_charcode) / 1000; | 1421 threshold = fontsize_h * pFont->GetCharWidthF(space_charcode) / 1000; |
1422 } | 1422 } |
1423 if (threshold > fontsize_h / 3) { | 1423 if (threshold > fontsize_h / 3) { |
1424 threshold = 0; | 1424 threshold = 0; |
1425 } else { | 1425 } else { |
1426 threshold /= 2; | 1426 threshold /= 2; |
1427 } | 1427 } |
1428 if (threshold == 0) { | 1428 if (threshold == 0) { |
(...skipping 12 matching lines...) Expand all Loading... |
1441 m_TempTextBuf.AppendChar(TEXT_BLANK_CHAR); | 1441 m_TempTextBuf.AppendChar(TEXT_BLANK_CHAR); |
1442 charinfo.m_CharCode = -1; | 1442 charinfo.m_CharCode = -1; |
1443 charinfo.m_Matrix.Copy(formMatrix); | 1443 charinfo.m_Matrix.Copy(formMatrix); |
1444 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX, | 1444 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX, |
1445 charinfo.m_OriginY); | 1445 charinfo.m_OriginY); |
1446 charinfo.m_CharBox = | 1446 charinfo.m_CharBox = |
1447 CFX_FloatRect(charinfo.m_OriginX, charinfo.m_OriginY, | 1447 CFX_FloatRect(charinfo.m_OriginX, charinfo.m_OriginY, |
1448 charinfo.m_OriginX, charinfo.m_OriginY); | 1448 charinfo.m_OriginX, charinfo.m_OriginY); |
1449 m_TempCharList.push_back(charinfo); | 1449 m_TempCharList.push_back(charinfo); |
1450 } | 1450 } |
1451 if (item.m_CharCode == (FX_DWORD)-1) { | 1451 if (item.m_CharCode == (uint32_t)-1) { |
1452 continue; | 1452 continue; |
1453 } | 1453 } |
1454 } | 1454 } |
1455 spacing = 0; | 1455 spacing = 0; |
1456 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); | 1456 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); |
1457 FX_BOOL bNoUnicode = FALSE; | 1457 FX_BOOL bNoUnicode = FALSE; |
1458 FX_WCHAR wChar = wstrItem.GetAt(0); | 1458 FX_WCHAR wChar = wstrItem.GetAt(0); |
1459 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { | 1459 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { |
1460 if (wstrItem.IsEmpty()) { | 1460 if (wstrItem.IsEmpty()) { |
1461 wstrItem += (FX_WCHAR)item.m_CharCode; | 1461 wstrItem += (FX_WCHAR)item.m_CharCode; |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1854 preChar = &m_CharList.back(); | 1854 preChar = &m_CharList.back(); |
1855 } else { | 1855 } else { |
1856 return FALSE; | 1856 return FALSE; |
1857 } | 1857 } |
1858 info.m_Index = m_TextBuf.GetLength(); | 1858 info.m_Index = m_TextBuf.GetLength(); |
1859 info.m_Unicode = unicode; | 1859 info.m_Unicode = unicode; |
1860 info.m_pTextObj = NULL; | 1860 info.m_pTextObj = NULL; |
1861 info.m_CharCode = -1; | 1861 info.m_CharCode = -1; |
1862 info.m_Flag = FPDFTEXT_CHAR_GENERATED; | 1862 info.m_Flag = FPDFTEXT_CHAR_GENERATED; |
1863 int preWidth = 0; | 1863 int preWidth = 0; |
1864 if (preChar->m_pTextObj && preChar->m_CharCode != (FX_DWORD)-1) | 1864 if (preChar->m_pTextObj && preChar->m_CharCode != (uint32_t)-1) |
1865 preWidth = | 1865 preWidth = |
1866 GetCharWidth(preChar->m_CharCode, preChar->m_pTextObj->GetFont()); | 1866 GetCharWidth(preChar->m_CharCode, preChar->m_pTextObj->GetFont()); |
1867 | 1867 |
1868 FX_FLOAT fFontSize = preChar->m_pTextObj ? preChar->m_pTextObj->GetFontSize() | 1868 FX_FLOAT fFontSize = preChar->m_pTextObj ? preChar->m_pTextObj->GetFontSize() |
1869 : preChar->m_CharBox.Height(); | 1869 : preChar->m_CharBox.Height(); |
1870 if (!fFontSize) | 1870 if (!fFontSize) |
1871 fFontSize = kDefaultFontSize; | 1871 fFontSize = kDefaultFontSize; |
1872 | 1872 |
1873 info.m_OriginX = preChar->m_OriginX + preWidth * (fFontSize) / 1000; | 1873 info.m_OriginX = preChar->m_OriginX + preWidth * (fFontSize) / 1000; |
1874 info.m_OriginY = preChar->m_OriginY; | 1874 info.m_OriginY = preChar->m_OriginY; |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2509 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { | 2509 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { |
2510 return; | 2510 return; |
2511 } | 2511 } |
2512 CPDF_LinkExt* link = NULL; | 2512 CPDF_LinkExt* link = NULL; |
2513 link = m_LinkList.GetAt(index); | 2513 link = m_LinkList.GetAt(index); |
2514 if (!link) { | 2514 if (!link) { |
2515 return; | 2515 return; |
2516 } | 2516 } |
2517 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); | 2517 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); |
2518 } | 2518 } |
OLD | NEW |