summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpdf_variabletext.cpp78
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp2
-rw-r--r--core/fpdfdoc/csection.h7
-rw-r--r--core/fpdfdoc/ctypeset.h7
-rw-r--r--core/fpdfdoc/doc_vt.cpp332
-rw-r--r--core/fpdfdoc/include/cpdf_variabletext.h8
-rw-r--r--core/fpdfdoc/pdf_vt.h (renamed from core/fpdfdoc/doc_vt.h)82
7 files changed, 258 insertions, 258 deletions
diff --git a/core/fpdfdoc/cpdf_variabletext.cpp b/core/fpdfdoc/cpdf_variabletext.cpp
index 33451dea5c..67887400a4 100644
--- a/core/fpdfdoc/cpdf_variabletext.cpp
+++ b/core/fpdfdoc/cpdf_variabletext.cpp
@@ -4,11 +4,10 @@
// 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"
@@ -71,8 +70,11 @@ int32_t CPDF_VariableText::Provider::GetWordFontIndex(uint16_t word,
}
FX_BOOL CPDF_VariableText::Provider::IsLatinWord(uint16_t word) {
- return (word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) ||
- word == 0x2D || word == 0x27;
+ if ((word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) ||
+ word == 0x2D || word == 0x27) {
+ return TRUE;
+ }
+ return FALSE;
}
int32_t CPDF_VariableText::Provider::GetDefaultFontIndex() {
@@ -162,36 +164,28 @@ FX_BOOL CPDF_VariableText::Iterator::PrevSection() {
FX_BOOL CPDF_VariableText::Iterator::GetWord(CPVT_Word& word) const {
word.WordPlace = m_CurPos;
- 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;
+ 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;
+ }
+ }
}
-
- 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;
+ return FALSE;
}
FX_BOOL CPDF_VariableText::Iterator::SetWord(const CPVT_Word& word) {
@@ -735,7 +729,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.GetSize() == 0)
+ if (m_SectionArray.IsEmpty())
return place;
if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex))
return pSection->AddLine(lineinfo);
@@ -744,9 +738,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);
@@ -1059,20 +1053,22 @@ FX_FLOAT CPDF_VariableText::GetAutoFontSize() {
return (FX_FLOAT)gFontSizeSteps[nMid];
}
-bool CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) const {
- CFX_PointF szTotal;
+FX_BOOL CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) {
+ FX_BOOL bBigger = FALSE;
+ CPVT_Size szTotal;
for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) {
if (CSection* pSection = m_SectionArray.GetAt(s)) {
- CFX_PointF size = pSection->GetSectionSize(fFontSize);
+ CPVT_Size 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())) {
- return true;
+ bBigger = TRUE;
+ break;
}
}
}
- return false;
+ return bBigger;
}
CPVT_FloatRect CPDF_VariableText::RearrangeSections(
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 3a7feddf44..ec1b9fbf4e 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 f6a9f3baa2..d8974cb020 100644
--- a/core/fpdfdoc/csection.h
+++ b/core/fpdfdoc/csection.h
@@ -21,8 +21,7 @@ struct CPVT_WordPlace;
class CSection {
public:
explicit CSection(CPDF_VariableText* pVT);
- ~CSection();
-
+ virtual ~CSection();
void ResetAll();
void ResetLineArray();
void ResetWordArray();
@@ -33,7 +32,7 @@ class CSection {
void ClearWords(const CPVT_WordRange& PlaceRange);
void ClearWord(const CPVT_WordPlace& place);
CPVT_FloatRect Rearrange();
- CFX_PointF GetSectionSize(FX_FLOAT fFontSize);
+ CPVT_Size GetSectionSize(FX_FLOAT fFontSize);
CPVT_WordPlace GetBeginWordPlace() const;
CPVT_WordPlace GetEndWordPlace() const;
CPVT_WordPlace GetPrevWordPlace(const CPVT_WordPlace& place) const;
@@ -48,7 +47,7 @@ class CSection {
CPVT_WordPlace SecPlace;
CPVT_SectionInfo m_SecInfo;
CLines m_LineArray;
- CFX_ArrayTemplate<CPVT_WordInfo*> m_WordArray;
+ CPVT_ArrayTemplate<CPVT_WordInfo*> m_WordArray;
private:
friend class CTypeset;
diff --git a/core/fpdfdoc/ctypeset.h b/core/fpdfdoc/ctypeset.h
index 1401050b42..25bb31a801 100644
--- a/core/fpdfdoc/ctypeset.h
+++ b/core/fpdfdoc/ctypeset.h
@@ -16,17 +16,14 @@ class CSection;
class CTypeset {
public:
explicit CTypeset(CSection* pSection);
- ~CTypeset();
-
- CFX_PointF GetEditSize(FX_FLOAT fFontSize);
+ virtual ~CTypeset();
+ CPVT_Size 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 985ffa5971..88a4636bbc 100644
--- a/core/fpdfdoc/doc_vt.cpp
+++ b/core/fpdfdoc/doc_vt.cpp
@@ -4,19 +4,16 @@
// 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);
}
@@ -64,104 +61,102 @@ 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();
}
-
-CFX_PointF CSection::GetSectionSize(FX_FLOAT fFontSize) {
+CPVT_Size 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 (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) {
+ if (CLine* pPrevLine = m_LineArray.GetAt(place.nLineIndex - 1)) {
+ return pPrevLine->GetEndWordPlace();
+ }
+ } else {
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 (place.nWordIndex >= pLine->m_LineInfo.nEndWordIndex) {
+ if (CLine* pNextLine = m_LineArray.GetAt(place.nLineIndex + 1)) {
+ return pNextLine->GetBeginWordPlace();
+ }
+ } else {
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) {
- 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;
+ 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;
+ }
} else {
- place.nLineIndex = nMid;
- return;
+ break;
}
}
}
-
CPVT_WordPlace CSection::SearchWordPlace(const CFX_FloatPoint& point) const {
ASSERT(m_pVT);
CPVT_WordPlace place = GetBeginWordPlace();
@@ -177,78 +172,81 @@ 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;
- }
- if (IsFloatBigger(point.y, fBottom)) {
+ } 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;
}
-
- 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 {
- 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()));
+ 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_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;
}
-
- CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid);
- if (!pWord)
+ 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 {
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) {
@@ -257,28 +255,24 @@ 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();
@@ -295,19 +289,15 @@ 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 =
@@ -386,14 +376,12 @@ CPVT_FloatRect CTypeset::CharArray() {
}
return m_rcRet = CPVT_FloatRect(0, 0, x, y);
}
-
-CFX_PointF CTypeset::GetEditSize(FX_FLOAT fFontSize) {
+CPVT_Size CTypeset::GetEditSize(FX_FLOAT fFontSize) {
ASSERT(m_pSection);
ASSERT(m_pVT);
SplitLines(FALSE, fFontSize);
- return CFX_PointF(m_rcRet.Width(), m_rcRet.Height());
+ return CPVT_Size(m_rcRet.Width(), m_rcRet.Height());
}
-
CPVT_FloatRect CTypeset::Typeset() {
ASSERT(m_pVT);
m_pSection->m_LineArray.Empty();
@@ -705,103 +693,77 @@ 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);
- 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_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY);
- return;
+ 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;
}
-
- 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) {
+ fMaxX = fMinX + m_rcRet.Width();
+ fMinY = 0.0f;
+ 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)) {
default:
- case CPDF_VariableText::ScriptType::Normal:
- pWord->fWordY = fPosY - fMinY;
+ case 0:
+ fPosX = 0;
break;
- case CPDF_VariableText::ScriptType::Super:
- pWord->fWordY = fPosY - m_pVT->GetWordAscent(*pWord) - fMinY;
+ case 1:
+ fPosX = (fTypesetWidth - pLine->m_LineInfo.fLineWidth) *
+ VARIABLETEXT_HALF;
break;
- case CPDF_VariableText::ScriptType::Sub:
- pWord->fWordY = fPosY - m_pVT->GetWordDescent(*pWord) - fMinY;
+ case 2:
+ fPosX = fTypesetWidth - pLine->m_LineInfo.fLineWidth;
break;
}
- } else {
- pWord->fWordY = fPosY - fMinY;
+ 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;
}
- 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/include/cpdf_variabletext.h b/core/fpdfdoc/include/cpdf_variabletext.h
index e438223680..b73d3df8c1 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:
- explicit Provider(IPVT_FontMap* pFontMap);
+ 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();
- bool IsBigger(FX_FLOAT fFontSize) const;
+ FX_BOOL IsBigger(FX_FLOAT fFontSize);
CPVT_FloatRect RearrangeSections(const CPVT_WordRange& PlaceRange);
void ResetSectionArray();
- CFX_ArrayTemplate<CSection*> m_SectionArray;
+ CPVT_ArrayTemplate<CSection*> m_SectionArray;
int32_t m_nLimitChar;
int32_t m_nCharArray;
FX_BOOL m_bMultiLine;
diff --git a/core/fpdfdoc/doc_vt.h b/core/fpdfdoc/pdf_vt.h
index 09be92b8e7..a3b7883a9b 100644
--- a/core/fpdfdoc/doc_vt.h
+++ b/core/fpdfdoc/pdf_vt.h
@@ -4,8 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef CORE_FPDFDOC_DOC_VT_H_
-#define CORE_FPDFDOC_DOC_VT_H_
+#ifndef CORE_FPDFDOC_PDF_VT_H_
+#define CORE_FPDFDOC_PDF_VT_H_
#include "core/fpdfdoc/cpvt_floatrect.h"
#include "core/fpdfdoc/cpvt_lineinfo.h"
@@ -20,11 +20,42 @@ 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();
- ~CLine();
-
+ virtual ~CLine();
CPVT_WordPlace GetBeginWordPlace() const;
CPVT_WordPlace GetEndWordPlace() const;
CPVT_WordPlace GetPrevWordPlace(const CPVT_WordPlace& place) const;
@@ -32,12 +63,10 @@ class CLine {
CPVT_WordPlace LinePlace;
CPVT_LineInfo m_LineInfo;
};
-
class CLines {
public:
CLines() : m_nTotal(0) {}
- ~CLines() { RemoveAll(); }
-
+ virtual ~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; }
@@ -66,38 +95,55 @@ class CLines {
}
private:
- CFX_ArrayTemplate<CLine*> m_Lines;
+ CPVT_ArrayTemplate<CLine*> m_Lines;
int32_t m_nTotal;
};
class CPDF_EditContainer {
public:
- CPDF_EditContainer();
- virtual ~CPDF_EditContainer();
-
- virtual const CFX_FloatRect& GetPlateRect() const { return m_rcPlate; }
+ 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; }
- virtual CFX_FloatRect GetContentRect() const { return m_rcContent; }
+ virtual const CFX_FloatRect& GetPlateRect() const { return m_rcPlate; }
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 InToOut(const CFX_FloatPoint& point) const {
+ CFX_FloatPoint GetETPoint() const {
+ return CFX_FloatPoint(m_rcPlate.right, m_rcPlate.bottom);
+ }
+ inline CFX_FloatPoint InToOut(const CFX_FloatPoint& point) const {
return CFX_FloatPoint(point.x + GetBTPoint().x, GetBTPoint().y - point.y);
}
- CFX_FloatPoint OutToIn(const CFX_FloatPoint& point) const {
+ inline CFX_FloatPoint OutToIn(const CFX_FloatPoint& point) const {
return CFX_FloatPoint(point.x - GetBTPoint().x, GetBTPoint().y - point.y);
}
- CFX_FloatRect InToOut(const CPVT_FloatRect& rect) const;
+ 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);
+ }
private:
CFX_FloatRect m_rcPlate;
CPVT_FloatRect m_rcContent;
};
-#endif // CORE_FPDFDOC_DOC_VT_H_
+#endif // CORE_FPDFDOC_PDF_VT_H_