CPVT_WordRange CPWL_Edit::GetSelectWordRange() const { if (m_pEdit->IsSelected()) { int32_t nStart = -1; int32_t nEnd = -1; m_pEdit->GetSel(nStart, nEnd); CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart); CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd); return CPVT_WordRange(wpStart, wpEnd); } return CPVT_WordRange(); }
void CPDF_VariableText::SetText(const FX_WCHAR* text, int32_t charset, const CPVT_SecProps* pSecProps, const CPVT_WordProps* pWordProps) { DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); CFX_WideString swText = text; CPVT_WordPlace wp(0, 0, -1); CPVT_SectionInfo secinfo; if (m_bRichText) { if (pSecProps) secinfo.pSecProps = new CPVT_SecProps(*pSecProps); if (pWordProps) secinfo.pWordProps = new CPVT_WordProps(*pWordProps); } if (CSection* pSection = m_SectionArray.GetAt(0)) pSection->m_SecInfo = secinfo; int32_t nCharCount = 0; for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) break; if (m_nCharArray > 0 && nCharCount >= m_nCharArray) break; uint16_t word = swText.GetAt(i); switch (word) { case 0x0D: if (m_bMultiLine) { if (swText.GetAt(i + 1) == 0x0A) i += 1; wp.nSecIndex++; wp.nLineIndex = 0; wp.nWordIndex = -1; AddSection(wp, secinfo); } break; case 0x0A: if (m_bMultiLine) { if (swText.GetAt(i + 1) == 0x0D) i += 1; wp.nSecIndex++; wp.nLineIndex = 0; wp.nWordIndex = -1; AddSection(wp, secinfo); } break; case 0x09: word = 0x20; default: wp = InsertWord(wp, word, charset, pWordProps); break; } nCharCount++; } }
CPVT_WordPlace CSection::SearchWordPlace( FX_FLOAT fx, const CPVT_WordPlace& lineplace) const { if (CLine* pLine = m_LineArray.GetAt(lineplace.nLineIndex)) { return SearchWordPlace( fx - m_SecInfo.rcSection.left, CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), pLine->GetEndWordPlace())); } return GetBeginWordPlace(); }
CPVT_FloatRect CPDF_VariableText::Rearrange(const CPVT_WordRange& PlaceRange) { CPVT_FloatRect rcRet; if (IsValid()) { if (m_bAutoFontSize) { SetFontSize(GetAutoFontSize()); rcRet = RearrangeSections( CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); } else { rcRet = RearrangeSections(PlaceRange); } } SetContentRect(rcRet); return rcRet; }
CPVT_WordPlace CSection::SearchWordPlace(const CFX_FloatPoint& point) const { ASSERT(m_pVT); CPVT_WordPlace place = GetBeginWordPlace(); bool bUp = true; bool bDown = true; int32_t nLeft = 0; int32_t nRight = m_LineArray.GetSize() - 1; int32_t nMid = m_LineArray.GetSize() / 2; FX_FLOAT fTop = 0; FX_FLOAT fBottom = 0; while (nLeft <= nRight) { if (CLine* pLine = m_LineArray.GetAt(nMid)) { fTop = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineAscent - m_pVT->GetLineLeading(m_SecInfo); fBottom = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineDescent; if (IsFloatBigger(point.y, fTop)) { bUp = false; } if (IsFloatSmaller(point.y, fBottom)) { bDown = false; } if (IsFloatSmaller(point.y, fTop)) { nRight = nMid - 1; nMid = (nLeft + nRight) / 2; continue; } else if (IsFloatBigger(point.y, fBottom)) { nLeft = nMid + 1; nMid = (nLeft + nRight) / 2; continue; } else { place = SearchWordPlace( point.x, CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), pLine->GetEndWordPlace())); place.nLineIndex = nMid; return place; } } } if (bUp) { place = GetBeginWordPlace(); } if (bDown) { place = GetEndWordPlace(); } return place; }
CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar, int32_t& nEndChar) const { CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar); CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar); return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd)); }
void CPDF_VariableText::RearrangeAll() { Rearrange(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); }