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_ffwidgetacc.h" | 7 #include "xfa/fxfa/app/xfa_ffwidgetacc.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
| 11 #include <vector> |
11 | 12 |
12 #include "fxjs/cfxjse_value.h" | 13 #include "fxjs/cfxjse_value.h" |
| 14 #include "third_party/base/stl_util.h" |
13 #include "xfa/fde/tto/fde_textout.h" | 15 #include "xfa/fde/tto/fde_textout.h" |
14 #include "xfa/fde/xml/fde_xml_imp.h" | 16 #include "xfa/fde/xml/fde_xml_imp.h" |
15 #include "xfa/fxfa/app/xfa_ffcheckbutton.h" | 17 #include "xfa/fxfa/app/xfa_ffcheckbutton.h" |
16 #include "xfa/fxfa/app/xfa_ffchoicelist.h" | 18 #include "xfa/fxfa/app/xfa_ffchoicelist.h" |
17 #include "xfa/fxfa/app/xfa_fffield.h" | 19 #include "xfa/fxfa/app/xfa_fffield.h" |
18 #include "xfa/fxfa/app/xfa_fwladapter.h" | 20 #include "xfa/fxfa/app/xfa_fwladapter.h" |
19 #include "xfa/fxfa/app/xfa_textlayout.h" | 21 #include "xfa/fxfa/app/xfa_textlayout.h" |
20 #include "xfa/fxfa/cxfa_eventparam.h" | 22 #include "xfa/fxfa/cxfa_eventparam.h" |
21 #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" | 23 #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" |
22 #include "xfa/fxfa/parser/cxfa_scriptcontext.h" | 24 #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return false; | 120 return false; |
119 m_pCapTextProvider.reset( | 121 m_pCapTextProvider.reset( |
120 new CXFA_TextProvider(pAcc, XFA_TEXTPROVIDERTYPE_Caption)); | 122 new CXFA_TextProvider(pAcc, XFA_TEXTPROVIDERTYPE_Caption)); |
121 m_pCapTextLayout.reset(new CXFA_TextLayout(m_pCapTextProvider.get())); | 123 m_pCapTextLayout.reset(new CXFA_TextLayout(m_pCapTextProvider.get())); |
122 return true; | 124 return true; |
123 } | 125 } |
124 | 126 |
125 std::unique_ptr<CXFA_TextLayout> m_pCapTextLayout; | 127 std::unique_ptr<CXFA_TextLayout> m_pCapTextLayout; |
126 std::unique_ptr<CXFA_TextProvider> m_pCapTextProvider; | 128 std::unique_ptr<CXFA_TextProvider> m_pCapTextProvider; |
127 std::unique_ptr<CFDE_TextOut> m_pTextOut; | 129 std::unique_ptr<CFDE_TextOut> m_pTextOut; |
128 std::unique_ptr<CFX_FloatArray> m_pFieldSplitArray; | 130 std::vector<FX_FLOAT> m_FieldSplitArray; |
129 }; | 131 }; |
130 | 132 |
131 class CXFA_TextEditData : public CXFA_FieldLayoutData { | 133 class CXFA_TextEditData : public CXFA_FieldLayoutData { |
132 public: | 134 public: |
133 }; | 135 }; |
134 | 136 |
135 class CXFA_ImageEditData : public CXFA_FieldLayoutData { | 137 class CXFA_ImageEditData : public CXFA_FieldLayoutData { |
136 public: | 138 public: |
137 CXFA_ImageEditData() | 139 CXFA_ImageEditData() |
138 : m_pDIBitmap(nullptr), | 140 : m_pDIBitmap(nullptr), |
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 if (wsText.IsEmpty()) { | 1234 if (wsText.IsEmpty()) { |
1233 iLinesCount = 1; | 1235 iLinesCount = 1; |
1234 } else { | 1236 } else { |
1235 if (!pFieldData->m_pTextOut) { | 1237 if (!pFieldData->m_pTextOut) { |
1236 FX_FLOAT fWidth = 0; | 1238 FX_FLOAT fWidth = 0; |
1237 GetWidth(fWidth); | 1239 GetWidth(fWidth); |
1238 CalculateAccWidthAndHeight(eUIType, fWidth, fHeight); | 1240 CalculateAccWidthAndHeight(eUIType, fWidth, fHeight); |
1239 } | 1241 } |
1240 iLinesCount = pFieldData->m_pTextOut->GetTotalLines(); | 1242 iLinesCount = pFieldData->m_pTextOut->GetTotalLines(); |
1241 } | 1243 } |
1242 if (!pFieldData->m_pFieldSplitArray) { | 1244 std::vector<FX_FLOAT>* pFieldArray = &pFieldData->m_FieldSplitArray; |
1243 pFieldData->m_pFieldSplitArray.reset(new CFX_FloatArray); | 1245 int32_t iFieldSplitCount = pdfium::CollectionSize<int32_t>(*pFieldArray); |
1244 } | |
1245 CFX_FloatArray* pFieldArray = pFieldData->m_pFieldSplitArray.get(); | |
1246 int32_t iFieldSplitCount = pFieldArray->GetSize(); | |
1247 for (int32_t i = 0; i < iBlockIndex * 3; i += 3) { | 1246 for (int32_t i = 0; i < iBlockIndex * 3; i += 3) { |
1248 iLinesCount -= (int32_t)pFieldArray->GetAt(i + 1); | 1247 iLinesCount -= (int32_t)(*pFieldArray)[i + 1]; |
1249 fHeight -= pFieldArray->GetAt(i + 2); | 1248 fHeight -= (*pFieldArray)[i + 2]; |
1250 } | 1249 } |
1251 if (iLinesCount == 0) { | 1250 if (iLinesCount == 0) { |
1252 return false; | 1251 return false; |
1253 } | 1252 } |
1254 FX_FLOAT fLineHeight = GetLineHeight(); | 1253 FX_FLOAT fLineHeight = GetLineHeight(); |
1255 FX_FLOAT fFontSize = GetFontSize(); | 1254 FX_FLOAT fFontSize = GetFontSize(); |
1256 FX_FLOAT fTextHeight = iLinesCount * fLineHeight - fLineHeight + fFontSize; | 1255 FX_FLOAT fTextHeight = iLinesCount * fLineHeight - fLineHeight + fFontSize; |
1257 FX_FLOAT fSpaceAbove = 0; | 1256 FX_FLOAT fSpaceAbove = 0; |
1258 FX_FLOAT fStartOffset = 0; | 1257 FX_FLOAT fStartOffset = 0; |
1259 if (fHeight > 0.1f && iBlockIndex == 0) { | 1258 if (fHeight > 0.1f && iBlockIndex == 0) { |
1260 fStartOffset = fTopInset; | 1259 fStartOffset = fTopInset; |
1261 fHeight -= (fTopInset + fBottomInset); | 1260 fHeight -= (fTopInset + fBottomInset); |
1262 if (CXFA_Para para = GetPara()) { | 1261 if (CXFA_Para para = GetPara()) { |
1263 fSpaceAbove = para.GetSpaceAbove(); | 1262 fSpaceAbove = para.GetSpaceAbove(); |
1264 FX_FLOAT fSpaceBelow = para.GetSpaceBelow(); | 1263 FX_FLOAT fSpaceBelow = para.GetSpaceBelow(); |
1265 fHeight -= (fSpaceAbove + fSpaceBelow); | 1264 fHeight -= (fSpaceAbove + fSpaceBelow); |
1266 switch (para.GetVerticalAlign()) { | 1265 switch (para.GetVerticalAlign()) { |
1267 case XFA_ATTRIBUTEENUM_Top: | 1266 case XFA_ATTRIBUTEENUM_Top: |
1268 fStartOffset += fSpaceAbove; | 1267 fStartOffset += fSpaceAbove; |
1269 break; | 1268 break; |
1270 case XFA_ATTRIBUTEENUM_Middle: | 1269 case XFA_ATTRIBUTEENUM_Middle: |
1271 fStartOffset += ((fHeight - fTextHeight) / 2 + fSpaceAbove); | 1270 fStartOffset += ((fHeight - fTextHeight) / 2 + fSpaceAbove); |
1272 break; | 1271 break; |
1273 case XFA_ATTRIBUTEENUM_Bottom: | 1272 case XFA_ATTRIBUTEENUM_Bottom: |
1274 fStartOffset += (fHeight - fTextHeight + fSpaceAbove); | 1273 fStartOffset += (fHeight - fTextHeight + fSpaceAbove); |
1275 break; | 1274 break; |
1276 } | 1275 } |
1277 } | 1276 } |
1278 if (fStartOffset < 0.1f) { | 1277 if (fStartOffset < 0.1f) |
1279 fStartOffset = 0; | 1278 fStartOffset = 0; |
1280 } | |
1281 } | 1279 } |
1282 for (int32_t i = iBlockIndex - 1; iBlockIndex > 0 && i < iBlockIndex; i++) { | 1280 for (int32_t i = iBlockIndex - 1; iBlockIndex > 0 && i < iBlockIndex; i++) { |
1283 fStartOffset = pFieldArray->GetAt(i * 3) - pFieldArray->GetAt(i * 3 + 2); | 1281 fStartOffset = (*pFieldArray)[i * 3] - (*pFieldArray)[i * 3 + 2]; |
1284 if (fStartOffset < 0.1f) { | 1282 if (fStartOffset < 0.1f) |
1285 fStartOffset = 0; | 1283 fStartOffset = 0; |
1286 } | |
1287 } | 1284 } |
1288 if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { | 1285 if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { |
1289 pFieldArray->SetAt(0, fStartOffset); | 1286 (*pFieldArray)[0] = fStartOffset; |
1290 } else { | 1287 } else { |
1291 pFieldArray->Add(fStartOffset); | 1288 pFieldArray->push_back(fStartOffset); |
1292 } | 1289 } |
1293 XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode(); | 1290 XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode(); |
1294 bool bCanSplitNoContent = false; | 1291 bool bCanSplitNoContent = false; |
1295 XFA_ATTRIBUTEENUM eLayoutMode; | 1292 XFA_ATTRIBUTEENUM eLayoutMode; |
1296 GetNode() | 1293 GetNode() |
1297 ->GetNodeItem(XFA_NODEITEM_Parent) | 1294 ->GetNodeItem(XFA_NODEITEM_Parent) |
1298 ->TryEnum(XFA_ATTRIBUTE_Layout, eLayoutMode, true); | 1295 ->TryEnum(XFA_ATTRIBUTE_Layout, eLayoutMode, true); |
1299 if ((eLayoutMode == XFA_ATTRIBUTEENUM_Position || | 1296 if ((eLayoutMode == XFA_ATTRIBUTEENUM_Position || |
1300 eLayoutMode == XFA_ATTRIBUTEENUM_Tb || | 1297 eLayoutMode == XFA_ATTRIBUTEENUM_Tb || |
1301 eLayoutMode == XFA_ATTRIBUTEENUM_Row || | 1298 eLayoutMode == XFA_ATTRIBUTEENUM_Row || |
(...skipping 12 matching lines...) Expand all Loading... |
1314 return true; | 1311 return true; |
1315 } | 1312 } |
1316 } | 1313 } |
1317 if (bCanSplitNoContent) { | 1314 if (bCanSplitNoContent) { |
1318 if ((fCalcHeight - fTopInset - fSpaceAbove < fLineHeight)) { | 1315 if ((fCalcHeight - fTopInset - fSpaceAbove < fLineHeight)) { |
1319 fCalcHeight = 0; | 1316 fCalcHeight = 0; |
1320 return true; | 1317 return true; |
1321 } | 1318 } |
1322 if (fStartOffset + XFA_FLOAT_PERCISION >= fCalcHeight) { | 1319 if (fStartOffset + XFA_FLOAT_PERCISION >= fCalcHeight) { |
1323 if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { | 1320 if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { |
1324 pFieldArray->SetAt(iBlockIndex * 3 + 1, 0); | 1321 (*pFieldArray)[iBlockIndex * 3 + 1] = 0; |
1325 pFieldArray->SetAt(iBlockIndex * 3 + 2, fCalcHeight); | 1322 (*pFieldArray)[iBlockIndex * 3 + 2] = fCalcHeight; |
1326 } else { | 1323 } else { |
1327 pFieldArray->Add(0); | 1324 pFieldArray->push_back(0); |
1328 pFieldArray->Add(fCalcHeight); | 1325 pFieldArray->push_back(fCalcHeight); |
1329 } | 1326 } |
1330 return false; | 1327 return false; |
1331 } | 1328 } |
1332 if (fCalcHeight - fStartOffset < fLineHeight) { | 1329 if (fCalcHeight - fStartOffset < fLineHeight) { |
1333 fCalcHeight = fStartOffset; | 1330 fCalcHeight = fStartOffset; |
1334 if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { | 1331 if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { |
1335 pFieldArray->SetAt(iBlockIndex * 3 + 1, 0); | 1332 (*pFieldArray)[iBlockIndex * 3 + 1] = 0; |
1336 pFieldArray->SetAt(iBlockIndex * 3 + 2, fCalcHeight); | 1333 (*pFieldArray)[iBlockIndex * 3 + 2] = fCalcHeight; |
1337 } else { | 1334 } else { |
1338 pFieldArray->Add(0); | 1335 pFieldArray->push_back(0); |
1339 pFieldArray->Add(fCalcHeight); | 1336 pFieldArray->push_back(fCalcHeight); |
1340 } | 1337 } |
1341 return true; | 1338 return true; |
1342 } | 1339 } |
1343 FX_FLOAT fTextNum = | 1340 FX_FLOAT fTextNum = |
1344 fCalcHeight + XFA_FLOAT_PERCISION - fCapReserve - fStartOffset; | 1341 fCalcHeight + XFA_FLOAT_PERCISION - fCapReserve - fStartOffset; |
1345 int32_t iLineNum = | 1342 int32_t iLineNum = |
1346 (int32_t)((fTextNum + (fLineHeight - fFontSize)) / fLineHeight); | 1343 (int32_t)((fTextNum + (fLineHeight - fFontSize)) / fLineHeight); |
1347 if (iLineNum >= iLinesCount) { | 1344 if (iLineNum >= iLinesCount) { |
1348 if (fCalcHeight - fStartOffset - fTextHeight >= fFontSize) { | 1345 if (fCalcHeight - fStartOffset - fTextHeight >= fFontSize) { |
1349 if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { | 1346 if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { |
1350 pFieldArray->SetAt(iBlockIndex * 3 + 1, (FX_FLOAT)iLinesCount); | 1347 (*pFieldArray)[iBlockIndex * 3 + 1] = (FX_FLOAT)iLinesCount; |
1351 pFieldArray->SetAt(iBlockIndex * 3 + 2, fCalcHeight); | 1348 (*pFieldArray)[iBlockIndex * 3 + 2] = fCalcHeight; |
1352 } else { | 1349 } else { |
1353 pFieldArray->Add((FX_FLOAT)iLinesCount); | 1350 pFieldArray->push_back((FX_FLOAT)iLinesCount); |
1354 pFieldArray->Add(fCalcHeight); | 1351 pFieldArray->push_back(fCalcHeight); |
1355 } | 1352 } |
1356 return false; | 1353 return false; |
1357 } | 1354 } |
1358 if (fHeight - fStartOffset - fTextHeight < fFontSize) { | 1355 if (fHeight - fStartOffset - fTextHeight < fFontSize) { |
1359 iLineNum -= 1; | 1356 iLineNum -= 1; |
1360 if (iLineNum == 0) { | 1357 if (iLineNum == 0) { |
1361 fCalcHeight = 0; | 1358 fCalcHeight = 0; |
1362 return true; | 1359 return true; |
1363 } | 1360 } |
1364 } else { | 1361 } else { |
1365 iLineNum = (int32_t)(fTextNum / fLineHeight); | 1362 iLineNum = (int32_t)(fTextNum / fLineHeight); |
1366 } | 1363 } |
1367 } | 1364 } |
1368 if (iLineNum > 0) { | 1365 if (iLineNum > 0) { |
1369 FX_FLOAT fSplitHeight = | 1366 FX_FLOAT fSplitHeight = |
1370 iLineNum * fLineHeight + fCapReserve + fStartOffset; | 1367 iLineNum * fLineHeight + fCapReserve + fStartOffset; |
1371 if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { | 1368 if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { |
1372 pFieldArray->SetAt(iBlockIndex * 3 + 1, (FX_FLOAT)iLineNum); | 1369 (*pFieldArray)[iBlockIndex * 3 + 1] = (FX_FLOAT)iLineNum; |
1373 pFieldArray->SetAt(iBlockIndex * 3 + 2, fSplitHeight); | 1370 (*pFieldArray)[iBlockIndex * 3 + 2] = fSplitHeight; |
1374 } else { | 1371 } else { |
1375 pFieldArray->Add((FX_FLOAT)iLineNum); | 1372 pFieldArray->push_back((FX_FLOAT)iLineNum); |
1376 pFieldArray->Add(fSplitHeight); | 1373 pFieldArray->push_back(fSplitHeight); |
1377 } | 1374 } |
1378 if (fabs(fSplitHeight - fCalcHeight) < XFA_FLOAT_PERCISION) { | 1375 if (fabs(fSplitHeight - fCalcHeight) < XFA_FLOAT_PERCISION) { |
1379 return false; | 1376 return false; |
1380 } | 1377 } |
1381 fCalcHeight = fSplitHeight; | 1378 fCalcHeight = fSplitHeight; |
1382 return true; | 1379 return true; |
1383 } | 1380 } |
1384 } | 1381 } |
1385 fCalcHeight = 0; | 1382 fCalcHeight = 0; |
1386 return true; | 1383 return true; |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1685 if (pIDNode) { | 1682 if (pIDNode) { |
1686 pEmbAcc = static_cast<CXFA_WidgetAcc*>(pIDNode->GetWidgetData()); | 1683 pEmbAcc = static_cast<CXFA_WidgetAcc*>(pIDNode->GetWidgetData()); |
1687 } | 1684 } |
1688 if (pEmbAcc) { | 1685 if (pEmbAcc) { |
1689 pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display); | 1686 pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display); |
1690 return true; | 1687 return true; |
1691 } | 1688 } |
1692 } | 1689 } |
1693 return false; | 1690 return false; |
1694 } | 1691 } |
OLD | NEW |