summaryrefslogtreecommitdiff
path: root/xps
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-04-04 00:59:49 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-04-04 00:59:49 +0200
commit68769d87e0c7fa0a365447d690eca45e48748bc4 (patch)
tree3aba2bf2952939e6b963ff36e2ddf1c815e4d9c4 /xps
parent19a4d970f4530ad330e5a7ae28c84692ee5f6bc0 (diff)
downloadmupdf-68769d87e0c7fa0a365447d690eca45e48748bc4.tar.xz
xps: Always use floats for floating point math.
Diffstat (limited to 'xps')
-rw-r--r--xps/xps_common.c32
-rw-r--r--xps/xps_glyphs.c20
-rw-r--r--xps/xps_gradient.c4
-rw-r--r--xps/xps_hash.c6
-rw-r--r--xps/xps_image.c4
-rw-r--r--xps/xps_jpeg.c7
-rw-r--r--xps/xps_path.c90
-rw-r--r--xps/xps_tiff.c4
-rw-r--r--xps/xps_tile.c8
9 files changed, 88 insertions, 87 deletions
diff --git a/xps/xps_common.c b/xps/xps_common.c
index 65f06e60..f4a0dcee 100644
--- a/xps/xps_common.c
+++ b/xps/xps_common.c
@@ -47,7 +47,7 @@ xps_begin_opacity(xps_context *ctx, fz_matrix ctm, fz_rect area,
if (!opacity_att && !opacity_mask_tag)
return;
- opacity = 1.0;
+ opacity = 1;
if (opacity_att)
opacity = atof(opacity_att);
@@ -105,9 +105,9 @@ xps_parse_render_transform(xps_context *ctx, char *transform, fz_matrix *matrix)
char *s = transform;
int i;
- args[0] = 1.0; args[1] = 0.0;
- args[2] = 0.0; args[3] = 1.0;
- args[4] = 0.0; args[5] = 0.0;
+ args[0] = 1; args[1] = 0;
+ args[2] = 0; args[3] = 1;
+ args[4] = 0; args[5] = 0;
for (i = 0; i < 6 && *s; i++)
{
@@ -145,8 +145,8 @@ xps_parse_rectangle(xps_context *ctx, char *text, fz_rect *rect)
char *s = text;
int i;
- args[0] = 0.0; args[1] = 0.0;
- args[2] = 1.0; args[3] = 1.0;
+ args[0] = 0; args[1] = 0;
+ args[2] = 1; args[3] = 1;
for (i = 0; i < 4 && *s; i++)
{
@@ -186,10 +186,10 @@ xps_parse_color(xps_context *ctx, char *base_uri, char *string,
*csp = fz_devicergb;
- samples[0] = 1.0;
- samples[1] = 0.0;
- samples[2] = 0.0;
- samples[3] = 0.0;
+ samples[0] = 1;
+ samples[1] = 0;
+ samples[2] = 0;
+ samples[3] = 0;
if (string[0] == '#')
{
@@ -202,16 +202,16 @@ xps_parse_color(xps_context *ctx, char *base_uri, char *string,
}
else
{
- samples[0] = 255.0;
+ samples[0] = 255;
samples[1] = unhex(string[1]) * 16 + unhex(string[2]);
samples[2] = unhex(string[3]) * 16 + unhex(string[4]);
samples[3] = unhex(string[5]) * 16 + unhex(string[6]);
}
- samples[0] /= 255.0;
- samples[1] /= 255.0;
- samples[2] /= 255.0;
- samples[3] /= 255.0;
+ samples[0] /= 255;
+ samples[1] /= 255;
+ samples[2] /= 255;
+ samples[3] /= 255;
}
else if (string[0] == 's' && string[1] == 'c' && string[2] == '#')
@@ -257,7 +257,7 @@ xps_parse_color(xps_context *ctx, char *base_uri, char *string,
}
while (i < n)
{
- samples[i++] = 0.0;
+ samples[i++] = 0;
}
/* TODO: load ICC profile */
diff --git a/xps/xps_glyphs.c b/xps/xps_glyphs.c
index 06438598..a5a98f6a 100644
--- a/xps/xps_glyphs.c
+++ b/xps/xps_glyphs.c
@@ -289,8 +289,8 @@ xps_parse_glyphs_imp(xps_context *ctx, fz_matrix ctm, fz_font *font, float size,
while (glyph_count--)
{
int glyph_index = -1;
- float u_offset = 0.0;
- float v_offset = 0.0;
+ float u_offset = 0;
+ float v_offset = 0;
float advance;
if (is && *is)
@@ -301,11 +301,11 @@ xps_parse_glyphs_imp(xps_context *ctx, fz_matrix ctm, fz_font *font, float size,
xps_measure_font_glyph(ctx, font, glyph_index, &mtx);
if (is_sideways)
- advance = mtx.vadv * 100.0;
+ advance = mtx.vadv * 100;
else if (bidi_level & 1)
- advance = -mtx.hadv * 100.0;
+ advance = -mtx.hadv * 100;
else
- advance = mtx.hadv * 100.0;
+ advance = mtx.hadv * 100;
if (is && *is)
{
@@ -317,13 +317,13 @@ xps_parse_glyphs_imp(xps_context *ctx, fz_matrix ctm, fz_font *font, float size,
if (bidi_level & 1)
u_offset = -mtx.hadv * 100 - u_offset;
- u_offset = u_offset * 0.01 * size;
- v_offset = v_offset * 0.01 * size;
+ u_offset = u_offset * 0.01f * size;
+ v_offset = v_offset * 0.01f * size;
if (is_sideways)
{
e = x + u_offset + (mtx.vorg * size);
- f = y - v_offset + (mtx.hadv * 0.5 * size);
+ f = y - v_offset + (mtx.hadv * 0.5f * size);
}
else
{
@@ -333,7 +333,7 @@ xps_parse_glyphs_imp(xps_context *ctx, fz_matrix ctm, fz_font *font, float size,
fz_addtext(text, glyph_index, char_code, e, f);
- x += advance * 0.01 * size;
+ x += advance * 0.01f * size;
}
}
@@ -379,7 +379,7 @@ xps_parse_glyphs(xps_context *ctx, fz_matrix ctm,
char partname[1024];
char *subfont;
- float font_size = 10.0;
+ float font_size = 10;
int subfontid = 0;
int is_sideways = 0;
int bidi_level = 0;
diff --git a/xps/xps_gradient.c b/xps/xps_gradient.c
index b23098bd..f03b8f6d 100644
--- a/xps/xps_gradient.c
+++ b/xps/xps_gradient.c
@@ -322,13 +322,13 @@ xps_draw_radial_gradient(xps_context *ctx, fz_matrix ctm,
yrad = atof(radius_y_att);
/* scale the ctm to make ellipses */
- ctm = fz_concat(fz_scale(1.0, yrad / xrad), ctm);
+ ctm = fz_concat(fz_scale(1, yrad / xrad), ctm);
invscale = xrad / yrad;
y0 = y0 * invscale;
y1 = y1 * invscale;
- r0 = 0.0;
+ r0 = 0;
r1 = xrad;
xps_draw_one_radial_gradient(ctx, ctm, stops, count, 1, x0, y0, r0, x1, y1, r1);
diff --git a/xps/xps_hash.c b/xps/xps_hash.c
index f2a7d48a..c0df8c1c 100644
--- a/xps/xps_hash.c
+++ b/xps/xps_hash.c
@@ -69,7 +69,7 @@ xps_hash_double(xps_hash_table *table)
xps_hash_entry *new_entries;
unsigned int old_size = table->size;
unsigned int new_size = table->size * 2;
- int i;
+ unsigned int i;
for (i = 0; primes[i] != 0; i++)
{
@@ -103,7 +103,7 @@ xps_hash_free(xps_hash_table *table,
void (*free_key)(void *),
void (*free_value)(void *))
{
- int i;
+ unsigned int i;
for (i = 0; i < table->size; i++)
{
@@ -175,7 +175,7 @@ xps_hash_insert(xps_hash_table *table, char *key, void *value)
void
xps_hash_debug(xps_hash_table *table)
{
- int i;
+ unsigned int i;
printf("hash table load %d / %d\n", table->load, table->size);
diff --git a/xps/xps_image.c b/xps/xps_image.c
index f4b75a1b..bc37d2e6 100644
--- a/xps/xps_image.c
+++ b/xps/xps_image.c
@@ -42,8 +42,8 @@ xps_paint_image_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_
xml_element *root, void *vimage)
{
fz_pixmap *pixmap = vimage;
- float xs = pixmap->w * 96.0 / pixmap->xres;
- float ys = pixmap->h * 96.0 / pixmap->yres;
+ float xs = pixmap->w * 96 / pixmap->xres;
+ float ys = pixmap->h * 96 / pixmap->yres;
fz_matrix im = fz_scale(xs, -ys);
im.f = ys;
ctm = fz_concat(im, ctm);
diff --git a/xps/xps_jpeg.c b/xps/xps_jpeg.c
index a8ea40f5..c40df1ca 100644
--- a/xps/xps_jpeg.c
+++ b/xps/xps_jpeg.c
@@ -55,7 +55,8 @@ xps_decode_jpeg(fz_pixmap **imagep, byte *rbuf, int rlen)
struct jpeg_source_mgr src;
unsigned char *row[1], *sp, *dp;
fz_colorspace *colorspace;
- int x, k;
+ unsigned int x;
+ int k;
fz_pixmap *image = NULL;
@@ -102,8 +103,8 @@ xps_decode_jpeg(fz_pixmap **imagep, byte *rbuf, int rlen)
}
else if (cinfo.density_unit == 2)
{
- image->xres = cinfo.X_density * 2.54;
- image->yres = cinfo.Y_density * 2.54;
+ image->xres = cinfo.X_density * 254 / 100;
+ image->yres = cinfo.Y_density * 254 / 100;
}
fz_clearpixmap(image);
diff --git a/xps/xps_path.c b/xps/xps_path.c
index 28b34894..83059ea1 100644
--- a/xps/xps_path.c
+++ b/xps/xps_path.c
@@ -47,63 +47,63 @@ xps_draw_arc_segment(fz_path *path, fz_matrix mtx, float th0, float th1, int isc
fz_point p;
while (th1 < th0)
- th1 += M_PI * 2.0;
+ th1 += (float)M_PI * 2;
- d = 1 * (M_PI / 180.0); /* 1-degree precision */
+ d = (float)M_PI / 180; /* 1-degree precision */
if (iscw)
{
- p.x = cos(th0);
- p.y = sin(th0);
+ p.x = cosf(th0);
+ p.y = sinf(th0);
p = fz_transformpoint(mtx, p);
fz_lineto(path, p.x, p.y);
for (t = th0; t < th1; t += d)
{
- p.x = cos(t);
- p.y = sin(t);
+ p.x = cosf(t);
+ p.y = sinf(t);
p = fz_transformpoint(mtx, p);
fz_lineto(path, p.x, p.y);
}
- p.x = cos(th1);
- p.y = sin(th1);
+ p.x = cosf(th1);
+ p.y = sinf(th1);
p = fz_transformpoint(mtx, p);
fz_lineto(path, p.x, p.y);
}
else
{
- th0 += M_PI * 2;
- p.x = cos(th0);
- p.y = sin(th0);
+ th0 += (float)M_PI * 2;
+ p.x = cosf(th0);
+ p.y = sinf(th0);
p = fz_transformpoint(mtx, p);
fz_lineto(path, p.x, p.y);
for (t = th0; t > th1; t -= d)
{
- p.x = cos(t);
- p.y = sin(t);
+ p.x = cosf(t);
+ p.y = sinf(t);
p = fz_transformpoint(mtx, p);
fz_lineto(path, p.x, p.y);
}
- p.x = cos(th1);
- p.y = sin(th1);
+ p.x = cosf(th1);
+ p.y = sinf(th1);
p = fz_transformpoint(mtx, p);
fz_lineto(path, p.x, p.y);
}
}
/* Given two vectors find the angle between them. */
-static inline double
+static inline float
angle_between(const fz_point u, const fz_point v)
{
- double det = u.x * v.y - u.y * v.x;
- double sign = (det < 0 ? -1.0 : 1.0);
- double magu = u.x * u.x + u.y * u.y;
- double magv = v.x * v.x + v.y * v.y;
- double udotv = u.x * v.x + u.y * v.y;
- double t = udotv / (magu * magv);
+ float det = u.x * v.y - u.y * v.x;
+ float sign = (det < 0 ? -1 : 1);
+ float magu = u.x * u.x + u.y * u.y;
+ float magv = v.x * v.x + v.y * v.y;
+ float udotv = u.x * v.x + u.y * v.y;
+ float t = udotv / (magu * magv);
/* guard against rounding errors when near |1| (where acos will return NaN) */
- if (t < -1.0) t = -1.0;
- if (t > 1.0) t = 1.0;
- return sign * acos(t);
+ if (t < -1) t = -1;
+ if (t > 1) t = 1;
+ return sign * acosf(t);
}
static void
@@ -115,13 +115,13 @@ xps_draw_arc(fz_path *path,
fz_matrix rotmat, revmat;
fz_matrix mtx;
fz_point pt;
- double rx, ry;
- double x1, y1, x2, y2;
- double x1t, y1t;
- double cxt, cyt, cx, cy;
- double t1, t2, t3;
- double sign;
- double th1, dth;
+ float rx, ry;
+ float x1, y1, x2, y2;
+ float x1t, y1t;
+ float cxt, cyt, cx, cy;
+ float t1, t2, t3;
+ float sign;
+ float th1, dth;
pt = fz_currentpoint(path);
x1 = pt.x;
@@ -145,7 +145,7 @@ xps_draw_arc(fz_path *path,
/* F.6.6.1 -- ensure radii are positive and non-zero */
rx = fabsf(rx);
ry = fabsf(ry);
- if (rx < 0.001 || ry < 0.001)
+ if (rx < 0.001f || ry < 0.001f)
{
fz_lineto(path, x2, y2);
return;
@@ -160,7 +160,7 @@ xps_draw_arc(fz_path *path,
/* F.6.6.2 -- ensure radii are large enough */
t1 = (x1t * x1t) / (rx * rx) + (y1t * y1t) / (ry * ry);
- if (t1 > 1.0)
+ if (t1 > 1)
{
rx = rx * sqrtf(t1);
ry = ry * sqrtf(t1);
@@ -171,7 +171,7 @@ xps_draw_arc(fz_path *path,
t2 = (rx * rx * y1t * y1t) + (ry * ry * x1t * x1t);
t3 = t1 / t2;
/* guard against rounding errors; sqrt of negative numbers is bad for your health */
- if (t3 < 0.0) t3 = 0.0;
+ if (t3 < 0) t3 = 0;
t3 = sqrtf(t3);
cxt = sign * t3 * (rx * y1t) / ry;
@@ -198,9 +198,9 @@ xps_draw_arc(fz_path *path,
th1 = angle_between(coord1, coord2);
dth = angle_between(coord3, coord4);
if (dth < 0 && !is_clockwise)
- dth += ((M_PI / 180.0) * 360);
+ dth += (((float)M_PI / 180) * 360);
if (dth > 0 && is_clockwise)
- dth -= ((M_PI / 180.0) * 360);
+ dth -= (((float)M_PI / 180) * 360);
}
mtx = fz_identity;
@@ -264,8 +264,8 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule)
old = 0;
reset_smooth = 1;
- smooth_x = 0.0;
- smooth_y = 0.0;
+ smooth_x = 0;
+ smooth_y = 0;
while (i < n)
{
@@ -277,8 +277,8 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule)
if (reset_smooth)
{
- smooth_x = 0.0;
- smooth_y = 0.0;
+ smooth_x = 0;
+ smooth_y = 0;
}
reset_smooth = 1;
@@ -629,8 +629,8 @@ xps_parse_path_figure(fz_path *path, xml_element *root, int stroking)
int is_closed = 0;
int is_filled = 1;
- float start_x = 0.0;
- float start_y = 0.0;
+ float start_x = 0;
+ float start_y = 0;
int skipped_stroke = 0;
@@ -892,11 +892,11 @@ xps_parse_path(xps_context *ctx, fz_matrix ctm, char *base_uri, xps_resource *di
if (!strcmp(stroke_line_join_att, "Bevel")) stroke.linejoin = 2;
}
- stroke.miterlimit = 10.0;
+ stroke.miterlimit = 10;
if (stroke_miter_limit_att)
stroke.miterlimit = atof(stroke_miter_limit_att);
- stroke.linewidth = 1.0;
+ stroke.linewidth = 1;
if (stroke_thickness_att)
stroke.linewidth = atof(stroke_thickness_att);
diff --git a/xps/xps_tiff.c b/xps/xps_tiff.c
index d70d5f87..8aabb084 100644
--- a/xps/xps_tiff.c
+++ b/xps/xps_tiff.c
@@ -415,8 +415,8 @@ xps_decode_tiff_strips(struct tiff *tiff)
/* no unit conversion needed */
break;
case 3:
- tiff->xresolution *= 2.54;
- tiff->yresolution *= 2.54;
+ tiff->xresolution = tiff->xresolution * 254 / 100;
+ tiff->yresolution = tiff->yresolution * 254 / 100;
break;
default:
tiff->xresolution = 96;
diff --git a/xps/xps_tile.c b/xps/xps_tile.c
index 1d87bdb3..2ddc190e 100644
--- a/xps/xps_tile.c
+++ b/xps/xps_tile.c
@@ -126,10 +126,10 @@ xps_parse_tiling_brush(xps_context *ctx, fz_matrix ctm, fz_rect area,
xps_parse_rectangle(ctx, viewport_att, &viewport);
/* some sanity checks on the viewport/viewbox size */
- if (fabs(viewport.x1 - viewport.x0) < 0.01) return;
- if (fabs(viewport.y1 - viewport.y0) < 0.01) return;
- if (fabs(viewbox.x1 - viewbox.x0) < 0.01) return;
- if (fabs(viewbox.y1 - viewbox.y0) < 0.01) return;
+ if (fabsf(viewport.x1 - viewport.x0) < 0.01f) return;
+ if (fabsf(viewport.y1 - viewport.y0) < 0.01f) return;
+ if (fabsf(viewbox.x1 - viewbox.x0) < 0.01f) return;
+ if (fabsf(viewbox.y1 - viewbox.y0) < 0.01f) return;
xstep = viewbox.x1 - viewbox.x0;
ystep = viewbox.y1 - viewbox.y0;