From 844d79e853074c99b7e5e64e051f1e1236c1723e Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Fri, 16 Feb 2018 03:46:26 +0000 Subject: Improve performance of writing path floats. This CL copies the SkPDF code to convert floats into strings when writing back to PDF files. Change-Id: I8f8af3924a07aa67f93b9d951af1eef5d2c705db Reviewed-on: https://pdfium-review.googlesource.com/21990 Commit-Queue: dsinclair Reviewed-by: Lei Zhang Reviewed-by: Hal Canary --- core/fpdfapi/edit/DEPS | 3 +++ core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 9 ++++++++- core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp | 11 ++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 core/fpdfapi/edit/DEPS (limited to 'core/fpdfapi') diff --git a/core/fpdfapi/edit/DEPS b/core/fpdfapi/edit/DEPS new file mode 100644 index 0000000000..8a4c38c44b --- /dev/null +++ b/core/fpdfapi/edit/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + '+third_party/skia_shared', +] diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index 8a08a849cc..a2d4d4f125 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -25,6 +25,7 @@ #include "core/fpdfapi/parser/cpdf_reference.h" #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fpdfapi/parser/fpdf_parser_decode.h" +#include "third_party/skia_shared/SkFloatToDecimal.h" namespace { @@ -221,7 +222,13 @@ void CPDF_PageContentGenerator::ProcessPath(std::ostringstream* buf, for (size_t i = 0; i < pPoints.size(); i++) { if (i > 0) *buf << " "; - *buf << pPoints[i].m_Point.x << " " << pPoints[i].m_Point.y; + + char buffer[kMaximumSkFloatToDecimalLength]; + unsigned size = SkFloatToDecimal(pPoints[i].m_Point.x, buffer); + buf->write(buffer, size) << " "; + size = SkFloatToDecimal(pPoints[i].m_Point.y, buffer); + buf->write(buffer, size); + FXPT_TYPE pointType = pPoints[i].m_Type; if (pointType == FXPT_TYPE::MoveTo) { *buf << " m"; diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp index a0db869410..403bd6ab03 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp @@ -103,8 +103,9 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessPath) { std::ostringstream buf; TestProcessPath(&generator, &buf, pPathObj.get()); EXPECT_EQ( - "q 1 0 0 1 0 0 cm 3.102 4.67 m 5.45 0.29 l 4.24 3.15 4.65 2.98 3.456 0.24" - " c 10.6 11.15 l 11 12.5 l 11.46 12.67 11.84 12.96 12 13.64 c h f Q\n", + "q 1 0 0 1 0 0 cm 3.102 4.6700001 m 5.4499998 .28999999 l 4.2399998 " + "3.1500001 4.65 2.98 3.456 0.24 c 10.6000004 11.1499996 l 11 12.5 " + "l 11.46 12.6700001 11.84 12.96 12 13.64 c h f Q\n", ByteString(buf)); } @@ -312,8 +313,8 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessFormWithPath) { pDoc->CreateNewDoc(); auto pDict = pdfium::MakeUnique(); const char content[] = - "q 1 0 0 1 0 0 cm 3.102 4.67 m 5.45 0.29 l 4.24 3.15 4.65 2.98 3.456 " - "0.24 c 3.102 4.67 l h f Q\n"; + "q 1 0 0 1 0 0 cm 3.102 4.6700001 m 5.4500012 .28999999 " + "l 4.2399998 3.1499999 4.65 2.98 3.456 0.24 c 3.102 4.6700001 l h f Q\n"; size_t buf_len = FX_ArraySize(content); std::unique_ptr buf(FX_Alloc(uint8_t, buf_len)); memcpy(buf.get(), content, buf_len); @@ -329,5 +330,5 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessFormWithPath) { CPDF_PageContentGenerator generator(pTestForm.get()); std::ostringstream process_buf; generator.ProcessPageObjects(&process_buf); - EXPECT_EQ(content, ByteString(process_buf)); + EXPECT_STREQ(content, ByteString(process_buf).c_str()); } -- cgit v1.2.3