Coalesce redundant path points.
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 <npm@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 798b9d4..d8b176b 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -1440,6 +1440,15 @@
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) {