diff options
-rw-r--r-- | Jamfile | 15 | ||||
-rw-r--r-- | include/fitz.h | 1 | ||||
-rw-r--r-- | include/fitz/image.h | 17 | ||||
-rw-r--r-- | include/fitz/path.h | 32 | ||||
-rw-r--r-- | include/fitz/render.h | 8 | ||||
-rw-r--r-- | include/fitz/scanconv.h | 6 | ||||
-rw-r--r-- | include/fitz/text.h | 10 | ||||
-rw-r--r-- | include/fitz/tree.h | 134 | ||||
-rw-r--r-- | include/mupdf.h | 6 | ||||
-rw-r--r-- | mupdf/build.c | 50 | ||||
-rw-r--r-- | mupdf/interpret.c | 28 | ||||
-rw-r--r-- | render/fill.c | 2 | ||||
-rw-r--r-- | render/render.c | 24 | ||||
-rw-r--r-- | render/stroke.c | 35 | ||||
-rw-r--r-- | tree/blend.c | 53 | ||||
-rw-r--r-- | tree/cache.c | 98 | ||||
-rw-r--r-- | tree/debug.c | 74 | ||||
-rw-r--r-- | tree/form.c | 30 | ||||
-rw-r--r-- | tree/image.c | 49 | ||||
-rw-r--r-- | tree/mask.c | 50 | ||||
-rw-r--r-- | tree/meta.c | 37 | ||||
-rw-r--r-- | tree/node.c | 148 | ||||
-rw-r--r-- | tree/node1.c | 165 | ||||
-rw-r--r-- | tree/node2.c | 304 | ||||
-rw-r--r-- | tree/over.c | 50 | ||||
-rw-r--r-- | tree/path.c | 58 | ||||
-rw-r--r-- | tree/solid.c | 33 | ||||
-rw-r--r-- | tree/text.c | 18 | ||||
-rw-r--r-- | tree/transform.c | 35 | ||||
-rw-r--r-- | tree/tree.c | 57 |
30 files changed, 748 insertions, 879 deletions
@@ -63,22 +63,15 @@ Library libfitz : filter/jpxd.c # jasper # tree - tree/tree.c - tree/debug.c tree/cmap.c tree/font.c - tree/node.c - tree/meta.c - tree/over.c - tree/mask.c - tree/blend.c - tree/form.c - tree/transform.c - tree/solid.c - tree/image.c + tree/tree.c + tree/node1.c + tree/node2.c tree/text.c tree/path.c + tree/debug.c # render render/glyphcache.c diff --git a/include/fitz.h b/include/fitz.h index 20c105db..30f37649 100644 --- a/include/fitz.h +++ b/include/fitz.h @@ -22,7 +22,6 @@ #include "fitz/tree.h" #include "fitz/path.h" #include "fitz/text.h" -#include "fitz/image.h" #include "fitz/pixmap.h" #include "fitz/scanconv.h" diff --git a/include/fitz/image.h b/include/fitz/image.h deleted file mode 100644 index 7f6038ce..00000000 --- a/include/fitz/image.h +++ /dev/null @@ -1,17 +0,0 @@ -enum -{ - FZ_CSGRAY, - FZ_CSRGB, - FZ_CSCMYK -}; - -struct fz_image_s -{ - fz_node super; - int w, h, n, bpc; - int cs; - unsigned char *data; -}; - -fz_error *fz_newimage(fz_node **nodep, int w, int h, int n, int bpc, int cs); - diff --git a/include/fitz/path.h b/include/fitz/path.h index 536ca281..1c8a05a8 100644 --- a/include/fitz/path.h +++ b/include/fitz/path.h @@ -28,29 +28,31 @@ union fz_pathel_s float v; }; -struct fz_path_s +struct fz_pathnode_s { fz_node super; fz_pathkind paint; - fz_stroke *stroke; fz_dash *dash; + int linecap; + int linejoin; + float linewidth; + float miterlimit; int len, cap; fz_pathel *els; }; -fz_error *fz_newpath(fz_path **pathp); -fz_error *fz_clonepath(fz_path **pathp, fz_path *oldpath); -fz_error *fz_moveto(fz_path*, float x, float y); -fz_error *fz_lineto(fz_path*, float x, float y); -fz_error *fz_curveto(fz_path*, float, float, float, float, float, float); -fz_error *fz_curvetov(fz_path*, float, float, float, float); -fz_error *fz_curvetoy(fz_path*, float, float, float, float); -fz_error *fz_closepath(fz_path*); -fz_error *fz_endpath(fz_path*, fz_pathkind paint, fz_stroke *stroke, fz_dash *dash); -void fz_freepath(fz_path *path); - -fz_rect fz_boundpath(fz_path *node, fz_matrix ctm); -void fz_debugpath(fz_path *node); +fz_error *fz_newpathnode(fz_pathnode **pathp); +fz_error *fz_clonepath(fz_pathnode **pathp, fz_pathnode *oldpath); +fz_error *fz_moveto(fz_pathnode*, float x, float y); +fz_error *fz_lineto(fz_pathnode*, float x, float y); +fz_error *fz_curveto(fz_pathnode*, float, float, float, float, float, float); +fz_error *fz_curvetov(fz_pathnode*, float, float, float, float); +fz_error *fz_curvetoy(fz_pathnode*, float, float, float, float); +fz_error *fz_closepath(fz_pathnode*); +fz_error *fz_endpath(fz_pathnode*, fz_pathkind paint, fz_stroke *stroke, fz_dash *dash); + +fz_rect fz_boundpathnode(fz_pathnode *node, fz_matrix ctm); +void fz_debugpathnode(fz_pathnode *node); fz_error *fz_newdash(fz_dash **dashp, float phase, int len, float *array); void fz_freedash(fz_dash *dash); diff --git a/include/fitz/render.h b/include/fitz/render.h index d237e872..4024bfec 100644 --- a/include/fitz/render.h +++ b/include/fitz/render.h @@ -3,9 +3,9 @@ typedef struct fz_renderer_s fz_renderer; fz_error *fz_newrenderer(fz_renderer **gcp); void fz_freerenderer(fz_renderer *gc); -fz_error *fz_renderover(fz_renderer *gc, fz_over *over, fz_matrix ctm, fz_pixmap *out); -fz_error *fz_rendermask(fz_renderer *gc, fz_mask *mask, fz_matrix ctm, fz_pixmap *out); -fz_error *fz_rendertransform(fz_renderer *gc, fz_transform *xform, fz_matrix ctm, fz_pixmap *out); -fz_error *fz_rendertext(fz_renderer *gc, fz_text *text, fz_matrix ctm, fz_pixmap *out); +fz_error *fz_renderover(fz_renderer *gc, fz_overnode *over, fz_matrix ctm, fz_pixmap *out); +fz_error *fz_rendermask(fz_renderer *gc, fz_masknode *mask, fz_matrix ctm, fz_pixmap *out); +fz_error *fz_rendertransform(fz_renderer *gc, fz_transformnode *xform, fz_matrix ctm, fz_pixmap *out); +fz_error *fz_rendertext(fz_renderer *gc, fz_textnode *text, fz_matrix ctm, fz_pixmap *out); fz_error *fz_rendernode(fz_renderer *gc, fz_node *node, fz_matrix ctm, fz_pixmap *out); diff --git a/include/fitz/scanconv.h b/include/fitz/scanconv.h index f391a387..0e073127 100644 --- a/include/fitz/scanconv.h +++ b/include/fitz/scanconv.h @@ -40,7 +40,7 @@ void fz_freeael(fz_ael *ael); fz_error *fz_scanconvert(fz_gel *gel, fz_ael *ael, int eofill); -fz_error *fz_fillpath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness); -fz_error *fz_strokepath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness); -fz_error *fz_dashpath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness); +fz_error *fz_fillpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness); +fz_error *fz_strokepath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness); +fz_error *fz_dashpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness); diff --git a/include/fitz/text.h b/include/fitz/text.h index 41a08c45..c28d96c7 100644 --- a/include/fitz/text.h +++ b/include/fitz/text.h @@ -1,4 +1,3 @@ -typedef struct fz_textbuilder_s fz_textbuilder; typedef struct fz_textel_s fz_textel; struct fz_textel_s @@ -7,7 +6,7 @@ struct fz_textel_s int g; }; -struct fz_text_s +struct fz_textnode_s { fz_node super; fz_font *font; @@ -16,8 +15,7 @@ struct fz_text_s fz_textel *els; }; -fz_error *fz_newtext(fz_text **textp, fz_font *face); -fz_error *fz_addtext(fz_text *text, int g, float x, float y); -fz_error *fz_endtext(fz_text *text); -void fz_freetext(fz_text *text); +fz_error *fz_newtextnode(fz_textnode **textp, fz_font *face); +fz_error *fz_addtext(fz_textnode *text, int g, float x, float y); +fz_error *fz_endtext(fz_textnode *text); diff --git a/include/fitz/tree.h b/include/fitz/tree.h index 080e55bf..4d6eb952 100644 --- a/include/fitz/tree.h +++ b/include/fitz/tree.h @@ -1,21 +1,38 @@ typedef struct fz_tree_s fz_tree; typedef struct fz_node_s fz_node; +struct fz_tree_s +{ + int refcount; + fz_node *root; + fz_node *head; +}; + +/* tree operations */ +fz_error *fz_newtree(fz_tree **treep); +fz_tree *fz_keeptree(fz_tree *tree); +void fz_droptree(fz_tree *tree); + +fz_rect fz_boundtree(fz_tree *tree, fz_matrix ctm); +void fz_debugtree(fz_tree *tree); +void fz_insertnode(fz_node *parent, fz_node *child); + +/* node types */ + typedef enum fz_nodekind_e fz_nodekind; typedef enum fz_blendkind_e fz_blendkind; -typedef struct fz_transform_s fz_transform; -typedef struct fz_over_s fz_over; -typedef struct fz_mask_s fz_mask; -typedef struct fz_blend_s fz_blend; -typedef struct fz_path_s fz_path; -typedef struct fz_text_s fz_text; -typedef struct fz_solid_s fz_solid; -typedef struct fz_image_s fz_image; -typedef struct fz_shade_s fz_shade; -typedef struct fz_form_s fz_form; -typedef struct fz_meta_s fz_meta; -typedef struct fz_halftone_s fz_halftone; +typedef struct fz_transformnode_s fz_transformnode; +typedef struct fz_overnode_s fz_overnode; +typedef struct fz_masknode_s fz_masknode; +typedef struct fz_blendnode_s fz_blendnode; +typedef struct fz_pathnode_s fz_pathnode; +typedef struct fz_textnode_s fz_textnode; +typedef struct fz_colornode_s fz_colornode; +typedef struct fz_imagenode_s fz_imagenode; +typedef struct fz_shadenode_s fz_shadenode; +typedef struct fz_linknode_s fz_linknode; +typedef struct fz_metanode_s fz_metanode; enum fz_nodekind_e { @@ -25,12 +42,11 @@ enum fz_nodekind_e FZ_NBLEND, FZ_NPATH, FZ_NTEXT, - FZ_NSOLID, + FZ_NCOLOR, FZ_NIMAGE, FZ_NSHADE, - FZ_NFORM, - FZ_NMETA, - FZ_NHALFTONE + FZ_NLINK, + FZ_NMETA }; enum fz_blendkind_e @@ -56,75 +72,65 @@ enum fz_blendkind_e FZ_BLUMINOSITY, FZ_BOVERPRINT, -}; - -struct fz_tree_s -{ - fz_node *root; - fz_node *head; + FZ_BRASTEROP, }; struct fz_node_s { fz_nodekind kind; fz_node *parent; + fz_node *child; fz_node *next; }; -struct fz_meta_s +struct fz_transformnode_s { fz_node super; - fz_node *child; - fz_obj *info; + fz_matrix m; }; -struct fz_over_s +struct fz_overnode_s { fz_node super; - fz_node *child; }; -struct fz_mask_s +struct fz_masknode_s { fz_node super; - fz_node *child; }; -struct fz_blend_s +struct fz_blendnode_s { fz_node super; - fz_node *child; fz_blendkind mode; int isolated; int knockout; }; -struct fz_transform_s +struct fz_colornode_s { fz_node super; - fz_node *child; - fz_matrix m; + float r, g, b; }; -struct fz_form_s +struct fz_linknode_s { fz_node super; fz_tree *tree; }; -struct fz_solid_s +struct fz_metanode_s { fz_node super; - float r, g, b; + fz_obj *info; }; -/* tree operations */ -fz_error *fz_newtree(fz_tree **treep); -void fz_freetree(fz_tree *tree); -fz_rect fz_boundtree(fz_tree *tree, fz_matrix ctm); - -void fz_debugtree(fz_tree *tree); -void fz_insertnode(fz_node *node, fz_node *child); +struct fz_imagenode_s +{ + fz_node super; + int w, h, n, a; + // XXX fz_image *image; +}; /* common to all nodes */ void fz_initnode(fz_node *node, fz_nodekind kind); @@ -132,25 +138,27 @@ fz_rect fz_boundnode(fz_node *node, fz_matrix ctm); void fz_freenode(fz_node *node); /* branch nodes */ -fz_error *fz_newmeta(fz_node **nodep, fz_obj *info); -fz_error *fz_newover(fz_node **nodep); -fz_error *fz_newmask(fz_node **nodep); -fz_error *fz_newblend(fz_node **nodep, fz_blendkind b, int k, int i); -fz_error *fz_newtransform(fz_node **nodep, fz_matrix m); - -int fz_ismeta(fz_node *node); -int fz_isover(fz_node *node); -int fz_ismask(fz_node *node); -int fz_isblend(fz_node *node); -int fz_istransform(fz_node *node); +fz_error *fz_newmetanode(fz_node **nodep, fz_obj *info); +fz_error *fz_newovernode(fz_node **nodep); +fz_error *fz_newmasknode(fz_node **nodep); +fz_error *fz_newblendnode(fz_node **nodep, fz_blendkind b, int k, int i); +fz_error *fz_newtransformnode(fz_node **nodep, fz_matrix m); + +int fz_istransformnode(fz_node *node); +int fz_isovernode(fz_node *node); +int fz_ismasknode(fz_node *node); +int fz_isblendnode(fz_node *node); +int fz_ismetanode(fz_node *node); /* leaf nodes */ -fz_error *fz_newform(fz_node **nodep, fz_tree *subtree); -fz_error *fz_newsolid(fz_node **nodep, float r, float g, float b); - -int fz_isform(fz_node *node); -int fz_issolid(fz_node *node); -int fz_ispath(fz_node *node); -int fz_istext(fz_node *node); -int fz_isimage(fz_node *node); +fz_error *fz_newlinknode(fz_node **nodep, fz_tree *subtree); +fz_error *fz_newcolornode(fz_node **nodep, float r, float g, float b); +fz_error *fz_newimagenode(fz_node **nodep, int w, int h, int n, int a); + +int fz_islinknode(fz_node *node); +int fz_iscolornode(fz_node *node); +int fz_ispathnode(fz_node *node); +int fz_istextnode(fz_node *node); +int fz_isimagenode(fz_node *node); +int fz_isshadenode(fz_node *node); diff --git a/include/mupdf.h b/include/mupdf.h index ca4a267b..c5dcc133 100644 --- a/include/mupdf.h +++ b/include/mupdf.h @@ -210,11 +210,11 @@ struct pdf_csi_s int xbalance; /* path object state */ - fz_path *path; - fz_path *clip; + fz_pathnode *path; + fz_pathnode *clip; /* text object state */ - fz_text *text; + fz_textnode *text; fz_matrix tlm; fz_matrix tm; diff --git a/mupdf/build.c b/mupdf/build.c index f759e500..dfca7446 100644 --- a/mupdf/build.c +++ b/mupdf/build.c @@ -35,37 +35,29 @@ pdf_initgstate(pdf_gstate *gs) } fz_error * -pdf_buildstrokepath(pdf_gstate *gs, fz_path *path) +pdf_buildstrokepath(pdf_gstate *gs, fz_pathnode *path) { fz_error *error; - fz_stroke *stroke; + fz_stroke stroke; fz_dash *dash; - stroke = fz_malloc(sizeof(fz_stroke)); - if (!stroke) - return fz_outofmem; - stroke->linecap = gs->linecap; - stroke->linejoin = gs->linejoin; - stroke->linewidth = gs->linewidth; - stroke->miterlimit = gs->miterlimit; + stroke.linecap = gs->linecap; + stroke.linejoin = gs->linejoin; + stroke.linewidth = gs->linewidth; + stroke.miterlimit = gs->miterlimit; if (gs->dashlen) { error = fz_newdash(&dash, gs->dashphase, gs->dashlen, gs->dashlist); - if (error) { - fz_free(stroke); + if (error) return error; - } } else - { dash = nil; - } - error = fz_endpath(path, FZ_STROKE, stroke, dash); + error = fz_endpath(path, FZ_STROKE, &stroke, dash); if (error) { fz_freedash(dash); - fz_free(stroke); return error; } @@ -73,7 +65,7 @@ pdf_buildstrokepath(pdf_gstate *gs, fz_path *path) } fz_error * -pdf_buildfillpath(pdf_gstate *gs, fz_path *path, int eofill) +pdf_buildfillpath(pdf_gstate *gs, fz_pathnode *path, int eofill) { return fz_endpath(path, eofill ? FZ_EOFILL : FZ_FILL, nil, nil); } @@ -85,10 +77,10 @@ addcolorshape(pdf_gstate *gs, fz_node *shape, float r, float g, float b) fz_node *mask; fz_node *solid; - error = fz_newmask(&mask); + error = fz_newmasknode(&mask); if (error) return error; - error = fz_newsolid(&solid, r, g, b); + error = fz_newcolornode(&solid, r, g, b); if (error) return error; fz_insertnode(mask, shape); @@ -117,10 +109,10 @@ pdf_addclipmask(pdf_gstate *gs, fz_node *shape) fz_node *mask; fz_node *over; - error = fz_newmask(&mask); + error = fz_newmasknode(&mask); if (error) return error; - error = fz_newover(&over); + error = fz_newovernode(&over); if (error) return error; fz_insertnode(mask, shape); @@ -132,16 +124,16 @@ pdf_addclipmask(pdf_gstate *gs, fz_node *shape) } fz_error * -pdf_addtransform(pdf_gstate *gs, fz_node *affine) +pdf_addtransform(pdf_gstate *gs, fz_node *transform) { fz_error *error; fz_node *over; - error = fz_newover(&over); + error = fz_newovernode(&over); if (error) return error; - fz_insertnode(gs->head, affine); - fz_insertnode(affine, over); + fz_insertnode(gs->head, transform); + fz_insertnode(transform, over); gs->head = over; return nil; @@ -153,8 +145,8 @@ pdf_showpath(pdf_csi *csi, { pdf_gstate *gstate = csi->gstate + csi->gtop; fz_error *error; - fz_path *spath; - fz_path *fpath; + fz_pathnode *spath; + fz_pathnode *fpath; if (doclose) { @@ -203,7 +195,7 @@ pdf_showpath(pdf_csi *csi, csi->path = nil; - error = fz_newpath(&csi->path); + error = fz_newpathnode(&csi->path); if (error) return error; return nil; @@ -266,7 +258,7 @@ showglyph(pdf_csi *csi, int g) error = pdf_flushtext(csi); if (error) return error; - error = fz_newtext(&csi->text, (fz_font*)font); + error = fz_newtextnode(&csi->text, (fz_font*)font); if (error) return error; csi->text->trm = trm; diff --git a/mupdf/interpret.c b/mupdf/interpret.c index 6ad24d11..2053422b 100644 --- a/mupdf/interpret.c +++ b/mupdf/interpret.c @@ -3,13 +3,13 @@ void pdf_initgstate(pdf_gstate *gs); -fz_error *pdf_buildstrokepath(pdf_gstate *gs, fz_path *path); -fz_error *pdf_buildfillpath(pdf_gstate *gs, fz_path *path, int evenodd); +fz_error *pdf_buildstrokepath(pdf_gstate *gs, fz_pathnode *path); +fz_error *pdf_buildfillpath(pdf_gstate *gs, fz_pathnode *path, int evenodd); fz_error *pdf_addfillshape(pdf_gstate *gs, fz_node *shape); fz_error *pdf_addstrokeshape(pdf_gstate *gs, fz_node *shape); fz_error *pdf_addclipmask(pdf_gstate *gs, fz_node *shape); -fz_error *pdf_addtransform(pdf_gstate *gs, fz_node *affine); +fz_error *pdf_addtransform(pdf_gstate *gs, fz_node *transform); fz_error *pdf_showpath(pdf_csi *, int doclose, int dofill, int dostroke, int evenodd); fz_error *pdf_showtext(pdf_csi *, fz_obj *text); @@ -33,7 +33,7 @@ pdf_newcsi(pdf_csi **csip) csi->xbalance = 0; - error = fz_newpath(&csi->path); + error = fz_newpathnode(&csi->path); if (error) { fz_free(csi); return error; @@ -41,12 +41,12 @@ pdf_newcsi(pdf_csi **csip) error = fz_newtree(&csi->tree); if (error) { - fz_freepath(csi->path); + fz_freenode((fz_node*)csi->path); fz_free(csi); return error; } - error = fz_newover(&node); + error = fz_newovernode(&node); csi->tree->root = node; csi->gstate[0].head = node; @@ -71,9 +71,9 @@ clearstack(pdf_csi *csi) void pdf_freecsi(pdf_csi *csi) { - if (csi->path) fz_freepath(csi->path); - if (csi->clip) fz_freepath(csi->clip); - if (csi->text) fz_freetext(csi->text); + if (csi->path) fz_freenode((fz_node*)csi->path); + if (csi->clip) fz_freenode((fz_node*)csi->clip); + if (csi->text) fz_freenode((fz_node*)csi->text); clearstack(csi); fz_free(csi); } @@ -164,7 +164,7 @@ runkeyword(pdf_csi *csi, pdf_resources *rdb, char *buf) fz_node *meta; if (csi->top != 1) goto syntaxerror; - error = fz_newmeta(&meta, csi->stack[0]); + error = fz_newmetanode(&meta, csi->stack[0]); if (error) return error; fz_insertnode(gstate->head, meta); } @@ -178,7 +178,7 @@ runkeyword(pdf_csi *csi, pdf_resources *rdb, char *buf) error = fz_packobj(&info, "<< %o %o >>", csi->stack[0], csi->stack[1]); if (error) return error; - error = fz_newmeta(&meta, info); + error = fz_newmetanode(&meta, info); fz_dropobj(info); if (error) return error; fz_insertnode(gstate->head, meta); @@ -187,7 +187,7 @@ runkeyword(pdf_csi *csi, pdf_resources *rdb, char *buf) else if (!strcmp(buf, "cm")) { fz_matrix m; - fz_node *affine; + fz_node *transform; if (csi->top != 6) goto syntaxerror; @@ -199,9 +199,9 @@ runkeyword(pdf_csi *csi, pdf_resources *rdb, char *buf) m.e = fz_toreal(csi->stack[4]); m.f = fz_toreal(csi->stack[5]); - error = fz_newtransform(&affine, m); + error = fz_newtransformnode(&transform, m); if (error) return error; - error = pdf_addtransform(gstate, affine); + error = pdf_addtransform(gstate, transform); if (error) return error; } diff --git a/render/fill.c b/render/fill.c index 4605726d..fdb12205 100644 --- a/render/fill.c +++ b/render/fill.c @@ -65,7 +65,7 @@ bezier(fz_gel *gel, fz_matrix *ctm, float flatness, } fz_error * -fz_fillpath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness) +fz_fillpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness) { fz_error *error; float x1, y1, x2, y2, x3, y3; diff --git a/render/render.c b/render/render.c index 64856dd2..bb875ee3 100644 --- a/render/render.c +++ b/render/render.c @@ -60,12 +60,12 @@ fz_freerenderer(fz_renderer *gc) } fz_error * -fz_renderover(fz_renderer *gc, fz_over *over, fz_matrix ctm, fz_pixmap *out) +fz_renderover(fz_renderer *gc, fz_overnode *over, fz_matrix ctm, fz_pixmap *out) { fz_error *error; fz_node *node; - for (node = over->child; node; node = node->next) + for (node = over->super.child; node; node = node->next) { error = fz_rendernode(gc, node, ctm, out); if (error) @@ -76,12 +76,12 @@ fz_renderover(fz_renderer *gc, fz_over *over, fz_matrix ctm, fz_pixmap *out) } fz_error * -fz_rendermask(fz_renderer *gc, fz_mask *mask, fz_matrix ctm, fz_pixmap *out) +fz_rendermask(fz_renderer *gc, fz_masknode *mask, fz_matrix ctm, fz_pixmap *out) { fz_error *error; fz_node *node; - for (node = mask->child; node; node = node->next) + for (node = mask->super.child; node; node = node->next) { error = fz_rendernode(gc, node, ctm, out); if (error) @@ -92,10 +92,10 @@ fz_rendermask(fz_renderer *gc, fz_mask *mask, fz_matrix ctm, fz_pixmap *out) } fz_error * -fz_rendertransform(fz_renderer *gc, fz_transform *xform, fz_matrix ctm, fz_pixmap *out) +fz_rendertransform(fz_renderer *gc, fz_transformnode *transform, fz_matrix ctm, fz_pixmap *out) { - ctm = fz_concat(ctm, xform->m); - return fz_rendernode(gc, xform->child, ctm, out); + ctm = fz_concat(ctm, transform->m); + return fz_rendernode(gc, transform->super.child, ctm, out); } @@ -124,7 +124,7 @@ void composite(fz_pixmap *out, fz_glyph *gl, int xo, int yo) } fz_error * -fz_rendertext(fz_renderer *gc, fz_text *text, fz_matrix ctm, fz_pixmap *out) +fz_rendertext(fz_renderer *gc, fz_textnode *text, fz_matrix ctm, fz_pixmap *out) { fz_error *error; fz_glyph gl; @@ -169,13 +169,13 @@ fz_rendernode(fz_renderer *gc, fz_node *node, fz_matrix ctm, fz_pixmap *out) switch (node->kind) { case FZ_NOVER: - return fz_renderover(gc, (fz_over*)node, ctm, out); + return fz_renderover(gc, (fz_overnode*)node, ctm, out); case FZ_NMASK: - return fz_rendermask(gc, (fz_mask*)node, ctm, out); + return fz_rendermask(gc, (fz_masknode*)node, ctm, out); case FZ_NTRANSFORM: - return fz_rendertransform(gc, (fz_transform*)node, ctm, out); + return fz_rendertransform(gc, (fz_transformnode*)node, ctm, out); case FZ_NTEXT: - return fz_rendertext(gc, (fz_text*)node, ctm, out); + return fz_rendertext(gc, (fz_textnode*)node, ctm, out); default: return nil; } diff --git a/render/stroke.c b/render/stroke.c index 1203f71b..cd4f5a13 100644 --- a/render/stroke.c +++ b/render/stroke.c @@ -8,7 +8,10 @@ struct sctx fz_matrix *ctm; float flatness; - fz_stroke *stroke; + int linecap; + int linejoin; + float linewidth; + float miterlimit; fz_point beg[2]; fz_point seg[2]; int sn, bn; @@ -43,7 +46,7 @@ arc(struct sctx *s, float ox, oy, nx, ny; int n, i; - r = fabs(s->stroke->linewidth); + r = fabs(s->linewidth); theta = 2 * M_SQRT2 * sqrt(s->flatness / r); th0 = atan2(y0, x0); th1 = atan2(y1, x1); @@ -87,7 +90,7 @@ linestroke(struct sctx *s, fz_point a, fz_point b) float dx = b.x - a.x; float dy = b.y - a.y; - float scale = s->stroke->linewidth / sqrt(dx * dx + dy * dy); + float scale = s->linewidth / sqrt(dx * dx + dy * dy); float dlx = dy * scale; float dly = -dx * scale; @@ -104,9 +107,9 @@ static fz_error * linejoin(struct sctx *s, fz_point a, fz_point b, fz_point c) { fz_error *error; - float miterlimit = s->stroke->miterlimit; - float linewidth = s->stroke->linewidth; - int linejoin = s->stroke->linejoin; + float miterlimit = s->miterlimit; + float linewidth = s->linewidth; + int linejoin = s->linejoin; float dx0, dy0; float dx1, dy1; float dlx0, dly0; @@ -208,8 +211,8 @@ linecap(struct sctx *s, fz_point a, fz_point b) { fz_error *error; float flatness = s->flatness; - float linewidth = s->stroke->linewidth; - int linecap = s->stroke->linecap; + float linewidth = s->linewidth; + int linecap = s->linecap; float dx = b.x - a.x; float dy = b.y - a.y; @@ -268,7 +271,7 @@ linedot(struct sctx *s, fz_point a) { fz_error *error; float flatness = s->flatness; - float linewidth = s->stroke->linewidth; + float linewidth = s->linewidth; int n = ceil(M_PI / (M_SQRT2 * sqrt(flatness / linewidth))); float ox = a.x - linewidth; float oy = a.y; @@ -453,7 +456,7 @@ strokebezier(struct sctx *s, } fz_error * -fz_strokepath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness) +fz_strokepath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness) { fz_error *error; struct sctx s; @@ -464,7 +467,10 @@ fz_strokepath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness) s.ctm = &ctm; s.flatness = flatness; - s.stroke = path->stroke; + s.linecap = path->linecap; + s.linejoin = path->linejoin; + s.linewidth = path->linewidth; + s.miterlimit = path->miterlimit; s.sn = 0; s.bn = 0; s.dot = 0; @@ -645,7 +651,7 @@ dashbezier(struct sctx *s, } fz_error * -fz_dashpath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness) +fz_dashpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness) { fz_error *error; struct sctx s; @@ -656,7 +662,10 @@ fz_dashpath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness) s.ctm = &ctm; s.flatness = flatness; - s.stroke = path->stroke; + s.linecap = path->linecap; + s.linejoin = path->linejoin; + s.linewidth = path->linewidth; + s.miterlimit = path->miterlimit; s.sn = 0; s.bn = 0; s.dot = 0; diff --git a/tree/blend.c b/tree/blend.c deleted file mode 100644 index d2154240..00000000 --- a/tree/blend.c +++ /dev/null @@ -1,53 +0,0 @@ -#include <fitz.h> - -fz_error * -fz_newblend(fz_node **nodep, fz_blendkind b, int k, int i) -{ - fz_blend *node; - - node = fz_malloc(sizeof (fz_blend)); - if (!node) - return fz_outofmem; - *nodep = (fz_node*)node; - - fz_initnode((fz_node*)node, FZ_NBLEND); - node->child = nil; - node->mode = b; - node->knockout = k; - node->isolated = i; - - return nil; -} - -void -fz_freeblend(fz_blend *node) -{ - if (node->child) - fz_freenode(node->child); - fz_free(node); -} - -fz_rect -fz_boundblend(fz_blend *node, fz_matrix ctm) -{ - fz_node *child; - fz_rect bbox; - fz_rect r; - - bbox = FZ_INFRECT; - - for (child = node->child; child; child = child->next) - { - r = fz_boundnode(child, ctm); - if (r.max.x >= r.min.x) - { - if (bbox.max.x >= bbox.min.x) - bbox = fz_mergerects(r, bbox); - else - bbox = r; - } - } - - return bbox; -} - diff --git a/tree/cache.c b/tree/cache.c deleted file mode 100644 index f4544844..00000000 --- a/tree/cache.c +++ /dev/null @@ -1,98 +0,0 @@ -#include <fitz.h> - -static int -hash(fz_cachekey *k) -{ - int h; - int i; - - h = (int)k->tree ^ (int)k->node ^ k->tag; - - /* http://www.cs.yorku.ca/~oz/hash.html -- sdbm */ - for (i = 0; i < k->len; i++) - h = k->key[i] + (h << 6) + (h << 16) - h; - - return h; -} - -static int -equal(fz_cachekey *a, fz_cachekey *b) -{ - if (a->tree != b->tree) return 0; - if (a->node != b->node) return 0; - if (a->tag != b->tag) return 0; - if (a->len != b->len) return 0; - return memcmp(a->key, b->key, a->len) == 0; -} - -fz_cache * -fz_newcache(int maxentries, int maxdatasize) -{ - fz_cache *cache; - int i; - - cache = fz_malloc(sizeof(fz_cache)); - if (!cache) return nil; - - cache->maxsize = maxdatasize; - cache->cursize = 0; - cache->len = maxentries; - cache->table = fz_malloc(sizeof(fz_cachebucket) * maxentries); - if (!cache->table) { - fz_free(cache); - return nil; - } - - for (i = 0; i < cache->len; i++) { - cache->table[i].val = nil; - } - - return cache; -} - -void * -fz_findincache(fz_cache *cache, fz_cachekey *key) -{ - int h; - int i; - - h = hash(key); - - i = h % cache->len; - if (equal(key, &cache->table[i].key)) - return cache->table[i].val; - return nil; -} - -int -fz_insertincache(fz_cache *cache, fz_cachekey *key, void *data, int size) -{ - int h; - int i; - - h = hash(key); - i = h % cache->len; - - if (cache->table[i].val) - fz_free(cache->table[i].val); - cache->table[i].key = *key; - - return FZ_OKAY; -} - -int -fz_evictfromcache(fz_cache *cache, fz_cachekey *key) -{ - /* TODO */ - return FZ_OKAY; -} - -void -fz_freecache(fz_cache *cache) -{ - /* FIXME evict everything from cache first? */ - if (cache->table) - fz_free(cache->table); - fz_free(cache); -} - diff --git a/tree/debug.c b/tree/debug.c index 2e7cfc4f..8e16c612 100644 --- a/tree/debug.c +++ b/tree/debug.c @@ -8,77 +8,77 @@ static void indent(int level) static void lispnode(fz_node *node, int level); -static void lispmeta(fz_meta *node, int level) +static void lispmeta(fz_metanode *node, int level) { fz_node *child; indent(level); printf("(meta "); fz_debugobj(node->info); printf("\n"); - for (child = node->child; child; child = child->next) + for (child = node->super.child; child; child = child->next) lispnode(child, level + 1); indent(level); printf(")\n"); } -static void lispover(fz_over *node, int level) +static void lispover(fz_overnode *node, int level) { fz_node *child; indent(level); printf("(over\n"); - for (child = node->child; child; child = child->next) + for (child = node->super.child; child; child = child->next) lispnode(child, level + 1); indent(level); printf(")\n"); } -static void lispmask(fz_mask *node, int level) +static void lispmask(fz_masknode *node, int level) { fz_node *child; indent(level); printf("(mask\n"); - for (child = node->child; child; child = child->next) + for (child = node->super.child; child; child = child->next) lispnode(child, level + 1); indent(level); printf(")\n"); } -static void lispblend(fz_blend *node, int level) +static void lispblend(fz_blendnode *node, int level) { fz_node *child; indent(level); printf("(blend-%d\n", node->mode); - for (child = node->child; child; child = child->next) + for (child = node->super.child; child; child = child->next) lispnode(child, level + 1); indent(level); printf(")\n"); } -static void lisptransform(fz_transform *node, int level) +static void lisptransform(fz_transformnode *node, int level) { indent(level); printf("(transform %g %g %g %g %g %g\n", node->m.a, node->m.b, node->m.c, node->m.d, node->m.e, node->m.f); - lispnode(node->child, level + 1); + lispnode(node->super.child, level + 1); indent(level); printf(")\n"); } -static void lispsolid(fz_solid *node, int level) +static void lispcolor(fz_colornode *node, int level) { indent(level); - printf("(solid %g %g %g)\n", node->r, node->g, node->b); + printf("(color %g %g %g)\n", node->r, node->g, node->b); } -static void lispform(fz_form *node, int level) +static void lisplink(fz_linknode *node, int level) { indent(level); - printf("(form %p)\n", node->tree); + printf("(link %p)\n", node->tree); } -static void lisppath(fz_path *node, int level) +static void lisppath(fz_pathnode *node, int level) { int i; @@ -87,10 +87,10 @@ static void lisppath(fz_path *node, int level) if (node->paint == FZ_STROKE) { printf("(path 'stroke %d %d %g %g ", - node->stroke->linecap, - node->stroke->linejoin, - node->stroke->linewidth, - node->stroke->miterlimit); + node->linecap, + node->linejoin, + node->linewidth, + node->miterlimit); if (node->dash) { printf("%g '( ", node->dash->phase); @@ -107,13 +107,13 @@ static void lisppath(fz_path *node, int level) } printf("\n"); - fz_debugpath(node); + fz_debugpathnode(node); indent(level); printf(")\n"); } -static void lisptext(fz_text *node, int level) +static void lisptext(fz_textnode *node, int level) { int i; @@ -131,18 +131,10 @@ static void lisptext(fz_text *node, int level) printf(")\n"); } -static void lispimage(fz_image *node, int level) +static void lispimage(fz_imagenode *node, int level) { indent(level); - printf("(image %d %d %d %d '", node->w, node->h, node->n, node->bpc); - switch (node->cs) - { - case FZ_CSGRAY: printf("gray"); break; - case FZ_CSRGB: printf("rgb"); break; - case FZ_CSCMYK: printf("cmyk"); break; - default: printf("unknown"); break; - } - printf(")\n"); + printf("(image %d %d %d %d)\n", node->w, node->h, node->n, node->a); } static void lispnode(fz_node *node, int level) @@ -156,16 +148,16 @@ static void lispnode(fz_node *node, int level) switch (node->kind) { - case FZ_NMETA: lispmeta((fz_meta*)node, level); break; - case FZ_NOVER: lispover((fz_over*)node, level); break; - case FZ_NMASK: lispmask((fz_mask*)node, level); break; - case FZ_NBLEND: lispblend((fz_blend*)node, level); break; - case FZ_NTRANSFORM: lisptransform((fz_transform*)node, level); break; - case FZ_NSOLID: lispsolid((fz_solid*)node, level); break; - case FZ_NPATH: lisppath((fz_path*)node, level); break; - case FZ_NTEXT: lisptext((fz_text*)node, level); break; - case FZ_NIMAGE: lispimage((fz_image*)node, level); break; - case FZ_NFORM: lispform((fz_form*)node, level); break; + case FZ_NMETA: lispmeta((fz_metanode*)node, level); break; + case FZ_NOVER: lispover((fz_overnode*)node, level); break; + case FZ_NMASK: lispmask((fz_masknode*)node, level); break; + case FZ_NBLEND: lispblend((fz_blendnode*)node, level); break; + case FZ_NTRANSFORM: lisptransform((fz_transformnode*)node, level); break; + case FZ_NCOLOR: lispcolor((fz_colornode*)node, level); break; + case FZ_NPATH: lisppath((fz_pathnode*)node, level); break; + case FZ_NTEXT: lisptext((fz_textnode*)node, level); break; + case FZ_NIMAGE: lispimage((fz_imagenode*)node, level); break; + case FZ_NLINK: lisplink((fz_linknode*)node, level); break; } } diff --git a/tree/form.c b/tree/form.c deleted file mode 100644 index dd45aad9..00000000 --- a/tree/form.c +++ /dev/null @@ -1,30 +0,0 @@ -#include <fitz.h> - -fz_error * -fz_newform(fz_node **nodep, fz_tree *child) -{ - fz_form *node; - - node = fz_malloc(sizeof (fz_form)); - if (!node) - return fz_outofmem; - *nodep = (fz_node*)node; - - fz_initnode((fz_node*)node, FZ_NFORM); - node->tree = child; - - return nil; -} - -void -fz_freeform(fz_form *node) -{ - fz_free(node); -} - -fz_rect -fz_boundform(fz_form *node, fz_matrix ctm) -{ - return fz_boundtree(node->tree, ctm); -} - diff --git a/tree/image.c b/tree/image.c deleted file mode 100644 index 7991ded3..00000000 --- a/tree/image.c +++ /dev/null @@ -1,49 +0,0 @@ -#include <fitz.h> - -fz_error * -fz_newimage(fz_node **nodep, int w, int h, int n, int bpc, int cs) -{ - fz_image *node; - - node = fz_malloc(sizeof (fz_image)); - if (!node) - return fz_outofmem; - *nodep = (fz_node*)node; - - fz_initnode((fz_node*)node, FZ_NIMAGE); - node->w = w; - node->h = h; - node->n = n; - node->bpc = bpc; - node->cs = cs; - node->data = nil; - - return nil; -} - -void -fz_freeimage(fz_image *node) -{ - fz_free(node->data); - fz_free(node); -} - -fz_rect -fz_boundimage(fz_image *node, fz_matrix ctm) -{ - fz_point ll, lr, ul, ur; - fz_rect r; - - ll = fz_transformpoint(ctm, (fz_point){0,0}); - lr = fz_transformpoint(ctm, (fz_point){1,0}); - ul = fz_transformpoint(ctm, (fz_point){0,1}); - ur = fz_transformpoint(ctm, (fz_point){1,1}); - - r.min.x = MIN4(ll.x, lr.x, ul.x, ur.x); - r.min.y = MIN4(ll.y, lr.y, ul.y, ur.y); - r.max.x = MAX4(ll.x, lr.x, ul.x, ur.x); - r.max.y = MAX4(ll.y, lr.y, ul.y, ur.y); - - return r; -} - diff --git a/tree/mask.c b/tree/mask.c deleted file mode 100644 index 62a469ff..00000000 --- a/tree/mask.c +++ /dev/null @@ -1,50 +0,0 @@ -#include <fitz.h> - -fz_error * -fz_newmask(fz_node **nodep) -{ - fz_mask *node; - - node = fz_malloc(sizeof (fz_mask)); - if (!node) - return fz_outofmem; - *nodep = (fz_node*)node; - - fz_initnode((fz_node*)node, FZ_NMASK); - node->child = nil; - - return nil; -} - -void -fz_freemask(fz_mask *node) -{ - if (node->child) - fz_freenode(node->child); - fz_free(node); -} - -fz_rect -fz_boundmask(fz_mask* node, fz_matrix ctm) -{ - fz_node *child; - fz_rect bbox; - fz_rect r; - - bbox = FZ_INFRECT; - - for (child = node->child; child; child = child->next) - { - r = fz_boundnode(child, ctm); - if (r.max.x >= r.min.x) - { - if (bbox.max.x >= bbox.min.x) - bbox = fz_intersectrects(r, bbox); - else - bbox = r; - } - } - - return bbox; -} - diff --git a/tree/meta.c b/tree/meta.c deleted file mode 100644 index 4d3a2a74..00000000 --- a/tree/meta.c +++ /dev/null @@ -1,37 +0,0 @@ -#include <fitz.h> - -fz_error * -fz_newmeta(fz_node **nodep, fz_obj *info) -{ - fz_meta *node; - - node = fz_malloc(sizeof (fz_meta)); - if (!node) - return fz_outofmem; - *nodep = (fz_node*)node; - - fz_initnode((fz_node*)node, FZ_NMETA); - node->info = fz_keepobj(info); - node->child = nil; - - return nil; -} - -void -fz_freemeta(fz_meta *node) -{ - if (node->child) - fz_freenode(node->child); - if (node->info) - fz_dropobj(node->info); - fz_free(node); -} - -fz_rect -fz_boundmeta(fz_meta *node, fz_matrix ctm) -{ - if (!node->child) - return FZ_INFRECT; - return fz_boundnode(node->child, ctm); -} - diff --git a/tree/node.c b/tree/node.c deleted file mode 100644 index 8b9d48cc..00000000 --- a/tree/node.c +++ /dev/null @@ -1,148 +0,0 @@ -#include <fitz.h> - -void fz_freeover(fz_over* node); -void fz_freemask(fz_mask* node); -void fz_freeblend(fz_blend* node); -void fz_freetransform(fz_transform* node); -void fz_freeform(fz_form* node); -void fz_freesolid(fz_solid* node); -void fz_freepath(fz_path* node); -void fz_freetext(fz_text* node); -void fz_freeimage(fz_image* node); - -fz_rect fz_boundover(fz_over* node, fz_matrix ctm); -fz_rect fz_boundmask(fz_mask* node, fz_matrix ctm); -fz_rect fz_boundblend(fz_blend* node, fz_matrix ctm); -fz_rect fz_boundtransform(fz_transform* node, fz_matrix ctm); -fz_rect fz_boundform(fz_form* node, fz_matrix ctm); -fz_rect fz_boundsolid(fz_solid* node, fz_matrix ctm); -fz_rect fz_boundpath(fz_path* node, fz_matrix ctm); -fz_rect fz_boundtext(fz_text* node, fz_matrix ctm); -fz_rect fz_boundimage(fz_image* node, fz_matrix ctm); - -void -fz_initnode(fz_node *node, fz_nodekind kind) -{ - node->kind = kind; - node->parent = nil; -} - -void -fz_freenode(fz_node *node) -{ - if (node->next) - fz_freenode(node->next); - - switch (node->kind) - { - case FZ_NOVER: - fz_freeover((fz_over *) node); - break; - case FZ_NMASK: - fz_freemask((fz_mask *) node); - break; - case FZ_NBLEND: - fz_freeblend((fz_blend *) node); - break; - case FZ_NTRANSFORM: - fz_freetransform((fz_transform *) node); - break; - case FZ_NFORM: - fz_freeform((fz_form *) node); - break; - case FZ_NSOLID: - fz_freesolid((fz_solid *) node); - break; - case FZ_NPATH: - fz_freepath((fz_path *) node); - break; - case FZ_NTEXT: - fz_freetext((fz_text *) node); - break; - case FZ_NIMAGE: - fz_freeimage((fz_image *) node); - break; - } -} - -fz_rect -fz_boundnode(fz_node *node, fz_matrix ctm) -{ - switch (node->kind) - { - case FZ_NOVER: - return fz_boundover((fz_over *) node, ctm); - case FZ_NMASK: - return fz_boundmask((fz_mask *) node, ctm); - case FZ_NBLEND: - return fz_boundblend((fz_blend *) node, ctm); - case FZ_NTRANSFORM: - return fz_boundtransform((fz_transform *) node, ctm); - case FZ_NFORM: - return fz_boundform((fz_form *) node, ctm); - case FZ_NSOLID: - return fz_boundsolid((fz_solid *) node, ctm); - case FZ_NPATH: - return fz_boundpath((fz_path *) node, ctm); - case FZ_NTEXT: - return fz_boundtext((fz_text *) node, ctm); - case FZ_NIMAGE: - return fz_boundimage((fz_image *) node, ctm); - } - return FZ_INFRECT; -} - -int -fz_isover(fz_node *node) -{ - return node ? node->kind == FZ_NOVER : 0; -} - -int -fz_ismask(fz_node *node) -{ - return node ? node->kind == FZ_NMASK : 0; -} - -int -fz_isblend(fz_node *node) -{ - return node ? node->kind == FZ_NBLEND : 0; -} - -int -fz_istransform(fz_node *node) -{ - return node ? node->kind == FZ_NTRANSFORM : 0; -} - -int -fz_isform(fz_node *node) -{ - return node ? node->kind == FZ_NFORM : 0; -} - -int -fz_issolid(fz_node *node) -{ - return node ? node->kind == FZ_NSOLID : 0; -} - -int -fz_ispath(fz_node *node) -{ - return node ? node->kind == FZ_NPATH : 0; -} - -int -fz_istext(fz_node *node) -{ - return node ? node->kind == FZ_NTEXT : 0; -} - -int -fz_isimage(fz_node *node) -{ - return node ? node->kind == FZ_NIMAGE : 0; -} - diff --git a/tree/node1.c b/tree/node1.c new file mode 100644 index 00000000..c24b974a --- /dev/null +++ b/tree/node1.c @@ -0,0 +1,165 @@ +#include <fitz.h> + +void fz_freemetanode(fz_metanode* node); +void fz_freelinknode(fz_linknode* node); +void fz_freepathnode(fz_pathnode* node); +void fz_freetextnode(fz_textnode* node); +void fz_freeimagenode(fz_imagenode* node); + +fz_rect fz_boundtransformnode(fz_transformnode* node, fz_matrix ctm); +fz_rect fz_boundovernode(fz_overnode* node, fz_matrix ctm); +fz_rect fz_boundmasknode(fz_masknode* node, fz_matrix ctm); +fz_rect fz_boundblendnode(fz_blendnode* node, fz_matrix ctm); +fz_rect fz_boundcolornode(fz_colornode* node, fz_matrix ctm); +fz_rect fz_boundpathnode(fz_pathnode* node, fz_matrix ctm); +fz_rect fz_boundtextnode(fz_textnode* node, fz_matrix ctm); +fz_rect fz_boundimagenode(fz_imagenode* node, fz_matrix ctm); +fz_rect fz_boundshadenode(fz_shadenode* node, fz_matrix ctm); +fz_rect fz_boundlinknode(fz_linknode* node, fz_matrix ctm); +fz_rect fz_boundmetanode(fz_metanode* node, fz_matrix ctm); + +void +fz_initnode(fz_node *node, fz_nodekind kind) +{ + node->kind = kind; + node->parent = nil; + node->child = nil; + node->next = nil; +} + +void +fz_freenode(fz_node *node) +{ + if (node->child) + fz_freenode(node->child); + if (node->next) + fz_freenode(node->next); + + switch (node->kind) + { + case FZ_NTRANSFORM: + case FZ_NOVER: + case FZ_NMASK: + case FZ_NBLEND: + case FZ_NCOLOR: + break; + case FZ_NPATH: + fz_freepathnode((fz_pathnode *) node); + break; + case FZ_NTEXT: + fz_freetextnode((fz_textnode *) node); + break; + case FZ_NIMAGE: + fz_freeimagenode((fz_imagenode *) node); + break; + case FZ_NSHADE: + // XXX fz_freeshadenode((fz_shadenode *) node); + break; + case FZ_NLINK: + fz_freelinknode((fz_linknode *) node); + break; + case FZ_NMETA: + fz_freemetanode((fz_metanode *) node); + break; + } + + fz_free(node); +} + +fz_rect +fz_boundnode(fz_node *node, fz_matrix ctm) +{ + switch (node->kind) + { + case FZ_NTRANSFORM: + return fz_boundtransformnode((fz_transformnode *) node, ctm); + case FZ_NOVER: + return fz_boundovernode((fz_overnode *) node, ctm); + case FZ_NMASK: + return fz_boundmasknode((fz_masknode *) node, ctm); + case FZ_NBLEND: + return fz_boundblendnode((fz_blendnode *) node, ctm); + case FZ_NCOLOR: + return fz_boundcolornode((fz_colornode *) node, ctm); + case FZ_NPATH: + return fz_boundpathnode((fz_pathnode *) node, ctm); + case FZ_NTEXT: + return fz_boundtextnode((fz_textnode *) node, ctm); + case FZ_NIMAGE: + return fz_boundimagenode((fz_imagenode *) node, ctm); + case FZ_NSHADE: + // XXX return fz_boundshadenode((fz_shadenode *) node, ctm); + case FZ_NLINK: + return fz_boundlinknode((fz_linknode *) node, ctm); + case FZ_NMETA: + return fz_boundmetanode((fz_metanode *) node, ctm); + } + return FZ_INFRECT; +} + +int +fz_istransformnode(fz_node *node) +{ + return node ? node->kind == FZ_NTRANSFORM : 0; +} + +int +fz_isovernode(fz_node *node) +{ + return node ? node->kind == FZ_NOVER : 0; +} + +int +fz_ismasknode(fz_node *node) +{ + return node ? node->kind == FZ_NMASK : 0; +} + +int +fz_isblendnode(fz_node *node) +{ + return node ? node->kind == FZ_NBLEND : 0; +} + +int +fz_iscolornode(fz_node *node) +{ + return node ? node->kind == FZ_NCOLOR : 0; +} + +int +fz_ispathnode(fz_node *node) +{ + return node ? node->kind == FZ_NPATH : 0; +} + +int +fz_istextnode(fz_node *node) +{ + return node ? node->kind == FZ_NTEXT : 0; +} + +int +fz_isimagenode(fz_node *node) +{ + return node ? node->kind == FZ_NIMAGE : 0; +} + +int +fz_isshadenode(fz_node *node) +{ + return node ? node->kind == FZ_NSHADE : 0; +} + +int +fz_islinknode(fz_node *node) +{ + return node ? node->kind == FZ_NLINK : 0; +} + +int +fz_ismetanode(fz_node *node) +{ + return node ? node->kind == FZ_NMETA : 0; +} + diff --git a/tree/node2.c b/tree/node2.c new file mode 100644 index 00000000..dc82265d --- /dev/null +++ b/tree/node2.c @@ -0,0 +1,304 @@ +#include <fitz.h> + +/* + * Over + */ + +fz_error * +fz_newovernode(fz_node **nodep) +{ + fz_node *node; + + node = *nodep = fz_malloc(sizeof (fz_overnode)); + if (!node) + return fz_outofmem; + + fz_initnode(node, FZ_NOVER); + + return nil; +} + +fz_rect +fz_boundovernode(fz_overnode *node, fz_matrix ctm) +{ + fz_node *child; + fz_rect bbox; + fz_rect r; + + bbox = FZ_INFRECT; + + for (child = node->super.child; child; child = child->next) + { + r = fz_boundnode(child, ctm); + if (r.max.x >= r.min.x) + { + if (bbox.max.x >= bbox.min.x) + bbox = fz_mergerects(r, bbox); + else + bbox = r; + } + } + + return bbox; +} + +/* + * Mask + */ + +fz_error * +fz_newmasknode(fz_node **nodep) +{ + fz_node *node; + + node = *nodep = fz_malloc(sizeof (fz_masknode)); + if (!node) + return fz_outofmem; + + fz_initnode(node, FZ_NMASK); + + return nil; +} + +fz_rect +fz_boundmasknode(fz_masknode *node, fz_matrix ctm) +{ + fz_node *child; + fz_rect bbox; + fz_rect r; + + bbox = FZ_INFRECT; + + for (child = node->super.child; child; child = child->next) + { + r = fz_boundnode(child, ctm); + if (r.max.x >= r.min.x) + { + if (bbox.max.x >= bbox.min.x) + bbox = fz_intersectrects(r, bbox); + else + bbox = r; + } + } + + return bbox; +} + +/* + * Blend + */ + +fz_error * +fz_newblendnode(fz_node **nodep, fz_blendkind b, int k, int i) +{ + fz_blendnode *node; + + node = fz_malloc(sizeof (fz_blendnode)); + if (!node) + return fz_outofmem; + *nodep = (fz_node*)node; + + fz_initnode((fz_node*)node, FZ_NBLEND); + node->mode = b; + node->knockout = k; + node->isolated = i; + + return nil; +} + +fz_rect +fz_boundblendnode(fz_blendnode *node, fz_matrix ctm) +{ + fz_node *child; + fz_rect bbox; + fz_rect r; + + bbox = FZ_INFRECT; + + for (child = node->super.child; child; child = child->next) + { + r = fz_boundnode(child, ctm); + if (r.max.x >= r.min.x) + { + if (bbox.max.x >= bbox.min.x) + bbox = fz_mergerects(r, bbox); + else + bbox = r; + } + } + + return bbox; +} + +/* + * Transform + */ + +fz_error * +fz_newtransformnode(fz_node **nodep, fz_matrix m) +{ + fz_transformnode *node; + + node = fz_malloc(sizeof (fz_transformnode)); + if (!node) + return fz_outofmem; + *nodep = (fz_node*)node; + + fz_initnode((fz_node*)node, FZ_NTRANSFORM); + node->m = m; + + return nil; +} + +fz_rect +fz_boundtransformnode(fz_transformnode *node, fz_matrix ctm) +{ + if (!node->super.child) + return FZ_INFRECT; + return fz_boundnode(node->super.child, fz_concat(node->m, ctm)); +} + +/* + * Meta info + */ + +fz_error * +fz_newmetanode(fz_node **nodep, fz_obj *info) +{ + fz_metanode *node; + + node = fz_malloc(sizeof (fz_metanode)); + if (!node) + return fz_outofmem; + *nodep = (fz_node*)node; + + fz_initnode((fz_node*)node, FZ_NMETA); + node->info = fz_keepobj(info); + + return nil; +} + +void +fz_freemetanode(fz_metanode *node) +{ + if (node->info) + fz_dropobj(node->info); +} + +fz_rect +fz_boundmetanode(fz_metanode *node, fz_matrix ctm) +{ + if (!node->super.child) + return FZ_INFRECT; + return fz_boundnode(node->super.child, ctm); +} + +/* + * Link to tree + */ + +fz_error * +fz_newlinknode(fz_node **nodep, fz_tree *subtree) +{ + fz_linknode *node; + + node = fz_malloc(sizeof (fz_linknode)); + if (!node) + return fz_outofmem; + *nodep = (fz_node*)node; + + fz_initnode((fz_node*)node, FZ_NLINK); + node->tree = fz_keeptree(subtree); + + return nil; +} + +void +fz_freelinknode(fz_linknode *node) +{ + fz_droptree(node->tree); +} + +fz_rect +fz_boundlinknode(fz_linknode *node, fz_matrix ctm) +{ + return fz_boundtree(node->tree, ctm); +} + +/* + * Solid color + */ + +fz_error * +fz_newcolornode(fz_node **nodep, float r, float g, float b) +{ + fz_colornode *node; + + node = fz_malloc(sizeof (fz_colornode)); + if (!node) + return fz_outofmem; + *nodep = (fz_node*)node; + + fz_initnode((fz_node*)node, FZ_NCOLOR); + node->r = r; + node->g = g; + node->b = b; + + return nil; +} + +fz_rect +fz_boundcolornode(fz_colornode *node, fz_matrix ctm) +{ + /* min > max => no bounds */ + return (fz_rect) { {1,1}, {-1,-1} }; +} + +/* + * Image node + */ + +fz_error * +fz_newimagenode(fz_node **nodep, int w, int h, int n, int a) +{ + fz_imagenode *node; + + node = fz_malloc(sizeof (fz_imagenode)); + if (!node) + return fz_outofmem; + *nodep = (fz_node*)node; + + fz_initnode((fz_node*)node, FZ_NIMAGE); + node->w = w; + node->h = h; + node->n = n; + node->a = a; + + return nil; +} + +void +fz_freeimagenode(fz_imagenode *node) +{ + // XXX fz_dropimage(node->image); +} + +fz_rect +fz_boundimagenode(fz_imagenode *node, fz_matrix ctm) +{ + fz_point ll, lr, ul, ur; + fz_rect r; + + ll = fz_transformpoint(ctm, (fz_point){0,0}); + lr = fz_transformpoint(ctm, (fz_point){1,0}); + ul = fz_transformpoint(ctm, (fz_point){0,1}); + ur = fz_transformpoint(ctm, (fz_point){1,1}); + + r.min.x = MIN4(ll.x, lr.x, ul.x, ur.x); + r.min.y = MIN4(ll.y, lr.y, ul.y, ur.y); + r.max.x = MAX4(ll.x, lr.x, ul.x, ur.x); + r.max.y = MAX4(ll.y, lr.y, ul.y, ur.y); + + return r; +} + diff --git a/tree/over.c b/tree/over.c deleted file mode 100644 index d55bb297..00000000 --- a/tree/over.c +++ /dev/null @@ -1,50 +0,0 @@ -#include <fitz.h> - -fz_error * -fz_newover(fz_node **nodep) -{ - fz_over *node; - - node = fz_malloc(sizeof (fz_over)); - if (!node) - return fz_outofmem; - *nodep = (fz_node*)node; - - fz_initnode((fz_node*)node, FZ_NOVER); - node->child = nil; - - return nil; -} - -void -fz_freeover(fz_over *node) -{ - if (node->child) - fz_freenode(node->child); - fz_free(node); -} - -fz_rect -fz_boundover(fz_over* node, fz_matrix ctm) -{ - fz_node *child; - fz_rect bbox; - fz_rect r; - - bbox = FZ_INFRECT; - - for (child = node->child; child; child = child->next) - { - r = fz_boundnode(child, ctm); - if (r.max.x >= r.min.x) - { - if (bbox.max.x >= bbox.min.x) - bbox = fz_mergerects(r, bbox); - else - bbox = r; - } - } - - return bbox; -} - diff --git a/tree/path.c b/tree/path.c index d21fda56..bab84401 100644 --- a/tree/path.c +++ b/tree/path.c @@ -1,18 +1,21 @@ #include <fitz.h> fz_error * -fz_newpath(fz_path **pathp) +fz_newpathnode(fz_pathnode **pathp) { - fz_path *path; + fz_pathnode *path; - path = *pathp = fz_malloc(sizeof(fz_path)); + path = *pathp = fz_malloc(sizeof(fz_pathnode)); if (!path) return fz_outofmem; fz_initnode((fz_node*)path, FZ_NPATH); path->paint = FZ_FILL; - path->stroke = nil; + path->linecap = 0; + path->linejoin = 0; + path->linewidth = 1.0; + path->miterlimit = 10.0; path->dash = nil; path->len = 0; path->cap = 0; @@ -22,18 +25,21 @@ fz_newpath(fz_path **pathp) } fz_error * -fz_clonepath(fz_path **pathp, fz_path *oldpath) +fz_clonepath(fz_pathnode **pathp, fz_pathnode *oldpath) { - fz_path *path; + fz_pathnode *path; - path = *pathp = fz_malloc(sizeof(fz_path)); + path = *pathp = fz_malloc(sizeof(fz_pathnode)); if (!path) return fz_outofmem; fz_initnode((fz_node*)path, FZ_NPATH); path->paint = FZ_FILL; - path->stroke = nil; + path->linecap = 0; + path->linejoin = 0; + path->linewidth = 1.0; + path->miterlimit = 10.0; path->dash = nil; path->len = oldpath->len; path->cap = oldpath->len; @@ -49,16 +55,14 @@ fz_clonepath(fz_path **pathp, fz_path *oldpath) } void -fz_freepath(fz_path *node) +fz_freepathnode(fz_pathnode *node) { - fz_free(node->stroke); fz_free(node->dash); fz_free(node->els); - fz_free(node); } static fz_error * -growpath(fz_path *path, int n) +growpath(fz_pathnode *path, int n) { int newcap; fz_pathel *newels; @@ -77,7 +81,7 @@ growpath(fz_path *path, int n) } fz_error * -fz_moveto(fz_path *path, float x, float y) +fz_moveto(fz_pathnode *path, float x, float y) { if (growpath(path, 3) != nil) return fz_outofmem; @@ -88,7 +92,7 @@ fz_moveto(fz_path *path, float x, float y) } fz_error * -fz_lineto(fz_path *path, float x, float y) +fz_lineto(fz_pathnode *path, float x, float y) { if (growpath(path, 3) != nil) return fz_outofmem; @@ -99,7 +103,7 @@ fz_lineto(fz_path *path, float x, float y) } fz_error * -fz_curveto(fz_path *path, +fz_curveto(fz_pathnode *path, float x1, float y1, float x2, float y2, float x3, float y3) @@ -117,7 +121,7 @@ fz_curveto(fz_path *path, } fz_error * -fz_curvetov(fz_path *path, float x2, float y2, float x3, float y3) +fz_curvetov(fz_pathnode *path, float x2, float y2, float x3, float y3) { float x1 = path->els[path->len-2].v; float y1 = path->els[path->len-1].v; @@ -125,13 +129,13 @@ fz_curvetov(fz_path *path, float x2, float y2, float x3, float y3) } fz_error * -fz_curvetoy(fz_path *path, float x1, float y1, float x3, float y3) +fz_curvetoy(fz_pathnode *path, float x1, float y1, float x3, float y3) { return fz_curveto(path, x1, y1, x3, y3, x3, y3); } fz_error * -fz_closepath(fz_path *path) +fz_closepath(fz_pathnode *path) { if (growpath(path, 1) != nil) return fz_outofmem; @@ -140,7 +144,7 @@ fz_closepath(fz_path *path) } fz_error * -fz_endpath(fz_path *path, fz_pathkind paint, fz_stroke *stroke, fz_dash *dash) +fz_endpath(fz_pathnode *path, fz_pathkind paint, fz_stroke *stroke, fz_dash *dash) { fz_pathel *newels; @@ -150,8 +154,14 @@ fz_endpath(fz_path *path, fz_pathkind paint, fz_stroke *stroke, fz_dash *dash) path->els = newels; path->paint = paint; - path->stroke = stroke; path->dash = dash; + if (stroke) + { + path->linecap = stroke->linecap; + path->linejoin = stroke->linejoin; + path->linewidth = stroke->linewidth; + path->miterlimit = stroke->miterlimit; + } return nil; } @@ -174,7 +184,7 @@ static inline fz_rect boundexpand(fz_rect r, fz_point p) } fz_rect -fz_boundpath(fz_path *path, fz_matrix ctm) +fz_boundpathnode(fz_pathnode *path, fz_matrix ctm) { fz_point p; fz_rect r = FZ_INFRECT; @@ -204,8 +214,8 @@ fz_boundpath(fz_path *path, fz_matrix ctm) if (path->paint == FZ_STROKE) { - float miterlength = sin(path->stroke->miterlimit / 2.0); - float linewidth = path->stroke->linewidth; + float miterlength = sin(path->miterlimit / 2.0); + float linewidth = path->linewidth; float expand = MAX(miterlength, linewidth) / 2.0; r.min.x -= expand; r.min.y -= expand; @@ -217,7 +227,7 @@ fz_boundpath(fz_path *path, fz_matrix ctm) } void -fz_debugpath(fz_path *path) +fz_debugpathnode(fz_pathnode *path) { float x, y; int i = 0; diff --git a/tree/solid.c b/tree/solid.c deleted file mode 100644 index 37ff55eb..00000000 --- a/tree/solid.c +++ /dev/null @@ -1,33 +0,0 @@ -#include <fitz.h> - -fz_error * -fz_newsolid(fz_node **nodep, float r, float g, float b) -{ - fz_solid *node; - - node = fz_malloc(sizeof (fz_solid)); - if (!node) - return fz_outofmem; - *nodep = (fz_node*)node; - - fz_initnode((fz_node*)node, FZ_NSOLID); - node->r = r; - node->g = g; - node->b = b; - - return nil; -} - -void -fz_freesolid(fz_solid *node) -{ - fz_free(node); -} - -fz_rect -fz_boundsolid(fz_solid *node, fz_matrix ctm) -{ - /* min > max => no bounds */ - return (fz_rect) { {1,1}, {-1,-1} }; -} - diff --git a/tree/text.c b/tree/text.c index 312e3bde..f1992ade 100644 --- a/tree/text.c +++ b/tree/text.c @@ -1,11 +1,11 @@ #include <fitz.h> fz_error * -fz_newtext(fz_text **textp, fz_font *font) +fz_newtextnode(fz_textnode **textp, fz_font *font) { - fz_text *text; + fz_textnode *text; - text = *textp = fz_malloc(sizeof(fz_text)); + text = *textp = fz_malloc(sizeof(fz_textnode)); if (!text) return fz_outofmem; @@ -21,21 +21,21 @@ fz_newtext(fz_text **textp, fz_font *font) } void -fz_freetext(fz_text *text) +fz_freetextnode(fz_textnode *text) { fz_free(text->els); - fz_free(text); -}; +} fz_rect -fz_boundtext(fz_text *text, fz_matrix ctm) +fz_boundtextnode(fz_textnode *text, fz_matrix ctm) { + // FIXME convolve font bbox to all glyph x,y pairs /* fz_rect bounds = fz_boundglyph(text->font, text->els[0], ctm); */ return FZ_INFRECT; } static fz_error * -growtext(fz_text *text, int n) +growtext(fz_textnode *text, int n) { int newcap; fz_textel *newels; @@ -54,7 +54,7 @@ growtext(fz_text *text, int n) } fz_error * -fz_addtext(fz_text *text, int g, float x, float y) +fz_addtext(fz_textnode *text, int g, float x, float y) { if (growtext(text, 1) != nil) return fz_outofmem; diff --git a/tree/transform.c b/tree/transform.c deleted file mode 100644 index 18910d6b..00000000 --- a/tree/transform.c +++ /dev/null @@ -1,35 +0,0 @@ -#include <fitz.h> - -fz_error * -fz_newtransform(fz_node **nodep, fz_matrix m) -{ - fz_transform *node; - - node = fz_malloc(sizeof (fz_transform)); - if (!node) - return fz_outofmem; - *nodep = (fz_node*)node; - - fz_initnode((fz_node*)node, FZ_NTRANSFORM); - node->child = nil; - node->m = m; - - return nil; -} - -void -fz_freetransform(fz_transform *node) -{ - if (node->child) - fz_freenode(node->child); - fz_free(node); -} - -fz_rect -fz_boundtransform(fz_transform *node, fz_matrix ctm) -{ - if (!node->child) - return FZ_INFRECT; - return fz_boundnode(node->child, fz_concat(node->m, ctm)); -} - diff --git a/tree/tree.c b/tree/tree.c index 1a96ec38..7de88e11 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -9,18 +9,31 @@ fz_newtree(fz_tree **treep) if (!tree) return fz_outofmem; + tree->refcount = 1; tree->root = nil; tree->head = nil; return nil; } +fz_tree * +fz_keeptree(fz_tree *tree) +{ + tree->refcount ++; + return tree; +} + void -fz_freetree(fz_tree *tree) +fz_droptree(fz_tree *tree) { - if (tree->root) - fz_freenode(tree->root); - fz_free(tree); + tree->refcount --; + + if (tree->refcount == 0) + { + if (tree->root) + fz_freenode(tree->root); + fz_free(tree); + } } fz_rect @@ -32,32 +45,16 @@ fz_boundtree(fz_tree *tree, fz_matrix ctm) } void -fz_insertnode(fz_node *node, fz_node *child) +fz_insertnode(fz_node *parent, fz_node *child) { - child->parent = node; - - if (fz_isover(node)) - { - child->next = ((fz_over*)node)->child; - ((fz_over*)node)->child = child; - } - - if (fz_ismask(node)) - { - child->next = ((fz_mask*)node)->child; - ((fz_mask*)node)->child = child; - } - - if (fz_isblend(node)) - { - child->next = ((fz_blend*)node)->child; - ((fz_blend*)node)->child = child; - } - - if (fz_istransform(node)) - { - child->next = ((fz_transform*)node)->child; - ((fz_transform*)node)->child = child; - } + assert(fz_istransformnode(parent) || + fz_isovernode(parent) || + fz_ismasknode(parent) || + fz_isblendnode(parent) || + fz_ismetanode(parent)); + + child->parent = parent; + child->next = parent->child; + parent->child = child; } |