summaryrefslogtreecommitdiff
path: root/fpdfsdk/pdfwindow/cpwl_appstream.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-07-20 11:08:03 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-20 15:52:52 +0000
commitdc11ec85ebf637efe99dd9195a2a6a52c3e4d48f (patch)
treec534ee86ebfc63474d77292cc6780c8c65d19e57 /fpdfsdk/pdfwindow/cpwl_appstream.cpp
parent14ddd425193946692042fcd910857963d333be3b (diff)
downloadpdfium-dc11ec85ebf637efe99dd9195a2a6a52c3e4d48f.tar.xz
Cleanup CPWL_Icon AppStream generation
This CL moves the AppSteam generation code for CPWL_Icon to a separate method. The CPWL_Image code is also folded directly into CPWL_Icon as it is the only subclass. Change-Id: I7936bac4af76e34d0f73d48ca00f5713c5f20095 Reviewed-on: https://pdfium-review.googlesource.com/8314 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/pdfwindow/cpwl_appstream.cpp')
-rw-r--r--fpdfsdk/pdfwindow/cpwl_appstream.cpp91
1 files changed, 49 insertions, 42 deletions
diff --git a/fpdfsdk/pdfwindow/cpwl_appstream.cpp b/fpdfsdk/pdfwindow/cpwl_appstream.cpp
index cf291e341d..f7b57365df 100644
--- a/fpdfsdk/pdfwindow/cpwl_appstream.cpp
+++ b/fpdfsdk/pdfwindow/cpwl_appstream.cpp
@@ -593,6 +593,53 @@ CFX_ByteString GetEditAppStream(CFX_Edit* pEdit,
return CFX_ByteString(sAppStream);
}
+CFX_ByteString GenerateIconAppStream(CPDF_IconFit& fit,
+ CPDF_Stream* pIconStream,
+ const CFX_FloatRect& rcIcon) {
+ if (rcIcon.IsEmpty() || !pIconStream)
+ return CFX_ByteString();
+
+ CPWL_Icon icon;
+ PWL_CREATEPARAM cp;
+ cp.dwFlags = PWS_VISIBLE;
+ icon.Create(cp);
+ icon.SetIconFit(&fit);
+ icon.SetPDFStream(pIconStream);
+ icon.Move(rcIcon, false, false);
+
+ CFX_ByteString sAlias = icon.GetImageAlias();
+ if (sAlias.GetLength() <= 0)
+ return CFX_ByteString();
+
+ CFX_FloatRect rcPlate = icon.GetClientRect();
+ CFX_Matrix mt = icon.GetImageMatrix().GetInverse();
+
+ float fHScale;
+ float fVScale;
+ std::tie(fHScale, fVScale) = icon.GetScale();
+
+ float fx;
+ float fy;
+ std::tie(fx, fy) = icon.GetImageOffset();
+
+ std::ostringstream str;
+ str << "q\n";
+ str << rcPlate.left << " " << rcPlate.bottom << " "
+ << rcPlate.right - rcPlate.left << " " << rcPlate.top - rcPlate.bottom
+ << " re W n\n";
+
+ str << fHScale << " 0 0 " << fVScale << " " << rcPlate.left + fx << " "
+ << rcPlate.bottom + fy << " cm\n";
+ str << mt.a << " " << mt.b << " " << mt.c << " " << mt.d << " " << mt.e << " "
+ << mt.f << " cm\n";
+
+ str << "0 g 0 G 1 w /" << sAlias << " Do\n"
+ << "Q\n";
+ icon.Destroy();
+
+ return CFX_ByteString(str);
+}
+
CFX_ByteString GetPushButtonAppStream(const CFX_FloatRect& rcBBox,
IPVT_FontMap* pFontMap,
CPDF_Stream* pIconStream,
@@ -756,54 +803,14 @@ CFX_ByteString GetPushButtonAppStream(const CFX_FloatRect& rcBBox,
}
std::ostringstream sTemp;
-
- if (!rcIcon.IsEmpty()) {
- CPWL_Icon icon;
- PWL_CREATEPARAM cp;
- cp.dwFlags = PWS_VISIBLE;
- icon.Create(cp);
- icon.SetIconFit(&IconFit);
- icon.SetPDFStream(pIconStream);
- icon.Move(rcIcon, false, false);
-
- CFX_ByteString sAlias = icon.GetImageAlias();
- if (sAlias.GetLength() > 0) {
- CFX_FloatRect rcPlate = icon.GetClientRect();
- CFX_Matrix mt = icon.GetImageMatrix().GetInverse();
-
- float fHScale = 1.0f;
- float fVScale = 1.0f;
- icon.GetScale(fHScale, fVScale);
-
- float fx = 0.0f;
- float fy = 0.0f;
- icon.GetImageOffset(fx, fy);
-
- if (icon.GetPDFStream()) {
- sTemp << "q\n";
- sTemp << rcPlate.left << " " << rcPlate.bottom << " "
- << rcPlate.right - rcPlate.left << " "
- << rcPlate.top - rcPlate.bottom << " re W n\n";
-
- sTemp << fHScale << " 0 0 " << fVScale << " " << rcPlate.left + fx
- << " " << rcPlate.bottom + fy << " cm\n";
- sTemp << mt.a << " " << mt.b << " " << mt.c << " " << mt.d << " "
- << mt.e << " " << mt.f << " cm\n";
-
- sTemp << "0 g 0 G 1 w /" << sAlias << " Do\n"
- << "Q\n";
- }
- }
- icon.Destroy();
- }
+ sTemp << GenerateIconAppStream(IconFit, pIconStream, rcIcon);
if (!rcLabel.IsEmpty()) {
pEdit->SetPlateRect(rcLabel);
CFX_ByteString sEdit =
GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, 0.0f), true, 0);
- if (sEdit.GetLength() > 0) {
+ if (sEdit.GetLength() > 0)
sTemp << "BT\n" << GetColorAppStream(crText, true) << sEdit << "ET\n";
- }
}
if (sTemp.tellp() <= 0)