1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-05 17:48:38 +00:00
This commit is contained in:
Lu Wang 2012-10-03 12:42:00 +08:00
parent 19db1a908d
commit 49fd259d6f
4 changed files with 55 additions and 15 deletions

View File

@ -36,6 +36,13 @@ static bool is_horizontal_line(GfxSubpath * path)
&& (_equal(path->getY(0), path->getY(1)))); && (_equal(path->getY(0), path->getY(1))));
} }
static bool is_vertical_line(GfxSubpath * path)
{
return ((path->getNumPoints() == 2)
&& (!path->getCurve(1))
&& (_equal(path->getX(0), path->getX(1))));
}
static bool is_rectangle(GfxSubpath * path) static bool is_rectangle(GfxSubpath * path)
{ {
if (!(((path->getNumPoints() != 4) && (path->isClosed())) if (!(((path->getNumPoints() != 4) && (path->isClosed()))
@ -94,17 +101,20 @@ static void get_shading_bbox(GfxState * state, GfxShading * shading,
/* /*
* Note that the coordinate system in HTML and PDF are different * 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 double get_angle(double dx, double dy)
{ {
double r = hypot(dx, dy); double r = hypot(dx, dy);
/*
* acos always returns [0, pi]
*/
double ang = acos(dx / r); double ang = acos(dx / r);
/*
* for angle below x-axis
*/
if(dy < 0)
ang = -ang;
return ang; return ang;
} }
@ -112,7 +122,7 @@ static double get_angle(double dx, double dy)
class LinearGradient class LinearGradient
{ {
public: public:
LinearGradient(GfxAxialShading * shading, LinearGradient(GfxAxialShading * shading,
double x1, double y1, double x2, double y2); double x1, double y1, double x2, double y2);
void dumpto (ostream & out); void dumpto (ostream & out);
@ -251,7 +261,23 @@ void HTMLRenderer::css_draw(GfxState *state, bool fill)
nullptr, 0, nullptr, 0,
nullptr, &stroke_color); nullptr, &stroke_color);
} }
else if (is_rectangle(subpath)) else if(is_vertical_line(subpath))
{
double x = subpath->getX(0);
double y1 = subpath->getY(0);
double y2 = subpath->getY(1);
if(y1 > y2) swap(y1, y2);
GfxRGB stroke_color;
state->getStrokeRGB(&stroke_color);
double lw = state->getLineWidth();
css_draw_rectangle(x-lw/2, y1, lw, y2-y1, state->getCTM(),
nullptr, 0,
nullptr, &stroke_color);
}
else if(is_rectangle(subpath))
{ {
close_text_line(); close_text_line();
double x1 = subpath->getX(0); double x1 = subpath->getX(0);
@ -305,7 +331,7 @@ void HTMLRenderer::css_draw_rectangle(double x, double y, double w, double h, co
double new_tm[6]; double new_tm[6];
memcpy(new_tm, tm, sizeof(new_tm)); memcpy(new_tm, tm, sizeof(new_tm));
_transform(new_tm, x, y); _tm_transform(new_tm, x, y);
double scale = 1.0; double scale = 1.0;
{ {

View File

@ -267,7 +267,7 @@ void HTMLRenderer::processLink(AnnotLink * al)
html_fout << "border-style:none;"; html_fout << "border-style:none;";
} }
_transform(default_ctm, x, y); _tm_transform(default_ctm, x, y);
html_fout << "position:absolute;" html_fout << "position:absolute;"
<< "left:" << _round(x) << "px;" << "left:" << _round(x) << "px;"

View File

@ -47,7 +47,8 @@ static inline bool _tm_equal(const double * tm1, const double * tm2, int size =
return true; return true;
} }
void _transform(const double * ctm, double & x, double & y, bool is_delta = false); void _tm_transform(const double * tm, double & x, double & y, bool is_delta = false);
void _tm_multiply(double * tm_left, const double * tm_right);
static inline long long hash_ref(const Ref * id) static inline long long hash_ref(const Ref * id)
{ {

View File

@ -54,18 +54,31 @@ const std::map<std::pair<std::string, bool>, std::pair<std::string, std::string>
{{".js", 1}, {"<script type=\"text/javascript\">", "</script>"}} {{".js", 1}, {"<script type=\"text/javascript\">", "</script>"}}
}); });
void _transform(const double * ctm, double & x, double & y, bool is_delta) void _tm_transform(const double * tm, double & x, double & y, bool is_delta)
{ {
double xx = x, yy = y; double xx = x, yy = y;
x = ctm[0] * xx + ctm[2] * yy; x = tm[0] * xx + tm[2] * yy;
y = ctm[1] * xx + ctm[3] * yy; y = tm[1] * xx + tm[3] * yy;
if(!is_delta) if(!is_delta)
{ {
x += ctm[4]; x += tm[4];
y += ctm[5]; y += tm[5];
} }
} }
void _tm_multiply(double * tm_left, const double * tm_right)
{
double old[4];
memcpy(old, tm_left, sizeof(old));
tm_left[0] = old[0] * tm_right[0] + old[2] * tm_right[1];
tm_left[1] = old[1] * tm_right[0] + old[3] * tm_right[1];
tm_left[2] = old[0] * tm_right[2] + old[2] * tm_right[3];
tm_left[3] = old[1] * tm_right[2] + old[3] * tm_right[3];
tm_left[4] += old[0] * tm_right[4] + old[2] * tm_right[5];
tm_left[5] += old[1] * tm_right[4] + old[3] * tm_right[5];
}
bool isLegalUnicode(Unicode u) bool isLegalUnicode(Unicode u)
{ {
/* /*