summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-04-03 19:52:27 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-03 19:52:27 +0000
commit28bb2f2ffe751cf4142329e27238da52ae9f848b (patch)
tree99229667c2b702b79f24d60faea4f89457e4ff32 /fpdfsdk
parent4c22dd5690cdec725389055bb7c07c300a4b6fe4 (diff)
downloadpdfium-28bb2f2ffe751cf4142329e27238da52ae9f848b.tar.xz
Remove DefaultAppearance HasColor and return an optional instead
This CL converts CPDF_DefaultAppearance to return Optional<CFX_Color:Type> items instead of having a HasColor. This saves the double parse of the appearance stream. Change-Id: Ib3c136da6e2adfb559e495de1d299cce0b4ad25f Reviewed-on: https://pdfium-review.googlesource.com/29630 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp20
-rw-r--r--fpdfsdk/pwl/cpwl_appstream.cpp15
2 files changed, 19 insertions, 16 deletions
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index f7aae09933..d2d8ecb148 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -431,14 +431,14 @@ bool CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const {
bool CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const {
CPDF_FormControl* pFormCtrl = GetFormControl();
CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
- if (!da.HasColor())
- return false;
-
FX_ARGB argb;
- int iColorType;
+ Optional<CFX_Color::Type> iColorType;
std::tie(iColorType, argb) = da.GetColor();
+ if (!iColorType)
+ return false;
+
color = ArgbToColorRef(argb);
- return iColorType != CFX_Color::kTransparent;
+ return *iColorType != CFX_Color::kTransparent;
}
float CPDFSDK_Widget::GetFontSize() const {
@@ -779,11 +779,11 @@ CFX_Color CPDFSDK_Widget::GetTextPWLColor() const {
CPDF_FormControl* pFormCtrl = GetFormControl();
CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
- if (da.HasColor()) {
- float fc[4];
- int iColorType = da.GetColor(fc);
- crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
- }
+
+ float fc[4];
+ Optional<CFX_Color::Type> iColorType = da.GetColor(fc);
+ if (iColorType)
+ crText = CFX_Color(*iColorType, fc[0], fc[1], fc[2], fc[3]);
return crText;
}
diff --git a/fpdfsdk/pwl/cpwl_appstream.cpp b/fpdfsdk/pwl/cpwl_appstream.cpp
index 6e65831627..cbe6501a32 100644
--- a/fpdfsdk/pwl/cpwl_appstream.cpp
+++ b/fpdfsdk/pwl/cpwl_appstream.cpp
@@ -1180,8 +1180,9 @@ void CPWL_AppStream::SetAsPushButton() {
CFX_Color crText(CFX_Color::kGray, 0);
ByteString csNameTag;
CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
- if (da.HasColor()) {
- iColorType = da.GetColor(fc);
+ Optional<CFX_Color::Type> color = da.GetColor(fc);
+ if (color) {
+ iColorType = *color;
crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
}
@@ -1358,8 +1359,9 @@ void CPWL_AppStream::SetAsCheckBox() {
CFX_FloatRect rcWindow = widget_->GetRotatedRect();
CFX_FloatRect rcClient = rcWindow.GetDeflated(fBorderWidth, fBorderWidth);
CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
- if (da.HasColor()) {
- iColorType = da.GetColor(fc);
+ Optional<CFX_Color::Type> color = da.GetColor(fc);
+ if (color) {
+ iColorType = *color;
crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
}
@@ -1474,8 +1476,9 @@ void CPWL_AppStream::SetAsRadioButton() {
CFX_FloatRect rcWindow = widget_->GetRotatedRect();
CFX_FloatRect rcClient = rcWindow.GetDeflated(fBorderWidth, fBorderWidth);
CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
- if (da.HasColor()) {
- iColorType = da.GetColor(fc);
+ Optional<CFX_Color::Type> color = da.GetColor(fc);
+ if (color) {
+ iColorType = *color;
crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
}