diff options
author | thestig <thestig@chromium.org> | 2016-05-02 12:40:36 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-02 12:40:36 -0700 |
commit | a354eb517429e10d84abff65e455f0c183fe58e0 (patch) | |
tree | 69dd116ad19e98f94239d43f03d7e685492ee413 | |
parent | 8f0d0da1b12e29133fb48a778603c03bf0056124 (diff) | |
download | pdfium-a354eb517429e10d84abff65e455f0c183fe58e0.tar.xz |
Remove unneeded CPVT classes.
- CPVT_Size is the same as CFX_PointF
- CPVT_FloatRange is unused.
- CPVT_ArrayTemplate is just a wrapper for CFX_ArrayTemplate.
Review-Url: https://codereview.chromium.org/1919283008
-rw-r--r-- | BUILD.gn | 2 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_variabletext.cpp | 78 | ||||
-rw-r--r-- | core/fpdfdoc/cpvt_generateap.cpp | 2 | ||||
-rw-r--r-- | core/fpdfdoc/csection.h | 7 | ||||
-rw-r--r-- | core/fpdfdoc/ctypeset.h | 7 | ||||
-rw-r--r-- | core/fpdfdoc/doc_vt.cpp | 332 | ||||
-rw-r--r-- | core/fpdfdoc/doc_vt.h (renamed from core/fpdfdoc/pdf_vt.h) | 82 | ||||
-rw-r--r-- | core/fpdfdoc/include/cpdf_variabletext.h | 8 | ||||
-rw-r--r-- | pdfium.gyp | 2 |
9 files changed, 260 insertions, 260 deletions
@@ -223,6 +223,7 @@ static_library("fpdfdoc") { "core/fpdfdoc/doc_utils.h", "core/fpdfdoc/doc_viewerPreferences.cpp", "core/fpdfdoc/doc_vt.cpp", + "core/fpdfdoc/doc_vt.h", "core/fpdfdoc/include/cpdf_variabletext.h", "core/fpdfdoc/include/cpvt_line.h", "core/fpdfdoc/include/cpvt_secprops.h", @@ -234,7 +235,6 @@ static_library("fpdfdoc") { "core/fpdfdoc/include/fpdf_doc.h", "core/fpdfdoc/include/fpdf_tagged.h", "core/fpdfdoc/ipvt_fontmap.h", - "core/fpdfdoc/pdf_vt.h", "core/fpdfdoc/tagged_int.h", ] configs += [ ":pdfium_config" ] diff --git a/core/fpdfdoc/cpdf_variabletext.cpp b/core/fpdfdoc/cpdf_variabletext.cpp index 67887400a4..33451dea5c 100644 --- a/core/fpdfdoc/cpdf_variabletext.cpp +++ b/core/fpdfdoc/cpdf_variabletext.cpp @@ -4,10 +4,11 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#include "core/fpdfdoc/include/cpdf_variabletext.h" + #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" #include "core/fpdfdoc/cpvt_wordinfo.h" #include "core/fpdfdoc/csection.h" -#include "core/fpdfdoc/include/cpdf_variabletext.h" #include "core/fpdfdoc/include/cpvt_section.h" #include "core/fpdfdoc/include/cpvt_word.h" #include "core/fpdfdoc/include/ipvt_fontmap.h" @@ -70,11 +71,8 @@ int32_t CPDF_VariableText::Provider::GetWordFontIndex(uint16_t word, } FX_BOOL CPDF_VariableText::Provider::IsLatinWord(uint16_t word) { - if ((word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) || - word == 0x2D || word == 0x27) { - return TRUE; - } - return FALSE; + return (word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) || + word == 0x2D || word == 0x27; } int32_t CPDF_VariableText::Provider::GetDefaultFontIndex() { @@ -164,28 +162,36 @@ FX_BOOL CPDF_VariableText::Iterator::PrevSection() { FX_BOOL CPDF_VariableText::Iterator::GetWord(CPVT_Word& word) const { word.WordPlace = m_CurPos; - if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { - if (pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { - if (CPVT_WordInfo* pWord = - pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) { - word.Word = pWord->Word; - word.nCharset = pWord->nCharset; - word.fWidth = m_pVT->GetWordWidth(*pWord); - word.ptWord = m_pVT->InToOut( - CFX_FloatPoint(pWord->fWordX + pSection->m_SecInfo.rcSection.left, - pWord->fWordY + pSection->m_SecInfo.rcSection.top)); - word.fAscent = m_pVT->GetWordAscent(*pWord); - word.fDescent = m_pVT->GetWordDescent(*pWord); - if (pWord->pWordProps) - word.WordProps = *pWord->pWordProps; - - word.nFontIndex = m_pVT->GetWordFontIndex(*pWord); - word.fFontSize = m_pVT->GetWordFontSize(*pWord); - return TRUE; - } - } + CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex); + if (!pSection) + return FALSE; + + if (!pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) + return FALSE; + + if (m_CurPos.nWordIndex < 0 || + m_CurPos.nWordIndex >= pSection->m_WordArray.GetSize()) { + return FALSE; } - return FALSE; + + CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(m_CurPos.nWordIndex); + if (!pWord) + return FALSE; + + word.Word = pWord->Word; + word.nCharset = pWord->nCharset; + word.fWidth = m_pVT->GetWordWidth(*pWord); + word.ptWord = m_pVT->InToOut( + CFX_FloatPoint(pWord->fWordX + pSection->m_SecInfo.rcSection.left, + pWord->fWordY + pSection->m_SecInfo.rcSection.top)); + word.fAscent = m_pVT->GetWordAscent(*pWord); + word.fDescent = m_pVT->GetWordDescent(*pWord); + if (pWord->pWordProps) + word.WordProps = *pWord->pWordProps; + + word.nFontIndex = m_pVT->GetWordFontIndex(*pWord); + word.fFontSize = m_pVT->GetWordFontSize(*pWord); + return TRUE; } FX_BOOL CPDF_VariableText::Iterator::SetWord(const CPVT_Word& word) { @@ -729,7 +735,7 @@ CPVT_WordPlace CPDF_VariableText::AddSection(const CPVT_WordPlace& place, CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace& place, const CPVT_LineInfo& lineinfo) { - if (m_SectionArray.IsEmpty()) + if (m_SectionArray.GetSize() == 0) return place; if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) return pSection->AddLine(lineinfo); @@ -738,9 +744,9 @@ CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace& place, CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace& place, const CPVT_WordInfo& wordinfo) { - if (m_SectionArray.GetSize() <= 0) { + if (m_SectionArray.GetSize() <= 0) return place; - } + CPVT_WordPlace newplace = place; newplace.nSecIndex = std::max(std::min(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0); @@ -1053,22 +1059,20 @@ FX_FLOAT CPDF_VariableText::GetAutoFontSize() { return (FX_FLOAT)gFontSizeSteps[nMid]; } -FX_BOOL CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) { - FX_BOOL bBigger = FALSE; - CPVT_Size szTotal; +bool CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) const { + CFX_PointF szTotal; for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { if (CSection* pSection = m_SectionArray.GetAt(s)) { - CPVT_Size size = pSection->GetSectionSize(fFontSize); + CFX_PointF size = pSection->GetSectionSize(fFontSize); szTotal.x = std::max(size.x, szTotal.x); szTotal.y += size.y; if (IsFloatBigger(szTotal.x, GetPlateWidth()) || IsFloatBigger(szTotal.y, GetPlateHeight())) { - bBigger = TRUE; - break; + return true; } } } - return bBigger; + return false; } CPVT_FloatRect CPDF_VariableText::RearrangeSections( diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index ec1b9fbf4e..3a7feddf44 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -13,9 +13,9 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" #include "core/fpdfdoc/cpvt_color.h" #include "core/fpdfdoc/cpvt_fontmap.h" +#include "core/fpdfdoc/doc_vt.h" #include "core/fpdfdoc/include/cpvt_word.h" #include "core/fpdfdoc/include/fpdf_doc.h" -#include "core/fpdfdoc/pdf_vt.h" namespace { diff --git a/core/fpdfdoc/csection.h b/core/fpdfdoc/csection.h index d8974cb020..f6a9f3baa2 100644 --- a/core/fpdfdoc/csection.h +++ b/core/fpdfdoc/csection.h @@ -21,7 +21,8 @@ struct CPVT_WordPlace; class CSection { public: explicit CSection(CPDF_VariableText* pVT); - virtual ~CSection(); + ~CSection(); + void ResetAll(); void ResetLineArray(); void ResetWordArray(); @@ -32,7 +33,7 @@ class CSection { void ClearWords(const CPVT_WordRange& PlaceRange); void ClearWord(const CPVT_WordPlace& place); CPVT_FloatRect Rearrange(); - CPVT_Size GetSectionSize(FX_FLOAT fFontSize); + CFX_PointF GetSectionSize(FX_FLOAT fFontSize); CPVT_WordPlace GetBeginWordPlace() const; CPVT_WordPlace GetEndWordPlace() const; CPVT_WordPlace GetPrevWordPlace(const CPVT_WordPlace& place) const; @@ -47,7 +48,7 @@ class CSection { CPVT_WordPlace SecPlace; CPVT_SectionInfo m_SecInfo; CLines m_LineArray; - CPVT_ArrayTemplate<CPVT_WordInfo*> m_WordArray; + CFX_ArrayTemplate<CPVT_WordInfo*> m_WordArray; private: friend class CTypeset; diff --git a/core/fpdfdoc/ctypeset.h b/core/fpdfdoc/ctypeset.h index 25bb31a801..1401050b42 100644 --- a/core/fpdfdoc/ctypeset.h +++ b/core/fpdfdoc/ctypeset.h @@ -16,14 +16,17 @@ class CSection; class CTypeset { public: explicit CTypeset(CSection* pSection); - virtual ~CTypeset(); - CPVT_Size GetEditSize(FX_FLOAT fFontSize); + ~CTypeset(); + + CFX_PointF GetEditSize(FX_FLOAT fFontSize); CPVT_FloatRect Typeset(); CPVT_FloatRect CharArray(); private: void SplitLines(FX_BOOL bTypeset, FX_FLOAT fFontSize); void OutputLines(); + FX_FLOAT GetXPosForAlignment(FX_FLOAT fTypesetWidth, + FX_FLOAT fLineWidth) const; CPVT_FloatRect m_rcRet; CPDF_VariableText* m_pVT; diff --git a/core/fpdfdoc/doc_vt.cpp b/core/fpdfdoc/doc_vt.cpp index 88a4636bbc..985ffa5971 100644 --- a/core/fpdfdoc/doc_vt.cpp +++ b/core/fpdfdoc/doc_vt.cpp @@ -4,16 +4,19 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#include "core/fpdfdoc/doc_vt.h" + #include <algorithm> #include "core/fpdfdoc/cpvt_wordinfo.h" #include "core/fpdfdoc/csection.h" #include "core/fpdfdoc/include/cpdf_variabletext.h" #include "core/fpdfdoc/include/fpdf_doc.h" -#include "core/fpdfdoc/pdf_vt.h" CLine::CLine() {} + CLine::~CLine() {} + CPVT_WordPlace CLine::GetBeginWordPlace() const { return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, -1); } @@ -61,102 +64,104 @@ void CSection::ResetLinePlace() { } } } + CPVT_WordPlace CSection::AddWord(const CPVT_WordPlace& place, const CPVT_WordInfo& wordinfo) { CPVT_WordInfo* pWord = new CPVT_WordInfo(wordinfo); int32_t nWordIndex = std::max(std::min(place.nWordIndex, m_WordArray.GetSize()), 0); - if (nWordIndex == m_WordArray.GetSize()) { + if (nWordIndex == m_WordArray.GetSize()) m_WordArray.Add(pWord); - } else { + else m_WordArray.InsertAt(nWordIndex, pWord); - } return place; } + CPVT_WordPlace CSection::AddLine(const CPVT_LineInfo& lineinfo) { return CPVT_WordPlace(SecPlace.nSecIndex, m_LineArray.Add(lineinfo), -1); } + CPVT_FloatRect CSection::Rearrange() { - if (m_pVT->m_nCharArray > 0) { + if (m_pVT->m_nCharArray > 0) return CTypeset(this).CharArray(); - } return CTypeset(this).Typeset(); } -CPVT_Size CSection::GetSectionSize(FX_FLOAT fFontSize) { + +CFX_PointF CSection::GetSectionSize(FX_FLOAT fFontSize) { return CTypeset(this).GetEditSize(fFontSize); } + CPVT_WordPlace CSection::GetBeginWordPlace() const { - if (CLine* pLine = m_LineArray.GetAt(0)) { + if (CLine* pLine = m_LineArray.GetAt(0)) return pLine->GetBeginWordPlace(); - } return SecPlace; } + CPVT_WordPlace CSection::GetEndWordPlace() const { - if (CLine* pLine = m_LineArray.GetAt(m_LineArray.GetSize() - 1)) { + if (CLine* pLine = m_LineArray.GetAt(m_LineArray.GetSize() - 1)) return pLine->GetEndWordPlace(); - } return SecPlace; } + CPVT_WordPlace CSection::GetPrevWordPlace(const CPVT_WordPlace& place) const { - if (place.nLineIndex < 0) { + if (place.nLineIndex < 0) return GetBeginWordPlace(); - } - if (place.nLineIndex >= m_LineArray.GetSize()) { + + if (place.nLineIndex >= m_LineArray.GetSize()) return GetEndWordPlace(); - } + if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { - if (place.nWordIndex == pLine->m_LineInfo.nBeginWordIndex) { + if (place.nWordIndex == pLine->m_LineInfo.nBeginWordIndex) return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); - } - if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { - if (CLine* pPrevLine = m_LineArray.GetAt(place.nLineIndex - 1)) { - return pPrevLine->GetEndWordPlace(); - } - } else { + + if (place.nWordIndex >= pLine->m_LineInfo.nBeginWordIndex) return pLine->GetPrevWordPlace(place); - } + + if (CLine* pPrevLine = m_LineArray.GetAt(place.nLineIndex - 1)) + return pPrevLine->GetEndWordPlace(); } return place; } + CPVT_WordPlace CSection::GetNextWordPlace(const CPVT_WordPlace& place) const { - if (place.nLineIndex < 0) { + if (place.nLineIndex < 0) return GetBeginWordPlace(); - } - if (place.nLineIndex >= m_LineArray.GetSize()) { + + if (place.nLineIndex >= m_LineArray.GetSize()) return GetEndWordPlace(); - } + if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { - if (place.nWordIndex >= pLine->m_LineInfo.nEndWordIndex) { - if (CLine* pNextLine = m_LineArray.GetAt(place.nLineIndex + 1)) { - return pNextLine->GetBeginWordPlace(); - } - } else { + if (place.nWordIndex < pLine->m_LineInfo.nEndWordIndex) return pLine->GetNextWordPlace(place); - } + + if (CLine* pNextLine = m_LineArray.GetAt(place.nLineIndex + 1)) + return pNextLine->GetBeginWordPlace(); } return place; } + void CSection::UpdateWordPlace(CPVT_WordPlace& place) const { int32_t nLeft = 0; int32_t nRight = m_LineArray.GetSize() - 1; int32_t nMid = (nLeft + nRight) / 2; while (nLeft <= nRight) { - if (CLine* pLine = m_LineArray.GetAt(nMid)) { - if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { - nRight = nMid - 1; - nMid = (nLeft + nRight) / 2; - } else if (place.nWordIndex > pLine->m_LineInfo.nEndWordIndex) { - nLeft = nMid + 1; - nMid = (nLeft + nRight) / 2; - } else { - place.nLineIndex = nMid; - return; - } + CLine* pLine = m_LineArray.GetAt(nMid); + if (!pLine) + return; + + if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { + nRight = nMid - 1; + nMid = (nLeft + nRight) / 2; + } else if (place.nWordIndex > pLine->m_LineInfo.nEndWordIndex) { + nLeft = nMid + 1; + nMid = (nLeft + nRight) / 2; } else { - break; + place.nLineIndex = nMid; + return; } } } + CPVT_WordPlace CSection::SearchWordPlace(const CFX_FloatPoint& point) const { ASSERT(m_pVT); CPVT_WordPlace place = GetBeginWordPlace(); @@ -172,81 +177,78 @@ CPVT_WordPlace CSection::SearchWordPlace(const CFX_FloatPoint& point) const { 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)) { + if (IsFloatBigger(point.y, fTop)) bUp = FALSE; - } - if (IsFloatSmaller(point.y, fBottom)) { + + 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)) { + } + 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; } + + place = SearchWordPlace( + point.x, + CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), + pLine->GetEndWordPlace())); + place.nLineIndex = nMid; + return place; } } - if (bUp) { + if (bUp) place = GetBeginWordPlace(); - } - if (bDown) { + if (bDown) place = GetEndWordPlace(); - } return place; } + 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(); + CLine* pLine = m_LineArray.GetAt(lineplace.nLineIndex); + if (!pLine) + return GetBeginWordPlace(); + return SearchWordPlace( + fx - m_SecInfo.rcSection.left, + CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), + pLine->GetEndWordPlace())); } + CPVT_WordPlace CSection::SearchWordPlace(FX_FLOAT fx, const CPVT_WordRange& range) const { CPVT_WordPlace wordplace = range.BeginPos; wordplace.nWordIndex = -1; - if (!m_pVT) { + if (!m_pVT) return wordplace; - } + int32_t nLeft = range.BeginPos.nWordIndex; int32_t nRight = range.EndPos.nWordIndex + 1; int32_t nMid = (nLeft + nRight) / 2; while (nLeft < nRight) { - if (nMid == nLeft) { + if (nMid == nLeft) break; - } + if (nMid == nRight) { nMid--; break; } - if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { - if (fx > - pWord->fWordX + m_pVT->GetWordWidth(*pWord) * VARIABLETEXT_HALF) { - nLeft = nMid; - nMid = (nLeft + nRight) / 2; - continue; - } else { - nRight = nMid; - nMid = (nLeft + nRight) / 2; - continue; - } - } else { + + CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid); + if (!pWord) break; - } + + if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * VARIABLETEXT_HALF) + nLeft = nMid; + else + nRight = nMid; + nMid = (nLeft + nRight) / 2; } if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * VARIABLETEXT_HALF) { @@ -255,24 +257,28 @@ CPVT_WordPlace CSection::SearchWordPlace(FX_FLOAT fx, } return wordplace; } + void CSection::ClearLeftWords(int32_t nWordIndex) { for (int32_t i = nWordIndex; i >= 0; i--) { delete m_WordArray.GetAt(i); m_WordArray.RemoveAt(i); } } + void CSection::ClearRightWords(int32_t nWordIndex) { for (int32_t i = m_WordArray.GetSize() - 1; i > nWordIndex; i--) { delete m_WordArray.GetAt(i); m_WordArray.RemoveAt(i); } } + void CSection::ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex) { for (int32_t i = nEndIndex; i > nBeginIndex; i--) { delete m_WordArray.GetAt(i); m_WordArray.RemoveAt(i); } } + void CSection::ClearWords(const CPVT_WordRange& PlaceRange) { CPVT_WordPlace SecBeginPos = GetBeginWordPlace(); CPVT_WordPlace SecEndPos = GetEndWordPlace(); @@ -289,15 +295,19 @@ void CSection::ClearWords(const CPVT_WordRange& PlaceRange) { ResetWordArray(); } } + void CSection::ClearWord(const CPVT_WordPlace& place) { delete m_WordArray.GetAt(place.nWordIndex); m_WordArray.RemoveAt(place.nWordIndex); } + CTypeset::CTypeset(CSection* pSection) : m_rcRet(0.0f, 0.0f, 0.0f, 0.0f), m_pVT(pSection->m_pVT), m_pSection(pSection) {} + CTypeset::~CTypeset() {} + CPVT_FloatRect CTypeset::CharArray() { ASSERT(m_pSection); FX_FLOAT fLineAscent = @@ -376,12 +386,14 @@ CPVT_FloatRect CTypeset::CharArray() { } return m_rcRet = CPVT_FloatRect(0, 0, x, y); } -CPVT_Size CTypeset::GetEditSize(FX_FLOAT fFontSize) { + +CFX_PointF CTypeset::GetEditSize(FX_FLOAT fFontSize) { ASSERT(m_pSection); ASSERT(m_pVT); SplitLines(FALSE, fFontSize); - return CPVT_Size(m_rcRet.Width(), m_rcRet.Height()); + return CFX_PointF(m_rcRet.Width(), m_rcRet.Height()); } + CPVT_FloatRect CTypeset::Typeset() { ASSERT(m_pVT); m_pSection->m_LineArray.Empty(); @@ -693,77 +705,103 @@ void CTypeset::SplitLines(FX_BOOL bTypeset, FX_FLOAT fFontSize) { } m_rcRet = CPVT_FloatRect(0, 0, fMaxX, fMaxY); } + void CTypeset::OutputLines() { - ASSERT(m_pVT); - ASSERT(m_pSection); - FX_FLOAT fMinX = 0.0f, fMinY = 0.0f, fMaxX = 0.0f, fMaxY = 0.0f; - FX_FLOAT fPosX = 0.0f, fPosY = 0.0f; FX_FLOAT fLineIndent = m_pVT->GetLineIndent(m_pSection->m_SecInfo); FX_FLOAT fTypesetWidth = std::max(m_pVT->GetPlateWidth() - fLineIndent, 0.0f); - switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { - default: - case 0: - fMinX = 0.0f; - break; - case 1: - fMinX = (fTypesetWidth - m_rcRet.Width()) * VARIABLETEXT_HALF; - break; - case 2: - fMinX = fTypesetWidth - m_rcRet.Width(); - break; - } - fMaxX = fMinX + m_rcRet.Width(); - fMinY = 0.0f; - fMaxY = m_rcRet.Height(); + FX_FLOAT fMinX = GetXPosForAlignment(fTypesetWidth, m_rcRet.Width()); + FX_FLOAT fMinY = 0.0f; + FX_FLOAT fMaxX = fMinX + m_rcRet.Width(); + FX_FLOAT fMaxY = m_rcRet.Height(); + int32_t nTotalLines = m_pSection->m_LineArray.GetSize(); - if (nTotalLines > 0) { - m_pSection->m_SecInfo.nTotalLine = nTotalLines; - for (int32_t l = 0; l < nTotalLines; l++) { - if (CLine* pLine = m_pSection->m_LineArray.GetAt(l)) { - switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { + if (nTotalLines <= 0) { + m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY); + return; + } + + FX_FLOAT fPosX = 0.0f; + FX_FLOAT fPosY = 0.0f; + m_pSection->m_SecInfo.nTotalLine = nTotalLines; + for (int32_t l = 0; l < nTotalLines; l++) { + CLine* pLine = m_pSection->m_LineArray.GetAt(l); + if (!pLine) + continue; + + fPosX = GetXPosForAlignment(fTypesetWidth, pLine->m_LineInfo.fLineWidth); + switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { + default: + case 0: + fPosX = 0; + break; + case 1: + fPosX = + (fTypesetWidth - pLine->m_LineInfo.fLineWidth) * VARIABLETEXT_HALF; + break; + case 2: + fPosX = fTypesetWidth - pLine->m_LineInfo.fLineWidth; + break; + } + fPosX += fLineIndent; + fPosY += m_pVT->GetLineLeading(m_pSection->m_SecInfo); + fPosY += pLine->m_LineInfo.fLineAscent; + pLine->m_LineInfo.fLineX = fPosX - fMinX; + pLine->m_LineInfo.fLineY = fPosY - fMinY; + for (int32_t w = pLine->m_LineInfo.nBeginWordIndex; + w <= pLine->m_LineInfo.nEndWordIndex; w++) { + if (w < 0 || w >= m_pSection->m_WordArray.GetSize()) + continue; + + CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(w); + if (!pWord) + continue; + + pWord->fWordX = fPosX - fMinX; + if (pWord->pWordProps) { + switch (pWord->pWordProps->nScriptType) { default: - case 0: - fPosX = 0; + case CPDF_VariableText::ScriptType::Normal: + pWord->fWordY = fPosY - fMinY; break; - case 1: - fPosX = (fTypesetWidth - pLine->m_LineInfo.fLineWidth) * - VARIABLETEXT_HALF; + case CPDF_VariableText::ScriptType::Super: + pWord->fWordY = fPosY - m_pVT->GetWordAscent(*pWord) - fMinY; break; - case 2: - fPosX = fTypesetWidth - pLine->m_LineInfo.fLineWidth; + case CPDF_VariableText::ScriptType::Sub: + pWord->fWordY = fPosY - m_pVT->GetWordDescent(*pWord) - fMinY; break; } - fPosX += fLineIndent; - fPosY += m_pVT->GetLineLeading(m_pSection->m_SecInfo); - fPosY += pLine->m_LineInfo.fLineAscent; - pLine->m_LineInfo.fLineX = fPosX - fMinX; - pLine->m_LineInfo.fLineY = fPosY - fMinY; - for (int32_t w = pLine->m_LineInfo.nBeginWordIndex; - w <= pLine->m_LineInfo.nEndWordIndex; w++) { - if (CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(w)) { - pWord->fWordX = fPosX - fMinX; - if (pWord->pWordProps) { - switch (pWord->pWordProps->nScriptType) { - default: - case CPDF_VariableText::ScriptType::Normal: - pWord->fWordY = fPosY - fMinY; - break; - case CPDF_VariableText::ScriptType::Super: - pWord->fWordY = fPosY - m_pVT->GetWordAscent(*pWord) - fMinY; - break; - case CPDF_VariableText::ScriptType::Sub: - pWord->fWordY = fPosY - m_pVT->GetWordDescent(*pWord) - fMinY; - break; - } - } else { - pWord->fWordY = fPosY - fMinY; - } - fPosX += m_pVT->GetWordWidth(*pWord); - } - } - fPosY -= pLine->m_LineInfo.fLineDescent; + } else { + pWord->fWordY = fPosY - fMinY; } + fPosX += m_pVT->GetWordWidth(*pWord); } + fPosY -= pLine->m_LineInfo.fLineDescent; } m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY); } + +FX_FLOAT CTypeset::GetXPosForAlignment(FX_FLOAT fTypesetWidth, + FX_FLOAT fLineWidth) const { + switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { + default: + case 0: + return 0; + case 1: + return (fTypesetWidth - fLineWidth) * VARIABLETEXT_HALF; + case 2: + return fTypesetWidth - fLineWidth; + } +} + +CPDF_EditContainer::CPDF_EditContainer() + : m_rcPlate(0, 0, 0, 0), m_rcContent(0, 0, 0, 0) {} + +CPDF_EditContainer::~CPDF_EditContainer() {} + +CFX_FloatRect CPDF_EditContainer::InToOut(const CPVT_FloatRect& rect) const { + CFX_FloatPoint ptLeftTop = InToOut(CFX_FloatPoint(rect.left, rect.top)); + CFX_FloatPoint ptRightBottom = + InToOut(CFX_FloatPoint(rect.right, rect.bottom)); + return CFX_FloatRect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x, + ptLeftTop.y); +} diff --git a/core/fpdfdoc/pdf_vt.h b/core/fpdfdoc/doc_vt.h index a3b7883a9b..09be92b8e7 100644 --- a/core/fpdfdoc/pdf_vt.h +++ b/core/fpdfdoc/doc_vt.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef CORE_FPDFDOC_PDF_VT_H_ -#define CORE_FPDFDOC_PDF_VT_H_ +#ifndef CORE_FPDFDOC_DOC_VT_H_ +#define CORE_FPDFDOC_DOC_VT_H_ #include "core/fpdfdoc/cpvt_floatrect.h" #include "core/fpdfdoc/cpvt_lineinfo.h" @@ -20,42 +20,11 @@ struct CPVT_WordInfo; #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) -class CPVT_Size { - public: - CPVT_Size() : x(0.0f), y(0.0f) {} - CPVT_Size(FX_FLOAT other_x, FX_FLOAT other_y) { - x = other_x; - y = other_y; - } - FX_FLOAT x, y; -}; - -struct CPVT_FloatRange { - CPVT_FloatRange() : fMin(0.0f), fMax(0.0f) {} - CPVT_FloatRange(FX_FLOAT min, FX_FLOAT max) : fMin(min), fMax(max) {} - FX_FLOAT Range() const { return fMax - fMin; } - FX_FLOAT fMin, fMax; -}; -template <class TYPE> -class CPVT_ArrayTemplate : public CFX_ArrayTemplate<TYPE> { - public: - FX_BOOL IsEmpty() { return CFX_ArrayTemplate<TYPE>::GetSize() <= 0; } - TYPE GetAt(int nIndex) const { - if (nIndex >= 0 && nIndex < CFX_ArrayTemplate<TYPE>::GetSize()) { - return CFX_ArrayTemplate<TYPE>::GetAt(nIndex); - } - return NULL; - } - void RemoveAt(int nIndex) { - if (nIndex >= 0 && nIndex < CFX_ArrayTemplate<TYPE>::GetSize()) { - CFX_ArrayTemplate<TYPE>::RemoveAt(nIndex); - } - } -}; class CLine { public: CLine(); - virtual ~CLine(); + ~CLine(); + CPVT_WordPlace GetBeginWordPlace() const; CPVT_WordPlace GetEndWordPlace() const; CPVT_WordPlace GetPrevWordPlace(const CPVT_WordPlace& place) const; @@ -63,10 +32,12 @@ class CLine { CPVT_WordPlace LinePlace; CPVT_LineInfo m_LineInfo; }; + class CLines { public: CLines() : m_nTotal(0) {} - virtual ~CLines() { RemoveAll(); } + ~CLines() { RemoveAll(); } + int32_t GetSize() const { return m_Lines.GetSize(); } CLine* GetAt(int32_t nIndex) const { return m_Lines.GetAt(nIndex); } void Empty() { m_nTotal = 0; } @@ -95,55 +66,38 @@ class CLines { } private: - CPVT_ArrayTemplate<CLine*> m_Lines; + CFX_ArrayTemplate<CLine*> m_Lines; int32_t m_nTotal; }; class CPDF_EditContainer { public: - CPDF_EditContainer() : m_rcPlate(0, 0, 0, 0), m_rcContent(0, 0, 0, 0) {} - virtual ~CPDF_EditContainer() {} - virtual void SetPlateRect(const CFX_FloatRect& rect) { m_rcPlate = rect; } + CPDF_EditContainer(); + virtual ~CPDF_EditContainer(); + virtual const CFX_FloatRect& GetPlateRect() const { return m_rcPlate; } + virtual void SetPlateRect(const CFX_FloatRect& rect) { m_rcPlate = rect; } + virtual CFX_FloatRect GetContentRect() const { return m_rcContent; } virtual void SetContentRect(const CPVT_FloatRect& rect) { m_rcContent = rect; } - virtual CFX_FloatRect GetContentRect() const { return m_rcContent; } + FX_FLOAT GetPlateWidth() const { return m_rcPlate.right - m_rcPlate.left; } FX_FLOAT GetPlateHeight() const { return m_rcPlate.top - m_rcPlate.bottom; } - CPVT_Size GetPlateSize() const { - return CPVT_Size(GetPlateWidth(), GetPlateHeight()); - } CFX_FloatPoint GetBTPoint() const { return CFX_FloatPoint(m_rcPlate.left, m_rcPlate.top); } - CFX_FloatPoint GetETPoint() const { - return CFX_FloatPoint(m_rcPlate.right, m_rcPlate.bottom); - } - inline CFX_FloatPoint InToOut(const CFX_FloatPoint& point) const { + CFX_FloatPoint InToOut(const CFX_FloatPoint& point) const { return CFX_FloatPoint(point.x + GetBTPoint().x, GetBTPoint().y - point.y); } - inline CFX_FloatPoint OutToIn(const CFX_FloatPoint& point) const { + CFX_FloatPoint OutToIn(const CFX_FloatPoint& point) const { return CFX_FloatPoint(point.x - GetBTPoint().x, GetBTPoint().y - point.y); } - inline CFX_FloatRect InToOut(const CPVT_FloatRect& rect) const { - CFX_FloatPoint ptLeftTop = InToOut(CFX_FloatPoint(rect.left, rect.top)); - CFX_FloatPoint ptRightBottom = - InToOut(CFX_FloatPoint(rect.right, rect.bottom)); - return CFX_FloatRect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x, - ptLeftTop.y); - } - inline CPVT_FloatRect OutToIn(const CFX_FloatRect& rect) const { - CFX_FloatPoint ptLeftTop = OutToIn(CFX_FloatPoint(rect.left, rect.top)); - CFX_FloatPoint ptRightBottom = - OutToIn(CFX_FloatPoint(rect.right, rect.bottom)); - return CPVT_FloatRect(ptLeftTop.x, ptLeftTop.y, ptRightBottom.x, - ptRightBottom.y); - } + CFX_FloatRect InToOut(const CPVT_FloatRect& rect) const; private: CFX_FloatRect m_rcPlate; CPVT_FloatRect m_rcContent; }; -#endif // CORE_FPDFDOC_PDF_VT_H_ +#endif // CORE_FPDFDOC_DOC_VT_H_ diff --git a/core/fpdfdoc/include/cpdf_variabletext.h b/core/fpdfdoc/include/cpdf_variabletext.h index b73d3df8c1..e438223680 100644 --- a/core/fpdfdoc/include/cpdf_variabletext.h +++ b/core/fpdfdoc/include/cpdf_variabletext.h @@ -9,10 +9,10 @@ #include "core/fpdfdoc/cpvt_floatrect.h" #include "core/fpdfdoc/cpvt_lineinfo.h" +#include "core/fpdfdoc/doc_vt.h" #include "core/fpdfdoc/include/cpvt_line.h" #include "core/fpdfdoc/include/cpvt_wordplace.h" #include "core/fpdfdoc/include/cpvt_wordrange.h" -#include "core/fpdfdoc/pdf_vt.h" #include "core/fxcrt/include/fx_coordinates.h" #include "core/fxcrt/include/fx_string.h" #include "core/fxcrt/include/fx_system.h" @@ -60,7 +60,7 @@ class CPDF_VariableText : private CPDF_EditContainer { class Provider { public: - Provider(IPVT_FontMap* pFontMap); + explicit Provider(IPVT_FontMap* pFontMap); virtual ~Provider(); virtual int32_t GetCharWidth(int32_t nFontIndex, @@ -227,12 +227,12 @@ class CPDF_VariableText : private CPDF_EditContainer { CPVT_FloatRect Rearrange(const CPVT_WordRange& PlaceRange); FX_FLOAT GetAutoFontSize(); - FX_BOOL IsBigger(FX_FLOAT fFontSize); + bool IsBigger(FX_FLOAT fFontSize) const; CPVT_FloatRect RearrangeSections(const CPVT_WordRange& PlaceRange); void ResetSectionArray(); - CPVT_ArrayTemplate<CSection*> m_SectionArray; + CFX_ArrayTemplate<CSection*> m_SectionArray; int32_t m_nLimitChar; int32_t m_nCharArray; FX_BOOL m_bMultiLine; diff --git a/pdfium.gyp b/pdfium.gyp index 10bba9d488..ba0744bf32 100644 --- a/pdfium.gyp +++ b/pdfium.gyp @@ -252,6 +252,7 @@ 'core/fpdfdoc/doc_utils.h', 'core/fpdfdoc/doc_viewerPreferences.cpp', 'core/fpdfdoc/doc_vt.cpp', + 'core/fpdfdoc/doc_vt.h', 'core/fpdfdoc/include/cpdf_variabletext.h', 'core/fpdfdoc/include/cpvt_line.h', 'core/fpdfdoc/include/cpvt_secprops.h', @@ -261,7 +262,6 @@ 'core/fpdfdoc/include/cpvt_wordprops.h', 'core/fpdfdoc/include/cpvt_wordrange.h', 'core/fpdfdoc/include/ipvt_fontmap.h', - 'core/fpdfdoc/pdf_vt.h', 'core/fpdfdoc/tagged_int.h', ], }, |