diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp | 60 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 5 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_formcontrol.cpp | 8 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_utils.cpp | 8 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_vt.cpp | 44 | ||||
-rw-r--r-- | core/src/fpdfdoc/pdf_vt.h | 33 | ||||
-rw-r--r-- | core/src/fpdftext/fpdf_text_int.cpp | 36 | ||||
-rw-r--r-- | core/src/fxcodec/codec/fx_codec_png.cpp | 12 | ||||
-rw-r--r-- | core/src/fxcodec/lbmp/fx_bmp.cpp | 23 | ||||
-rw-r--r-- | core/src/fxcrt/extension.h | 61 | ||||
-rw-r--r-- | core/src/fxcrt/fx_basic_buffer.cpp | 4 | ||||
-rw-r--r-- | core/src/fxcrt/fx_basic_wstring.cpp | 8 | ||||
-rw-r--r-- | core/src/fxcrt/fx_extension.cpp | 53 | ||||
-rw-r--r-- | core/src/fxcrt/xml_int.h | 9 | ||||
-rw-r--r-- | core/src/fxge/agg/src/fx_agg_driver.cpp | 34 | ||||
-rw-r--r-- | core/src/fxge/android/fpf_skiafont.cpp | 7 |
16 files changed, 237 insertions, 168 deletions
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp index 168cbf3a61..87b9e025bc 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp @@ -8,6 +8,8 @@ #include <limits.h> +#include <algorithm> + #include "core/include/fpdfapi/fpdf_page.h" #include "core/include/fpdfapi/fpdf_module.h" #include "core/include/fxcodec/fx_codec.h" @@ -41,6 +43,24 @@ int ComponentsForFamily(int family) { return 4; } +void ReverseRGB(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels) { + if (pDestBuf == pSrcBuf) { + for (int i = 0; i < pixels; i++) { + uint8_t temp = pDestBuf[2]; + pDestBuf[2] = pDestBuf[0]; + pDestBuf[0] = temp; + pDestBuf += 3; + } + } else { + for (int i = 0; i < pixels; i++) { + *pDestBuf++ = pSrcBuf[2]; + *pDestBuf++ = pSrcBuf[1]; + *pDestBuf++ = pSrcBuf[0]; + pSrcBuf += 3; + } + } +} + } // namespace CPDF_DeviceCS::CPDF_DeviceCS(CPDF_Document* pDoc, int family) @@ -82,9 +102,9 @@ FX_BOOL CPDF_DeviceCS::GetRGB(FX_FLOAT* pBuf, AdobeCMYK_to_sRGB(pBuf[0], pBuf[1], pBuf[2], pBuf[3], R, G, B); } else { FX_FLOAT k = pBuf[3]; - R = 1.0f - FX_MIN(1.0f, pBuf[0] + k); - G = 1.0f - FX_MIN(1.0f, pBuf[1] + k); - B = 1.0f - FX_MIN(1.0f, pBuf[2] + k); + R = 1.0f - std::min(1.0f, pBuf[0] + k); + G = 1.0f - std::min(1.0f, pBuf[1] + k); + B = 1.0f - std::min(1.0f, pBuf[2] + k); } } else { ASSERT(m_Family == PDFCS_PATTERN); @@ -148,22 +168,7 @@ FX_BOOL CPDF_DeviceCS::v_SetCMYK(FX_FLOAT* pBuf, } return FALSE; } -static void ReverseRGB(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels) { - if (pDestBuf == pSrcBuf) - for (int i = 0; i < pixels; i++) { - uint8_t temp = pDestBuf[2]; - pDestBuf[2] = pDestBuf[0]; - pDestBuf[0] = temp; - pDestBuf += 3; - } - else - for (int i = 0; i < pixels; i++) { - *pDestBuf++ = pSrcBuf[2]; - *pDestBuf++ = pSrcBuf[1]; - *pDestBuf++ = pSrcBuf[0]; - pSrcBuf += 3; - } -} + void CPDF_DeviceCS::TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, @@ -196,9 +201,9 @@ void CPDF_DeviceCS::TranslateImageLine(uint8_t* pDestBuf, pDestBuf[2], pDestBuf[1], pDestBuf[0]); } else { uint8_t k = pSrcBuf[3]; - pDestBuf[2] = 255 - FX_MIN(255, pSrcBuf[0] + k); - pDestBuf[1] = 255 - FX_MIN(255, pSrcBuf[1] + k); - pDestBuf[0] = 255 - FX_MIN(255, pSrcBuf[2] + k); + pDestBuf[2] = 255 - std::min(255, pSrcBuf[0] + k); + pDestBuf[1] = 255 - std::min(255, pSrcBuf[1] + k); + pDestBuf[0] = 255 - std::min(255, pSrcBuf[2] + k); } pSrcBuf += 4; pDestBuf += 3; @@ -1012,11 +1017,13 @@ CPDF_ColorSpace* CPDF_PatternCS::GetBaseCS() const { } class CPDF_SeparationCS : public CPDF_ColorSpace { public: - CPDF_SeparationCS(CPDF_Document* pDoc) + explicit CPDF_SeparationCS(CPDF_Document* pDoc) : CPDF_ColorSpace(pDoc, PDFCS_SEPARATION, 1), m_pAltCS(nullptr), m_pFunc(nullptr) {} ~CPDF_SeparationCS() override; + + // CPDF_ColorSpace: void GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, @@ -1109,11 +1116,13 @@ void CPDF_SeparationCS::EnableStdConversion(FX_BOOL bEnabled) { } class CPDF_DeviceNCS : public CPDF_ColorSpace { public: - CPDF_DeviceNCS(CPDF_Document* pDoc) + explicit CPDF_DeviceNCS(CPDF_Document* pDoc) : CPDF_ColorSpace(pDoc, PDFCS_DEVICEN, 0), m_pAltCS(nullptr), m_pFunc(nullptr) {} ~CPDF_DeviceNCS() override; + + // CPDF_ColorSpace: void GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, @@ -1183,10 +1192,11 @@ void CPDF_DeviceNCS::EnableStdConversion(FX_BOOL bEnabled) { m_pAltCS->EnableStdConversion(bEnabled); } } + CPDF_ColorSpace* CPDF_ColorSpace::GetStockCS(int family) { return CPDF_ModuleMgr::Get()->GetPageModule()->GetStockCS(family); - ; } + CPDF_ColorSpace* _CSFromName(const CFX_ByteString& name) { if (name == "DeviceRGB" || name == "RGB") { return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB); diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index c74aea9a21..f690c209a0 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -6,6 +6,7 @@ #include "render_int.h" +#include <algorithm> #include <memory> #include <vector> @@ -573,8 +574,8 @@ DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode, for (FX_DWORD i = 0; i < m_nComponents; i++) { int min_num = pArray->GetInteger(i * 2); int max_num = pArray->GetInteger(i * 2 + 1); - pCompData[i].m_ColorKeyMin = FX_MAX(min_num, 0); - pCompData[i].m_ColorKeyMax = FX_MIN(max_num, max_data); + pCompData[i].m_ColorKeyMin = std::max(min_num, 0); + pCompData[i].m_ColorKeyMax = std::min(max_num, max_data); } } bColorKey = TRUE; 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 diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp index cf6cde1169..f527f48814 100644 --- a/core/src/fpdftext/fpdf_text_int.cpp +++ b/core/src/fpdftext/fpdf_text_int.cpp @@ -161,9 +161,9 @@ FX_BOOL CPDF_TextPage::ParseTextPage() { PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(i); if (charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) { bNormal = TRUE; - } else if (charinfo.m_Unicode == 0 || IsControlChar(charinfo)) + } else if (charinfo.m_Unicode == 0 || IsControlChar(charinfo)) { bNormal = FALSE; - else { + } else { bNormal = TRUE; } if (bNormal) { @@ -1807,10 +1807,10 @@ FX_BOOL CPDF_TextPage::IsHyphen(FX_WCHAR curChar) { } preChar = (PAGECHAR_INFO)m_charList[size - 1]; } - if (FPDFTEXT_CHAR_PIECE == preChar.m_Flag) - if (0xAD == preChar.m_Unicode || 0x2D == preChar.m_Unicode) { - return TRUE; - } + if (FPDFTEXT_CHAR_PIECE == preChar.m_Flag && + (0xAD == preChar.m_Unicode || 0x2D == preChar.m_Unicode)) { + return TRUE; + } } return FALSE; } @@ -1920,17 +1920,14 @@ int CPDF_TextPage::ProcessInsertObject(const CPDF_TextObject* pObj, } } } - if (bNewline) { - if (IsHyphen(curChar)) { - return 3; - } - return 2; - } + if (bNewline) + return IsHyphen(curChar) ? 3 : 2; + int32_t nChars = pObj->CountChars(); - if (nChars == 1 && (0x2D == curChar || 0xAD == curChar)) - if (IsHyphen(curChar)) { - return 3; - } + if (nChars == 1 && (0x2D == curChar || 0xAD == curChar) && + IsHyphen(curChar)) { + return 3; + } CFX_WideString PrevStr = m_pPreTextObj->GetFont()->UnicodeFromCharCode(PrevItem.m_CharCode); FX_WCHAR preChar = PrevStr.GetAt(PrevStr.GetLength() - 1); @@ -1956,7 +1953,7 @@ int CPDF_TextPage::ProcessInsertObject(const CPDF_TextObject* pObj, threshold *= 1.5; } if (FXSYS_fabs(last_pos + last_width - x) > threshold && curChar != L' ' && - preChar != L' ') + preChar != L' ') { if (curChar != L' ' && preChar != L' ') { if ((x - last_pos - last_width) > threshold || (last_pos - x - last_width) > threshold) { @@ -1970,6 +1967,7 @@ int CPDF_TextPage::ProcessInsertObject(const CPDF_TextObject* pObj, return 1; } } + } return 0; } FX_BOOL CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1, @@ -2023,8 +2021,8 @@ FX_BOOL CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1, GetCharWidth(itemPer.m_CharCode, pTextObj2->GetFont()) * pTextObj2->GetFontSize() / 1000 * 0.9 || FXSYS_fabs(pTextObj1->GetPosY() - pTextObj2->GetPosY()) > - FX_MAX(FX_MAX(rcPreObj.Height(), rcPreObj.Width()), - pTextObj2->GetFontSize()) / + std::max(std::max(rcPreObj.Height(), rcPreObj.Width()), + pTextObj2->GetFontSize()) / 8) { return FALSE; } diff --git a/core/src/fxcodec/codec/fx_codec_png.cpp b/core/src/fxcodec/codec/fx_codec_png.cpp index 6401081ea3..3acfc19442 100644 --- a/core/src/fxcodec/codec/fx_codec_png.cpp +++ b/core/src/fxcodec/codec/fx_codec_png.cpp @@ -4,6 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include <algorithm>
+
#include "core/include/fxcodec/fx_codec.h"
#include "core/include/fxge/fx_dib.h"
#include "codec_int.h"
@@ -62,24 +64,24 @@ static void _png_load_bmp_attribute(png_structp png_ptr, #endif
#if defined(PNG_TEXT_SUPPORTED)
int i;
- FX_DWORD len;
+ FX_STRSIZE len;
const FX_CHAR* buf;
int num_text;
png_textp text = NULL;
png_get_text(png_ptr, info_ptr, &text, &num_text);
for (i = 0; i < num_text; i++) {
- len = (FX_DWORD)FXSYS_strlen(text[i].key);
+ len = FXSYS_strlen(text[i].key);
buf = "Time";
- if (!FXSYS_memcmp(buf, text[i].key, FX_MIN(len, FXSYS_strlen(buf)))) {
+ if (!FXSYS_memcmp(buf, text[i].key, std::min(len, FXSYS_strlen(buf)))) {
if (!bTime) {
FXSYS_memset(pAttribute->m_strTime, 0, sizeof(pAttribute->m_strTime));
FXSYS_memcpy(
pAttribute->m_strTime, text[i].text,
- FX_MIN(sizeof(pAttribute->m_strTime) - 1, text[i].text_length));
+ std::min(sizeof(pAttribute->m_strTime) - 1, text[i].text_length));
}
} else {
buf = "Author";
- if (!FXSYS_memcmp(buf, text[i].key, FX_MIN(len, FXSYS_strlen(buf)))) {
+ if (!FXSYS_memcmp(buf, text[i].key, std::min(len, FXSYS_strlen(buf)))) {
pAttribute->m_strAuthor.Empty();
pAttribute->m_strAuthor.Load((uint8_t*)text[i].text,
(FX_STRSIZE)text[i].text_length);
diff --git a/core/src/fxcodec/lbmp/fx_bmp.cpp b/core/src/fxcodec/lbmp/fx_bmp.cpp index 98bcefdaba..00477581a1 100644 --- a/core/src/fxcodec/lbmp/fx_bmp.cpp +++ b/core/src/fxcodec/lbmp/fx_bmp.cpp @@ -5,6 +5,16 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "fx_bmp.h"
+
+#include <algorithm>
+
+namespace {
+
+const size_t kBmpCoreHeaderSize = 12;
+const size_t kBmpInfoHeaderSize = 40;
+
+} // namespace
+
FX_DWORD _GetDWord_LSBFirst(uint8_t* p) {
return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
}
@@ -80,10 +90,12 @@ int32_t _bmp_read_header(bmp_decompress_struct_p bmp_ptr) { bmp_ptr->img_ifh_size =
_GetDWord_LSBFirst(bmp_ptr->next_in + bmp_ptr->skip_size);
bmp_ptr->pal_type = 0;
- ASSERT(sizeof(BmpCoreHeader) == 12);
- ASSERT(sizeof(BmpInfoHeader) == 40);
+ static_assert(sizeof(BmpCoreHeader) == kBmpCoreHeaderSize,
+ "BmpCoreHeader has wrong size");
+ static_assert(sizeof(BmpInfoHeader) == kBmpInfoHeaderSize,
+ "BmpInfoHeader has wrong size");
switch (bmp_ptr->img_ifh_size) {
- case FX_MIN(12, sizeof(BmpCoreHeader)): {
+ case kBmpCoreHeaderSize: {
bmp_ptr->pal_type = 1;
BmpCoreHeaderPtr bmp_core_header_ptr = NULL;
if (_bmp_read_data(bmp_ptr, (uint8_t**)&bmp_core_header_ptr,
@@ -100,7 +112,7 @@ int32_t _bmp_read_header(bmp_decompress_struct_p bmp_ptr) { bmp_ptr->compress_flag = BMP_RGB;
bmp_ptr->imgTB_flag = FALSE;
} break;
- case FX_MIN(40, sizeof(BmpInfoHeader)): {
+ case kBmpInfoHeaderSize: {
BmpInfoHeaderPtr bmp_info_header_ptr = NULL;
if (_bmp_read_data(bmp_ptr, (uint8_t**)&bmp_info_header_ptr,
bmp_ptr->img_ifh_size) == NULL) {
@@ -127,7 +139,8 @@ int32_t _bmp_read_header(bmp_decompress_struct_p bmp_ptr) { }
} break;
default: {
- if (bmp_ptr->img_ifh_size > FX_MIN(40, sizeof(BmpInfoHeader))) {
+ if (bmp_ptr->img_ifh_size >
+ std::min(kBmpInfoHeaderSize, sizeof(BmpInfoHeader))) {
BmpInfoHeaderPtr bmp_info_header_ptr = NULL;
if (_bmp_read_data(bmp_ptr, (uint8_t**)&bmp_info_header_ptr,
bmp_ptr->img_ifh_size) == NULL) {
diff --git a/core/src/fxcrt/extension.h b/core/src/fxcrt/extension.h index 638ffef58e..6e799eb3a4 100644 --- a/core/src/fxcrt/extension.h +++ b/core/src/fxcrt/extension.h @@ -7,6 +7,8 @@ #ifndef CORE_SRC_FXCRT_EXTENSION_H_ #define CORE_SRC_FXCRT_EXTENSION_H_ +#include <algorithm> + #include "core/include/fxcrt/fx_basic.h" #include "core/include/fxcrt/fx_safe_types.h" @@ -67,39 +69,21 @@ class CFX_CRTFileAccess : public IFX_FileAccess { class CFX_CRTFileStream final : public IFX_FileStream { public: - CFX_CRTFileStream(IFXCRT_FileAccess* pFA) : m_pFile(pFA), m_dwCount(1) {} - ~CFX_CRTFileStream() override { - if (m_pFile) { - m_pFile->Release(); - } - } - virtual IFX_FileStream* Retain() override { - m_dwCount++; - return this; - } - virtual void Release() override { - FX_DWORD nCount = --m_dwCount; - if (!nCount) { - delete this; - } - } - virtual FX_FILESIZE GetSize() override { return m_pFile->GetSize(); } - virtual FX_BOOL IsEOF() override { return GetPosition() >= GetSize(); } - virtual FX_FILESIZE GetPosition() override { return m_pFile->GetPosition(); } - virtual FX_BOOL ReadBlock(void* buffer, - FX_FILESIZE offset, - size_t size) override { - return (FX_BOOL)m_pFile->ReadPos(buffer, size, offset); - } - virtual size_t ReadBlock(void* buffer, size_t size) override { - return m_pFile->Read(buffer, size); - } - virtual FX_BOOL WriteBlock(const void* buffer, - FX_FILESIZE offset, - size_t size) override { - return (FX_BOOL)m_pFile->WritePos(buffer, size, offset); - } - virtual FX_BOOL Flush() override { return m_pFile->Flush(); } + explicit CFX_CRTFileStream(IFXCRT_FileAccess* pFA); + ~CFX_CRTFileStream() override; + + // IFX_FileStream: + IFX_FileStream* Retain() override; + void Release() override; + FX_FILESIZE GetSize() override; + FX_BOOL IsEOF() override; + FX_FILESIZE GetPosition() override; + FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; + size_t ReadBlock(void* buffer, size_t size) override; + FX_BOOL WriteBlock(const void* buffer, + FX_FILESIZE offset, + size_t size) override; + FX_BOOL Flush() override; protected: IFXCRT_FileAccess* m_pFile; @@ -111,7 +95,7 @@ class CFX_CRTFileStream final : public IFX_FileStream { #define FX_MEMSTREAM_TakeOver 0x02 class CFX_MemoryStream final : public IFX_MemoryStream { public: - CFX_MemoryStream(FX_BOOL bConsecutive) + explicit CFX_MemoryStream(FX_BOOL bConsecutive) : m_dwCount(1), m_nTotalSize(0), m_nCurSize(0), @@ -190,7 +174,7 @@ class CFX_MemoryStream final : public IFX_MemoryStream { if (m_nCurPos >= m_nCurSize) { return 0; } - size_t nRead = FX_MIN(size, m_nCurSize - m_nCurPos); + size_t nRead = std::min(size, m_nCurSize - m_nCurPos); if (!ReadBlock(buffer, (int32_t)m_nCurPos, nRead)) { return 0; } @@ -262,12 +246,13 @@ class CFX_MemoryStream final : public IFX_MemoryStream { void EstimateSize(size_t nInitSize, size_t nGrowSize) override { if (m_dwFlags & FX_MEMSTREAM_Consecutive) { if (m_Blocks.GetSize() < 1) { - uint8_t* pBlock = FX_Alloc(uint8_t, FX_MAX(nInitSize, 4096)); + uint8_t* pBlock = + FX_Alloc(uint8_t, std::max(nInitSize, static_cast<size_t>(4096))); m_Blocks.Add(pBlock); } - m_nGrowSize = FX_MAX(nGrowSize, 4096); + m_nGrowSize = std::max(nGrowSize, static_cast<size_t>(4096)); } else if (m_Blocks.GetSize() < 1) { - m_nGrowSize = FX_MAX(nGrowSize, 4096); + m_nGrowSize = std::max(nGrowSize, static_cast<size_t>(4096)); } } uint8_t* GetBuffer() const override { diff --git a/core/src/fxcrt/fx_basic_buffer.cpp b/core/src/fxcrt/fx_basic_buffer.cpp index e5c6c6d4b9..4ef86bbf41 100644 --- a/core/src/fxcrt/fx_basic_buffer.cpp +++ b/core/src/fxcrt/fx_basic_buffer.cpp @@ -4,6 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#include <algorithm> + #include "core/include/fxcrt/fx_basic.h" FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); @@ -401,7 +403,7 @@ int32_t IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) { uint8_t* buffer = (uint8_t*)pBuf; FX_STRSIZE temp_size = (FX_STRSIZE)size; while (temp_size > 0) { - FX_STRSIZE buf_size = FX_MIN(m_BufSize - m_Length, (FX_STRSIZE)temp_size); + FX_STRSIZE buf_size = std::min(m_BufSize - m_Length, (FX_STRSIZE)temp_size); FXSYS_memcpy(m_pBuffer + m_Length, buffer, buf_size); m_Length += buf_size; if (m_Length == m_BufSize) { diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp index dd26f595f2..2370c87cf1 100644 --- a/core/src/fxcrt/fx_basic_wstring.cpp +++ b/core/src/fxcrt/fx_basic_wstring.cpp @@ -5,6 +5,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include <stddef.h> // For offsetof(). + +#include <algorithm> #include <cctype> #include "core/include/fxcrt/fx_basic.h" @@ -639,7 +641,7 @@ FX_STRSIZE CFX_WideString::Replace(const FX_WCHAR* lpszOld, pOldData->Release(); } lpszStart = m_pData->m_String; - lpszEnd = m_pData->m_String + FX_MAX(m_pData->m_nDataLength, nNewLength); + lpszEnd = m_pData->m_String + std::max(m_pData->m_nDataLength, nNewLength); { while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != NULL && @@ -758,9 +760,7 @@ void CFX_WideString::FormatV(const FX_WCHAR* lpszFormat, va_list argList) { nMaxLen += 2; } else if (*lpsz == '*') { nWidth = va_arg(argList, int); - } else if (*lpsz == '-' || *lpsz == '+' || *lpsz == '0' || *lpsz == ' ') - ; - else { + } else if (*lpsz != '-' && *lpsz != '+' && *lpsz != '0' && *lpsz != ' ') { break; } } diff --git a/core/src/fxcrt/fx_extension.cpp b/core/src/fxcrt/fx_extension.cpp index 4669ac4be4..8a6987b066 100644 --- a/core/src/fxcrt/fx_extension.cpp +++ b/core/src/fxcrt/fx_extension.cpp @@ -14,6 +14,59 @@ #include <ctime> #endif +CFX_CRTFileStream::CFX_CRTFileStream(IFXCRT_FileAccess* pFA) + : m_pFile(pFA), m_dwCount(1) {} + +CFX_CRTFileStream::~CFX_CRTFileStream() { + if (m_pFile) { + m_pFile->Release(); + } +} + +IFX_FileStream* CFX_CRTFileStream::Retain() { + m_dwCount++; + return this; +} + +void CFX_CRTFileStream::Release() { + FX_DWORD nCount = --m_dwCount; + if (!nCount) { + delete this; + } +} + +FX_FILESIZE CFX_CRTFileStream::GetSize() { + return m_pFile->GetSize(); +} + +FX_BOOL CFX_CRTFileStream::IsEOF() { + return GetPosition() >= GetSize(); +} + +FX_FILESIZE CFX_CRTFileStream::GetPosition() { + return m_pFile->GetPosition(); +} + +FX_BOOL CFX_CRTFileStream::ReadBlock(void* buffer, + FX_FILESIZE offset, + size_t size) { + return (FX_BOOL)m_pFile->ReadPos(buffer, size, offset); +} + +size_t CFX_CRTFileStream::ReadBlock(void* buffer, size_t size) { + return m_pFile->Read(buffer, size); +} + +FX_BOOL CFX_CRTFileStream::WriteBlock(const void* buffer, + FX_FILESIZE offset, + size_t size) { + return (FX_BOOL)m_pFile->WritePos(buffer, size, offset); +} + +FX_BOOL CFX_CRTFileStream::Flush() { + return m_pFile->Flush(); +} + #ifdef PDF_ENABLE_XFA IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath) { if (wsPath.GetLength() == 0) diff --git a/core/src/fxcrt/xml_int.h b/core/src/fxcrt/xml_int.h index b11a64b505..a837327445 100644 --- a/core/src/fxcrt/xml_int.h +++ b/core/src/fxcrt/xml_int.h @@ -7,6 +7,8 @@ #ifndef CORE_SRC_FXCRT_XML_INT_H_ #define CORE_SRC_FXCRT_XML_INT_H_ +#include <algorithm> + #include "core/include/fxcrt/fx_stream.h" class CFX_UTF8Decoder; @@ -43,10 +45,9 @@ class CXML_DataBufAcc : public IFX_BufferRead { size_t m_dwCurPos; }; -#define FX_XMLDATASTREAM_BufferSize (32 * 1024) class CXML_DataStmAcc : public IFX_BufferRead { public: - CXML_DataStmAcc(IFX_FileRead* pFileRead) + explicit CXML_DataStmAcc(IFX_FileRead* pFileRead) : m_pFileRead(pFileRead), m_pBuffer(NULL), m_nStart(0), m_dwSize(0) { FXSYS_assert(m_pFileRead); } @@ -69,7 +70,9 @@ class CXML_DataStmAcc : public IFX_BufferRead { if (m_nStart >= nLength) { return FALSE; } - m_dwSize = (size_t)FX_MIN(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart); + static const FX_FILESIZE FX_XMLDATASTREAM_BufferSize = 32 * 1024; + m_dwSize = static_cast<size_t>( + std::min(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart)); if (!m_pBuffer) { m_pBuffer = FX_Alloc(uint8_t, m_dwSize); } diff --git a/core/src/fxge/agg/src/fx_agg_driver.cpp b/core/src/fxge/agg/src/fx_agg_driver.cpp index ed2e8e41f0..6828531cba 100644 --- a/core/src/fxge/agg/src/fx_agg_driver.cpp +++ b/core/src/fxge/agg/src/fx_agg_driver.cpp @@ -6,6 +6,8 @@ #include "core/src/fxge/agg/include/fx_agg_driver.h" +#include <algorithm> + #include "core/include/fxcodec/fx_codec.h" #include "core/include/fxge/fx_ge.h" #include "core/src/fxge/dib/dib_int.h" @@ -19,20 +21,15 @@ #include "third_party/agg23/agg_renderer_scanline.h" #include "third_party/agg23/agg_scanline_u.h" -void _HardClip(FX_FLOAT& x, FX_FLOAT& y) { - if (x > 50000) { - x = 50000; - } - if (x < -50000) { - x = -50000; - } - if (y > 50000) { - y = 50000; - } - if (y < -50000) { - y = -50000; - } +namespace { + +void HardClip(FX_FLOAT& x, FX_FLOAT& y) { + x = std::max(std::min(x, 50000.0f), -50000.0f); + y = std::max(std::min(y, 50000.0f), -50000.0f); } + +} // namespace + void CAgg_PathData::BuildPath(const CFX_PathData* pPathData, const CFX_Matrix* pObject2Device) { int nPoints = pPathData->GetPointCount(); @@ -42,7 +39,7 @@ void CAgg_PathData::BuildPath(const CFX_PathData* pPathData, if (pObject2Device) { pObject2Device->Transform(x, y); } - _HardClip(x, y); + HardClip(x, y); int point_type = pPoints[i].m_Flag & FXPT_TYPE; if (point_type == FXPT_MOVETO) { m_PathData.move_to(x, y); @@ -73,6 +70,7 @@ void CAgg_PathData::BuildPath(const CFX_PathData* pPathData, } } namespace agg { + template <class BaseRenderer> class renderer_scanline_aa_offset { public: @@ -109,7 +107,9 @@ class renderer_scanline_aa_offset { color_type m_color; unsigned m_left, m_top; }; -} + +} // namespace agg + static void RasterizeStroke(agg::rasterizer_scanline_aa& rasterizer, agg::path_storage& path_data, const CFX_Matrix* pObject2Device, @@ -1257,8 +1257,8 @@ FX_BOOL CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData, } CFX_Matrix matrix1, matrix2; if (pObject2Device) { - matrix1.a = - FX_MAX(FXSYS_fabs(pObject2Device->a), FXSYS_fabs(pObject2Device->b)); + matrix1.a = std::max(FXSYS_fabs(pObject2Device->a), + FXSYS_fabs(pObject2Device->b)); matrix1.d = matrix1.a; matrix2.Set(pObject2Device->a / matrix1.a, pObject2Device->b / matrix1.a, pObject2Device->c / matrix1.d, pObject2Device->d / matrix1.d, diff --git a/core/src/fxge/android/fpf_skiafont.cpp b/core/src/fxge/android/fpf_skiafont.cpp index ba202acc92..222b28ee8f 100644 --- a/core/src/fxge/android/fpf_skiafont.cpp +++ b/core/src/fxge/android/fpf_skiafont.cpp @@ -5,6 +5,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "fx_fpf.h" + +#include <algorithm> + #if _FX_OS_ == _FX_ANDROID_ #include "fpf_skiafont.h" #include "fpf_skiafontmgr.h" @@ -106,8 +109,8 @@ FX_BOOL CFPF_SkiaFont::GetGlyphBBox(int32_t iGlyphIndex, FX_RECT& rtBBox) { rtBBox.right = FPF_EM_ADJUST(x_ppem, cbox.xMax); rtBBox.top = FPF_EM_ADJUST(y_ppem, cbox.yMax); rtBBox.bottom = FPF_EM_ADJUST(y_ppem, cbox.yMin); - rtBBox.top = FX_MIN(rtBBox.top, GetAscent()); - rtBBox.bottom = FX_MAX(rtBBox.bottom, GetDescent()); + rtBBox.top = std::min(rtBBox.top, GetAscent()); + rtBBox.bottom = std::max(rtBBox.bottom, GetDescent()); FXFT_Done_Glyph(glyph); return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; } |