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 | 11 |
11 #include "xfa/fde/tto/fde_textout.h" | 12 #include "xfa/fde/tto/fde_textout.h" |
12 #include "xfa/fde/xml/fde_xml_imp.h" | 13 #include "xfa/fde/xml/fde_xml_imp.h" |
13 #include "xfa/fxfa/app/xfa_ffcheckbutton.h" | 14 #include "xfa/fxfa/app/xfa_ffcheckbutton.h" |
14 #include "xfa/fxfa/app/xfa_ffchoicelist.h" | 15 #include "xfa/fxfa/app/xfa_ffchoicelist.h" |
15 #include "xfa/fxfa/app/xfa_fffield.h" | 16 #include "xfa/fxfa/app/xfa_fffield.h" |
16 #include "xfa/fxfa/app/xfa_fwladapter.h" | 17 #include "xfa/fxfa/app/xfa_fwladapter.h" |
17 #include "xfa/fxfa/app/xfa_textlayout.h" | 18 #include "xfa/fxfa/app/xfa_textlayout.h" |
18 #include "xfa/fxfa/include/xfa_ffapp.h" | 19 #include "xfa/fxfa/include/xfa_ffapp.h" |
19 #include "xfa/fxfa/include/xfa_ffdoc.h" | 20 #include "xfa/fxfa/include/xfa_ffdoc.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 pAcc->SetImageImage(XFA_LoadImageData(pFFDoc, &imageObj, m_bNamedImage, | 95 pAcc->SetImageImage(XFA_LoadImageData(pFFDoc, &imageObj, m_bNamedImage, |
95 m_iImageXDpi, m_iImageYDpi)); | 96 m_iImageXDpi, m_iImageYDpi)); |
96 return m_pDIBitmap != NULL; | 97 return m_pDIBitmap != NULL; |
97 } | 98 } |
98 | 99 |
99 CFX_DIBitmap* m_pDIBitmap; | 100 CFX_DIBitmap* m_pDIBitmap; |
100 FX_BOOL m_bNamedImage; | 101 FX_BOOL m_bNamedImage; |
101 int32_t m_iImageXDpi; | 102 int32_t m_iImageXDpi; |
102 int32_t m_iImageYDpi; | 103 int32_t m_iImageYDpi; |
103 }; | 104 }; |
| 105 |
104 class CXFA_FieldLayoutData : public CXFA_WidgetLayoutData { | 106 class CXFA_FieldLayoutData : public CXFA_WidgetLayoutData { |
105 public: | 107 public: |
106 CXFA_FieldLayoutData() | 108 CXFA_FieldLayoutData() {} |
107 : m_pCapTextLayout(NULL), | 109 ~CXFA_FieldLayoutData() {} |
108 m_pCapTextProvider(NULL), | 110 |
109 m_pTextOut(NULL), | 111 FX_BOOL LoadCaption(CXFA_WidgetAcc* pAcc) { |
110 m_pFieldSplitArray(NULL) {} | 112 if (m_pCapTextLayout) |
111 ~CXFA_FieldLayoutData() { | 113 return TRUE; |
112 if (m_pCapTextLayout) { | 114 CXFA_Caption caption = pAcc->GetCaption(); |
113 delete m_pCapTextLayout; | 115 if (!caption || caption.GetPresence() == XFA_ATTRIBUTEENUM_Hidden) |
114 } | 116 return FALSE; |
115 m_pCapTextLayout = NULL; | 117 m_pCapTextProvider.reset( |
116 if (m_pCapTextProvider) { | 118 new CXFA_TextProvider(pAcc, XFA_TEXTPROVIDERTYPE_Caption)); |
117 delete m_pCapTextProvider; | 119 m_pCapTextLayout.reset(new CXFA_TextLayout(m_pCapTextProvider.get())); |
118 } | 120 return TRUE; |
119 m_pCapTextProvider = NULL; | |
120 if (m_pTextOut) { | |
121 m_pTextOut->Release(); | |
122 } | |
123 m_pTextOut = NULL; | |
124 if (m_pFieldSplitArray) { | |
125 m_pFieldSplitArray->RemoveAll(); | |
126 delete m_pFieldSplitArray; | |
127 m_pFieldSplitArray = NULL; | |
128 } | |
129 } | 121 } |
130 FX_BOOL LoadCaption(CXFA_WidgetAcc* pAcc) { | 122 |
131 if (m_pCapTextLayout) { | 123 std::unique_ptr<CXFA_TextLayout> m_pCapTextLayout; |
132 return TRUE; | 124 std::unique_ptr<CXFA_TextProvider> m_pCapTextProvider; |
133 } | 125 std::unique_ptr<CFDE_TextOut> m_pTextOut; |
134 CXFA_Caption caption = pAcc->GetCaption(); | 126 std::unique_ptr<CFX_FloatArray> m_pFieldSplitArray; |
135 if (caption && caption.GetPresence() != XFA_ATTRIBUTEENUM_Hidden) { | |
136 m_pCapTextProvider = | |
137 new CXFA_TextProvider(pAcc, XFA_TEXTPROVIDERTYPE_Caption); | |
138 m_pCapTextLayout = new CXFA_TextLayout(m_pCapTextProvider); | |
139 return TRUE; | |
140 } | |
141 return FALSE; | |
142 } | |
143 CXFA_TextLayout* m_pCapTextLayout; | |
144 CXFA_TextProvider* m_pCapTextProvider; | |
145 CFDE_TextOut* m_pTextOut; | |
146 CFX_FloatArray* m_pFieldSplitArray; | |
147 }; | 127 }; |
| 128 |
148 class CXFA_TextEditData : public CXFA_FieldLayoutData { | 129 class CXFA_TextEditData : public CXFA_FieldLayoutData { |
149 public: | 130 public: |
150 }; | 131 }; |
151 class CXFA_ImageEditData : public CXFA_FieldLayoutData { | 132 class CXFA_ImageEditData : public CXFA_FieldLayoutData { |
152 public: | 133 public: |
153 CXFA_ImageEditData() | 134 CXFA_ImageEditData() |
154 : m_pDIBitmap(NULL), | 135 : m_pDIBitmap(NULL), |
155 m_bNamedImage(FALSE), | 136 m_bNamedImage(FALSE), |
156 m_iImageXDpi(0), | 137 m_iImageXDpi(0), |
157 m_iImageYDpi(0) {} | 138 m_iImageYDpi(0) {} |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 return; | 737 return; |
757 } | 738 } |
758 LoadCaption(); | 739 LoadCaption(); |
759 XFA_ELEMENT eUIType = (XFA_ELEMENT)GetUIType(); | 740 XFA_ELEMENT eUIType = (XFA_ELEMENT)GetUIType(); |
760 int32_t iCapPlacement = caption.GetPlacementType(); | 741 int32_t iCapPlacement = caption.GetPlacementType(); |
761 FX_FLOAT fCapReserve = caption.GetReserve(); | 742 FX_FLOAT fCapReserve = caption.GetReserve(); |
762 const bool bVert = iCapPlacement == XFA_ATTRIBUTEENUM_Top || | 743 const bool bVert = iCapPlacement == XFA_ATTRIBUTEENUM_Top || |
763 iCapPlacement == XFA_ATTRIBUTEENUM_Bottom; | 744 iCapPlacement == XFA_ATTRIBUTEENUM_Bottom; |
764 const bool bReserveExit = fCapReserve > 0.01; | 745 const bool bReserveExit = fCapReserve > 0.01; |
765 CXFA_TextLayout* pCapTextLayout = | 746 CXFA_TextLayout* pCapTextLayout = |
766 ((CXFA_FieldLayoutData*)m_pLayoutData)->m_pCapTextLayout; | 747 static_cast<CXFA_FieldLayoutData*>(m_pLayoutData)->m_pCapTextLayout.get(); |
767 if (pCapTextLayout) { | 748 if (pCapTextLayout) { |
768 if (!bVert && eUIType != XFA_ELEMENT_Button) { | 749 if (!bVert && eUIType != XFA_ELEMENT_Button) { |
769 szCap.x = fCapReserve; | 750 szCap.x = fCapReserve; |
770 } | 751 } |
771 CFX_SizeF minSize; | 752 CFX_SizeF minSize; |
772 pCapTextLayout->CalcSize(minSize, szCap, szCap); | 753 pCapTextLayout->CalcSize(minSize, szCap, szCap); |
773 if (bReserveExit) { | 754 if (bReserveExit) { |
774 bVert ? szCap.y = fCapReserve : szCap.x = fCapReserve; | 755 bVert ? szCap.y = fCapReserve : szCap.x = fCapReserve; |
775 } | 756 } |
776 } else { | 757 } else { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 } | 860 } |
880 FX_WCHAR wcEnter = '\n'; | 861 FX_WCHAR wcEnter = '\n'; |
881 FX_WCHAR wsLast = wsText.GetAt(wsText.GetLength() - 1); | 862 FX_WCHAR wsLast = wsText.GetAt(wsText.GetLength() - 1); |
882 if (wsLast == wcEnter) { | 863 if (wsLast == wcEnter) { |
883 wsText = wsText + wcEnter; | 864 wsText = wsText + wcEnter; |
884 } | 865 } |
885 | 866 |
886 CXFA_FieldLayoutData* layoutData = | 867 CXFA_FieldLayoutData* layoutData = |
887 static_cast<CXFA_FieldLayoutData*>(m_pLayoutData); | 868 static_cast<CXFA_FieldLayoutData*>(m_pLayoutData); |
888 if (!layoutData->m_pTextOut) { | 869 if (!layoutData->m_pTextOut) { |
889 layoutData->m_pTextOut = new CFDE_TextOut; | 870 layoutData->m_pTextOut.reset(new CFDE_TextOut); |
890 CFDE_TextOut* pTextOut = layoutData->m_pTextOut; | 871 CFDE_TextOut* pTextOut = layoutData->m_pTextOut.get(); |
891 pTextOut->SetFont(GetFDEFont()); | 872 pTextOut->SetFont(GetFDEFont()); |
892 pTextOut->SetFontSize(fFontSize); | 873 pTextOut->SetFontSize(fFontSize); |
893 pTextOut->SetLineBreakTolerance(fFontSize * 0.2f); | 874 pTextOut->SetLineBreakTolerance(fFontSize * 0.2f); |
894 pTextOut->SetLineSpace(GetLineHeight()); | 875 pTextOut->SetLineSpace(GetLineHeight()); |
895 uint32_t dwStyles = FDE_TTOSTYLE_LastLineHeight; | 876 uint32_t dwStyles = FDE_TTOSTYLE_LastLineHeight; |
896 if (GetUIType() == XFA_ELEMENT_TextEdit && IsMultiLine()) { | 877 if (GetUIType() == XFA_ELEMENT_TextEdit && IsMultiLine()) { |
897 dwStyles |= FDE_TTOSTYLE_LineWrap; | 878 dwStyles |= FDE_TTOSTYLE_LineWrap; |
898 } | 879 } |
899 pTextOut->SetStyles(dwStyles); | 880 pTextOut->SetStyles(dwStyles); |
900 } | 881 } |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 iLinesCount = 1; | 1238 iLinesCount = 1; |
1258 } else { | 1239 } else { |
1259 if (!((CXFA_FieldLayoutData*)m_pLayoutData)->m_pTextOut) { | 1240 if (!((CXFA_FieldLayoutData*)m_pLayoutData)->m_pTextOut) { |
1260 FX_FLOAT fWidth = 0; | 1241 FX_FLOAT fWidth = 0; |
1261 GetWidth(fWidth); | 1242 GetWidth(fWidth); |
1262 CalculateAccWidthAndHeight(eUIType, fWidth, fHeight); | 1243 CalculateAccWidthAndHeight(eUIType, fWidth, fHeight); |
1263 } | 1244 } |
1264 iLinesCount = | 1245 iLinesCount = |
1265 ((CXFA_FieldLayoutData*)m_pLayoutData)->m_pTextOut->GetTotalLines(); | 1246 ((CXFA_FieldLayoutData*)m_pLayoutData)->m_pTextOut->GetTotalLines(); |
1266 } | 1247 } |
1267 if (!((CXFA_FieldLayoutData*)m_pLayoutData)->m_pFieldSplitArray) { | 1248 if (!static_cast<CXFA_FieldLayoutData*>(m_pLayoutData)->m_pFieldSplitArray) { |
1268 ((CXFA_FieldLayoutData*)m_pLayoutData)->m_pFieldSplitArray = | 1249 static_cast<CXFA_FieldLayoutData*>(m_pLayoutData) |
1269 new CFX_FloatArray; | 1250 ->m_pFieldSplitArray.reset(new CFX_FloatArray); |
1270 } | 1251 } |
1271 CFX_FloatArray* pFieldArray = | 1252 CFX_FloatArray* pFieldArray = |
1272 ((CXFA_FieldLayoutData*)m_pLayoutData)->m_pFieldSplitArray; | 1253 static_cast<CXFA_FieldLayoutData*>(m_pLayoutData) |
| 1254 ->m_pFieldSplitArray.get(); |
1273 int32_t iFieldSplitCount = pFieldArray->GetSize(); | 1255 int32_t iFieldSplitCount = pFieldArray->GetSize(); |
1274 for (int32_t i = 0; i < iBlockIndex * 3; i += 3) { | 1256 for (int32_t i = 0; i < iBlockIndex * 3; i += 3) { |
1275 iLinesCount -= (int32_t)pFieldArray->GetAt(i + 1); | 1257 iLinesCount -= (int32_t)pFieldArray->GetAt(i + 1); |
1276 fHeight -= pFieldArray->GetAt(i + 2); | 1258 fHeight -= pFieldArray->GetAt(i + 2); |
1277 } | 1259 } |
1278 if (iLinesCount == 0) { | 1260 if (iLinesCount == 0) { |
1279 return FALSE; | 1261 return FALSE; |
1280 } | 1262 } |
1281 FX_FLOAT fLineHeight = GetLineHeight(); | 1263 FX_FLOAT fLineHeight = GetLineHeight(); |
1282 FX_FLOAT fFontSize = GetFontSize(); | 1264 FX_FLOAT fFontSize = GetFontSize(); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 fTextHeight = GetHeightWithoutMargin(fTextHeight); | 1461 fTextHeight = GetHeightWithoutMargin(fTextHeight); |
1480 pTextLayout->DoLayout(0, fTextHeight, -1, fTextHeight); | 1462 pTextLayout->DoLayout(0, fTextHeight, -1, fTextHeight); |
1481 fCalcHeight = m_pLayoutData->m_fWidgetHeight; | 1463 fCalcHeight = m_pLayoutData->m_fWidgetHeight; |
1482 } | 1464 } |
1483 FX_BOOL CXFA_WidgetAcc::LoadCaption() { | 1465 FX_BOOL CXFA_WidgetAcc::LoadCaption() { |
1484 InitLayoutData(); | 1466 InitLayoutData(); |
1485 return ((CXFA_FieldLayoutData*)m_pLayoutData)->LoadCaption(this); | 1467 return ((CXFA_FieldLayoutData*)m_pLayoutData)->LoadCaption(this); |
1486 } | 1468 } |
1487 CXFA_TextLayout* CXFA_WidgetAcc::GetCaptionTextLayout() { | 1469 CXFA_TextLayout* CXFA_WidgetAcc::GetCaptionTextLayout() { |
1488 return m_pLayoutData | 1470 return m_pLayoutData |
1489 ? ((CXFA_FieldLayoutData*)m_pLayoutData)->m_pCapTextLayout | 1471 ? static_cast<CXFA_FieldLayoutData*>(m_pLayoutData) |
1490 : NULL; | 1472 ->m_pCapTextLayout.get() |
| 1473 : nullptr; |
1491 } | 1474 } |
1492 CXFA_TextLayout* CXFA_WidgetAcc::GetTextLayout() { | 1475 CXFA_TextLayout* CXFA_WidgetAcc::GetTextLayout() { |
1493 return m_pLayoutData ? ((CXFA_TextLayoutData*)m_pLayoutData)->m_pTextLayout | 1476 return m_pLayoutData ? ((CXFA_TextLayoutData*)m_pLayoutData)->m_pTextLayout |
1494 : NULL; | 1477 : NULL; |
1495 } | 1478 } |
1496 CFX_DIBitmap* CXFA_WidgetAcc::GetImageImage() { | 1479 CFX_DIBitmap* CXFA_WidgetAcc::GetImageImage() { |
1497 return m_pLayoutData ? ((CXFA_ImageLayoutData*)m_pLayoutData)->m_pDIBitmap | 1480 return m_pLayoutData ? ((CXFA_ImageLayoutData*)m_pLayoutData)->m_pDIBitmap |
1498 : NULL; | 1481 : NULL; |
1499 } | 1482 } |
1500 CFX_DIBitmap* CXFA_WidgetAcc::GetImageEditImage() { | 1483 CFX_DIBitmap* CXFA_WidgetAcc::GetImageEditImage() { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1699 if (pIDNode) { | 1682 if (pIDNode) { |
1700 pEmbAcc = (CXFA_WidgetAcc*)pIDNode->GetWidgetData(); | 1683 pEmbAcc = (CXFA_WidgetAcc*)pIDNode->GetWidgetData(); |
1701 } | 1684 } |
1702 if (pEmbAcc) { | 1685 if (pEmbAcc) { |
1703 pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display); | 1686 pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display); |
1704 return TRUE; | 1687 return TRUE; |
1705 } | 1688 } |
1706 } | 1689 } |
1707 return FALSE; | 1690 return FALSE; |
1708 } | 1691 } |
OLD | NEW |