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/include/cpdf_textpage.h" | 7 #include "core/fpdftext/include/cpdf_textpage.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 27 matching lines...) Expand all Loading... |
38 return threshold / 4.0f; | 38 return threshold / 4.0f; |
39 if (threshold < 700) | 39 if (threshold < 700) |
40 return threshold / 5.0f; | 40 return threshold / 5.0f; |
41 return threshold / 6.0f; | 41 return threshold / 6.0f; |
42 } | 42 } |
43 | 43 |
44 FX_FLOAT CalculateBaseSpace(const CPDF_TextObject* pTextObj, | 44 FX_FLOAT CalculateBaseSpace(const CPDF_TextObject* pTextObj, |
45 const CFX_Matrix& matrix) { | 45 const CFX_Matrix& matrix) { |
46 FX_FLOAT baseSpace = 0.0; | 46 FX_FLOAT baseSpace = 0.0; |
47 const int nItems = pTextObj->CountItems(); | 47 const int nItems = pTextObj->CountItems(); |
48 if (pTextObj->m_TextState.GetObject()->m_CharSpace && nItems >= 3) { | 48 if (pTextObj->m_TextState->m_CharSpace && nItems >= 3) { |
49 bool bAllChar = true; | 49 bool bAllChar = true; |
50 FX_FLOAT spacing = matrix.TransformDistance( | 50 FX_FLOAT spacing = |
51 pTextObj->m_TextState.GetObject()->m_CharSpace); | 51 matrix.TransformDistance(pTextObj->m_TextState->m_CharSpace); |
52 baseSpace = spacing; | 52 baseSpace = spacing; |
53 for (int i = 0; i < nItems; i++) { | 53 for (int i = 0; i < nItems; i++) { |
54 CPDF_TextObjectItem item; | 54 CPDF_TextObjectItem item; |
55 pTextObj->GetItemInfo(i, &item); | 55 pTextObj->GetItemInfo(i, &item); |
56 if (item.m_CharCode == static_cast<uint32_t>(-1)) { | 56 if (item.m_CharCode == static_cast<uint32_t>(-1)) { |
57 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); | 57 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); |
58 FX_FLOAT kerning = -fontsize_h * item.m_OriginX / 1000; | 58 FX_FLOAT kerning = -fontsize_h * item.m_OriginX / 1000; |
59 baseSpace = std::min(baseSpace, kerning + spacing); | 59 baseSpace = std::min(baseSpace, kerning + spacing); |
60 bAllChar = false; | 60 bAllChar = false; |
61 } | 61 } |
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 CFX_WideString str = m_TempTextBuf.MakeString(); | 1081 CFX_WideString str = m_TempTextBuf.MakeString(); |
1082 if (str.IsEmpty()) | 1082 if (str.IsEmpty()) |
1083 str = m_TextBuf.AsStringC(); | 1083 str = m_TextBuf.AsStringC(); |
1084 if (str.IsEmpty() || str.GetAt(str.GetLength() - 1) == TEXT_SPACE_CHAR) | 1084 if (str.IsEmpty() || str.GetAt(str.GetLength() - 1) == TEXT_SPACE_CHAR) |
1085 continue; | 1085 continue; |
1086 | 1086 |
1087 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); | 1087 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); |
1088 spacing = -fontsize_h * item.m_OriginX / 1000; | 1088 spacing = -fontsize_h * item.m_OriginX / 1000; |
1089 continue; | 1089 continue; |
1090 } | 1090 } |
1091 FX_FLOAT charSpace = pTextObj->m_TextState.GetObject()->m_CharSpace; | 1091 FX_FLOAT charSpace = pTextObj->m_TextState->m_CharSpace; |
1092 if (charSpace > 0.001) | 1092 if (charSpace > 0.001) |
1093 spacing += matrix.TransformDistance(charSpace); | 1093 spacing += matrix.TransformDistance(charSpace); |
1094 else if (charSpace < -0.001) | 1094 else if (charSpace < -0.001) |
1095 spacing -= matrix.TransformDistance(FXSYS_fabs(charSpace)); | 1095 spacing -= matrix.TransformDistance(FXSYS_fabs(charSpace)); |
1096 spacing -= baseSpace; | 1096 spacing -= baseSpace; |
1097 if (spacing && i > 0) { | 1097 if (spacing && i > 0) { |
1098 int last_width = 0; | 1098 int last_width = 0; |
1099 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); | 1099 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); |
1100 uint32_t space_charcode = pFont->CharCodeFromUnicode(' '); | 1100 uint32_t space_charcode = pFont->CharCodeFromUnicode(' '); |
1101 FX_FLOAT threshold = 0; | 1101 FX_FLOAT threshold = 0; |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1540 info.m_OriginY); | 1540 info.m_OriginY); |
1541 return TRUE; | 1541 return TRUE; |
1542 } | 1542 } |
1543 | 1543 |
1544 FX_BOOL CPDF_TextPage::IsRectIntersect(const CFX_FloatRect& rect1, | 1544 FX_BOOL CPDF_TextPage::IsRectIntersect(const CFX_FloatRect& rect1, |
1545 const CFX_FloatRect& rect2) { | 1545 const CFX_FloatRect& rect2) { |
1546 CFX_FloatRect rect = rect1; | 1546 CFX_FloatRect rect = rect1; |
1547 rect.Intersect(rect2); | 1547 rect.Intersect(rect2); |
1548 return !rect.IsEmpty(); | 1548 return !rect.IsEmpty(); |
1549 } | 1549 } |
OLD | NEW |