summaryrefslogtreecommitdiff
path: root/core/src/fpdfdoc
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-07-23 14:42:09 -0700
committerTom Sepez <tsepez@chromium.org>2015-07-23 14:42:09 -0700
commit2f2ffece124e4ed4b96d2846263015d4b5ad6c00 (patch)
tree6966e44279e8d9e1516b7c71219cf66f77a89ca2 /core/src/fpdfdoc
parentd07958fd2d1c4134d865f4ccb056eb925aaa7d2a (diff)
downloadpdfium-2f2ffece124e4ed4b96d2846263015d4b5ad6c00.tar.xz
Merge to XFA - else after returns.
(cherry picked from commit 3c012fef2bb72c8ec1faa73e11ee35539b2559d6) Original Review URL: https://codereview.chromium.org/1243953004 . R=thestig@chromium.org Review URL: https://codereview.chromium.org/1239313005 .
Diffstat (limited to 'core/src/fpdfdoc')
-rw-r--r--core/src/fpdfdoc/doc_action.cpp27
-rw-r--r--core/src/fpdfdoc/doc_ap.cpp14
-rw-r--r--core/src/fpdfdoc/doc_basic.cpp11
-rw-r--r--core/src/fpdfdoc/doc_form.cpp208
-rw-r--r--core/src/fpdfdoc/doc_formcontrol.cpp33
-rw-r--r--core/src/fpdfdoc/doc_formfield.cpp5
-rw-r--r--core/src/fpdfdoc/doc_metadata.cpp16
-rw-r--r--core/src/fpdfdoc/doc_ocg.cpp11
-rw-r--r--core/src/fpdfdoc/doc_utils.cpp8
-rw-r--r--core/src/fpdfdoc/doc_vt.cpp128
10 files changed, 217 insertions, 244 deletions
diff --git a/core/src/fpdfdoc/doc_action.cpp b/core/src/fpdfdoc/doc_action.cpp
index da2e05af2e..851b2d6709 100644
--- a/core/src/fpdfdoc/doc_action.cpp
+++ b/core/src/fpdfdoc/doc_action.cpp
@@ -112,9 +112,11 @@ FX_DWORD CPDF_ActionFields::GetFieldsCount() const
int iType = pFields->GetType();
if (iType == PDFOBJ_DICTIONARY) {
return 1;
- } else if (iType == PDFOBJ_STRING) {
+ }
+ if (iType == PDFOBJ_STRING) {
return 1;
- } else if (iType == PDFOBJ_ARRAY) {
+ }
+ if (iType == PDFOBJ_ARRAY) {
return ((CPDF_Array*)pFields)->GetCount();
}
return 0;
@@ -207,16 +209,17 @@ CFX_WideString CPDF_Action::GetJavaScript() const
}
CPDF_Dictionary* CPDF_Action::GetAnnot() const
{
- if (m_pDict == NULL) {
- return NULL;
+ if (!m_pDict) {
+ return nullptr;
}
CFX_ByteString csType = m_pDict->GetString("S");
if (csType == FX_BSTRC("Rendition")) {
return m_pDict->GetDict("AN");
- } else if (csType == FX_BSTRC("Movie")) {
+ }
+ if (csType == FX_BSTRC("Movie")) {
return m_pDict->GetDict("Annotation");
}
- return NULL;
+ return nullptr;
}
int32_t CPDF_Action::GetOperationType() const
{
@@ -226,15 +229,19 @@ int32_t CPDF_Action::GetOperationType() const
CFX_ByteString csType = m_pDict->GetString("S");
if (csType == FX_BSTRC("Rendition")) {
return m_pDict->GetInteger("OP");
- } else if (csType == FX_BSTRC("Movie")) {
+ }
+ if (csType == FX_BSTRC("Movie")) {
CFX_ByteString csOP = m_pDict->GetString("Operation");
if (csOP == FX_BSTRC("Play")) {
return 0;
- } else if (csOP == FX_BSTRC("Stop")) {
+ }
+ if (csOP == FX_BSTRC("Stop")) {
return 1;
- } else if (csOP == FX_BSTRC("Pause")) {
+ }
+ if (csOP == FX_BSTRC("Pause")) {
return 2;
- } else if (csOP == FX_BSTRC("Resume")) {
+ }
+ if (csOP == FX_BSTRC("Resume")) {
return 3;
}
}
diff --git a/core/src/fpdfdoc/doc_ap.cpp b/core/src/fpdfdoc/doc_ap.cpp
index 2d991b39c2..f94a4d60e0 100644
--- a/core/src/fpdfdoc/doc_ap.cpp
+++ b/core/src/fpdfdoc/doc_ap.cpp
@@ -17,13 +17,13 @@ FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict)
FX_DWORD flags = FPDF_GetFieldAttr(pAnnotDict, "Ff")? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() : 0;
if (field_type == "Tx") {
return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict);
- } else if (field_type == "Ch") {
- if (flags & (1 << 17)) {
- return CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict);
- } else {
- return CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict);
- }
- } else if (field_type == "Btn") {
+ }
+ if (field_type == "Ch") {
+ return (flags & (1 << 17)) ?
+ CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict) :
+ CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict);
+ }
+ if (field_type == "Btn") {
if (!(flags & (1 << 16))) {
if (!pAnnotDict->KeyExist("AS")) {
if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDict("Parent")) {
diff --git a/core/src/fpdfdoc/doc_basic.cpp b/core/src/fpdfdoc/doc_basic.cpp
index 9d31d15624..3ba109b016 100644
--- a/core/src/fpdfdoc/doc_basic.cpp
+++ b/core/src/fpdfdoc/doc_basic.cpp
@@ -148,13 +148,12 @@ static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, int nIndex, int& nCur
if (nIndex >= nCurIndex + nCount) {
nCurIndex += nCount;
return NULL;
- } else {
- if (ppFind != NULL) {
- *ppFind = pNames;
- }
- csName = pNames->GetString((nIndex - nCurIndex) * 2);
- return pNames->GetElementValue((nIndex - nCurIndex) * 2 + 1);
}
+ if (ppFind != NULL) {
+ *ppFind = pNames;
+ }
+ csName = pNames->GetString((nIndex - nCurIndex) * 2);
+ return pNames->GetElementValue((nIndex - nCurIndex) * 2 + 1);
}
CPDF_Array* pKids = pNode->GetArray(FX_BSTRC("Kids"));
if (pKids == NULL) {
diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp
index 3740f41510..5a2bd1425b 100644
--- a/core/src/fpdfdoc/doc_form.cpp
+++ b/core/src/fpdfdoc/doc_form.cpp
@@ -357,12 +357,11 @@ static int CALLBACK EnumFontFamExProc( ENUMLOGFONTEXA *lpelfe,
{
if (FontType != 0x004 || strchr(lpelfe->elfLogFont.lfFaceName, '@') != NULL) {
return 1;
- } else {
- LPDF_FONTDATA pData = (LPDF_FONTDATA)lParam;
- memcpy(&pData->lf, &lpelfe->elfLogFont, sizeof(LOGFONTA));
- pData->bFind = TRUE;
- return 0;
}
+ LPDF_FONTDATA pData = (LPDF_FONTDATA)lParam;
+ memcpy(&pData->lf, &lpelfe->elfLogFont, sizeof(LOGFONTA));
+ pData->bFind = TRUE;
+ return 0;
}
static FX_BOOL RetrieveSpecificFont(LOGFONTA& lf)
{
@@ -700,41 +699,39 @@ int CPDF_InterForm::CompareFieldName(const CFX_ByteString& name1, const CFX_Byte
{
const FX_CHAR* ptr1 = name1;
const FX_CHAR* ptr2 = name2;
- if (name1.GetLength() != name2.GetLength()) {
- int i = 0;
- while (ptr1[i] == ptr2[i]) {
- i ++;
- }
- if (i == name1.GetLength()) {
- return 2;
- }
- if (i == name2.GetLength()) {
- return 3;
- }
- return 0;
- } else {
+ if (name1.GetLength() == name2.GetLength()) {
return name1 == name2 ? 1 : 0;
}
+ int i = 0;
+ while (ptr1[i] == ptr2[i]) {
+ i ++;
+ }
+ if (i == name1.GetLength()) {
+ return 2;
+ }
+ if (i == name2.GetLength()) {
+ return 3;
+ }
+ return 0;
}
int CPDF_InterForm::CompareFieldName(const CFX_WideString& name1, const CFX_WideString& name2)
{
const FX_WCHAR* ptr1 = name1.c_str();
const FX_WCHAR* ptr2 = name2.c_str();
- if (name1.GetLength() != name2.GetLength()) {
- int i = 0;
- while (ptr1[i] == ptr2[i]) {
- i ++;
- }
- if (i == name1.GetLength()) {
- return 2;
- }
- if (i == name2.GetLength()) {
- return 3;
- }
- return 0;
- } else {
+ if (name1.GetLength() == name2.GetLength()) {
return name1 == name2 ? 1 : 0;
}
+ int i = 0;
+ while (ptr1[i] == ptr2[i]) {
+ i ++;
+ }
+ if (i == name1.GetLength()) {
+ return 2;
+ }
+ if (i == name2.GetLength()) {
+ return 3;
+ }
+ return 0;
}
FX_DWORD CPDF_InterForm::CountFields(const CFX_WideString &csFieldName)
{
@@ -903,115 +900,104 @@ CPDF_FormControl* CPDF_InterForm::GetControlByDict(CPDF_Dictionary* pWidgetDict)
}
FX_DWORD CPDF_InterForm::CountInternalFields(const CFX_WideString& csFieldName) const
{
- if (m_pFormDict == NULL) {
+ if (!m_pFormDict) {
return 0;
}
CPDF_Array* pArray = m_pFormDict->GetArray("Fields");
- if (pArray == NULL) {
+ if (!pArray) {
return 0;
}
if (csFieldName.IsEmpty()) {
return pArray->GetCount();
- } else {
- int iLength = csFieldName.GetLength();
- int iPos = 0;
- CPDF_Dictionary* pDict = NULL;
- while (pArray != NULL) {
- CFX_WideString csSub;
- if (iPos < iLength && csFieldName[iPos] == L'.') {
- iPos ++;
- }
- while (iPos < iLength && csFieldName[iPos] != L'.') {
- csSub += csFieldName[iPos ++];
- }
- int iCount = pArray->GetCount();
- FX_BOOL bFind = FALSE;
- for (int i = 0; i < iCount; i ++) {
- pDict = pArray->GetDict(i);
- if (pDict == NULL) {
- continue;
- }
- CFX_WideString csT = pDict->GetUnicodeText("T");
- if (csT == csSub) {
- bFind = TRUE;
- break;
- }
- }
- if (!bFind) {
- return 0;
+ }
+ int iLength = csFieldName.GetLength();
+ int iPos = 0;
+ CPDF_Dictionary* pDict = NULL;
+ while (pArray != NULL) {
+ CFX_WideString csSub;
+ if (iPos < iLength && csFieldName[iPos] == L'.') {
+ iPos ++;
+ }
+ while (iPos < iLength && csFieldName[iPos] != L'.') {
+ csSub += csFieldName[iPos ++];
+ }
+ int iCount = pArray->GetCount();
+ FX_BOOL bFind = FALSE;
+ for (int i = 0; i < iCount; i ++) {
+ pDict = pArray->GetDict(i);
+ if (pDict == NULL) {
+ continue;
}
- if (iPos >= iLength) {
+ CFX_WideString csT = pDict->GetUnicodeText("T");
+ if (csT == csSub) {
+ bFind = TRUE;
break;
}
- pArray = pDict->GetArray("Kids");
}
- if (pDict == NULL) {
+ if (!bFind) {
return 0;
- } else {
- pArray = pDict->GetArray("Kids");
- if (pArray == NULL) {
- return 1;
- } else {
- return pArray->GetCount();
- }
}
+ if (iPos >= iLength) {
+ break;
+ }
+ pArray = pDict->GetArray("Kids");
+ }
+ if (!pDict) {
+ return 0;
}
+ pArray = pDict->GetArray("Kids");
+ return pArray ? pArray->GetCount() : 1;
}
+
CPDF_Dictionary* CPDF_InterForm::GetInternalField(FX_DWORD index, const CFX_WideString& csFieldName) const
{
- if (m_pFormDict == NULL) {
- return NULL;
+ if (!m_pFormDict) {
+ return nullptr;
}
CPDF_Array* pArray = m_pFormDict->GetArray("Fields");
- if (pArray == NULL) {
- return 0;
+ if (!pArray) {
+ return nullptr;
}
if (csFieldName.IsEmpty()) {
return pArray->GetDict(index);
- } else {
- int iLength = csFieldName.GetLength();
- int iPos = 0;
- CPDF_Dictionary* pDict = NULL;
- while (pArray != NULL) {
- CFX_WideString csSub;
- if (iPos < iLength && csFieldName[iPos] == L'.') {
- iPos ++;
- }
- while (iPos < iLength && csFieldName[iPos] != L'.') {
- csSub += csFieldName[iPos ++];
- }
- int iCount = pArray->GetCount();
- FX_BOOL bFind = FALSE;
- for (int i = 0; i < iCount; i ++) {
- pDict = pArray->GetDict(i);
- if (pDict == NULL) {
- continue;
- }
- CFX_WideString csT = pDict->GetUnicodeText("T");
- if (csT == csSub) {
- bFind = TRUE;
- break;
- }
- }
- if (!bFind) {
- return NULL;
+ }
+ int iLength = csFieldName.GetLength();
+ int iPos = 0;
+ CPDF_Dictionary* pDict = NULL;
+ while (pArray != NULL) {
+ CFX_WideString csSub;
+ if (iPos < iLength && csFieldName[iPos] == L'.') {
+ iPos ++;
+ }
+ while (iPos < iLength && csFieldName[iPos] != L'.') {
+ csSub += csFieldName[iPos ++];
+ }
+ int iCount = pArray->GetCount();
+ FX_BOOL bFind = FALSE;
+ for (int i = 0; i < iCount; i ++) {
+ pDict = pArray->GetDict(i);
+ if (pDict == NULL) {
+ continue;
}
- if (iPos >= iLength) {
+ CFX_WideString csT = pDict->GetUnicodeText("T");
+ if (csT == csSub) {
+ bFind = TRUE;
break;
}
- pArray = pDict->GetArray("Kids");
}
- if (pDict == NULL) {
+ if (!bFind) {
return NULL;
- } else {
- pArray = pDict->GetArray("Kids");
- if (pArray == NULL) {
- return pDict;
- } else {
- return pArray->GetDict(index);
- }
}
+ if (iPos >= iLength) {
+ break;
+ }
+ pArray = pDict->GetArray("Kids");
+ }
+ if (!pDict) {
+ return nullptr;
}
+ pArray = pDict->GetArray("Kids");
+ return pArray ? pArray->GetDict(index) : pDict;
}
FX_BOOL CPDF_InterForm::NeedConstructAP()
{
diff --git a/core/src/fpdfdoc/doc_formcontrol.cpp b/core/src/fpdfdoc/doc_formcontrol.cpp
index 7fa17b8ffa..87eee92c2e 100644
--- a/core/src/fpdfdoc/doc_formcontrol.cpp
+++ b/core/src/fpdfdoc/doc_formcontrol.cpp
@@ -262,29 +262,27 @@ CPDF_Action CPDF_FormControl::GetAction()
}
CPDF_AAction CPDF_FormControl::GetAdditionalAction()
{
- if (m_pWidgetDict == NULL) {
- return NULL;
+ if (!m_pWidgetDict) {
+ return nullptr;
}
if (m_pWidgetDict->KeyExist("AA")) {
return m_pWidgetDict->GetDict("AA");
- } else {
- return m_pField->GetAdditionalAction();
}
+ return m_pField->GetAdditionalAction();
}
CPDF_DefaultAppearance CPDF_FormControl::GetDefaultAppearance()
{
- if (m_pWidgetDict == NULL) {
+ if (!m_pWidgetDict) {
return CFX_ByteString();
}
if (m_pWidgetDict->KeyExist("DA")) {
return m_pWidgetDict->GetString("DA");
- } else {
- CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "DA");
- if (pObj == NULL) {
- return m_pField->m_pForm->GetDefaultAppearance();
- }
- return pObj->GetString();
}
+ CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "DA");
+ if (!pObj) {
+ return m_pField->m_pForm->GetDefaultAppearance();
+ }
+ return pObj->GetString();
}
CPDF_Font* CPDF_FormControl::GetDefaultControlFont()
@@ -333,18 +331,17 @@ CPDF_Font* CPDF_FormControl::GetDefaultControlFont()
int CPDF_FormControl::GetControlAlignment()
{
- if (m_pWidgetDict == NULL) {
+ if (!m_pWidgetDict) {
return 0;
}
if (m_pWidgetDict->KeyExist("Q")) {
return m_pWidgetDict->GetInteger("Q", 0);
- } else {
- CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q");
- if (pObj == NULL) {
- return m_pField->m_pForm->GetFormAlignment();
- }
- return pObj->GetInteger();
}
+ CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q");
+ if (pObj == NULL) {
+ return m_pField->m_pForm->GetFormAlignment();
+ }
+ return pObj->GetInteger();
}
FX_BOOL CPDF_ApSettings::HasMKEntry(const CFX_ByteStringC& csEntry)
{
diff --git a/core/src/fpdfdoc/doc_formfield.cpp b/core/src/fpdfdoc/doc_formfield.cpp
index 1a6fc3d6d9..8b644e4f93 100644
--- a/core/src/fpdfdoc/doc_formfield.cpp
+++ b/core/src/fpdfdoc/doc_formfield.cpp
@@ -472,14 +472,15 @@ int CPDF_FormField::GetSelectedIndex(int index)
return -1;
}
}
+ if (pValue->GetType() == PDFOBJ_NUMBER) {
+ return pValue->GetInteger();
+ }
CFX_WideString sel_value;
if (pValue->GetType() == PDFOBJ_STRING) {
if (index != 0) {
return -1;
}
sel_value = pValue->GetUnicodeText();
- } else if (pValue->GetType() == PDFOBJ_NUMBER) {
- return pValue->GetInteger();
} else {
if (pValue->GetType() != PDFOBJ_ARRAY) {
return -1;
diff --git a/core/src/fpdfdoc/doc_metadata.cpp b/core/src/fpdfdoc/doc_metadata.cpp
index a4c77debd3..7624e0a2f0 100644
--- a/core/src/fpdfdoc/doc_metadata.cpp
+++ b/core/src/fpdfdoc/doc_metadata.cpp
@@ -113,7 +113,8 @@ int32_t CPDF_Metadata::GetString(const CFX_ByteStringC& bsItem, CFX_WideString &
}
wsStr = pElmnt->GetContent(0);
return wsStr.GetLength();
- } else if (bsItem == FX_BSTRC("Author")) {
+ }
+ if (bsItem == FX_BSTRC("Author")) {
CXML_Element *pElmnt = pTag->GetElement(NULL, bsTag);
if (!pElmnt) {
continue;
@@ -128,14 +129,13 @@ int32_t CPDF_Metadata::GetString(const CFX_ByteStringC& bsItem, CFX_WideString &
}
wsStr = pElmnt->GetContent(0);
return wsStr.GetLength();
- } else {
- CXML_Element *pElmnt = pTag->GetElement(NULL, bsTag);
- if (!pElmnt) {
- continue;
- }
- wsStr = pElmnt->GetContent(0);
- return wsStr.GetLength();
}
+ CXML_Element *pElmnt = pTag->GetElement(NULL, bsTag);
+ if (!pElmnt) {
+ continue;
+ }
+ wsStr = pElmnt->GetContent(0);
+ return wsStr.GetLength();
}
return -1;
}
diff --git a/core/src/fpdfdoc/doc_ocg.cpp b/core/src/fpdfdoc/doc_ocg.cpp
index 8477cb85d0..d525227219 100644
--- a/core/src/fpdfdoc/doc_ocg.cpp
+++ b/core/src/fpdfdoc/doc_ocg.cpp
@@ -207,11 +207,11 @@ FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array *pExpression, FX_BOOL bFromConfig, i
}
if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) {
return !(bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) : GetOCGVisible((CPDF_Dictionary*)pOCGObj));
- } else if (pOCGObj->GetType() == PDFOBJ_ARRAY) {
+ }
+ if (pOCGObj->GetType() == PDFOBJ_ARRAY) {
return !GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1);
- } else {
- return FALSE;
}
+ return FALSE;
}
if (csOperator == FX_BSTRC("Or") || csOperator == FX_BSTRC("And")) {
FX_BOOL bValue = FALSE;
@@ -286,15 +286,14 @@ FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary *pOCMDDict, FX_BOOL
}
FX_BOOL CPDF_OCContext::CheckOCGVisible(const CPDF_Dictionary *pOCGDict)
{
- if (pOCGDict == NULL) {
+ if (!pOCGDict) {
return TRUE;
}
CFX_ByteString csType = pOCGDict->GetString(FX_BSTRC("Type"), FX_BSTRC("OCG"));
if (csType == FX_BSTRC("OCG")) {
return GetOCGVisible(pOCGDict);
- } else {
- return LoadOCMDState(pOCGDict, FALSE);
}
+ return LoadOCMDState(pOCGDict, FALSE);
}
void CPDF_OCContext::ResetOCContext()
{
diff --git a/core/src/fpdfdoc/doc_utils.cpp b/core/src/fpdfdoc/doc_utils.cpp
index 10ca14697d..96d2ccf689 100644
--- a/core/src/fpdfdoc/doc_utils.cpp
+++ b/core/src/fpdfdoc/doc_utils.cpp
@@ -655,15 +655,17 @@ CPDF_Font* GetDefaultInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pD
}
CPDF_IconFit::ScaleMethod CPDF_IconFit::GetScaleMethod()
{
- if (m_pDict == NULL) {
+ if (!m_pDict) {
return Always;
}
CFX_ByteString csSW = m_pDict->GetString("SW", "A");
if (csSW == "B") {
return Bigger;
- } else if (csSW == "S") {
+ }
+ if (csSW == "S") {
return Smaller;
- } else if (csSW == "N") {
+ }
+ if (csSW == "N") {
return Never;
}
return Always;
diff --git a/core/src/fpdfdoc/doc_vt.cpp b/core/src/fpdfdoc/doc_vt.cpp
index c9f5673a60..9b87d920cf 100644
--- a/core/src/fpdfdoc/doc_vt.cpp
+++ b/core/src/fpdfdoc/doc_vt.cpp
@@ -96,9 +96,8 @@ CPVT_FloatRect CSection::Rearrange()
ASSERT(m_pVT != NULL);
if (m_pVT->m_nCharArray > 0) {
return CTypeset(this).CharArray();
- } else {
- return CTypeset(this).Typeset();
}
+ return CTypeset(this).Typeset();
}
CPVT_Size CSection::GetSectionSize(FX_FLOAT fFontSize)
{
@@ -108,17 +107,15 @@ CPVT_WordPlace CSection::GetBeginWordPlace() const
{
if (CLine * pLine = m_LineArray.GetAt(0)) {
return pLine->GetBeginWordPlace();
- } else {
- return SecPlace;
}
+ return SecPlace;
}
CPVT_WordPlace CSection::GetEndWordPlace() const
{
if (CLine * pLine = m_LineArray.GetAt(m_LineArray.GetSize() - 1)) {
return pLine->GetEndWordPlace();
- } else {
- return SecPlace;
}
+ return SecPlace;
}
CPVT_WordPlace CSection::GetPrevWordPlace(const CPVT_WordPlace & place) const
{
@@ -131,7 +128,8 @@ CPVT_WordPlace CSection::GetPrevWordPlace(const CPVT_WordPlace & place) const
if (CLine * pLine = m_LineArray.GetAt(place.nLineIndex)) {
if (place.nWordIndex == pLine->m_LineInfo.nBeginWordIndex) {
return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1);
- } else 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();
}
@@ -572,17 +570,23 @@ static FX_BOOL NeedDivision(FX_WORD prevWord, FX_WORD curWord)
{
if ((IsLatin(prevWord) || IsDigit(prevWord)) && (IsLatin(curWord) || IsDigit(curWord))) {
return FALSE;
- } else if (IsSpace(curWord) || IsPunctuation(curWord)) {
+ }
+ if (IsSpace(curWord) || IsPunctuation(curWord)) {
return FALSE;
- } else if (IsConnectiveSymbol(prevWord) || IsConnectiveSymbol(curWord)) {
+ }
+ if (IsConnectiveSymbol(prevWord) || IsConnectiveSymbol(curWord)) {
return FALSE;
- } else if (IsSpace(prevWord) || IsPunctuation(prevWord)) {
+ }
+ if (IsSpace(prevWord) || IsPunctuation(prevWord)) {
return TRUE;
- } else if (IsPrefixSymbol(prevWord)) {
+ }
+ if (IsPrefixSymbol(prevWord)) {
return FALSE;
- } else if (IsPrefixSymbol(curWord) || IsCJK(curWord)) {
+ }
+ if (IsPrefixSymbol(curWord) || IsCJK(curWord)) {
return TRUE;
- } else if (IsCJK(prevWord)) {
+ }
+ if (IsCJK(prevWord)) {
return TRUE;
}
return FALSE;
@@ -866,16 +870,12 @@ CPVT_WordPlace CPDF_VariableText::InsertWord(const CPVT_WordPlace & place, FX_WO
CPVT_WordPlace newplace = place;
newplace.nWordIndex ++;
if (m_bRichText) {
- CPVT_WordProps * pNewProps = pWordProps ? FX_NEW CPVT_WordProps(*pWordProps) : FX_NEW CPVT_WordProps();
- if (pNewProps) {
- pNewProps->nFontIndex = GetWordFontIndex(word, charset, pWordProps->nFontIndex);
- return AddWord(newplace, CPVT_WordInfo(word, charset, -1, pNewProps));
- }
- } else {
- int32_t nFontIndex = GetSubWord() > 0 ? GetDefaultFontIndex() : GetWordFontIndex(word, charset, GetDefaultFontIndex());
- return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, NULL));
+ CPVT_WordProps* pNewProps = pWordProps ? new CPVT_WordProps(*pWordProps) : new CPVT_WordProps();
+ pNewProps->nFontIndex = GetWordFontIndex(word, charset, pWordProps->nFontIndex);
+ return AddWord(newplace, CPVT_WordInfo(word, charset, -1, pNewProps));
}
- return place;
+ int32_t nFontIndex = GetSubWord() > 0 ? GetDefaultFontIndex() : GetWordFontIndex(word, charset, GetDefaultFontIndex());
+ return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, NULL));
}
CPVT_WordPlace CPDF_VariableText::InsertSection(const CPVT_WordPlace & place, const CPVT_SecProps * pSecProps,
const CPVT_WordProps * pWordProps)
@@ -1123,12 +1123,10 @@ CPVT_WordPlace CPDF_VariableText::GetPrevWordPlace(const CPVT_WordPlace & place)
if (place.WordCmp(pSection->GetBeginWordPlace()) <= 0) {
if (CSection * pPrevSection = m_SectionArray.GetAt(place.nSecIndex - 1)) {
return pPrevSection->GetEndWordPlace();
- } else {
- return GetBeginWordPlace();
}
- } else {
- return pSection->GetPrevWordPlace(place);
+ return GetBeginWordPlace();
}
+ return pSection->GetPrevWordPlace(place);
}
return place;
}
@@ -1144,12 +1142,10 @@ CPVT_WordPlace CPDF_VariableText::GetNextWordPlace(const CPVT_WordPlace & place)
if (place.WordCmp(pSection->GetEndWordPlace()) >= 0) {
if (CSection * pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) {
return pNextSection->GetBeginWordPlace();
- } else {
- return GetEndWordPlace();
}
- } else {
- return pSection->GetNextWordPlace(place);
+ return GetEndWordPlace();
}
+ return pSection->GetNextWordPlace(place);
}
return place;
}
@@ -1204,12 +1200,11 @@ CPVT_WordPlace CPDF_VariableText::GetUpWordPlace(const CPVT_WordPlace & place, c
CPDF_Point pt = OutToIn(point);
if (temp.nLineIndex-- > 0) {
return pSection->SearchWordPlace(pt.x - pSection->m_SecInfo.rcSection.left, temp);
- } else {
- if (temp.nSecIndex-- > 0) {
- if (CSection * pLastSection = m_SectionArray.GetAt(temp.nSecIndex)) {
- temp.nLineIndex = pLastSection->m_LineArray.GetSize() - 1;
- return pLastSection->SearchWordPlace(pt.x - pLastSection->m_SecInfo.rcSection.left, temp);
- }
+ }
+ if (temp.nSecIndex-- > 0) {
+ if (CSection * pLastSection = m_SectionArray.GetAt(temp.nSecIndex)) {
+ temp.nLineIndex = pLastSection->m_LineArray.GetSize() - 1;
+ return pLastSection->SearchWordPlace(pt.x - pLastSection->m_SecInfo.rcSection.left, temp);
}
}
}
@@ -1222,12 +1217,11 @@ CPVT_WordPlace CPDF_VariableText::GetDownWordPlace(const CPVT_WordPlace & place,
CPDF_Point pt = OutToIn(point);
if (temp.nLineIndex++ < pSection->m_LineArray.GetSize() - 1) {
return pSection->SearchWordPlace(pt.x - pSection->m_SecInfo.rcSection.left, temp);
- } else {
- if (temp.nSecIndex++ < m_SectionArray.GetSize() - 1) {
- if (CSection * pNextSection = m_SectionArray.GetAt(temp.nSecIndex)) {
- temp.nLineIndex = 0;
- return pNextSection->SearchWordPlace(pt.x - pSection->m_SecInfo.rcSection.left, temp);
- }
+ }
+ if (temp.nSecIndex++ < m_SectionArray.GetSize() - 1) {
+ if (CSection * pNextSection = m_SectionArray.GetAt(temp.nSecIndex)) {
+ temp.nLineIndex = 0;
+ return pNextSection->SearchWordPlace(pt.x - pSection->m_SecInfo.rcSection.left, temp);
}
}
}
@@ -1239,10 +1233,10 @@ CPVT_WordPlace CPDF_VariableText::GetLineBeginPlace(const CPVT_WordPlace & place
}
CPVT_WordPlace CPDF_VariableText::GetLineEndPlace(const CPVT_WordPlace & place) const
{
- if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex))
- if (CLine * pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) {
+ if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
+ if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex))
return pLine->GetEndWordPlace();
- }
+ }
return place;
}
CPVT_WordPlace CPDF_VariableText::GetSectionBeginPlace(const CPVT_WordPlace & place) const
@@ -1439,11 +1433,7 @@ void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace & place)
CPVT_WordPlace CPDF_VariableText::AjustLineHeader(const CPVT_WordPlace & place, FX_BOOL bPrevOrNext) const
{
if (place.nWordIndex < 0 && place.nLineIndex > 0) {
- if (bPrevOrNext) {
- return GetPrevWordPlace(place);
- } else {
- return GetNextWordPlace(place);
- }
+ return bPrevOrNext ? GetPrevWordPlace(place) : GetNextWordPlace(place);
}
return place;
}
@@ -1639,14 +1629,13 @@ CPVT_FloatRect CPDF_VariableText::RearrangeSections(const CPVT_WordRange & Place
}
int32_t CPDF_VariableText::GetCharWidth(int32_t nFontIndex, FX_WORD Word, FX_WORD SubWord, int32_t nWordStyle)
{
- if (m_pVTProvider) {
- if (SubWord > 0) {
- return m_pVTProvider->GetCharWidth(nFontIndex, SubWord, nWordStyle);
- } else {
- return m_pVTProvider->GetCharWidth(nFontIndex, Word, nWordStyle);
- }
+ if (!m_pVTProvider) {
+ return 0;
+ }
+ if (SubWord > 0) {
+ return m_pVTProvider->GetCharWidth(nFontIndex, SubWord, nWordStyle);
}
- return 0;
+ return m_pVTProvider->GetCharWidth(nFontIndex, Word, nWordStyle);
}
int32_t CPDF_VariableText::GetTypeAscent(int32_t nFontIndex)
{
@@ -1701,7 +1690,6 @@ void CPDF_VariableText_Iterator::SetAt(const CPVT_WordPlace & place)
}
FX_BOOL CPDF_VariableText_Iterator::NextWord()
{
- ASSERT(m_pVT != NULL);
if (m_CurPos == m_pVT->GetEndWordPlace()) {
return FALSE;
}
@@ -1710,7 +1698,6 @@ FX_BOOL CPDF_VariableText_Iterator::NextWord()
}
FX_BOOL CPDF_VariableText_Iterator::PrevWord()
{
- ASSERT(m_pVT != NULL);
if (m_CurPos == m_pVT->GetBeginWordPlace()) {
return FALSE;
}
@@ -1719,33 +1706,29 @@ FX_BOOL CPDF_VariableText_Iterator::PrevWord()
}
FX_BOOL CPDF_VariableText_Iterator::NextLine()
{
- ASSERT(m_pVT != NULL);
if (CSection * pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
if (m_CurPos.nLineIndex < pSection->m_LineArray.GetSize() - 1) {
m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex + 1, -1);
return TRUE;
- } else {
- if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) {
- m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1);
- return TRUE;
- }
+ }
+ if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) {
+ m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1);
+ return TRUE;
}
}
return FALSE;
}
FX_BOOL CPDF_VariableText_Iterator::PrevLine()
{
- ASSERT(m_pVT != NULL);
if (m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
if (m_CurPos.nLineIndex > 0) {
m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex - 1, -1);
return TRUE;
- } else {
- if (m_CurPos.nSecIndex > 0) {
- if (CSection * pLastSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex - 1)) {
- m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, pLastSection->m_LineArray.GetSize() - 1, -1);
- return TRUE;
- }
+ }
+ if (m_CurPos.nSecIndex > 0) {
+ if (CSection * pLastSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex - 1)) {
+ m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, pLastSection->m_LineArray.GetSize() - 1, -1);
+ return TRUE;
}
}
}
@@ -1753,7 +1736,6 @@ FX_BOOL CPDF_VariableText_Iterator::PrevLine()
}
FX_BOOL CPDF_VariableText_Iterator::NextSection()
{
- ASSERT(m_pVT != NULL);
if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) {
m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1);
return TRUE;