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 <algorithm> |
| 8 |
7 #include "xfa/src/fgas/include/fx_lbk.h" | 9 #include "xfa/src/fgas/include/fx_lbk.h" |
8 #include "xfa/src/fgas/src/fgas_base.h" | 10 #include "xfa/src/fgas/src/fgas_base.h" |
9 #include "xfa/src/fgas/src/layout/fx_unicode.h" | 11 #include "xfa/src/fgas/src/layout/fx_unicode.h" |
10 #include "xfa/src/fgas/src/layout/fx_rtfbreak.h" | 12 #include "xfa/src/fgas/src/layout/fx_rtfbreak.h" |
11 | 13 |
12 IFX_RTFBreak* IFX_RTFBreak::Create(FX_DWORD dwPolicies) { | 14 IFX_RTFBreak* IFX_RTFBreak::Create(FX_DWORD dwPolicies) { |
13 return new CFX_RTFBreak(dwPolicies); | 15 return new CFX_RTFBreak(dwPolicies); |
14 } | 16 } |
15 CFX_RTFBreak::CFX_RTFBreak(FX_DWORD dwPolicies) | 17 CFX_RTFBreak::CFX_RTFBreak(FX_DWORD dwPolicies) |
16 : m_dwPolicies(dwPolicies), | 18 : m_dwPolicies(dwPolicies), |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 384 } |
383 } | 385 } |
384 int32_t iRotation = m_iRotation; | 386 int32_t iRotation = m_iRotation; |
385 if (m_bVertical && (dwProps & 0x8000) != 0) { | 387 if (m_bVertical && (dwProps & 0x8000) != 0) { |
386 iRotation = (iRotation + 1) % 4; | 388 iRotation = (iRotation + 1) % 4; |
387 } | 389 } |
388 FX_DWORD dwRet2 = | 390 FX_DWORD dwRet2 = |
389 (this->*g_FX_RTFBreak_lpfAppendChar[dwType >> FX_CHARTYPEBITS])( | 391 (this->*g_FX_RTFBreak_lpfAppendChar[dwType >> FX_CHARTYPEBITS])( |
390 pCurChar, iRotation); | 392 pCurChar, iRotation); |
391 m_dwCharType = dwType; | 393 m_dwCharType = dwType; |
392 return FX_MAX(dwRet1, dwRet2); | 394 return std::max(dwRet1, dwRet2); |
393 } | 395 } |
394 FX_DWORD CFX_RTFBreak::AppendChar_CharCode(FX_WCHAR wch) { | 396 FX_DWORD CFX_RTFBreak::AppendChar_CharCode(FX_WCHAR wch) { |
395 FXSYS_assert(m_pFont != NULL && m_pCurLine != NULL); | 397 FXSYS_assert(m_pFont != NULL && m_pCurLine != NULL); |
396 FXSYS_assert(m_bCharCode); | 398 FXSYS_assert(m_bCharCode); |
397 m_pCurLine->m_iMBCSChars++; | 399 m_pCurLine->m_iMBCSChars++; |
398 CFX_RTFCharArray& tca = m_pCurLine->m_LineChars; | 400 CFX_RTFCharArray& tca = m_pCurLine->m_LineChars; |
399 CFX_RTFChar* pCurChar = tca.AddSpace(); | 401 CFX_RTFChar* pCurChar = tca.AddSpace(); |
400 pCurChar->m_dwStatus = 0; | 402 pCurChar->m_dwStatus = 0; |
401 pCurChar->m_wCharCode = wch; | 403 pCurChar->m_wCharCode = wch; |
402 pCurChar->m_dwCharProps = 0; | 404 pCurChar->m_dwCharProps = 0; |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 if (iCount < 1) { | 1146 if (iCount < 1) { |
1145 rect.width = 0; | 1147 rect.width = 0; |
1146 return; | 1148 return; |
1147 } | 1149 } |
1148 CFX_RTFPiece* pBreakPiece; | 1150 CFX_RTFPiece* pBreakPiece; |
1149 int32_t iLineHeight = 0, iMax; | 1151 int32_t iLineHeight = 0, iMax; |
1150 for (int32_t i = 0; i < iCount; i++) { | 1152 for (int32_t i = 0; i < iCount; i++) { |
1151 pBreakPiece = rtfPieces.GetPtrAt(i); | 1153 pBreakPiece = rtfPieces.GetPtrAt(i); |
1152 int32_t iFontHeight = FXSYS_round(pBreakPiece->m_iFontHeight * | 1154 int32_t iFontHeight = FXSYS_round(pBreakPiece->m_iFontHeight * |
1153 pBreakPiece->m_iVerticalScale / 100.0f); | 1155 pBreakPiece->m_iVerticalScale / 100.0f); |
1154 iMax = FX_MAX(pBreakPiece->m_iFontSize, iFontHeight); | 1156 iMax = std::max(pBreakPiece->m_iFontSize, iFontHeight); |
1155 if (i == 0) { | 1157 if (i == 0) { |
1156 iLineHeight = iMax; | 1158 iLineHeight = iMax; |
1157 } else if (iLineHeight < iMax) { | 1159 } else if (iLineHeight < iMax) { |
1158 iLineHeight = iMax; | 1160 iLineHeight = iMax; |
1159 } | 1161 } |
1160 } | 1162 } |
1161 rect.height = ((FX_FLOAT)iLineHeight) / 20.0f; | 1163 rect.height = ((FX_FLOAT)iLineHeight) / 20.0f; |
1162 } | 1164 } |
1163 void CFX_RTFBreak::ClearBreakPieces() { | 1165 void CFX_RTFBreak::ClearBreakPieces() { |
1164 CFX_RTFLine* pRTFLine = GetRTFLine(TRUE); | 1166 CFX_RTFLine* pRTFLine = GetRTFLine(TRUE); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 FX_FLOAT fScale = fFontSize / 1000.0f; | 1436 FX_FLOAT fScale = fFontSize / 1000.0f; |
1435 IFX_Font* pFont = pText->pFont; | 1437 IFX_Font* pFont = pText->pFont; |
1436 if (pFont == NULL) { | 1438 if (pFont == NULL) { |
1437 bCharBBox = FALSE; | 1439 bCharBBox = FALSE; |
1438 } | 1440 } |
1439 CFX_Rect bbox; | 1441 CFX_Rect bbox; |
1440 bbox.Set(0, 0, 0, 0); | 1442 bbox.Set(0, 0, 0, 0); |
1441 if (bCharBBox) { | 1443 if (bCharBBox) { |
1442 bCharBBox = pFont->GetBBox(bbox); | 1444 bCharBBox = pFont->GetBBox(bbox); |
1443 } | 1445 } |
1444 FX_FLOAT fLeft = FX_MAX(0, bbox.left * fScale); | 1446 FX_FLOAT fLeft = std::max(0.0f, bbox.left * fScale); |
1445 FX_FLOAT fHeight = FXSYS_fabs(bbox.height * fScale); | 1447 FX_FLOAT fHeight = FXSYS_fabs(bbox.height * fScale); |
1446 rtArray.RemoveAll(); | 1448 rtArray.RemoveAll(); |
1447 rtArray.SetSize(iLength); | 1449 rtArray.SetSize(iLength); |
1448 FX_DWORD dwStyles = pText->dwLayoutStyles; | 1450 FX_DWORD dwStyles = pText->dwLayoutStyles; |
1449 FX_BOOL bVertical = (dwStyles & FX_RTFLAYOUTSTYLE_VerticalLayout) != 0; | 1451 FX_BOOL bVertical = (dwStyles & FX_RTFLAYOUTSTYLE_VerticalLayout) != 0; |
1450 FX_BOOL bSingleLine = (dwStyles & FX_RTFLAYOUTSTYLE_SingleLine) != 0; | 1452 FX_BOOL bSingleLine = (dwStyles & FX_RTFLAYOUTSTYLE_SingleLine) != 0; |
1451 FX_BOOL bCombText = (dwStyles & FX_TXTLAYOUTSTYLE_CombText) != 0; | 1453 FX_BOOL bCombText = (dwStyles & FX_TXTLAYOUTSTYLE_CombText) != 0; |
1452 FX_WCHAR wch, wLineBreakChar = pText->wLineBreakChar; | 1454 FX_WCHAR wch, wLineBreakChar = pText->wLineBreakChar; |
1453 int32_t iCharSize; | 1455 int32_t iCharSize; |
1454 FX_FLOAT fCharSize, fStart; | 1456 FX_FLOAT fCharSize, fStart; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 if (bCombText) { | 1501 if (bCombText) { |
1500 fRTLeft = (rect.width - fCharWidth) / 2.0f; | 1502 fRTLeft = (rect.width - fCharWidth) / 2.0f; |
1501 } | 1503 } |
1502 } | 1504 } |
1503 CFX_RectF rtBBoxF; | 1505 CFX_RectF rtBBoxF; |
1504 if (bVertical) { | 1506 if (bVertical) { |
1505 rtBBoxF.top = rect.left + fRTLeft; | 1507 rtBBoxF.top = rect.left + fRTLeft; |
1506 rtBBoxF.left = rect.top + (rect.height - fHeight) / 2.0f; | 1508 rtBBoxF.left = rect.top + (rect.height - fHeight) / 2.0f; |
1507 rtBBoxF.height = fCharWidth; | 1509 rtBBoxF.height = fCharWidth; |
1508 rtBBoxF.width = fHeight; | 1510 rtBBoxF.width = fHeight; |
1509 rtBBoxF.left = FX_MAX(rtBBoxF.left, 0); | 1511 rtBBoxF.left = std::max(rtBBoxF.left, 0.0f); |
1510 } else { | 1512 } else { |
1511 rtBBoxF.left = rect.left + fRTLeft; | 1513 rtBBoxF.left = rect.left + fRTLeft; |
1512 rtBBoxF.top = rect.top + (rect.height - fHeight) / 2.0f; | 1514 rtBBoxF.top = rect.top + (rect.height - fHeight) / 2.0f; |
1513 rtBBoxF.width = fCharWidth; | 1515 rtBBoxF.width = fCharWidth; |
1514 rtBBoxF.height = fHeight; | 1516 rtBBoxF.height = fHeight; |
1515 rtBBoxF.top = FX_MAX(rtBBoxF.top, 0); | 1517 rtBBoxF.top = std::max(rtBBoxF.top, 0.0f); |
1516 } | 1518 } |
1517 rtArray.SetAt(i, rtBBoxF); | 1519 rtArray.SetAt(i, rtBBoxF); |
1518 continue; | 1520 continue; |
1519 } | 1521 } |
1520 rtArray.SetAt(i, rect); | 1522 rtArray.SetAt(i, rect); |
1521 } | 1523 } |
1522 return iLength; | 1524 return iLength; |
1523 } | 1525 } |
OLD | NEW |