From 2eb1a705c243b2d5ab912268dd453f5ade075b6f Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Thu, 9 Feb 2017 18:17:33 -0500 Subject: Add line width option for stroking paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG=pdfium:661 Change-Id: Ie1dc82a1323a35ebbd63a5b7b8f8c95f9a5325fe Reviewed-on: https://pdfium-review.googlesource.com/2613 Reviewed-by: Tom Sepez Commit-Queue: Nicolás Peña --- core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 4 ++++ core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+) (limited to 'core/fpdfapi/edit') diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index a5bd741cc0..9de97ee718 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -192,6 +192,7 @@ void CPDF_PageContentGenerator::ProcessPath(CFX_ByteTextBuf* buf, // values cannot be obtained. The method also adds an external graphics // dictionary, as described in Section 4.3.4. // "rg" sets the fill color, "RG" sets the stroke color (using DefaultRGB) +// "w" sets the stroke line width. // "ca" sets the fill alpha, "CA" sets the stroke alpha. // "q" saves the graphics state, so that the settings can later be reversed void CPDF_PageContentGenerator::ProcessGraphics(CFX_ByteTextBuf* buf, @@ -207,6 +208,9 @@ void CPDF_PageContentGenerator::ProcessGraphics(CFX_ByteTextBuf* buf, *buf << strokeColor[0] << " " << strokeColor[1] << " " << strokeColor[2] << " RG "; } + FX_FLOAT lineWidth = pPageObj->m_GraphState.GetLineWidth(); + if (lineWidth != 1.0f) + *buf << lineWidth << " w "; GraphicsData graphD; graphD.fillAlpha = pPageObj->m_GeneralState.GetFillAlpha(); diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp index 3267f5218c..4846b1bd3c 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp @@ -167,4 +167,17 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) { ASSERT_TRUE(externalGS); EXPECT_EQ(0.5f, externalGS->GetNumberFor("ca")); EXPECT_EQ(0.8f, externalGS->GetNumberFor("CA")); + + // Same path, now with a stroke. + pPathObj->m_GraphState.SetLineWidth(10.5f); + buf.Clear(); + TestProcessPath(&generator, &buf, pPathObj.get()); + CFX_ByteString pathString2 = buf.MakeString(); + EXPECT_EQ("q 0.501961 0.701961 0.34902 rg 1 0.901961 0 RG 10.5 w /", + pathString2.Left(55)); + EXPECT_EQ(" gs 1 2 m 3 4 l 5 6 l h B Q\n", pathString2.Right(28)); + // Compare with the previous (should use same dictionary for gs) + EXPECT_EQ(pathString.GetLength() + 7, pathString2.GetLength()); + EXPECT_EQ(pathString.Mid(48, pathString.GetLength() - 76), + pathString2.Mid(55, pathString2.GetLength() - 83)); } -- cgit v1.2.3