summaryrefslogtreecommitdiff
path: root/fpdfsdk/pdfwindow/cpwl_utils.cpp
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2017-06-29 11:18:49 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-06-29 15:40:59 +0000
commitf1eae2c37cb4bbf7a536cf251706147bbac51880 (patch)
tree8eead543163dddefc63a518d9d44b5ca1ee49875 /fpdfsdk/pdfwindow/cpwl_utils.cpp
parenta0b48aa8043be95e5c6b602e0e261fb163282536 (diff)
downloadpdfium-f1eae2c37cb4bbf7a536cf251706147bbac51880.tar.xz
Converted low-hanging cpwl classes in CFX_ByteTextBuf to ostringstream.
Bug: pdfium:731 Change-Id: I3faf5a4ec4b2af6145348e526f39ccbc2055e62e Reviewed-on: https://pdfium-review.googlesource.com/7050 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/pdfwindow/cpwl_utils.cpp')
-rw-r--r--fpdfsdk/pdfwindow/cpwl_utils.cpp160
1 files changed, 81 insertions, 79 deletions
diff --git a/fpdfsdk/pdfwindow/cpwl_utils.cpp b/fpdfsdk/pdfwindow/cpwl_utils.cpp
index 0a3591923a..ce263eff8b 100644
--- a/fpdfsdk/pdfwindow/cpwl_utils.cpp
+++ b/fpdfsdk/pdfwindow/cpwl_utils.cpp
@@ -8,6 +8,7 @@
#include <algorithm>
#include <memory>
+#include <sstream>
#include "core/fpdfdoc/cpvt_word.h"
#include "core/fxge/cfx_graphstatedata.h"
@@ -63,7 +64,7 @@ CFX_ByteString CPWL_Utils::GetAP_Check(const CFX_FloatRect& crBBox) {
}
}
- CFX_ByteTextBuf csAP;
+ std::ostringstream csAP;
csAP << pts[0][0].x << " " << pts[0][0].y << " m\n";
for (size_t i = 0; i < FX_ArraySize(pts); ++i) {
@@ -81,11 +82,11 @@ CFX_ByteString CPWL_Utils::GetAP_Check(const CFX_FloatRect& crBBox) {
<< pts[nNext][0].y << " c\n";
}
- return csAP.MakeString();
+ return CFX_ByteString(csAP);
}
CFX_ByteString CPWL_Utils::GetAP_Circle(const CFX_FloatRect& crBBox) {
- CFX_ByteTextBuf csAP;
+ std::ostringstream csAP;
float fWidth = crBBox.right - crBBox.left;
float fHeight = crBBox.top - crBBox.bottom;
@@ -123,22 +124,22 @@ CFX_ByteString CPWL_Utils::GetAP_Circle(const CFX_FloatRect& crBBox) {
csAP << pt4.x - px * FX_BEZIER << " " << pt4.y << " " << pt1.x << " "
<< pt1.y - py * FX_BEZIER << " " << pt1.x << " " << pt1.y << " c\n";
- return csAP.MakeString();
+ return CFX_ByteString(csAP);
}
CFX_ByteString CPWL_Utils::GetAP_Cross(const CFX_FloatRect& crBBox) {
- CFX_ByteTextBuf csAP;
+ std::ostringstream csAP;
csAP << crBBox.left << " " << crBBox.top << " m\n";
csAP << crBBox.right << " " << crBBox.bottom << " l\n";
csAP << crBBox.left << " " << crBBox.bottom << " m\n";
csAP << crBBox.right << " " << crBBox.top << " l\n";
- return csAP.MakeString();
+ return CFX_ByteString(csAP);
}
CFX_ByteString CPWL_Utils::GetAP_Diamond(const CFX_FloatRect& crBBox) {
- CFX_ByteTextBuf csAP;
+ std::ostringstream csAP;
float fWidth = crBBox.right - crBBox.left;
float fHeight = crBBox.top - crBBox.bottom;
@@ -154,11 +155,11 @@ CFX_ByteString CPWL_Utils::GetAP_Diamond(const CFX_FloatRect& crBBox) {
csAP << pt4.x << " " << pt4.y << " l\n";
csAP << pt1.x << " " << pt1.y << " l\n";
- return csAP.MakeString();
+ return CFX_ByteString(csAP);
}
CFX_ByteString CPWL_Utils::GetAP_Square(const CFX_FloatRect& crBBox) {
- CFX_ByteTextBuf csAP;
+ std::ostringstream csAP;
csAP << crBBox.left << " " << crBBox.top << " m\n";
csAP << crBBox.right << " " << crBBox.top << " l\n";
@@ -166,11 +167,11 @@ CFX_ByteString CPWL_Utils::GetAP_Square(const CFX_FloatRect& crBBox) {
csAP << crBBox.left << " " << crBBox.bottom << " l\n";
csAP << crBBox.left << " " << crBBox.top << " l\n";
- return csAP.MakeString();
+ return CFX_ByteString(csAP);
}
CFX_ByteString CPWL_Utils::GetAP_Star(const CFX_FloatRect& crBBox) {
- CFX_ByteTextBuf csAP;
+ std::ostringstream csAP;
float fRadius = (crBBox.top - crBBox.bottom) / (1 + (float)cos(FX_PI / 5.0f));
CFX_PointF ptCenter = CFX_PointF((crBBox.left + crBBox.right) / 2.0f,
@@ -197,12 +198,12 @@ CFX_ByteString CPWL_Utils::GetAP_Star(const CFX_FloatRect& crBBox) {
csAP << px[nNext] << " " << py[nNext] << " l\n";
}
- return csAP.MakeString();
+ return CFX_ByteString(csAP);
}
CFX_ByteString CPWL_Utils::GetAP_HalfCircle(const CFX_FloatRect& crBBox,
float fRotate) {
- CFX_ByteTextBuf csAP;
+ std::ostringstream csAP;
float fWidth = crBBox.right - crBBox.left;
float fHeight = crBBox.top - crBBox.bottom;
@@ -232,7 +233,7 @@ CFX_ByteString CPWL_Utils::GetAP_HalfCircle(const CFX_FloatRect& crBBox,
csAP << pt2.x + px * FX_BEZIER << " " << pt2.y << " " << pt3.x << " "
<< pt3.y + py * FX_BEZIER << " " << pt3.x << " " << pt3.y << " c\n";
- return csAP.MakeString();
+ return CFX_ByteString(csAP);
}
CFX_FloatRect CPWL_Utils::InflateRect(const CFX_FloatRect& rcRect,
@@ -271,7 +272,7 @@ CFX_FloatRect CPWL_Utils::ScaleRect(const CFX_FloatRect& rcRect, float fScale) {
CFX_ByteString CPWL_Utils::GetRectFillAppStream(const CFX_FloatRect& rect,
const CPWL_Color& color) {
- CFX_ByteTextBuf sAppStream;
+ std::ostringstream sAppStream;
CFX_ByteString sColor = GetColorAppStream(color, true);
if (sColor.GetLength() > 0) {
sAppStream << "q\n" << sColor;
@@ -280,17 +281,16 @@ CFX_ByteString CPWL_Utils::GetRectFillAppStream(const CFX_FloatRect& rect,
<< " re f\nQ\n";
}
- return sAppStream.MakeString();
+ return CFX_ByteString(sAppStream);
}
CFX_ByteString CPWL_Utils::GetCircleFillAppStream(const CFX_FloatRect& rect,
const CPWL_Color& color) {
- CFX_ByteTextBuf sAppStream;
+ std::ostringstream sAppStream;
CFX_ByteString sColor = GetColorAppStream(color, true);
- if (sColor.GetLength() > 0) {
+ if (sColor.GetLength() > 0)
sAppStream << "q\n" << sColor << CPWL_Utils::GetAP_Circle(rect) << "f\nQ\n";
- }
- return sAppStream.MakeString();
+ return CFX_ByteString(sAppStream);
}
CFX_FloatRect CPWL_Utils::GetCenterSquare(const CFX_FloatRect& rect) {
@@ -514,7 +514,7 @@ CFX_ByteString CPWL_Utils::GetPushButtonAppStream(const CFX_FloatRect& rcBBox,
break;
}
- CFX_ByteTextBuf sAppStream, sTemp;
+ std::ostringstream sTemp;
if (!rcIcon.IsEmpty()) {
Icon.Move(rcIcon, false, false);
@@ -533,19 +533,21 @@ CFX_ByteString CPWL_Utils::GetPushButtonAppStream(const CFX_FloatRect& rcBBox,
}
}
- if (sTemp.GetSize() > 0) {
- sAppStream << "q\n"
- << rcBBox.left << " " << rcBBox.bottom << " "
- << rcBBox.right - rcBBox.left << " "
- << rcBBox.top - rcBBox.bottom << " re W n\n";
- sAppStream << sTemp << "Q\n";
- }
- return sAppStream.MakeString();
+ if (sTemp.tellp() <= 0)
+ return CFX_ByteString();
+
+ std::ostringstream sAppStream;
+ sAppStream << "q\n"
+ << rcBBox.left << " " << rcBBox.bottom << " "
+ << rcBBox.right - rcBBox.left << " " << rcBBox.top - rcBBox.bottom
+ << " re W n\n";
+ sAppStream << sTemp.str().c_str() << "Q\n";
+ return CFX_ByteString(sAppStream);
}
CFX_ByteString CPWL_Utils::GetColorAppStream(const CPWL_Color& color,
const bool& bFillOrStroke) {
- CFX_ByteTextBuf sColorStream;
+ std::ostringstream sColorStream;
switch (color.nColorType) {
case COLORTYPE_RGB:
@@ -564,7 +566,7 @@ CFX_ByteString CPWL_Utils::GetColorAppStream(const CPWL_Color& color,
break;
}
- return sColorStream.MakeString();
+ return CFX_ByteString(sColorStream);
}
CFX_ByteString CPWL_Utils::GetBorderAppStream(const CFX_FloatRect& rect,
@@ -574,7 +576,7 @@ CFX_ByteString CPWL_Utils::GetBorderAppStream(const CFX_FloatRect& rect,
const CPWL_Color& crRightBottom,
BorderStyle nStyle,
const CPWL_Dash& dash) {
- CFX_ByteTextBuf sAppStream;
+ std::ostringstream sAppStream;
CFX_ByteString sColor;
float fLeft = rect.left;
@@ -680,7 +682,7 @@ CFX_ByteString CPWL_Utils::GetBorderAppStream(const CFX_FloatRect& rect,
sAppStream << "Q\n";
}
- return sAppStream.MakeString();
+ return CFX_ByteString(sAppStream);
}
CFX_ByteString CPWL_Utils::GetCircleBorderAppStream(
@@ -691,7 +693,7 @@ CFX_ByteString CPWL_Utils::GetCircleBorderAppStream(
const CPWL_Color& crRightBottom,
BorderStyle nStyle,
const CPWL_Dash& dash) {
- CFX_ByteTextBuf sAppStream;
+ std::ostringstream sAppStream;
CFX_ByteString sColor;
if (fWidth > 0.0f) {
@@ -793,61 +795,61 @@ CFX_ByteString CPWL_Utils::GetCircleBorderAppStream(
sAppStream << "Q\n";
}
- return sAppStream.MakeString();
+ return CFX_ByteString(sAppStream);
}
CFX_ByteString CPWL_Utils::GetAppStream_Check(const CFX_FloatRect& rcBBox,
const CPWL_Color& crText) {
- CFX_ByteTextBuf sAP;
+ std::ostringstream sAP;
sAP << "q\n"
<< CPWL_Utils::GetColorAppStream(crText, true)
<< CPWL_Utils::GetAP_Check(rcBBox) << "f\nQ\n";
- return sAP.MakeString();
+ return CFX_ByteString(sAP);
}
CFX_ByteString CPWL_Utils::GetAppStream_Circle(const CFX_FloatRect& rcBBox,
const CPWL_Color& crText) {
- CFX_ByteTextBuf sAP;
+ std::ostringstream sAP;
sAP << "q\n"
<< CPWL_Utils::GetColorAppStream(crText, true)
<< CPWL_Utils::GetAP_Circle(rcBBox) << "f\nQ\n";
- return sAP.MakeString();
+ return CFX_ByteString(sAP);
}
CFX_ByteString CPWL_Utils::GetAppStream_Cross(const CFX_FloatRect& rcBBox,
const CPWL_Color& crText) {
- CFX_ByteTextBuf sAP;
+ std::ostringstream sAP;
sAP << "q\n"
<< CPWL_Utils::GetColorAppStream(crText, false)
<< CPWL_Utils::GetAP_Cross(rcBBox) << "S\nQ\n";
- return sAP.MakeString();
+ return CFX_ByteString(sAP);
}
CFX_ByteString CPWL_Utils::GetAppStream_Diamond(const CFX_FloatRect& rcBBox,
const CPWL_Color& crText) {
- CFX_ByteTextBuf sAP;
+ std::ostringstream sAP;
sAP << "q\n1 w\n"
<< CPWL_Utils::GetColorAppStream(crText, true)
<< CPWL_Utils::GetAP_Diamond(rcBBox) << "f\nQ\n";
- return sAP.MakeString();
+ return CFX_ByteString(sAP);
}
CFX_ByteString CPWL_Utils::GetAppStream_Square(const CFX_FloatRect& rcBBox,
const CPWL_Color& crText) {
- CFX_ByteTextBuf sAP;
+ std::ostringstream sAP;
sAP << "q\n"
<< CPWL_Utils::GetColorAppStream(crText, true)
<< CPWL_Utils::GetAP_Square(rcBBox) << "f\nQ\n";
- return sAP.MakeString();
+ return CFX_ByteString(sAP);
}
CFX_ByteString CPWL_Utils::GetAppStream_Star(const CFX_FloatRect& rcBBox,
const CPWL_Color& crText) {
- CFX_ByteTextBuf sAP;
+ std::ostringstream sAP;
sAP << "q\n"
<< CPWL_Utils::GetColorAppStream(crText, true)
<< CPWL_Utils::GetAP_Star(rcBBox) << "f\nQ\n";
- return sAP.MakeString();
+ return CFX_ByteString(sAP);
}
CFX_ByteString CPWL_Utils::GetCheckBoxAppStream(const CFX_FloatRect& rcBBox,
@@ -893,42 +895,42 @@ CFX_ByteString CPWL_Utils::GetRadioButtonAppStream(const CFX_FloatRect& rcBBox,
}
CFX_ByteString CPWL_Utils::GetDropButtonAppStream(const CFX_FloatRect& rcBBox) {
- CFX_ByteTextBuf sAppStream;
-
- if (!rcBBox.IsEmpty()) {
+ if (rcBBox.IsEmpty())
+ return CFX_ByteString();
+
+ std::ostringstream sAppStream;
+ sAppStream << "q\n"
+ << CPWL_Utils::GetColorAppStream(
+ CPWL_Color(COLORTYPE_RGB, 220.0f / 255.0f, 220.0f / 255.0f,
+ 220.0f / 255.0f),
+ true)
+ << rcBBox.left << " " << rcBBox.bottom << " "
+ << rcBBox.right - rcBBox.left << " " << rcBBox.top - rcBBox.bottom
+ << " re f\n"
+ << "Q\n";
+
+ sAppStream << "q\n"
+ << CPWL_Utils::GetBorderAppStream(
+ rcBBox, 2, CPWL_Color(COLORTYPE_GRAY, 0),
+ CPWL_Color(COLORTYPE_GRAY, 1),
+ CPWL_Color(COLORTYPE_GRAY, 0.5), BorderStyle::BEVELED,
+ CPWL_Dash(3, 0, 0))
+ << "Q\n";
+
+ CFX_PointF ptCenter = CFX_PointF((rcBBox.left + rcBBox.right) / 2,
+ (rcBBox.top + rcBBox.bottom) / 2);
+ if (IsFloatBigger(rcBBox.right - rcBBox.left, 6) &&
+ IsFloatBigger(rcBBox.top - rcBBox.bottom, 6)) {
sAppStream << "q\n"
- << CPWL_Utils::GetColorAppStream(
- CPWL_Color(COLORTYPE_RGB, 220.0f / 255.0f,
- 220.0f / 255.0f, 220.0f / 255.0f),
- true);
- sAppStream << rcBBox.left << " " << rcBBox.bottom << " "
- << rcBBox.right - rcBBox.left << " "
- << rcBBox.top - rcBBox.bottom << " re f\n";
- sAppStream << "Q\n";
-
- sAppStream << "q\n"
- << CPWL_Utils::GetBorderAppStream(
- rcBBox, 2, CPWL_Color(COLORTYPE_GRAY, 0),
- CPWL_Color(COLORTYPE_GRAY, 1),
- CPWL_Color(COLORTYPE_GRAY, 0.5), BorderStyle::BEVELED,
- CPWL_Dash(3, 0, 0))
+ << " 0 g\n"
+ << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n"
+ << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n"
+ << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n"
+ << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n"
<< "Q\n";
-
- CFX_PointF ptCenter = CFX_PointF((rcBBox.left + rcBBox.right) / 2,
- (rcBBox.top + rcBBox.bottom) / 2);
- if (IsFloatBigger(rcBBox.right - rcBBox.left, 6) &&
- IsFloatBigger(rcBBox.top - rcBBox.bottom, 6)) {
- sAppStream << "q\n"
- << " 0 g\n";
- sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n";
- sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n";
- sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n";
- sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n";
- sAppStream << "Q\n";
- }
}
- return sAppStream.MakeString();
+ return CFX_ByteString(sAppStream);
}
void CPWL_Utils::DrawFillRect(CFX_RenderDevice* pDevice,