| 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 |
| 11 #include "core/fxcrt/include/fx_arabic.h" | 11 #include "core/fxcrt/include/fx_arabic.h" |
| 12 #include "core/fxcrt/include/fx_arb.h" | 12 #include "core/fxcrt/include/fx_arb.h" |
| 13 #include "xfa/fgas/layout/fgas_linebreak.h" | 13 #include "xfa/fgas/layout/fgas_linebreak.h" |
| 14 #include "xfa/fgas/layout/fgas_unicode.h" | 14 #include "xfa/fgas/layout/fgas_unicode.h" |
| 15 | 15 |
| 16 CFX_RTFBreak::CFX_RTFBreak(uint32_t dwPolicies) | 16 CFX_RTFBreak::CFX_RTFBreak(uint32_t dwPolicies) |
| 17 : m_dwPolicies(dwPolicies), | 17 : m_dwPolicies(dwPolicies), |
| 18 m_pArabicChar(NULL), | |
| 19 m_iBoundaryStart(0), | 18 m_iBoundaryStart(0), |
| 20 m_iBoundaryEnd(2000000), | 19 m_iBoundaryEnd(2000000), |
| 21 m_dwLayoutStyles(0), | 20 m_dwLayoutStyles(0), |
| 22 m_bPagination(FALSE), | 21 m_bPagination(FALSE), |
| 23 m_bVertical(FALSE), | 22 m_bVertical(FALSE), |
| 24 m_bSingleLine(FALSE), | 23 m_bSingleLine(FALSE), |
| 25 m_bCharCode(FALSE), | 24 m_bCharCode(FALSE), |
| 26 m_pFont(NULL), | 25 m_pFont(NULL), |
| 27 m_iFontHeight(240), | 26 m_iFontHeight(240), |
| 28 m_iFontSize(240), | 27 m_iFontSize(240), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 43 m_bRTL(FALSE), | 42 m_bRTL(FALSE), |
| 44 m_iAlignment(FX_RTFLINEALIGNMENT_Left), | 43 m_iAlignment(FX_RTFLINEALIGNMENT_Left), |
| 45 m_pUserData(NULL), | 44 m_pUserData(NULL), |
| 46 m_dwCharType(0), | 45 m_dwCharType(0), |
| 47 m_dwIdentity(0), | 46 m_dwIdentity(0), |
| 48 m_RTFLine1(), | 47 m_RTFLine1(), |
| 49 m_RTFLine2(), | 48 m_RTFLine2(), |
| 50 m_pCurLine(NULL), | 49 m_pCurLine(NULL), |
| 51 m_iReady(0), | 50 m_iReady(0), |
| 52 m_iTolerance(0) { | 51 m_iTolerance(0) { |
| 53 m_pArabicChar = new CFX_ArabicChar; | |
| 54 m_pCurLine = &m_RTFLine1; | 52 m_pCurLine = &m_RTFLine1; |
| 55 } | 53 } |
| 56 CFX_RTFBreak::~CFX_RTFBreak() { | 54 CFX_RTFBreak::~CFX_RTFBreak() { |
| 57 Reset(); | 55 Reset(); |
| 58 m_PositionedTabs.RemoveAll(); | 56 m_PositionedTabs.RemoveAll(); |
| 59 m_pArabicChar->Release(); | |
| 60 if (m_pUserData != NULL) { | 57 if (m_pUserData != NULL) { |
| 61 m_pUserData->Release(); | 58 m_pUserData->Release(); |
| 62 } | 59 } |
| 63 } | 60 } |
| 64 void CFX_RTFBreak::SetLineBoundary(FX_FLOAT fLineStart, FX_FLOAT fLineEnd) { | 61 void CFX_RTFBreak::SetLineBoundary(FX_FLOAT fLineStart, FX_FLOAT fLineEnd) { |
| 65 if (fLineStart > fLineEnd) | 62 if (fLineStart > fLineEnd) |
| 66 return; | 63 return; |
| 67 m_iBoundaryStart = FXSYS_round(fLineStart * 20000.0f); | 64 m_iBoundaryStart = FXSYS_round(fLineStart * 20000.0f); |
| 68 m_iBoundaryEnd = FXSYS_round(fLineEnd * 20000.0f); | 65 m_iBoundaryEnd = FXSYS_round(fLineEnd * 20000.0f); |
| 69 m_pCurLine->m_iStart = std::min(m_pCurLine->m_iStart, m_iBoundaryEnd); | 66 m_pCurLine->m_iStart = std::min(m_pCurLine->m_iStart, m_iBoundaryEnd); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Tab, | 333 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Tab, |
| 337 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Control, | 334 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Control, |
| 338 &CFX_RTFBreak::AppendChar_Combination, &CFX_RTFBreak::AppendChar_Others, | 335 &CFX_RTFBreak::AppendChar_Combination, &CFX_RTFBreak::AppendChar_Others, |
| 339 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Arabic, | 336 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Arabic, |
| 340 &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Arabic, | 337 &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Arabic, |
| 341 &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Arabic, | 338 &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Arabic, |
| 342 &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Others, | 339 &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Others, |
| 343 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Others, | 340 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Others, |
| 344 }; | 341 }; |
| 345 uint32_t CFX_RTFBreak::AppendChar(FX_WCHAR wch) { | 342 uint32_t CFX_RTFBreak::AppendChar(FX_WCHAR wch) { |
| 346 ASSERT(m_pFont != NULL && m_pCurLine != NULL && m_pArabicChar != NULL); | 343 ASSERT(m_pFont && m_pCurLine); |
| 347 if (m_bCharCode) { | 344 if (m_bCharCode) { |
| 348 return AppendChar_CharCode(wch); | 345 return AppendChar_CharCode(wch); |
| 349 } | 346 } |
| 350 uint32_t dwProps = kTextLayoutCodeProperties[(uint16_t)wch]; | 347 uint32_t dwProps = kTextLayoutCodeProperties[(uint16_t)wch]; |
| 351 uint32_t dwType = (dwProps & FX_CHARTYPEBITSMASK); | 348 uint32_t dwType = (dwProps & FX_CHARTYPEBITSMASK); |
| 352 CFX_RTFCharArray& tca = m_pCurLine->m_LineChars; | 349 CFX_RTFCharArray& tca = m_pCurLine->m_LineChars; |
| 353 CFX_RTFChar* pCurChar = tca.AddSpace(); | 350 CFX_RTFChar* pCurChar = tca.AddSpace(); |
| 354 pCurChar->m_dwStatus = 0; | 351 pCurChar->m_dwStatus = 0; |
| 355 pCurChar->m_wCharCode = wch; | 352 pCurChar->m_wCharCode = wch; |
| 356 pCurChar->m_dwCharProps = dwProps; | 353 pCurChar->m_dwCharProps = dwProps; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 int32_t& iLineWidth = m_pCurLine->m_iWidth; | 510 int32_t& iLineWidth = m_pCurLine->m_iWidth; |
| 514 int32_t iCharWidth = 0; | 511 int32_t iCharWidth = 0; |
| 515 FX_WCHAR wForm; | 512 FX_WCHAR wForm; |
| 516 FX_BOOL bAlef = FALSE; | 513 FX_BOOL bAlef = FALSE; |
| 517 if (m_dwCharType >= FX_CHARTYPE_ArabicAlef && | 514 if (m_dwCharType >= FX_CHARTYPE_ArabicAlef && |
| 518 m_dwCharType <= FX_CHARTYPE_ArabicDistortion) { | 515 m_dwCharType <= FX_CHARTYPE_ArabicDistortion) { |
| 519 pLastChar = GetLastChar(1); | 516 pLastChar = GetLastChar(1); |
| 520 if (pLastChar != NULL) { | 517 if (pLastChar != NULL) { |
| 521 iLineWidth -= pLastChar->m_iCharWidth; | 518 iLineWidth -= pLastChar->m_iCharWidth; |
| 522 CFX_RTFChar* pPrevChar = GetLastChar(2); | 519 CFX_RTFChar* pPrevChar = GetLastChar(2); |
| 523 wForm = m_pArabicChar->GetFormChar(pLastChar, pPrevChar, pCurChar); | 520 wForm = pdfium::arabic::GetFormChar(pLastChar, pPrevChar, pCurChar); |
| 524 bAlef = (wForm == 0xFEFF && | 521 bAlef = (wForm == 0xFEFF && |
| 525 pLastChar->GetCharType() == FX_CHARTYPE_ArabicAlef); | 522 pLastChar->GetCharType() == FX_CHARTYPE_ArabicAlef); |
| 526 int32_t iLastRotation = pLastChar->m_nRotation + m_iLineRotation; | 523 int32_t iLastRotation = pLastChar->m_nRotation + m_iLineRotation; |
| 527 if (m_bVertical && (pLastChar->m_dwCharProps & 0x8000) != 0) { | 524 if (m_bVertical && (pLastChar->m_dwCharProps & 0x8000) != 0) { |
| 528 iLastRotation++; | 525 iLastRotation++; |
| 529 } | 526 } |
| 530 if (m_bVertical != FX_IsOdd(iLastRotation)) { | 527 if (m_bVertical != FX_IsOdd(iLastRotation)) { |
| 531 iCharWidth = 1000; | 528 iCharWidth = 1000; |
| 532 } else { | 529 } else { |
| 533 if (!m_pFont->GetCharWidth(wForm, iCharWidth, m_bCharCode)) { | 530 if (!m_pFont->GetCharWidth(wForm, iCharWidth, m_bCharCode)) { |
| 534 if (!m_pFont->GetCharWidth(pLastChar->m_wCharCode, iCharWidth, | 531 if (!m_pFont->GetCharWidth(pLastChar->m_wCharCode, iCharWidth, |
| 535 m_bCharCode)) { | 532 m_bCharCode)) { |
| 536 iCharWidth = m_iDefChar; | 533 iCharWidth = m_iDefChar; |
| 537 } | 534 } |
| 538 } | 535 } |
| 539 } | 536 } |
| 540 iCharWidth *= m_iFontSize; | 537 iCharWidth *= m_iFontSize; |
| 541 iCharWidth = iCharWidth * m_iHorizontalScale / 100; | 538 iCharWidth = iCharWidth * m_iHorizontalScale / 100; |
| 542 pLastChar->m_iCharWidth = iCharWidth; | 539 pLastChar->m_iCharWidth = iCharWidth; |
| 543 iLineWidth += iCharWidth; | 540 iLineWidth += iCharWidth; |
| 544 iCharWidth = 0; | 541 iCharWidth = 0; |
| 545 } | 542 } |
| 546 } | 543 } |
| 547 wForm = | 544 wForm = pdfium::arabic::GetFormChar(pCurChar, bAlef ? nullptr : pLastChar, |
| 548 m_pArabicChar->GetFormChar(pCurChar, (bAlef ? NULL : pLastChar), NULL); | 545 nullptr); |
| 549 if (m_bVertical != FX_IsOdd(iRotation)) { | 546 if (m_bVertical != FX_IsOdd(iRotation)) { |
| 550 iCharWidth = 1000; | 547 iCharWidth = 1000; |
| 551 } else if (!m_pFont->GetCharWidth(wForm, iCharWidth, m_bCharCode) && | 548 } else if (!m_pFont->GetCharWidth(wForm, iCharWidth, m_bCharCode) && |
| 552 !m_pFont->GetCharWidth(pCurChar->m_wCharCode, iCharWidth, | 549 !m_pFont->GetCharWidth(pCurChar->m_wCharCode, iCharWidth, |
| 553 m_bCharCode)) { | 550 m_bCharCode)) { |
| 554 iCharWidth = m_iDefChar; | 551 iCharWidth = m_iDefChar; |
| 555 } | 552 } |
| 556 | 553 |
| 557 iCharWidth *= m_iFontSize; | 554 iCharWidth *= m_iFontSize; |
| 558 iCharWidth = iCharWidth * m_iHorizontalScale / 100; | 555 iCharWidth = iCharWidth * m_iHorizontalScale / 100; |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 if (i < iLength) { | 1258 if (i < iLength) { |
| 1262 wNext = *pStr; | 1259 wNext = *pStr; |
| 1263 if (*pWidths < 0) { | 1260 if (*pWidths < 0) { |
| 1264 if (i + 1 < iLength) { | 1261 if (i + 1 < iLength) { |
| 1265 wNext = pStr[1]; | 1262 wNext = pStr[1]; |
| 1266 } | 1263 } |
| 1267 } | 1264 } |
| 1268 } else { | 1265 } else { |
| 1269 wNext = 0xFEFF; | 1266 wNext = 0xFEFF; |
| 1270 } | 1267 } |
| 1271 wForm = m_pArabicChar->GetFormChar(wch, wPrev, wNext); | 1268 wForm = pdfium::arabic::GetFormChar(wch, wPrev, wNext); |
| 1272 } else if (bRTLPiece || bVerticalChar) { | 1269 } else if (bRTLPiece || bVerticalChar) { |
| 1273 wForm = FX_GetMirrorChar(wch, dwProps, bRTLPiece, bVerticalChar); | 1270 wForm = FX_GetMirrorChar(wch, dwProps, bRTLPiece, bVerticalChar); |
| 1274 } else if (dwCharType == FX_CHARTYPE_Numeric && bArabicNumber) { | 1271 } else if (dwCharType == FX_CHARTYPE_Numeric && bArabicNumber) { |
| 1275 wForm = wch + 0x0630; | 1272 wForm = wch + 0x0630; |
| 1276 } | 1273 } |
| 1277 dwProps = FX_GetUnicodeProperties(wForm); | 1274 dwProps = FX_GetUnicodeProperties(wForm); |
| 1278 } | 1275 } |
| 1279 iCharRotation = iRotation; | 1276 iCharRotation = iRotation; |
| 1280 if (!bMBCSCode && bVerticalChar && (dwProps & 0x8000) != 0) { | 1277 if (!bMBCSCode && bVerticalChar && (dwProps & 0x8000) != 0) { |
| 1281 iCharRotation++; | 1278 iCharRotation++; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 rtBBoxF.height = fHeight; | 1511 rtBBoxF.height = fHeight; |
| 1515 rtBBoxF.top = std::max(rtBBoxF.top, 0.0f); | 1512 rtBBoxF.top = std::max(rtBBoxF.top, 0.0f); |
| 1516 } | 1513 } |
| 1517 rtArray.SetAt(i, rtBBoxF); | 1514 rtArray.SetAt(i, rtBBoxF); |
| 1518 continue; | 1515 continue; |
| 1519 } | 1516 } |
| 1520 rtArray.SetAt(i, rect); | 1517 rtArray.SetAt(i, rect); |
| 1521 } | 1518 } |
| 1522 return iLength; | 1519 return iLength; |
| 1523 } | 1520 } |
| OLD | NEW |