poppler/SplashOutputDev.cc | 6 +++--- splash/Splash.cc | 35 ++++++++++++----------------------- splash/Splash.h | 6 ++---- splash/SplashState.cc | 27 ++++----------------------- splash/SplashState.h | 9 ++++----- 5 files changed, 25 insertions(+), 58 deletions(-)
New commits: commit 1abe4a246adc4b655b7e2bf9a00c537d8d360329 Author: Albert Astals Cid <[email protected]> Date: Sat Aug 6 11:50:40 2022 +0200 Save copying data in SplashState::setLineDash diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc index c690b5d3..ac96db02 100644 --- a/poppler/SplashOutputDev.cc +++ b/poppler/SplashOutputDev.cc @@ -15,7 +15,7 @@ // // Copyright (C) 2005 Takashi Iwai <[email protected]> // Copyright (C) 2006 Stefan Schweizer <[email protected]> -// Copyright (C) 2006-2021 Albert Astals Cid <[email protected]> +// Copyright (C) 2006-2022 Albert Astals Cid <[email protected]> // Copyright (C) 2006 Krzysztof Kowalczyk <[email protected]> // Copyright (C) 2006 Scott Turner <[email protected]> // Copyright (C) 2007 Koji Otani <[email protected]> @@ -1404,7 +1404,7 @@ void SplashOutputDev::startPage(int pageNum, GfxState *state, XRef *xrefA) splash->setFillPattern(new SplashSolidColor(color)); splash->setLineCap(splashLineCapButt); splash->setLineJoin(splashLineJoinMiter); - splash->setLineDash(nullptr, 0, 0); + splash->setLineDash({}, 0); splash->setMiterLimit(10); splash->setFlatness(1); // the SA parameter supposedly defaults to false, but Acrobat @@ -1485,7 +1485,7 @@ void SplashOutputDev::updateLineDash(GfxState *state) dash[i] = 0; } } - splash->setLineDash(dash.data(), dashLength, (SplashCoord)dashStart); + splash->setLineDash(std::move(dash), (SplashCoord)dashStart); } void SplashOutputDev::updateFlatness(GfxState *state) diff --git a/splash/Splash.cc b/splash/Splash.cc index e3f6e9e9..aa5aaa38 100644 --- a/splash/Splash.cc +++ b/splash/Splash.cc @@ -1558,16 +1558,6 @@ SplashCoord Splash::getFlatness() return state->flatness; } -SplashCoord *Splash::getLineDash() -{ - return state->lineDash; -} - -int Splash::getLineDashLength() -{ - return state->lineDashLength; -} - SplashCoord Splash::getLineDashPhase() { return state->lineDashPhase; @@ -1690,9 +1680,9 @@ void Splash::setFlatness(SplashCoord flatness) } } -void Splash::setLineDash(SplashCoord *lineDash, int lineDashLength, SplashCoord lineDashPhase) +void Splash::setLineDash(std::vector<SplashCoord> &&lineDash, SplashCoord lineDashPhase) { - state->setLineDash(lineDash, lineDashLength, lineDashPhase); + state->setLineDash(std::move(lineDash), lineDashPhase); } void Splash::setStrokeAdjust(bool strokeAdjust) @@ -1898,7 +1888,7 @@ SplashError Splash::stroke(SplashPath *path) SplashCoord d1, d2, t1, t2, w; if (debugMode) { - printf("stroke [dash:%d] [width:%.2f]:\n", state->lineDashLength, (double)state->lineWidth); + printf("stroke [dash:%ld] [width:%.2f]:\n", state->lineDash.size(), (double)state->lineWidth); dumpPath(path); } opClipRes = splashClipAllOutside; @@ -1906,7 +1896,7 @@ SplashError Splash::stroke(SplashPath *path) return splashErrEmptyPath; } path2 = flattenPath(path, state->matrix, state->flatness); - if (state->lineDashLength > 0) { + if (!state->lineDash.empty()) { dPath = makeDashedPath(path2); delete path2; path2 = dPath; @@ -2175,12 +2165,11 @@ SplashPath *Splash::makeDashedPath(SplashPath *path) SplashCoord lineDashStartPhase, lineDashDist, segLen; SplashCoord x0, y0, x1, y1, xa, ya; bool lineDashStartOn, lineDashOn, newPath; - int lineDashStartIdx, lineDashIdx; int i, j, k; lineDashTotal = 0; - for (i = 0; i < state->lineDashLength; ++i) { - lineDashTotal += state->lineDash[i]; + for (SplashCoord dash : state->lineDash) { + lineDashTotal += dash; } // Acrobat simply draws nothing if the dash array is [0] if (lineDashTotal == 0) { @@ -2190,14 +2179,14 @@ SplashPath *Splash::makeDashedPath(SplashPath *path) i = splashFloor(lineDashStartPhase / lineDashTotal); lineDashStartPhase -= (SplashCoord)i * lineDashTotal; lineDashStartOn = true; - lineDashStartIdx = 0; + size_t lineDashStartIdx = 0; if (lineDashStartPhase > 0) { - while (lineDashStartIdx < state->lineDashLength && lineDashStartPhase >= state->lineDash[lineDashStartIdx]) { + while (lineDashStartIdx < state->lineDash.size() && lineDashStartPhase >= state->lineDash[lineDashStartIdx]) { lineDashStartOn = !lineDashStartOn; lineDashStartPhase -= state->lineDash[lineDashStartIdx]; ++lineDashStartIdx; } - if (unlikely(lineDashStartIdx == state->lineDashLength)) { + if (unlikely(lineDashStartIdx == state->lineDash.size())) { return new SplashPath(); } } @@ -2215,7 +2204,7 @@ SplashPath *Splash::makeDashedPath(SplashPath *path) // initialize the dash parameters lineDashOn = lineDashStartOn; - lineDashIdx = lineDashStartIdx; + size_t lineDashIdx = lineDashStartIdx; lineDashDist = state->lineDash[lineDashIdx] - lineDashStartPhase; // process each segment of the subpath @@ -2262,7 +2251,7 @@ SplashPath *Splash::makeDashedPath(SplashPath *path) // get the next entry in the dash array if (lineDashDist <= 0) { lineDashOn = !lineDashOn; - if (++lineDashIdx == state->lineDashLength) { + if (++lineDashIdx == state->lineDash.size()) { lineDashIdx = 0; } lineDashDist = state->lineDash[lineDashIdx]; @@ -5864,7 +5853,7 @@ SplashPath *Splash::makeStrokePath(SplashPath *path, SplashCoord w, bool flatten if (flatten) { pathIn = flattenPath(path, state->matrix, state->flatness); - if (state->lineDashLength > 0) { + if (!state->lineDash.empty()) { dashPath = makeDashedPath(pathIn); delete pathIn; pathIn = dashPath; diff --git a/splash/Splash.h b/splash/Splash.h index 68f27ae6..e13be54c 100644 --- a/splash/Splash.h +++ b/splash/Splash.h @@ -12,7 +12,7 @@ // under GPL version 2 or later // // Copyright (C) 2005 Marco Pesenti Gritti <[email protected]> -// Copyright (C) 2007, 2011, 2018, 2019, 2021 Albert Astals Cid <[email protected]> +// Copyright (C) 2007, 2011, 2018, 2019, 2021, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2010-2013, 2015 Thomas Freitag <[email protected]> // Copyright (C) 2010 Christian Feuersänger <[email protected]> // Copyright (C) 2012, 2017 Adrian Johnson <[email protected]> @@ -105,8 +105,6 @@ public: int getLineJoin(); SplashCoord getMiterLimit(); SplashCoord getFlatness(); - SplashCoord *getLineDash(); - int getLineDashLength(); SplashCoord getLineDashPhase(); bool getStrokeAdjust(); SplashClip *getClip(); @@ -133,7 +131,7 @@ public: void setMiterLimit(SplashCoord miterLimit); void setFlatness(SplashCoord flatness); // the <lineDash> array will be copied - void setLineDash(SplashCoord *lineDash, int lineDashLength, SplashCoord lineDashPhase); + void setLineDash(std::vector<SplashCoord> &&lineDash, SplashCoord lineDashPhase); void setStrokeAdjust(bool strokeAdjust); // NB: uses transformed coordinates. void clipResetToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1); diff --git a/splash/SplashState.cc b/splash/SplashState.cc index 89400d37..39f3c530 100644 --- a/splash/SplashState.cc +++ b/splash/SplashState.cc @@ -13,7 +13,7 @@ // // Copyright (C) 2009, 2011, 2012, 2015 Thomas Freitag <[email protected]> // Copyright (C) 2017 Adrian Johnson <[email protected]> -// Copyright (C) 2019, 2021 Albert Astals Cid <[email protected]> +// Copyright (C) 2019, 2021, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2020 Peter Wang <[email protected]> // // To see a description of the changes please see the Changelog file that @@ -64,8 +64,6 @@ SplashState::SplashState(int width, int height, bool vectorAntialias, SplashScre lineJoin = splashLineJoinMiter; miterLimit = 10; flatness = 1; - lineDash = nullptr; - lineDashLength = 0; lineDashPhase = 0; strokeAdjust = false; clip = new SplashClip(0, 0, width - 0.001, height - 0.001, vectorAntialias); @@ -119,8 +117,6 @@ SplashState::SplashState(int width, int height, bool vectorAntialias, SplashScre lineJoin = splashLineJoinMiter; miterLimit = 10; flatness = 1; - lineDash = nullptr; - lineDashLength = 0; lineDashPhase = 0; strokeAdjust = false; clip = new SplashClip(0, 0, width - 0.001, height - 0.001, vectorAntialias); @@ -165,14 +161,7 @@ SplashState::SplashState(const SplashState *state) lineJoin = state->lineJoin; miterLimit = state->miterLimit; flatness = state->flatness; - if (state->lineDash) { - lineDashLength = state->lineDashLength; - lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord)); - memcpy(lineDash, state->lineDash, lineDashLength * sizeof(SplashCoord)); - } else { - lineDash = nullptr; - lineDashLength = 0; - } + lineDash = state->lineDash; lineDashPhase = state->lineDashPhase; strokeAdjust = state->strokeAdjust; clip = state->clip->copy(); @@ -203,7 +192,6 @@ SplashState::~SplashState() delete strokePattern; delete fillPattern; delete screen; - gfree(lineDash); delete clip; if (deleteSoftMask && softMask) { delete softMask; @@ -228,16 +216,9 @@ void SplashState::setScreen(SplashScreen *screenA) screen = screenA; } -void SplashState::setLineDash(SplashCoord *lineDashA, int lineDashLengthA, SplashCoord lineDashPhaseA) +void SplashState::setLineDash(std::vector<SplashCoord> &&lineDashA, SplashCoord lineDashPhaseA) { - gfree(lineDash); - lineDashLength = lineDashLengthA; - if (lineDashLength > 0) { - lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord)); - memcpy(lineDash, lineDashA, lineDashLength * sizeof(SplashCoord)); - } else { - lineDash = nullptr; - } + lineDash = lineDashA; lineDashPhase = lineDashPhaseA; } diff --git a/splash/SplashState.h b/splash/SplashState.h index a7e4f686..009c1f14 100644 --- a/splash/SplashState.h +++ b/splash/SplashState.h @@ -13,7 +13,7 @@ // // Copyright (C) 2011, 2012, 2015 Thomas Freitag <[email protected]> // Copyright (C) 2017 Adrian Johnson <[email protected]> -// Copyright (C) 2018, 2021 Albert Astals Cid <[email protected]> +// Copyright (C) 2018, 2021, 2022 Albert Astals Cid <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -74,8 +74,8 @@ public: // Set the screen. This does not copy <screenA>. void setScreen(SplashScreen *screenA); - // Set the line dash pattern. This copies the <lineDashA> array. - void setLineDash(SplashCoord *lineDashA, int lineDashLengthA, SplashCoord lineDashPhaseA); + // Set the line dash pattern. + void setLineDash(std::vector<SplashCoord> &&lineDashA, SplashCoord lineDashPhaseA); // Set the soft mask bitmap. void setSoftMask(SplashBitmap *softMaskA); @@ -106,8 +106,7 @@ private: int lineJoin; SplashCoord miterLimit; SplashCoord flatness; - SplashCoord *lineDash; - int lineDashLength; + std::vector<SplashCoord> lineDash; SplashCoord lineDashPhase; bool strokeAdjust; SplashClip *clip;
