int32_t CFDE_TxtEdtTextSet::GetDisplayPos(FDE_TEXTEDITPIECE* pPiece, FXTEXT_CHARPOS* pCharPos, bool bCharCode, CFX_WideString* pWSForms) { if (!pPiece) return 0; int32_t nLength = pPiece->nCount; if (nLength < 1) return 0; CFDE_TxtEdtEngine* pEngine = static_cast<CFDE_TxtEdtEngine*>(m_pPage->GetEngine()); const FDE_TXTEDTPARAMS* pTextParams = pEngine->GetEditParams(); CFX_TxtBreak* pBreak = pEngine->GetTextBreak(); uint32_t dwLayoutStyle = pBreak->GetLayoutStyles(); FX_TXTRUN tr; tr.pAccess = m_pPage; tr.pIdentity = pPiece; tr.iLength = nLength; tr.pFont = pTextParams->pFont; tr.fFontSize = pTextParams->fFontSize; tr.dwStyles = dwLayoutStyle; tr.iCharRotation = pTextParams->nCharRotation; tr.dwCharStyles = pPiece->dwCharStyles; tr.pRect = &(pPiece->rtPiece); tr.wLineBreakChar = pTextParams->wLineBreakChar; return pBreak->GetDisplayPos(&tr, pCharPos, bCharCode, pWSForms); }
void CFDE_TxtEdtParag::CalcLines() { CFX_TxtBreak* pTxtBreak = m_pEngine->GetTextBreak(); CFDE_TxtEdtBuf* pTxtBuf = m_pEngine->GetTextBuf(); int32_t nCount = 0; uint32_t dwBreakStatus = FX_TXTBREAK_None; int32_t nEndIndex = m_nCharStart + m_nCharCount; std::unique_ptr<IFX_CharIter> pIter( new CFDE_TxtEdtBuf::Iterator(static_cast<CFDE_TxtEdtBuf*>(pTxtBuf))); pIter->SetAt(m_nCharStart); bool bReload = false; do { if (bReload) { dwBreakStatus = pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); } else { FX_WCHAR wAppend = pIter->GetChar(); dwBreakStatus = pTxtBreak->AppendChar(wAppend); } if (pIter->GetAt() + 1 == nEndIndex && dwBreakStatus < FX_TXTBREAK_LineBreak) { dwBreakStatus = pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); } if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { nCount++; pTxtBreak->ClearBreakPieces(); } if ((pIter->GetAt() + 1 == nEndIndex) && (dwBreakStatus == FX_TXTBREAK_LineBreak)) { bReload = true; pIter->Next(true); } } while (pIter->Next(false) && (pIter->GetAt() < nEndIndex)); pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); pTxtBreak->ClearBreakPieces(); m_nLineCount = nCount; }
void CFDE_TxtEdtParag::LoadParag() { if (m_lpData) { m_lpData[0]++; return; } CFX_TxtBreak* pTxtBreak = m_pEngine->GetTextBreak(); CFDE_TxtEdtBuf* pTxtBuf = m_pEngine->GetTextBuf(); const FDE_TXTEDTPARAMS* pParam = m_pEngine->GetEditParams(); FX_WCHAR wcAlias = 0; if (pParam->dwMode & FDE_TEXTEDITMODE_Password) { wcAlias = m_pEngine->GetAliasChar(); } std::unique_ptr<IFX_CharIter> pIter(new CFDE_TxtEdtBuf::Iterator( static_cast<CFDE_TxtEdtBuf*>(pTxtBuf), wcAlias)); pIter->SetAt(m_nCharStart); int32_t nEndIndex = m_nCharStart + m_nCharCount; CFX_ArrayTemplate<int32_t> LineBaseArr; bool bReload = false; uint32_t dwBreakStatus = FX_TXTBREAK_None; do { if (bReload) { dwBreakStatus = pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); } else { FX_WCHAR wAppend = pIter->GetChar(); dwBreakStatus = pTxtBreak->AppendChar(wAppend); } if (pIter->GetAt() + 1 == nEndIndex && dwBreakStatus < FX_TXTBREAK_LineBreak) { dwBreakStatus = pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); } if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { int32_t nCount = pTxtBreak->CountBreakPieces(); int32_t nTotal = 0; for (int32_t j = 0; j < nCount; j++) { const CFX_TxtPiece* Piece = pTxtBreak->GetBreakPiece(j); nTotal += Piece->GetLength(); } LineBaseArr.Add(nTotal); pTxtBreak->ClearBreakPieces(); } if ((pIter->GetAt() + 1 == nEndIndex) && (dwBreakStatus == FX_TXTBREAK_LineBreak)) { bReload = true; pIter->Next(true); } } while (pIter->Next(false) && (pIter->GetAt() < nEndIndex)); pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); pTxtBreak->ClearBreakPieces(); int32_t nLineCount = LineBaseArr.GetSize(); m_nLineCount = nLineCount; if (m_lpData) { m_lpData = FX_Realloc(int32_t, m_lpData, nLineCount + 1); } else { m_lpData = FX_Alloc(int32_t, nLineCount + 1); } int32_t* pIntArr = m_lpData; pIntArr[0] = 1; m_nLineCount = nLineCount; pIntArr++; for (int32_t j = 0; j < nLineCount; j++, pIntArr++) { *pIntArr = LineBaseArr[j]; } LineBaseArr.RemoveAll(); }
int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox, IFX_Pause* pPause) { if (m_nRefCount > 0) { m_nRefCount++; return m_nRefCount; } CFDE_TxtEdtBuf* pBuf = m_pEditEngine->GetTextBuf(); const FDE_TXTEDTPARAMS* pParams = m_pEditEngine->GetEditParams(); FX_WCHAR wcAlias = 0; if (pParams->dwMode & FDE_TEXTEDITMODE_Password) { wcAlias = m_pEditEngine->GetAliasChar(); } m_pIter.reset( new CFDE_TxtEdtBufIter(static_cast<CFDE_TxtEdtBuf*>(pBuf), wcAlias)); CFX_TxtBreak* pBreak = m_pEditEngine->GetTextBreak(); pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); pBreak->ClearBreakPieces(); int32_t nPageLineCount = m_pEditEngine->GetPageLineCount(); int32_t nStartLine = nPageLineCount * m_nPageIndex; int32_t nEndLine = std::min((nStartLine + nPageLineCount - 1), (m_pEditEngine->GetLineCount() - 1)); int32_t nPageStart, nPageEnd, nTemp, nBgnParag, nStartLineInParag, nEndParag, nEndLineInParag; nBgnParag = m_pEditEngine->Line2Parag(0, 0, nStartLine, nStartLineInParag); m_pBgnParag = static_cast<CFDE_TxtEdtParag*>(m_pEditEngine->GetParag(nBgnParag)); m_pBgnParag->LoadParag(); m_pBgnParag->GetLineRange(nStartLine - nStartLineInParag, nPageStart, nTemp); nEndParag = m_pEditEngine->Line2Parag(nBgnParag, nStartLineInParag, nEndLine, nEndLineInParag); m_pEndParag = static_cast<CFDE_TxtEdtParag*>(m_pEditEngine->GetParag(nEndParag)); m_pEndParag->LoadParag(); m_pEndParag->GetLineRange(nEndLine - nEndLineInParag, nPageEnd, nTemp); nPageEnd += (nTemp - 1); FX_BOOL bVertial = pParams->dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical; FX_BOOL bLineReserve = pParams->dwLayoutStyles & FDE_TEXTEDITLAYOUT_LineReserve; FX_FLOAT fLineStart = bVertial ? (bLineReserve ? (pParams->fPlateWidth - pParams->fLineSpace) : 0.0f) : 0.0f; FX_FLOAT fLineStep = (bVertial && bLineReserve) ? (-pParams->fLineSpace) : pParams->fLineSpace; FX_FLOAT fLinePos = fLineStart; if (!m_pTextSet) m_pTextSet = new CFDE_TxtEdtTextSet(this); m_PieceMassArr.RemoveAll(TRUE); uint32_t dwBreakStatus = FX_TXTBREAK_None; int32_t nPieceStart = 0; delete[] m_pCharWidth; m_pCharWidth = new int32_t[nPageEnd - nPageStart + 1]; pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); pBreak->ClearBreakPieces(); m_nPageStart = nPageStart; m_nCharCount = nPageEnd - nPageStart + 1; FX_BOOL bReload = FALSE; FX_FLOAT fDefCharWidth = 0; std::unique_ptr<IFX_CharIter> pIter(m_pIter->Clone()); pIter->SetAt(nPageStart); m_pIter->SetAt(nPageStart); FX_BOOL bFirstPiece = TRUE; do { if (bReload) { dwBreakStatus = pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); } else { FX_WCHAR wAppend = pIter->GetChar(); dwBreakStatus = pBreak->AppendChar(wAppend); } if (pIter->GetAt() == nPageEnd && dwBreakStatus < FX_TXTBREAK_LineBreak) { dwBreakStatus = pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); } if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { int32_t nPieceCount = pBreak->CountBreakPieces(); for (int32_t j = 0; j < nPieceCount; j++) { const CFX_TxtPiece* pPiece = pBreak->GetBreakPiece(j); FDE_TEXTEDITPIECE TxtEdtPiece; FXSYS_memset(&TxtEdtPiece, 0, sizeof(FDE_TEXTEDITPIECE)); TxtEdtPiece.nBidiLevel = pPiece->m_iBidiLevel; TxtEdtPiece.nCount = pPiece->GetLength(); TxtEdtPiece.nStart = nPieceStart; TxtEdtPiece.dwCharStyles = pPiece->m_dwCharStyles; if (FX_IsOdd(pPiece->m_iBidiLevel)) { TxtEdtPiece.dwCharStyles |= FX_TXTCHARSTYLE_OddBidiLevel; } FX_FLOAT fParaBreakWidth = 0.0f; if (pPiece->m_dwStatus > FX_TXTBREAK_PieceBreak) { FX_WCHAR wRtChar = pParams->wLineBreakChar; if (TxtEdtPiece.nCount >= 2) { FX_WCHAR wChar = pBuf->GetCharByIndex( m_nPageStart + TxtEdtPiece.nStart + TxtEdtPiece.nCount - 1); FX_WCHAR wCharPre = pBuf->GetCharByIndex( m_nPageStart + TxtEdtPiece.nStart + TxtEdtPiece.nCount - 2); if (wChar == wRtChar) { fParaBreakWidth += fDefCharWidth; } if (wCharPre == wRtChar) { fParaBreakWidth += fDefCharWidth; } } else if (TxtEdtPiece.nCount >= 1) { FX_WCHAR wChar = pBuf->GetCharByIndex( m_nPageStart + TxtEdtPiece.nStart + TxtEdtPiece.nCount - 1); if (wChar == wRtChar) { fParaBreakWidth += fDefCharWidth; } } } if (pParams->dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) { TxtEdtPiece.rtPiece.left = fLinePos; TxtEdtPiece.rtPiece.top = (FX_FLOAT)pPiece->m_iStartPos / 20000.0f; TxtEdtPiece.rtPiece.width = pParams->fLineSpace; TxtEdtPiece.rtPiece.height = (FX_FLOAT)pPiece->m_iWidth / 20000.0f + fParaBreakWidth; } else { TxtEdtPiece.rtPiece.left = (FX_FLOAT)pPiece->m_iStartPos / 20000.0f; TxtEdtPiece.rtPiece.top = fLinePos; TxtEdtPiece.rtPiece.width = (FX_FLOAT)pPiece->m_iWidth / 20000.0f + fParaBreakWidth; TxtEdtPiece.rtPiece.height = pParams->fLineSpace; } if (bFirstPiece) { m_rtPageContents = TxtEdtPiece.rtPiece; bFirstPiece = FALSE; } else { m_rtPageContents.Union(TxtEdtPiece.rtPiece); } nPieceStart += TxtEdtPiece.nCount; m_PieceMassArr.Add(TxtEdtPiece); for (int32_t k = 0; k < TxtEdtPiece.nCount; k++) { CFX_Char* ptc = pPiece->GetCharPtr(k); m_pCharWidth[TxtEdtPiece.nStart + k] = ptc->m_iCharWidth; } } fLinePos += fLineStep; pBreak->ClearBreakPieces(); } if (pIter->GetAt() == nPageEnd && dwBreakStatus == FX_TXTBREAK_LineBreak) { bReload = TRUE; pIter->Next(TRUE); } } while (pIter->Next(FALSE) && (pIter->GetAt() <= nPageEnd)); if (m_rtPageContents.left != 0) { FX_FLOAT fDelta = 0.0f; if (m_rtPageContents.width < pParams->fPlateWidth) { if (pParams->dwAlignment & FDE_TEXTEDITALIGN_Right) { fDelta = pParams->fPlateWidth - m_rtPageContents.width; } else if (pParams->dwAlignment & FDE_TEXTEDITALIGN_Center) { if ((pParams->dwLayoutStyles & FDE_TEXTEDITLAYOUT_CombText) && m_nCharCount > 1) { int32_t nCount = m_nCharCount - 1; int32_t n = (m_pEditEngine->m_nLimit - nCount) / 2; fDelta = (m_rtPageContents.width / nCount) * n; } else { fDelta = (pParams->fPlateWidth - m_rtPageContents.width) / 2; } } } FX_FLOAT fOffset = m_rtPageContents.left - fDelta; int32_t nCount = m_PieceMassArr.GetSize(); for (int32_t i = 0; i < nCount; i++) { FDE_TEXTEDITPIECE* pPiece = m_PieceMassArr.GetPtrAt(i); pPiece->rtPiece.Offset(-fOffset, 0.0f); } m_rtPageContents.Offset(-fOffset, 0.0f); } if (m_pEditEngine->GetEditParams()->dwLayoutStyles & FDE_TEXTEDITLAYOUT_LastLineHeight) { m_rtPageContents.height -= pParams->fLineSpace - pParams->fFontSize; int32_t nCount = m_PieceMassArr.GetSize(); FDE_TEXTEDITPIECE* pPiece = m_PieceMassArr.GetPtrAt(nCount - 1); pPiece->rtPiece.height = pParams->fFontSize; } m_nRefCount = 1; m_bLoaded = TRUE; return 0; }