summaryrefslogtreecommitdiff
path: root/fpdfsdk/cpdfsdk_widget.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-07-19 15:24:49 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-19 19:56:19 +0000
commitcb2ea42cc56eb6aaab3e498abf13e63742e64181 (patch)
treeb6e576eb901382cd302109e831d693f81913644a /fpdfsdk/cpdfsdk_widget.cpp
parent67ccef73bf664b7cdb4c6eed7acbaa4163c22a80 (diff)
downloadpdfium-cb2ea42cc56eb6aaab3e498abf13e63742e64181.tar.xz
Create CPWL_AppStream.
This CL creates a CPWL_AppStream and consolidates app stream generation code from CPDFSDK_Widget, CPDFSDK_BAAnnot and CPWL_Utils. The remaining app stream code from CPWL_Utils will be cleaned up in a future CL. Change-Id: I20cfdec09a351bd509241d2c667a182fba84b0c1 Reviewed-on: https://pdfium-review.googlesource.com/8310 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk/cpdfsdk_widget.cpp')
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp858
1 files changed, 9 insertions, 849 deletions
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index 80e7c8adb1..fed6b953da 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -30,6 +30,7 @@
#include "fpdfsdk/fsdk_actionhandler.h"
#include "fpdfsdk/fsdk_define.h"
#include "fpdfsdk/fxedit/fxet_edit.h"
+#include "fpdfsdk/pdfwindow/cpwl_appstream.h"
#include "fpdfsdk/pdfwindow/cpwl_edit.h"
#include "fpdfsdk/pdfwindow/cpwl_utils.h"
@@ -764,26 +765,25 @@ void CPDFSDK_Widget::ResetAppearance(const CFX_WideString* sValue,
if (bValueChanged)
m_nValueAge++;
- int nFieldType = GetFieldType();
-
- switch (nFieldType) {
+ CPWL_AppStream appStream(this, GetAPDict());
+ switch (GetFieldType()) {
case FIELDTYPE_PUSHBUTTON:
- ResetAppearance_PushButton();
+ appStream.SetAsPushButton();
break;
case FIELDTYPE_CHECKBOX:
- ResetAppearance_CheckBox();
+ appStream.SetAsCheckBox();
break;
case FIELDTYPE_RADIOBUTTON:
- ResetAppearance_RadioButton();
+ appStream.SetAsRadioButton();
break;
case FIELDTYPE_COMBOBOX:
- ResetAppearance_ComboBox(sValue);
+ appStream.SetAsComboBox(sValue);
break;
case FIELDTYPE_LISTBOX:
- ResetAppearance_ListBox();
+ appStream.SetAsListBox();
break;
case FIELDTYPE_TEXTFIELD:
- ResetAppearance_TextField(sValue);
+ appStream.SetAsTextField(sValue);
break;
}
@@ -861,777 +861,6 @@ void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
m_pInterForm->GetHighlightColor(nFieldType)));
}
-void CPDFSDK_Widget::ResetAppearance_PushButton() {
- CPDF_FormControl* pControl = GetFormControl();
- CFX_FloatRect rcWindow = GetRotatedRect();
- int32_t nLayout = 0;
- switch (pControl->GetTextPosition()) {
- case TEXTPOS_ICON:
- nLayout = PPBL_ICON;
- break;
- case TEXTPOS_BELOW:
- nLayout = PPBL_ICONTOPLABELBOTTOM;
- break;
- case TEXTPOS_ABOVE:
- nLayout = PPBL_LABELTOPICONBOTTOM;
- break;
- case TEXTPOS_RIGHT:
- nLayout = PPBL_ICONLEFTLABELRIGHT;
- break;
- case TEXTPOS_LEFT:
- nLayout = PPBL_LABELLEFTICONRIGHT;
- break;
- case TEXTPOS_OVERLAID:
- nLayout = PPBL_LABELOVERICON;
- break;
- default:
- nLayout = PPBL_LABEL;
- break;
- }
-
- CFX_Color crBackground;
- CFX_Color crBorder;
- int iColorType;
- float fc[4];
- pControl->GetOriginalBackgroundColor(iColorType, fc);
- if (iColorType > 0)
- crBackground = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- pControl->GetOriginalBorderColor(iColorType, fc);
- if (iColorType > 0)
- crBorder = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- float fBorderWidth = (float)GetBorderWidth();
- CPWL_Dash dsBorder(3, 0, 0);
- CFX_Color crLeftTop;
- CFX_Color crRightBottom;
-
- BorderStyle nBorderStyle = GetBorderStyle();
- switch (nBorderStyle) {
- case BorderStyle::DASH:
- dsBorder = CPWL_Dash(3, 3, 0);
- break;
- case BorderStyle::BEVELED:
- fBorderWidth *= 2;
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 1);
- crRightBottom = crBackground / 2.0f;
- break;
- case BorderStyle::INSET:
- fBorderWidth *= 2;
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5);
- crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75);
- break;
- default:
- break;
- }
-
- CFX_FloatRect rcClient = rcWindow.GetDeflated(fBorderWidth, fBorderWidth);
- CFX_Color crText(COLORTYPE_GRAY, 0);
-
- CFX_ByteString csNameTag;
- CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
- if (da.HasColor()) {
- da.GetColor(iColorType, fc);
- crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
- }
- float fFontSize = 12.0f;
- if (da.HasFont())
- csNameTag = da.GetFont(&fFontSize);
-
- CFX_WideString csWCaption;
- CFX_WideString csNormalCaption;
- CFX_WideString csRolloverCaption;
- CFX_WideString csDownCaption;
- if (pControl->HasMKEntry("CA"))
- csNormalCaption = pControl->GetNormalCaption();
-
- if (pControl->HasMKEntry("RC"))
- csRolloverCaption = pControl->GetRolloverCaption();
-
- if (pControl->HasMKEntry("AC"))
- csDownCaption = pControl->GetDownCaption();
-
- CPDF_Stream* pNormalIcon = nullptr;
- CPDF_Stream* pRolloverIcon = nullptr;
- CPDF_Stream* pDownIcon = nullptr;
- if (pControl->HasMKEntry("I"))
- pNormalIcon = pControl->GetNormalIcon();
-
- if (pControl->HasMKEntry("RI"))
- pRolloverIcon = pControl->GetRolloverIcon();
-
- if (pControl->HasMKEntry("IX"))
- pDownIcon = pControl->GetDownIcon();
-
- if (pNormalIcon) {
- if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) {
- if (pImageDict->GetStringFor("Name").IsEmpty())
- pImageDict->SetNewFor<CPDF_String>("Name", "ImgA", false);
- }
- }
-
- if (pRolloverIcon) {
- if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) {
- if (pImageDict->GetStringFor("Name").IsEmpty())
- pImageDict->SetNewFor<CPDF_String>("Name", "ImgB", false);
- }
- }
-
- if (pDownIcon) {
- if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) {
- if (pImageDict->GetStringFor("Name").IsEmpty())
- pImageDict->SetNewFor<CPDF_String>("Name", "ImgC", false);
- }
- }
-
- CPDF_IconFit iconFit = pControl->GetIconFit();
-
- CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
- font_map.SetAPType("N");
-
- CFX_ByteString csAP =
- CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
- CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
- crLeftTop, crRightBottom, nBorderStyle,
- dsBorder) +
- CPWL_Utils::GetPushButtonAppStream(
- iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
- pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);
-
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);
- if (pNormalIcon)
- AddImageToAppearance("N", pNormalIcon);
-
- CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();
- if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) {
- if (csRolloverCaption.IsEmpty() && !pRolloverIcon) {
- csRolloverCaption = csNormalCaption;
- pRolloverIcon = pNormalIcon;
- }
-
- font_map.SetAPType("R");
-
- csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
- CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
- crLeftTop, crRightBottom,
- nBorderStyle, dsBorder) +
- CPWL_Utils::GetPushButtonAppStream(
- iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
- pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize,
- nLayout);
-
- WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);
- if (pRolloverIcon)
- AddImageToAppearance("R", pRolloverIcon);
-
- if (csDownCaption.IsEmpty() && !pDownIcon) {
- csDownCaption = csNormalCaption;
- pDownIcon = pNormalIcon;
- }
-
- switch (nBorderStyle) {
- case BorderStyle::BEVELED: {
- CFX_Color crTemp = crLeftTop;
- crLeftTop = crRightBottom;
- crRightBottom = crTemp;
- break;
- }
- case BorderStyle::INSET: {
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 0);
- crRightBottom = CFX_Color(COLORTYPE_GRAY, 1);
- break;
- }
- default:
- break;
- }
-
- font_map.SetAPType("D");
-
- csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) +
- CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
- crLeftTop, crRightBottom,
- nBorderStyle, dsBorder) +
- CPWL_Utils::GetPushButtonAppStream(
- iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
- pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout);
-
- WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP);
- if (pDownIcon)
- AddImageToAppearance("D", pDownIcon);
- } else {
- RemoveAppearance("D");
- RemoveAppearance("R");
- }
-}
-
-void CPDFSDK_Widget::ResetAppearance_CheckBox() {
- CPDF_FormControl* pControl = GetFormControl();
- CFX_Color crBackground, crBorder, crText;
- int iColorType;
- float fc[4];
-
- pControl->GetOriginalBackgroundColor(iColorType, fc);
- if (iColorType > 0)
- crBackground = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- pControl->GetOriginalBorderColor(iColorType, fc);
- if (iColorType > 0)
- crBorder = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- float fBorderWidth = (float)GetBorderWidth();
- CPWL_Dash dsBorder(3, 0, 0);
- CFX_Color crLeftTop, crRightBottom;
-
- BorderStyle nBorderStyle = GetBorderStyle();
- switch (nBorderStyle) {
- case BorderStyle::DASH:
- dsBorder = CPWL_Dash(3, 3, 0);
- break;
- case BorderStyle::BEVELED:
- fBorderWidth *= 2;
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 1);
- crRightBottom = crBackground / 2.0f;
- break;
- case BorderStyle::INSET:
- fBorderWidth *= 2;
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5);
- crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75);
- break;
- default:
- break;
- }
-
- CFX_FloatRect rcWindow = GetRotatedRect();
- CFX_FloatRect rcClient = rcWindow.GetDeflated(fBorderWidth, fBorderWidth);
- CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
- if (da.HasColor()) {
- da.GetColor(iColorType, fc);
- crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
- }
-
- int32_t nStyle = 0;
- CFX_WideString csWCaption = pControl->GetNormalCaption();
- if (csWCaption.GetLength() > 0) {
- switch (csWCaption[0]) {
- case L'l':
- nStyle = PCS_CIRCLE;
- break;
- case L'8':
- nStyle = PCS_CROSS;
- break;
- case L'u':
- nStyle = PCS_DIAMOND;
- break;
- case L'n':
- nStyle = PCS_SQUARE;
- break;
- case L'H':
- nStyle = PCS_STAR;
- break;
- default: // L'4'
- nStyle = PCS_CHECK;
- break;
- }
- } else {
- nStyle = PCS_CHECK;
- }
-
- CFX_ByteString csAP_N_ON =
- CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
- CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
- crLeftTop, crRightBottom, nBorderStyle,
- dsBorder);
-
- CFX_ByteString csAP_N_OFF = csAP_N_ON;
-
- switch (nBorderStyle) {
- case BorderStyle::BEVELED: {
- CFX_Color crTemp = crLeftTop;
- crLeftTop = crRightBottom;
- crRightBottom = crTemp;
- break;
- }
- case BorderStyle::INSET: {
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 0);
- crRightBottom = CFX_Color(COLORTYPE_GRAY, 1);
- break;
- }
- default:
- break;
- }
-
- CFX_ByteString csAP_D_ON =
- CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) +
- CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
- crLeftTop, crRightBottom, nBorderStyle,
- dsBorder);
-
- CFX_ByteString csAP_D_OFF = csAP_D_ON;
-
- csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
- csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
-
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
- pControl->GetCheckedAPState());
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
-
- WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
- pControl->GetCheckedAPState());
- WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
-
- CFX_ByteString csAS = GetAppState();
- if (csAS.IsEmpty())
- SetAppState("Off");
-}
-
-void CPDFSDK_Widget::ResetAppearance_RadioButton() {
- CPDF_FormControl* pControl = GetFormControl();
- CFX_Color crBackground, crBorder, crText;
- int iColorType;
- float fc[4];
-
- pControl->GetOriginalBackgroundColor(iColorType, fc);
- if (iColorType > 0)
- crBackground = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- pControl->GetOriginalBorderColor(iColorType, fc);
- if (iColorType > 0)
- crBorder = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
-
- float fBorderWidth = (float)GetBorderWidth();
- CPWL_Dash dsBorder(3, 0, 0);
- CFX_Color crLeftTop;
- CFX_Color crRightBottom;
- BorderStyle nBorderStyle = GetBorderStyle();
- switch (nBorderStyle) {
- case BorderStyle::DASH:
- dsBorder = CPWL_Dash(3, 3, 0);
- break;
- case BorderStyle::BEVELED:
- fBorderWidth *= 2;
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 1);
- crRightBottom = crBackground / 2.0f;
- break;
- case BorderStyle::INSET:
- fBorderWidth *= 2;
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5);
- crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75);
- break;
- default:
- break;
- }
-
- CFX_FloatRect rcWindow = GetRotatedRect();
- CFX_FloatRect rcClient = rcWindow.GetDeflated(fBorderWidth, fBorderWidth);
- CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
- if (da.HasColor()) {
- da.GetColor(iColorType, fc);
- crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
- }
-
- int32_t nStyle = 0;
- CFX_WideString csWCaption = pControl->GetNormalCaption();
- if (csWCaption.GetLength() > 0) {
- switch (csWCaption[0]) {
- default: // L'l':
- nStyle = PCS_CIRCLE;
- break;
- case L'8':
- nStyle = PCS_CROSS;
- break;
- case L'u':
- nStyle = PCS_DIAMOND;
- break;
- case L'n':
- nStyle = PCS_SQUARE;
- break;
- case L'H':
- nStyle = PCS_STAR;
- break;
- case L'4':
- nStyle = PCS_CHECK;
- break;
- }
- } else {
- nStyle = PCS_CIRCLE;
- }
-
- CFX_ByteString csAP_N_ON;
- CFX_FloatRect rcCenter = rcWindow.GetCenterSquare().GetDeflated(1.0f, 1.0f);
- if (nStyle == PCS_CIRCLE) {
- if (nBorderStyle == BorderStyle::BEVELED) {
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 1);
- crRightBottom = crBackground - 0.25f;
- } else if (nBorderStyle == BorderStyle::INSET) {
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5f);
- crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75f);
- }
-
- csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) +
- CPWL_Utils::GetCircleBorderAppStream(
- rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
- nBorderStyle, dsBorder);
- } else {
- csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
- CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
- crLeftTop, crRightBottom,
- nBorderStyle, dsBorder);
- }
-
- CFX_ByteString csAP_N_OFF = csAP_N_ON;
-
- switch (nBorderStyle) {
- case BorderStyle::BEVELED: {
- CFX_Color crTemp = crLeftTop;
- crLeftTop = crRightBottom;
- crRightBottom = crTemp;
- break;
- }
- case BorderStyle::INSET: {
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 0);
- crRightBottom = CFX_Color(COLORTYPE_GRAY, 1);
- break;
- }
- default:
- break;
- }
-
- CFX_ByteString csAP_D_ON;
-
- if (nStyle == PCS_CIRCLE) {
- CFX_Color crBK = crBackground - 0.25f;
- if (nBorderStyle == BorderStyle::BEVELED) {
- crLeftTop = crBackground - 0.25f;
- crRightBottom = CFX_Color(COLORTYPE_GRAY, 1);
- crBK = crBackground;
- } else if (nBorderStyle == BorderStyle::INSET) {
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 0);
- crRightBottom = CFX_Color(COLORTYPE_GRAY, 1);
- }
-
- csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) +
- CPWL_Utils::GetCircleBorderAppStream(
- rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
- nBorderStyle, dsBorder);
- } else {
- csAP_D_ON =
- CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) +
- CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
- crLeftTop, crRightBottom, nBorderStyle,
- dsBorder);
- }
-
- CFX_ByteString csAP_D_OFF = csAP_D_ON;
-
- csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
- csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
-
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
- pControl->GetCheckedAPState());
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
-
- WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
- pControl->GetCheckedAPState());
- WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
-
- CFX_ByteString csAS = GetAppState();
- if (csAS.IsEmpty())
- SetAppState("Off");
-}
-
-void CPDFSDK_Widget::ResetAppearance_ComboBox(const CFX_WideString* sValue) {
- CPDF_FormControl* pControl = GetFormControl();
- CPDF_FormField* pField = pControl->GetField();
- std::ostringstream sBody;
-
- CFX_FloatRect rcClient = GetClientRect();
- CFX_FloatRect rcButton = rcClient;
- rcButton.left = rcButton.right - 13;
- rcButton.Normalize();
-
- auto pEdit = pdfium::MakeUnique<CFX_Edit>();
- pEdit->EnableRefresh(false);
-
- CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
- pEdit->SetFontMap(&font_map);
-
- CFX_FloatRect rcEdit = rcClient;
- rcEdit.right = rcButton.left;
- rcEdit.Normalize();
-
- pEdit->SetPlateRect(rcEdit);
- pEdit->SetAlignmentV(1, true);
-
- float fFontSize = GetFontSize();
- if (IsFloatZero(fFontSize))
- pEdit->SetAutoFontSize(true, true);
- else
- pEdit->SetFontSize(fFontSize);
-
- pEdit->Initialize();
-
- if (sValue) {
- pEdit->SetText(*sValue);
- } else {
- int32_t nCurSel = pField->GetSelectedIndex(0);
- if (nCurSel < 0)
- pEdit->SetText(pField->GetValue());
- else
- pEdit->SetText(pField->GetOptionLabel(nCurSel));
- }
-
- CFX_FloatRect rcContent = pEdit->GetContentRect();
-
- CFX_ByteString sEdit =
- CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF());
- 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_Color crText = GetTextPWLColor();
- sBody << "BT\n"
- << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"
- << "Q\nEMC\n";
- }
-
- sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);
-
- CFX_ByteString sAP =
- GetBackgroundAppStream() + GetBorderAppStream() + CFX_ByteString(sBody);
-
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
-}
-
-void CPDFSDK_Widget::ResetAppearance_ListBox() {
- CPDF_FormControl* pControl = GetFormControl();
- CPDF_FormField* pField = pControl->GetField();
- CFX_FloatRect rcClient = GetClientRect();
- std::ostringstream sBody;
-
- auto pEdit = pdfium::MakeUnique<CFX_Edit>();
- pEdit->EnableRefresh(false);
-
- CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
- pEdit->SetFontMap(&font_map);
-
- pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f));
-
- float fFontSize = GetFontSize();
-
- pEdit->SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize);
-
- pEdit->Initialize();
-
- std::ostringstream sList;
- float fy = rcClient.top;
-
- int32_t nTop = pField->GetTopVisibleIndex();
- int32_t nCount = pField->CountOptions();
- int32_t nSelCount = pField->CountSelectedItems();
-
- for (int32_t i = nTop; i < nCount; ++i) {
- bool bSelected = false;
- for (int32_t j = 0; j < nSelCount; ++j) {
- if (pField->GetSelectedIndex(j) == i) {
- bSelected = true;
- break;
- }
- }
-
- pEdit->SetText(pField->GetOptionLabel(i));
-
- CFX_FloatRect rcContent = pEdit->GetContentRect();
- float fItemHeight = rcContent.Height();
-
- if (bSelected) {
- CFX_FloatRect rcItem =
- CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy);
- sList << "q\n"
- << CPWL_Utils::GetColorAppStream(
- CFX_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(CFX_Color(COLORTYPE_GRAY, 1), true)
- << CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy))
- << "ET\n";
- } else {
- CFX_Color crText = GetTextPWLColor();
- sList << "BT\n"
- << CPWL_Utils::GetColorAppStream(crText, true)
- << CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy))
- << "ET\n";
- }
-
- fy -= fItemHeight;
- }
-
- if (sList.tellp() > 0) {
- sBody << "/Tx BMC\n"
- << "q\n"
- << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width()
- << " " << rcClient.Height() << " re\nW\nn\n";
- sBody << sList.str() << "Q\nEMC\n";
- }
-
- CFX_ByteString sAP =
- GetBackgroundAppStream() + GetBorderAppStream() + CFX_ByteString(sBody);
-
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
-}
-
-void CPDFSDK_Widget::ResetAppearance_TextField(const CFX_WideString* sValue) {
- CPDF_FormControl* pControl = GetFormControl();
- CPDF_FormField* pField = pControl->GetField();
- std::ostringstream sBody;
- std::ostringstream sLines;
-
- auto pEdit = pdfium::MakeUnique<CFX_Edit>();
- pEdit->EnableRefresh(false);
-
- CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
- pEdit->SetFontMap(&font_map);
-
- CFX_FloatRect rcClient = GetClientRect();
- pEdit->SetPlateRect(rcClient);
- pEdit->SetAlignmentH(pControl->GetControlAlignment(), true);
-
- uint32_t dwFieldFlags = pField->GetFieldFlags();
- bool bMultiLine = (dwFieldFlags >> 12) & 1;
-
- if (bMultiLine) {
- pEdit->SetMultiLine(true, true);
- pEdit->SetAutoReturn(true, true);
- } else {
- pEdit->SetAlignmentV(1, true);
- }
-
- uint16_t subWord = 0;
- if ((dwFieldFlags >> 13) & 1) {
- subWord = '*';
- pEdit->SetPasswordChar(subWord, true);
- }
-
- int nMaxLen = pField->GetMaxLen();
- bool bCharArray = (dwFieldFlags >> 24) & 1;
- float fFontSize = GetFontSize();
-
-#ifdef PDF_ENABLE_XFA
- CFX_WideString sValueTmp;
- if (!sValue && GetMixXFAWidget()) {
- sValueTmp = GetValue(true);
- sValue = &sValueTmp;
- }
-#endif // PDF_ENABLE_XFA
-
- 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 = sValue->GetLength();
- pEdit->SetLimitChar(nMaxLen);
- }
- }
-
- if (IsFloatZero(fFontSize))
- pEdit->SetAutoFontSize(true, true);
- else
- pEdit->SetFontSize(fFontSize);
-
- pEdit->Initialize();
- pEdit->SetText(sValue ? *sValue : pField->GetValue());
-
- CFX_FloatRect rcContent = pEdit->GetContentRect();
- CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(
- pEdit.get(), CFX_PointF(), nullptr, !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";
- }
- CFX_Color crText = GetTextPWLColor();
- sBody << "BT\n"
- << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"
- << "Q\nEMC\n";
- }
-
- if (bCharArray) {
- switch (GetBorderStyle()) {
- case BorderStyle::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";
- }
- break;
- }
- case BorderStyle::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";
- }
- break;
- }
- default:
- break;
- }
- }
-
- CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
- CFX_ByteString(sLines) + CFX_ByteString(sBody);
- WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
-}
-
CFX_FloatRect CPDFSDK_Widget::GetClientRect() const {
CFX_FloatRect rcWindow = GetRotatedRect();
float fBorderWidth = (float)GetBorderWidth();
@@ -1668,47 +897,6 @@ CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const {
return rcPDFWindow;
}
-CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const {
- CFX_Color crBackground = GetFillPWLColor();
- if (crBackground.nColorType != COLORTYPE_TRANSPARENT)
- return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
-
- return "";
-}
-
-CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const {
- CFX_FloatRect rcWindow = GetRotatedRect();
- CFX_Color crBorder = GetBorderPWLColor();
- CFX_Color crBackground = GetFillPWLColor();
- CFX_Color crLeftTop, crRightBottom;
-
- float fBorderWidth = (float)GetBorderWidth();
- CPWL_Dash dsBorder(3, 0, 0);
-
- BorderStyle nBorderStyle = GetBorderStyle();
- switch (nBorderStyle) {
- case BorderStyle::DASH:
- dsBorder = CPWL_Dash(3, 3, 0);
- break;
- case BorderStyle::BEVELED:
- fBorderWidth *= 2;
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 1);
- crRightBottom = crBackground / 2.0f;
- break;
- case BorderStyle::INSET:
- fBorderWidth *= 2;
- crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5);
- crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75);
- break;
- default:
- break;
- }
-
- return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
- crLeftTop, crRightBottom, nBorderStyle,
- dsBorder);
-}
-
CFX_Matrix CPDFSDK_Widget::GetMatrix() const {
CFX_Matrix mt;
CPDF_FormControl* pControl = GetFormControl();
@@ -1775,34 +963,6 @@ CFX_Color CPDFSDK_Widget::GetFillPWLColor() const {
return crFill;
}
-void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType,
- CPDF_Stream* pImage) {
- CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
- CPDF_Stream* pStream = pAPDict->GetStreamFor(sAPType);
- CPDF_Dictionary* pStreamDict = pStream->GetDict();
- CFX_ByteString sImageAlias = "IMG";
-
- if (CPDF_Dictionary* pImageDict = pImage->GetDict()) {
- sImageAlias = pImageDict->GetStringFor("Name");
- if (sImageAlias.IsEmpty())
- sImageAlias = "IMG";
- }
-
- CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
- CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
- if (!pStreamResList)
- pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources");
-
- CPDF_Dictionary* pXObject =
- pStreamResList->SetNewFor<CPDF_Dictionary>("XObject");
- pXObject->SetNewFor<CPDF_Reference>(sImageAlias, pDoc, pImage->GetObjNum());
-}
-
-void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) {
- if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"))
- pAPDict->RemoveFor(sAPType);
-}
-
bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
PDFSDK_FieldAction& data,
CPDFSDK_PageView* pPageView) {