summaryrefslogtreecommitdiff
path: root/core/src/fpdfdoc
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2016-01-11 11:59:17 -0800
committerLei Zhang <thestig@chromium.org>2016-01-11 11:59:17 -0800
commit375a86403b7fa8d17d7b142c270e2d8e33bb924f (patch)
tree1db1ffddb2bbbcd429cd1d7954b1949bfa54e1ab /core/src/fpdfdoc
parent492961df3011ccc25646eae12ac6e6dcfe7f26da (diff)
downloadpdfium-375a86403b7fa8d17d7b142c270e2d8e33bb924f.tar.xz
Merge to XFA: Switch most min/max macros to std::min/max.
Fix lint errors along the way. R=tsepez@chromium.org TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1567343002 . (cherry picked from commit 9adfbb0920a258e916003b1ee9515e97879db82a) Review URL: https://codereview.chromium.org/1577503002 .
Diffstat (limited to 'core/src/fpdfdoc')
-rw-r--r--core/src/fpdfdoc/doc_formcontrol.cpp8
-rw-r--r--core/src/fpdfdoc/doc_utils.cpp8
-rw-r--r--core/src/fpdfdoc/doc_vt.cpp44
-rw-r--r--core/src/fpdfdoc/pdf_vt.h33
4 files changed, 46 insertions, 47 deletions
diff --git a/core/src/fpdfdoc/doc_formcontrol.cpp b/core/src/fpdfdoc/doc_formcontrol.cpp
index bd339e375c..6c3d1ec9c4 100644
--- a/core/src/fpdfdoc/doc_formcontrol.cpp
+++ b/core/src/fpdfdoc/doc_formcontrol.cpp
@@ -4,6 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include <algorithm>
+
#include "core/include/fpdfdoc/fpdf_doc.h"
CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField,
@@ -353,9 +355,9 @@ FX_ARGB CPDF_ApSettings::GetColor(int& iColorType,
FX_FLOAT m = pEntry->GetNumber(1);
FX_FLOAT y = pEntry->GetNumber(2);
FX_FLOAT k = pEntry->GetNumber(3);
- FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
- FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
- FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
+ FX_FLOAT r = 1.0f - std::min(1.0f, c + k);
+ FX_FLOAT g = 1.0f - std::min(1.0f, m + k);
+ FX_FLOAT b = 1.0f - std::min(1.0f, y + k);
color = ArgbEncode(255, (int)(r * 255), (int)(g * 255), (int)(b * 255));
}
return color;
diff --git a/core/src/fpdfdoc/doc_utils.cpp b/core/src/fpdfdoc/doc_utils.cpp
index 89836739b3..4856cb51e5 100644
--- a/core/src/fpdfdoc/doc_utils.cpp
+++ b/core/src/fpdfdoc/doc_utils.cpp
@@ -4,6 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include <algorithm>
+
#include "core/include/fpdfdoc/fpdf_doc.h"
#include "doc_utils.h"
@@ -179,9 +181,9 @@ void CPDF_DefaultAppearance::GetColor(FX_ARGB& color,
FX_FLOAT m = FX_atof((CFX_ByteString)syntax.GetWord());
FX_FLOAT y = FX_atof((CFX_ByteString)syntax.GetWord());
FX_FLOAT k = FX_atof((CFX_ByteString)syntax.GetWord());
- FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
- FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
- FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
+ FX_FLOAT r = 1.0f - std::min(1.0f, c + k);
+ FX_FLOAT g = 1.0f - std::min(1.0f, m + k);
+ FX_FLOAT b = 1.0f - std::min(1.0f, y + k);
color = ArgbEncode(255, (int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f),
(int)(b * 255 + 0.5f));
}
diff --git a/core/src/fpdfdoc/doc_vt.cpp b/core/src/fpdfdoc/doc_vt.cpp
index 8df687ed59..e5c9ad8eba 100644
--- a/core/src/fpdfdoc/doc_vt.cpp
+++ b/core/src/fpdfdoc/doc_vt.cpp
@@ -4,6 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include <algorithm>
+
#include "core/include/fpdfdoc/fpdf_doc.h"
#include "core/include/fpdfdoc/fpdf_vt.h"
#include "pdf_vt.h"
@@ -72,7 +74,7 @@ CPVT_WordPlace CSection::AddWord(const CPVT_WordPlace& place,
const CPVT_WordInfo& wordinfo) {
CPVT_WordInfo* pWord = new CPVT_WordInfo(wordinfo);
int32_t nWordIndex =
- FPDF_MAX(FPDF_MIN(place.nWordIndex, m_WordArray.GetSize()), 0);
+ std::max(std::min(place.nWordIndex, m_WordArray.GetSize()), 0);
if (nWordIndex == m_WordArray.GetSize()) {
m_WordArray.Add(pWord);
} else {
@@ -356,17 +358,17 @@ CPVT_FloatRect CTypeset::CharArray() {
if (w == 0) {
pLine->m_LineInfo.fLineX = x;
}
- if (w != m_pSection->m_WordArray.GetSize() - 1)
+ if (w != m_pSection->m_WordArray.GetSize() - 1) {
pWord->fWordTail =
(fNodeWidth - (fWordWidth + fNextWidth) * PVT_HALF > 0
? fNodeWidth - (fWordWidth + fNextWidth) * PVT_HALF
: 0);
- else {
+ } else {
pWord->fWordTail = 0;
}
x += fWordWidth;
- fLineAscent = FPDF_MAX(fLineAscent, fWordAscent);
- fLineDescent = FPDF_MIN(fLineDescent, fWordDescent);
+ fLineAscent = std::max(fLineAscent, fWordAscent);
+ fLineDescent = std::min(fLineDescent, fWordDescent);
}
}
pLine->m_LineInfo.nBeginWordIndex = 0;
@@ -582,7 +584,7 @@ void CTypeset::SplitLines(FX_BOOL bTypeset, FX_FLOAT fFontSize) {
int32_t nCharIndex = 0;
CPVT_LineInfo line;
FX_FLOAT fWordWidth = 0;
- FX_FLOAT fTypesetWidth = FPDF_MAX(
+ FX_FLOAT fTypesetWidth = std::max(
m_pVT->GetPlateWidth() - m_pVT->GetLineIndent(m_pSection->m_SecInfo),
0.0f);
int32_t nTotalWords = m_pSection->m_WordArray.GetSize();
@@ -598,15 +600,15 @@ void CTypeset::SplitLines(FX_BOOL bTypeset, FX_FLOAT fFontSize) {
if (pWord) {
if (bTypeset) {
fLineAscent =
- FPDF_MAX(fLineAscent, m_pVT->GetWordAscent(*pWord, TRUE));
+ std::max(fLineAscent, m_pVT->GetWordAscent(*pWord, TRUE));
fLineDescent =
- FPDF_MIN(fLineDescent, m_pVT->GetWordDescent(*pWord, TRUE));
+ std::min(fLineDescent, m_pVT->GetWordDescent(*pWord, TRUE));
fWordWidth = m_pVT->GetWordWidth(*pWord);
} else {
fLineAscent =
- FPDF_MAX(fLineAscent, m_pVT->GetWordAscent(*pWord, fFontSize));
+ std::max(fLineAscent, m_pVT->GetWordAscent(*pWord, fFontSize));
fLineDescent =
- FPDF_MIN(fLineDescent, m_pVT->GetWordDescent(*pWord, fFontSize));
+ std::min(fLineDescent, m_pVT->GetWordDescent(*pWord, fFontSize));
fWordWidth = m_pVT->GetWordWidth(
pWord->nFontIndex, pWord->Word, m_pVT->m_wSubWord,
m_pVT->m_fCharSpace, m_pVT->m_nHorzScale, fFontSize,
@@ -662,7 +664,7 @@ void CTypeset::SplitLines(FX_BOOL bTypeset, FX_FLOAT fFontSize) {
}
fMaxY += (fLineAscent + m_pVT->GetLineLeading(m_pSection->m_SecInfo));
fMaxY += (-fLineDescent);
- fMaxX = FPDF_MAX(fLineWidth, fMaxX);
+ fMaxX = std::max(fLineWidth, fMaxX);
nLineHead = i;
fLineWidth = 0.0f;
fLineAscent = 0.0f;
@@ -688,7 +690,7 @@ void CTypeset::SplitLines(FX_BOOL bTypeset, FX_FLOAT fFontSize) {
}
fMaxY += (fLineAscent + m_pVT->GetLineLeading(m_pSection->m_SecInfo));
fMaxY += (-fLineDescent);
- fMaxX = FPDF_MAX(fLineWidth, fMaxX);
+ fMaxX = std::max(fLineWidth, fMaxX);
}
} else {
if (bTypeset) {
@@ -720,7 +722,7 @@ void CTypeset::OutputLines() {
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 = FPDF_MAX(m_pVT->GetPlateWidth() - fLineIndent, 0.0f);
+ FX_FLOAT fTypesetWidth = std::max(m_pVT->GetPlateWidth() - fLineIndent, 0.0f);
switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) {
default:
case 0:
@@ -1259,7 +1261,7 @@ CPVT_WordPlace CPDF_VariableText::AddSection(const CPVT_WordPlace& place,
return place;
}
int32_t nSecIndex =
- FPDF_MAX(FPDF_MIN(place.nSecIndex, m_SectionArray.GetSize()), 0);
+ std::max(std::min(place.nSecIndex, m_SectionArray.GetSize()), 0);
CSection* pSection = new CSection(this);
pSection->m_SecInfo = secinfo;
pSection->SecPlace.nSecIndex = nSecIndex;
@@ -1287,7 +1289,7 @@ CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace& place,
}
CPVT_WordPlace newplace = place;
newplace.nSecIndex =
- FPDF_MAX(FPDF_MIN(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0);
+ std::max(std::min(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0);
if (CSection* pSection = m_SectionArray.GetAt(newplace.nSecIndex)) {
return pSection->AddWord(newplace, wordinfo);
}
@@ -1332,7 +1334,7 @@ FX_BOOL CPDF_VariableText::GetSectionInfo(const CPVT_WordPlace& place,
return FALSE;
}
CPDF_Rect CPDF_VariableText::GetContentRect() const {
- return InToOut(CPDF_EditContainer::GetContentRect());
+ return InToOut(CPVT_FloatRect(CPDF_EditContainer::GetContentRect()));
}
FX_FLOAT CPDF_VariableText::GetWordFontSize(const CPVT_WordInfo& WordInfo,
FX_BOOL bFactFontSize) {
@@ -1576,7 +1578,7 @@ FX_BOOL CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) {
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);
- szTotal.x = FPDF_MAX(size.x, szTotal.x);
+ szTotal.x = std::max(size.x, szTotal.x);
szTotal.y += size.y;
if (IsFloatBigger(szTotal.x, GetPlateWidth()) ||
IsFloatBigger(szTotal.y, GetPlateHeight())) {
@@ -1617,10 +1619,10 @@ CPVT_FloatRect CPDF_VariableText::RearrangeSections(
if (s == 0) {
rcRet = rcSec;
} else {
- rcRet.left = FPDF_MIN(rcSec.left, rcRet.left);
- rcRet.top = FPDF_MIN(rcSec.top, rcRet.top);
- rcRet.right = FPDF_MAX(rcSec.right, rcRet.right);
- rcRet.bottom = FPDF_MAX(rcSec.bottom, rcRet.bottom);
+ rcRet.left = std::min(rcSec.left, rcRet.left);
+ rcRet.top = std::min(rcSec.top, rcRet.top);
+ rcRet.right = std::max(rcSec.right, rcRet.right);
+ rcRet.bottom = std::max(rcSec.bottom, rcRet.bottom);
}
fPosY += rcSec.Height();
}
diff --git a/core/src/fpdfdoc/pdf_vt.h b/core/src/fpdfdoc/pdf_vt.h
index 2cd673fbe5..286fad5772 100644
--- a/core/src/fpdfdoc/pdf_vt.h
+++ b/core/src/fpdfdoc/pdf_vt.h
@@ -22,14 +22,7 @@ class CPDF_VariableText_Iterator;
#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
#define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
#define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
-template <class T>
-T FPDF_MIN(const T& i, const T& j) {
- return ((i < j) ? i : j);
-}
-template <class T>
-T FPDF_MAX(const T& i, const T& j) {
- return ((i > j) ? i : j);
-}
+
class CPVT_Size {
public:
CPVT_Size() : x(0.0f), y(0.0f) {}
@@ -51,7 +44,7 @@ class CPVT_FloatRect : public CFX_FloatRect {
right = other_right;
bottom = other_bottom;
}
- CPVT_FloatRect(const CPDF_Rect& rect) {
+ explicit CPVT_FloatRect(const CPDF_Rect& rect) {
left = rect.left;
top = rect.top;
right = rect.right;
@@ -246,7 +239,7 @@ class CSection {
friend class CTypeset;
public:
- CSection(CPDF_VariableText* pVT);
+ explicit CSection(CPDF_VariableText* pVT);
virtual ~CSection();
void ResetAll();
void ResetLineArray();
@@ -285,7 +278,7 @@ class CSection {
};
class CTypeset {
public:
- CTypeset(CSection* pSection);
+ explicit CTypeset(CSection* pSection);
virtual ~CTypeset();
CPVT_Size GetEditSize(FX_FLOAT fFontSize);
CPVT_FloatRect Typeset();
@@ -307,37 +300,37 @@ class CPDF_EditContainer {
virtual const CPDF_Rect& GetPlateRect() const { return m_rcPlate; }
virtual void SetContentRect(const CPVT_FloatRect& rect) {
m_rcContent = rect;
- };
+ }
virtual CPDF_Rect 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());
- };
+ }
CPDF_Point GetBTPoint() const {
return CPDF_Point(m_rcPlate.left, m_rcPlate.top);
- };
+ }
CPDF_Point GetETPoint() const {
return CPDF_Point(m_rcPlate.right, m_rcPlate.bottom);
- };
+ }
inline CPDF_Point InToOut(const CPDF_Point& point) const {
return CPDF_Point(point.x + GetBTPoint().x, GetBTPoint().y - point.y);
- };
+ }
inline CPDF_Point OutToIn(const CPDF_Point& point) const {
return CPDF_Point(point.x - GetBTPoint().x, GetBTPoint().y - point.y);
- };
+ }
inline CPDF_Rect InToOut(const CPVT_FloatRect& rect) const {
CPDF_Point ptLeftTop = InToOut(CPDF_Point(rect.left, rect.top));
CPDF_Point ptRightBottom = InToOut(CPDF_Point(rect.right, rect.bottom));
return CPDF_Rect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x,
ptLeftTop.y);
- };
+ }
inline CPVT_FloatRect OutToIn(const CPDF_Rect& rect) const {
CPDF_Point ptLeftTop = OutToIn(CPDF_Point(rect.left, rect.top));
CPDF_Point ptRightBottom = OutToIn(CPDF_Point(rect.right, rect.bottom));
return CPVT_FloatRect(ptLeftTop.x, ptLeftTop.y, ptRightBottom.x,
ptRightBottom.y);
- };
+ }
private:
CPDF_Rect m_rcPlate;
@@ -539,7 +532,7 @@ class CPDF_VariableText : public IPDF_VariableText, private CPDF_EditContainer {
class CPDF_VariableText_Iterator : public IPDF_VariableText_Iterator {
public:
- CPDF_VariableText_Iterator(CPDF_VariableText* pVT);
+ explicit CPDF_VariableText_Iterator(CPDF_VariableText* pVT);
~CPDF_VariableText_Iterator() override;
// IPDF_VariableText_Iterator