1 diff -up inkscape-1.4_2024-10-09_e7c3feb100/src/extension/internal/pdfinput/pdf-parser.cpp.omv~ inkscape-1.4_2024-10-09_e7c3feb100/src/extension/internal/pdfinput/pdf-parser.cpp
2 --- inkscape-1.4_2024-10-09_e7c3feb100/src/extension/internal/pdfinput/pdf-parser.cpp.omv~ 2024-10-16 22:02:45.286278494 +0200
3 +++ inkscape-1.4_2024-10-09_e7c3feb100/src/extension/internal/pdfinput/pdf-parser.cpp 2024-10-16 23:49:12.890891669 +0200
4 @@ -810,7 +810,7 @@ void PdfParser::opSetExtGState(Object ar
6 if (_POPPLER_CALL_ARGS_DEREF(obj3, obj2.dictLookup, "G").isStream()) {
7 if (_POPPLER_CALL_ARGS_DEREF(obj4, obj3.streamGetDict()->lookup, "Group").isDict()) {
8 - GfxColorSpace *blendingColorSpace = nullptr;
9 + std::unique_ptr<GfxColorSpace> blendingColorSpace = nullptr;
10 GBool isolated = gFalse;
11 GBool knockout = gFalse;
12 if (!_POPPLER_CALL_ARGS_DEREF(obj5, obj4.dictLookup, "CS").isNull()) {
13 @@ -857,7 +857,7 @@ void PdfParser::opSetExtGState(Object ar
16 void PdfParser::doSoftMask(Object *str, GBool alpha,
17 - GfxColorSpace *blendingColorSpace,
18 + std::unique_ptr<GfxColorSpace> const &blendingColorSpace,
19 GBool isolated, GBool knockout,
20 Function *transferFunc, GfxColor *backdropColor) {
22 @@ -920,9 +920,9 @@ void PdfParser::doSoftMask(Object *str,
23 alpha, transferFunc, backdropColor);
26 - if (blendingColorSpace) {
27 - delete blendingColorSpace;
29 +// if (blendingColorSpace) {
30 +// delete blendingColorSpace;
35 @@ -936,41 +936,28 @@ void PdfParser::opSetRenderingIntent(Obj
38 * Get a newly allocated color space instance by CS operation argument.
40 - * Maintains a cache for named color spaces to avoid expensive re-parsing.
42 -GfxColorSpace *PdfParser::lookupColorSpaceCopy(Object &arg)
43 +std::unique_ptr<GfxColorSpace> PdfParser::lookupColorSpaceCopy(Object &arg)
45 assert(!arg.isNull());
46 - GfxColorSpace *colorSpace = nullptr;
48 if (char const *name = arg.isName() ? arg.getName() : nullptr) {
49 - auto const cache_name = std::to_string(formDepth) + "-" + name;
50 - if ((colorSpace = colorSpacesCache[cache_name].get())) {
51 - return colorSpace->copy();
54 Object obj = res->lookupColorSpace(name);
56 - colorSpace = GfxColorSpace::parse(res, &arg, nullptr, state);
57 + return GfxColorSpace::parse(res, &arg, nullptr, state);
59 - colorSpace = GfxColorSpace::parse(res, &obj, nullptr, state);
62 - if (colorSpace && colorSpace->getMode() != csPattern) {
63 - colorSpacesCache[cache_name].reset(colorSpace->copy());
64 + return GfxColorSpace::parse(res, &obj, nullptr, state);
67 // We were passed in an object directly.
68 - colorSpace = GfxColorSpace::parse(res, &arg, nullptr, state);
69 + return GfxColorSpace::parse(res, &arg, nullptr, state);
75 * Look up pattern/gradients from the GfxResource dictionary
77 -GfxPattern *PdfParser::lookupPattern(Object *obj, GfxState *state)
78 +std::unique_ptr<GfxPattern> PdfParser::lookupPattern(Object *obj, GfxState *state)
82 @@ -983,7 +970,7 @@ void PdfParser::opSetFillGray(Object arg
84 builder->beforeStateChange(state);
85 state->setFillPattern(nullptr);
86 - state->setFillColorSpace(new GfxDeviceGrayColorSpace());
87 + state->setFillColorSpace(std::unique_ptr<GfxColorSpace>(new GfxDeviceGrayColorSpace()));
88 color.c[0] = dblToCol(args[0].getNum());
89 state->setFillColor(&color);
90 builder->updateStyle(state);
91 @@ -995,7 +982,7 @@ void PdfParser::opSetStrokeGray(Object a
93 builder->beforeStateChange(state);
94 state->setStrokePattern(nullptr);
95 - state->setStrokeColorSpace(new GfxDeviceGrayColorSpace());
96 + state->setStrokeColorSpace(std::unique_ptr<GfxColorSpace>(new GfxDeviceGrayColorSpace()));
97 color.c[0] = dblToCol(args[0].getNum());
98 state->setStrokeColor(&color);
99 builder->updateStyle(state);
100 @@ -1008,7 +995,7 @@ void PdfParser::opSetFillCMYKColor(Objec
102 builder->beforeStateChange(state);
103 state->setFillPattern(nullptr);
104 - state->setFillColorSpace(new GfxDeviceCMYKColorSpace());
105 + state->setFillColorSpace(std::unique_ptr<GfxColorSpace>(new GfxDeviceCMYKColorSpace()));
106 for (i = 0; i < 4; ++i) {
107 color.c[i] = dblToCol(args[i].getNum());
109 @@ -1022,7 +1009,7 @@ void PdfParser::opSetStrokeCMYKColor(Obj
111 builder->beforeStateChange(state);
112 state->setStrokePattern(nullptr);
113 - state->setStrokeColorSpace(new GfxDeviceCMYKColorSpace());
114 + state->setStrokeColorSpace(std::unique_ptr<GfxColorSpace>(new GfxDeviceCMYKColorSpace()));
115 for (int i = 0; i < 4; ++i) {
116 color.c[i] = dblToCol(args[i].getNum());
118 @@ -1036,7 +1023,7 @@ void PdfParser::opSetFillRGBColor(Object
120 builder->beforeStateChange(state);
121 state->setFillPattern(nullptr);
122 - state->setFillColorSpace(new GfxDeviceRGBColorSpace());
123 + state->setFillColorSpace(std::unique_ptr<GfxColorSpace>(new GfxDeviceRGBColorSpace()));
124 for (int i = 0; i < 3; ++i) {
125 color.c[i] = dblToCol(args[i].getNum());
127 @@ -1049,7 +1036,7 @@ void PdfParser::opSetStrokeRGBColor(Obje
129 builder->beforeStateChange(state);
130 state->setStrokePattern(nullptr);
131 - state->setStrokeColorSpace(new GfxDeviceRGBColorSpace());
132 + state->setStrokeColorSpace(std::unique_ptr<GfxColorSpace>(new GfxDeviceRGBColorSpace()));
133 for (int i = 0; i < 3; ++i) {
134 color.c[i] = dblToCol(args[i].getNum());
136 @@ -1061,13 +1048,13 @@ void PdfParser::opSetStrokeRGBColor(Obje
137 void PdfParser::opSetFillColorSpace(Object args[], int numArgs)
139 assert(numArgs >= 1);
140 - GfxColorSpace *colorSpace = lookupColorSpaceCopy(args[0]);
141 + std::unique_ptr<GfxColorSpace> colorSpace = lookupColorSpaceCopy(args[0]);
142 builder->beforeStateChange(state);
143 state->setFillPattern(nullptr);
147 - state->setFillColorSpace(colorSpace);
148 + state->setFillColorSpace(colorSpace->copy());
149 colorSpace->getDefaultColor(&color);
150 state->setFillColor(&color);
151 builder->updateStyle(state);
152 @@ -1082,13 +1069,13 @@ void PdfParser::opSetStrokeColorSpace(Ob
153 assert(numArgs >= 1);
154 builder->beforeStateChange(state);
156 - GfxColorSpace *colorSpace = lookupColorSpaceCopy(args[0]);
157 + std::unique_ptr<GfxColorSpace> colorSpace = lookupColorSpaceCopy(args[0]);
159 state->setStrokePattern(nullptr);
163 - state->setStrokeColorSpace(colorSpace);
164 + state->setStrokeColorSpace(colorSpace->copy());
165 colorSpace->getDefaultColor(&color);
166 state->setStrokeColor(&color);
167 builder->updateStyle(state);
168 @@ -1152,7 +1139,7 @@ void PdfParser::opSetFillColorN(Object a
169 builder->updateStyle(state);
171 if (auto pattern = lookupPattern(&(args[numArgs - 1]), state)) {
172 - state->setFillPattern(pattern);
173 + state->setFillPattern(pattern->copy());
174 builder->updateStyle(state);
177 @@ -1195,7 +1182,7 @@ void PdfParser::opSetStrokeColorN(Object
178 builder->updateStyle(state);
180 if (auto pattern = lookupPattern(&(args[numArgs - 1]), state)) {
181 - state->setStrokePattern(pattern);
182 + state->setStrokePattern(pattern->copy());
183 builder->updateStyle(state);
186 @@ -1572,7 +1559,7 @@ void PdfParser::doShadingPatternFillFall
187 // TODO not good that numArgs is ignored but args[] is used:
188 void PdfParser::opShFill(Object args[], int /*numArgs*/)
190 - GfxShading *shading = nullptr;
191 + std::unique_ptr<GfxShading> shading = nullptr;
192 GfxPath *savedPath = nullptr;
193 bool savedState = false;
195 @@ -1608,19 +1595,19 @@ void PdfParser::opShFill(Object args[],
196 // do shading type-specific operations
197 switch (shading->getType()) {
198 case 1: // Function-based shading
199 - doFunctionShFill(static_cast<GfxFunctionShading *>(shading));
200 + doFunctionShFill(static_cast<GfxFunctionShading *>(shading.get()));
202 case 2: // Axial shading
203 case 3: // Radial shading
204 - builder->addClippedFill(shading, stateToAffine(state));
205 + builder->addClippedFill(shading.get(), stateToAffine(state));
207 case 4: // Free-form Gouraud-shaded triangle mesh
208 case 5: // Lattice-form Gouraud-shaded triangle mesh
209 - doGouraudTriangleShFill(static_cast<GfxGouraudTriangleShading *>(shading));
210 + doGouraudTriangleShFill(static_cast<GfxGouraudTriangleShading *>(shading.get()));
212 case 6: // Coons patch mesh
213 case 7: // Tensor-product patch mesh
214 - doPatchMeshShFill(static_cast<GfxPatchMeshShading *>(shading));
215 + doPatchMeshShFill(static_cast<GfxPatchMeshShading *>(shading.get()));
219 @@ -1630,7 +1617,6 @@ void PdfParser::opShFill(Object args[],
220 state->setPath(savedPath);
226 void PdfParser::doFunctionShFill(GfxFunctionShading *shading) {
227 @@ -2521,7 +2507,7 @@ void PdfParser::doImage(Object * /*ref*/
230 // get color space and color map
231 - GfxColorSpace *colorSpace;
232 + std::unique_ptr<GfxColorSpace> colorSpace;
233 _POPPLER_CALL_ARGS(obj1, dict->lookup, "ColorSpace");
236 @@ -2530,11 +2516,11 @@ void PdfParser::doImage(Object * /*ref*/
237 if (!obj1.isNull()) {
238 colorSpace = lookupColorSpaceCopy(obj1);
239 } else if (csMode == streamCSDeviceGray) {
240 - colorSpace = new GfxDeviceGrayColorSpace();
241 + colorSpace = std::unique_ptr<GfxColorSpace>(new GfxDeviceGrayColorSpace());
242 } else if (csMode == streamCSDeviceRGB) {
243 - colorSpace = new GfxDeviceRGBColorSpace();
244 + colorSpace = std::unique_ptr<GfxColorSpace>(new GfxDeviceRGBColorSpace());
245 } else if (csMode == streamCSDeviceCMYK) {
246 - colorSpace = new GfxDeviceCMYKColorSpace();
247 + colorSpace = std::unique_ptr<GfxColorSpace>(new GfxDeviceCMYKColorSpace());
249 colorSpace = nullptr;
251 @@ -2547,7 +2533,7 @@ void PdfParser::doImage(Object * /*ref*/
253 _POPPLER_CALL_ARGS(obj1, dict->lookup, "D");
255 - GfxImageColorMap *colorMap = new GfxImageColorMap(bits, &obj1, colorSpace);
256 + GfxImageColorMap *colorMap = new GfxImageColorMap(bits, &obj1, colorSpace->copy());
258 if (!colorMap->isOk()) {
260 @@ -2617,7 +2603,7 @@ void PdfParser::doImage(Object * /*ref*/
262 _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "CS");
264 - GfxColorSpace *maskColorSpace = lookupColorSpaceCopy(obj1);
265 + std::unique_ptr<GfxColorSpace> maskColorSpace = lookupColorSpaceCopy(obj1);
267 if (!maskColorSpace || maskColorSpace->getMode() != csDeviceGray) {
269 @@ -2627,7 +2613,7 @@ void PdfParser::doImage(Object * /*ref*/
271 _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "D");
273 - maskColorMap = new GfxImageColorMap(maskBits, &obj1, maskColorSpace);
274 + maskColorMap = new GfxImageColorMap(maskBits, &obj1, maskColorSpace->copy());
276 if (!maskColorMap->isOk()) {
278 @@ -2739,7 +2725,7 @@ void PdfParser::doForm(Object *str, doub
281 GBool transpGroup, isolated, knockout;
282 - GfxColorSpace *blendingColorSpace;
283 + std::unique_ptr<GfxColorSpace> blendingColorSpace;
284 Object matrixObj, bboxObj;
285 double m[6], bbox[4];
287 @@ -2831,14 +2817,11 @@ void PdfParser::doForm(Object *str, doub
288 doForm1(str, resDict, m, bbox, transpGroup, gFalse, blendingColorSpace, isolated, knockout);
291 - if (blendingColorSpace) {
292 - delete blendingColorSpace;
294 _POPPLER_FREE(resObj);
297 void PdfParser::doForm1(Object *str, Dict *resDict, double *matrix, double *bbox, GBool transpGroup, GBool softMask,
298 - GfxColorSpace *blendingColorSpace, GBool isolated, GBool knockout, GBool alpha,
299 + std::unique_ptr<GfxColorSpace> const &blendingColorSpace, GBool isolated, GBool knockout, GBool alpha,
300 Function *transferFunc, GfxColor *backdropColor)
303 @@ -2847,7 +2830,7 @@ void PdfParser::doForm1(Object *str, Dic
304 pushResources(resDict);
306 // Add a new container group before saving the state
307 - builder->startGroup(state, bbox, blendingColorSpace, isolated, knockout, softMask);
308 + builder->startGroup(state, bbox, blendingColorSpace.get(), isolated, knockout, softMask);
310 // save current graphics state
312 diff -up inkscape-1.4_2024-10-09_e7c3feb100/src/extension/internal/pdfinput/pdf-parser.h.omv~ inkscape-1.4_2024-10-09_e7c3feb100/src/extension/internal/pdfinput/pdf-parser.h
313 --- inkscape-1.4_2024-10-09_e7c3feb100/src/extension/internal/pdfinput/pdf-parser.h.omv~ 2024-10-16 22:03:47.306988617 +0200
314 +++ inkscape-1.4_2024-10-09_e7c3feb100/src/extension/internal/pdfinput/pdf-parser.h 2024-10-16 23:19:36.970279193 +0200
315 @@ -138,7 +138,7 @@ public:
316 void loadPatternColorProfiles(Dict *resources);
317 void loadColorProfile();
318 void loadColorSpaceProfile(GfxColorSpace *space, Object *obj);
319 - GfxPattern *lookupPattern(Object *obj, GfxState *state);
320 + std::unique_ptr<GfxPattern> lookupPattern(Object *obj, GfxState *state);
322 std::shared_ptr<CairoFontEngine> getFontEngine();
324 @@ -174,10 +174,7 @@ private:
326 OpHistoryEntry *operatorHistory; // list containing the last N operators
328 - //! Caches color spaces by name
329 - std::map<std::string, std::unique_ptr<GfxColorSpace>> colorSpacesCache;
331 - GfxColorSpace *lookupColorSpaceCopy(Object &);
332 + std::unique_ptr<GfxColorSpace> lookupColorSpaceCopy(Object &);
334 void setDefaultApproximationPrecision(); // init color deltas
335 void pushOperator(const char *name);
336 @@ -203,7 +200,7 @@ private:
337 void opSetMiterLimit(Object args[], int numArgs);
338 void opSetLineWidth(Object args[], int numArgs);
339 void opSetExtGState(Object args[], int numArgs);
340 - void doSoftMask(Object *str, GBool alpha, GfxColorSpace *blendingColorSpace, GBool isolated, GBool knockout,
341 + void doSoftMask(Object *str, GBool alpha, std::unique_ptr<GfxColorSpace> const &blendingColorSpace, GBool isolated, GBool knockout,
342 Function *transferFunc, GfxColor *backdropColor);
343 void opSetRenderingIntent(Object args[], int numArgs);
345 @@ -297,7 +294,7 @@ private:
346 void doForm(Object *str, double *offset = nullptr);
347 void doForm1(Object *str, Dict *resDict, double *matrix, double *bbox,
348 GBool transpGroup = gFalse, GBool softMask = gFalse,
349 - GfxColorSpace *blendingColorSpace = nullptr,
350 + std::unique_ptr<GfxColorSpace> const &blendingColorSpace = nullptr,
351 GBool isolated = gFalse, GBool knockout = gFalse,
352 GBool alpha = gFalse, Function *transferFunc = nullptr,
353 GfxColor *backdropColor = nullptr);