From 78616574cedcb52cce8a25bd684bf9638a87de7a Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 16 Mar 2017 22:24:11 -0700 Subject: Coalesce redundant path points. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There exists PDFs with many redundant path points, and keeping track of them all uses a lot of memory. BUG=chromium:679353 Change-Id: I514610cbba181658b6396e30f5bf58a3661359f5 Reviewed-on: https://pdfium-review.googlesource.com/3110 Reviewed-by: Nicolás Peña Commit-Queue: Lei Zhang --- core/fpdfapi/page/cpdf_streamcontentparser.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'core/fpdfapi/page') diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 798b9d4f4e..d8b176b288 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -1440,6 +1440,15 @@ void CPDF_StreamContentParser::AddPathPoint(float x, float y, FXPT_TYPE type, bool close) { + // If the path point is the same move as the previous one and neither of them + // closes the path, then just skip it. + if (!close && type == FXPT_TYPE::MoveTo && m_PathPointCount && + !m_pPathPoints[m_PathPointCount - 1].m_CloseFigure && + m_pPathPoints[m_PathPointCount - 1].m_Type == type && + m_PathCurrentX == x && m_PathCurrentY == y) { + return; + } + m_PathCurrentX = x; m_PathCurrentY = y; if (type == FXPT_TYPE::MoveTo && !close) { -- cgit v1.2.3