summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-04-03 19:59:11 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-04-03 19:59:11 +0200
commit5ea6c5701e7ec3f738a8adb6d20790edcda781ba (patch)
tree38352e2cff9f1b9ae7f48d20480b5a8088624de9 /fitz
parenta5bfe0eef4361ec3ca8190b2533eca041eb7ef61 (diff)
parentbc5be11061e7687a80bcda6edc9bf3c136529111 (diff)
downloadmupdf-5ea6c5701e7ec3f738a8adb6d20790edcda781ba.tar.xz
Merge branch 'xps'
Diffstat (limited to 'fitz')
-rw-r--r--fitz/fitz.h12
-rw-r--r--fitz/obj_simple.c32
-rw-r--r--fitz/res_font.c28
-rw-r--r--fitz/res_path.c36
-rw-r--r--fitz/res_pixmap.c38
5 files changed, 108 insertions, 38 deletions
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 6de8d9b7..d79e280e 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -406,13 +406,15 @@ struct fz_obj_s
} u;
};
+extern fz_obj* (*fz_resolveindirect)(fz_obj*);
+
fz_obj *fz_newnull(void);
fz_obj *fz_newbool(int b);
fz_obj *fz_newint(int i);
fz_obj *fz_newreal(float f);
fz_obj *fz_newname(char *str);
fz_obj *fz_newstring(char *str, int len);
-fz_obj *fz_newindirect(int num, int gen, struct pdf_xref_s *xref);
+fz_obj *fz_newindirect(int num, int gen, void *xref);
fz_obj *fz_newarray(int initialcap);
fz_obj *fz_newdict(int initialcap);
@@ -435,8 +437,6 @@ int fz_isindirect(fz_obj *obj);
int fz_objcmp(fz_obj *a, fz_obj *b);
-fz_obj *fz_resolveindirect(fz_obj *obj);
-
/* silent failure, no error reporting */
int fz_tobool(fz_obj *obj);
int fz_toint(fz_obj *obj);
@@ -673,6 +673,7 @@ struct fz_pixmap_s
int x, y, w, h, n;
fz_pixmap *mask; /* explicit soft/image mask */
int interpolate;
+ int xres, yres;
fz_colorspace *colorspace;
unsigned char *samples;
int freesamples;
@@ -685,6 +686,7 @@ fz_pixmap *fz_keeppixmap(fz_pixmap *pix);
void fz_droppixmap(fz_pixmap *pix);
void fz_clearpixmap(fz_pixmap *pix);
void fz_clearpixmapwithcolor(fz_pixmap *pix, int value);
+void fz_premultiplypixmap(fz_pixmap *pix);
fz_pixmap *fz_alphafromgray(fz_pixmap *gray, int luminosity);
fz_bbox fz_boundpixmap(fz_pixmap *pix);
@@ -829,6 +831,8 @@ void fz_curvetoy(fz_path*, float, float, float, float);
void fz_closepath(fz_path*);
void fz_freepath(fz_path *path);
+void fz_transformpath(fz_path *path, fz_matrix transform);
+
fz_path *fz_clonepath(fz_path *old);
fz_rect fz_boundpath(fz_path *path, fz_strokestate *stroke, fz_matrix ctm);
@@ -897,7 +901,7 @@ struct fz_shade_s
float background[FZ_MAXCOLORS];
int usefunction;
- float function[256][FZ_MAXCOLORS];
+ float function[256][FZ_MAXCOLORS + 1];
int type; /* linear, radial, mesh */
int extend[2];
diff --git a/fitz/obj_simple.c b/fitz/obj_simple.c
index f279bd55..b629974e 100644
--- a/fitz/obj_simple.c
+++ b/fitz/obj_simple.c
@@ -1,9 +1,15 @@
#include "fitz.h"
-#include "mupdf.h" /* for pdf_loadobject */
extern void fz_freearray(fz_obj *array);
extern void fz_freedict(fz_obj *dict);
+static fz_obj *fz_resolve_indirect_null(fz_obj *ref)
+{
+ return ref;
+}
+
+fz_obj* (*fz_resolveindirect)(fz_obj*) = fz_resolve_indirect_null;
+
fz_obj *
fz_newnull(void)
{
@@ -66,7 +72,7 @@ fz_newname(char *str)
}
fz_obj *
-fz_newindirect(int num, int gen, pdf_xref *xref)
+fz_newindirect(int num, int gen, void *xref)
{
fz_obj *o = fz_malloc(sizeof(fz_obj));
o->refs = 1;
@@ -219,28 +225,6 @@ int fz_togen(fz_obj *obj)
return 0;
}
-fz_obj *fz_resolveindirect(fz_obj *ref)
-{
- if (fz_isindirect(ref))
- {
- pdf_xref *xref = ref->u.r.xref;
- int num = fz_tonum(ref);
- int gen = fz_togen(ref);
- if (xref)
- {
- fz_error error = pdf_cacheobject(xref, num, gen);
- if (error)
- {
- fz_catch(error, "cannot load object (%d %d R) into cache", num, gen);
- return ref;
- }
- if (xref->table[num].obj)
- return xref->table[num].obj;
- }
- }
- return ref;
-}
-
int
fz_objcmp(fz_obj *a, fz_obj *b)
{
diff --git a/fitz/res_font.c b/fitz/res_font.c
index 1df8b2e6..44046451 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -176,6 +176,7 @@ fz_finalizefreetype(void)
fz_error
fz_newfontfromfile(fz_font **fontp, char *path, int index)
{
+ FT_Face face;
fz_error error;
fz_font *font;
int fterr;
@@ -184,14 +185,16 @@ fz_newfontfromfile(fz_font **fontp, char *path, int index)
if (error)
return fz_rethrow(error, "cannot init freetype library");
- font = fz_newfont();
-
- fterr = FT_New_Face(fz_ftlib, path, index, (FT_Face*)&font->ftface);
+ fterr = FT_New_Face(fz_ftlib, path, index, &face);
if (fterr)
- {
- fz_free(font);
return fz_throw("freetype: cannot load font: %s", ft_errorstring(fterr));
- }
+
+ font = fz_newfont();
+ font->ftface = face;
+ font->bbox.x0 = face->bbox.xMin * 1000 / face->units_per_EM;
+ font->bbox.y0 = face->bbox.yMin * 1000 / face->units_per_EM;
+ font->bbox.x1 = face->bbox.xMax * 1000 / face->units_per_EM;
+ font->bbox.y1 = face->bbox.yMax * 1000 / face->units_per_EM;
*fontp = font;
return fz_okay;
@@ -200,6 +203,7 @@ fz_newfontfromfile(fz_font **fontp, char *path, int index)
fz_error
fz_newfontfrombuffer(fz_font **fontp, unsigned char *data, int len, int index)
{
+ FT_Face face;
fz_error error;
fz_font *font;
int fterr;
@@ -210,12 +214,16 @@ fz_newfontfrombuffer(fz_font **fontp, unsigned char *data, int len, int index)
font = fz_newfont();
- fterr = FT_New_Memory_Face(fz_ftlib, data, len, index, (FT_Face*)&font->ftface);
+ fterr = FT_New_Memory_Face(fz_ftlib, data, len, index, &face);
if (fterr)
- {
- fz_free(font);
return fz_throw("freetype: cannot load font: %s", ft_errorstring(fterr));
- }
+
+ font = fz_newfont();
+ font->ftface = face;
+ font->bbox.x0 = face->bbox.xMin * 1000 / face->units_per_EM;
+ font->bbox.y0 = face->bbox.yMin * 1000 / face->units_per_EM;
+ font->bbox.x1 = face->bbox.xMax * 1000 / face->units_per_EM;
+ font->bbox.y1 = face->bbox.yMax * 1000 / face->units_per_EM;
*fontp = font;
return fz_okay;
diff --git a/fitz/res_path.c b/fitz/res_path.c
index ebfb3cdc..b4ac415a 100644
--- a/fitz/res_path.c
+++ b/fitz/res_path.c
@@ -171,6 +171,42 @@ fz_boundpath(fz_path *path, fz_strokestate *stroke, fz_matrix ctm)
}
void
+fz_transformpath(fz_path *path, fz_matrix ctm)
+{
+ fz_point p;
+ int k, i = 0;
+
+ while (i < path->len)
+ {
+ switch (path->els[i++].k)
+ {
+ case FZ_CURVETO:
+ for (k = 0; k < 3; k++)
+ {
+ p.x = path->els[i].v;
+ p.y = path->els[i+1].v;
+ p = fz_transformpoint(ctm, p);
+ path->els[i].v = p.x;
+ path->els[i+1].v = p.y;
+ i += 2;
+ }
+ break;
+ case FZ_MOVETO:
+ case FZ_LINETO:
+ p.x = path->els[i].v;
+ p.y = path->els[i+1].v;
+ p = fz_transformpoint(ctm, p);
+ path->els[i].v = p.x;
+ path->els[i+1].v = p.y;
+ i += 2;
+ break;
+ case FZ_CLOSEPATH:
+ break;
+ }
+ }
+}
+
+void
fz_debugpath(fz_path *path, int indent)
{
float x, y;
diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c
index e70d084d..9f336ab1 100644
--- a/fitz/res_pixmap.c
+++ b/fitz/res_pixmap.c
@@ -13,6 +13,8 @@ fz_newpixmapwithdata(fz_colorspace *colorspace, int x, int y, int w, int h, unsi
pix->h = h;
pix->mask = nil;
pix->interpolate = 1;
+ pix->xres = 96;
+ pix->yres = 96;
pix->colorspace = nil;
pix->n = 1;
@@ -97,6 +99,42 @@ fz_clearpixmapwithcolor(fz_pixmap *pix, int value)
}
}
+void
+fz_premultiplypixmap(fz_pixmap *pix)
+{
+ unsigned char *s = pix->samples;
+ unsigned char a;
+ int k, x, y;
+
+ /* special case for CMYK (subtractive colors) */
+ if (pix->n == 5)
+ {
+ for (y = 0; y < pix->h; y++)
+ {
+ for (x = 0; x < pix->w; x++)
+ {
+ a = s[pix->n - 1];
+ for (k = 0; k < pix->n - 1; k++)
+ s[k] = 255 - fz_mul255(255 - s[k], a);
+ s += pix->n;
+ }
+ }
+ }
+ else
+ {
+ for (y = 0; y < pix->h; y++)
+ {
+ for (x = 0; x < pix->w; x++)
+ {
+ a = s[pix->n - 1];
+ for (k = 0; k < pix->n - 1; k++)
+ s[k] = fz_mul255(s[k], a);
+ s += pix->n;
+ }
+ }
+ }
+}
+
fz_bbox
fz_boundpixmap(fz_pixmap *pix)
{