summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-06-08 13:30:06 -0700
committerCommit bot <commit-bot@chromium.org>2016-06-08 13:30:06 -0700
commitc1835615f386d8e6e30df89b6517ebf605335a0e (patch)
treea84b7ecfd51799e8e7ef7e481c1ee68bcb651a25 /core
parentbc58de0409636f64200b14097e4c781ace12422d (diff)
downloadpdfium-c1835615f386d8e6e30df89b6517ebf605335a0e.tar.xz
Add some consts and remove more casts in core/
Review-Url: https://codereview.chromium.org/2049003003
Diffstat (limited to 'core')
-rw-r--r--core/fpdfdoc/ctypeset.cpp6
-rw-r--r--core/fpdfdoc/doc_form.cpp5
-rw-r--r--core/fpdfdoc/doc_formfield.cpp59
-rw-r--r--core/fpdfdoc/include/fpdf_doc.h85
-rw-r--r--core/fpdftext/fpdf_text_int.cpp14
5 files changed, 72 insertions, 97 deletions
diff --git a/core/fpdfdoc/ctypeset.cpp b/core/fpdfdoc/ctypeset.cpp
index 076c901885..8c85e79922 100644
--- a/core/fpdfdoc/ctypeset.cpp
+++ b/core/fpdfdoc/ctypeset.cpp
@@ -214,13 +214,11 @@ CPVT_FloatRect CTypeset::CharArray() {
break;
}
fNextWidth = 0;
- if (CPVT_WordInfo* pNextWord =
- (CPVT_WordInfo*)m_pSection->m_WordArray.GetAt(w + 1)) {
+ if (CPVT_WordInfo* pNextWord = m_pSection->m_WordArray.GetAt(w + 1)) {
pNextWord->fWordTail = 0;
fNextWidth = m_pVT->GetWordWidth(*pNextWord);
}
- if (CPVT_WordInfo* pWord =
- (CPVT_WordInfo*)m_pSection->m_WordArray.GetAt(w)) {
+ if (CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(w)) {
pWord->fWordTail = 0;
FX_FLOAT fWordWidth = m_pVT->GetWordWidth(*pWord);
FX_FLOAT fWordAscent = m_pVT->GetWordAscent(*pWord);
diff --git a/core/fpdfdoc/doc_form.cpp b/core/fpdfdoc/doc_form.cpp
index 7ecf35de37..25a9f0b72d 100644
--- a/core/fpdfdoc/doc_form.cpp
+++ b/core/fpdfdoc/doc_form.cpp
@@ -620,8 +620,7 @@ FX_BOOL CPDF_InterForm::ValidateFieldName(CFX_WideString& csNewFieldName,
FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormField* pField,
CFX_WideString& csNewFieldName) {
return pField && !csNewFieldName.IsEmpty() &&
- ValidateFieldName(csNewFieldName,
- ((CPDF_FormField*)pField)->GetFieldType(), pField,
+ ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField,
nullptr);
}
FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormControl* pControl,
@@ -629,7 +628,7 @@ FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormControl* pControl,
if (!pControl || csNewFieldName.IsEmpty()) {
return FALSE;
}
- CPDF_FormField* pField = ((CPDF_FormControl*)pControl)->GetField();
+ CPDF_FormField* pField = pControl->GetField();
return ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField,
pControl);
}
diff --git a/core/fpdfdoc/doc_formfield.cpp b/core/fpdfdoc/doc_formfield.cpp
index 310f0754bf..14497ef045 100644
--- a/core/fpdfdoc/doc_formfield.cpp
+++ b/core/fpdfdoc/doc_formfield.cpp
@@ -105,7 +105,7 @@ void CPDF_FormField::SyncFieldFlags() {
m_Type = Sign;
}
}
-CFX_WideString CPDF_FormField::GetFullName() {
+CFX_WideString CPDF_FormField::GetFullName() const {
return ::GetFullName(m_pDict);
}
@@ -188,7 +188,7 @@ FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) {
return TRUE;
}
-int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) {
+int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) const {
if (!pControl)
return -1;
@@ -198,7 +198,8 @@ int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) {
}
return -1;
}
-int CPDF_FormField::GetFieldType() {
+
+int CPDF_FormField::GetFieldType() const {
switch (m_Type) {
case PushButton:
return FIELDTYPE_PUSHBUTTON;
@@ -222,47 +223,47 @@ int CPDF_FormField::GetFieldType() {
return FIELDTYPE_UNKNOWN;
}
-CPDF_AAction CPDF_FormField::GetAdditionalAction() {
+CPDF_AAction CPDF_FormField::GetAdditionalAction() const {
CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "AA");
return CPDF_AAction(pObj ? pObj->GetDict() : nullptr);
}
-CFX_WideString CPDF_FormField::GetAlternateName() {
+CFX_WideString CPDF_FormField::GetAlternateName() const {
CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TU");
if (!pObj) {
return L"";
}
return pObj->GetUnicodeText();
}
-CFX_WideString CPDF_FormField::GetMappingName() {
+CFX_WideString CPDF_FormField::GetMappingName() const {
CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TM");
if (!pObj) {
return L"";
}
return pObj->GetUnicodeText();
}
-uint32_t CPDF_FormField::GetFieldFlags() {
+uint32_t CPDF_FormField::GetFieldFlags() const {
CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "Ff");
if (!pObj) {
return 0;
}
return pObj->GetInteger();
}
-CFX_ByteString CPDF_FormField::GetDefaultStyle() {
+CFX_ByteString CPDF_FormField::GetDefaultStyle() const {
CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DS");
if (!pObj) {
return "";
}
return pObj->GetString();
}
-CFX_WideString CPDF_FormField::GetRichTextString() {
+CFX_WideString CPDF_FormField::GetRichTextString() const {
CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "RV");
if (!pObj) {
return L"";
}
return pObj->GetUnicodeText();
}
-CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) {
+CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) const {
if (GetType() == CheckBox || GetType() == RadioButton)
return GetCheckValue(bDefault);
@@ -294,11 +295,11 @@ CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) {
return CFX_WideString();
}
-CFX_WideString CPDF_FormField::GetValue() {
+CFX_WideString CPDF_FormField::GetValue() const {
return GetValue(FALSE);
}
-CFX_WideString CPDF_FormField::GetDefaultValue() {
+CFX_WideString CPDF_FormField::GetDefaultValue() const {
return GetValue(TRUE);
}
@@ -365,7 +366,7 @@ FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bNotify) {
return SetValue(value, FALSE, bNotify);
}
-int CPDF_FormField::GetMaxLen() {
+int CPDF_FormField::GetMaxLen() const {
if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen"))
return pObj->GetInteger();
@@ -381,7 +382,7 @@ int CPDF_FormField::GetMaxLen() {
return 0;
}
-int CPDF_FormField::CountSelectedItems() {
+int CPDF_FormField::CountSelectedItems() const {
CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
if (!pValue) {
pValue = FPDF_GetFieldAttr(m_pDict, "I");
@@ -396,7 +397,7 @@ int CPDF_FormField::CountSelectedItems() {
return 0;
}
-int CPDF_FormField::GetSelectedIndex(int index) {
+int CPDF_FormField::GetSelectedIndex(int index) const {
CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
if (!pValue) {
pValue = FPDF_GetFieldAttr(m_pDict, "I");
@@ -451,7 +452,7 @@ FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) {
return TRUE;
}
-FX_BOOL CPDF_FormField::IsItemSelected(int index) {
+FX_BOOL CPDF_FormField::IsItemSelected(int index) const {
ASSERT(GetType() == ComboBox || GetType() == ListBox);
if (index < 0 || index >= CountOptions()) {
return FALSE;
@@ -560,7 +561,7 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index,
return TRUE;
}
-FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) {
+FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) const {
ASSERT(GetType() == ComboBox || GetType() == ListBox);
if (index < 0 || index >= CountOptions())
return FALSE;
@@ -568,7 +569,7 @@ FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) {
return iDVIndex >= 0 && iDVIndex == index;
}
-int CPDF_FormField::GetDefaultSelectedItem() {
+int CPDF_FormField::GetDefaultSelectedItem() const {
ASSERT(GetType() == ComboBox || GetType() == ListBox);
CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV");
if (!pValue)
@@ -583,12 +584,12 @@ int CPDF_FormField::GetDefaultSelectedItem() {
return -1;
}
-int CPDF_FormField::CountOptions() {
+int CPDF_FormField::CountOptions() const {
CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt"));
return pArray ? pArray->GetCount() : 0;
}
-CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) {
+CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) const {
CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt"));
if (!pArray)
return CFX_WideString();
@@ -602,14 +603,14 @@ CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) {
CPDF_String* pString = ToString(pOption);
return pString ? pString->GetUnicodeText() : CFX_WideString();
}
-CFX_WideString CPDF_FormField::GetOptionLabel(int index) {
+CFX_WideString CPDF_FormField::GetOptionLabel(int index) const {
return GetOptionText(index, 1);
}
-CFX_WideString CPDF_FormField::GetOptionValue(int index) {
+CFX_WideString CPDF_FormField::GetOptionValue(int index) const {
return GetOptionText(index, 0);
}
-int CPDF_FormField::FindOption(CFX_WideString csOptLabel) {
+int CPDF_FormField::FindOption(CFX_WideString csOptLabel) const {
for (int i = 0; i < CountOptions(); i++) {
if (GetOptionValue(i) == csOptLabel)
return i;
@@ -617,7 +618,7 @@ int CPDF_FormField::FindOption(CFX_WideString csOptLabel) {
return -1;
}
-int CPDF_FormField::FindOptionValue(const CFX_WideString& csOptValue) {
+int CPDF_FormField::FindOptionValue(const CFX_WideString& csOptValue) const {
for (int i = 0; i < CountOptions(); i++) {
if (GetOptionValue(i) == csOptValue)
return i;
@@ -741,7 +742,7 @@ FX_BOOL CPDF_FormField::CheckControl(int iControlIndex,
return TRUE;
}
-CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) {
+CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) const {
ASSERT(GetType() == CheckBox || GetType() == RadioButton);
CFX_WideString csExport = L"Off";
int iCount = CountControls();
@@ -776,17 +777,17 @@ FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value,
return TRUE;
}
-int CPDF_FormField::GetTopVisibleIndex() {
+int CPDF_FormField::GetTopVisibleIndex() const {
CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI");
return pObj ? pObj->GetInteger() : 0;
}
-int CPDF_FormField::CountSelectedOptions() {
+int CPDF_FormField::CountSelectedOptions() const {
CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I"));
return pArray ? pArray->GetCount() : 0;
}
-int CPDF_FormField::GetSelectedOptionIndex(int index) {
+int CPDF_FormField::GetSelectedOptionIndex(int index) const {
CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I"));
if (!pArray)
return -1;
@@ -797,7 +798,7 @@ int CPDF_FormField::GetSelectedOptionIndex(int index) {
return pArray->GetIntegerAt(index);
}
-FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex) {
+FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex) const {
CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I"));
if (!pArray)
return FALSE;
diff --git a/core/fpdfdoc/include/fpdf_doc.h b/core/fpdfdoc/include/fpdf_doc.h
index a70a24c1e3..0f65ee02b6 100644
--- a/core/fpdfdoc/include/fpdf_doc.h
+++ b/core/fpdfdoc/include/fpdf_doc.h
@@ -570,6 +570,7 @@ class CPDF_InterForm {
#define FORMTEXT_COMB 0x800
#define FORMCOMBO_EDIT 0x100
#define FORMLIST_MULTISELECT 0x100
+
class CPDF_FormField {
public:
enum Type {
@@ -585,7 +586,7 @@ class CPDF_FormField {
Sign
};
- CFX_WideString GetFullName();
+ CFX_WideString GetFullName() const;
Type GetType() const { return m_Type; }
uint32_t GetFlags() const { return m_Flags; }
@@ -601,65 +602,49 @@ class CPDF_FormField {
return m_ControlList.GetAt(index);
}
- int GetControlIndex(const CPDF_FormControl* pControl);
-
- int GetFieldType();
-
- CPDF_AAction GetAdditionalAction();
-
- CFX_WideString GetAlternateName();
-
- CFX_WideString GetMappingName();
+ int GetControlIndex(const CPDF_FormControl* pControl) const;
+ int GetFieldType() const;
- uint32_t GetFieldFlags();
+ CPDF_AAction GetAdditionalAction() const;
+ CFX_WideString GetAlternateName() const;
+ CFX_WideString GetMappingName() const;
- CFX_ByteString GetDefaultStyle();
-
- CFX_WideString GetRichTextString();
-
- CFX_WideString GetValue();
-
- CFX_WideString GetDefaultValue();
+ uint32_t GetFieldFlags() const;
+ CFX_ByteString GetDefaultStyle() const;
+ CFX_WideString GetRichTextString() const;
+ CFX_WideString GetValue() const;
+ CFX_WideString GetDefaultValue() const;
FX_BOOL SetValue(const CFX_WideString& value, FX_BOOL bNotify = FALSE);
- int GetMaxLen();
-
- int CountSelectedItems();
-
- int GetSelectedIndex(int index);
+ int GetMaxLen() const;
+ int CountSelectedItems() const;
+ int GetSelectedIndex(int index) const;
FX_BOOL ClearSelection(FX_BOOL bNotify = FALSE);
-
- FX_BOOL IsItemSelected(int index);
-
+ FX_BOOL IsItemSelected(int index) const;
FX_BOOL SetItemSelection(int index,
FX_BOOL bSelected,
FX_BOOL bNotify = FALSE);
- FX_BOOL IsItemDefaultSelected(int index);
-
- int GetDefaultSelectedItem();
-
- int CountOptions();
+ FX_BOOL IsItemDefaultSelected(int index) const;
- CFX_WideString GetOptionLabel(int index);
+ int GetDefaultSelectedItem() const;
+ int CountOptions() const;
- CFX_WideString GetOptionValue(int index);
+ CFX_WideString GetOptionLabel(int index) const;
+ CFX_WideString GetOptionValue(int index) const;
- int FindOption(CFX_WideString csOptLabel);
-
- int FindOptionValue(const CFX_WideString& csOptValue);
+ int FindOption(CFX_WideString csOptLabel) const;
+ int FindOptionValue(const CFX_WideString& csOptValue) const;
FX_BOOL CheckControl(int iControlIndex, bool bChecked, bool bNotify = false);
- int GetTopVisibleIndex();
-
- int CountSelectedOptions();
-
- int GetSelectedOptionIndex(int index);
+ int GetTopVisibleIndex() const;
+ int CountSelectedOptions() const;
- FX_BOOL IsOptionSelected(int iOptIndex);
+ int GetSelectedOptionIndex(int index) const;
+ FX_BOOL IsOptionSelected(int iOptIndex) const;
FX_BOOL SelectOption(int iOptIndex,
FX_BOOL bSelected,
@@ -675,30 +660,24 @@ class CPDF_FormField {
FX_BOOL bNotify = FALSE);
#endif // PDF_ENABLE_XFA
- FX_FLOAT GetFontSize() { return m_FontSize; }
-
- CPDF_Font* GetFont() { return m_pFont; }
+ FX_FLOAT GetFontSize() const { return m_FontSize; }
+ CPDF_Font* GetFont() const { return m_pFont; }
protected:
CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict);
~CPDF_FormField();
- CFX_WideString GetValue(FX_BOOL bDefault);
-
+ CFX_WideString GetValue(FX_BOOL bDefault) const;
FX_BOOL SetValue(const CFX_WideString& value,
FX_BOOL bDefault,
FX_BOOL bNotify);
void SyncFieldFlags();
-
int FindListSel(CPDF_String* str);
-
- CFX_WideString GetOptionText(int index, int sub_index);
+ CFX_WideString GetOptionText(int index, int sub_index) const;
void LoadDA();
-
- CFX_WideString GetCheckValue(FX_BOOL bDefault);
-
+ CFX_WideString GetCheckValue(FX_BOOL bDefault) const;
FX_BOOL SetCheckValue(const CFX_WideString& value,
FX_BOOL bDefault,
FX_BOOL bNotify);
diff --git a/core/fpdftext/fpdf_text_int.cpp b/core/fpdftext/fpdf_text_int.cpp
index fd1214b588..8ae2c1ef35 100644
--- a/core/fpdftext/fpdf_text_int.cpp
+++ b/core/fpdftext/fpdf_text_int.cpp
@@ -1008,8 +1008,7 @@ void CPDF_TextPage::ProcessTextObject(
FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) {
CPDF_TextObject* pTextObj = Obj.m_pTextObj;
- CPDF_ContentMarkData* pMarkData =
- (CPDF_ContentMarkData*)pTextObj->m_ContentMark.GetObject();
+ const CPDF_ContentMarkData* pMarkData = pTextObj->m_ContentMark.GetObject();
if (!pMarkData)
return FPDFText_MarkedContent::Pass;
@@ -1022,7 +1021,7 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) {
CPDF_Dictionary* pDict = nullptr;
int n = 0;
for (n = 0; n < nContentMark; n++) {
- CPDF_ContentMarkItem& item = pMarkData->GetItem(n);
+ const CPDF_ContentMarkItem& item = pMarkData->GetItem(n);
if (item.GetParamType() == CPDF_ContentMarkItem::ParamType::None)
continue;
pDict = item.GetParam();
@@ -1037,8 +1036,8 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) {
return FPDFText_MarkedContent::Pass;
if (m_pPreTextObj) {
- CPDF_ContentMarkData* pPreMarkData =
- (CPDF_ContentMarkData*)m_pPreTextObj->m_ContentMark.GetObject();
+ const CPDF_ContentMarkData* pPreMarkData =
+ m_pPreTextObj->m_ContentMark.GetObject();
if (pPreMarkData && pPreMarkData->CountItems() == n &&
pDict == pPreMarkData->GetItem(n - 1).GetParam()) {
return FPDFText_MarkedContent::Done;
@@ -1076,8 +1075,7 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) {
void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) {
CPDF_TextObject* pTextObj = Obj.m_pTextObj;
- CPDF_ContentMarkData* pMarkData =
- (CPDF_ContentMarkData*)pTextObj->m_ContentMark.GetObject();
+ const CPDF_ContentMarkData* pMarkData = pTextObj->m_ContentMark.GetObject();
if (!pMarkData)
return;
@@ -1087,7 +1085,7 @@ void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) {
CFX_WideString actText;
CPDF_Dictionary* pDict = nullptr;
for (int n = 0; n < nContentMark; n++) {
- CPDF_ContentMarkItem& item = pMarkData->GetItem(n);
+ const CPDF_ContentMarkItem& item = pMarkData->GetItem(n);
if (item.GetParamType() == CPDF_ContentMarkItem::ParamType::None)
continue;
pDict = item.GetParam();