| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| 8 | 8 #include "core/fpdfdoc/cpvt_wordinfo.h" |
| 9 #include "core/fpdfdoc/pdf_vt.h" | 9 #include "core/fpdfdoc/csection.h" |
| 10 #include "core/include/fpdfdoc/fpdf_doc.h" | 10 #include "core/fpdfdoc/include/cpdf_variabletext.h" |
| 11 #include "core/include/fpdfdoc/fpdf_vt.h" | 11 #include "core/fpdfdoc/include/cpvt_section.h" |
| 12 #include "core/include/fpdfdoc/fpdf_vt.h" | 12 #include "core/fpdfdoc/include/cpvt_word.h" |
| 13 #include "core/fpdfdoc/include/ipvt_fontmap.h" |
| 14 |
| 15 namespace { |
| 16 |
| 17 const float kDefaultFontSize = 18.0f; |
| 18 const float kFontScale = 0.001f; |
| 19 const uint8_t kReturnLength = 1; |
| 20 const float kScalePercent = 0.01f; |
| 13 | 21 |
| 14 const uint8_t gFontSizeSteps[] = {4, 6, 8, 9, 10, 12, 14, 18, 20, | 22 const uint8_t gFontSizeSteps[] = {4, 6, 8, 9, 10, 12, 14, 18, 20, |
| 15 25, 30, 35, 40, 45, 50, 55, 60, 70, | 23 25, 30, 35, 40, 45, 50, 55, 60, 70, |
| 16 80, 90, 100, 110, 120, 130, 144}; | 24 80, 90, 100, 110, 120, 130, 144}; |
| 17 #define PVT_RETURN_LENGTH 1 | 25 |
| 18 #define PVT_DEFAULT_FONTSIZE 18.0f | 26 } // namespace |
| 19 #define PVTWORD_SCRIPT_NORMAL 0 | 27 |
| 20 #define PVTWORD_SCRIPT_SUPER 1 | 28 CPDF_VariableText::Provider::Provider(IPVT_FontMap* pFontMap) |
| 21 #define PVTWORD_SCRIPT_SUB 2 | 29 : m_pFontMap(pFontMap) { |
| 22 #define PVT_FONTSCALE 0.001f | 30 ASSERT(m_pFontMap); |
| 23 #define PVT_PERCENT 0.01f | 31 } |
| 24 #define PVT_HALF 0.5f | 32 |
| 25 CLine::CLine() {} | 33 CPDF_VariableText::Provider::~Provider() {} |
| 26 CLine::~CLine() {} | 34 |
| 27 CPVT_WordPlace CLine::GetBeginWordPlace() const { | 35 int32_t CPDF_VariableText::Provider::GetCharWidth(int32_t nFontIndex, |
| 28 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, -1); | 36 uint16_t word, |
| 29 } | 37 int32_t nWordStyle) { |
| 30 CPVT_WordPlace CLine::GetEndWordPlace() const { | 38 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
| 31 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, | 39 uint32_t charcode = pPDFFont->CharCodeFromUnicode(word); |
| 32 m_LineInfo.nEndWordIndex); | 40 if (charcode != CPDF_Font::kInvalidCharCode) |
| 33 } | 41 return pPDFFont->GetCharWidthF(charcode); |
| 34 CPVT_WordPlace CLine::GetPrevWordPlace(const CPVT_WordPlace& place) const { | 42 } |
| 35 if (place.nWordIndex > m_LineInfo.nEndWordIndex) { | 43 return 0; |
| 36 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, | 44 } |
| 37 m_LineInfo.nEndWordIndex); | 45 |
| 38 } | 46 int32_t CPDF_VariableText::Provider::GetTypeAscent(int32_t nFontIndex) { |
| 39 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, | 47 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) |
| 40 place.nWordIndex - 1); | 48 return pPDFFont->GetTypeAscent(); |
| 41 } | 49 return 0; |
| 42 CPVT_WordPlace CLine::GetNextWordPlace(const CPVT_WordPlace& place) const { | 50 } |
| 43 if (place.nWordIndex < m_LineInfo.nBeginWordIndex) { | 51 |
| 44 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, | 52 int32_t CPDF_VariableText::Provider::GetTypeDescent(int32_t nFontIndex) { |
| 45 m_LineInfo.nBeginWordIndex); | 53 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) |
| 46 } | 54 return pPDFFont->GetTypeDescent(); |
| 47 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, | 55 return 0; |
| 48 place.nWordIndex + 1); | 56 } |
| 49 } | 57 |
| 50 CSection::CSection(CPDF_VariableText* pVT) : m_pVT(pVT) {} | 58 int32_t CPDF_VariableText::Provider::GetWordFontIndex(uint16_t word, |
| 51 CSection::~CSection() { | 59 int32_t charset, |
| 52 ResetAll(); | 60 int32_t nFontIndex) { |
| 53 } | 61 if (CPDF_Font* pDefFont = m_pFontMap->GetPDFFont(0)) { |
| 54 void CSection::ResetAll() { | 62 if (pDefFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode) |
| 55 ResetWordArray(); | 63 return 0; |
| 56 ResetLineArray(); | 64 } |
| 57 } | 65 if (CPDF_Font* pSysFont = m_pFontMap->GetPDFFont(1)) { |
| 58 void CSection::ResetLineArray() { | 66 if (pSysFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode) |
| 59 m_LineArray.RemoveAll(); | 67 return 1; |
| 60 } | 68 } |
| 61 void CSection::ResetWordArray() { | 69 return -1; |
| 62 for (int32_t i = 0, sz = m_WordArray.GetSize(); i < sz; i++) { | 70 } |
| 63 delete m_WordArray.GetAt(i); | 71 |
| 64 } | 72 FX_BOOL CPDF_VariableText::Provider::IsLatinWord(uint16_t word) { |
| 65 m_WordArray.RemoveAll(); | 73 if ((word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) || |
| 66 } | 74 word == 0x2D || word == 0x27) { |
| 67 void CSection::ResetLinePlace() { | 75 return TRUE; |
| 68 for (int32_t i = 0, sz = m_LineArray.GetSize(); i < sz; i++) { | 76 } |
| 69 if (CLine* pLine = m_LineArray.GetAt(i)) { | 77 return FALSE; |
| 70 pLine->LinePlace = CPVT_WordPlace(SecPlace.nSecIndex, i, -1); | 78 } |
| 71 } | 79 |
| 72 } | 80 int32_t CPDF_VariableText::Provider::GetDefaultFontIndex() { |
| 73 } | 81 return 0; |
| 74 CPVT_WordPlace CSection::AddWord(const CPVT_WordPlace& place, | 82 } |
| 75 const CPVT_WordInfo& wordinfo) { | 83 |
| 76 CPVT_WordInfo* pWord = new CPVT_WordInfo(wordinfo); | 84 CPDF_VariableText::Iterator::Iterator(CPDF_VariableText* pVT) |
| 77 int32_t nWordIndex = | 85 : m_CurPos(-1, -1, -1), m_pVT(pVT) {} |
| 78 std::max(std::min(place.nWordIndex, m_WordArray.GetSize()), 0); | 86 |
| 79 if (nWordIndex == m_WordArray.GetSize()) { | 87 CPDF_VariableText::Iterator::~Iterator() {} |
| 80 m_WordArray.Add(pWord); | 88 |
| 81 } else { | 89 void CPDF_VariableText::Iterator::SetAt(int32_t nWordIndex) { |
| 82 m_WordArray.InsertAt(nWordIndex, pWord); | 90 m_CurPos = m_pVT->WordIndexToWordPlace(nWordIndex); |
| 83 } | 91 } |
| 84 return place; | 92 |
| 85 } | 93 void CPDF_VariableText::Iterator::SetAt(const CPVT_WordPlace& place) { |
| 86 CPVT_WordPlace CSection::AddLine(const CPVT_LineInfo& lineinfo) { | 94 ASSERT(m_pVT); |
| 87 return CPVT_WordPlace(SecPlace.nSecIndex, m_LineArray.Add(lineinfo), -1); | 95 m_CurPos = place; |
| 88 } | 96 } |
| 89 CPVT_FloatRect CSection::Rearrange() { | 97 |
| 90 if (m_pVT->m_nCharArray > 0) { | 98 FX_BOOL CPDF_VariableText::Iterator::NextWord() { |
| 91 return CTypeset(this).CharArray(); | 99 if (m_CurPos == m_pVT->GetEndWordPlace()) |
| 92 } | 100 return FALSE; |
| 93 return CTypeset(this).Typeset(); | 101 |
| 94 } | 102 m_CurPos = m_pVT->GetNextWordPlace(m_CurPos); |
| 95 CPVT_Size CSection::GetSectionSize(FX_FLOAT fFontSize) { | 103 return TRUE; |
| 96 return CTypeset(this).GetEditSize(fFontSize); | 104 } |
| 97 } | 105 |
| 98 CPVT_WordPlace CSection::GetBeginWordPlace() const { | 106 FX_BOOL CPDF_VariableText::Iterator::PrevWord() { |
| 99 if (CLine* pLine = m_LineArray.GetAt(0)) { | 107 if (m_CurPos == m_pVT->GetBeginWordPlace()) |
| 100 return pLine->GetBeginWordPlace(); | 108 return FALSE; |
| 101 } | 109 |
| 102 return SecPlace; | 110 m_CurPos = m_pVT->GetPrevWordPlace(m_CurPos); |
| 103 } | 111 return TRUE; |
| 104 CPVT_WordPlace CSection::GetEndWordPlace() const { | 112 } |
| 105 if (CLine* pLine = m_LineArray.GetAt(m_LineArray.GetSize() - 1)) { | 113 |
| 106 return pLine->GetEndWordPlace(); | 114 FX_BOOL CPDF_VariableText::Iterator::NextLine() { |
| 107 } | 115 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 108 return SecPlace; | 116 if (m_CurPos.nLineIndex < pSection->m_LineArray.GetSize() - 1) { |
| 109 } | 117 m_CurPos = |
| 110 CPVT_WordPlace CSection::GetPrevWordPlace(const CPVT_WordPlace& place) const { | 118 CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex + 1, -1); |
| 111 if (place.nLineIndex < 0) { | 119 return TRUE; |
| 112 return GetBeginWordPlace(); | 120 } |
| 113 } | 121 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) { |
| 114 if (place.nLineIndex >= m_LineArray.GetSize()) { | 122 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1); |
| 115 return GetEndWordPlace(); | 123 return TRUE; |
| 116 } | 124 } |
| 117 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { | 125 } |
| 118 if (place.nWordIndex == pLine->m_LineInfo.nBeginWordIndex) { | 126 return FALSE; |
| 119 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); | 127 } |
| 120 } | 128 |
| 121 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { | 129 FX_BOOL CPDF_VariableText::Iterator::PrevLine() { |
| 122 if (CLine* pPrevLine = m_LineArray.GetAt(place.nLineIndex - 1)) { | 130 if (m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 123 return pPrevLine->GetEndWordPlace(); | 131 if (m_CurPos.nLineIndex > 0) { |
| 132 m_CurPos = |
| 133 CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex - 1, -1); |
| 134 return TRUE; |
| 135 } |
| 136 if (m_CurPos.nSecIndex > 0) { |
| 137 if (CSection* pLastSection = |
| 138 m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex - 1)) { |
| 139 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, |
| 140 pLastSection->m_LineArray.GetSize() - 1, -1); |
| 141 return TRUE; |
| 124 } | 142 } |
| 125 } else { | 143 } |
| 126 return pLine->GetPrevWordPlace(place); | 144 } |
| 127 } | 145 return FALSE; |
| 128 } | 146 } |
| 129 return place; | 147 |
| 130 } | 148 FX_BOOL CPDF_VariableText::Iterator::NextSection() { |
| 131 CPVT_WordPlace CSection::GetNextWordPlace(const CPVT_WordPlace& place) const { | 149 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) { |
| 132 if (place.nLineIndex < 0) { | 150 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1); |
| 133 return GetBeginWordPlace(); | 151 return TRUE; |
| 134 } | 152 } |
| 135 if (place.nLineIndex >= m_LineArray.GetSize()) { | 153 return FALSE; |
| 136 return GetEndWordPlace(); | 154 } |
| 137 } | 155 |
| 138 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { | 156 FX_BOOL CPDF_VariableText::Iterator::PrevSection() { |
| 139 if (place.nWordIndex >= pLine->m_LineInfo.nEndWordIndex) { | 157 ASSERT(m_pVT); |
| 140 if (CLine* pNextLine = m_LineArray.GetAt(place.nLineIndex + 1)) { | 158 if (m_CurPos.nSecIndex > 0) { |
| 141 return pNextLine->GetBeginWordPlace(); | 159 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, 0, -1); |
| 160 return TRUE; |
| 161 } |
| 162 return FALSE; |
| 163 } |
| 164 |
| 165 FX_BOOL CPDF_VariableText::Iterator::GetWord(CPVT_Word& word) const { |
| 166 word.WordPlace = m_CurPos; |
| 167 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 168 if (pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { |
| 169 if (CPVT_WordInfo* pWord = |
| 170 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) { |
| 171 word.Word = pWord->Word; |
| 172 word.nCharset = pWord->nCharset; |
| 173 word.fWidth = m_pVT->GetWordWidth(*pWord); |
| 174 word.ptWord = m_pVT->InToOut( |
| 175 CFX_FloatPoint(pWord->fWordX + pSection->m_SecInfo.rcSection.left, |
| 176 pWord->fWordY + pSection->m_SecInfo.rcSection.top)); |
| 177 word.fAscent = m_pVT->GetWordAscent(*pWord); |
| 178 word.fDescent = m_pVT->GetWordDescent(*pWord); |
| 179 if (pWord->pWordProps) |
| 180 word.WordProps = *pWord->pWordProps; |
| 181 |
| 182 word.nFontIndex = m_pVT->GetWordFontIndex(*pWord); |
| 183 word.fFontSize = m_pVT->GetWordFontSize(*pWord); |
| 184 return TRUE; |
| 142 } | 185 } |
| 143 } else { | 186 } |
| 144 return pLine->GetNextWordPlace(place); | 187 } |
| 145 } | 188 return FALSE; |
| 146 } | 189 } |
| 147 return place; | 190 |
| 148 } | 191 FX_BOOL CPDF_VariableText::Iterator::SetWord(const CPVT_Word& word) { |
| 149 void CSection::UpdateWordPlace(CPVT_WordPlace& place) const { | 192 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 150 int32_t nLeft = 0; | 193 if (CPVT_WordInfo* pWord = |
| 151 int32_t nRight = m_LineArray.GetSize() - 1; | 194 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) { |
| 152 int32_t nMid = (nLeft + nRight) / 2; | 195 if (pWord->pWordProps) |
| 153 while (nLeft <= nRight) { | 196 *pWord->pWordProps = word.WordProps; |
| 154 if (CLine* pLine = m_LineArray.GetAt(nMid)) { | 197 return TRUE; |
| 155 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { | 198 } |
| 156 nRight = nMid - 1; | 199 } |
| 157 nMid = (nLeft + nRight) / 2; | 200 return FALSE; |
| 158 } else if (place.nWordIndex > pLine->m_LineInfo.nEndWordIndex) { | 201 } |
| 159 nLeft = nMid + 1; | 202 |
| 160 nMid = (nLeft + nRight) / 2; | 203 FX_BOOL CPDF_VariableText::Iterator::GetLine(CPVT_Line& line) const { |
| 161 } else { | |
| 162 place.nLineIndex = nMid; | |
| 163 return; | |
| 164 } | |
| 165 } else { | |
| 166 break; | |
| 167 } | |
| 168 } | |
| 169 } | |
| 170 CPVT_WordPlace CSection::SearchWordPlace(const CFX_FloatPoint& point) const { | |
| 171 ASSERT(m_pVT); | 204 ASSERT(m_pVT); |
| 172 CPVT_WordPlace place = GetBeginWordPlace(); | 205 line.lineplace = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex, -1); |
| 173 FX_BOOL bUp = TRUE; | 206 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 174 FX_BOOL bDown = TRUE; | 207 if (CLine* pLine = pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { |
| 175 int32_t nLeft = 0; | 208 line.ptLine = m_pVT->InToOut(CFX_FloatPoint( |
| 176 int32_t nRight = m_LineArray.GetSize() - 1; | 209 pLine->m_LineInfo.fLineX + pSection->m_SecInfo.rcSection.left, |
| 177 int32_t nMid = m_LineArray.GetSize() / 2; | 210 pLine->m_LineInfo.fLineY + pSection->m_SecInfo.rcSection.top)); |
| 178 FX_FLOAT fTop = 0; | 211 line.fLineWidth = pLine->m_LineInfo.fLineWidth; |
| 179 FX_FLOAT fBottom = 0; | 212 line.fLineAscent = pLine->m_LineInfo.fLineAscent; |
| 180 while (nLeft <= nRight) { | 213 line.fLineDescent = pLine->m_LineInfo.fLineDescent; |
| 181 if (CLine* pLine = m_LineArray.GetAt(nMid)) { | 214 line.lineEnd = pLine->GetEndWordPlace(); |
| 182 fTop = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineAscent - | 215 return TRUE; |
| 183 m_pVT->GetLineLeading(m_SecInfo); | 216 } |
| 184 fBottom = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineDescent; | 217 } |
| 185 if (IsFloatBigger(point.y, fTop)) { | 218 return FALSE; |
| 186 bUp = FALSE; | 219 } |
| 187 } | 220 |
| 188 if (IsFloatSmaller(point.y, fBottom)) { | 221 FX_BOOL CPDF_VariableText::Iterator::GetSection(CPVT_Section& section) const { |
| 189 bDown = FALSE; | 222 section.secplace = CPVT_WordPlace(m_CurPos.nSecIndex, 0, -1); |
| 190 } | 223 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 191 if (IsFloatSmaller(point.y, fTop)) { | 224 section.rcSection = m_pVT->InToOut(pSection->m_SecInfo.rcSection); |
| 192 nRight = nMid - 1; | 225 if (pSection->m_SecInfo.pSecProps) |
| 193 nMid = (nLeft + nRight) / 2; | 226 section.SecProps = *pSection->m_SecInfo.pSecProps; |
| 194 continue; | 227 if (pSection->m_SecInfo.pWordProps) |
| 195 } else if (IsFloatBigger(point.y, fBottom)) { | 228 section.WordProps = *pSection->m_SecInfo.pWordProps; |
| 196 nLeft = nMid + 1; | 229 return TRUE; |
| 197 nMid = (nLeft + nRight) / 2; | 230 } |
| 198 continue; | 231 return FALSE; |
| 199 } else { | 232 } |
| 200 place = SearchWordPlace( | 233 |
| 201 point.x, | 234 FX_BOOL CPDF_VariableText::Iterator::SetSection(const CPVT_Section& section) { |
| 202 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), | 235 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 203 pLine->GetEndWordPlace())); | 236 if (pSection->m_SecInfo.pSecProps) |
| 204 place.nLineIndex = nMid; | 237 *pSection->m_SecInfo.pSecProps = section.SecProps; |
| 205 return place; | 238 if (pSection->m_SecInfo.pWordProps) |
| 206 } | 239 *pSection->m_SecInfo.pWordProps = section.WordProps; |
| 207 } | 240 return TRUE; |
| 208 } | 241 } |
| 209 if (bUp) { | 242 return FALSE; |
| 210 place = GetBeginWordPlace(); | 243 } |
| 211 } | 244 |
| 212 if (bDown) { | |
| 213 place = GetEndWordPlace(); | |
| 214 } | |
| 215 return place; | |
| 216 } | |
| 217 CPVT_WordPlace CSection::SearchWordPlace( | |
| 218 FX_FLOAT fx, | |
| 219 const CPVT_WordPlace& lineplace) const { | |
| 220 if (CLine* pLine = m_LineArray.GetAt(lineplace.nLineIndex)) { | |
| 221 return SearchWordPlace( | |
| 222 fx - m_SecInfo.rcSection.left, | |
| 223 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), | |
| 224 pLine->GetEndWordPlace())); | |
| 225 } | |
| 226 return GetBeginWordPlace(); | |
| 227 } | |
| 228 CPVT_WordPlace CSection::SearchWordPlace(FX_FLOAT fx, | |
| 229 const CPVT_WordRange& range) const { | |
| 230 CPVT_WordPlace wordplace = range.BeginPos; | |
| 231 wordplace.nWordIndex = -1; | |
| 232 if (!m_pVT) { | |
| 233 return wordplace; | |
| 234 } | |
| 235 int32_t nLeft = range.BeginPos.nWordIndex; | |
| 236 int32_t nRight = range.EndPos.nWordIndex + 1; | |
| 237 int32_t nMid = (nLeft + nRight) / 2; | |
| 238 while (nLeft < nRight) { | |
| 239 if (nMid == nLeft) { | |
| 240 break; | |
| 241 } | |
| 242 if (nMid == nRight) { | |
| 243 nMid--; | |
| 244 break; | |
| 245 } | |
| 246 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { | |
| 247 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * PVT_HALF) { | |
| 248 nLeft = nMid; | |
| 249 nMid = (nLeft + nRight) / 2; | |
| 250 continue; | |
| 251 } else { | |
| 252 nRight = nMid; | |
| 253 nMid = (nLeft + nRight) / 2; | |
| 254 continue; | |
| 255 } | |
| 256 } else { | |
| 257 break; | |
| 258 } | |
| 259 } | |
| 260 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { | |
| 261 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * PVT_HALF) { | |
| 262 wordplace.nWordIndex = nMid; | |
| 263 } | |
| 264 } | |
| 265 return wordplace; | |
| 266 } | |
| 267 void CSection::ClearLeftWords(int32_t nWordIndex) { | |
| 268 for (int32_t i = nWordIndex; i >= 0; i--) { | |
| 269 delete m_WordArray.GetAt(i); | |
| 270 m_WordArray.RemoveAt(i); | |
| 271 } | |
| 272 } | |
| 273 void CSection::ClearRightWords(int32_t nWordIndex) { | |
| 274 for (int32_t i = m_WordArray.GetSize() - 1; i > nWordIndex; i--) { | |
| 275 delete m_WordArray.GetAt(i); | |
| 276 m_WordArray.RemoveAt(i); | |
| 277 } | |
| 278 } | |
| 279 void CSection::ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex) { | |
| 280 for (int32_t i = nEndIndex; i > nBeginIndex; i--) { | |
| 281 delete m_WordArray.GetAt(i); | |
| 282 m_WordArray.RemoveAt(i); | |
| 283 } | |
| 284 } | |
| 285 void CSection::ClearWords(const CPVT_WordRange& PlaceRange) { | |
| 286 CPVT_WordPlace SecBeginPos = GetBeginWordPlace(); | |
| 287 CPVT_WordPlace SecEndPos = GetEndWordPlace(); | |
| 288 if (PlaceRange.BeginPos.WordCmp(SecBeginPos) >= 0) { | |
| 289 if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) { | |
| 290 ClearMidWords(PlaceRange.BeginPos.nWordIndex, | |
| 291 PlaceRange.EndPos.nWordIndex); | |
| 292 } else { | |
| 293 ClearRightWords(PlaceRange.BeginPos.nWordIndex); | |
| 294 } | |
| 295 } else if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) { | |
| 296 ClearLeftWords(PlaceRange.EndPos.nWordIndex); | |
| 297 } else { | |
| 298 ResetWordArray(); | |
| 299 } | |
| 300 } | |
| 301 void CSection::ClearWord(const CPVT_WordPlace& place) { | |
| 302 delete m_WordArray.GetAt(place.nWordIndex); | |
| 303 m_WordArray.RemoveAt(place.nWordIndex); | |
| 304 } | |
| 305 CTypeset::CTypeset(CSection* pSection) | |
| 306 : m_rcRet(0.0f, 0.0f, 0.0f, 0.0f), | |
| 307 m_pVT(pSection->m_pVT), | |
| 308 m_pSection(pSection) {} | |
| 309 CTypeset::~CTypeset() {} | |
| 310 CPVT_FloatRect CTypeset::CharArray() { | |
| 311 ASSERT(m_pSection); | |
| 312 FX_FLOAT fLineAscent = | |
| 313 m_pVT->GetFontAscent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize()); | |
| 314 FX_FLOAT fLineDescent = | |
| 315 m_pVT->GetFontDescent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize()); | |
| 316 m_rcRet.Default(); | |
| 317 FX_FLOAT x = 0.0f, y = 0.0f; | |
| 318 FX_FLOAT fNextWidth; | |
| 319 int32_t nStart = 0; | |
| 320 FX_FLOAT fNodeWidth = m_pVT->GetPlateWidth() / | |
| 321 (m_pVT->m_nCharArray <= 0 ? 1 : m_pVT->m_nCharArray); | |
| 322 if (CLine* pLine = m_pSection->m_LineArray.GetAt(0)) { | |
| 323 x = 0.0f; | |
| 324 y += m_pVT->GetLineLeading(m_pSection->m_SecInfo); | |
| 325 y += fLineAscent; | |
| 326 nStart = 0; | |
| 327 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { | |
| 328 case 0: | |
| 329 pLine->m_LineInfo.fLineX = fNodeWidth * PVT_HALF; | |
| 330 break; | |
| 331 case 1: | |
| 332 nStart = (m_pVT->m_nCharArray - m_pSection->m_WordArray.GetSize()) / 2; | |
| 333 pLine->m_LineInfo.fLineX = fNodeWidth * nStart - fNodeWidth * PVT_HALF; | |
| 334 break; | |
| 335 case 2: | |
| 336 nStart = m_pVT->m_nCharArray - m_pSection->m_WordArray.GetSize(); | |
| 337 pLine->m_LineInfo.fLineX = fNodeWidth * nStart - fNodeWidth * PVT_HALF; | |
| 338 break; | |
| 339 } | |
| 340 for (int32_t w = 0, sz = m_pSection->m_WordArray.GetSize(); w < sz; w++) { | |
| 341 if (w >= m_pVT->m_nCharArray) { | |
| 342 break; | |
| 343 } | |
| 344 fNextWidth = 0; | |
| 345 if (CPVT_WordInfo* pNextWord = | |
| 346 (CPVT_WordInfo*)m_pSection->m_WordArray.GetAt(w + 1)) { | |
| 347 pNextWord->fWordTail = 0; | |
| 348 fNextWidth = m_pVT->GetWordWidth(*pNextWord); | |
| 349 } | |
| 350 if (CPVT_WordInfo* pWord = | |
| 351 (CPVT_WordInfo*)m_pSection->m_WordArray.GetAt(w)) { | |
| 352 pWord->fWordTail = 0; | |
| 353 FX_FLOAT fWordWidth = m_pVT->GetWordWidth(*pWord); | |
| 354 FX_FLOAT fWordAscent = m_pVT->GetWordAscent(*pWord); | |
| 355 FX_FLOAT fWordDescent = m_pVT->GetWordDescent(*pWord); | |
| 356 x = (FX_FLOAT)(fNodeWidth * (w + nStart + 0.5) - fWordWidth * PVT_HALF); | |
| 357 pWord->fWordX = x; | |
| 358 pWord->fWordY = y; | |
| 359 if (w == 0) { | |
| 360 pLine->m_LineInfo.fLineX = x; | |
| 361 } | |
| 362 if (w != m_pSection->m_WordArray.GetSize() - 1) { | |
| 363 pWord->fWordTail = | |
| 364 (fNodeWidth - (fWordWidth + fNextWidth) * PVT_HALF > 0 | |
| 365 ? fNodeWidth - (fWordWidth + fNextWidth) * PVT_HALF | |
| 366 : 0); | |
| 367 } else { | |
| 368 pWord->fWordTail = 0; | |
| 369 } | |
| 370 x += fWordWidth; | |
| 371 fLineAscent = std::max(fLineAscent, fWordAscent); | |
| 372 fLineDescent = std::min(fLineDescent, fWordDescent); | |
| 373 } | |
| 374 } | |
| 375 pLine->m_LineInfo.nBeginWordIndex = 0; | |
| 376 pLine->m_LineInfo.nEndWordIndex = m_pSection->m_WordArray.GetSize() - 1; | |
| 377 pLine->m_LineInfo.fLineY = y; | |
| 378 pLine->m_LineInfo.fLineWidth = x - pLine->m_LineInfo.fLineX; | |
| 379 pLine->m_LineInfo.fLineAscent = fLineAscent; | |
| 380 pLine->m_LineInfo.fLineDescent = fLineDescent; | |
| 381 y += (-fLineDescent); | |
| 382 } | |
| 383 return m_rcRet = CPVT_FloatRect(0, 0, x, y); | |
| 384 } | |
| 385 CPVT_Size CTypeset::GetEditSize(FX_FLOAT fFontSize) { | |
| 386 ASSERT(m_pSection); | |
| 387 ASSERT(m_pVT); | |
| 388 SplitLines(FALSE, fFontSize); | |
| 389 return CPVT_Size(m_rcRet.Width(), m_rcRet.Height()); | |
| 390 } | |
| 391 CPVT_FloatRect CTypeset::Typeset() { | |
| 392 ASSERT(m_pVT); | |
| 393 m_pSection->m_LineArray.Empty(); | |
| 394 SplitLines(TRUE, 0.0f); | |
| 395 m_pSection->m_LineArray.Clear(); | |
| 396 OutputLines(); | |
| 397 return m_rcRet; | |
| 398 } | |
| 399 | |
| 400 static const uint8_t special_chars[128] = { | |
| 401 0x00, 0x0C, 0x08, 0x0C, 0x08, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, | |
| 402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
| 403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x00, | |
| 404 0x10, 0x00, 0x00, 0x28, 0x0C, 0x08, 0x00, 0x00, 0x28, 0x28, 0x28, 0x28, | |
| 405 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x08, 0x08, | |
| 406 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, | |
| 407 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, | |
| 408 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0C, 0x00, 0x08, 0x00, 0x00, | |
| 409 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, | |
| 410 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, | |
| 411 0x01, 0x01, 0x01, 0x0C, 0x00, 0x08, 0x00, 0x00, | |
| 412 }; | |
| 413 | |
| 414 static bool IsLatin(uint16_t word) { | |
| 415 if (word <= 0x007F) | |
| 416 return !!(special_chars[word] & 0x01); | |
| 417 | |
| 418 return ((word >= 0x00C0 && word <= 0x00FF) || | |
| 419 (word >= 0x0100 && word <= 0x024F) || | |
| 420 (word >= 0x1E00 && word <= 0x1EFF) || | |
| 421 (word >= 0x2C60 && word <= 0x2C7F) || | |
| 422 (word >= 0xA720 && word <= 0xA7FF) || | |
| 423 (word >= 0xFF21 && word <= 0xFF3A) || | |
| 424 (word >= 0xFF41 && word <= 0xFF5A)); | |
| 425 } | |
| 426 | |
| 427 static bool IsDigit(uint32_t word) { | |
| 428 return word >= 0x0030 && word <= 0x0039; | |
| 429 } | |
| 430 | |
| 431 static bool IsCJK(uint32_t word) { | |
| 432 if ((word >= 0x1100 && word <= 0x11FF) || | |
| 433 (word >= 0x2E80 && word <= 0x2FFF) || | |
| 434 (word >= 0x3040 && word <= 0x9FBF) || | |
| 435 (word >= 0xAC00 && word <= 0xD7AF) || | |
| 436 (word >= 0xF900 && word <= 0xFAFF) || | |
| 437 (word >= 0xFE30 && word <= 0xFE4F) || | |
| 438 (word >= 0x20000 && word <= 0x2A6DF) || | |
| 439 (word >= 0x2F800 && word <= 0x2FA1F)) { | |
| 440 return true; | |
| 441 } | |
| 442 if (word >= 0x3000 && word <= 0x303F) { | |
| 443 return ( | |
| 444 word == 0x3005 || word == 0x3006 || word == 0x3021 || word == 0x3022 || | |
| 445 word == 0x3023 || word == 0x3024 || word == 0x3025 || word == 0x3026 || | |
| 446 word == 0x3027 || word == 0x3028 || word == 0x3029 || word == 0x3031 || | |
| 447 word == 0x3032 || word == 0x3033 || word == 0x3034 || word == 0x3035); | |
| 448 } | |
| 449 return word >= 0xFF66 && word <= 0xFF9D; | |
| 450 } | |
| 451 | |
| 452 static bool IsPunctuation(uint32_t word) { | |
| 453 if (word <= 0x007F) | |
| 454 return !!(special_chars[word] & 0x08); | |
| 455 | |
| 456 if (word >= 0x0080 && word <= 0x00FF) { | |
| 457 return (word == 0x0082 || word == 0x0084 || word == 0x0085 || | |
| 458 word == 0x0091 || word == 0x0092 || word == 0x0093 || | |
| 459 word <= 0x0094 || word == 0x0096 || word == 0x00B4 || | |
| 460 word == 0x00B8); | |
| 461 } | |
| 462 | |
| 463 if (word >= 0x2000 && word <= 0x206F) { | |
| 464 return ( | |
| 465 word == 0x2010 || word == 0x2011 || word == 0x2012 || word == 0x2013 || | |
| 466 word == 0x2018 || word == 0x2019 || word == 0x201A || word == 0x201B || | |
| 467 word == 0x201C || word == 0x201D || word == 0x201E || word == 0x201F || | |
| 468 word == 0x2032 || word == 0x2033 || word == 0x2034 || word == 0x2035 || | |
| 469 word == 0x2036 || word == 0x2037 || word == 0x203C || word == 0x203D || | |
| 470 word == 0x203E || word == 0x2044); | |
| 471 } | |
| 472 | |
| 473 if (word >= 0x3000 && word <= 0x303F) { | |
| 474 return ( | |
| 475 word == 0x3001 || word == 0x3002 || word == 0x3003 || word == 0x3005 || | |
| 476 word == 0x3009 || word == 0x300A || word == 0x300B || word == 0x300C || | |
| 477 word == 0x300D || word == 0x300F || word == 0x300E || word == 0x3010 || | |
| 478 word == 0x3011 || word == 0x3014 || word == 0x3015 || word == 0x3016 || | |
| 479 word == 0x3017 || word == 0x3018 || word == 0x3019 || word == 0x301A || | |
| 480 word == 0x301B || word == 0x301D || word == 0x301E || word == 0x301F); | |
| 481 } | |
| 482 | |
| 483 if (word >= 0xFE50 && word <= 0xFE6F) | |
| 484 return (word >= 0xFE50 && word <= 0xFE5E) || word == 0xFE63; | |
| 485 | |
| 486 if (word >= 0xFF00 && word <= 0xFFEF) { | |
| 487 return ( | |
| 488 word == 0xFF01 || word == 0xFF02 || word == 0xFF07 || word == 0xFF08 || | |
| 489 word == 0xFF09 || word == 0xFF0C || word == 0xFF0E || word == 0xFF0F || | |
| 490 word == 0xFF1A || word == 0xFF1B || word == 0xFF1F || word == 0xFF3B || | |
| 491 word == 0xFF3D || word == 0xFF40 || word == 0xFF5B || word == 0xFF5C || | |
| 492 word == 0xFF5D || word == 0xFF61 || word == 0xFF62 || word == 0xFF63 || | |
| 493 word == 0xFF64 || word == 0xFF65 || word == 0xFF9E || word == 0xFF9F); | |
| 494 } | |
| 495 | |
| 496 return false; | |
| 497 } | |
| 498 | |
| 499 static bool IsConnectiveSymbol(uint32_t word) { | |
| 500 return word <= 0x007F && (special_chars[word] & 0x20); | |
| 501 } | |
| 502 | |
| 503 static bool IsOpenStylePunctuation(uint32_t word) { | |
| 504 if (word <= 0x007F) | |
| 505 return !!(special_chars[word] & 0x04); | |
| 506 | |
| 507 return (word == 0x300A || word == 0x300C || word == 0x300E || | |
| 508 word == 0x3010 || word == 0x3014 || word == 0x3016 || | |
| 509 word == 0x3018 || word == 0x301A || word == 0xFF08 || | |
| 510 word == 0xFF3B || word == 0xFF5B || word == 0xFF62); | |
| 511 } | |
| 512 | |
| 513 static bool IsCurrencySymbol(uint16_t word) { | |
| 514 return (word == 0x0024 || word == 0x0080 || word == 0x00A2 || | |
| 515 word == 0x00A3 || word == 0x00A4 || word == 0x00A5 || | |
| 516 (word >= 0x20A0 && word <= 0x20CF) || word == 0xFE69 || | |
| 517 word == 0xFF04 || word == 0xFFE0 || word == 0xFFE1 || | |
| 518 word == 0xFFE5 || word == 0xFFE6); | |
| 519 } | |
| 520 | |
| 521 static bool IsPrefixSymbol(uint16_t word) { | |
| 522 return IsCurrencySymbol(word) || word == 0x2116; | |
| 523 } | |
| 524 | |
| 525 static bool IsSpace(uint16_t word) { | |
| 526 return word == 0x0020 || word == 0x3000; | |
| 527 } | |
| 528 | |
| 529 static bool NeedDivision(uint16_t prevWord, uint16_t curWord) { | |
| 530 if ((IsLatin(prevWord) || IsDigit(prevWord)) && | |
| 531 (IsLatin(curWord) || IsDigit(curWord))) { | |
| 532 return false; | |
| 533 } | |
| 534 if (IsSpace(curWord) || IsPunctuation(curWord)) { | |
| 535 return false; | |
| 536 } | |
| 537 if (IsConnectiveSymbol(prevWord) || IsConnectiveSymbol(curWord)) { | |
| 538 return false; | |
| 539 } | |
| 540 if (IsSpace(prevWord) || IsPunctuation(prevWord)) { | |
| 541 return true; | |
| 542 } | |
| 543 if (IsPrefixSymbol(prevWord)) { | |
| 544 return false; | |
| 545 } | |
| 546 if (IsPrefixSymbol(curWord) || IsCJK(curWord)) { | |
| 547 return true; | |
| 548 } | |
| 549 if (IsCJK(prevWord)) { | |
| 550 return true; | |
| 551 } | |
| 552 return false; | |
| 553 } | |
| 554 | |
| 555 void CTypeset::SplitLines(FX_BOOL bTypeset, FX_FLOAT fFontSize) { | |
| 556 ASSERT(m_pVT); | |
| 557 ASSERT(m_pSection); | |
| 558 int32_t nLineHead = 0; | |
| 559 int32_t nLineTail = 0; | |
| 560 FX_FLOAT fMaxX = 0.0f, fMaxY = 0.0f; | |
| 561 FX_FLOAT fLineWidth = 0.0f, fBackupLineWidth = 0.0f; | |
| 562 FX_FLOAT fLineAscent = 0.0f, fBackupLineAscent = 0.0f; | |
| 563 FX_FLOAT fLineDescent = 0.0f, fBackupLineDescent = 0.0f; | |
| 564 int32_t nWordStartPos = 0; | |
| 565 FX_BOOL bFullWord = FALSE; | |
| 566 int32_t nLineFullWordIndex = 0; | |
| 567 int32_t nCharIndex = 0; | |
| 568 CPVT_LineInfo line; | |
| 569 FX_FLOAT fWordWidth = 0; | |
| 570 FX_FLOAT fTypesetWidth = std::max( | |
| 571 m_pVT->GetPlateWidth() - m_pVT->GetLineIndent(m_pSection->m_SecInfo), | |
| 572 0.0f); | |
| 573 int32_t nTotalWords = m_pSection->m_WordArray.GetSize(); | |
| 574 FX_BOOL bOpened = FALSE; | |
| 575 if (nTotalWords > 0) { | |
| 576 int32_t i = 0; | |
| 577 while (i < nTotalWords) { | |
| 578 CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(i); | |
| 579 CPVT_WordInfo* pOldWord = pWord; | |
| 580 if (i > 0) { | |
| 581 pOldWord = m_pSection->m_WordArray.GetAt(i - 1); | |
| 582 } | |
| 583 if (pWord) { | |
| 584 if (bTypeset) { | |
| 585 fLineAscent = | |
| 586 std::max(fLineAscent, m_pVT->GetWordAscent(*pWord, TRUE)); | |
| 587 fLineDescent = | |
| 588 std::min(fLineDescent, m_pVT->GetWordDescent(*pWord, TRUE)); | |
| 589 fWordWidth = m_pVT->GetWordWidth(*pWord); | |
| 590 } else { | |
| 591 fLineAscent = | |
| 592 std::max(fLineAscent, m_pVT->GetWordAscent(*pWord, fFontSize)); | |
| 593 fLineDescent = | |
| 594 std::min(fLineDescent, m_pVT->GetWordDescent(*pWord, fFontSize)); | |
| 595 fWordWidth = m_pVT->GetWordWidth( | |
| 596 pWord->nFontIndex, pWord->Word, m_pVT->m_wSubWord, | |
| 597 m_pVT->m_fCharSpace, m_pVT->m_nHorzScale, fFontSize, | |
| 598 pWord->fWordTail, 0); | |
| 599 } | |
| 600 if (!bOpened) { | |
| 601 if (IsOpenStylePunctuation(pWord->Word)) { | |
| 602 bOpened = TRUE; | |
| 603 bFullWord = TRUE; | |
| 604 } else if (pOldWord) { | |
| 605 if (NeedDivision(pOldWord->Word, pWord->Word)) { | |
| 606 bFullWord = TRUE; | |
| 607 } | |
| 608 } | |
| 609 } else { | |
| 610 if (!IsSpace(pWord->Word) && !IsOpenStylePunctuation(pWord->Word)) { | |
| 611 bOpened = FALSE; | |
| 612 } | |
| 613 } | |
| 614 if (bFullWord) { | |
| 615 bFullWord = FALSE; | |
| 616 if (nCharIndex > 0) { | |
| 617 nLineFullWordIndex++; | |
| 618 } | |
| 619 nWordStartPos = i; | |
| 620 fBackupLineWidth = fLineWidth; | |
| 621 fBackupLineAscent = fLineAscent; | |
| 622 fBackupLineDescent = fLineDescent; | |
| 623 } | |
| 624 nCharIndex++; | |
| 625 } | |
| 626 if (m_pVT->m_bLimitWidth && fTypesetWidth > 0 && | |
| 627 fLineWidth + fWordWidth > fTypesetWidth) { | |
| 628 if (nLineFullWordIndex > 0) { | |
| 629 i = nWordStartPos; | |
| 630 fLineWidth = fBackupLineWidth; | |
| 631 fLineAscent = fBackupLineAscent; | |
| 632 fLineDescent = fBackupLineDescent; | |
| 633 } | |
| 634 if (nCharIndex == 1) { | |
| 635 fLineWidth = fWordWidth; | |
| 636 i++; | |
| 637 } | |
| 638 nLineTail = i - 1; | |
| 639 if (bTypeset) { | |
| 640 line.nBeginWordIndex = nLineHead; | |
| 641 line.nEndWordIndex = nLineTail; | |
| 642 line.nTotalWord = nLineTail - nLineHead + 1; | |
| 643 line.fLineWidth = fLineWidth; | |
| 644 line.fLineAscent = fLineAscent; | |
| 645 line.fLineDescent = fLineDescent; | |
| 646 m_pSection->AddLine(line); | |
| 647 } | |
| 648 fMaxY += (fLineAscent + m_pVT->GetLineLeading(m_pSection->m_SecInfo)); | |
| 649 fMaxY += (-fLineDescent); | |
| 650 fMaxX = std::max(fLineWidth, fMaxX); | |
| 651 nLineHead = i; | |
| 652 fLineWidth = 0.0f; | |
| 653 fLineAscent = 0.0f; | |
| 654 fLineDescent = 0.0f; | |
| 655 nCharIndex = 0; | |
| 656 nLineFullWordIndex = 0; | |
| 657 bFullWord = FALSE; | |
| 658 } else { | |
| 659 fLineWidth += fWordWidth; | |
| 660 i++; | |
| 661 } | |
| 662 } | |
| 663 if (nLineHead <= nTotalWords - 1) { | |
| 664 nLineTail = nTotalWords - 1; | |
| 665 if (bTypeset) { | |
| 666 line.nBeginWordIndex = nLineHead; | |
| 667 line.nEndWordIndex = nLineTail; | |
| 668 line.nTotalWord = nLineTail - nLineHead + 1; | |
| 669 line.fLineWidth = fLineWidth; | |
| 670 line.fLineAscent = fLineAscent; | |
| 671 line.fLineDescent = fLineDescent; | |
| 672 m_pSection->AddLine(line); | |
| 673 } | |
| 674 fMaxY += (fLineAscent + m_pVT->GetLineLeading(m_pSection->m_SecInfo)); | |
| 675 fMaxY += (-fLineDescent); | |
| 676 fMaxX = std::max(fLineWidth, fMaxX); | |
| 677 } | |
| 678 } else { | |
| 679 if (bTypeset) { | |
| 680 fLineAscent = m_pVT->GetLineAscent(m_pSection->m_SecInfo); | |
| 681 fLineDescent = m_pVT->GetLineDescent(m_pSection->m_SecInfo); | |
| 682 } else { | |
| 683 fLineAscent = | |
| 684 m_pVT->GetFontAscent(m_pVT->GetDefaultFontIndex(), fFontSize); | |
| 685 fLineDescent = | |
| 686 m_pVT->GetFontDescent(m_pVT->GetDefaultFontIndex(), fFontSize); | |
| 687 } | |
| 688 if (bTypeset) { | |
| 689 line.nBeginWordIndex = -1; | |
| 690 line.nEndWordIndex = -1; | |
| 691 line.nTotalWord = 0; | |
| 692 line.fLineWidth = 0; | |
| 693 line.fLineAscent = fLineAscent; | |
| 694 line.fLineDescent = fLineDescent; | |
| 695 m_pSection->AddLine(line); | |
| 696 } | |
| 697 fMaxY += (m_pVT->GetLineLeading(m_pSection->m_SecInfo) + fLineAscent + | |
| 698 (-fLineDescent)); | |
| 699 } | |
| 700 m_rcRet = CPVT_FloatRect(0, 0, fMaxX, fMaxY); | |
| 701 } | |
| 702 void CTypeset::OutputLines() { | |
| 703 ASSERT(m_pVT); | |
| 704 ASSERT(m_pSection); | |
| 705 FX_FLOAT fMinX = 0.0f, fMinY = 0.0f, fMaxX = 0.0f, fMaxY = 0.0f; | |
| 706 FX_FLOAT fPosX = 0.0f, fPosY = 0.0f; | |
| 707 FX_FLOAT fLineIndent = m_pVT->GetLineIndent(m_pSection->m_SecInfo); | |
| 708 FX_FLOAT fTypesetWidth = std::max(m_pVT->GetPlateWidth() - fLineIndent, 0.0f); | |
| 709 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { | |
| 710 default: | |
| 711 case 0: | |
| 712 fMinX = 0.0f; | |
| 713 break; | |
| 714 case 1: | |
| 715 fMinX = (fTypesetWidth - m_rcRet.Width()) * PVT_HALF; | |
| 716 break; | |
| 717 case 2: | |
| 718 fMinX = fTypesetWidth - m_rcRet.Width(); | |
| 719 break; | |
| 720 } | |
| 721 fMaxX = fMinX + m_rcRet.Width(); | |
| 722 fMinY = 0.0f; | |
| 723 fMaxY = m_rcRet.Height(); | |
| 724 int32_t nTotalLines = m_pSection->m_LineArray.GetSize(); | |
| 725 if (nTotalLines > 0) { | |
| 726 m_pSection->m_SecInfo.nTotalLine = nTotalLines; | |
| 727 for (int32_t l = 0; l < nTotalLines; l++) { | |
| 728 if (CLine* pLine = m_pSection->m_LineArray.GetAt(l)) { | |
| 729 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { | |
| 730 default: | |
| 731 case 0: | |
| 732 fPosX = 0; | |
| 733 break; | |
| 734 case 1: | |
| 735 fPosX = (fTypesetWidth - pLine->m_LineInfo.fLineWidth) * PVT_HALF; | |
| 736 break; | |
| 737 case 2: | |
| 738 fPosX = fTypesetWidth - pLine->m_LineInfo.fLineWidth; | |
| 739 break; | |
| 740 } | |
| 741 fPosX += fLineIndent; | |
| 742 fPosY += m_pVT->GetLineLeading(m_pSection->m_SecInfo); | |
| 743 fPosY += pLine->m_LineInfo.fLineAscent; | |
| 744 pLine->m_LineInfo.fLineX = fPosX - fMinX; | |
| 745 pLine->m_LineInfo.fLineY = fPosY - fMinY; | |
| 746 for (int32_t w = pLine->m_LineInfo.nBeginWordIndex; | |
| 747 w <= pLine->m_LineInfo.nEndWordIndex; w++) { | |
| 748 if (CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(w)) { | |
| 749 pWord->fWordX = fPosX - fMinX; | |
| 750 if (pWord->pWordProps) { | |
| 751 switch (pWord->pWordProps->nScriptType) { | |
| 752 default: | |
| 753 case PVTWORD_SCRIPT_NORMAL: | |
| 754 pWord->fWordY = fPosY - fMinY; | |
| 755 break; | |
| 756 case PVTWORD_SCRIPT_SUPER: | |
| 757 pWord->fWordY = fPosY - m_pVT->GetWordAscent(*pWord) - fMinY; | |
| 758 break; | |
| 759 case PVTWORD_SCRIPT_SUB: | |
| 760 pWord->fWordY = fPosY - m_pVT->GetWordDescent(*pWord) - fMinY; | |
| 761 break; | |
| 762 } | |
| 763 } else { | |
| 764 pWord->fWordY = fPosY - fMinY; | |
| 765 } | |
| 766 fPosX += m_pVT->GetWordWidth(*pWord); | |
| 767 } | |
| 768 } | |
| 769 fPosY += (-pLine->m_LineInfo.fLineDescent); | |
| 770 } | |
| 771 } | |
| 772 } | |
| 773 m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY); | |
| 774 } | |
| 775 CPDF_VariableText::CPDF_VariableText() | 245 CPDF_VariableText::CPDF_VariableText() |
| 776 : m_nLimitChar(0), | 246 : m_nLimitChar(0), |
| 777 m_nCharArray(0), | 247 m_nCharArray(0), |
| 778 m_bMultiLine(FALSE), | 248 m_bMultiLine(FALSE), |
| 779 m_bLimitWidth(FALSE), | 249 m_bLimitWidth(FALSE), |
| 780 m_bAutoFontSize(FALSE), | 250 m_bAutoFontSize(FALSE), |
| 781 m_nAlignment(0), | 251 m_nAlignment(0), |
| 782 m_fLineLeading(0.0f), | 252 m_fLineLeading(0.0f), |
| 783 m_fCharSpace(0.0f), | 253 m_fCharSpace(0.0f), |
| 784 m_nHorzScale(100), | 254 m_nHorzScale(100), |
| 785 m_wSubWord(0), | 255 m_wSubWord(0), |
| 786 m_fFontSize(0.0f), | 256 m_fFontSize(0.0f), |
| 787 m_bInitial(FALSE), | 257 m_bInitial(FALSE), |
| 788 m_bRichText(FALSE), | 258 m_bRichText(FALSE), |
| 789 m_pVTProvider(NULL), | 259 m_pVTProvider(nullptr), |
| 790 m_pVTIterator(NULL) {} | 260 m_pVTIterator(nullptr) {} |
| 261 |
| 791 CPDF_VariableText::~CPDF_VariableText() { | 262 CPDF_VariableText::~CPDF_VariableText() { |
| 792 delete m_pVTIterator; | 263 delete m_pVTIterator; |
| 793 m_pVTIterator = NULL; | |
| 794 ResetAll(); | 264 ResetAll(); |
| 795 } | 265 } |
| 266 |
| 796 void CPDF_VariableText::Initialize() { | 267 void CPDF_VariableText::Initialize() { |
| 797 if (!m_bInitial) { | 268 if (!m_bInitial) { |
| 798 CPVT_SectionInfo secinfo; | 269 CPVT_SectionInfo secinfo; |
| 799 if (m_bRichText) { | 270 if (m_bRichText) { |
| 800 secinfo.pSecProps = new CPVT_SecProps(0.0f, 0.0f, 0); | 271 secinfo.pSecProps = new CPVT_SecProps(0.0f, 0.0f, 0); |
| 801 secinfo.pWordProps = new CPVT_WordProps(GetDefaultFontIndex(), | 272 secinfo.pWordProps = new CPVT_WordProps( |
| 802 PVT_DEFAULT_FONTSIZE, 0, 0, 0); | 273 GetDefaultFontIndex(), kDefaultFontSize, 0, ScriptType::Normal, 0); |
| 803 } | 274 } |
| 804 CPVT_WordPlace place; | 275 CPVT_WordPlace place; |
| 805 place.nSecIndex = 0; | 276 place.nSecIndex = 0; |
| 806 AddSection(place, secinfo); | 277 AddSection(place, secinfo); |
| 807 CPVT_LineInfo lineinfo; | 278 CPVT_LineInfo lineinfo; |
| 808 lineinfo.fLineAscent = GetFontAscent(GetDefaultFontIndex(), GetFontSize()); | 279 lineinfo.fLineAscent = GetFontAscent(GetDefaultFontIndex(), GetFontSize()); |
| 809 lineinfo.fLineDescent = | 280 lineinfo.fLineDescent = |
| 810 GetFontDescent(GetDefaultFontIndex(), GetFontSize()); | 281 GetFontDescent(GetDefaultFontIndex(), GetFontSize()); |
| 811 AddLine(place, lineinfo); | 282 AddLine(place, lineinfo); |
| 812 if (CSection* pSection = m_SectionArray.GetAt(0)) { | 283 if (CSection* pSection = m_SectionArray.GetAt(0)) |
| 813 pSection->ResetLinePlace(); | 284 pSection->ResetLinePlace(); |
| 814 } | 285 |
| 815 m_bInitial = TRUE; | 286 m_bInitial = TRUE; |
| 816 } | 287 } |
| 817 } | 288 } |
| 289 |
| 818 void CPDF_VariableText::ResetAll() { | 290 void CPDF_VariableText::ResetAll() { |
| 819 m_bInitial = FALSE; | 291 m_bInitial = FALSE; |
| 820 ResetSectionArray(); | 292 ResetSectionArray(); |
| 821 } | 293 } |
| 294 |
| 822 CPVT_WordPlace CPDF_VariableText::InsertWord(const CPVT_WordPlace& place, | 295 CPVT_WordPlace CPDF_VariableText::InsertWord(const CPVT_WordPlace& place, |
| 823 uint16_t word, | 296 uint16_t word, |
| 824 int32_t charset, | 297 int32_t charset, |
| 825 const CPVT_WordProps* pWordProps) { | 298 const CPVT_WordProps* pWordProps) { |
| 826 int32_t nTotlaWords = GetTotalWords(); | 299 int32_t nTotlaWords = GetTotalWords(); |
| 827 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) { | 300 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) |
| 828 return place; | 301 return place; |
| 829 } | 302 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) |
| 830 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) { | |
| 831 return place; | 303 return place; |
| 832 } | 304 |
| 833 CPVT_WordPlace newplace = place; | 305 CPVT_WordPlace newplace = place; |
| 834 newplace.nWordIndex++; | 306 newplace.nWordIndex++; |
| 835 if (m_bRichText) { | 307 if (m_bRichText) { |
| 836 CPVT_WordProps* pNewProps = | 308 CPVT_WordProps* pNewProps = |
| 837 pWordProps ? new CPVT_WordProps(*pWordProps) : new CPVT_WordProps(); | 309 pWordProps ? new CPVT_WordProps(*pWordProps) : new CPVT_WordProps(); |
| 838 pNewProps->nFontIndex = | 310 pNewProps->nFontIndex = |
| 839 GetWordFontIndex(word, charset, pWordProps->nFontIndex); | 311 GetWordFontIndex(word, charset, pWordProps->nFontIndex); |
| 840 return AddWord(newplace, CPVT_WordInfo(word, charset, -1, pNewProps)); | 312 return AddWord(newplace, CPVT_WordInfo(word, charset, -1, pNewProps)); |
| 841 } | 313 } |
| 842 int32_t nFontIndex = | 314 int32_t nFontIndex = |
| 843 GetSubWord() > 0 ? GetDefaultFontIndex() | 315 GetSubWord() > 0 ? GetDefaultFontIndex() |
| 844 : GetWordFontIndex(word, charset, GetDefaultFontIndex()); | 316 : GetWordFontIndex(word, charset, GetDefaultFontIndex()); |
| 845 return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, NULL)); | 317 return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, NULL)); |
| 846 } | 318 } |
| 319 |
| 847 CPVT_WordPlace CPDF_VariableText::InsertSection( | 320 CPVT_WordPlace CPDF_VariableText::InsertSection( |
| 848 const CPVT_WordPlace& place, | 321 const CPVT_WordPlace& place, |
| 849 const CPVT_SecProps* pSecProps, | 322 const CPVT_SecProps* pSecProps, |
| 850 const CPVT_WordProps* pWordProps) { | 323 const CPVT_WordProps* pWordProps) { |
| 851 int32_t nTotlaWords = GetTotalWords(); | 324 int32_t nTotlaWords = GetTotalWords(); |
| 852 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) { | 325 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) |
| 853 return place; | 326 return place; |
| 854 } | 327 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) |
| 855 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) { | |
| 856 return place; | 328 return place; |
| 857 } | 329 if (!m_bMultiLine) |
| 858 if (!m_bMultiLine) { | |
| 859 return place; | 330 return place; |
| 860 } | 331 |
| 861 CPVT_WordPlace wordplace = place; | 332 CPVT_WordPlace wordplace = place; |
| 862 UpdateWordPlace(wordplace); | 333 UpdateWordPlace(wordplace); |
| 863 CPVT_WordPlace newplace = place; | 334 CPVT_WordPlace newplace = place; |
| 864 if (CSection* pSection = m_SectionArray.GetAt(wordplace.nSecIndex)) { | 335 if (CSection* pSection = m_SectionArray.GetAt(wordplace.nSecIndex)) { |
| 865 CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1); | 336 CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1); |
| 866 CPVT_SectionInfo secinfo; | 337 CPVT_SectionInfo secinfo; |
| 867 if (m_bRichText) { | 338 if (m_bRichText) { |
| 868 if (pSecProps) { | 339 if (pSecProps) |
| 869 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); | 340 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); |
| 870 } | 341 if (pWordProps) |
| 871 if (pWordProps) { | |
| 872 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); | 342 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); |
| 873 } | |
| 874 } | 343 } |
| 875 AddSection(NewPlace, secinfo); | 344 AddSection(NewPlace, secinfo); |
| 876 newplace = NewPlace; | 345 newplace = NewPlace; |
| 877 if (CSection* pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) { | 346 if (CSection* pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) { |
| 878 for (int32_t w = wordplace.nWordIndex + 1, | 347 for (int32_t w = wordplace.nWordIndex + 1, |
| 879 sz = pSection->m_WordArray.GetSize(); | 348 sz = pSection->m_WordArray.GetSize(); |
| 880 w < sz; w++) { | 349 w < sz; w++) { |
| 881 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(w)) { | 350 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(w)) { |
| 882 NewPlace.nWordIndex++; | 351 NewPlace.nWordIndex++; |
| 883 pNewSection->AddWord(NewPlace, *pWord); | 352 pNewSection->AddWord(NewPlace, *pWord); |
| 884 } | 353 } |
| 885 } | 354 } |
| 886 } | 355 } |
| 887 ClearSectionRightWords(wordplace); | 356 ClearSectionRightWords(wordplace); |
| 888 } | 357 } |
| 889 return newplace; | 358 return newplace; |
| 890 } | 359 } |
| 360 |
| 891 CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace& place, | 361 CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace& place, |
| 892 const FX_WCHAR* text, | 362 const FX_WCHAR* text, |
| 893 int32_t charset, | 363 int32_t charset, |
| 894 const CPVT_SecProps* pSecProps, | 364 const CPVT_SecProps* pSecProps, |
| 895 const CPVT_WordProps* pProps) { | 365 const CPVT_WordProps* pProps) { |
| 896 CFX_WideString swText = text; | 366 CFX_WideString swText = text; |
| 897 CPVT_WordPlace wp = place; | 367 CPVT_WordPlace wp = place; |
| 898 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { | 368 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { |
| 899 CPVT_WordPlace oldwp = wp; | 369 CPVT_WordPlace oldwp = wp; |
| 900 uint16_t word = swText.GetAt(i); | 370 uint16_t word = swText.GetAt(i); |
| 901 switch (word) { | 371 switch (word) { |
| 902 case 0x0D: | 372 case 0x0D: |
| 903 if (m_bMultiLine) { | 373 if (m_bMultiLine) { |
| 904 if (swText.GetAt(i + 1) == 0x0A) { | 374 if (swText.GetAt(i + 1) == 0x0A) |
| 905 i += 1; | 375 i += 1; |
| 906 } | 376 |
| 907 wp = InsertSection(wp, pSecProps, pProps); | 377 wp = InsertSection(wp, pSecProps, pProps); |
| 908 } | 378 } |
| 909 break; | 379 break; |
| 910 case 0x0A: | 380 case 0x0A: |
| 911 if (m_bMultiLine) { | 381 if (m_bMultiLine) { |
| 912 if (swText.GetAt(i + 1) == 0x0D) { | 382 if (swText.GetAt(i + 1) == 0x0D) |
| 913 i += 1; | 383 i += 1; |
| 914 } | 384 |
| 915 wp = InsertSection(wp, pSecProps, pProps); | 385 wp = InsertSection(wp, pSecProps, pProps); |
| 916 } | 386 } |
| 917 break; | 387 break; |
| 918 case 0x09: | 388 case 0x09: |
| 919 word = 0x20; | 389 word = 0x20; |
| 920 default: | 390 default: |
| 921 wp = InsertWord(wp, word, charset, pProps); | 391 wp = InsertWord(wp, word, charset, pProps); |
| 922 break; | 392 break; |
| 923 } | 393 } |
| 924 if (wp == oldwp) { | 394 if (wp == oldwp) |
| 925 break; | 395 break; |
| 926 } | |
| 927 } | 396 } |
| 928 return wp; | 397 return wp; |
| 929 } | 398 } |
| 399 |
| 930 CPVT_WordPlace CPDF_VariableText::DeleteWords( | 400 CPVT_WordPlace CPDF_VariableText::DeleteWords( |
| 931 const CPVT_WordRange& PlaceRange) { | 401 const CPVT_WordRange& PlaceRange) { |
| 932 FX_BOOL bLastSecPos = FALSE; | 402 FX_BOOL bLastSecPos = FALSE; |
| 933 if (CSection* pSection = m_SectionArray.GetAt(PlaceRange.EndPos.nSecIndex)) { | 403 if (CSection* pSection = m_SectionArray.GetAt(PlaceRange.EndPos.nSecIndex)) |
| 934 bLastSecPos = (PlaceRange.EndPos == pSection->GetEndWordPlace()); | 404 bLastSecPos = (PlaceRange.EndPos == pSection->GetEndWordPlace()); |
| 935 } | 405 |
| 936 ClearWords(PlaceRange); | 406 ClearWords(PlaceRange); |
| 937 if (PlaceRange.BeginPos.nSecIndex != PlaceRange.EndPos.nSecIndex) { | 407 if (PlaceRange.BeginPos.nSecIndex != PlaceRange.EndPos.nSecIndex) { |
| 938 ClearEmptySections(PlaceRange); | 408 ClearEmptySections(PlaceRange); |
| 939 if (!bLastSecPos) { | 409 if (!bLastSecPos) |
| 940 LinkLatterSection(PlaceRange.BeginPos); | 410 LinkLatterSection(PlaceRange.BeginPos); |
| 941 } | |
| 942 } | 411 } |
| 943 return PlaceRange.BeginPos; | 412 return PlaceRange.BeginPos; |
| 944 } | 413 } |
| 414 |
| 945 CPVT_WordPlace CPDF_VariableText::DeleteWord(const CPVT_WordPlace& place) { | 415 CPVT_WordPlace CPDF_VariableText::DeleteWord(const CPVT_WordPlace& place) { |
| 946 return ClearRightWord(AdjustLineHeader(place, TRUE)); | 416 return ClearRightWord(AdjustLineHeader(place, TRUE)); |
| 947 } | 417 } |
| 418 |
| 948 CPVT_WordPlace CPDF_VariableText::BackSpaceWord(const CPVT_WordPlace& place) { | 419 CPVT_WordPlace CPDF_VariableText::BackSpaceWord(const CPVT_WordPlace& place) { |
| 949 return ClearLeftWord(AdjustLineHeader(place, TRUE)); | 420 return ClearLeftWord(AdjustLineHeader(place, TRUE)); |
| 950 } | 421 } |
| 422 |
| 951 void CPDF_VariableText::SetText(const FX_WCHAR* text, | 423 void CPDF_VariableText::SetText(const FX_WCHAR* text, |
| 952 int32_t charset, | 424 int32_t charset, |
| 953 const CPVT_SecProps* pSecProps, | 425 const CPVT_SecProps* pSecProps, |
| 954 const CPVT_WordProps* pWordProps) { | 426 const CPVT_WordProps* pWordProps) { |
| 955 DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); | 427 DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); |
| 956 CFX_WideString swText = text; | 428 CFX_WideString swText = text; |
| 957 CPVT_WordPlace wp(0, 0, -1); | 429 CPVT_WordPlace wp(0, 0, -1); |
| 958 CPVT_SectionInfo secinfo; | 430 CPVT_SectionInfo secinfo; |
| 959 if (m_bRichText) { | 431 if (m_bRichText) { |
| 960 if (pSecProps) { | 432 if (pSecProps) |
| 961 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); | 433 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); |
| 962 } | 434 if (pWordProps) |
| 963 if (pWordProps) { | |
| 964 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); | 435 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); |
| 965 } | |
| 966 } | 436 } |
| 967 if (CSection* pSection = m_SectionArray.GetAt(0)) { | 437 if (CSection* pSection = m_SectionArray.GetAt(0)) |
| 968 pSection->m_SecInfo = secinfo; | 438 pSection->m_SecInfo = secinfo; |
| 969 } | 439 |
| 970 int32_t nCharCount = 0; | 440 int32_t nCharCount = 0; |
| 971 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { | 441 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { |
| 972 if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) { | 442 if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) |
| 973 break; | 443 break; |
| 974 } | 444 if (m_nCharArray > 0 && nCharCount >= m_nCharArray) |
| 975 if (m_nCharArray > 0 && nCharCount >= m_nCharArray) { | |
| 976 break; | 445 break; |
| 977 } | 446 |
| 978 uint16_t word = swText.GetAt(i); | 447 uint16_t word = swText.GetAt(i); |
| 979 switch (word) { | 448 switch (word) { |
| 980 case 0x0D: | 449 case 0x0D: |
| 981 if (m_bMultiLine) { | 450 if (m_bMultiLine) { |
| 982 if (swText.GetAt(i + 1) == 0x0A) { | 451 if (swText.GetAt(i + 1) == 0x0A) |
| 983 i += 1; | 452 i += 1; |
| 984 } | 453 |
| 985 wp.nSecIndex++; | 454 wp.nSecIndex++; |
| 986 wp.nLineIndex = 0; | 455 wp.nLineIndex = 0; |
| 987 wp.nWordIndex = -1; | 456 wp.nWordIndex = -1; |
| 988 AddSection(wp, secinfo); | 457 AddSection(wp, secinfo); |
| 989 } | 458 } |
| 990 break; | 459 break; |
| 991 case 0x0A: | 460 case 0x0A: |
| 992 if (m_bMultiLine) { | 461 if (m_bMultiLine) { |
| 993 if (swText.GetAt(i + 1) == 0x0D) { | 462 if (swText.GetAt(i + 1) == 0x0D) |
| 994 i += 1; | 463 i += 1; |
| 995 } | 464 |
| 996 wp.nSecIndex++; | 465 wp.nSecIndex++; |
| 997 wp.nLineIndex = 0; | 466 wp.nLineIndex = 0; |
| 998 wp.nWordIndex = -1; | 467 wp.nWordIndex = -1; |
| 999 AddSection(wp, secinfo); | 468 AddSection(wp, secinfo); |
| 1000 } | 469 } |
| 1001 break; | 470 break; |
| 1002 case 0x09: | 471 case 0x09: |
| 1003 word = 0x20; | 472 word = 0x20; |
| 1004 default: | 473 default: |
| 1005 wp = InsertWord(wp, word, charset, pWordProps); | 474 wp = InsertWord(wp, word, charset, pWordProps); |
| 1006 break; | 475 break; |
| 1007 } | 476 } |
| 1008 nCharCount++; | 477 nCharCount++; |
| 1009 } | 478 } |
| 1010 } | 479 } |
| 480 |
| 1011 void CPDF_VariableText::UpdateWordPlace(CPVT_WordPlace& place) const { | 481 void CPDF_VariableText::UpdateWordPlace(CPVT_WordPlace& place) const { |
| 1012 if (place.nSecIndex < 0) { | 482 if (place.nSecIndex < 0) |
| 1013 place = GetBeginWordPlace(); | 483 place = GetBeginWordPlace(); |
| 1014 } | 484 if (place.nSecIndex >= m_SectionArray.GetSize()) |
| 1015 if (place.nSecIndex >= m_SectionArray.GetSize()) { | |
| 1016 place = GetEndWordPlace(); | 485 place = GetEndWordPlace(); |
| 1017 } | 486 |
| 1018 place = AdjustLineHeader(place, TRUE); | 487 place = AdjustLineHeader(place, TRUE); |
| 1019 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 488 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) |
| 1020 pSection->UpdateWordPlace(place); | 489 pSection->UpdateWordPlace(place); |
| 1021 } | |
| 1022 } | 490 } |
| 491 |
| 1023 int32_t CPDF_VariableText::WordPlaceToWordIndex( | 492 int32_t CPDF_VariableText::WordPlaceToWordIndex( |
| 1024 const CPVT_WordPlace& place) const { | 493 const CPVT_WordPlace& place) const { |
| 1025 CPVT_WordPlace newplace = place; | 494 CPVT_WordPlace newplace = place; |
| 1026 UpdateWordPlace(newplace); | 495 UpdateWordPlace(newplace); |
| 1027 int32_t nIndex = 0; | 496 int32_t nIndex = 0; |
| 1028 int32_t i = 0; | 497 int32_t i = 0; |
| 1029 int32_t sz = 0; | 498 int32_t sz = 0; |
| 1030 for (i = 0, sz = m_SectionArray.GetSize(); i < sz && i < newplace.nSecIndex; | 499 for (i = 0, sz = m_SectionArray.GetSize(); i < sz && i < newplace.nSecIndex; |
| 1031 i++) { | 500 i++) { |
| 1032 if (CSection* pSection = m_SectionArray.GetAt(i)) { | 501 if (CSection* pSection = m_SectionArray.GetAt(i)) { |
| 1033 nIndex += pSection->m_WordArray.GetSize(); | 502 nIndex += pSection->m_WordArray.GetSize(); |
| 1034 if (i != m_SectionArray.GetSize() - 1) { | 503 if (i != m_SectionArray.GetSize() - 1) |
| 1035 nIndex += PVT_RETURN_LENGTH; | 504 nIndex += kReturnLength; |
| 1036 } | |
| 1037 } | 505 } |
| 1038 } | 506 } |
| 1039 if (i >= 0 && i < m_SectionArray.GetSize()) { | 507 if (i >= 0 && i < m_SectionArray.GetSize()) |
| 1040 nIndex += newplace.nWordIndex + PVT_RETURN_LENGTH; | 508 nIndex += newplace.nWordIndex + kReturnLength; |
| 1041 } | |
| 1042 return nIndex; | 509 return nIndex; |
| 1043 } | 510 } |
| 511 |
| 1044 CPVT_WordPlace CPDF_VariableText::WordIndexToWordPlace(int32_t index) const { | 512 CPVT_WordPlace CPDF_VariableText::WordIndexToWordPlace(int32_t index) const { |
| 1045 CPVT_WordPlace place = GetBeginWordPlace(); | 513 CPVT_WordPlace place = GetBeginWordPlace(); |
| 1046 int32_t nOldIndex = 0, nIndex = 0; | 514 int32_t nOldIndex = 0, nIndex = 0; |
| 1047 FX_BOOL bFind = FALSE; | 515 FX_BOOL bFind = FALSE; |
| 1048 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) { | 516 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) { |
| 1049 if (CSection* pSection = m_SectionArray.GetAt(i)) { | 517 if (CSection* pSection = m_SectionArray.GetAt(i)) { |
| 1050 nIndex += pSection->m_WordArray.GetSize(); | 518 nIndex += pSection->m_WordArray.GetSize(); |
| 1051 if (nIndex == index) { | 519 if (nIndex == index) { |
| 1052 place = pSection->GetEndWordPlace(); | 520 place = pSection->GetEndWordPlace(); |
| 1053 bFind = TRUE; | 521 bFind = TRUE; |
| 1054 break; | 522 break; |
| 1055 } else if (nIndex > index) { | 523 } else if (nIndex > index) { |
| 1056 place.nSecIndex = i; | 524 place.nSecIndex = i; |
| 1057 place.nWordIndex = index - nOldIndex - 1; | 525 place.nWordIndex = index - nOldIndex - 1; |
| 1058 pSection->UpdateWordPlace(place); | 526 pSection->UpdateWordPlace(place); |
| 1059 bFind = TRUE; | 527 bFind = TRUE; |
| 1060 break; | 528 break; |
| 1061 } | 529 } |
| 1062 if (i != m_SectionArray.GetSize() - 1) { | 530 if (i != m_SectionArray.GetSize() - 1) |
| 1063 nIndex += PVT_RETURN_LENGTH; | 531 nIndex += kReturnLength; |
| 1064 } | |
| 1065 nOldIndex = nIndex; | 532 nOldIndex = nIndex; |
| 1066 } | 533 } |
| 1067 } | 534 } |
| 1068 if (!bFind) { | 535 if (!bFind) |
| 1069 place = GetEndWordPlace(); | 536 place = GetEndWordPlace(); |
| 1070 } | |
| 1071 return place; | 537 return place; |
| 1072 } | 538 } |
| 539 |
| 1073 CPVT_WordPlace CPDF_VariableText::GetBeginWordPlace() const { | 540 CPVT_WordPlace CPDF_VariableText::GetBeginWordPlace() const { |
| 1074 return m_bInitial ? CPVT_WordPlace(0, 0, -1) : CPVT_WordPlace(); | 541 return m_bInitial ? CPVT_WordPlace(0, 0, -1) : CPVT_WordPlace(); |
| 1075 } | 542 } |
| 543 |
| 1076 CPVT_WordPlace CPDF_VariableText::GetEndWordPlace() const { | 544 CPVT_WordPlace CPDF_VariableText::GetEndWordPlace() const { |
| 1077 if (CSection* pSection = m_SectionArray.GetAt(m_SectionArray.GetSize() - 1)) { | 545 if (CSection* pSection = m_SectionArray.GetAt(m_SectionArray.GetSize() - 1)) |
| 1078 return pSection->GetEndWordPlace(); | 546 return pSection->GetEndWordPlace(); |
| 1079 } | |
| 1080 return CPVT_WordPlace(); | 547 return CPVT_WordPlace(); |
| 1081 } | 548 } |
| 549 |
| 1082 CPVT_WordPlace CPDF_VariableText::GetPrevWordPlace( | 550 CPVT_WordPlace CPDF_VariableText::GetPrevWordPlace( |
| 1083 const CPVT_WordPlace& place) const { | 551 const CPVT_WordPlace& place) const { |
| 1084 if (place.nSecIndex < 0) { | 552 if (place.nSecIndex < 0) |
| 1085 return GetBeginWordPlace(); | 553 return GetBeginWordPlace(); |
| 1086 } | 554 if (place.nSecIndex >= m_SectionArray.GetSize()) |
| 1087 if (place.nSecIndex >= m_SectionArray.GetSize()) { | |
| 1088 return GetEndWordPlace(); | 555 return GetEndWordPlace(); |
| 1089 } | |
| 1090 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 556 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1091 if (place.WordCmp(pSection->GetBeginWordPlace()) <= 0) { | 557 if (place.WordCmp(pSection->GetBeginWordPlace()) <= 0) { |
| 1092 if (CSection* pPrevSection = m_SectionArray.GetAt(place.nSecIndex - 1)) { | 558 if (CSection* pPrevSection = m_SectionArray.GetAt(place.nSecIndex - 1)) |
| 1093 return pPrevSection->GetEndWordPlace(); | 559 return pPrevSection->GetEndWordPlace(); |
| 1094 } | |
| 1095 return GetBeginWordPlace(); | 560 return GetBeginWordPlace(); |
| 1096 } | 561 } |
| 1097 return pSection->GetPrevWordPlace(place); | 562 return pSection->GetPrevWordPlace(place); |
| 1098 } | 563 } |
| 1099 return place; | 564 return place; |
| 1100 } | 565 } |
| 566 |
| 1101 CPVT_WordPlace CPDF_VariableText::GetNextWordPlace( | 567 CPVT_WordPlace CPDF_VariableText::GetNextWordPlace( |
| 1102 const CPVT_WordPlace& place) const { | 568 const CPVT_WordPlace& place) const { |
| 1103 if (place.nSecIndex < 0) { | 569 if (place.nSecIndex < 0) |
| 1104 return GetBeginWordPlace(); | 570 return GetBeginWordPlace(); |
| 1105 } | 571 if (place.nSecIndex >= m_SectionArray.GetSize()) |
| 1106 if (place.nSecIndex >= m_SectionArray.GetSize()) { | |
| 1107 return GetEndWordPlace(); | 572 return GetEndWordPlace(); |
| 1108 } | |
| 1109 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 573 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1110 if (place.WordCmp(pSection->GetEndWordPlace()) >= 0) { | 574 if (place.WordCmp(pSection->GetEndWordPlace()) >= 0) { |
| 1111 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { | 575 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) |
| 1112 return pNextSection->GetBeginWordPlace(); | 576 return pNextSection->GetBeginWordPlace(); |
| 1113 } | |
| 1114 return GetEndWordPlace(); | 577 return GetEndWordPlace(); |
| 1115 } | 578 } |
| 1116 return pSection->GetNextWordPlace(place); | 579 return pSection->GetNextWordPlace(place); |
| 1117 } | 580 } |
| 1118 return place; | 581 return place; |
| 1119 } | 582 } |
| 583 |
| 1120 CPVT_WordPlace CPDF_VariableText::SearchWordPlace( | 584 CPVT_WordPlace CPDF_VariableText::SearchWordPlace( |
| 1121 const CFX_FloatPoint& point) const { | 585 const CFX_FloatPoint& point) const { |
| 1122 CFX_FloatPoint pt = OutToIn(point); | 586 CFX_FloatPoint pt = OutToIn(point); |
| 1123 CPVT_WordPlace place = GetBeginWordPlace(); | 587 CPVT_WordPlace place = GetBeginWordPlace(); |
| 1124 int32_t nLeft = 0; | 588 int32_t nLeft = 0; |
| 1125 int32_t nRight = m_SectionArray.GetSize() - 1; | 589 int32_t nRight = m_SectionArray.GetSize() - 1; |
| 1126 int32_t nMid = m_SectionArray.GetSize() / 2; | 590 int32_t nMid = m_SectionArray.GetSize() / 2; |
| 1127 FX_BOOL bUp = TRUE; | 591 FX_BOOL bUp = TRUE; |
| 1128 FX_BOOL bDown = TRUE; | 592 FX_BOOL bDown = TRUE; |
| 1129 while (nLeft <= nRight) { | 593 while (nLeft <= nRight) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1146 place = pSection->SearchWordPlace( | 610 place = pSection->SearchWordPlace( |
| 1147 CFX_FloatPoint(pt.x - pSection->m_SecInfo.rcSection.left, | 611 CFX_FloatPoint(pt.x - pSection->m_SecInfo.rcSection.left, |
| 1148 pt.y - pSection->m_SecInfo.rcSection.top)); | 612 pt.y - pSection->m_SecInfo.rcSection.top)); |
| 1149 place.nSecIndex = nMid; | 613 place.nSecIndex = nMid; |
| 1150 return place; | 614 return place; |
| 1151 } | 615 } |
| 1152 } else { | 616 } else { |
| 1153 break; | 617 break; |
| 1154 } | 618 } |
| 1155 } | 619 } |
| 1156 if (bUp) { | 620 if (bUp) |
| 1157 place = GetBeginWordPlace(); | 621 place = GetBeginWordPlace(); |
| 1158 } | 622 if (bDown) |
| 1159 if (bDown) { | |
| 1160 place = GetEndWordPlace(); | 623 place = GetEndWordPlace(); |
| 1161 } | |
| 1162 return place; | 624 return place; |
| 1163 } | 625 } |
| 626 |
| 1164 CPVT_WordPlace CPDF_VariableText::GetUpWordPlace( | 627 CPVT_WordPlace CPDF_VariableText::GetUpWordPlace( |
| 1165 const CPVT_WordPlace& place, | 628 const CPVT_WordPlace& place, |
| 1166 const CFX_FloatPoint& point) const { | 629 const CFX_FloatPoint& point) const { |
| 1167 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 630 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1168 CPVT_WordPlace temp = place; | 631 CPVT_WordPlace temp = place; |
| 1169 CFX_FloatPoint pt = OutToIn(point); | 632 CFX_FloatPoint pt = OutToIn(point); |
| 1170 if (temp.nLineIndex-- > 0) { | 633 if (temp.nLineIndex-- > 0) { |
| 1171 return pSection->SearchWordPlace( | 634 return pSection->SearchWordPlace( |
| 1172 pt.x - pSection->m_SecInfo.rcSection.left, temp); | 635 pt.x - pSection->m_SecInfo.rcSection.left, temp); |
| 1173 } | 636 } |
| 1174 if (temp.nSecIndex-- > 0) { | 637 if (temp.nSecIndex-- > 0) { |
| 1175 if (CSection* pLastSection = m_SectionArray.GetAt(temp.nSecIndex)) { | 638 if (CSection* pLastSection = m_SectionArray.GetAt(temp.nSecIndex)) { |
| 1176 temp.nLineIndex = pLastSection->m_LineArray.GetSize() - 1; | 639 temp.nLineIndex = pLastSection->m_LineArray.GetSize() - 1; |
| 1177 return pLastSection->SearchWordPlace( | 640 return pLastSection->SearchWordPlace( |
| 1178 pt.x - pLastSection->m_SecInfo.rcSection.left, temp); | 641 pt.x - pLastSection->m_SecInfo.rcSection.left, temp); |
| 1179 } | 642 } |
| 1180 } | 643 } |
| 1181 } | 644 } |
| 1182 return place; | 645 return place; |
| 1183 } | 646 } |
| 647 |
| 1184 CPVT_WordPlace CPDF_VariableText::GetDownWordPlace( | 648 CPVT_WordPlace CPDF_VariableText::GetDownWordPlace( |
| 1185 const CPVT_WordPlace& place, | 649 const CPVT_WordPlace& place, |
| 1186 const CFX_FloatPoint& point) const { | 650 const CFX_FloatPoint& point) const { |
| 1187 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 651 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1188 CPVT_WordPlace temp = place; | 652 CPVT_WordPlace temp = place; |
| 1189 CFX_FloatPoint pt = OutToIn(point); | 653 CFX_FloatPoint pt = OutToIn(point); |
| 1190 if (temp.nLineIndex++ < pSection->m_LineArray.GetSize() - 1) { | 654 if (temp.nLineIndex++ < pSection->m_LineArray.GetSize() - 1) { |
| 1191 return pSection->SearchWordPlace( | 655 return pSection->SearchWordPlace( |
| 1192 pt.x - pSection->m_SecInfo.rcSection.left, temp); | 656 pt.x - pSection->m_SecInfo.rcSection.left, temp); |
| 1193 } | 657 } |
| 1194 if (temp.nSecIndex++ < m_SectionArray.GetSize() - 1) { | 658 if (temp.nSecIndex++ < m_SectionArray.GetSize() - 1) { |
| 1195 if (CSection* pNextSection = m_SectionArray.GetAt(temp.nSecIndex)) { | 659 if (CSection* pNextSection = m_SectionArray.GetAt(temp.nSecIndex)) { |
| 1196 temp.nLineIndex = 0; | 660 temp.nLineIndex = 0; |
| 1197 return pNextSection->SearchWordPlace( | 661 return pNextSection->SearchWordPlace( |
| 1198 pt.x - pSection->m_SecInfo.rcSection.left, temp); | 662 pt.x - pSection->m_SecInfo.rcSection.left, temp); |
| 1199 } | 663 } |
| 1200 } | 664 } |
| 1201 } | 665 } |
| 1202 return place; | 666 return place; |
| 1203 } | 667 } |
| 668 |
| 1204 CPVT_WordPlace CPDF_VariableText::GetLineBeginPlace( | 669 CPVT_WordPlace CPDF_VariableText::GetLineBeginPlace( |
| 1205 const CPVT_WordPlace& place) const { | 670 const CPVT_WordPlace& place) const { |
| 1206 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); | 671 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); |
| 1207 } | 672 } |
| 673 |
| 1208 CPVT_WordPlace CPDF_VariableText::GetLineEndPlace( | 674 CPVT_WordPlace CPDF_VariableText::GetLineEndPlace( |
| 1209 const CPVT_WordPlace& place) const { | 675 const CPVT_WordPlace& place) const { |
| 1210 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 676 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1211 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) | 677 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) |
| 1212 return pLine->GetEndWordPlace(); | 678 return pLine->GetEndWordPlace(); |
| 1213 } | 679 } |
| 1214 return place; | 680 return place; |
| 1215 } | 681 } |
| 682 |
| 1216 CPVT_WordPlace CPDF_VariableText::GetSectionBeginPlace( | 683 CPVT_WordPlace CPDF_VariableText::GetSectionBeginPlace( |
| 1217 const CPVT_WordPlace& place) const { | 684 const CPVT_WordPlace& place) const { |
| 1218 return CPVT_WordPlace(place.nSecIndex, 0, -1); | 685 return CPVT_WordPlace(place.nSecIndex, 0, -1); |
| 1219 } | 686 } |
| 687 |
| 1220 CPVT_WordPlace CPDF_VariableText::GetSectionEndPlace( | 688 CPVT_WordPlace CPDF_VariableText::GetSectionEndPlace( |
| 1221 const CPVT_WordPlace& place) const { | 689 const CPVT_WordPlace& place) const { |
| 1222 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 690 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) |
| 1223 return pSection->GetEndWordPlace(); | 691 return pSection->GetEndWordPlace(); |
| 1224 } | |
| 1225 return place; | 692 return place; |
| 1226 } | 693 } |
| 694 |
| 1227 int32_t CPDF_VariableText::GetTotalWords() const { | 695 int32_t CPDF_VariableText::GetTotalWords() const { |
| 1228 int32_t nTotal = 0; | 696 int32_t nTotal = 0; |
| 1229 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) | 697 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) { |
| 1230 if (CSection* pSection = m_SectionArray.GetAt(i)) { | 698 if (CSection* pSection = m_SectionArray.GetAt(i)) |
| 1231 nTotal += (pSection->m_WordArray.GetSize() + PVT_RETURN_LENGTH); | 699 nTotal += (pSection->m_WordArray.GetSize() + kReturnLength); |
| 1232 } | 700 } |
| 1233 return nTotal - PVT_RETURN_LENGTH; | 701 |
| 702 return nTotal - kReturnLength; |
| 1234 } | 703 } |
| 704 |
| 1235 void CPDF_VariableText::ResetSectionArray() { | 705 void CPDF_VariableText::ResetSectionArray() { |
| 1236 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { | 706 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) |
| 1237 delete m_SectionArray.GetAt(s); | 707 delete m_SectionArray.GetAt(s); |
| 1238 } | 708 |
| 1239 m_SectionArray.RemoveAll(); | 709 m_SectionArray.RemoveAll(); |
| 1240 } | 710 } |
| 711 |
| 1241 CPVT_WordPlace CPDF_VariableText::AddSection(const CPVT_WordPlace& place, | 712 CPVT_WordPlace CPDF_VariableText::AddSection(const CPVT_WordPlace& place, |
| 1242 const CPVT_SectionInfo& secinfo) { | 713 const CPVT_SectionInfo& secinfo) { |
| 1243 if (IsValid() && !m_bMultiLine) { | 714 if (IsValid() && !m_bMultiLine) |
| 1244 return place; | 715 return place; |
| 1245 } | 716 |
| 1246 int32_t nSecIndex = | 717 int32_t nSecIndex = |
| 1247 std::max(std::min(place.nSecIndex, m_SectionArray.GetSize()), 0); | 718 std::max(std::min(place.nSecIndex, m_SectionArray.GetSize()), 0); |
| 1248 CSection* pSection = new CSection(this); | 719 CSection* pSection = new CSection(this); |
| 1249 pSection->m_SecInfo = secinfo; | 720 pSection->m_SecInfo = secinfo; |
| 1250 pSection->SecPlace.nSecIndex = nSecIndex; | 721 pSection->SecPlace.nSecIndex = nSecIndex; |
| 1251 if (nSecIndex == m_SectionArray.GetSize()) { | 722 if (nSecIndex == m_SectionArray.GetSize()) |
| 1252 m_SectionArray.Add(pSection); | 723 m_SectionArray.Add(pSection); |
| 1253 } else { | 724 else |
| 1254 m_SectionArray.InsertAt(nSecIndex, pSection); | 725 m_SectionArray.InsertAt(nSecIndex, pSection); |
| 1255 } | 726 |
| 1256 return place; | 727 return place; |
| 1257 } | 728 } |
| 729 |
| 1258 CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace& place, | 730 CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace& place, |
| 1259 const CPVT_LineInfo& lineinfo) { | 731 const CPVT_LineInfo& lineinfo) { |
| 1260 if (m_SectionArray.IsEmpty()) { | 732 if (m_SectionArray.IsEmpty()) |
| 1261 return place; | 733 return place; |
| 1262 } | 734 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) |
| 1263 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1264 return pSection->AddLine(lineinfo); | 735 return pSection->AddLine(lineinfo); |
| 1265 } | |
| 1266 return place; | 736 return place; |
| 1267 } | 737 } |
| 738 |
| 1268 CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace& place, | 739 CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace& place, |
| 1269 const CPVT_WordInfo& wordinfo) { | 740 const CPVT_WordInfo& wordinfo) { |
| 1270 if (m_SectionArray.GetSize() <= 0) { | 741 if (m_SectionArray.GetSize() <= 0) { |
| 1271 return place; | 742 return place; |
| 1272 } | 743 } |
| 1273 CPVT_WordPlace newplace = place; | 744 CPVT_WordPlace newplace = place; |
| 1274 newplace.nSecIndex = | 745 newplace.nSecIndex = |
| 1275 std::max(std::min(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0); | 746 std::max(std::min(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0); |
| 1276 if (CSection* pSection = m_SectionArray.GetAt(newplace.nSecIndex)) { | 747 if (CSection* pSection = m_SectionArray.GetAt(newplace.nSecIndex)) |
| 1277 return pSection->AddWord(newplace, wordinfo); | 748 return pSection->AddWord(newplace, wordinfo); |
| 1278 } | |
| 1279 return place; | 749 return place; |
| 1280 } | 750 } |
| 751 |
| 1281 FX_BOOL CPDF_VariableText::GetWordInfo(const CPVT_WordPlace& place, | 752 FX_BOOL CPDF_VariableText::GetWordInfo(const CPVT_WordPlace& place, |
| 1282 CPVT_WordInfo& wordinfo) { | 753 CPVT_WordInfo& wordinfo) { |
| 1283 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 754 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1284 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) { | 755 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) { |
| 1285 wordinfo = *pWord; | 756 wordinfo = *pWord; |
| 1286 return TRUE; | 757 return TRUE; |
| 1287 } | 758 } |
| 1288 } | 759 } |
| 1289 return FALSE; | 760 return FALSE; |
| 1290 } | 761 } |
| 762 |
| 1291 FX_BOOL CPDF_VariableText::SetWordInfo(const CPVT_WordPlace& place, | 763 FX_BOOL CPDF_VariableText::SetWordInfo(const CPVT_WordPlace& place, |
| 1292 const CPVT_WordInfo& wordinfo) { | 764 const CPVT_WordInfo& wordinfo) { |
| 1293 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 765 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1294 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) { | 766 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) { |
| 1295 *pWord = wordinfo; | 767 *pWord = wordinfo; |
| 1296 return TRUE; | 768 return TRUE; |
| 1297 } | 769 } |
| 1298 } | 770 } |
| 1299 return FALSE; | 771 return FALSE; |
| 1300 } | 772 } |
| 773 |
| 1301 FX_BOOL CPDF_VariableText::GetLineInfo(const CPVT_WordPlace& place, | 774 FX_BOOL CPDF_VariableText::GetLineInfo(const CPVT_WordPlace& place, |
| 1302 CPVT_LineInfo& lineinfo) { | 775 CPVT_LineInfo& lineinfo) { |
| 1303 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 776 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1304 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) { | 777 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) { |
| 1305 lineinfo = pLine->m_LineInfo; | 778 lineinfo = pLine->m_LineInfo; |
| 1306 return TRUE; | 779 return TRUE; |
| 1307 } | 780 } |
| 1308 } | 781 } |
| 1309 return FALSE; | 782 return FALSE; |
| 1310 } | 783 } |
| 784 |
| 1311 FX_BOOL CPDF_VariableText::GetSectionInfo(const CPVT_WordPlace& place, | 785 FX_BOOL CPDF_VariableText::GetSectionInfo(const CPVT_WordPlace& place, |
| 1312 CPVT_SectionInfo& secinfo) { | 786 CPVT_SectionInfo& secinfo) { |
| 1313 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 787 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1314 secinfo = pSection->m_SecInfo; | 788 secinfo = pSection->m_SecInfo; |
| 1315 return TRUE; | 789 return TRUE; |
| 1316 } | 790 } |
| 1317 return FALSE; | 791 return FALSE; |
| 1318 } | 792 } |
| 793 |
| 1319 CFX_FloatRect CPDF_VariableText::GetContentRect() const { | 794 CFX_FloatRect CPDF_VariableText::GetContentRect() const { |
| 1320 return InToOut(CPVT_FloatRect(CPDF_EditContainer::GetContentRect())); | 795 return InToOut(CPVT_FloatRect(CPDF_EditContainer::GetContentRect())); |
| 1321 } | 796 } |
| 797 |
| 1322 FX_FLOAT CPDF_VariableText::GetWordFontSize(const CPVT_WordInfo& WordInfo, | 798 FX_FLOAT CPDF_VariableText::GetWordFontSize(const CPVT_WordInfo& WordInfo, |
| 1323 FX_BOOL bFactFontSize) { | 799 FX_BOOL bFactFontSize) { |
| 1324 return m_bRichText && WordInfo.pWordProps | 800 return m_bRichText && WordInfo.pWordProps |
| 1325 ? (WordInfo.pWordProps->nScriptType == PVTWORD_SCRIPT_NORMAL || | 801 ? (WordInfo.pWordProps->nScriptType == ScriptType::Normal || |
| 1326 bFactFontSize | 802 bFactFontSize |
| 1327 ? WordInfo.pWordProps->fFontSize | 803 ? WordInfo.pWordProps->fFontSize |
| 1328 : WordInfo.pWordProps->fFontSize * PVT_HALF) | 804 : WordInfo.pWordProps->fFontSize * VARIABLETEXT_HALF) |
| 1329 : GetFontSize(); | 805 : GetFontSize(); |
| 1330 } | 806 } |
| 807 |
| 1331 int32_t CPDF_VariableText::GetWordFontIndex(const CPVT_WordInfo& WordInfo) { | 808 int32_t CPDF_VariableText::GetWordFontIndex(const CPVT_WordInfo& WordInfo) { |
| 1332 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nFontIndex | 809 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nFontIndex |
| 1333 : WordInfo.nFontIndex; | 810 : WordInfo.nFontIndex; |
| 1334 } | 811 } |
| 812 |
| 1335 FX_FLOAT CPDF_VariableText::GetWordWidth(int32_t nFontIndex, | 813 FX_FLOAT CPDF_VariableText::GetWordWidth(int32_t nFontIndex, |
| 1336 uint16_t Word, | 814 uint16_t Word, |
| 1337 uint16_t SubWord, | 815 uint16_t SubWord, |
| 1338 FX_FLOAT fCharSpace, | 816 FX_FLOAT fCharSpace, |
| 1339 int32_t nHorzScale, | 817 int32_t nHorzScale, |
| 1340 FX_FLOAT fFontSize, | 818 FX_FLOAT fFontSize, |
| 1341 FX_FLOAT fWordTail, | 819 FX_FLOAT fWordTail, |
| 1342 int32_t nWordStyle) { | 820 int32_t nWordStyle) { |
| 1343 return (GetCharWidth(nFontIndex, Word, SubWord, nWordStyle) * fFontSize * | 821 return (GetCharWidth(nFontIndex, Word, SubWord, nWordStyle) * fFontSize * |
| 1344 PVT_FONTSCALE + | 822 kFontScale + |
| 1345 fCharSpace) * | 823 fCharSpace) * |
| 1346 nHorzScale * PVT_PERCENT + | 824 nHorzScale * kScalePercent + |
| 1347 fWordTail; | 825 fWordTail; |
| 1348 } | 826 } |
| 827 |
| 1349 FX_FLOAT CPDF_VariableText::GetWordWidth(const CPVT_WordInfo& WordInfo) { | 828 FX_FLOAT CPDF_VariableText::GetWordWidth(const CPVT_WordInfo& WordInfo) { |
| 1350 return GetWordWidth( | 829 return GetWordWidth( |
| 1351 GetWordFontIndex(WordInfo), WordInfo.Word, GetSubWord(), | 830 GetWordFontIndex(WordInfo), WordInfo.Word, GetSubWord(), |
| 1352 GetCharSpace(WordInfo), GetHorzScale(WordInfo), GetWordFontSize(WordInfo), | 831 GetCharSpace(WordInfo), GetHorzScale(WordInfo), GetWordFontSize(WordInfo), |
| 1353 WordInfo.fWordTail, | 832 WordInfo.fWordTail, |
| 1354 WordInfo.pWordProps ? WordInfo.pWordProps->nWordStyle : 0); | 833 WordInfo.pWordProps ? WordInfo.pWordProps->nWordStyle : 0); |
| 1355 } | 834 } |
| 835 |
| 1356 FX_FLOAT CPDF_VariableText::GetLineAscent(const CPVT_SectionInfo& SecInfo) { | 836 FX_FLOAT CPDF_VariableText::GetLineAscent(const CPVT_SectionInfo& SecInfo) { |
| 1357 return m_bRichText && SecInfo.pWordProps | 837 return m_bRichText && SecInfo.pWordProps |
| 1358 ? GetFontAscent(SecInfo.pWordProps->nFontIndex, | 838 ? GetFontAscent(SecInfo.pWordProps->nFontIndex, |
| 1359 SecInfo.pWordProps->fFontSize) | 839 SecInfo.pWordProps->fFontSize) |
| 1360 : GetFontAscent(GetDefaultFontIndex(), GetFontSize()); | 840 : GetFontAscent(GetDefaultFontIndex(), GetFontSize()); |
| 1361 } | 841 } |
| 842 |
| 1362 FX_FLOAT CPDF_VariableText::GetLineDescent(const CPVT_SectionInfo& SecInfo) { | 843 FX_FLOAT CPDF_VariableText::GetLineDescent(const CPVT_SectionInfo& SecInfo) { |
| 1363 return m_bRichText && SecInfo.pWordProps | 844 return m_bRichText && SecInfo.pWordProps |
| 1364 ? GetFontDescent(SecInfo.pWordProps->nFontIndex, | 845 ? GetFontDescent(SecInfo.pWordProps->nFontIndex, |
| 1365 SecInfo.pWordProps->fFontSize) | 846 SecInfo.pWordProps->fFontSize) |
| 1366 : GetFontDescent(GetDefaultFontIndex(), GetFontSize()); | 847 : GetFontDescent(GetDefaultFontIndex(), GetFontSize()); |
| 1367 } | 848 } |
| 849 |
| 1368 FX_FLOAT CPDF_VariableText::GetFontAscent(int32_t nFontIndex, | 850 FX_FLOAT CPDF_VariableText::GetFontAscent(int32_t nFontIndex, |
| 1369 FX_FLOAT fFontSize) { | 851 FX_FLOAT fFontSize) { |
| 1370 return (FX_FLOAT)GetTypeAscent(nFontIndex) * fFontSize * PVT_FONTSCALE; | 852 return (FX_FLOAT)GetTypeAscent(nFontIndex) * fFontSize * kFontScale; |
| 1371 } | 853 } |
| 854 |
| 1372 FX_FLOAT CPDF_VariableText::GetFontDescent(int32_t nFontIndex, | 855 FX_FLOAT CPDF_VariableText::GetFontDescent(int32_t nFontIndex, |
| 1373 FX_FLOAT fFontSize) { | 856 FX_FLOAT fFontSize) { |
| 1374 return (FX_FLOAT)GetTypeDescent(nFontIndex) * fFontSize * PVT_FONTSCALE; | 857 return (FX_FLOAT)GetTypeDescent(nFontIndex) * fFontSize * kFontScale; |
| 1375 } | 858 } |
| 859 |
| 1376 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo, | 860 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo, |
| 1377 FX_FLOAT fFontSize) { | 861 FX_FLOAT fFontSize) { |
| 1378 return GetFontAscent(GetWordFontIndex(WordInfo), fFontSize); | 862 return GetFontAscent(GetWordFontIndex(WordInfo), fFontSize); |
| 1379 } | 863 } |
| 864 |
| 1380 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo, | 865 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo, |
| 1381 FX_FLOAT fFontSize) { | 866 FX_FLOAT fFontSize) { |
| 1382 return GetFontDescent(GetWordFontIndex(WordInfo), fFontSize); | 867 return GetFontDescent(GetWordFontIndex(WordInfo), fFontSize); |
| 1383 } | 868 } |
| 869 |
| 1384 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo, | 870 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo, |
| 1385 FX_BOOL bFactFontSize) { | 871 FX_BOOL bFactFontSize) { |
| 1386 return GetFontAscent(GetWordFontIndex(WordInfo), | 872 return GetFontAscent(GetWordFontIndex(WordInfo), |
| 1387 GetWordFontSize(WordInfo, bFactFontSize)); | 873 GetWordFontSize(WordInfo, bFactFontSize)); |
| 1388 } | 874 } |
| 875 |
| 1389 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo, | 876 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo, |
| 1390 FX_BOOL bFactFontSize) { | 877 FX_BOOL bFactFontSize) { |
| 1391 return GetFontDescent(GetWordFontIndex(WordInfo), | 878 return GetFontDescent(GetWordFontIndex(WordInfo), |
| 1392 GetWordFontSize(WordInfo, bFactFontSize)); | 879 GetWordFontSize(WordInfo, bFactFontSize)); |
| 1393 } | 880 } |
| 881 |
| 1394 FX_FLOAT CPDF_VariableText::GetLineLeading(const CPVT_SectionInfo& SecInfo) { | 882 FX_FLOAT CPDF_VariableText::GetLineLeading(const CPVT_SectionInfo& SecInfo) { |
| 1395 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineLeading | 883 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineLeading |
| 1396 : m_fLineLeading; | 884 : m_fLineLeading; |
| 1397 } | 885 } |
| 886 |
| 1398 FX_FLOAT CPDF_VariableText::GetLineIndent(const CPVT_SectionInfo& SecInfo) { | 887 FX_FLOAT CPDF_VariableText::GetLineIndent(const CPVT_SectionInfo& SecInfo) { |
| 1399 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineIndent | 888 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineIndent |
| 1400 : 0.0f; | 889 : 0.0f; |
| 1401 } | 890 } |
| 891 |
| 1402 int32_t CPDF_VariableText::GetAlignment(const CPVT_SectionInfo& SecInfo) { | 892 int32_t CPDF_VariableText::GetAlignment(const CPVT_SectionInfo& SecInfo) { |
| 1403 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->nAlignment | 893 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->nAlignment |
| 1404 : m_nAlignment; | 894 : m_nAlignment; |
| 1405 } | 895 } |
| 896 |
| 1406 FX_FLOAT CPDF_VariableText::GetCharSpace(const CPVT_WordInfo& WordInfo) { | 897 FX_FLOAT CPDF_VariableText::GetCharSpace(const CPVT_WordInfo& WordInfo) { |
| 1407 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->fCharSpace | 898 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->fCharSpace |
| 1408 : m_fCharSpace; | 899 : m_fCharSpace; |
| 1409 } | 900 } |
| 901 |
| 1410 int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) { | 902 int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) { |
| 1411 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nHorzScale | 903 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nHorzScale |
| 1412 : m_nHorzScale; | 904 : m_nHorzScale; |
| 1413 } | 905 } |
| 906 |
| 1414 void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) { | 907 void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) { |
| 1415 CPVT_WordPlace wordplace = AdjustLineHeader(place, TRUE); | 908 CPVT_WordPlace wordplace = AdjustLineHeader(place, TRUE); |
| 1416 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 909 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1417 for (int32_t w = pSection->m_WordArray.GetSize() - 1; | 910 for (int32_t w = pSection->m_WordArray.GetSize() - 1; |
| 1418 w > wordplace.nWordIndex; w--) { | 911 w > wordplace.nWordIndex; w--) { |
| 1419 delete pSection->m_WordArray.GetAt(w); | 912 delete pSection->m_WordArray.GetAt(w); |
| 1420 pSection->m_WordArray.RemoveAt(w); | 913 pSection->m_WordArray.RemoveAt(w); |
| 1421 } | 914 } |
| 1422 } | 915 } |
| 1423 } | 916 } |
| 917 |
| 1424 CPVT_WordPlace CPDF_VariableText::AdjustLineHeader(const CPVT_WordPlace& place, | 918 CPVT_WordPlace CPDF_VariableText::AdjustLineHeader(const CPVT_WordPlace& place, |
| 1425 FX_BOOL bPrevOrNext) const { | 919 FX_BOOL bPrevOrNext) const { |
| 1426 if (place.nWordIndex < 0 && place.nLineIndex > 0) { | 920 if (place.nWordIndex < 0 && place.nLineIndex > 0) |
| 1427 return bPrevOrNext ? GetPrevWordPlace(place) : GetNextWordPlace(place); | 921 return bPrevOrNext ? GetPrevWordPlace(place) : GetNextWordPlace(place); |
| 1428 } | |
| 1429 return place; | 922 return place; |
| 1430 } | 923 } |
| 924 |
| 1431 FX_BOOL CPDF_VariableText::ClearEmptySection(const CPVT_WordPlace& place) { | 925 FX_BOOL CPDF_VariableText::ClearEmptySection(const CPVT_WordPlace& place) { |
| 1432 if (place.nSecIndex == 0 && m_SectionArray.GetSize() == 1) { | 926 if (place.nSecIndex == 0 && m_SectionArray.GetSize() == 1) |
| 1433 return FALSE; | 927 return FALSE; |
| 1434 } | |
| 1435 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 928 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1436 if (pSection->m_WordArray.GetSize() == 0) { | 929 if (pSection->m_WordArray.GetSize() == 0) { |
| 1437 delete pSection; | 930 delete pSection; |
| 1438 m_SectionArray.RemoveAt(place.nSecIndex); | 931 m_SectionArray.RemoveAt(place.nSecIndex); |
| 1439 return TRUE; | 932 return TRUE; |
| 1440 } | 933 } |
| 1441 } | 934 } |
| 1442 return FALSE; | 935 return FALSE; |
| 1443 } | 936 } |
| 937 |
| 1444 void CPDF_VariableText::ClearEmptySections(const CPVT_WordRange& PlaceRange) { | 938 void CPDF_VariableText::ClearEmptySections(const CPVT_WordRange& PlaceRange) { |
| 1445 CPVT_WordPlace wordplace; | 939 CPVT_WordPlace wordplace; |
| 1446 for (int32_t s = PlaceRange.EndPos.nSecIndex; | 940 for (int32_t s = PlaceRange.EndPos.nSecIndex; |
| 1447 s > PlaceRange.BeginPos.nSecIndex; s--) { | 941 s > PlaceRange.BeginPos.nSecIndex; s--) { |
| 1448 wordplace.nSecIndex = s; | 942 wordplace.nSecIndex = s; |
| 1449 ClearEmptySection(wordplace); | 943 ClearEmptySection(wordplace); |
| 1450 } | 944 } |
| 1451 } | 945 } |
| 946 |
| 1452 void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace& place) { | 947 void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace& place) { |
| 1453 CPVT_WordPlace oldplace = AdjustLineHeader(place, TRUE); | 948 CPVT_WordPlace oldplace = AdjustLineHeader(place, TRUE); |
| 1454 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { | 949 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { |
| 1455 if (CSection* pSection = m_SectionArray.GetAt(oldplace.nSecIndex)) { | 950 if (CSection* pSection = m_SectionArray.GetAt(oldplace.nSecIndex)) { |
| 1456 for (int32_t w = 0, sz = pNextSection->m_WordArray.GetSize(); w < sz; | 951 for (int32_t w = 0, sz = pNextSection->m_WordArray.GetSize(); w < sz; |
| 1457 w++) { | 952 w++) { |
| 1458 if (CPVT_WordInfo* pWord = pNextSection->m_WordArray.GetAt(w)) { | 953 if (CPVT_WordInfo* pWord = pNextSection->m_WordArray.GetAt(w)) { |
| 1459 oldplace.nWordIndex++; | 954 oldplace.nWordIndex++; |
| 1460 pSection->AddWord(oldplace, *pWord); | 955 pSection->AddWord(oldplace, *pWord); |
| 1461 } | 956 } |
| 1462 } | 957 } |
| 1463 } | 958 } |
| 1464 delete pNextSection; | 959 delete pNextSection; |
| 1465 m_SectionArray.RemoveAt(place.nSecIndex + 1); | 960 m_SectionArray.RemoveAt(place.nSecIndex + 1); |
| 1466 } | 961 } |
| 1467 } | 962 } |
| 963 |
| 1468 void CPDF_VariableText::ClearWords(const CPVT_WordRange& PlaceRange) { | 964 void CPDF_VariableText::ClearWords(const CPVT_WordRange& PlaceRange) { |
| 1469 CPVT_WordRange NewRange; | 965 CPVT_WordRange NewRange; |
| 1470 NewRange.BeginPos = AdjustLineHeader(PlaceRange.BeginPos, TRUE); | 966 NewRange.BeginPos = AdjustLineHeader(PlaceRange.BeginPos, TRUE); |
| 1471 NewRange.EndPos = AdjustLineHeader(PlaceRange.EndPos, TRUE); | 967 NewRange.EndPos = AdjustLineHeader(PlaceRange.EndPos, TRUE); |
| 1472 for (int32_t s = NewRange.EndPos.nSecIndex; s >= NewRange.BeginPos.nSecIndex; | 968 for (int32_t s = NewRange.EndPos.nSecIndex; s >= NewRange.BeginPos.nSecIndex; |
| 1473 s--) { | 969 s--) { |
| 1474 if (CSection* pSection = m_SectionArray.GetAt(s)) { | 970 if (CSection* pSection = m_SectionArray.GetAt(s)) |
| 1475 pSection->ClearWords(NewRange); | 971 pSection->ClearWords(NewRange); |
| 1476 } | |
| 1477 } | 972 } |
| 1478 } | 973 } |
| 974 |
| 1479 CPVT_WordPlace CPDF_VariableText::ClearLeftWord(const CPVT_WordPlace& place) { | 975 CPVT_WordPlace CPDF_VariableText::ClearLeftWord(const CPVT_WordPlace& place) { |
| 1480 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 976 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1481 CPVT_WordPlace leftplace = GetPrevWordPlace(place); | 977 CPVT_WordPlace leftplace = GetPrevWordPlace(place); |
| 1482 if (leftplace != place) { | 978 if (leftplace != place) { |
| 1483 if (leftplace.nSecIndex != place.nSecIndex) { | 979 if (leftplace.nSecIndex != place.nSecIndex) { |
| 1484 if (pSection->m_WordArray.GetSize() == 0) { | 980 if (pSection->m_WordArray.GetSize() == 0) |
| 1485 ClearEmptySection(place); | 981 ClearEmptySection(place); |
| 1486 } else { | 982 else |
| 1487 LinkLatterSection(leftplace); | 983 LinkLatterSection(leftplace); |
| 1488 } | |
| 1489 } else { | 984 } else { |
| 1490 pSection->ClearWord(place); | 985 pSection->ClearWord(place); |
| 1491 } | 986 } |
| 1492 } | 987 } |
| 1493 return leftplace; | 988 return leftplace; |
| 1494 } | 989 } |
| 1495 return place; | 990 return place; |
| 1496 } | 991 } |
| 992 |
| 1497 CPVT_WordPlace CPDF_VariableText::ClearRightWord(const CPVT_WordPlace& place) { | 993 CPVT_WordPlace CPDF_VariableText::ClearRightWord(const CPVT_WordPlace& place) { |
| 1498 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 994 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1499 CPVT_WordPlace rightplace = | 995 CPVT_WordPlace rightplace = |
| 1500 AdjustLineHeader(GetNextWordPlace(place), FALSE); | 996 AdjustLineHeader(GetNextWordPlace(place), FALSE); |
| 1501 if (rightplace != place) { | 997 if (rightplace != place) { |
| 1502 if (rightplace.nSecIndex != place.nSecIndex) { | 998 if (rightplace.nSecIndex != place.nSecIndex) |
| 1503 LinkLatterSection(place); | 999 LinkLatterSection(place); |
| 1504 } else { | 1000 else |
| 1505 pSection->ClearWord(rightplace); | 1001 pSection->ClearWord(rightplace); |
| 1506 } | |
| 1507 } | 1002 } |
| 1508 } | 1003 } |
| 1509 return place; | 1004 return place; |
| 1510 } | 1005 } |
| 1006 |
| 1511 void CPDF_VariableText::RearrangeAll() { | 1007 void CPDF_VariableText::RearrangeAll() { |
| 1512 Rearrange(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); | 1008 Rearrange(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); |
| 1513 } | 1009 } |
| 1010 |
| 1514 void CPDF_VariableText::RearrangePart(const CPVT_WordRange& PlaceRange) { | 1011 void CPDF_VariableText::RearrangePart(const CPVT_WordRange& PlaceRange) { |
| 1515 Rearrange(PlaceRange); | 1012 Rearrange(PlaceRange); |
| 1516 } | 1013 } |
| 1014 |
| 1517 CPVT_FloatRect CPDF_VariableText::Rearrange(const CPVT_WordRange& PlaceRange) { | 1015 CPVT_FloatRect CPDF_VariableText::Rearrange(const CPVT_WordRange& PlaceRange) { |
| 1518 CPVT_FloatRect rcRet; | 1016 CPVT_FloatRect rcRet; |
| 1519 if (IsValid()) { | 1017 if (IsValid()) { |
| 1520 if (m_bAutoFontSize) { | 1018 if (m_bAutoFontSize) { |
| 1521 SetFontSize(GetAutoFontSize()); | 1019 SetFontSize(GetAutoFontSize()); |
| 1522 rcRet = RearrangeSections( | 1020 rcRet = RearrangeSections( |
| 1523 CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); | 1021 CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); |
| 1524 } else { | 1022 } else { |
| 1525 rcRet = RearrangeSections(PlaceRange); | 1023 rcRet = RearrangeSections(PlaceRange); |
| 1526 } | 1024 } |
| 1527 } | 1025 } |
| 1528 SetContentRect(rcRet); | 1026 SetContentRect(rcRet); |
| 1529 return rcRet; | 1027 return rcRet; |
| 1530 } | 1028 } |
| 1029 |
| 1531 FX_FLOAT CPDF_VariableText::GetAutoFontSize() { | 1030 FX_FLOAT CPDF_VariableText::GetAutoFontSize() { |
| 1532 int32_t nTotal = sizeof(gFontSizeSteps) / sizeof(uint8_t); | 1031 int32_t nTotal = sizeof(gFontSizeSteps) / sizeof(uint8_t); |
| 1533 if (IsMultiLine()) { | 1032 if (IsMultiLine()) |
| 1534 nTotal /= 4; | 1033 nTotal /= 4; |
| 1535 } | 1034 if (nTotal <= 0) |
| 1536 if (nTotal <= 0) { | |
| 1537 return 0; | 1035 return 0; |
| 1538 } | 1036 if (GetPlateWidth() <= 0) |
| 1539 if (GetPlateWidth() <= 0) { | |
| 1540 return 0; | 1037 return 0; |
| 1541 } | 1038 |
| 1542 int32_t nLeft = 0; | 1039 int32_t nLeft = 0; |
| 1543 int32_t nRight = nTotal - 1; | 1040 int32_t nRight = nTotal - 1; |
| 1544 int32_t nMid = nTotal / 2; | 1041 int32_t nMid = nTotal / 2; |
| 1545 while (nLeft <= nRight) { | 1042 while (nLeft <= nRight) { |
| 1546 if (IsBigger(gFontSizeSteps[nMid])) { | 1043 if (IsBigger(gFontSizeSteps[nMid])) { |
| 1547 nRight = nMid - 1; | 1044 nRight = nMid - 1; |
| 1548 nMid = (nLeft + nRight) / 2; | 1045 nMid = (nLeft + nRight) / 2; |
| 1549 continue; | 1046 continue; |
| 1550 } else { | 1047 } else { |
| 1551 nLeft = nMid + 1; | 1048 nLeft = nMid + 1; |
| 1552 nMid = (nLeft + nRight) / 2; | 1049 nMid = (nLeft + nRight) / 2; |
| 1553 continue; | 1050 continue; |
| 1554 } | 1051 } |
| 1555 } | 1052 } |
| 1556 return (FX_FLOAT)gFontSizeSteps[nMid]; | 1053 return (FX_FLOAT)gFontSizeSteps[nMid]; |
| 1557 } | 1054 } |
| 1055 |
| 1558 FX_BOOL CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) { | 1056 FX_BOOL CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) { |
| 1559 FX_BOOL bBigger = FALSE; | 1057 FX_BOOL bBigger = FALSE; |
| 1560 CPVT_Size szTotal; | 1058 CPVT_Size szTotal; |
| 1561 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { | 1059 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { |
| 1562 if (CSection* pSection = m_SectionArray.GetAt(s)) { | 1060 if (CSection* pSection = m_SectionArray.GetAt(s)) { |
| 1563 CPVT_Size size = pSection->GetSectionSize(fFontSize); | 1061 CPVT_Size size = pSection->GetSectionSize(fFontSize); |
| 1564 szTotal.x = std::max(size.x, szTotal.x); | 1062 szTotal.x = std::max(size.x, szTotal.x); |
| 1565 szTotal.y += size.y; | 1063 szTotal.y += size.y; |
| 1566 if (IsFloatBigger(szTotal.x, GetPlateWidth()) || | 1064 if (IsFloatBigger(szTotal.x, GetPlateWidth()) || |
| 1567 IsFloatBigger(szTotal.y, GetPlateHeight())) { | 1065 IsFloatBigger(szTotal.y, GetPlateHeight())) { |
| 1568 bBigger = TRUE; | 1066 bBigger = TRUE; |
| 1569 break; | 1067 break; |
| 1570 } | 1068 } |
| 1571 } | 1069 } |
| 1572 } | 1070 } |
| 1573 return bBigger; | 1071 return bBigger; |
| 1574 } | 1072 } |
| 1073 |
| 1575 CPVT_FloatRect CPDF_VariableText::RearrangeSections( | 1074 CPVT_FloatRect CPDF_VariableText::RearrangeSections( |
| 1576 const CPVT_WordRange& PlaceRange) { | 1075 const CPVT_WordRange& PlaceRange) { |
| 1577 CPVT_WordPlace place; | 1076 CPVT_WordPlace place; |
| 1578 FX_FLOAT fPosY = 0; | 1077 FX_FLOAT fPosY = 0; |
| 1579 FX_FLOAT fOldHeight; | 1078 FX_FLOAT fOldHeight; |
| 1580 int32_t nSSecIndex = PlaceRange.BeginPos.nSecIndex; | 1079 int32_t nSSecIndex = PlaceRange.BeginPos.nSecIndex; |
| 1581 int32_t nESecIndex = PlaceRange.EndPos.nSecIndex; | 1080 int32_t nESecIndex = PlaceRange.EndPos.nSecIndex; |
| 1582 CPVT_FloatRect rcRet; | 1081 CPVT_FloatRect rcRet; |
| 1583 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { | 1082 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { |
| 1584 place.nSecIndex = s; | 1083 place.nSecIndex = s; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1605 rcRet.left = std::min(rcSec.left, rcRet.left); | 1104 rcRet.left = std::min(rcSec.left, rcRet.left); |
| 1606 rcRet.top = std::min(rcSec.top, rcRet.top); | 1105 rcRet.top = std::min(rcSec.top, rcRet.top); |
| 1607 rcRet.right = std::max(rcSec.right, rcRet.right); | 1106 rcRet.right = std::max(rcSec.right, rcRet.right); |
| 1608 rcRet.bottom = std::max(rcSec.bottom, rcRet.bottom); | 1107 rcRet.bottom = std::max(rcSec.bottom, rcRet.bottom); |
| 1609 } | 1108 } |
| 1610 fPosY += rcSec.Height(); | 1109 fPosY += rcSec.Height(); |
| 1611 } | 1110 } |
| 1612 } | 1111 } |
| 1613 return rcRet; | 1112 return rcRet; |
| 1614 } | 1113 } |
| 1114 |
| 1615 int32_t CPDF_VariableText::GetCharWidth(int32_t nFontIndex, | 1115 int32_t CPDF_VariableText::GetCharWidth(int32_t nFontIndex, |
| 1616 uint16_t Word, | 1116 uint16_t Word, |
| 1617 uint16_t SubWord, | 1117 uint16_t SubWord, |
| 1618 int32_t nWordStyle) { | 1118 int32_t nWordStyle) { |
| 1619 if (!m_pVTProvider) { | 1119 if (!m_pVTProvider) |
| 1620 return 0; | 1120 return 0; |
| 1621 } | 1121 if (SubWord > 0) |
| 1622 if (SubWord > 0) { | |
| 1623 return m_pVTProvider->GetCharWidth(nFontIndex, SubWord, nWordStyle); | 1122 return m_pVTProvider->GetCharWidth(nFontIndex, SubWord, nWordStyle); |
| 1624 } | |
| 1625 return m_pVTProvider->GetCharWidth(nFontIndex, Word, nWordStyle); | 1123 return m_pVTProvider->GetCharWidth(nFontIndex, Word, nWordStyle); |
| 1626 } | 1124 } |
| 1125 |
| 1627 int32_t CPDF_VariableText::GetTypeAscent(int32_t nFontIndex) { | 1126 int32_t CPDF_VariableText::GetTypeAscent(int32_t nFontIndex) { |
| 1628 return m_pVTProvider ? m_pVTProvider->GetTypeAscent(nFontIndex) : 0; | 1127 return m_pVTProvider ? m_pVTProvider->GetTypeAscent(nFontIndex) : 0; |
| 1629 } | 1128 } |
| 1129 |
| 1630 int32_t CPDF_VariableText::GetTypeDescent(int32_t nFontIndex) { | 1130 int32_t CPDF_VariableText::GetTypeDescent(int32_t nFontIndex) { |
| 1631 return m_pVTProvider ? m_pVTProvider->GetTypeDescent(nFontIndex) : 0; | 1131 return m_pVTProvider ? m_pVTProvider->GetTypeDescent(nFontIndex) : 0; |
| 1632 } | 1132 } |
| 1133 |
| 1633 int32_t CPDF_VariableText::GetWordFontIndex(uint16_t word, | 1134 int32_t CPDF_VariableText::GetWordFontIndex(uint16_t word, |
| 1634 int32_t charset, | 1135 int32_t charset, |
| 1635 int32_t nFontIndex) { | 1136 int32_t nFontIndex) { |
| 1636 return m_pVTProvider | 1137 return m_pVTProvider |
| 1637 ? m_pVTProvider->GetWordFontIndex(word, charset, nFontIndex) | 1138 ? m_pVTProvider->GetWordFontIndex(word, charset, nFontIndex) |
| 1638 : -1; | 1139 : -1; |
| 1639 } | 1140 } |
| 1141 |
| 1640 int32_t CPDF_VariableText::GetDefaultFontIndex() { | 1142 int32_t CPDF_VariableText::GetDefaultFontIndex() { |
| 1641 return m_pVTProvider ? m_pVTProvider->GetDefaultFontIndex() : -1; | 1143 return m_pVTProvider ? m_pVTProvider->GetDefaultFontIndex() : -1; |
| 1642 } | 1144 } |
| 1145 |
| 1643 FX_BOOL CPDF_VariableText::IsLatinWord(uint16_t word) { | 1146 FX_BOOL CPDF_VariableText::IsLatinWord(uint16_t word) { |
| 1644 return m_pVTProvider ? m_pVTProvider->IsLatinWord(word) : FALSE; | 1147 return m_pVTProvider ? m_pVTProvider->IsLatinWord(word) : FALSE; |
| 1645 } | 1148 } |
| 1646 IPDF_VariableText::Iterator* CPDF_VariableText::GetIterator() { | 1149 |
| 1647 if (!m_pVTIterator) { | 1150 CPDF_VariableText::Iterator* CPDF_VariableText::GetIterator() { |
| 1648 m_pVTIterator = new CPDF_VariableText_Iterator(this); | 1151 if (!m_pVTIterator) |
| 1649 } | 1152 m_pVTIterator = new CPDF_VariableText::Iterator(this); |
| 1650 return m_pVTIterator; | 1153 return m_pVTIterator; |
| 1651 } | 1154 } |
| 1652 IPDF_VariableText::Provider* CPDF_VariableText::SetProvider( | 1155 |
| 1653 IPDF_VariableText::Provider* pProvider) { | 1156 CPDF_VariableText::Provider* CPDF_VariableText::SetProvider( |
| 1654 IPDF_VariableText::Provider* pOld = m_pVTProvider; | 1157 CPDF_VariableText::Provider* pProvider) { |
| 1158 CPDF_VariableText::Provider* pOld = m_pVTProvider; |
| 1655 m_pVTProvider = pProvider; | 1159 m_pVTProvider = pProvider; |
| 1656 return pOld; | 1160 return pOld; |
| 1657 } | 1161 } |
| 1658 CPDF_VariableText_Iterator::CPDF_VariableText_Iterator(CPDF_VariableText* pVT) | |
| 1659 : m_CurPos(-1, -1, -1), m_pVT(pVT) {} | |
| 1660 CPDF_VariableText_Iterator::~CPDF_VariableText_Iterator() {} | |
| 1661 void CPDF_VariableText_Iterator::SetAt(int32_t nWordIndex) { | |
| 1662 m_CurPos = m_pVT->WordIndexToWordPlace(nWordIndex); | |
| 1663 } | |
| 1664 void CPDF_VariableText_Iterator::SetAt(const CPVT_WordPlace& place) { | |
| 1665 ASSERT(m_pVT); | |
| 1666 m_CurPos = place; | |
| 1667 } | |
| 1668 FX_BOOL CPDF_VariableText_Iterator::NextWord() { | |
| 1669 if (m_CurPos == m_pVT->GetEndWordPlace()) { | |
| 1670 return FALSE; | |
| 1671 } | |
| 1672 m_CurPos = m_pVT->GetNextWordPlace(m_CurPos); | |
| 1673 return TRUE; | |
| 1674 } | |
| 1675 FX_BOOL CPDF_VariableText_Iterator::PrevWord() { | |
| 1676 if (m_CurPos == m_pVT->GetBeginWordPlace()) { | |
| 1677 return FALSE; | |
| 1678 } | |
| 1679 m_CurPos = m_pVT->GetPrevWordPlace(m_CurPos); | |
| 1680 return TRUE; | |
| 1681 } | |
| 1682 FX_BOOL CPDF_VariableText_Iterator::NextLine() { | |
| 1683 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1684 if (m_CurPos.nLineIndex < pSection->m_LineArray.GetSize() - 1) { | |
| 1685 m_CurPos = | |
| 1686 CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex + 1, -1); | |
| 1687 return TRUE; | |
| 1688 } | |
| 1689 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) { | |
| 1690 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1); | |
| 1691 return TRUE; | |
| 1692 } | |
| 1693 } | |
| 1694 return FALSE; | |
| 1695 } | |
| 1696 FX_BOOL CPDF_VariableText_Iterator::PrevLine() { | |
| 1697 if (m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1698 if (m_CurPos.nLineIndex > 0) { | |
| 1699 m_CurPos = | |
| 1700 CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex - 1, -1); | |
| 1701 return TRUE; | |
| 1702 } | |
| 1703 if (m_CurPos.nSecIndex > 0) { | |
| 1704 if (CSection* pLastSection = | |
| 1705 m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex - 1)) { | |
| 1706 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, | |
| 1707 pLastSection->m_LineArray.GetSize() - 1, -1); | |
| 1708 return TRUE; | |
| 1709 } | |
| 1710 } | |
| 1711 } | |
| 1712 return FALSE; | |
| 1713 } | |
| 1714 FX_BOOL CPDF_VariableText_Iterator::NextSection() { | |
| 1715 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) { | |
| 1716 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1); | |
| 1717 return TRUE; | |
| 1718 } | |
| 1719 return FALSE; | |
| 1720 } | |
| 1721 FX_BOOL CPDF_VariableText_Iterator::PrevSection() { | |
| 1722 ASSERT(m_pVT); | |
| 1723 if (m_CurPos.nSecIndex > 0) { | |
| 1724 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, 0, -1); | |
| 1725 return TRUE; | |
| 1726 } | |
| 1727 return FALSE; | |
| 1728 } | |
| 1729 FX_BOOL CPDF_VariableText_Iterator::GetWord(CPVT_Word& word) const { | |
| 1730 word.WordPlace = m_CurPos; | |
| 1731 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1732 if (pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { | |
| 1733 if (CPVT_WordInfo* pWord = | |
| 1734 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) { | |
| 1735 word.Word = pWord->Word; | |
| 1736 word.nCharset = pWord->nCharset; | |
| 1737 word.fWidth = m_pVT->GetWordWidth(*pWord); | |
| 1738 word.ptWord = m_pVT->InToOut( | |
| 1739 CFX_FloatPoint(pWord->fWordX + pSection->m_SecInfo.rcSection.left, | |
| 1740 pWord->fWordY + pSection->m_SecInfo.rcSection.top)); | |
| 1741 word.fAscent = m_pVT->GetWordAscent(*pWord); | |
| 1742 word.fDescent = m_pVT->GetWordDescent(*pWord); | |
| 1743 if (pWord->pWordProps) { | |
| 1744 word.WordProps = *pWord->pWordProps; | |
| 1745 } | |
| 1746 word.nFontIndex = m_pVT->GetWordFontIndex(*pWord); | |
| 1747 word.fFontSize = m_pVT->GetWordFontSize(*pWord); | |
| 1748 return TRUE; | |
| 1749 } | |
| 1750 } | |
| 1751 } | |
| 1752 return FALSE; | |
| 1753 } | |
| 1754 FX_BOOL CPDF_VariableText_Iterator::SetWord(const CPVT_Word& word) { | |
| 1755 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1756 if (CPVT_WordInfo* pWord = | |
| 1757 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) { | |
| 1758 if (pWord->pWordProps) { | |
| 1759 *pWord->pWordProps = word.WordProps; | |
| 1760 } | |
| 1761 return TRUE; | |
| 1762 } | |
| 1763 } | |
| 1764 return FALSE; | |
| 1765 } | |
| 1766 FX_BOOL CPDF_VariableText_Iterator::GetLine(CPVT_Line& line) const { | |
| 1767 ASSERT(m_pVT); | |
| 1768 line.lineplace = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex, -1); | |
| 1769 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1770 if (CLine* pLine = pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { | |
| 1771 line.ptLine = m_pVT->InToOut(CFX_FloatPoint( | |
| 1772 pLine->m_LineInfo.fLineX + pSection->m_SecInfo.rcSection.left, | |
| 1773 pLine->m_LineInfo.fLineY + pSection->m_SecInfo.rcSection.top)); | |
| 1774 line.fLineWidth = pLine->m_LineInfo.fLineWidth; | |
| 1775 line.fLineAscent = pLine->m_LineInfo.fLineAscent; | |
| 1776 line.fLineDescent = pLine->m_LineInfo.fLineDescent; | |
| 1777 line.lineEnd = pLine->GetEndWordPlace(); | |
| 1778 return TRUE; | |
| 1779 } | |
| 1780 } | |
| 1781 return FALSE; | |
| 1782 } | |
| 1783 FX_BOOL CPDF_VariableText_Iterator::GetSection(CPVT_Section& section) const { | |
| 1784 section.secplace = CPVT_WordPlace(m_CurPos.nSecIndex, 0, -1); | |
| 1785 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1786 section.rcSection = m_pVT->InToOut(pSection->m_SecInfo.rcSection); | |
| 1787 if (pSection->m_SecInfo.pSecProps) { | |
| 1788 section.SecProps = *pSection->m_SecInfo.pSecProps; | |
| 1789 } | |
| 1790 if (pSection->m_SecInfo.pWordProps) { | |
| 1791 section.WordProps = *pSection->m_SecInfo.pWordProps; | |
| 1792 } | |
| 1793 return TRUE; | |
| 1794 } | |
| 1795 return FALSE; | |
| 1796 } | |
| 1797 FX_BOOL CPDF_VariableText_Iterator::SetSection(const CPVT_Section& section) { | |
| 1798 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1799 if (pSection->m_SecInfo.pSecProps) { | |
| 1800 *pSection->m_SecInfo.pSecProps = section.SecProps; | |
| 1801 } | |
| 1802 if (pSection->m_SecInfo.pWordProps) { | |
| 1803 *pSection->m_SecInfo.pWordProps = section.WordProps; | |
| 1804 } | |
| 1805 return TRUE; | |
| 1806 } | |
| 1807 return FALSE; | |
| 1808 } | |
| OLD | NEW |