From 732f6a01f11749192badba3d5151a33460560b7f Mon Sep 17 00:00:00 2001 From: thestig Date: Thu, 12 May 2016 10:41:56 -0700 Subject: IFX_Edit::NewEdit never returns nullptr. Review-Url: https://codereview.chromium.org/1969353002 --- fpdfsdk/fsdk_baseform.cpp | 430 +++++++++++++++++++++++----------------------- 1 file changed, 216 insertions(+), 214 deletions(-) (limited to 'fpdfsdk/fsdk_baseform.cpp') diff --git a/fpdfsdk/fsdk_baseform.cpp b/fpdfsdk/fsdk_baseform.cpp index a5cb562a3b..46e9c46fb1 100644 --- a/fpdfsdk/fsdk_baseform.cpp +++ b/fpdfsdk/fsdk_baseform.cpp @@ -1352,62 +1352,61 @@ void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) { rcButton.left = rcButton.right - 13; rcButton.Normalize(); - if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) { - pEdit->EnableRefresh(FALSE); + IFX_Edit* pEdit = IFX_Edit::NewEdit(); + pEdit->EnableRefresh(FALSE); - CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); - CPDFDoc_Environment* pEnv = pDoc->GetEnv(); - CBA_FontMap font_map(this, pEnv->GetSysHandler()); - pEdit->SetFontMap(&font_map); + CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); + CPDFDoc_Environment* pEnv = pDoc->GetEnv(); + CBA_FontMap font_map(this, pEnv->GetSysHandler()); + pEdit->SetFontMap(&font_map); - CFX_FloatRect rcEdit = rcClient; - rcEdit.right = rcButton.left; - rcEdit.Normalize(); + CFX_FloatRect rcEdit = rcClient; + rcEdit.right = rcButton.left; + rcEdit.Normalize(); - pEdit->SetPlateRect(rcEdit); - pEdit->SetAlignmentV(1); + pEdit->SetPlateRect(rcEdit); + pEdit->SetAlignmentV(1); - FX_FLOAT fFontSize = GetFontSize(); - if (IsFloatZero(fFontSize)) - pEdit->SetAutoFontSize(TRUE); - else - pEdit->SetFontSize(fFontSize); + FX_FLOAT fFontSize = GetFontSize(); + if (IsFloatZero(fFontSize)) + pEdit->SetAutoFontSize(TRUE); + else + pEdit->SetFontSize(fFontSize); - pEdit->Initialize(); + pEdit->Initialize(); - if (sValue) { - pEdit->SetText(sValue); - } else { - int32_t nCurSel = pField->GetSelectedIndex(0); - - if (nCurSel < 0) - pEdit->SetText(pField->GetValue().c_str()); - else - pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str()); - } + if (sValue) { + pEdit->SetText(sValue); + } else { + int32_t nCurSel = pField->GetSelectedIndex(0); - CFX_FloatRect rcContent = pEdit->GetContentRect(); + if (nCurSel < 0) + pEdit->SetText(pField->GetValue().c_str()); + else + pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str()); + } - CFX_ByteString sEdit = - CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f)); - if (sEdit.GetLength() > 0) { - sBody << "/Tx BMC\n" - << "q\n"; - if (rcContent.Width() > rcEdit.Width() || - rcContent.Height() > rcEdit.Height()) { - sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() - << " " << rcEdit.Height() << " re\nW\nn\n"; - } + CFX_FloatRect rcContent = pEdit->GetContentRect(); - CPWL_Color crText = GetTextPWLColor(); - sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit - << "ET\n" - << "Q\nEMC\n"; + CFX_ByteString sEdit = + CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f)); + if (sEdit.GetLength() > 0) { + sBody << "/Tx BMC\n" + << "q\n"; + if (rcContent.Width() > rcEdit.Width() || + rcContent.Height() > rcEdit.Height()) { + sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() + << " " << rcEdit.Height() << " re\nW\nn\n"; } - IFX_Edit::DelEdit(pEdit); + CPWL_Color crText = GetTextPWLColor(); + sBody << "BT\n" + << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" + << "Q\nEMC\n"; } + IFX_Edit::DelEdit(pEdit); + sBody << CPWL_Utils::GetDropButtonAppStream(rcButton); CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + @@ -1422,83 +1421,85 @@ void CPDFSDK_Widget::ResetAppearance_ListBox() { CFX_FloatRect rcClient = GetClientRect(); CFX_ByteTextBuf sBody, sLines; - if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) { - pEdit->EnableRefresh(FALSE); + IFX_Edit* pEdit = IFX_Edit::NewEdit(); + pEdit->EnableRefresh(FALSE); - CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); - CPDFDoc_Environment* pEnv = pDoc->GetEnv(); + CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); + CPDFDoc_Environment* pEnv = pDoc->GetEnv(); - CBA_FontMap font_map(this, pEnv->GetSysHandler()); - pEdit->SetFontMap(&font_map); + CBA_FontMap font_map(this, pEnv->GetSysHandler()); + pEdit->SetFontMap(&font_map); - pEdit->SetPlateRect( - CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f)); + pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f)); - FX_FLOAT fFontSize = GetFontSize(); + FX_FLOAT fFontSize = GetFontSize(); - if (IsFloatZero(fFontSize)) - pEdit->SetFontSize(12.0f); - else - pEdit->SetFontSize(fFontSize); + if (IsFloatZero(fFontSize)) + pEdit->SetFontSize(12.0f); + else + pEdit->SetFontSize(fFontSize); - pEdit->Initialize(); + pEdit->Initialize(); - CFX_ByteTextBuf sList; - FX_FLOAT fy = rcClient.top; + CFX_ByteTextBuf sList; + FX_FLOAT fy = rcClient.top; - int32_t nTop = pField->GetTopVisibleIndex(); - int32_t nCount = pField->CountOptions(); - int32_t nSelCount = pField->CountSelectedItems(); + int32_t nTop = pField->GetTopVisibleIndex(); + int32_t nCount = pField->CountOptions(); + int32_t nSelCount = pField->CountSelectedItems(); - for (int32_t i = nTop; i < nCount; i++) { - FX_BOOL bSelected = FALSE; - for (int32_t j = 0; j < nSelCount; j++) { - if (pField->GetSelectedIndex(j) == i) { - bSelected = TRUE; - break; - } + for (int32_t i = nTop; i < nCount; i++) { + FX_BOOL bSelected = FALSE; + for (int32_t j = 0; j < nSelCount; j++) { + if (pField->GetSelectedIndex(j) == i) { + bSelected = TRUE; + break; } + } - pEdit->SetText(pField->GetOptionLabel(i).c_str()); - - CFX_FloatRect rcContent = pEdit->GetContentRect(); - FX_FLOAT fItemHeight = rcContent.Height(); - - if (bSelected) { - CFX_FloatRect rcItem = - CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy); - sList << "q\n" << CPWL_Utils::GetColorAppStream( - CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, - 113.0f / 255.0f), - TRUE) - << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() - << " " << rcItem.Height() << " re f\n" - << "Q\n"; - - sList << "BT\n" << CPWL_Utils::GetColorAppStream( - CPWL_Color(COLORTYPE_GRAY, 1), TRUE) - << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) - << "ET\n"; - } else { - CPWL_Color crText = GetTextPWLColor(); - sList << "BT\n" << CPWL_Utils::GetColorAppStream(crText, TRUE) - << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) - << "ET\n"; - } + pEdit->SetText(pField->GetOptionLabel(i).c_str()); - fy -= fItemHeight; + CFX_FloatRect rcContent = pEdit->GetContentRect(); + FX_FLOAT fItemHeight = rcContent.Height(); + + if (bSelected) { + CFX_FloatRect rcItem = + CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy); + sList << "q\n" + << CPWL_Utils::GetColorAppStream( + CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, + 113.0f / 255.0f), + TRUE) + << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() + << " " << rcItem.Height() << " re f\n" + << "Q\n"; + + sList << "BT\n" + << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1), + TRUE) + << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) + << "ET\n"; + } else { + CPWL_Color crText = GetTextPWLColor(); + sList << "BT\n" + << CPWL_Utils::GetColorAppStream(crText, TRUE) + << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) + << "ET\n"; } - if (sList.GetSize() > 0) { - sBody << "/Tx BMC\n" - << "q\n" << rcClient.left << " " << rcClient.bottom << " " - << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; - sBody << sList << "Q\nEMC\n"; - } + fy -= fItemHeight; + } - IFX_Edit::DelEdit(pEdit); + if (sList.GetSize() > 0) { + sBody << "/Tx BMC\n" + << "q\n" + << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width() + << " " << rcClient.Height() << " re\nW\nn\n"; + sBody << sList << "Q\nEMC\n"; } + IFX_Edit::DelEdit(pEdit); + CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.AsStringC() + sBody.AsStringC(); @@ -1510,144 +1511,145 @@ void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) { CPDF_FormField* pField = pControl->GetField(); CFX_ByteTextBuf sBody, sLines; - if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) { - pEdit->EnableRefresh(FALSE); + IFX_Edit* pEdit = IFX_Edit::NewEdit(); + pEdit->EnableRefresh(FALSE); - CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); - CPDFDoc_Environment* pEnv = pDoc->GetEnv(); + CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); + CPDFDoc_Environment* pEnv = pDoc->GetEnv(); - CBA_FontMap font_map(this, pEnv->GetSysHandler()); - pEdit->SetFontMap(&font_map); + CBA_FontMap font_map(this, pEnv->GetSysHandler()); + pEdit->SetFontMap(&font_map); - CFX_FloatRect rcClient = GetClientRect(); - pEdit->SetPlateRect(rcClient); - pEdit->SetAlignmentH(pControl->GetControlAlignment()); + CFX_FloatRect rcClient = GetClientRect(); + pEdit->SetPlateRect(rcClient); + pEdit->SetAlignmentH(pControl->GetControlAlignment()); - uint32_t dwFieldFlags = pField->GetFieldFlags(); - FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1; + uint32_t dwFieldFlags = pField->GetFieldFlags(); + FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1; - if (bMultiLine) { - pEdit->SetMultiLine(TRUE); - pEdit->SetAutoReturn(TRUE); - } else { - pEdit->SetAlignmentV(1); - } + if (bMultiLine) { + pEdit->SetMultiLine(TRUE); + pEdit->SetAutoReturn(TRUE); + } else { + pEdit->SetAlignmentV(1); + } - uint16_t subWord = 0; - if ((dwFieldFlags >> 13) & 1) { - subWord = '*'; - pEdit->SetPasswordChar(subWord); - } + uint16_t subWord = 0; + if ((dwFieldFlags >> 13) & 1) { + subWord = '*'; + pEdit->SetPasswordChar(subWord); + } - int nMaxLen = pField->GetMaxLen(); - FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1; - FX_FLOAT fFontSize = GetFontSize(); + int nMaxLen = pField->GetMaxLen(); + FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1; + FX_FLOAT fFontSize = GetFontSize(); #ifdef PDF_ENABLE_XFA - CFX_WideString sValueTmp; - if (!sValue && GetMixXFAWidget()) { - sValueTmp = GetValue(TRUE); - sValue = sValueTmp.c_str(); - } + CFX_WideString sValueTmp; + if (!sValue && GetMixXFAWidget()) { + sValueTmp = GetValue(TRUE); + sValue = sValueTmp.c_str(); + } #endif // PDF_ENABLE_XFA - if (nMaxLen > 0) { - if (bCharArray) { - pEdit->SetCharArray(nMaxLen); + if (nMaxLen > 0) { + if (bCharArray) { + pEdit->SetCharArray(nMaxLen); - if (IsFloatZero(fFontSize)) { - fFontSize = CPWL_Edit::GetCharArrayAutoFontSize( - font_map.GetPDFFont(0), rcClient, nMaxLen); - } - } else { - if (sValue) - nMaxLen = wcslen((const wchar_t*)sValue); - pEdit->SetLimitChar(nMaxLen); + if (IsFloatZero(fFontSize)) { + fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0), + rcClient, nMaxLen); } + } else { + if (sValue) + nMaxLen = wcslen((const wchar_t*)sValue); + pEdit->SetLimitChar(nMaxLen); } + } - if (IsFloatZero(fFontSize)) - pEdit->SetAutoFontSize(TRUE); - else - pEdit->SetFontSize(fFontSize); + if (IsFloatZero(fFontSize)) + pEdit->SetAutoFontSize(TRUE); + else + pEdit->SetFontSize(fFontSize); - pEdit->Initialize(); + pEdit->Initialize(); - if (sValue) - pEdit->SetText(sValue); - else - pEdit->SetText(pField->GetValue().c_str()); + if (sValue) + pEdit->SetText(sValue); + else + pEdit->SetText(pField->GetValue().c_str()); - CFX_FloatRect rcContent = pEdit->GetContentRect(); + CFX_FloatRect rcContent = pEdit->GetContentRect(); - CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( - pEdit, CFX_FloatPoint(0.0f, 0.0f), NULL, !bCharArray, subWord); + CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( + pEdit, CFX_FloatPoint(0.0f, 0.0f), NULL, !bCharArray, subWord); - if (sEdit.GetLength() > 0) { - sBody << "/Tx BMC\n" - << "q\n"; - if (rcContent.Width() > rcClient.Width() || - rcContent.Height() > rcClient.Height()) { - sBody << rcClient.left << " " << rcClient.bottom << " " - << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; - } - CPWL_Color crText = GetTextPWLColor(); - sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit - << "ET\n" - << "Q\nEMC\n"; + if (sEdit.GetLength() > 0) { + sBody << "/Tx BMC\n" + << "q\n"; + if (rcContent.Width() > rcClient.Width() || + rcContent.Height() > rcClient.Height()) { + sBody << rcClient.left << " " << rcClient.bottom << " " + << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; } - - if (bCharArray) { - switch (GetBorderStyle()) { - case BBS_SOLID: { - CFX_ByteString sColor = - CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); - if (sColor.GetLength() > 0) { - sLines << "q\n" << GetBorderWidth() << " w\n" - << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) - << " 2 J 0 j\n"; - - for (int32_t i = 1; i < nMaxLen; i++) { - sLines << rcClient.left + - ((rcClient.right - rcClient.left) / nMaxLen) * i - << " " << rcClient.bottom << " m\n" - << rcClient.left + - ((rcClient.right - rcClient.left) / nMaxLen) * i - << " " << rcClient.top << " l S\n"; - } - - sLines << "Q\n"; + CPWL_Color crText = GetTextPWLColor(); + sBody << "BT\n" + << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" + << "Q\nEMC\n"; + } + + if (bCharArray) { + switch (GetBorderStyle()) { + case BBS_SOLID: { + CFX_ByteString sColor = + CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); + if (sColor.GetLength() > 0) { + sLines << "q\n" + << GetBorderWidth() << " w\n" + << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) + << " 2 J 0 j\n"; + + for (int32_t i = 1; i < nMaxLen; i++) { + sLines << rcClient.left + + ((rcClient.right - rcClient.left) / nMaxLen) * i + << " " << rcClient.bottom << " m\n" + << rcClient.left + + ((rcClient.right - rcClient.left) / nMaxLen) * i + << " " << rcClient.top << " l S\n"; } - } break; - case BBS_DASH: { - CFX_ByteString sColor = - CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); - if (sColor.GetLength() > 0) { - CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0); - - sLines << "q\n" << GetBorderWidth() << " w\n" - << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) - << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] " - << dsBorder.nPhase << " d\n"; - - for (int32_t i = 1; i < nMaxLen; i++) { - sLines << rcClient.left + - ((rcClient.right - rcClient.left) / nMaxLen) * i - << " " << rcClient.bottom << " m\n" - << rcClient.left + - ((rcClient.right - rcClient.left) / nMaxLen) * i - << " " << rcClient.top << " l S\n"; - } - sLines << "Q\n"; + sLines << "Q\n"; + } + } break; + case BBS_DASH: { + CFX_ByteString sColor = + CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); + if (sColor.GetLength() > 0) { + CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0); + + sLines << "q\n" + << GetBorderWidth() << " w\n" + << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) + << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] " + << dsBorder.nPhase << " d\n"; + + for (int32_t i = 1; i < nMaxLen; i++) { + sLines << rcClient.left + + ((rcClient.right - rcClient.left) / nMaxLen) * i + << " " << rcClient.bottom << " m\n" + << rcClient.left + + ((rcClient.right - rcClient.left) / nMaxLen) * i + << " " << rcClient.top << " l S\n"; } - } break; - } - } - IFX_Edit::DelEdit(pEdit); + sLines << "Q\n"; + } + } break; + } } + IFX_Edit::DelEdit(pEdit); + CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.AsStringC() + sBody.AsStringC(); WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); -- cgit v1.2.3