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/fgas/layout/fgas_rtfbreak.h" | 7 #include "xfa/fgas/layout/fgas_rtfbreak.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 m_dwLayoutStyles = dwLayoutStyles; | 86 m_dwLayoutStyles = dwLayoutStyles; |
87 m_bPagination = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_Pagination) != 0; | 87 m_bPagination = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_Pagination) != 0; |
88 m_bVertical = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_VerticalChars) != 0; | 88 m_bVertical = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_VerticalChars) != 0; |
89 m_bSingleLine = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_SingleLine) != 0; | 89 m_bSingleLine = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_SingleLine) != 0; |
90 m_bCharCode = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_MBCSCode) != 0; | 90 m_bCharCode = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_MBCSCode) != 0; |
91 m_iLineRotation = GetLineRotation(m_dwLayoutStyles); | 91 m_iLineRotation = GetLineRotation(m_dwLayoutStyles); |
92 m_iRotation = m_iLineRotation + m_iCharRotation; | 92 m_iRotation = m_iLineRotation + m_iCharRotation; |
93 m_iRotation %= 4; | 93 m_iRotation %= 4; |
94 } | 94 } |
95 | 95 |
96 void CFX_RTFBreak::SetFont(CFGAS_GEFont* pFont) { | 96 void CFX_RTFBreak::SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont) { |
97 if (!pFont) { | 97 if (!pFont || pFont == m_pFont) |
98 return; | 98 return; |
99 } | 99 |
100 if (m_pFont == pFont) { | |
101 return; | |
102 } | |
103 SetBreakStatus(); | 100 SetBreakStatus(); |
104 m_pFont = pFont; | 101 m_pFont = pFont; |
105 m_iDefChar = 0; | 102 m_iDefChar = 0; |
106 if (m_pFont) { | 103 if (m_pFont) { |
107 m_iFontHeight = m_iFontSize; | 104 m_iFontHeight = m_iFontSize; |
108 if (m_wDefChar != 0xFEFF) { | 105 if (m_wDefChar != 0xFEFF) { |
109 m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false); | 106 m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false); |
110 m_iDefChar *= m_iFontSize; | 107 m_iDefChar *= m_iFontSize; |
111 } | 108 } |
112 } | 109 } |
113 } | 110 } |
| 111 |
114 void CFX_RTFBreak::SetFontSize(FX_FLOAT fFontSize) { | 112 void CFX_RTFBreak::SetFontSize(FX_FLOAT fFontSize) { |
115 int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); | 113 int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); |
116 if (m_iFontSize == iFontSize) { | 114 if (m_iFontSize == iFontSize) { |
117 return; | 115 return; |
118 } | 116 } |
119 SetBreakStatus(); | 117 SetBreakStatus(); |
120 m_iFontSize = iFontSize; | 118 m_iFontSize = iFontSize; |
121 m_iDefChar = 0; | 119 m_iDefChar = 0; |
122 if (m_pFont) { | 120 if (m_pFont) { |
123 m_iFontHeight = m_iFontSize; | 121 m_iFontHeight = m_iFontSize; |
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 bool bCharCode, | 1175 bool bCharCode, |
1178 CFX_WideString* pWSForms, | 1176 CFX_WideString* pWSForms, |
1179 FX_AdjustCharDisplayPos pAdjustPos) const { | 1177 FX_AdjustCharDisplayPos pAdjustPos) const { |
1180 if (!pText || pText->iLength < 1) { | 1178 if (!pText || pText->iLength < 1) { |
1181 return 0; | 1179 return 0; |
1182 } | 1180 } |
1183 ASSERT(pText->pStr && pText->pWidths && pText->pFont && pText->pRect); | 1181 ASSERT(pText->pStr && pText->pWidths && pText->pFont && pText->pRect); |
1184 const FX_WCHAR* pStr = pText->pStr; | 1182 const FX_WCHAR* pStr = pText->pStr; |
1185 int32_t* pWidths = pText->pWidths; | 1183 int32_t* pWidths = pText->pWidths; |
1186 int32_t iLength = pText->iLength - 1; | 1184 int32_t iLength = pText->iLength - 1; |
1187 CFGAS_GEFont* pFont = pText->pFont; | 1185 CFX_RetainPtr<CFGAS_GEFont> pFont = pText->pFont; |
1188 uint32_t dwStyles = pText->dwLayoutStyles; | 1186 uint32_t dwStyles = pText->dwLayoutStyles; |
1189 CFX_RectF rtText(*pText->pRect); | 1187 CFX_RectF rtText(*pText->pRect); |
1190 bool bRTLPiece = FX_IsOdd(pText->iBidiLevel); | 1188 bool bRTLPiece = FX_IsOdd(pText->iBidiLevel); |
1191 FX_FLOAT fFontSize = pText->fFontSize; | 1189 FX_FLOAT fFontSize = pText->fFontSize; |
1192 int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); | 1190 int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); |
1193 int32_t iAscent = pFont->GetAscent(); | 1191 int32_t iAscent = pFont->GetAscent(); |
1194 int32_t iDescent = pFont->GetDescent(); | 1192 int32_t iDescent = pFont->GetDescent(); |
1195 int32_t iMaxHeight = iAscent - iDescent; | 1193 int32_t iMaxHeight = iAscent - iDescent; |
1196 FX_FLOAT fFontHeight = fFontSize; | 1194 FX_FLOAT fFontHeight = fFontSize; |
1197 FX_FLOAT fAscent = fFontHeight * (FX_FLOAT)iAscent / (FX_FLOAT)iMaxHeight; | 1195 FX_FLOAT fAscent = fFontHeight * (FX_FLOAT)iAscent / (FX_FLOAT)iMaxHeight; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 } | 1410 } |
1413 if (iWidth > 0) { | 1411 if (iWidth > 0) { |
1414 wPrev = wch; | 1412 wPrev = wch; |
1415 } | 1413 } |
1416 } | 1414 } |
1417 return iCount; | 1415 return iCount; |
1418 } | 1416 } |
1419 int32_t CFX_RTFBreak::GetCharRects(const FX_RTFTEXTOBJ* pText, | 1417 int32_t CFX_RTFBreak::GetCharRects(const FX_RTFTEXTOBJ* pText, |
1420 CFX_RectFArray& rtArray, | 1418 CFX_RectFArray& rtArray, |
1421 bool bCharBBox) const { | 1419 bool bCharBBox) const { |
1422 if (!pText || pText->iLength < 1) { | 1420 if (!pText || pText->iLength < 1) |
1423 return 0; | 1421 return 0; |
1424 } | 1422 |
1425 ASSERT(pText->pStr && pText->pWidths && pText->pFont && pText->pRect); | 1423 ASSERT(pText->pStr && pText->pWidths && pText->pFont && pText->pRect); |
1426 const FX_WCHAR* pStr = pText->pStr; | 1424 const FX_WCHAR* pStr = pText->pStr; |
1427 int32_t* pWidths = pText->pWidths; | 1425 int32_t* pWidths = pText->pWidths; |
1428 int32_t iLength = pText->iLength; | 1426 int32_t iLength = pText->iLength; |
1429 CFX_RectF rect(*pText->pRect); | 1427 CFX_RectF rect(*pText->pRect); |
1430 bool bRTLPiece = FX_IsOdd(pText->iBidiLevel); | 1428 bool bRTLPiece = FX_IsOdd(pText->iBidiLevel); |
1431 FX_FLOAT fFontSize = pText->fFontSize; | 1429 FX_FLOAT fFontSize = pText->fFontSize; |
1432 int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); | 1430 int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); |
1433 FX_FLOAT fScale = fFontSize / 1000.0f; | 1431 FX_FLOAT fScale = fFontSize / 1000.0f; |
1434 CFGAS_GEFont* pFont = pText->pFont; | 1432 CFX_RetainPtr<CFGAS_GEFont> pFont = pText->pFont; |
1435 if (!pFont) { | 1433 if (!pFont) |
1436 bCharBBox = false; | 1434 bCharBBox = false; |
1437 } | 1435 |
1438 CFX_Rect bbox; | 1436 CFX_Rect bbox; |
1439 bbox.Set(0, 0, 0, 0); | 1437 bbox.Set(0, 0, 0, 0); |
1440 if (bCharBBox) { | 1438 if (bCharBBox) |
1441 bCharBBox = pFont->GetBBox(bbox); | 1439 bCharBBox = pFont->GetBBox(bbox); |
1442 } | 1440 |
1443 FX_FLOAT fLeft = std::max(0.0f, bbox.left * fScale); | 1441 FX_FLOAT fLeft = std::max(0.0f, bbox.left * fScale); |
1444 FX_FLOAT fHeight = FXSYS_fabs(bbox.height * fScale); | 1442 FX_FLOAT fHeight = FXSYS_fabs(bbox.height * fScale); |
1445 rtArray.RemoveAll(); | 1443 rtArray.RemoveAll(); |
1446 rtArray.SetSize(iLength); | 1444 rtArray.SetSize(iLength); |
1447 uint32_t dwStyles = pText->dwLayoutStyles; | 1445 uint32_t dwStyles = pText->dwLayoutStyles; |
1448 bool bVertical = (dwStyles & FX_RTFLAYOUTSTYLE_VerticalLayout) != 0; | 1446 bool bVertical = (dwStyles & FX_RTFLAYOUTSTYLE_VerticalLayout) != 0; |
1449 bool bSingleLine = (dwStyles & FX_RTFLAYOUTSTYLE_SingleLine) != 0; | 1447 bool bSingleLine = (dwStyles & FX_RTFLAYOUTSTYLE_SingleLine) != 0; |
1450 bool bCombText = (dwStyles & FX_TXTLAYOUTSTYLE_CombText) != 0; | 1448 bool bCombText = (dwStyles & FX_TXTLAYOUTSTYLE_CombText) != 0; |
1451 FX_WCHAR wch, wLineBreakChar = pText->wLineBreakChar; | 1449 FX_WCHAR wch, wLineBreakChar = pText->wLineBreakChar; |
1452 int32_t iCharSize; | 1450 int32_t iCharSize; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1559 iLength(0), | 1557 iLength(0), |
1560 pFont(nullptr), | 1558 pFont(nullptr), |
1561 fFontSize(12.0f), | 1559 fFontSize(12.0f), |
1562 dwLayoutStyles(0), | 1560 dwLayoutStyles(0), |
1563 iCharRotation(0), | 1561 iCharRotation(0), |
1564 iBidiLevel(0), | 1562 iBidiLevel(0), |
1565 pRect(nullptr), | 1563 pRect(nullptr), |
1566 wLineBreakChar(L'\n'), | 1564 wLineBreakChar(L'\n'), |
1567 iHorizontalScale(100), | 1565 iHorizontalScale(100), |
1568 iVerticalScale(100) {} | 1566 iVerticalScale(100) {} |
| 1567 |
| 1568 FX_RTFTEXTOBJ::~FX_RTFTEXTOBJ() {} |
OLD | NEW |