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 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 FX_FLOAT fLinePos = 0; | 1035 FX_FLOAT fLinePos = 0; |
1036 Loader(size, fLinePos, TRUE); | 1036 Loader(size, fLinePos, TRUE); |
1037 UpdateAlign(size.y, fLinePos); | 1037 UpdateAlign(size.y, fLinePos); |
1038 m_pTabstopContext.reset(); | 1038 m_pTabstopContext.reset(); |
1039 if (fHeight) | 1039 if (fHeight) |
1040 *fHeight = fLinePos; | 1040 *fHeight = fLinePos; |
1041 return TRUE; | 1041 return TRUE; |
1042 } | 1042 } |
1043 | 1043 |
1044 FX_BOOL CXFA_TextLayout::Layout(int32_t iBlock) { | 1044 FX_BOOL CXFA_TextLayout::Layout(int32_t iBlock) { |
1045 if (m_pLoader == NULL || iBlock < 0 || iBlock >= CountBlocks()) { | 1045 if (m_pLoader == NULL || iBlock < 0 || iBlock >= CountBlocks()) |
1046 return FALSE; | 1046 return FALSE; |
1047 } | 1047 if (m_pLoader->m_fWidth < 1) |
1048 if (m_pLoader->m_fWidth < 1) { | |
1049 return FALSE; | 1048 return FALSE; |
1050 } | 1049 |
1051 m_pLoader->m_iTotalLines = -1; | 1050 m_pLoader->m_iTotalLines = -1; |
1052 m_iLines = 0; | 1051 m_iLines = 0; |
1053 FX_FLOAT fLinePos = 0; | 1052 FX_FLOAT fLinePos = 0; |
1054 CXFA_Node* pNode = NULL; | 1053 CXFA_Node* pNode = NULL; |
1055 CFX_SizeF szText(m_pLoader->m_fWidth, m_pLoader->m_fHeight); | 1054 CFX_SizeF szText(m_pLoader->m_fWidth, m_pLoader->m_fHeight); |
1056 int32_t iCount = m_Blocks.GetSize(); | 1055 int32_t iCount = m_Blocks.GetSize(); |
1057 int32_t iBlocksHeightCount = m_pLoader->m_BlocksHeight.GetSize(); | 1056 int32_t iBlocksHeightCount = m_pLoader->m_BlocksHeight.GetSize(); |
1058 iBlocksHeightCount /= 2; | 1057 iBlocksHeightCount /= 2; |
1059 if (iBlock < iBlocksHeightCount) { | 1058 if (iBlock < iBlocksHeightCount) |
1060 return TRUE; | 1059 return TRUE; |
1061 } | |
1062 if (iBlock == iBlocksHeightCount) { | 1060 if (iBlock == iBlocksHeightCount) { |
1063 Unload(); | 1061 Unload(); |
1064 m_pBreak.reset(CreateBreak(TRUE)); | 1062 m_pBreak.reset(CreateBreak(TRUE)); |
1065 fLinePos = m_pLoader->m_fStartLineOffset; | 1063 fLinePos = m_pLoader->m_fStartLineOffset; |
1066 for (int32_t i = 0; i < iBlocksHeightCount; i++) { | 1064 for (int32_t i = 0; i < iBlocksHeightCount; i++) { |
1067 fLinePos -= m_pLoader->m_BlocksHeight.ElementAt(i * 2 + 1); | 1065 fLinePos -= m_pLoader->m_BlocksHeight.ElementAt(i * 2 + 1); |
1068 } | 1066 } |
1069 m_pLoader->m_iChar = 0; | 1067 m_pLoader->m_iChar = 0; |
1070 if (iCount > 1) { | 1068 if (iCount > 1) |
1071 m_pLoader->m_iTotalLines = m_Blocks.ElementAt(iBlock * 2 + 1); | 1069 m_pLoader->m_iTotalLines = m_Blocks.ElementAt(iBlock * 2 + 1); |
1072 } | |
1073 Loader(szText, fLinePos, TRUE); | 1070 Loader(szText, fLinePos, TRUE); |
1074 if (iCount == 0 && m_pLoader->m_fStartLineOffset < 0.1f) { | 1071 if (iCount == 0 && m_pLoader->m_fStartLineOffset < 0.1f) |
1075 UpdateAlign(szText.y, fLinePos); | 1072 UpdateAlign(szText.y, fLinePos); |
1076 } | |
1077 } else if (m_pTextDataNode) { | 1073 } else if (m_pTextDataNode) { |
1078 iBlock *= 2; | 1074 iBlock *= 2; |
1079 if (iBlock < iCount - 2) { | 1075 if (iBlock < iCount - 2) |
1080 m_pLoader->m_iTotalLines = m_Blocks.ElementAt(iBlock + 1); | 1076 m_pLoader->m_iTotalLines = m_Blocks.ElementAt(iBlock + 1); |
1081 } | |
1082 m_pBreak->Reset(); | 1077 m_pBreak->Reset(); |
1083 if (m_bRichText) { | 1078 if (m_bRichText) { |
1084 CFDE_XMLNode* pContainerNode = GetXMLContainerNode(); | 1079 CFDE_XMLNode* pContainerNode = GetXMLContainerNode(); |
1085 if (!pContainerNode) { | 1080 if (!pContainerNode) { |
1086 return TRUE; | 1081 return TRUE; |
1087 } | 1082 } |
1088 CFDE_XMLNode* pXMLNode = m_pLoader->m_pXMLNode; | 1083 CFDE_XMLNode* pXMLNode = m_pLoader->m_pXMLNode; |
1089 if (pXMLNode == NULL) { | 1084 if (!pXMLNode) |
1090 return TRUE; | 1085 return TRUE; |
1091 } | |
1092 CFDE_XMLNode* pSaveXMLNode = m_pLoader->m_pXMLNode; | 1086 CFDE_XMLNode* pSaveXMLNode = m_pLoader->m_pXMLNode; |
1093 for (; pXMLNode; | 1087 for (; pXMLNode; |
1094 pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 1088 pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
1095 FX_BOOL bFlag = LoadRichText(pXMLNode, szText, fLinePos, | 1089 if (!LoadRichText(pXMLNode, szText, fLinePos, m_pLoader->m_pParentStyle, |
1096 m_pLoader->m_pParentStyle, TRUE); | 1090 TRUE)) { |
1097 if (!bFlag) { | |
1098 break; | 1091 break; |
1099 } | 1092 } |
1100 } | 1093 } |
1101 while (pXMLNode == NULL) { | 1094 while (!pXMLNode) { |
1102 pXMLNode = pSaveXMLNode->GetNodeItem(CFDE_XMLNode::Parent); | 1095 pXMLNode = pSaveXMLNode->GetNodeItem(CFDE_XMLNode::Parent); |
1103 if (pXMLNode == pContainerNode) { | 1096 if (pXMLNode == pContainerNode) |
1104 break; | 1097 break; |
1105 } | 1098 if (!LoadRichText(pXMLNode, szText, fLinePos, m_pLoader->m_pParentStyle, |
1106 FX_BOOL bFlag = | 1099 TRUE, NULL, FALSE)) { |
1107 LoadRichText(pXMLNode, szText, fLinePos, m_pLoader->m_pParentStyle, | |
1108 TRUE, NULL, FALSE); | |
1109 if (!bFlag) { | |
1110 break; | 1100 break; |
1111 } | 1101 } |
1112 pSaveXMLNode = pXMLNode; | 1102 pSaveXMLNode = pXMLNode; |
1113 pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling); | 1103 pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling); |
1114 if (!pXMLNode) { | 1104 if (!pXMLNode) |
1115 continue; | 1105 continue; |
1116 } | |
1117 for (; pXMLNode; | 1106 for (; pXMLNode; |
1118 pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 1107 pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
1119 FX_BOOL bFlag = LoadRichText(pXMLNode, szText, fLinePos, | 1108 if (!LoadRichText(pXMLNode, szText, fLinePos, |
1120 m_pLoader->m_pParentStyle, TRUE); | 1109 m_pLoader->m_pParentStyle, TRUE)) { |
1121 if (!bFlag) { | |
1122 break; | 1110 break; |
1123 } | 1111 } |
1124 } | 1112 } |
1125 } | 1113 } |
1126 } else { | 1114 } else { |
1127 pNode = m_pLoader->m_pNode; | 1115 pNode = m_pLoader->m_pNode; |
1128 if (pNode == NULL) { | 1116 if (!pNode) |
1129 return TRUE; | 1117 return TRUE; |
1130 } | |
1131 LoadText(pNode, szText, fLinePos, TRUE); | 1118 LoadText(pNode, szText, fLinePos, TRUE); |
1132 } | 1119 } |
1133 } | 1120 } |
1134 if (iBlock == iCount) { | 1121 if (iBlock == iCount) { |
1135 m_pTabstopContext.reset(); | 1122 m_pTabstopContext.reset(); |
1136 m_pLoader.reset(); | 1123 m_pLoader.reset(); |
1137 } | 1124 } |
1138 return TRUE; | 1125 return TRUE; |
1139 } | 1126 } |
1140 void CXFA_TextLayout::ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex) { | 1127 void CXFA_TextLayout::ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex) { |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1832 FX_BOOL bNoLineThrough = pPiece->iLineThrough < 1 || pPiece->iLineThrough > 2; | 1819 FX_BOOL bNoLineThrough = pPiece->iLineThrough < 1 || pPiece->iLineThrough > 2; |
1833 if (bNoUnderline && bNoLineThrough) { | 1820 if (bNoUnderline && bNoLineThrough) { |
1834 return; | 1821 return; |
1835 } | 1822 } |
1836 pPen->SetColor(pPiece->dwColor); | 1823 pPen->SetColor(pPiece->dwColor); |
1837 std::unique_ptr<CFDE_Path> pPath(new CFDE_Path); | 1824 std::unique_ptr<CFDE_Path> pPath(new CFDE_Path); |
1838 int32_t iChars = GetDisplayPos(pPiece, pCharPos); | 1825 int32_t iChars = GetDisplayPos(pPiece, pCharPos); |
1839 if (iChars > 0) { | 1826 if (iChars > 0) { |
1840 CFX_PointF pt1, pt2; | 1827 CFX_PointF pt1, pt2; |
1841 FX_FLOAT fEndY = pCharPos[0].m_OriginY + 1.05f; | 1828 FX_FLOAT fEndY = pCharPos[0].m_OriginY + 1.05f; |
1842 int32_t i = 0; | |
1843 if (pPiece->iPeriod == XFA_ATTRIBUTEENUM_Word) { | 1829 if (pPiece->iPeriod == XFA_ATTRIBUTEENUM_Word) { |
1844 for (int32_t i = 0; i < pPiece->iUnderline; i++) { | 1830 for (int32_t i = 0; i < pPiece->iUnderline; i++) { |
1845 for (int32_t j = 0; j < iChars; j++) { | 1831 for (int32_t j = 0; j < iChars; j++) { |
1846 pt1.x = pCharPos[j].m_OriginX; | 1832 pt1.x = pCharPos[j].m_OriginX; |
1847 pt2.x = | 1833 pt2.x = |
1848 pt1.x + pCharPos[j].m_FontCharWidth * pPiece->fFontSize / 1000.0f; | 1834 pt1.x + pCharPos[j].m_FontCharWidth * pPiece->fFontSize / 1000.0f; |
1849 pt1.y = pt2.y = fEndY; | 1835 pt1.y = pt2.y = fEndY; |
1850 pPath->AddLine(pt1, pt2); | 1836 pPath->AddLine(pt1, pt2); |
1851 } | 1837 } |
1852 fEndY += 2.0f; | 1838 fEndY += 2.0f; |
1853 } | 1839 } |
1854 } else { | 1840 } else { |
1855 pt1.x = pCharPos[0].m_OriginX; | 1841 pt1.x = pCharPos[0].m_OriginX; |
1856 pt2.x = | 1842 pt2.x = |
1857 pCharPos[iChars - 1].m_OriginX + | 1843 pCharPos[iChars - 1].m_OriginX + |
1858 pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; | 1844 pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; |
1859 for (int32_t i = 0; i < pPiece->iUnderline; i++) { | 1845 for (int32_t i = 0; i < pPiece->iUnderline; i++) { |
1860 pt1.y = pt2.y = fEndY; | 1846 pt1.y = pt2.y = fEndY; |
1861 pPath->AddLine(pt1, pt2); | 1847 pPath->AddLine(pt1, pt2); |
1862 fEndY += 2.0f; | 1848 fEndY += 2.0f; |
1863 } | 1849 } |
1864 } | 1850 } |
1865 fEndY = pCharPos[0].m_OriginY - pPiece->rtPiece.height * 0.25f; | 1851 fEndY = pCharPos[0].m_OriginY - pPiece->rtPiece.height * 0.25f; |
1866 pt1.x = pCharPos[0].m_OriginX; | 1852 pt1.x = pCharPos[0].m_OriginX; |
1867 pt2.x = pCharPos[iChars - 1].m_OriginX + | 1853 pt2.x = pCharPos[iChars - 1].m_OriginX + |
1868 pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; | 1854 pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; |
1869 for (i = 0; i < pPiece->iLineThrough; i++) { | 1855 for (int32_t i = 0; i < pPiece->iLineThrough; i++) { |
1870 pt1.y = pt2.y = fEndY; | 1856 pt1.y = pt2.y = fEndY; |
1871 pPath->AddLine(pt1, pt2); | 1857 pPath->AddLine(pt1, pt2); |
1872 fEndY += 2.0f; | 1858 fEndY += 2.0f; |
1873 } | 1859 } |
1874 } else { | 1860 } else { |
1875 if (bNoLineThrough && | 1861 if (bNoLineThrough && |
1876 (bNoUnderline || pPiece->iPeriod != XFA_ATTRIBUTEENUM_All)) { | 1862 (bNoUnderline || pPiece->iPeriod != XFA_ATTRIBUTEENUM_All)) { |
1877 return; | 1863 return; |
1878 } | 1864 } |
1879 int32_t iCharsTmp = 0; | 1865 int32_t iCharsTmp = 0; |
(...skipping 30 matching lines...) Expand all Loading... |
1910 pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; | 1896 pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; |
1911 pPiece = pPieceLine->m_textPieces.GetAt(iPieceNext); | 1897 pPiece = pPieceLine->m_textPieces.GetAt(iPieceNext); |
1912 iChars = GetDisplayPos(pPiece, pCharPos); | 1898 iChars = GetDisplayPos(pPiece, pCharPos); |
1913 if (iChars < 1) { | 1899 if (iChars < 1) { |
1914 return; | 1900 return; |
1915 } | 1901 } |
1916 fEndX = pCharPos[0].m_OriginX; | 1902 fEndX = pCharPos[0].m_OriginX; |
1917 CFX_PointF pt1, pt2; | 1903 CFX_PointF pt1, pt2; |
1918 pt1.x = fOrgX, pt2.x = fEndX; | 1904 pt1.x = fOrgX, pt2.x = fEndX; |
1919 FX_FLOAT fEndY = pCharPos[0].m_OriginY + 1.05f; | 1905 FX_FLOAT fEndY = pCharPos[0].m_OriginY + 1.05f; |
1920 int32_t i = 0; | 1906 for (int32_t i = 0; i < pPiece->iUnderline; i++) { |
1921 for (i = 0; i < pPiece->iUnderline; i++) { | |
1922 pt1.y = pt2.y = fEndY; | 1907 pt1.y = pt2.y = fEndY; |
1923 pPath->AddLine(pt1, pt2); | 1908 pPath->AddLine(pt1, pt2); |
1924 fEndY += 2.0f; | 1909 fEndY += 2.0f; |
1925 } | 1910 } |
1926 fEndY = pCharPos[0].m_OriginY - pPiece->rtPiece.height * 0.25f; | 1911 fEndY = pCharPos[0].m_OriginY - pPiece->rtPiece.height * 0.25f; |
1927 for (i = 0; i < pPiece->iLineThrough; i++) { | 1912 for (int32_t i = 0; i < pPiece->iLineThrough; i++) { |
1928 pt1.y = pt2.y = fEndY; | 1913 pt1.y = pt2.y = fEndY; |
1929 pPath->AddLine(pt1, pt2); | 1914 pPath->AddLine(pt1, pt2); |
1930 fEndY += 2.0f; | 1915 fEndY += 2.0f; |
1931 } | 1916 } |
1932 } | 1917 } |
1933 pDevice->DrawPath(pPen, 1, pPath.get(), &tmDoc2Device); | 1918 pDevice->DrawPath(pPen, 1, pPath.get(), &tmDoc2Device); |
1934 } | 1919 } |
1935 | 1920 |
1936 int32_t CXFA_TextLayout::GetDisplayPos(const XFA_TextPiece* pPiece, | 1921 int32_t CXFA_TextLayout::GetDisplayPos(const XFA_TextPiece* pPiece, |
1937 FXTEXT_CHARPOS* pCharPos, | 1922 FXTEXT_CHARPOS* pCharPos, |
(...skipping 19 matching lines...) Expand all Loading... |
1957 tr.iLength = iLength; | 1942 tr.iLength = iLength; |
1958 tr.fFontSize = pPiece->fFontSize; | 1943 tr.fFontSize = pPiece->fFontSize; |
1959 tr.iBidiLevel = pPiece->iBidiLevel; | 1944 tr.iBidiLevel = pPiece->iBidiLevel; |
1960 tr.iCharRotation = 0; | 1945 tr.iCharRotation = 0; |
1961 tr.wLineBreakChar = L'\n'; | 1946 tr.wLineBreakChar = L'\n'; |
1962 tr.iVerticalScale = pPiece->iVerScale; | 1947 tr.iVerticalScale = pPiece->iVerScale; |
1963 tr.dwLayoutStyles = FX_RTFLAYOUTSTYLE_ExpandTab; | 1948 tr.dwLayoutStyles = FX_RTFLAYOUTSTYLE_ExpandTab; |
1964 tr.iHorizontalScale = pPiece->iHorScale; | 1949 tr.iHorizontalScale = pPiece->iHorScale; |
1965 return TRUE; | 1950 return TRUE; |
1966 } | 1951 } |
OLD | NEW |