summaryrefslogtreecommitdiff
path: root/fpdfsdk/pdfwindow/PWL_FontMap.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-14 15:53:36 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-15 00:03:38 +0000
commit193e6ca5e48ee99e620f0e7546f1407ba1a20323 (patch)
tree11d920c59a89247d28fe590d77ab6d6a9ce37a0c /fpdfsdk/pdfwindow/PWL_FontMap.cpp
parentcd5139a291113f177d3494990efbcaf388d1f3bf (diff)
downloadpdfium-193e6ca5e48ee99e620f0e7546f1407ba1a20323.tar.xz
Add IndexInBounds() convenience routine.
Avoid writing |Type| in CollectionSize<Type>() so that index type can change without rewriting conditions. Change-Id: I40c94ca39148b379908760ba9b861114b88af7bb Reviewed-on: https://pdfium-review.googlesource.com/3056 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk/pdfwindow/PWL_FontMap.cpp')
-rw-r--r--fpdfsdk/pdfwindow/PWL_FontMap.cpp29
1 files changed, 10 insertions, 19 deletions
diff --git a/fpdfsdk/pdfwindow/PWL_FontMap.cpp b/fpdfsdk/pdfwindow/PWL_FontMap.cpp
index 9a2962cd56..a7c42698cd 100644
--- a/fpdfsdk/pdfwindow/PWL_FontMap.cpp
+++ b/fpdfsdk/pdfwindow/PWL_FontMap.cpp
@@ -55,32 +55,26 @@ CPDF_Document* CPWL_FontMap::GetDocument() {
m_pPDFDoc->CreateNewDoc();
}
}
-
return m_pPDFDoc.get();
}
CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) {
- if (nFontIndex >= 0 && nFontIndex < pdfium::CollectionSize<int32_t>(m_Data)) {
- if (m_Data[nFontIndex])
- return m_Data[nFontIndex]->pFont;
- }
+ if (pdfium::IndexInBounds(m_Data, nFontIndex) && m_Data[nFontIndex])
+ return m_Data[nFontIndex]->pFont;
+
return nullptr;
}
CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) {
- if (nFontIndex >= 0 && nFontIndex < pdfium::CollectionSize<int32_t>(m_Data)) {
- if (m_Data[nFontIndex])
- return m_Data[nFontIndex]->sFontName;
- }
+ if (pdfium::IndexInBounds(m_Data, nFontIndex) && m_Data[nFontIndex])
+ return m_Data[nFontIndex]->sFontName;
+
return CFX_ByteString();
}
bool CPWL_FontMap::KnowWord(int32_t nFontIndex, uint16_t word) {
- if (nFontIndex >= 0 && nFontIndex < pdfium::CollectionSize<int32_t>(m_Data)) {
- if (m_Data[nFontIndex])
- return CharCodeFromUnicode(nFontIndex, word) >= 0;
- }
- return false;
+ return pdfium::IndexInBounds(m_Data, nFontIndex) && m_Data[nFontIndex] &&
+ CharCodeFromUnicode(nFontIndex, word) >= 0;
}
int32_t CPWL_FontMap::GetWordFontIndex(uint16_t word,
@@ -116,7 +110,7 @@ int32_t CPWL_FontMap::GetWordFontIndex(uint16_t word,
}
int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) {
- if (nFontIndex < 0 || nFontIndex >= pdfium::CollectionSize<int32_t>(m_Data))
+ if (!pdfium::IndexInBounds(m_Data, nFontIndex))
return -1;
CPWL_FontMap_Data* pData = m_Data[nFontIndex].get();
@@ -284,10 +278,7 @@ CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) {
}
const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const {
- if (nIndex < 0 || nIndex >= pdfium::CollectionSize<int32_t>(m_Data))
- return nullptr;
-
- return m_Data[nIndex].get();
+ return pdfium::IndexInBounds(m_Data, nIndex) ? m_Data[nIndex].get() : nullptr;
}
int32_t CPWL_FontMap::GetNativeCharset() {