| 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_textlayout.h" | 7 #include "xfa/fxfa/app/xfa_textlayout.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 CXFA_Para para = pTextProvider->GetParaNode(); | 105 CXFA_Para para = pTextProvider->GetParaNode(); |
| 106 IFDE_CSSComputedStyle* pStyle = m_pSelector->CreateComputedStyle(NULL); | 106 IFDE_CSSComputedStyle* pStyle = m_pSelector->CreateComputedStyle(NULL); |
| 107 IFDE_CSSFontStyle* pFontStyle = pStyle->GetFontStyles(); | 107 IFDE_CSSFontStyle* pFontStyle = pStyle->GetFontStyles(); |
| 108 IFDE_CSSParagraphStyle* pParaStyle = pStyle->GetParagraphStyles(); | 108 IFDE_CSSParagraphStyle* pParaStyle = pStyle->GetParagraphStyles(); |
| 109 FX_FLOAT fLineHeight = 0, fFontSize = 10; | 109 FX_FLOAT fLineHeight = 0, fFontSize = 10; |
| 110 if (para) { | 110 if (para) { |
| 111 fLineHeight = para.GetLineHeight(); | 111 fLineHeight = para.GetLineHeight(); |
| 112 FDE_CSSLENGTH indent; | 112 FDE_CSSLENGTH indent; |
| 113 indent.Set(FDE_CSSLENGTHUNIT_Point, para.GetTextIndent()); | 113 indent.Set(FDE_CSSLENGTHUNIT_Point, para.GetTextIndent()); |
| 114 pParaStyle->SetTextIndent(indent); | 114 pParaStyle->SetTextIndent(indent); |
| 115 FDE_CSSTEXTALIGN hAlgin = FDE_CSSTEXTALIGN_Left; | 115 FDE_CSSTEXTALIGN hAlign = FDE_CSSTEXTALIGN_Left; |
| 116 switch (para.GetHorizontalAlign()) { | 116 switch (para.GetHorizontalAlign()) { |
| 117 case XFA_ATTRIBUTEENUM_Center: | 117 case XFA_ATTRIBUTEENUM_Center: |
| 118 hAlgin = FDE_CSSTEXTALIGN_Center; | 118 hAlign = FDE_CSSTEXTALIGN_Center; |
| 119 break; | 119 break; |
| 120 case XFA_ATTRIBUTEENUM_Right: | 120 case XFA_ATTRIBUTEENUM_Right: |
| 121 hAlgin = FDE_CSSTEXTALIGN_Right; | 121 hAlign = FDE_CSSTEXTALIGN_Right; |
| 122 break; | 122 break; |
| 123 case XFA_ATTRIBUTEENUM_Justify: | 123 case XFA_ATTRIBUTEENUM_Justify: |
| 124 hAlgin = FDE_CSSTEXTALIGN_Justify; | 124 hAlign = FDE_CSSTEXTALIGN_Justify; |
| 125 break; | 125 break; |
| 126 case XFA_ATTRIBUTEENUM_JustifyAll: | 126 case XFA_ATTRIBUTEENUM_JustifyAll: |
| 127 hAlgin = FDE_CSSTEXTALIGN_JustifyAll; | 127 hAlign = FDE_CSSTEXTALIGN_JustifyAll; |
| 128 break; | 128 break; |
| 129 } | 129 } |
| 130 pParaStyle->SetTextAlign(hAlgin); | 130 pParaStyle->SetTextAlign(hAlign); |
| 131 FDE_CSSRECT rtMarginWidth; | 131 FDE_CSSRECT rtMarginWidth; |
| 132 rtMarginWidth.left.Set(FDE_CSSLENGTHUNIT_Point, para.GetMarginLeft()); | 132 rtMarginWidth.left.Set(FDE_CSSLENGTHUNIT_Point, para.GetMarginLeft()); |
| 133 rtMarginWidth.top.Set(FDE_CSSLENGTHUNIT_Point, para.GetSpaceAbove()); | 133 rtMarginWidth.top.Set(FDE_CSSLENGTHUNIT_Point, para.GetSpaceAbove()); |
| 134 rtMarginWidth.right.Set(FDE_CSSLENGTHUNIT_Point, para.GetMarginRight()); | 134 rtMarginWidth.right.Set(FDE_CSSLENGTHUNIT_Point, para.GetMarginRight()); |
| 135 rtMarginWidth.bottom.Set(FDE_CSSLENGTHUNIT_Point, para.GetSpaceBelow()); | 135 rtMarginWidth.bottom.Set(FDE_CSSLENGTHUNIT_Point, para.GetSpaceBelow()); |
| 136 pStyle->GetBoundaryStyles()->SetMarginWidth(rtMarginWidth); | 136 pStyle->GetBoundaryStyles()->SetMarginWidth(rtMarginWidth); |
| 137 } | 137 } |
| 138 if (font) { | 138 if (font) { |
| 139 pFontStyle->SetColor(font.GetColor()); | 139 pFontStyle->SetColor(font.GetColor()); |
| 140 pFontStyle->SetFontStyle(font.IsItalic() ? FDE_CSSFONTSTYLE_Italic | 140 pFontStyle->SetFontStyle(font.IsItalic() ? FDE_CSSFONTSTYLE_Italic |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 static const uint32_t s_XFATagName[] = { | 268 static const uint32_t s_XFATagName[] = { |
| 269 0x61, 0x62, 0x69, 0x70, 0x0001f714, | 269 0x61, 0x62, 0x69, 0x70, 0x0001f714, |
| 270 0x00022a55, 0x000239bb, 0x00025881, 0x0bd37faa, 0x0bd37fb8, | 270 0x00022a55, 0x000239bb, 0x00025881, 0x0bd37faa, 0x0bd37fb8, |
| 271 0xa73e3af2, 0xb182eaae, 0xdb8ac455, | 271 0xa73e3af2, 0xb182eaae, 0xdb8ac455, |
| 272 }; | 272 }; |
| 273 CFX_WideString wsName; | 273 CFX_WideString wsName; |
| 274 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { | 274 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { |
| 275 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); | 275 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
| 276 pXMLElement->GetLocalTagName(wsName); | 276 pXMLElement->GetLocalTagName(wsName); |
| 277 tagProvider.SetTagNameObj(wsName); | 277 tagProvider.SetTagNameObj(wsName); |
| 278 uint32_t dwHashCode = | 278 uint32_t dwHashCode = FX_HashCode_GetW(wsName.AsStringC(), true); |
| 279 FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength(), TRUE); | |
| 280 static const int32_t s_iCount = sizeof(s_XFATagName) / sizeof(uint32_t); | 279 static const int32_t s_iCount = sizeof(s_XFATagName) / sizeof(uint32_t); |
| 281 CFX_DSPATemplate<uint32_t> lookup; | 280 CFX_DSPATemplate<uint32_t> lookup; |
| 282 tagProvider.m_bTagAviliable = | 281 tagProvider.m_bTagAviliable = |
| 283 lookup.Lookup(dwHashCode, s_XFATagName, s_iCount) > -1; | 282 lookup.Lookup(dwHashCode, s_XFATagName, s_iCount) > -1; |
| 284 CFX_WideString wsValue; | 283 CFX_WideString wsValue; |
| 285 pXMLElement->GetString(FX_WSTRC(L"style").c_str(), wsValue); | 284 pXMLElement->GetString(FX_WSTRC(L"style").c_str(), wsValue); |
| 286 if (!wsValue.IsEmpty()) { | 285 if (!wsValue.IsEmpty()) { |
| 287 tagProvider.SetAttribute(FX_WSTRC(L"style"), wsValue); | 286 tagProvider.SetAttribute(FX_WSTRC(L"style"), wsValue); |
| 288 } | 287 } |
| 289 } else if (pXMLNode->GetType() == FDE_XMLNODE_Text) { | 288 } else if (pXMLNode->GetType() == FDE_XMLNODE_Text) { |
| 290 tagProvider.m_bTagAviliable = TRUE; | 289 tagProvider.m_bTagAviliable = TRUE; |
| 291 tagProvider.m_bContent = TRUE; | 290 tagProvider.m_bContent = TRUE; |
| 292 } | 291 } |
| 293 } | 292 } |
| 294 | 293 |
| 295 int32_t CXFA_TextParser::GetVAlgin(CXFA_TextProvider* pTextProvider) const { | 294 int32_t CXFA_TextParser::GetVAlign(CXFA_TextProvider* pTextProvider) const { |
| 296 CXFA_Para para = pTextProvider->GetParaNode(); | 295 CXFA_Para para = pTextProvider->GetParaNode(); |
| 297 return para ? para.GetVerticalAlign() : XFA_ATTRIBUTEENUM_Top; | 296 return para ? para.GetVerticalAlign() : XFA_ATTRIBUTEENUM_Top; |
| 298 } | 297 } |
| 299 | 298 |
| 300 FX_FLOAT CXFA_TextParser::GetTabInterval(IFDE_CSSComputedStyle* pStyle) const { | 299 FX_FLOAT CXFA_TextParser::GetTabInterval(IFDE_CSSComputedStyle* pStyle) const { |
| 301 CFX_WideString wsValue; | 300 CFX_WideString wsValue; |
| 302 if (pStyle && pStyle->GetCustomStyle(FX_WSTRC(L"tab-interval"), wsValue)) | 301 if (pStyle && pStyle->GetCustomStyle(FX_WSTRC(L"tab-interval"), wsValue)) |
| 303 return CXFA_Measurement(wsValue.AsStringC()).ToUnit(XFA_UNIT_Pt); | 302 return CXFA_Measurement(wsValue.AsStringC()).ToUnit(XFA_UNIT_Pt); |
| 304 return 36; | 303 return 36; |
| 305 } | 304 } |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 } | 605 } |
| 607 while (iCur < iLength && pTabStops[iCur] <= ' ') { | 606 while (iCur < iLength && pTabStops[iCur] <= ' ') { |
| 608 iCur++; | 607 iCur++; |
| 609 } | 608 } |
| 610 iLast = iCur; | 609 iLast = iCur; |
| 611 eStatus = XFA_TABSTOPSSTATUS_Location; | 610 eStatus = XFA_TABSTOPSSTATUS_Location; |
| 612 } | 611 } |
| 613 break; | 612 break; |
| 614 case XFA_TABSTOPSSTATUS_Location: | 613 case XFA_TABSTOPSSTATUS_Location: |
| 615 if (ch == ' ') { | 614 if (ch == ' ') { |
| 616 uint32_t dwHashCode = FX_HashCode_String_GetW( | 615 uint32_t dwHashCode = FX_HashCode_GetW(wsAlign.AsStringC(), true); |
| 617 wsAlign.c_str(), wsAlign.GetLength(), TRUE); | |
| 618 CXFA_Measurement ms(CFX_WideStringC(pTabStops + iLast, iCur - iLast)); | 616 CXFA_Measurement ms(CFX_WideStringC(pTabStops + iLast, iCur - iLast)); |
| 619 FX_FLOAT fPos = ms.ToUnit(XFA_UNIT_Pt); | 617 FX_FLOAT fPos = ms.ToUnit(XFA_UNIT_Pt); |
| 620 pTabstopContext->Append(dwHashCode, fPos); | 618 pTabstopContext->Append(dwHashCode, fPos); |
| 621 wsAlign.clear(); | 619 wsAlign.clear(); |
| 622 eStatus = XFA_TABSTOPSSTATUS_None; | 620 eStatus = XFA_TABSTOPSSTATUS_None; |
| 623 } | 621 } |
| 624 iCur++; | 622 iCur++; |
| 625 break; | 623 break; |
| 626 default: | 624 default: |
| 627 break; | 625 break; |
| 628 } | 626 } |
| 629 } | 627 } |
| 630 if (!wsAlign.IsEmpty()) { | 628 if (!wsAlign.IsEmpty()) { |
| 631 uint32_t dwHashCode = | 629 uint32_t dwHashCode = FX_HashCode_GetW(wsAlign.AsStringC(), true); |
| 632 FX_HashCode_String_GetW(wsAlign.c_str(), wsAlign.GetLength(), TRUE); | |
| 633 CXFA_Measurement ms(CFX_WideStringC(pTabStops + iLast, iCur - iLast)); | 630 CXFA_Measurement ms(CFX_WideStringC(pTabStops + iLast, iCur - iLast)); |
| 634 FX_FLOAT fPos = ms.ToUnit(XFA_UNIT_Pt); | 631 FX_FLOAT fPos = ms.ToUnit(XFA_UNIT_Pt); |
| 635 pTabstopContext->Append(dwHashCode, fPos); | 632 pTabstopContext->Append(dwHashCode, fPos); |
| 636 } | 633 } |
| 637 return TRUE; | 634 return TRUE; |
| 638 } | 635 } |
| 639 CXFA_TextLayout::CXFA_TextLayout(CXFA_TextProvider* pTextProvider) | 636 CXFA_TextLayout::CXFA_TextLayout(CXFA_TextProvider* pTextProvider) |
| 640 : m_bHasBlock(FALSE), | 637 : m_bHasBlock(FALSE), |
| 641 m_pTextProvider(pTextProvider), | 638 m_pTextProvider(pTextProvider), |
| 642 m_pTextDataNode(nullptr), | 639 m_pTextDataNode(nullptr), |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 fHeight = GetLayoutHeight(); | 924 fHeight = GetLayoutHeight(); |
| 928 } | 925 } |
| 929 m_pLoader->m_fHeight = fHeight; | 926 m_pLoader->m_fHeight = fHeight; |
| 930 if (fContentAreaHeight < 0) { | 927 if (fContentAreaHeight < 0) { |
| 931 return FALSE; | 928 return FALSE; |
| 932 } | 929 } |
| 933 m_bHasBlock = TRUE; | 930 m_bHasBlock = TRUE; |
| 934 if (iBlockCount == 0 && fHeight > 0) { | 931 if (iBlockCount == 0 && fHeight > 0) { |
| 935 fHeight = fTextHeight - GetLayoutHeight(); | 932 fHeight = fTextHeight - GetLayoutHeight(); |
| 936 if (fHeight > 0) { | 933 if (fHeight > 0) { |
| 937 int32_t iAlign = m_textParser.GetVAlgin(m_pTextProvider); | 934 int32_t iAlign = m_textParser.GetVAlign(m_pTextProvider); |
| 938 if (iAlign == XFA_ATTRIBUTEENUM_Middle) { | 935 if (iAlign == XFA_ATTRIBUTEENUM_Middle) { |
| 939 fHeight /= 2.0f; | 936 fHeight /= 2.0f; |
| 940 } else if (iAlign != XFA_ATTRIBUTEENUM_Bottom) { | 937 } else if (iAlign != XFA_ATTRIBUTEENUM_Bottom) { |
| 941 fHeight = 0; | 938 fHeight = 0; |
| 942 } | 939 } |
| 943 m_pLoader->m_fStartLineOffset = fHeight; | 940 m_pLoader->m_fStartLineOffset = fHeight; |
| 944 } | 941 } |
| 945 } | 942 } |
| 946 FX_FLOAT fLinePos = m_pLoader->m_fStartLineOffset; | 943 FX_FLOAT fLinePos = m_pLoader->m_fStartLineOffset; |
| 947 int32_t iLineIndex = 0; | 944 int32_t iLineIndex = 0; |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 delete pSolidBrush; | 1243 delete pSolidBrush; |
| 1247 delete pPen; | 1244 delete pPen; |
| 1248 pDevice->Release(); | 1245 pDevice->Release(); |
| 1249 return iPieceLines; | 1246 return iPieceLines; |
| 1250 } | 1247 } |
| 1251 void CXFA_TextLayout::UpdateAlign(FX_FLOAT fHeight, FX_FLOAT fBottom) { | 1248 void CXFA_TextLayout::UpdateAlign(FX_FLOAT fHeight, FX_FLOAT fBottom) { |
| 1252 fHeight -= fBottom; | 1249 fHeight -= fBottom; |
| 1253 if (fHeight < 0.1f) { | 1250 if (fHeight < 0.1f) { |
| 1254 return; | 1251 return; |
| 1255 } | 1252 } |
| 1256 switch (m_textParser.GetVAlgin(m_pTextProvider)) { | 1253 switch (m_textParser.GetVAlign(m_pTextProvider)) { |
| 1257 case XFA_ATTRIBUTEENUM_Middle: | 1254 case XFA_ATTRIBUTEENUM_Middle: |
| 1258 fHeight /= 2.0f; | 1255 fHeight /= 2.0f; |
| 1259 break; | 1256 break; |
| 1260 case XFA_ATTRIBUTEENUM_Bottom: | 1257 case XFA_ATTRIBUTEENUM_Bottom: |
| 1261 break; | 1258 break; |
| 1262 default: | 1259 default: |
| 1263 return; | 1260 return; |
| 1264 } | 1261 } |
| 1265 int32_t iCount = m_pieceLines.GetSize(); | 1262 int32_t iCount = m_pieceLines.GetSize(); |
| 1266 for (int32_t i = 0; i < iCount; i++) { | 1263 for (int32_t i = 0; i < iCount; i++) { |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1636 XFA_TextPiece* p = pPieceLine->m_textPieces.GetAt(iPieces - 2); | 1633 XFA_TextPiece* p = pPieceLine->m_textPieces.GetAt(iPieces - 2); |
| 1637 fRight = p->rtPiece.right(); | 1634 fRight = p->rtPiece.right(); |
| 1638 } | 1635 } |
| 1639 m_pTabstopContext->m_fTabWidth = | 1636 m_pTabstopContext->m_fTabWidth = |
| 1640 pPiece->rtPiece.width + pPiece->rtPiece.left - fRight; | 1637 pPiece->rtPiece.width + pPiece->rtPiece.left - fRight; |
| 1641 } else if (iTabstopsIndex > -1) { | 1638 } else if (iTabstopsIndex > -1) { |
| 1642 FX_FLOAT fLeft = 0; | 1639 FX_FLOAT fLeft = 0; |
| 1643 if (m_pTabstopContext->m_bTabstops) { | 1640 if (m_pTabstopContext->m_bTabstops) { |
| 1644 XFA_TABSTOPS* pTabstops = | 1641 XFA_TABSTOPS* pTabstops = |
| 1645 m_pTabstopContext->m_tabstops.GetDataPtr(iTabstopsIndex); | 1642 m_pTabstopContext->m_tabstops.GetDataPtr(iTabstopsIndex); |
| 1646 uint32_t dwAlgin = pTabstops->dwAlign; | 1643 uint32_t dwAlign = pTabstops->dwAlign; |
| 1647 if (dwAlgin == FX_HashCode_String_GetW(L"center", 6)) { | 1644 if (dwAlign == FX_HashCode_GetW(L"center", false)) { |
| 1648 fLeft = pPiece->rtPiece.width / 2.0f; | 1645 fLeft = pPiece->rtPiece.width / 2.0f; |
| 1649 } else if (dwAlgin == FX_HashCode_String_GetW(L"right", 5) || | 1646 } else if (dwAlign == FX_HashCode_GetW(L"right", false) || |
| 1650 dwAlgin == FX_HashCode_String_GetW(L"before", 6)) { | 1647 dwAlign == FX_HashCode_GetW(L"before", false)) { |
| 1651 fLeft = pPiece->rtPiece.width; | 1648 fLeft = pPiece->rtPiece.width; |
| 1652 } else if (dwAlgin == FX_HashCode_String_GetW(L"decimal", 7)) { | 1649 } else if (dwAlign == FX_HashCode_GetW(L"decimal", false)) { |
| 1653 int32_t iChars = pPiece->iChars; | 1650 int32_t iChars = pPiece->iChars; |
| 1654 for (int32_t i = 0; i < iChars; i++) { | 1651 for (int32_t i = 0; i < iChars; i++) { |
| 1655 if (pPiece->pszText[i] == L'.') { | 1652 if (pPiece->pszText[i] == L'.') { |
| 1656 break; | 1653 break; |
| 1657 } | 1654 } |
| 1658 fLeft += pPiece->pWidths[i] / 20000.0f; | 1655 fLeft += pPiece->pWidths[i] / 20000.0f; |
| 1659 } | 1656 } |
| 1660 } | 1657 } |
| 1661 m_pTabstopContext->m_fLeft = | 1658 m_pTabstopContext->m_fLeft = |
| 1662 std::min(fLeft, m_pTabstopContext->m_fTabWidth); | 1659 std::min(fLeft, m_pTabstopContext->m_fTabWidth); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1963 tr.iLength = iLength; | 1960 tr.iLength = iLength; |
| 1964 tr.fFontSize = pPiece->fFontSize; | 1961 tr.fFontSize = pPiece->fFontSize; |
| 1965 tr.iBidiLevel = pPiece->iBidiLevel; | 1962 tr.iBidiLevel = pPiece->iBidiLevel; |
| 1966 tr.iCharRotation = 0; | 1963 tr.iCharRotation = 0; |
| 1967 tr.wLineBreakChar = L'\n'; | 1964 tr.wLineBreakChar = L'\n'; |
| 1968 tr.iVerticalScale = pPiece->iVerScale; | 1965 tr.iVerticalScale = pPiece->iVerScale; |
| 1969 tr.dwLayoutStyles = FX_RTFLAYOUTSTYLE_ExpandTab; | 1966 tr.dwLayoutStyles = FX_RTFLAYOUTSTYLE_ExpandTab; |
| 1970 tr.iHorizontalScale = pPiece->iHorScale; | 1967 tr.iHorizontalScale = pPiece->iHorScale; |
| 1971 return TRUE; | 1968 return TRUE; |
| 1972 } | 1969 } |
| OLD | NEW |