1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-05 17:48:38 +00:00

first implementation of linear gradient

This commit is contained in:
Lu Wang 2012-10-03 02:52:45 +08:00
parent 2041c2d146
commit 2755cf6567

View File

@ -92,16 +92,21 @@ static void get_shading_bbox(GfxState * state, GfxShading * shading,
} }
} }
static double get_degree(double dx, double dy) /*
* Note that the coordinate system in HTML and PDF are different
* In HTML:
* UP = 0
* RIGHT = PI / 2
* DOWN = PI
* LEFT = - PI / 2
*/
static double get_angle(double dx, double dy)
{ {
static const double PI = acos(-1.0);
double r = hypot(dx, dy); double r = hypot(dx, dy);
double ang = acos(dx / r); double ang = acos(dx / r);
if(!_is_positive(dy))
ang = 2 * PI - ang;
return ang * 180.0 / PI; return ang;
} }
class LinearGradient class LinearGradient
@ -118,6 +123,7 @@ public:
} }
// TODO, add alpha // TODO, add alpha
class ColorStop class ColorStop
{ {
public: public:
@ -126,7 +132,7 @@ public:
}; };
vector<ColorStop> stops; vector<ColorStop> stops;
double degree; double angle;
}; };
LinearGradient::LinearGradient (GfxAxialShading * shading, LinearGradient::LinearGradient (GfxAxialShading * shading,
@ -136,7 +142,7 @@ LinearGradient::LinearGradient (GfxAxialShading * shading,
double t0x, t0y, t1x, t1y; double t0x, t0y, t1x, t1y;
shading->getCoords(&t0x, &t0y, &t1x, &t1y); shading->getCoords(&t0x, &t0y, &t1x, &t1y);
degree = get_degree(t1x - t0x, t1y - t0y); angle = get_angle(t1x - t0x, t1y - t0y);
// get the range of t in the box // get the range of t in the box
// from GfxState.cc in poppler // from GfxState.cc in poppler
@ -188,7 +194,12 @@ LinearGradient::LinearGradient (GfxAxialShading * shading,
void LinearGradient::dumpto (ostream & out) void LinearGradient::dumpto (ostream & out)
{ {
out << "background-color:red;"; out << "background-image:-moz-linear-gradient(" << _round(angle) << "rad";
for(auto iter = stops.begin(); iter != stops.end(); ++iter)
{
out << "," << (iter->rgb) << " " << _round((iter->pos) * 100) << "%";
}
out << ");";
} }
GBool HTMLRenderer::axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax) GBool HTMLRenderer::axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax)