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 "xfa/fxfa/app/xfa_textlayout.h" | 7 #include "xfa/fxfa/app/xfa_textlayout.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "core/fxcrt/fx_ext.h" | 11 #include "core/fxcrt/fx_ext.h" |
| 12 #include "third_party/base/stl_util.h" |
12 #include "xfa/fde/cfde_path.h" | 13 #include "xfa/fde/cfde_path.h" |
13 #include "xfa/fde/css/fde_csscache.h" | 14 #include "xfa/fde/css/fde_csscache.h" |
14 #include "xfa/fde/css/fde_cssstyleselector.h" | 15 #include "xfa/fde/css/fde_cssstyleselector.h" |
15 #include "xfa/fde/fde_gedevice.h" | 16 #include "xfa/fde/fde_gedevice.h" |
16 #include "xfa/fde/fde_object.h" | 17 #include "xfa/fde/fde_object.h" |
17 #include "xfa/fde/xml/fde_xml_imp.h" | 18 #include "xfa/fde/xml/fde_xml_imp.h" |
18 #include "xfa/fgas/crt/fgas_codepage.h" | 19 #include "xfa/fgas/crt/fgas_codepage.h" |
19 #include "xfa/fxfa/app/xfa_ffwidgetacc.h" | 20 #include "xfa/fxfa/app/xfa_ffwidgetacc.h" |
20 #include "xfa/fxfa/parser/cxfa_measurement.h" | 21 #include "xfa/fxfa/parser/cxfa_measurement.h" |
21 #include "xfa/fxfa/xfa_ffapp.h" | 22 #include "xfa/fxfa/xfa_ffapp.h" |
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 } | 998 } |
998 FX_FLOAT fLinePos = m_pLoader->m_fStartLineOffset; | 999 FX_FLOAT fLinePos = m_pLoader->m_fStartLineOffset; |
999 int32_t iLineIndex = 0; | 1000 int32_t iLineIndex = 0; |
1000 if (iBlockCount > 1) { | 1001 if (iBlockCount > 1) { |
1001 if (iBlockCount >= (iBlockIndex + 1) * 2) { | 1002 if (iBlockCount >= (iBlockIndex + 1) * 2) { |
1002 iLineIndex = m_Blocks.ElementAt(iBlockIndex * 2); | 1003 iLineIndex = m_Blocks.ElementAt(iBlockIndex * 2); |
1003 } else { | 1004 } else { |
1004 iLineIndex = m_Blocks.ElementAt(iBlockCount - 1) + | 1005 iLineIndex = m_Blocks.ElementAt(iBlockCount - 1) + |
1005 m_Blocks.ElementAt(iBlockCount - 2); | 1006 m_Blocks.ElementAt(iBlockCount - 2); |
1006 } | 1007 } |
1007 if (m_pLoader->m_BlocksHeight.GetSize() > 0) { | 1008 if (!m_pLoader->m_BlocksHeight.empty()) { |
1008 for (int32_t i = 0; i < iBlockIndex; i++) { | 1009 for (int32_t i = 0; i < iBlockIndex; i++) |
1009 fLinePos -= m_pLoader->m_BlocksHeight.ElementAt(i * 2 + 1); | 1010 fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; |
1010 } | |
1011 } | 1011 } |
1012 } | 1012 } |
1013 int32_t iCount = m_pLoader->m_lineHeights.GetSize(); | 1013 int32_t iCount = m_pLoader->m_lineHeights.GetSize(); |
1014 int32_t i = 0; | 1014 int32_t i = 0; |
1015 for (i = iLineIndex; i < iCount; i++) { | 1015 for (i = iLineIndex; i < iCount; i++) { |
1016 FX_FLOAT fLineHeight = m_pLoader->m_lineHeights.ElementAt(i); | 1016 FX_FLOAT fLineHeight = m_pLoader->m_lineHeights.ElementAt(i); |
1017 if ((i == iLineIndex) && (fLineHeight - fContentAreaHeight > 0.001)) { | 1017 if ((i == iLineIndex) && (fLineHeight - fContentAreaHeight > 0.001)) { |
1018 fCalcHeight = 0; | 1018 fCalcHeight = 0; |
1019 return true; | 1019 return true; |
1020 } | 1020 } |
1021 if (fLinePos + fLineHeight - fContentAreaHeight > 0.001) { | 1021 if (fLinePos + fLineHeight - fContentAreaHeight > 0.001) { |
1022 if (iBlockCount >= (iBlockIndex + 1) * 2) { | 1022 if (iBlockCount >= (iBlockIndex + 1) * 2) { |
1023 m_Blocks.SetAt(iBlockIndex * 2, iLineIndex); | 1023 m_Blocks.SetAt(iBlockIndex * 2, iLineIndex); |
1024 m_Blocks.SetAt(iBlockIndex * 2 + 1, i - iLineIndex); | 1024 m_Blocks.SetAt(iBlockIndex * 2 + 1, i - iLineIndex); |
1025 } else { | 1025 } else { |
1026 m_Blocks.Add(iLineIndex); | 1026 m_Blocks.Add(iLineIndex); |
1027 m_Blocks.Add(i - iLineIndex); | 1027 m_Blocks.Add(i - iLineIndex); |
1028 } | 1028 } |
1029 if (i == iLineIndex) { | 1029 if (i == iLineIndex) { |
1030 if (fCalcHeight <= fLinePos) { | 1030 if (fCalcHeight <= fLinePos) { |
1031 if (m_pLoader->m_BlocksHeight.GetSize() > iBlockIndex * 2 && | 1031 if (pdfium::CollectionSize<int32_t>(m_pLoader->m_BlocksHeight) > |
1032 (m_pLoader->m_BlocksHeight.GetAt(iBlockIndex * 2) == | 1032 iBlockIndex * 2 && |
1033 iBlockIndex)) { | 1033 (m_pLoader->m_BlocksHeight[iBlockIndex * 2] == iBlockIndex)) { |
1034 m_pLoader->m_BlocksHeight.SetAt(iBlockIndex * 2 + 1, fCalcHeight); | 1034 m_pLoader->m_BlocksHeight[iBlockIndex * 2 + 1] = fCalcHeight; |
1035 } else { | 1035 } else { |
1036 m_pLoader->m_BlocksHeight.Add((FX_FLOAT)iBlockIndex); | 1036 m_pLoader->m_BlocksHeight.push_back((FX_FLOAT)iBlockIndex); |
1037 m_pLoader->m_BlocksHeight.Add(fCalcHeight); | 1037 m_pLoader->m_BlocksHeight.push_back(fCalcHeight); |
1038 } | 1038 } |
1039 } | 1039 } |
1040 return true; | 1040 return true; |
1041 } | 1041 } |
1042 fCalcHeight = fLinePos; | 1042 fCalcHeight = fLinePos; |
1043 return true; | 1043 return true; |
1044 } | 1044 } |
1045 fLinePos += fLineHeight; | 1045 fLinePos += fLineHeight; |
1046 } | 1046 } |
1047 return false; | 1047 return false; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 return false; | 1096 return false; |
1097 if (m_pLoader->m_fWidth < 1) | 1097 if (m_pLoader->m_fWidth < 1) |
1098 return false; | 1098 return false; |
1099 | 1099 |
1100 m_pLoader->m_iTotalLines = -1; | 1100 m_pLoader->m_iTotalLines = -1; |
1101 m_iLines = 0; | 1101 m_iLines = 0; |
1102 FX_FLOAT fLinePos = 0; | 1102 FX_FLOAT fLinePos = 0; |
1103 CXFA_Node* pNode = nullptr; | 1103 CXFA_Node* pNode = nullptr; |
1104 CFX_SizeF szText(m_pLoader->m_fWidth, m_pLoader->m_fHeight); | 1104 CFX_SizeF szText(m_pLoader->m_fWidth, m_pLoader->m_fHeight); |
1105 int32_t iCount = m_Blocks.GetSize(); | 1105 int32_t iCount = m_Blocks.GetSize(); |
1106 int32_t iBlocksHeightCount = m_pLoader->m_BlocksHeight.GetSize(); | 1106 int32_t iBlocksHeightCount = |
| 1107 pdfium::CollectionSize<int32_t>(m_pLoader->m_BlocksHeight); |
1107 iBlocksHeightCount /= 2; | 1108 iBlocksHeightCount /= 2; |
1108 if (iBlock < iBlocksHeightCount) | 1109 if (iBlock < iBlocksHeightCount) |
1109 return true; | 1110 return true; |
1110 if (iBlock == iBlocksHeightCount) { | 1111 if (iBlock == iBlocksHeightCount) { |
1111 Unload(); | 1112 Unload(); |
1112 m_pBreak.reset(CreateBreak(true)); | 1113 m_pBreak.reset(CreateBreak(true)); |
1113 fLinePos = m_pLoader->m_fStartLineOffset; | 1114 fLinePos = m_pLoader->m_fStartLineOffset; |
1114 for (int32_t i = 0; i < iBlocksHeightCount; i++) { | 1115 for (int32_t i = 0; i < iBlocksHeightCount; i++) { |
1115 fLinePos -= m_pLoader->m_BlocksHeight.ElementAt(i * 2 + 1); | 1116 fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; |
1116 } | 1117 } |
1117 m_pLoader->m_iChar = 0; | 1118 m_pLoader->m_iChar = 0; |
1118 if (iCount > 1) | 1119 if (iCount > 1) |
1119 m_pLoader->m_iTotalLines = m_Blocks.ElementAt(iBlock * 2 + 1); | 1120 m_pLoader->m_iTotalLines = m_Blocks.ElementAt(iBlock * 2 + 1); |
1120 Loader(szText, fLinePos, true); | 1121 Loader(szText, fLinePos, true); |
1121 if (iCount == 0 && m_pLoader->m_fStartLineOffset < 0.1f) | 1122 if (iCount == 0 && m_pLoader->m_fStartLineOffset < 0.1f) |
1122 UpdateAlign(szText.y, fLinePos); | 1123 UpdateAlign(szText.y, fLinePos); |
1123 } else if (m_pTextDataNode) { | 1124 } else if (m_pTextDataNode) { |
1124 iBlock *= 2; | 1125 iBlock *= 2; |
1125 if (iBlock < iCount - 2) | 1126 if (iBlock < iCount - 2) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 } | 1181 } |
1181 int32_t iCountHeight = m_pLoader->m_lineHeights.GetSize(); | 1182 int32_t iCountHeight = m_pLoader->m_lineHeights.GetSize(); |
1182 if (iCountHeight == 0) { | 1183 if (iCountHeight == 0) { |
1183 return; | 1184 return; |
1184 } | 1185 } |
1185 bool bEndItem = true; | 1186 bool bEndItem = true; |
1186 int32_t iBlockCount = m_Blocks.GetSize(); | 1187 int32_t iBlockCount = m_Blocks.GetSize(); |
1187 FX_FLOAT fLinePos = m_pLoader->m_fStartLineOffset; | 1188 FX_FLOAT fLinePos = m_pLoader->m_fStartLineOffset; |
1188 int32_t iLineIndex = 0; | 1189 int32_t iLineIndex = 0; |
1189 if (iBlockIndex > 0) { | 1190 if (iBlockIndex > 0) { |
1190 int32_t iBlockHeightCount = m_pLoader->m_BlocksHeight.GetSize(); | 1191 int32_t iBlockHeightCount = |
| 1192 pdfium::CollectionSize<int32_t>(m_pLoader->m_BlocksHeight); |
1191 iBlockHeightCount /= 2; | 1193 iBlockHeightCount /= 2; |
1192 if (iBlockHeightCount >= iBlockIndex) { | 1194 if (iBlockHeightCount >= iBlockIndex) { |
1193 for (int32_t i = 0; i < iBlockIndex; i++) { | 1195 for (int32_t i = 0; i < iBlockIndex; i++) { |
1194 fLinePos -= m_pLoader->m_BlocksHeight.ElementAt(i * 2 + 1); | 1196 fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; |
1195 } | 1197 } |
1196 } else { | 1198 } else { |
1197 fLinePos = 0; | 1199 fLinePos = 0; |
1198 } | 1200 } |
1199 iLineIndex = m_Blocks.ElementAt(iBlockCount - 1) + | 1201 iLineIndex = m_Blocks[iBlockCount - 1] + m_Blocks[iBlockCount - 2]; |
1200 m_Blocks.ElementAt(iBlockCount - 2); | |
1201 } | 1202 } |
1202 int32_t i = 0; | 1203 int32_t i = 0; |
1203 for (i = iLineIndex; i < iCountHeight; i++) { | 1204 for (i = iLineIndex; i < iCountHeight; i++) { |
1204 FX_FLOAT fLineHeight = m_pLoader->m_lineHeights.ElementAt(i); | 1205 FX_FLOAT fLineHeight = m_pLoader->m_lineHeights.ElementAt(i); |
1205 if (fLinePos + fLineHeight - rtText.height > 0.001) { | 1206 if (fLinePos + fLineHeight - rtText.height > 0.001) { |
1206 m_Blocks.Add(iLineIndex); | 1207 m_Blocks.Add(iLineIndex); |
1207 m_Blocks.Add(i - iLineIndex); | 1208 m_Blocks.Add(i - iLineIndex); |
1208 bEndItem = false; | 1209 bEndItem = false; |
1209 break; | 1210 break; |
1210 } | 1211 } |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2094 m_tabstops.RemoveAll(); | 2095 m_tabstops.RemoveAll(); |
2095 m_iTabCount = 0; | 2096 m_iTabCount = 0; |
2096 } | 2097 } |
2097 | 2098 |
2098 void CXFA_TextTabstopsContext::Reset() { | 2099 void CXFA_TextTabstopsContext::Reset() { |
2099 m_iTabIndex = -1; | 2100 m_iTabIndex = -1; |
2100 m_bTabstops = false; | 2101 m_bTabstops = false; |
2101 m_fTabWidth = 0; | 2102 m_fTabWidth = 0; |
2102 m_fLeft = 0; | 2103 m_fLeft = 0; |
2103 } | 2104 } |
OLD | NEW |