| 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 "core/fpdfdoc/doc_vt.h" |
| 8 |
| 7 #include <algorithm> | 9 #include <algorithm> |
| 8 | 10 |
| 9 #include "core/fpdfdoc/cpvt_wordinfo.h" | 11 #include "core/fpdfdoc/cpvt_wordinfo.h" |
| 10 #include "core/fpdfdoc/csection.h" | 12 #include "core/fpdfdoc/csection.h" |
| 11 #include "core/fpdfdoc/include/cpdf_variabletext.h" | 13 #include "core/fpdfdoc/include/cpdf_variabletext.h" |
| 12 #include "core/fpdfdoc/include/fpdf_doc.h" | 14 #include "core/fpdfdoc/include/fpdf_doc.h" |
| 13 #include "core/fpdfdoc/pdf_vt.h" | |
| 14 | 15 |
| 15 CLine::CLine() {} | 16 CLine::CLine() {} |
| 17 |
| 16 CLine::~CLine() {} | 18 CLine::~CLine() {} |
| 19 |
| 17 CPVT_WordPlace CLine::GetBeginWordPlace() const { | 20 CPVT_WordPlace CLine::GetBeginWordPlace() const { |
| 18 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, -1); | 21 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, -1); |
| 19 } | 22 } |
| 20 CPVT_WordPlace CLine::GetEndWordPlace() const { | 23 CPVT_WordPlace CLine::GetEndWordPlace() const { |
| 21 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, | 24 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, |
| 22 m_LineInfo.nEndWordIndex); | 25 m_LineInfo.nEndWordIndex); |
| 23 } | 26 } |
| 24 CPVT_WordPlace CLine::GetPrevWordPlace(const CPVT_WordPlace& place) const { | 27 CPVT_WordPlace CLine::GetPrevWordPlace(const CPVT_WordPlace& place) const { |
| 25 if (place.nWordIndex > m_LineInfo.nEndWordIndex) { | 28 if (place.nWordIndex > m_LineInfo.nEndWordIndex) { |
| 26 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, | 29 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 54 } | 57 } |
| 55 m_WordArray.RemoveAll(); | 58 m_WordArray.RemoveAll(); |
| 56 } | 59 } |
| 57 void CSection::ResetLinePlace() { | 60 void CSection::ResetLinePlace() { |
| 58 for (int32_t i = 0, sz = m_LineArray.GetSize(); i < sz; i++) { | 61 for (int32_t i = 0, sz = m_LineArray.GetSize(); i < sz; i++) { |
| 59 if (CLine* pLine = m_LineArray.GetAt(i)) { | 62 if (CLine* pLine = m_LineArray.GetAt(i)) { |
| 60 pLine->LinePlace = CPVT_WordPlace(SecPlace.nSecIndex, i, -1); | 63 pLine->LinePlace = CPVT_WordPlace(SecPlace.nSecIndex, i, -1); |
| 61 } | 64 } |
| 62 } | 65 } |
| 63 } | 66 } |
| 67 |
| 64 CPVT_WordPlace CSection::AddWord(const CPVT_WordPlace& place, | 68 CPVT_WordPlace CSection::AddWord(const CPVT_WordPlace& place, |
| 65 const CPVT_WordInfo& wordinfo) { | 69 const CPVT_WordInfo& wordinfo) { |
| 66 CPVT_WordInfo* pWord = new CPVT_WordInfo(wordinfo); | 70 CPVT_WordInfo* pWord = new CPVT_WordInfo(wordinfo); |
| 67 int32_t nWordIndex = | 71 int32_t nWordIndex = |
| 68 std::max(std::min(place.nWordIndex, m_WordArray.GetSize()), 0); | 72 std::max(std::min(place.nWordIndex, m_WordArray.GetSize()), 0); |
| 69 if (nWordIndex == m_WordArray.GetSize()) { | 73 if (nWordIndex == m_WordArray.GetSize()) |
| 70 m_WordArray.Add(pWord); | 74 m_WordArray.Add(pWord); |
| 71 } else { | 75 else |
| 72 m_WordArray.InsertAt(nWordIndex, pWord); | 76 m_WordArray.InsertAt(nWordIndex, pWord); |
| 77 return place; |
| 78 } |
| 79 |
| 80 CPVT_WordPlace CSection::AddLine(const CPVT_LineInfo& lineinfo) { |
| 81 return CPVT_WordPlace(SecPlace.nSecIndex, m_LineArray.Add(lineinfo), -1); |
| 82 } |
| 83 |
| 84 CPVT_FloatRect CSection::Rearrange() { |
| 85 if (m_pVT->m_nCharArray > 0) |
| 86 return CTypeset(this).CharArray(); |
| 87 return CTypeset(this).Typeset(); |
| 88 } |
| 89 |
| 90 CFX_PointF CSection::GetSectionSize(FX_FLOAT fFontSize) { |
| 91 return CTypeset(this).GetEditSize(fFontSize); |
| 92 } |
| 93 |
| 94 CPVT_WordPlace CSection::GetBeginWordPlace() const { |
| 95 if (CLine* pLine = m_LineArray.GetAt(0)) |
| 96 return pLine->GetBeginWordPlace(); |
| 97 return SecPlace; |
| 98 } |
| 99 |
| 100 CPVT_WordPlace CSection::GetEndWordPlace() const { |
| 101 if (CLine* pLine = m_LineArray.GetAt(m_LineArray.GetSize() - 1)) |
| 102 return pLine->GetEndWordPlace(); |
| 103 return SecPlace; |
| 104 } |
| 105 |
| 106 CPVT_WordPlace CSection::GetPrevWordPlace(const CPVT_WordPlace& place) const { |
| 107 if (place.nLineIndex < 0) |
| 108 return GetBeginWordPlace(); |
| 109 |
| 110 if (place.nLineIndex >= m_LineArray.GetSize()) |
| 111 return GetEndWordPlace(); |
| 112 |
| 113 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { |
| 114 if (place.nWordIndex == pLine->m_LineInfo.nBeginWordIndex) |
| 115 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); |
| 116 |
| 117 if (place.nWordIndex >= pLine->m_LineInfo.nBeginWordIndex) |
| 118 return pLine->GetPrevWordPlace(place); |
| 119 |
| 120 if (CLine* pPrevLine = m_LineArray.GetAt(place.nLineIndex - 1)) |
| 121 return pPrevLine->GetEndWordPlace(); |
| 73 } | 122 } |
| 74 return place; | 123 return place; |
| 75 } | 124 } |
| 76 CPVT_WordPlace CSection::AddLine(const CPVT_LineInfo& lineinfo) { | 125 |
| 77 return CPVT_WordPlace(SecPlace.nSecIndex, m_LineArray.Add(lineinfo), -1); | 126 CPVT_WordPlace CSection::GetNextWordPlace(const CPVT_WordPlace& place) const { |
| 78 } | 127 if (place.nLineIndex < 0) |
| 79 CPVT_FloatRect CSection::Rearrange() { | |
| 80 if (m_pVT->m_nCharArray > 0) { | |
| 81 return CTypeset(this).CharArray(); | |
| 82 } | |
| 83 return CTypeset(this).Typeset(); | |
| 84 } | |
| 85 CPVT_Size CSection::GetSectionSize(FX_FLOAT fFontSize) { | |
| 86 return CTypeset(this).GetEditSize(fFontSize); | |
| 87 } | |
| 88 CPVT_WordPlace CSection::GetBeginWordPlace() const { | |
| 89 if (CLine* pLine = m_LineArray.GetAt(0)) { | |
| 90 return pLine->GetBeginWordPlace(); | |
| 91 } | |
| 92 return SecPlace; | |
| 93 } | |
| 94 CPVT_WordPlace CSection::GetEndWordPlace() const { | |
| 95 if (CLine* pLine = m_LineArray.GetAt(m_LineArray.GetSize() - 1)) { | |
| 96 return pLine->GetEndWordPlace(); | |
| 97 } | |
| 98 return SecPlace; | |
| 99 } | |
| 100 CPVT_WordPlace CSection::GetPrevWordPlace(const CPVT_WordPlace& place) const { | |
| 101 if (place.nLineIndex < 0) { | |
| 102 return GetBeginWordPlace(); | 128 return GetBeginWordPlace(); |
| 103 } | 129 |
| 104 if (place.nLineIndex >= m_LineArray.GetSize()) { | 130 if (place.nLineIndex >= m_LineArray.GetSize()) |
| 105 return GetEndWordPlace(); | 131 return GetEndWordPlace(); |
| 106 } | 132 |
| 107 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { | 133 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { |
| 108 if (place.nWordIndex == pLine->m_LineInfo.nBeginWordIndex) { | 134 if (place.nWordIndex < pLine->m_LineInfo.nEndWordIndex) |
| 109 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); | 135 return pLine->GetNextWordPlace(place); |
| 110 } | 136 |
| 111 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { | 137 if (CLine* pNextLine = m_LineArray.GetAt(place.nLineIndex + 1)) |
| 112 if (CLine* pPrevLine = m_LineArray.GetAt(place.nLineIndex - 1)) { | 138 return pNextLine->GetBeginWordPlace(); |
| 113 return pPrevLine->GetEndWordPlace(); | |
| 114 } | |
| 115 } else { | |
| 116 return pLine->GetPrevWordPlace(place); | |
| 117 } | |
| 118 } | 139 } |
| 119 return place; | 140 return place; |
| 120 } | 141 } |
| 121 CPVT_WordPlace CSection::GetNextWordPlace(const CPVT_WordPlace& place) const { | 142 |
| 122 if (place.nLineIndex < 0) { | |
| 123 return GetBeginWordPlace(); | |
| 124 } | |
| 125 if (place.nLineIndex >= m_LineArray.GetSize()) { | |
| 126 return GetEndWordPlace(); | |
| 127 } | |
| 128 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { | |
| 129 if (place.nWordIndex >= pLine->m_LineInfo.nEndWordIndex) { | |
| 130 if (CLine* pNextLine = m_LineArray.GetAt(place.nLineIndex + 1)) { | |
| 131 return pNextLine->GetBeginWordPlace(); | |
| 132 } | |
| 133 } else { | |
| 134 return pLine->GetNextWordPlace(place); | |
| 135 } | |
| 136 } | |
| 137 return place; | |
| 138 } | |
| 139 void CSection::UpdateWordPlace(CPVT_WordPlace& place) const { | 143 void CSection::UpdateWordPlace(CPVT_WordPlace& place) const { |
| 140 int32_t nLeft = 0; | 144 int32_t nLeft = 0; |
| 141 int32_t nRight = m_LineArray.GetSize() - 1; | 145 int32_t nRight = m_LineArray.GetSize() - 1; |
| 142 int32_t nMid = (nLeft + nRight) / 2; | 146 int32_t nMid = (nLeft + nRight) / 2; |
| 143 while (nLeft <= nRight) { | 147 while (nLeft <= nRight) { |
| 144 if (CLine* pLine = m_LineArray.GetAt(nMid)) { | 148 CLine* pLine = m_LineArray.GetAt(nMid); |
| 145 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { | 149 if (!pLine) |
| 146 nRight = nMid - 1; | 150 return; |
| 147 nMid = (nLeft + nRight) / 2; | 151 |
| 148 } else if (place.nWordIndex > pLine->m_LineInfo.nEndWordIndex) { | 152 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { |
| 149 nLeft = nMid + 1; | 153 nRight = nMid - 1; |
| 150 nMid = (nLeft + nRight) / 2; | 154 nMid = (nLeft + nRight) / 2; |
| 151 } else { | 155 } else if (place.nWordIndex > pLine->m_LineInfo.nEndWordIndex) { |
| 152 place.nLineIndex = nMid; | 156 nLeft = nMid + 1; |
| 153 return; | 157 nMid = (nLeft + nRight) / 2; |
| 154 } | |
| 155 } else { | 158 } else { |
| 156 break; | 159 place.nLineIndex = nMid; |
| 160 return; |
| 157 } | 161 } |
| 158 } | 162 } |
| 159 } | 163 } |
| 164 |
| 160 CPVT_WordPlace CSection::SearchWordPlace(const CFX_FloatPoint& point) const { | 165 CPVT_WordPlace CSection::SearchWordPlace(const CFX_FloatPoint& point) const { |
| 161 ASSERT(m_pVT); | 166 ASSERT(m_pVT); |
| 162 CPVT_WordPlace place = GetBeginWordPlace(); | 167 CPVT_WordPlace place = GetBeginWordPlace(); |
| 163 FX_BOOL bUp = TRUE; | 168 FX_BOOL bUp = TRUE; |
| 164 FX_BOOL bDown = TRUE; | 169 FX_BOOL bDown = TRUE; |
| 165 int32_t nLeft = 0; | 170 int32_t nLeft = 0; |
| 166 int32_t nRight = m_LineArray.GetSize() - 1; | 171 int32_t nRight = m_LineArray.GetSize() - 1; |
| 167 int32_t nMid = m_LineArray.GetSize() / 2; | 172 int32_t nMid = m_LineArray.GetSize() / 2; |
| 168 FX_FLOAT fTop = 0; | 173 FX_FLOAT fTop = 0; |
| 169 FX_FLOAT fBottom = 0; | 174 FX_FLOAT fBottom = 0; |
| 170 while (nLeft <= nRight) { | 175 while (nLeft <= nRight) { |
| 171 if (CLine* pLine = m_LineArray.GetAt(nMid)) { | 176 if (CLine* pLine = m_LineArray.GetAt(nMid)) { |
| 172 fTop = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineAscent - | 177 fTop = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineAscent - |
| 173 m_pVT->GetLineLeading(m_SecInfo); | 178 m_pVT->GetLineLeading(m_SecInfo); |
| 174 fBottom = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineDescent; | 179 fBottom = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineDescent; |
| 175 if (IsFloatBigger(point.y, fTop)) { | 180 if (IsFloatBigger(point.y, fTop)) |
| 176 bUp = FALSE; | 181 bUp = FALSE; |
| 177 } | 182 |
| 178 if (IsFloatSmaller(point.y, fBottom)) { | 183 if (IsFloatSmaller(point.y, fBottom)) |
| 179 bDown = FALSE; | 184 bDown = FALSE; |
| 180 } | 185 |
| 181 if (IsFloatSmaller(point.y, fTop)) { | 186 if (IsFloatSmaller(point.y, fTop)) { |
| 182 nRight = nMid - 1; | 187 nRight = nMid - 1; |
| 183 nMid = (nLeft + nRight) / 2; | 188 nMid = (nLeft + nRight) / 2; |
| 184 continue; | 189 continue; |
| 185 } else if (IsFloatBigger(point.y, fBottom)) { | 190 } |
| 191 if (IsFloatBigger(point.y, fBottom)) { |
| 186 nLeft = nMid + 1; | 192 nLeft = nMid + 1; |
| 187 nMid = (nLeft + nRight) / 2; | 193 nMid = (nLeft + nRight) / 2; |
| 188 continue; | 194 continue; |
| 189 } else { | |
| 190 place = SearchWordPlace( | |
| 191 point.x, | |
| 192 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), | |
| 193 pLine->GetEndWordPlace())); | |
| 194 place.nLineIndex = nMid; | |
| 195 return place; | |
| 196 } | 195 } |
| 196 |
| 197 place = SearchWordPlace( |
| 198 point.x, |
| 199 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), |
| 200 pLine->GetEndWordPlace())); |
| 201 place.nLineIndex = nMid; |
| 202 return place; |
| 197 } | 203 } |
| 198 } | 204 } |
| 199 if (bUp) { | 205 if (bUp) |
| 200 place = GetBeginWordPlace(); | 206 place = GetBeginWordPlace(); |
| 201 } | 207 if (bDown) |
| 202 if (bDown) { | |
| 203 place = GetEndWordPlace(); | 208 place = GetEndWordPlace(); |
| 204 } | |
| 205 return place; | 209 return place; |
| 206 } | 210 } |
| 211 |
| 207 CPVT_WordPlace CSection::SearchWordPlace( | 212 CPVT_WordPlace CSection::SearchWordPlace( |
| 208 FX_FLOAT fx, | 213 FX_FLOAT fx, |
| 209 const CPVT_WordPlace& lineplace) const { | 214 const CPVT_WordPlace& lineplace) const { |
| 210 if (CLine* pLine = m_LineArray.GetAt(lineplace.nLineIndex)) { | 215 CLine* pLine = m_LineArray.GetAt(lineplace.nLineIndex); |
| 211 return SearchWordPlace( | 216 if (!pLine) |
| 212 fx - m_SecInfo.rcSection.left, | 217 return GetBeginWordPlace(); |
| 213 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), | 218 return SearchWordPlace( |
| 214 pLine->GetEndWordPlace())); | 219 fx - m_SecInfo.rcSection.left, |
| 215 } | 220 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), |
| 216 return GetBeginWordPlace(); | 221 pLine->GetEndWordPlace())); |
| 217 } | 222 } |
| 223 |
| 218 CPVT_WordPlace CSection::SearchWordPlace(FX_FLOAT fx, | 224 CPVT_WordPlace CSection::SearchWordPlace(FX_FLOAT fx, |
| 219 const CPVT_WordRange& range) const { | 225 const CPVT_WordRange& range) const { |
| 220 CPVT_WordPlace wordplace = range.BeginPos; | 226 CPVT_WordPlace wordplace = range.BeginPos; |
| 221 wordplace.nWordIndex = -1; | 227 wordplace.nWordIndex = -1; |
| 222 if (!m_pVT) { | 228 if (!m_pVT) |
| 223 return wordplace; | 229 return wordplace; |
| 224 } | 230 |
| 225 int32_t nLeft = range.BeginPos.nWordIndex; | 231 int32_t nLeft = range.BeginPos.nWordIndex; |
| 226 int32_t nRight = range.EndPos.nWordIndex + 1; | 232 int32_t nRight = range.EndPos.nWordIndex + 1; |
| 227 int32_t nMid = (nLeft + nRight) / 2; | 233 int32_t nMid = (nLeft + nRight) / 2; |
| 228 while (nLeft < nRight) { | 234 while (nLeft < nRight) { |
| 229 if (nMid == nLeft) { | 235 if (nMid == nLeft) |
| 230 break; | 236 break; |
| 231 } | 237 |
| 232 if (nMid == nRight) { | 238 if (nMid == nRight) { |
| 233 nMid--; | 239 nMid--; |
| 234 break; | 240 break; |
| 235 } | 241 } |
| 236 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { | 242 |
| 237 if (fx > | 243 CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid); |
| 238 pWord->fWordX + m_pVT->GetWordWidth(*pWord) * VARIABLETEXT_HALF) { | 244 if (!pWord) |
| 239 nLeft = nMid; | |
| 240 nMid = (nLeft + nRight) / 2; | |
| 241 continue; | |
| 242 } else { | |
| 243 nRight = nMid; | |
| 244 nMid = (nLeft + nRight) / 2; | |
| 245 continue; | |
| 246 } | |
| 247 } else { | |
| 248 break; | 245 break; |
| 249 } | 246 |
| 247 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * VARIABLETEXT_HALF) |
| 248 nLeft = nMid; |
| 249 else |
| 250 nRight = nMid; |
| 251 nMid = (nLeft + nRight) / 2; |
| 250 } | 252 } |
| 251 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { | 253 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { |
| 252 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * VARIABLETEXT_HALF) { | 254 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * VARIABLETEXT_HALF) { |
| 253 wordplace.nWordIndex = nMid; | 255 wordplace.nWordIndex = nMid; |
| 254 } | 256 } |
| 255 } | 257 } |
| 256 return wordplace; | 258 return wordplace; |
| 257 } | 259 } |
| 260 |
| 258 void CSection::ClearLeftWords(int32_t nWordIndex) { | 261 void CSection::ClearLeftWords(int32_t nWordIndex) { |
| 259 for (int32_t i = nWordIndex; i >= 0; i--) { | 262 for (int32_t i = nWordIndex; i >= 0; i--) { |
| 260 delete m_WordArray.GetAt(i); | 263 delete m_WordArray.GetAt(i); |
| 261 m_WordArray.RemoveAt(i); | 264 m_WordArray.RemoveAt(i); |
| 262 } | 265 } |
| 263 } | 266 } |
| 267 |
| 264 void CSection::ClearRightWords(int32_t nWordIndex) { | 268 void CSection::ClearRightWords(int32_t nWordIndex) { |
| 265 for (int32_t i = m_WordArray.GetSize() - 1; i > nWordIndex; i--) { | 269 for (int32_t i = m_WordArray.GetSize() - 1; i > nWordIndex; i--) { |
| 266 delete m_WordArray.GetAt(i); | 270 delete m_WordArray.GetAt(i); |
| 267 m_WordArray.RemoveAt(i); | 271 m_WordArray.RemoveAt(i); |
| 268 } | 272 } |
| 269 } | 273 } |
| 274 |
| 270 void CSection::ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex) { | 275 void CSection::ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex) { |
| 271 for (int32_t i = nEndIndex; i > nBeginIndex; i--) { | 276 for (int32_t i = nEndIndex; i > nBeginIndex; i--) { |
| 272 delete m_WordArray.GetAt(i); | 277 delete m_WordArray.GetAt(i); |
| 273 m_WordArray.RemoveAt(i); | 278 m_WordArray.RemoveAt(i); |
| 274 } | 279 } |
| 275 } | 280 } |
| 281 |
| 276 void CSection::ClearWords(const CPVT_WordRange& PlaceRange) { | 282 void CSection::ClearWords(const CPVT_WordRange& PlaceRange) { |
| 277 CPVT_WordPlace SecBeginPos = GetBeginWordPlace(); | 283 CPVT_WordPlace SecBeginPos = GetBeginWordPlace(); |
| 278 CPVT_WordPlace SecEndPos = GetEndWordPlace(); | 284 CPVT_WordPlace SecEndPos = GetEndWordPlace(); |
| 279 if (PlaceRange.BeginPos.WordCmp(SecBeginPos) >= 0) { | 285 if (PlaceRange.BeginPos.WordCmp(SecBeginPos) >= 0) { |
| 280 if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) { | 286 if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) { |
| 281 ClearMidWords(PlaceRange.BeginPos.nWordIndex, | 287 ClearMidWords(PlaceRange.BeginPos.nWordIndex, |
| 282 PlaceRange.EndPos.nWordIndex); | 288 PlaceRange.EndPos.nWordIndex); |
| 283 } else { | 289 } else { |
| 284 ClearRightWords(PlaceRange.BeginPos.nWordIndex); | 290 ClearRightWords(PlaceRange.BeginPos.nWordIndex); |
| 285 } | 291 } |
| 286 } else if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) { | 292 } else if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) { |
| 287 ClearLeftWords(PlaceRange.EndPos.nWordIndex); | 293 ClearLeftWords(PlaceRange.EndPos.nWordIndex); |
| 288 } else { | 294 } else { |
| 289 ResetWordArray(); | 295 ResetWordArray(); |
| 290 } | 296 } |
| 291 } | 297 } |
| 298 |
| 292 void CSection::ClearWord(const CPVT_WordPlace& place) { | 299 void CSection::ClearWord(const CPVT_WordPlace& place) { |
| 293 delete m_WordArray.GetAt(place.nWordIndex); | 300 delete m_WordArray.GetAt(place.nWordIndex); |
| 294 m_WordArray.RemoveAt(place.nWordIndex); | 301 m_WordArray.RemoveAt(place.nWordIndex); |
| 295 } | 302 } |
| 303 |
| 296 CTypeset::CTypeset(CSection* pSection) | 304 CTypeset::CTypeset(CSection* pSection) |
| 297 : m_rcRet(0.0f, 0.0f, 0.0f, 0.0f), | 305 : m_rcRet(0.0f, 0.0f, 0.0f, 0.0f), |
| 298 m_pVT(pSection->m_pVT), | 306 m_pVT(pSection->m_pVT), |
| 299 m_pSection(pSection) {} | 307 m_pSection(pSection) {} |
| 308 |
| 300 CTypeset::~CTypeset() {} | 309 CTypeset::~CTypeset() {} |
| 310 |
| 301 CPVT_FloatRect CTypeset::CharArray() { | 311 CPVT_FloatRect CTypeset::CharArray() { |
| 302 ASSERT(m_pSection); | 312 ASSERT(m_pSection); |
| 303 FX_FLOAT fLineAscent = | 313 FX_FLOAT fLineAscent = |
| 304 m_pVT->GetFontAscent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize()); | 314 m_pVT->GetFontAscent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize()); |
| 305 FX_FLOAT fLineDescent = | 315 FX_FLOAT fLineDescent = |
| 306 m_pVT->GetFontDescent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize()); | 316 m_pVT->GetFontDescent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize()); |
| 307 m_rcRet.Default(); | 317 m_rcRet.Default(); |
| 308 FX_FLOAT x = 0.0f, y = 0.0f; | 318 FX_FLOAT x = 0.0f, y = 0.0f; |
| 309 FX_FLOAT fNextWidth; | 319 FX_FLOAT fNextWidth; |
| 310 int32_t nStart = 0; | 320 int32_t nStart = 0; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 pLine->m_LineInfo.nBeginWordIndex = 0; | 379 pLine->m_LineInfo.nBeginWordIndex = 0; |
| 370 pLine->m_LineInfo.nEndWordIndex = m_pSection->m_WordArray.GetSize() - 1; | 380 pLine->m_LineInfo.nEndWordIndex = m_pSection->m_WordArray.GetSize() - 1; |
| 371 pLine->m_LineInfo.fLineY = y; | 381 pLine->m_LineInfo.fLineY = y; |
| 372 pLine->m_LineInfo.fLineWidth = x - pLine->m_LineInfo.fLineX; | 382 pLine->m_LineInfo.fLineWidth = x - pLine->m_LineInfo.fLineX; |
| 373 pLine->m_LineInfo.fLineAscent = fLineAscent; | 383 pLine->m_LineInfo.fLineAscent = fLineAscent; |
| 374 pLine->m_LineInfo.fLineDescent = fLineDescent; | 384 pLine->m_LineInfo.fLineDescent = fLineDescent; |
| 375 y -= fLineDescent; | 385 y -= fLineDescent; |
| 376 } | 386 } |
| 377 return m_rcRet = CPVT_FloatRect(0, 0, x, y); | 387 return m_rcRet = CPVT_FloatRect(0, 0, x, y); |
| 378 } | 388 } |
| 379 CPVT_Size CTypeset::GetEditSize(FX_FLOAT fFontSize) { | 389 |
| 390 CFX_PointF CTypeset::GetEditSize(FX_FLOAT fFontSize) { |
| 380 ASSERT(m_pSection); | 391 ASSERT(m_pSection); |
| 381 ASSERT(m_pVT); | 392 ASSERT(m_pVT); |
| 382 SplitLines(FALSE, fFontSize); | 393 SplitLines(FALSE, fFontSize); |
| 383 return CPVT_Size(m_rcRet.Width(), m_rcRet.Height()); | 394 return CFX_PointF(m_rcRet.Width(), m_rcRet.Height()); |
| 384 } | 395 } |
| 396 |
| 385 CPVT_FloatRect CTypeset::Typeset() { | 397 CPVT_FloatRect CTypeset::Typeset() { |
| 386 ASSERT(m_pVT); | 398 ASSERT(m_pVT); |
| 387 m_pSection->m_LineArray.Empty(); | 399 m_pSection->m_LineArray.Empty(); |
| 388 SplitLines(TRUE, 0.0f); | 400 SplitLines(TRUE, 0.0f); |
| 389 m_pSection->m_LineArray.Clear(); | 401 m_pSection->m_LineArray.Clear(); |
| 390 OutputLines(); | 402 OutputLines(); |
| 391 return m_rcRet; | 403 return m_rcRet; |
| 392 } | 404 } |
| 393 | 405 |
| 394 static const uint8_t special_chars[128] = { | 406 static const uint8_t special_chars[128] = { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 line.fLineWidth = 0; | 698 line.fLineWidth = 0; |
| 687 line.fLineAscent = fLineAscent; | 699 line.fLineAscent = fLineAscent; |
| 688 line.fLineDescent = fLineDescent; | 700 line.fLineDescent = fLineDescent; |
| 689 m_pSection->AddLine(line); | 701 m_pSection->AddLine(line); |
| 690 } | 702 } |
| 691 fMaxY += m_pVT->GetLineLeading(m_pSection->m_SecInfo) + fLineAscent - | 703 fMaxY += m_pVT->GetLineLeading(m_pSection->m_SecInfo) + fLineAscent - |
| 692 fLineDescent; | 704 fLineDescent; |
| 693 } | 705 } |
| 694 m_rcRet = CPVT_FloatRect(0, 0, fMaxX, fMaxY); | 706 m_rcRet = CPVT_FloatRect(0, 0, fMaxX, fMaxY); |
| 695 } | 707 } |
| 708 |
| 696 void CTypeset::OutputLines() { | 709 void CTypeset::OutputLines() { |
| 697 ASSERT(m_pVT); | |
| 698 ASSERT(m_pSection); | |
| 699 FX_FLOAT fMinX = 0.0f, fMinY = 0.0f, fMaxX = 0.0f, fMaxY = 0.0f; | |
| 700 FX_FLOAT fPosX = 0.0f, fPosY = 0.0f; | |
| 701 FX_FLOAT fLineIndent = m_pVT->GetLineIndent(m_pSection->m_SecInfo); | 710 FX_FLOAT fLineIndent = m_pVT->GetLineIndent(m_pSection->m_SecInfo); |
| 702 FX_FLOAT fTypesetWidth = std::max(m_pVT->GetPlateWidth() - fLineIndent, 0.0f); | 711 FX_FLOAT fTypesetWidth = std::max(m_pVT->GetPlateWidth() - fLineIndent, 0.0f); |
| 712 FX_FLOAT fMinX = GetXPosForAlignment(fTypesetWidth, m_rcRet.Width()); |
| 713 FX_FLOAT fMinY = 0.0f; |
| 714 FX_FLOAT fMaxX = fMinX + m_rcRet.Width(); |
| 715 FX_FLOAT fMaxY = m_rcRet.Height(); |
| 716 |
| 717 int32_t nTotalLines = m_pSection->m_LineArray.GetSize(); |
| 718 if (nTotalLines <= 0) { |
| 719 m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY); |
| 720 return; |
| 721 } |
| 722 |
| 723 FX_FLOAT fPosX = 0.0f; |
| 724 FX_FLOAT fPosY = 0.0f; |
| 725 m_pSection->m_SecInfo.nTotalLine = nTotalLines; |
| 726 for (int32_t l = 0; l < nTotalLines; l++) { |
| 727 CLine* pLine = m_pSection->m_LineArray.GetAt(l); |
| 728 if (!pLine) |
| 729 continue; |
| 730 |
| 731 fPosX = GetXPosForAlignment(fTypesetWidth, pLine->m_LineInfo.fLineWidth); |
| 732 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { |
| 733 default: |
| 734 case 0: |
| 735 fPosX = 0; |
| 736 break; |
| 737 case 1: |
| 738 fPosX = |
| 739 (fTypesetWidth - pLine->m_LineInfo.fLineWidth) * VARIABLETEXT_HALF; |
| 740 break; |
| 741 case 2: |
| 742 fPosX = fTypesetWidth - pLine->m_LineInfo.fLineWidth; |
| 743 break; |
| 744 } |
| 745 fPosX += fLineIndent; |
| 746 fPosY += m_pVT->GetLineLeading(m_pSection->m_SecInfo); |
| 747 fPosY += pLine->m_LineInfo.fLineAscent; |
| 748 pLine->m_LineInfo.fLineX = fPosX - fMinX; |
| 749 pLine->m_LineInfo.fLineY = fPosY - fMinY; |
| 750 for (int32_t w = pLine->m_LineInfo.nBeginWordIndex; |
| 751 w <= pLine->m_LineInfo.nEndWordIndex; w++) { |
| 752 if (w < 0 || w >= m_pSection->m_WordArray.GetSize()) |
| 753 continue; |
| 754 |
| 755 CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(w); |
| 756 if (!pWord) |
| 757 continue; |
| 758 |
| 759 pWord->fWordX = fPosX - fMinX; |
| 760 if (pWord->pWordProps) { |
| 761 switch (pWord->pWordProps->nScriptType) { |
| 762 default: |
| 763 case CPDF_VariableText::ScriptType::Normal: |
| 764 pWord->fWordY = fPosY - fMinY; |
| 765 break; |
| 766 case CPDF_VariableText::ScriptType::Super: |
| 767 pWord->fWordY = fPosY - m_pVT->GetWordAscent(*pWord) - fMinY; |
| 768 break; |
| 769 case CPDF_VariableText::ScriptType::Sub: |
| 770 pWord->fWordY = fPosY - m_pVT->GetWordDescent(*pWord) - fMinY; |
| 771 break; |
| 772 } |
| 773 } else { |
| 774 pWord->fWordY = fPosY - fMinY; |
| 775 } |
| 776 fPosX += m_pVT->GetWordWidth(*pWord); |
| 777 } |
| 778 fPosY -= pLine->m_LineInfo.fLineDescent; |
| 779 } |
| 780 m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY); |
| 781 } |
| 782 |
| 783 FX_FLOAT CTypeset::GetXPosForAlignment(FX_FLOAT fTypesetWidth, |
| 784 FX_FLOAT fLineWidth) const { |
| 703 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { | 785 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { |
| 704 default: | 786 default: |
| 705 case 0: | 787 case 0: |
| 706 fMinX = 0.0f; | 788 return 0; |
| 707 break; | |
| 708 case 1: | 789 case 1: |
| 709 fMinX = (fTypesetWidth - m_rcRet.Width()) * VARIABLETEXT_HALF; | 790 return (fTypesetWidth - fLineWidth) * VARIABLETEXT_HALF; |
| 710 break; | |
| 711 case 2: | 791 case 2: |
| 712 fMinX = fTypesetWidth - m_rcRet.Width(); | 792 return fTypesetWidth - fLineWidth; |
| 713 break; | |
| 714 } | 793 } |
| 715 fMaxX = fMinX + m_rcRet.Width(); | |
| 716 fMinY = 0.0f; | |
| 717 fMaxY = m_rcRet.Height(); | |
| 718 int32_t nTotalLines = m_pSection->m_LineArray.GetSize(); | |
| 719 if (nTotalLines > 0) { | |
| 720 m_pSection->m_SecInfo.nTotalLine = nTotalLines; | |
| 721 for (int32_t l = 0; l < nTotalLines; l++) { | |
| 722 if (CLine* pLine = m_pSection->m_LineArray.GetAt(l)) { | |
| 723 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { | |
| 724 default: | |
| 725 case 0: | |
| 726 fPosX = 0; | |
| 727 break; | |
| 728 case 1: | |
| 729 fPosX = (fTypesetWidth - pLine->m_LineInfo.fLineWidth) * | |
| 730 VARIABLETEXT_HALF; | |
| 731 break; | |
| 732 case 2: | |
| 733 fPosX = fTypesetWidth - pLine->m_LineInfo.fLineWidth; | |
| 734 break; | |
| 735 } | |
| 736 fPosX += fLineIndent; | |
| 737 fPosY += m_pVT->GetLineLeading(m_pSection->m_SecInfo); | |
| 738 fPosY += pLine->m_LineInfo.fLineAscent; | |
| 739 pLine->m_LineInfo.fLineX = fPosX - fMinX; | |
| 740 pLine->m_LineInfo.fLineY = fPosY - fMinY; | |
| 741 for (int32_t w = pLine->m_LineInfo.nBeginWordIndex; | |
| 742 w <= pLine->m_LineInfo.nEndWordIndex; w++) { | |
| 743 if (CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(w)) { | |
| 744 pWord->fWordX = fPosX - fMinX; | |
| 745 if (pWord->pWordProps) { | |
| 746 switch (pWord->pWordProps->nScriptType) { | |
| 747 default: | |
| 748 case CPDF_VariableText::ScriptType::Normal: | |
| 749 pWord->fWordY = fPosY - fMinY; | |
| 750 break; | |
| 751 case CPDF_VariableText::ScriptType::Super: | |
| 752 pWord->fWordY = fPosY - m_pVT->GetWordAscent(*pWord) - fMinY; | |
| 753 break; | |
| 754 case CPDF_VariableText::ScriptType::Sub: | |
| 755 pWord->fWordY = fPosY - m_pVT->GetWordDescent(*pWord) - fMinY; | |
| 756 break; | |
| 757 } | |
| 758 } else { | |
| 759 pWord->fWordY = fPosY - fMinY; | |
| 760 } | |
| 761 fPosX += m_pVT->GetWordWidth(*pWord); | |
| 762 } | |
| 763 } | |
| 764 fPosY -= pLine->m_LineInfo.fLineDescent; | |
| 765 } | |
| 766 } | |
| 767 } | |
| 768 m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY); | |
| 769 } | 794 } |
| 795 |
| 796 CPDF_EditContainer::CPDF_EditContainer() |
| 797 : m_rcPlate(0, 0, 0, 0), m_rcContent(0, 0, 0, 0) {} |
| 798 |
| 799 CPDF_EditContainer::~CPDF_EditContainer() {} |
| 800 |
| 801 CFX_FloatRect CPDF_EditContainer::InToOut(const CPVT_FloatRect& rect) const { |
| 802 CFX_FloatPoint ptLeftTop = InToOut(CFX_FloatPoint(rect.left, rect.top)); |
| 803 CFX_FloatPoint ptRightBottom = |
| 804 InToOut(CFX_FloatPoint(rect.right, rect.bottom)); |
| 805 return CFX_FloatRect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x, |
| 806 ptLeftTop.y); |
| 807 } |
| OLD | NEW |