Author: jghali
Date: Thu May 16 11:55:24 2019
New Revision: 22978

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22978
Log:
#15685: Multi-step gradient incorrectly imported from PDF

Modified:
    trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp

Modified: trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=22978&path=/trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp      (original)
+++ trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp      Thu May 16 
11:55:24 2019
@@ -1755,33 +1755,35 @@
                StitchingFunction *stitchingFunc = (StitchingFunction*)func;
                const double *bounds = stitchingFunc->getBounds();
                int num_funcs = stitchingFunc->getNumFuncs();
+               double domain_min = stitchingFunc->getDomainMin(0);
+               double domain_max = stitchingFunc->getDomainMax(0);
+               if (fabs(domain_max - domain_min) < 1e-6)
+               {
+                       domain_min = 0.0;
+                       domain_max = 1.0;
+               }
                // Add stops from all the stitched functions
-               for ( int i = 0 ; i < num_funcs ; i++ )
+               for (int i = 0 ; i <= num_funcs ; i++)
                {
                        GfxColor temp;
-                       ((GfxAxialShading*)shading)->getColor(bounds[i], &temp);
+                       shading->getColor(bounds[i], &temp);
                        QString stopColor = getColor(color_space, &temp, 
&shade);
-                       FillGradient.addStop( 
ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), 
bounds[i], 0.5, 1.0, stopColor, shade );
-                       if (i == num_funcs - 1)
-                       {
-                               
((GfxAxialShading*)shading)->getColor(bounds[i+1], &temp);
-                               QString stopColor = getColor(color_space, 
&temp, &shade);
-                               FillGradient.addStop( 
ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), 
bounds[i+1], 0.5, 1.0, stopColor, shade );
-                       }
+                       double stopPoint = (bounds[i] - domain_min) / 
(domain_max - domain_min);
+                       FillGradient.addStop( 
ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), 
stopPoint, 0.5, 1.0, stopColor, shade );
                }
        }
        else if ((func->getType() == 2) || (func->getType() == 0))
        {
                GfxColor stop1;
-               ((GfxAxialShading*)shading)->getColor(0.0, &stop1);
+               shading->getColor(0.0, &stop1);
                QString stopColor1 = getColor(color_space, &stop1, &shade);
                FillGradient.addStop( 
ScColorEngine::getShadeColor(m_doc->PageColors[stopColor1], m_doc, shade), 0.0, 
0.5, 1.0, stopColor1, shade );
                GfxColor stop2;
-               ((GfxAxialShading*)shading)->getColor(1.0, &stop2);
+               shading->getColor(1.0, &stop2);
                QString stopColor2 = getColor(color_space, &stop2, &shade);
                FillGradient.addStop( 
ScColorEngine::getShadeColor(m_doc->PageColors[stopColor2], m_doc, shade), 1.0, 
0.5, 1.0, stopColor2, shade );
        }
-       ((GfxAxialShading*)shading)->getCoords(&GrStartX, &GrStartY, &GrEndX, 
&GrEndY);
+       shading->getCoords(&GrStartX, &GrStartY, &GrEndX, &GrEndY);
        double xmin, ymin, xmax, ymax;
        // get the clip region bbox
        state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
@@ -1865,34 +1867,36 @@
                StitchingFunction *stitchingFunc = (StitchingFunction*)func;
                const double *bounds = stitchingFunc->getBounds();
                int num_funcs = stitchingFunc->getNumFuncs();
+               double domain_min = stitchingFunc->getDomainMin(0);
+               double domain_max = stitchingFunc->getDomainMax(0);
+               if (fabs(domain_max - domain_min) < 1e-6)
+               {
+                       domain_min = 0.0;
+                       domain_max = 1.0;
+               }
                // Add stops from all the stitched functions
-               for ( int i = 0 ; i < num_funcs ; i++ )
+               for (int i = 0 ; i <= num_funcs ; i++)
                {
                        GfxColor temp;
-                       ((GfxRadialShading*)shading)->getColor(bounds[i], 
&temp);
+                       shading->getColor(bounds[i], &temp);
                        QString stopColor = getColor(color_space, &temp, 
&shade);
-                       FillGradient.addStop( 
ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), 
bounds[i], 0.5, 1.0, stopColor, shade );
-                       if (i == num_funcs - 1)
-                       {
-                               
((GfxRadialShading*)shading)->getColor(bounds[i+1], &temp);
-                               QString stopColor = getColor(color_space, 
&temp, &shade);
-                               FillGradient.addStop( 
ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), 
bounds[i+1], 0.5, 1.0, stopColor, shade );
-                       }
+                       double stopPoint = (bounds[i] - domain_min) / 
(domain_max - domain_min);
+                       FillGradient.addStop( 
ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), 
stopPoint, 0.5, 1.0, stopColor, shade );
                }
        }
        else if ((func->getType() == 2) || (func->getType() == 0))
        {
                GfxColor stop1;
-               ((GfxRadialShading*)shading)->getColor(0.0, &stop1);
+               shading->getColor(0.0, &stop1);
                QString stopColor1 = getColor(color_space, &stop1, &shade);
                FillGradient.addStop( 
ScColorEngine::getShadeColor(m_doc->PageColors[stopColor1], m_doc, shade), 0.0, 
0.5, 1.0, stopColor1, shade );
                GfxColor stop2;
-               ((GfxRadialShading*)shading)->getColor(1.0, &stop2);
+               shading->getColor(1.0, &stop2);
                QString stopColor2 = getColor(color_space, &stop2, &shade);
                FillGradient.addStop( 
ScColorEngine::getShadeColor(m_doc->PageColors[stopColor2], m_doc, shade), 1.0, 
0.5, 1.0, stopColor2, shade );
        }
        double r0, x1, y1, r1;
-       ((GfxRadialShading*)shading)->getCoords(&GrStartX, &GrStartY, &r0, &x1, 
&y1, &r1);
+       shading->getCoords(&GrStartX, &GrStartY, &r0, &x1, &y1, &r1);
        double xmin, ymin, xmax, ymax;
        // get the clip region bbox
        state->getClipBBox(&xmin, &ymin, &xmax, &ymax);


_______________________________________________
scribus-commit mailing list
[email protected]
http://lists.scribus.net/mailman/listinfo/scribus-commit

Reply via email to