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> | 7 #include <algorithm> |
8 | 8 |
9 #include "core/include/fpdfdoc/fpdf_doc.h" | 9 #include "core/include/fpdfdoc/fpdf_doc.h" |
10 #include "core/include/fpdfdoc/fpdf_vt.h" | 10 #include "core/include/fpdfdoc/fpdf_vt.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 nMid = (nLeft + nRight) / 2; | 159 nMid = (nLeft + nRight) / 2; |
160 } else { | 160 } else { |
161 place.nLineIndex = nMid; | 161 place.nLineIndex = nMid; |
162 return; | 162 return; |
163 } | 163 } |
164 } else { | 164 } else { |
165 break; | 165 break; |
166 } | 166 } |
167 } | 167 } |
168 } | 168 } |
169 CPVT_WordPlace CSection::SearchWordPlace(const CPDF_Point& point) const { | 169 CPVT_WordPlace CSection::SearchWordPlace(const CFX_FloatPoint& point) const { |
170 ASSERT(m_pVT); | 170 ASSERT(m_pVT); |
171 CPVT_WordPlace place = GetBeginWordPlace(); | 171 CPVT_WordPlace place = GetBeginWordPlace(); |
172 FX_BOOL bUp = TRUE; | 172 FX_BOOL bUp = TRUE; |
173 FX_BOOL bDown = TRUE; | 173 FX_BOOL bDown = TRUE; |
174 int32_t nLeft = 0; | 174 int32_t nLeft = 0; |
175 int32_t nRight = m_LineArray.GetSize() - 1; | 175 int32_t nRight = m_LineArray.GetSize() - 1; |
176 int32_t nMid = m_LineArray.GetSize() / 2; | 176 int32_t nMid = m_LineArray.GetSize() / 2; |
177 FX_FLOAT fTop = 0; | 177 FX_FLOAT fTop = 0; |
178 FX_FLOAT fBottom = 0; | 178 FX_FLOAT fBottom = 0; |
179 while (nLeft <= nRight) { | 179 while (nLeft <= nRight) { |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { | 1128 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { |
1129 return pNextSection->GetBeginWordPlace(); | 1129 return pNextSection->GetBeginWordPlace(); |
1130 } | 1130 } |
1131 return GetEndWordPlace(); | 1131 return GetEndWordPlace(); |
1132 } | 1132 } |
1133 return pSection->GetNextWordPlace(place); | 1133 return pSection->GetNextWordPlace(place); |
1134 } | 1134 } |
1135 return place; | 1135 return place; |
1136 } | 1136 } |
1137 CPVT_WordPlace CPDF_VariableText::SearchWordPlace( | 1137 CPVT_WordPlace CPDF_VariableText::SearchWordPlace( |
1138 const CPDF_Point& point) const { | 1138 const CFX_FloatPoint& point) const { |
1139 CPDF_Point pt = OutToIn(point); | 1139 CFX_FloatPoint pt = OutToIn(point); |
1140 CPVT_WordPlace place = GetBeginWordPlace(); | 1140 CPVT_WordPlace place = GetBeginWordPlace(); |
1141 int32_t nLeft = 0; | 1141 int32_t nLeft = 0; |
1142 int32_t nRight = m_SectionArray.GetSize() - 1; | 1142 int32_t nRight = m_SectionArray.GetSize() - 1; |
1143 int32_t nMid = m_SectionArray.GetSize() / 2; | 1143 int32_t nMid = m_SectionArray.GetSize() / 2; |
1144 FX_BOOL bUp = TRUE; | 1144 FX_BOOL bUp = TRUE; |
1145 FX_BOOL bDown = TRUE; | 1145 FX_BOOL bDown = TRUE; |
1146 while (nLeft <= nRight) { | 1146 while (nLeft <= nRight) { |
1147 if (CSection* pSection = m_SectionArray.GetAt(nMid)) { | 1147 if (CSection* pSection = m_SectionArray.GetAt(nMid)) { |
1148 if (IsFloatBigger(pt.y, pSection->m_SecInfo.rcSection.top)) { | 1148 if (IsFloatBigger(pt.y, pSection->m_SecInfo.rcSection.top)) { |
1149 bUp = FALSE; | 1149 bUp = FALSE; |
1150 } | 1150 } |
1151 if (IsFloatBigger(pSection->m_SecInfo.rcSection.bottom, pt.y)) { | 1151 if (IsFloatBigger(pSection->m_SecInfo.rcSection.bottom, pt.y)) { |
1152 bDown = FALSE; | 1152 bDown = FALSE; |
1153 } | 1153 } |
1154 if (IsFloatSmaller(pt.y, pSection->m_SecInfo.rcSection.top)) { | 1154 if (IsFloatSmaller(pt.y, pSection->m_SecInfo.rcSection.top)) { |
1155 nRight = nMid - 1; | 1155 nRight = nMid - 1; |
1156 nMid = (nLeft + nRight) / 2; | 1156 nMid = (nLeft + nRight) / 2; |
1157 continue; | 1157 continue; |
1158 } else if (IsFloatBigger(pt.y, pSection->m_SecInfo.rcSection.bottom)) { | 1158 } else if (IsFloatBigger(pt.y, pSection->m_SecInfo.rcSection.bottom)) { |
1159 nLeft = nMid + 1; | 1159 nLeft = nMid + 1; |
1160 nMid = (nLeft + nRight) / 2; | 1160 nMid = (nLeft + nRight) / 2; |
1161 continue; | 1161 continue; |
1162 } else { | 1162 } else { |
1163 place = pSection->SearchWordPlace( | 1163 place = pSection->SearchWordPlace( |
1164 CPDF_Point(pt.x - pSection->m_SecInfo.rcSection.left, | 1164 CFX_FloatPoint(pt.x - pSection->m_SecInfo.rcSection.left, |
1165 pt.y - pSection->m_SecInfo.rcSection.top)); | 1165 pt.y - pSection->m_SecInfo.rcSection.top)); |
1166 place.nSecIndex = nMid; | 1166 place.nSecIndex = nMid; |
1167 return place; | 1167 return place; |
1168 } | 1168 } |
1169 } else { | 1169 } else { |
1170 break; | 1170 break; |
1171 } | 1171 } |
1172 } | 1172 } |
1173 if (bUp) { | 1173 if (bUp) { |
1174 place = GetBeginWordPlace(); | 1174 place = GetBeginWordPlace(); |
1175 } | 1175 } |
1176 if (bDown) { | 1176 if (bDown) { |
1177 place = GetEndWordPlace(); | 1177 place = GetEndWordPlace(); |
1178 } | 1178 } |
1179 return place; | 1179 return place; |
1180 } | 1180 } |
1181 CPVT_WordPlace CPDF_VariableText::GetUpWordPlace( | 1181 CPVT_WordPlace CPDF_VariableText::GetUpWordPlace( |
1182 const CPVT_WordPlace& place, | 1182 const CPVT_WordPlace& place, |
1183 const CPDF_Point& point) const { | 1183 const CFX_FloatPoint& point) const { |
1184 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 1184 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
1185 CPVT_WordPlace temp = place; | 1185 CPVT_WordPlace temp = place; |
1186 CPDF_Point pt = OutToIn(point); | 1186 CFX_FloatPoint pt = OutToIn(point); |
1187 if (temp.nLineIndex-- > 0) { | 1187 if (temp.nLineIndex-- > 0) { |
1188 return pSection->SearchWordPlace( | 1188 return pSection->SearchWordPlace( |
1189 pt.x - pSection->m_SecInfo.rcSection.left, temp); | 1189 pt.x - pSection->m_SecInfo.rcSection.left, temp); |
1190 } | 1190 } |
1191 if (temp.nSecIndex-- > 0) { | 1191 if (temp.nSecIndex-- > 0) { |
1192 if (CSection* pLastSection = m_SectionArray.GetAt(temp.nSecIndex)) { | 1192 if (CSection* pLastSection = m_SectionArray.GetAt(temp.nSecIndex)) { |
1193 temp.nLineIndex = pLastSection->m_LineArray.GetSize() - 1; | 1193 temp.nLineIndex = pLastSection->m_LineArray.GetSize() - 1; |
1194 return pLastSection->SearchWordPlace( | 1194 return pLastSection->SearchWordPlace( |
1195 pt.x - pLastSection->m_SecInfo.rcSection.left, temp); | 1195 pt.x - pLastSection->m_SecInfo.rcSection.left, temp); |
1196 } | 1196 } |
1197 } | 1197 } |
1198 } | 1198 } |
1199 return place; | 1199 return place; |
1200 } | 1200 } |
1201 CPVT_WordPlace CPDF_VariableText::GetDownWordPlace( | 1201 CPVT_WordPlace CPDF_VariableText::GetDownWordPlace( |
1202 const CPVT_WordPlace& place, | 1202 const CPVT_WordPlace& place, |
1203 const CPDF_Point& point) const { | 1203 const CFX_FloatPoint& point) const { |
1204 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 1204 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
1205 CPVT_WordPlace temp = place; | 1205 CPVT_WordPlace temp = place; |
1206 CPDF_Point pt = OutToIn(point); | 1206 CFX_FloatPoint pt = OutToIn(point); |
1207 if (temp.nLineIndex++ < pSection->m_LineArray.GetSize() - 1) { | 1207 if (temp.nLineIndex++ < pSection->m_LineArray.GetSize() - 1) { |
1208 return pSection->SearchWordPlace( | 1208 return pSection->SearchWordPlace( |
1209 pt.x - pSection->m_SecInfo.rcSection.left, temp); | 1209 pt.x - pSection->m_SecInfo.rcSection.left, temp); |
1210 } | 1210 } |
1211 if (temp.nSecIndex++ < m_SectionArray.GetSize() - 1) { | 1211 if (temp.nSecIndex++ < m_SectionArray.GetSize() - 1) { |
1212 if (CSection* pNextSection = m_SectionArray.GetAt(temp.nSecIndex)) { | 1212 if (CSection* pNextSection = m_SectionArray.GetAt(temp.nSecIndex)) { |
1213 temp.nLineIndex = 0; | 1213 temp.nLineIndex = 0; |
1214 return pNextSection->SearchWordPlace( | 1214 return pNextSection->SearchWordPlace( |
1215 pt.x - pSection->m_SecInfo.rcSection.left, temp); | 1215 pt.x - pSection->m_SecInfo.rcSection.left, temp); |
1216 } | 1216 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1326 return FALSE; | 1326 return FALSE; |
1327 } | 1327 } |
1328 FX_BOOL CPDF_VariableText::GetSectionInfo(const CPVT_WordPlace& place, | 1328 FX_BOOL CPDF_VariableText::GetSectionInfo(const CPVT_WordPlace& place, |
1329 CPVT_SectionInfo& secinfo) { | 1329 CPVT_SectionInfo& secinfo) { |
1330 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 1330 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
1331 secinfo = pSection->m_SecInfo; | 1331 secinfo = pSection->m_SecInfo; |
1332 return TRUE; | 1332 return TRUE; |
1333 } | 1333 } |
1334 return FALSE; | 1334 return FALSE; |
1335 } | 1335 } |
1336 CPDF_Rect CPDF_VariableText::GetContentRect() const { | 1336 CFX_FloatRect CPDF_VariableText::GetContentRect() const { |
1337 return InToOut(CPVT_FloatRect(CPDF_EditContainer::GetContentRect())); | 1337 return InToOut(CPVT_FloatRect(CPDF_EditContainer::GetContentRect())); |
1338 } | 1338 } |
1339 FX_FLOAT CPDF_VariableText::GetWordFontSize(const CPVT_WordInfo& WordInfo, | 1339 FX_FLOAT CPDF_VariableText::GetWordFontSize(const CPVT_WordInfo& WordInfo, |
1340 FX_BOOL bFactFontSize) { | 1340 FX_BOOL bFactFontSize) { |
1341 return m_bRichText && WordInfo.pWordProps | 1341 return m_bRichText && WordInfo.pWordProps |
1342 ? (WordInfo.pWordProps->nScriptType == PVTWORD_SCRIPT_NORMAL || | 1342 ? (WordInfo.pWordProps->nScriptType == PVTWORD_SCRIPT_NORMAL || |
1343 bFactFontSize | 1343 bFactFontSize |
1344 ? WordInfo.pWordProps->fFontSize | 1344 ? WordInfo.pWordProps->fFontSize |
1345 : WordInfo.pWordProps->fFontSize * PVT_HALF) | 1345 : WordInfo.pWordProps->fFontSize * PVT_HALF) |
1346 : GetFontSize(); | 1346 : GetFontSize(); |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1746 FX_BOOL CPDF_VariableText_Iterator::GetWord(CPVT_Word& word) const { | 1746 FX_BOOL CPDF_VariableText_Iterator::GetWord(CPVT_Word& word) const { |
1747 word.WordPlace = m_CurPos; | 1747 word.WordPlace = m_CurPos; |
1748 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | 1748 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
1749 if (pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { | 1749 if (pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { |
1750 if (CPVT_WordInfo* pWord = | 1750 if (CPVT_WordInfo* pWord = |
1751 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) { | 1751 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) { |
1752 word.Word = pWord->Word; | 1752 word.Word = pWord->Word; |
1753 word.nCharset = pWord->nCharset; | 1753 word.nCharset = pWord->nCharset; |
1754 word.fWidth = m_pVT->GetWordWidth(*pWord); | 1754 word.fWidth = m_pVT->GetWordWidth(*pWord); |
1755 word.ptWord = m_pVT->InToOut( | 1755 word.ptWord = m_pVT->InToOut( |
1756 CPDF_Point(pWord->fWordX + pSection->m_SecInfo.rcSection.left, | 1756 CFX_FloatPoint(pWord->fWordX + pSection->m_SecInfo.rcSection.left, |
1757 pWord->fWordY + pSection->m_SecInfo.rcSection.top)); | 1757 pWord->fWordY + pSection->m_SecInfo.rcSection.top)); |
1758 word.fAscent = m_pVT->GetWordAscent(*pWord); | 1758 word.fAscent = m_pVT->GetWordAscent(*pWord); |
1759 word.fDescent = m_pVT->GetWordDescent(*pWord); | 1759 word.fDescent = m_pVT->GetWordDescent(*pWord); |
1760 if (pWord->pWordProps) { | 1760 if (pWord->pWordProps) { |
1761 word.WordProps = *pWord->pWordProps; | 1761 word.WordProps = *pWord->pWordProps; |
1762 } | 1762 } |
1763 word.nFontIndex = m_pVT->GetWordFontIndex(*pWord); | 1763 word.nFontIndex = m_pVT->GetWordFontIndex(*pWord); |
1764 word.fFontSize = m_pVT->GetWordFontSize(*pWord); | 1764 word.fFontSize = m_pVT->GetWordFontSize(*pWord); |
1765 return TRUE; | 1765 return TRUE; |
1766 } | 1766 } |
1767 } | 1767 } |
(...skipping 10 matching lines...) Expand all Loading... |
1778 return TRUE; | 1778 return TRUE; |
1779 } | 1779 } |
1780 } | 1780 } |
1781 return FALSE; | 1781 return FALSE; |
1782 } | 1782 } |
1783 FX_BOOL CPDF_VariableText_Iterator::GetLine(CPVT_Line& line) const { | 1783 FX_BOOL CPDF_VariableText_Iterator::GetLine(CPVT_Line& line) const { |
1784 ASSERT(m_pVT); | 1784 ASSERT(m_pVT); |
1785 line.lineplace = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex, -1); | 1785 line.lineplace = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex, -1); |
1786 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | 1786 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
1787 if (CLine* pLine = pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { | 1787 if (CLine* pLine = pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { |
1788 line.ptLine = m_pVT->InToOut(CPDF_Point( | 1788 line.ptLine = m_pVT->InToOut(CFX_FloatPoint( |
1789 pLine->m_LineInfo.fLineX + pSection->m_SecInfo.rcSection.left, | 1789 pLine->m_LineInfo.fLineX + pSection->m_SecInfo.rcSection.left, |
1790 pLine->m_LineInfo.fLineY + pSection->m_SecInfo.rcSection.top)); | 1790 pLine->m_LineInfo.fLineY + pSection->m_SecInfo.rcSection.top)); |
1791 line.fLineWidth = pLine->m_LineInfo.fLineWidth; | 1791 line.fLineWidth = pLine->m_LineInfo.fLineWidth; |
1792 line.fLineAscent = pLine->m_LineInfo.fLineAscent; | 1792 line.fLineAscent = pLine->m_LineInfo.fLineAscent; |
1793 line.fLineDescent = pLine->m_LineInfo.fLineDescent; | 1793 line.fLineDescent = pLine->m_LineInfo.fLineDescent; |
1794 line.lineEnd = pLine->GetEndWordPlace(); | 1794 line.lineEnd = pLine->GetEndWordPlace(); |
1795 return TRUE; | 1795 return TRUE; |
1796 } | 1796 } |
1797 } | 1797 } |
1798 return FALSE; | 1798 return FALSE; |
(...skipping 17 matching lines...) Expand all Loading... |
1816 if (pSection->m_SecInfo.pSecProps) { | 1816 if (pSection->m_SecInfo.pSecProps) { |
1817 *pSection->m_SecInfo.pSecProps = section.SecProps; | 1817 *pSection->m_SecInfo.pSecProps = section.SecProps; |
1818 } | 1818 } |
1819 if (pSection->m_SecInfo.pWordProps) { | 1819 if (pSection->m_SecInfo.pWordProps) { |
1820 *pSection->m_SecInfo.pWordProps = section.WordProps; | 1820 *pSection->m_SecInfo.pWordProps = section.WordProps; |
1821 } | 1821 } |
1822 return TRUE; | 1822 return TRUE; |
1823 } | 1823 } |
1824 return FALSE; | 1824 return FALSE; |
1825 } | 1825 } |
OLD | NEW |