diff options
41 files changed, 3 insertions, 9515 deletions
diff --git a/main/pcl6_gcc.mak b/main/pcl6_gcc.mak index 34a0c8d50..9c7e4a7ee 100644 --- a/main/pcl6_gcc.mak +++ b/main/pcl6_gcc.mak @@ -23,11 +23,7 @@ GLSRCDIR?=../gs/src PCLSRCDIR?=../pcl PLSRCDIR?=../pl PXLSRCDIR?=../pxl -ifeq ($(MET_INCLUDED), TRUE) -XPSSRCDIR?=../met -else XPSSRCDIR?=../xps -endif COMMONDIR?=../common MAINSRCDIR?=../main @@ -73,29 +69,19 @@ XPSOBJDIR?=$(GENDIR) ifeq ($(XPS_INCLUDED), TRUE) TARGET_DEVS?=$(PXLOBJDIR)/pxl.dev $(PCLOBJDIR)/pcl5c.dev $(PCLOBJDIR)/hpgl2c.dev $(XPSOBJDIR)/xps.dev else -ifeq ($(MET_INCLUDED), TRUE) -TARGET_DEVS?=$(PXLOBJDIR)/pxl.dev $(PCLOBJDIR)/pcl5c.dev $(PCLOBJDIR)/hpgl2c.dev $(XPSOBJDIR)/xps.dev -else TARGET_DEVS?=$(PXLOBJDIR)/pxl.dev $(PCLOBJDIR)/pcl5c.dev $(PCLOBJDIR)/hpgl2c.dev endif -endif TARGET_XE?=$(GENDIR)/pcl6 TARGET_LIB?=$(GENDIR)/pcl6.a MAIN_OBJ?=$(PLOBJDIR)/plmain.$(OBJ) $(PLOBJDIR)/plimpl.$(OBJ) PCL_TOP_OBJ?=$(PCLOBJDIR)/pctop.$(OBJ) PXL_TOP_OBJ?=$(PXLOBJDIR)/pxtop.$(OBJ) -ifeq ($(MET_INCLUDED), TRUE) -XPS_TOP_OBJ?=$(XPSOBJDIR)/mettop.$(OBJ) -TOP_OBJ+= $(PCL_TOP_OBJ) $(PXL_TOP_OBJ) $(XPS_TOP_OBJ) -XCFLAGS?=-DXPS_INCLUDED -else ifeq ($(XPS_INCLUDED), TRUE) XPS_TOP_OBJ?=$(XPSOBJDIR)/xpstop.$(OBJ) TOP_OBJ+= $(PCL_TOP_OBJ) $(PXL_TOP_OBJ) $(XPS_TOP_OBJ) XCFLAGS?=-DXPS_INCLUDED else TOP_OBJ+= $(PCL_TOP_OBJ) $(PXL_TOP_OBJ) -endif endif # note agfa gives its libraries incompatible names so they cannot be @@ -135,7 +121,7 @@ UFST_ROMFS_ARGS?=-b \ EXTRALIBS?= $(UFST_LIB)if_lib.a $(UFST_LIB)fco_lib.a $(UFST_LIB)tt_lib.a $(UFST_LIB)if_lib.a UFSTFONTDIR?=/usr/local/fontdata5.0/ -endif +endif # PL_SCALER = ufst # flags for artifex scaler ifeq ($(PL_SCALER), afs) @@ -150,15 +136,10 @@ ifeq ($(ROMFONTS), true) PL_SCALER=afs XLDFLAGS=-L../pl/ EXTRALIBS=-lttffont -endif - -endif +endif # ROMFONTS +endif # PL_SCALER = afs -ifeq ($(MET_INCLUDED), TRUE) -# include the xml parser library -EXTRALIBS+=-lexpat -endif ifeq ($(XPS_INCLUDED), TRUE) # include the xml parser library EXTRALIBS+=-lexpat @@ -233,9 +214,6 @@ include $(COMMONDIR)/ugcc_top.mak include $(PLSRCDIR)/pl.mak include $(PXLSRCDIR)/pxl.mak include $(PCLSRCDIR)/pcl.mak -ifeq ($(MET_INCLUDED), TRUE) -include $(XPSSRCDIR)/met.mak -endif ifeq ($(XPS_INCLUDED), TRUE) include $(XPSSRCDIR)/xps.mak endif diff --git a/met/met.mak b/met/met.mak deleted file mode 100644 index 07e93a82c..000000000 --- a/met/met.mak +++ /dev/null @@ -1,143 +0,0 @@ -XPSSRC = $(XPSSRCDIR)$(D) -XPSGEN = $(XPSGENDIR)$(D) -XPSOBJ = $(XPSOBJDIR)$(D) -XPSO_ = $(O_)$(XPSOBJ) - -XPSCCC = $(CC_) $(I_)$(XPSSRCDIR)$(_I) $(I_)$(XPSGENDIR)$(_I) $(I_)$(PLSRCDIR)$(_I) $(I_)$(GLSRCDIR)$(_I) $(C_) - -# $(I_)$(EXPATINCDIR)$(_I) - -# Define the name of this makefile. -XPS_MAK = $(XPSSRC)met.mak - -met.clean: met.config-clean met.clean-not-config-clean - -met.clean-not-config-clean: - $(RM_) $(XPSOBJ)*.$(OBJ) - -met.config-clean: clean_gs - $(RM_) $(XPSOBJ)*.dev - $(RM_) $(XPSOBJ)devs.tr5 - -# NB needs expat dependencies. - -# NB hack - we don't seem to be keeping up with dependencies so make -# all .h files dependent and include them in each target... fix me -# later - -XPSINCLUDES=$(XPSSRC)*.h - -metgstate_h = $(XPSSRC)metgstate.h - -metparse_h = $(XPSSRC)metparse.h \ - $(gx_h) - -metstate_h = $(XPSSRC)metstate.h \ - $(gx_h) - -metsimple_h = $(metsimple.h) - -metcomplex_h = $(XPSSRC)metcomplex.h \ - $(metsimple_h) - -metutil_h = $(XPSSRC)metutil.h - -zipparse_h = $(XPSSRC)zipparse.h - -$(XPSOBJ)metrecorder.$(OBJ): $(XPSSRC)metrecorder.c $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)metrecorder.c $(XPSO_)metrecorder.$(OBJ) - - -$(XPSOBJ)metcanvas.$(OBJ): $(XPSSRC)metcanvas.c $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)metcanvas.c $(XPSO_)metcanvas.$(OBJ) - -$(XPSOBJ)xps_clip.$(OBJ): $(XPSSRC)xps_clip.c $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)xps_clip.c $(XPSO_)xps_clip.$(OBJ) - -$(XPSOBJ)metimage.$(OBJ): $(XPSSRC)metimage.c $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)metimage.c $(XPSO_)metimage.$(OBJ) - -$(XPSOBJ)xps_gradient_brush.$(OBJ): $(XPSSRC)xps_gradient_brush.c $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)xps_gradient_brush.c $(XPSO_)xps_gradient_brush.$(OBJ) - -$(XPSOBJ)xps_gradient_stop.$(OBJ): $(XPSSRC)xps_gradient_stop.c $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)xps_gradient_stop.c $(XPSO_)xps_gradient_stop.$(OBJ) - -$(XPSOBJ)xps_visual_brush.$(OBJ): $(XPSSRC)xps_visual_brush.c $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)xps_visual_brush.c $(XPSO_)xps_visual_brush.$(OBJ) - -$(XPSOBJ)metpage.$(OBJ): $(XPSSRC)metpage.c $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)metpage.c $(XPSO_)metpage.$(OBJ) - -$(XPSOBJ)metpath.$(OBJ): $(XPSSRC)metpath.c $(metutil_h) $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)metpath.c $(XPSO_)metpath.$(OBJ) - -$(XPSOBJ)metglyphs.$(OBJ): $(XPSSRC)metglyphs.c $(metutil_h) $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)metglyphs.c $(XPSO_)metglyphs.$(OBJ) - -$(XPSOBJ)metgstate.$(OBJ): $(XPSSRC)metgstate.c $(metgstate_h) $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)metgstate.c $(XPSO_)metgstate.$(OBJ) - -$(XPSOBJ)metutil.$(OBJ): $(XPSSRC)metutil.c $(metutil_h) $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)metutil.c $(XPSO_)metutil.$(OBJ) - -$(XPSOBJ)metparse.$(OBJ): $(XPSSRC)metparse.c \ - $(metparse_h) $(metcomplex_h) $(metelement_h)\ - $(memory__h) $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)metparse.c $(XPSO_)metparse.$(OBJ) - -$(XPSOBJ)metstate.$(OBJ): $(XPSSRC)metstate.c \ - $(metstate_h) $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)metstate.c $(XPSO_)metstate.$(OBJ) - -$(XPSOBJ)metelement.$(OBJ): $(XPSSRC)metelement.c $(metelement_h) $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)metelement.c $(XPSO_)metelement.$(OBJ) - -$(XPSOBJ)metundone.$(OBJ): $(XPSSRC)metundone.c $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)metundone.c $(XPSO_)metundone.$(OBJ) - -$(XPSOBJ)zippart.$(OBJ): $(XPSSRC)zippart.c $(zipparse_h) $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)zippart.c $(XPSO_)zippart.$(OBJ) - -$(XPSOBJ)zipparse.$(OBJ): $(XPSSRC)zipparse.c $(zipparse_h) $(pltop_h) $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)zipparse.c $(XPSO_)zipparse.$(OBJ) - -$(XPSOBJ)xps_image_jpeg.$(OBJ): $(XPSSRC)xps_image_jpeg.c $(xps_error_h) $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)xps_image_jpeg.c $(XPSO_)xps_image_jpeg.$(OBJ) - -$(XPSOBJ)xps_image_png.$(OBJ): $(XPSSRC)xps_image_png.c $(xps_error_h) $(XPSINCLUDES) - $(XPSCCC) $(I_)$(PSRCDIR)$(_I) $(XPSSRC)xps_image_png.c $(XPSO_)xps_image_png.$(OBJ) - -$(XPSOBJ)xps_image_tiff.$(OBJ): $(XPSSRC)xps_image_tiff.c $(xps_error_h) $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)xps_image_tiff.c $(XPSO_)xps_image_tiff.$(OBJ) - -$(XPSOBJ)xps_gradient_draw.$(OBJ): $(XPSSRC)xps_gradient_draw.c $(xps_error_h) $(XPSINCLUDES) - $(XPSCCC) $(XPSSRC)xps_gradient_draw.c $(XPSO_)xps_gradient_draw.$(OBJ) - -$(XPS_TOP_OBJ): $(XPSSRC)mettop.c \ - $(metstate_h) \ - $(pltop_h) $(XPSINCLUDES) - $(CP_) $(XPSGEN)pconf.h $(XPSGEN)pconfig.h - $(XPSCCC) $(XPSSRC)mettop.c $(XPSO_)mettop.$(OBJ) - -XPS_OBJS=$(XPSOBJ)metparse.$(OBJ) $(XPSOBJ)metstate.$(OBJ) \ - $(XPSOBJ)metundone.$(OBJ) $(XPSOBJ)metpage.$(OBJ) \ - $(XPSOBJ)metelement.$(OBJ) $(XPSOBJ)metpath.$(OBJ)\ - $(XPSOBJ)metglyphs.$(OBJ) $(XPSOBJ)metutil.$(OBJ) \ - $(XPSOBJ)metimage.$(OBJ) \ - $(XPSOBJ)xps_clip.$(OBJ) \ - $(XPSOBJ)xps_gradient_brush.$(OBJ) \ - $(XPSOBJ)xps_gradient_stop.$(OBJ) \ - $(XPSOBJ)xps_visual_brush.$(OBJ) \ - $(XPSOBJ)zipparse.$(OBJ) $(XPSOBJ)zippart.$(OBJ) \ - $(XPSOBJ)xps_image_jpeg.$(OBJ) \ - $(XPSOBJ)xps_image_png.$(OBJ) \ - $(XPSOBJ)xps_image_tiff.$(OBJ) \ - $(XPSOBJ)xps_gradient_draw.$(OBJ) \ - $(XPSOBJ)metgstate.$(OBJ) \ - $(XPSOBJ)metcanvas.$(OBJ) \ - $(XPSOBJ)metrecorder.$(OBJ) - -$(XPSOBJ)xps.dev: $(XPS_MAK) $(ECHOGS_XE) $(XPS_OBJS) - $(SETMOD) $(XPSOBJ)xps $(XPS_OBJS) - diff --git a/met/metcanvas.c b/met/metcanvas.c deleted file mode 100644 index bec3e8571..000000000 --- a/met/metcanvas.c +++ /dev/null @@ -1,258 +0,0 @@ -/* Portions Copyright (C) 2007 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id:$ */ - -#include <stdlib.h> /* NB for atof */ -#include "memory_.h" -#include "ctype_.h" -#include "metcomplex.h" -#include "metstate.h" -#include "metelement.h" -#include "metutil.h" -#include "metparse.h" -#include "gserror.h" -#include "gscoord.h" -#include "gxfixed.h" /* for gdevbbox.h stuff */ -#include "gxdevcli.h" /* for gdevbbox.h stuff */ -#include "gdevbbox.h" -#include "metgstate.h" - -private int -Canvas_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_Canvas *aCanvas = - (CT_Canvas *)gs_alloc_bytes(ms->memory, - sizeof(CT_Canvas), - "Canvas_cook"); - int i; - - memset(aCanvas, 0, sizeof(CT_Canvas)); - aCanvas->Opacity = 1; -#define MYSET(field, value) \ - met_cmp_and_set((field), attr[i], attr[i+1], (value)) - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - if (!MYSET(&aCanvas->RenderTransform, "RenderTransform")) - ; - else if (!MYSET(&aCanvas->Clip, "Clip")) - ; - else if (!MYSET(&aCanvas->Name, "Name")) - ; - else if (!MYSET(&aCanvas->EdgeMode, "EdgeMode")) - ; - else if (!MYSET(&aCanvas->FixedPage, "FixedPage")) - ; - else if (!MYSET(&aCanvas->Key, "Key")) - ; - else if (!strcmp(attr[i], "Opacity")) { - aCanvas->Opacity = atof(attr[i+1]); - } - else - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } -#undef MYSET - /* copy back the data for the parser. */ - *ppdata = aCanvas; - return 0; -#ifdef NOT_YET - return 1; /* record me */ -#endif -} - -/* NB duplication */ -private bool is_Data_delimeter(char b) -{ - return (b == ',') || (isspace(b)); -} - -/* action associated with this element */ -private int -Canvas_action(void *data, met_state_t *ms) -{ - CT_Canvas *aCanvas = data; - gs_state *pgs = ms->pgs; - int code; - gs_matrix canvas_mat; - - if ((code = gs_gsave(pgs)) < 0) - return gs_rethrow(code, "gsave failed"); - if ((code = met_get_transform(&canvas_mat, aCanvas->RenderTransform)) < 0) - return gs_rethrow(code, "transform failed"); - if ((code = gs_concat(pgs, &canvas_mat)) < 0) - return gs_rethrow(code, "concat failed"); - return 0; -} - -private int -Canvas_done(void *data, met_state_t *ms) -{ - CT_Canvas *aCanvas = (CT_Canvas *)data; - - gs_grestore(ms->pgs); -#ifdef NOT_YET - int i; - data_element_t *ds = (data_element_t *)data; - gs_state *pgs = ms->pgs; - gs_memory_t *mem = ms->memory; - gx_device_bbox bdev; - - gs_gsave(pgs); - gx_device_bbox_init(&bdev, NULL, mem); - /* bias the reference count idiocy since bdev is an automatic - variable that shouldn't be freed */ - gx_device_retain(&bdev, true); - gs_setdevice_no_erase(pgs, &bdev); - - for (i = 1; i < ms->entries_recorded; i++) { - /* already cooked so just do action and destructor. assume - the parser has not given us elements without - implementations. */ - met_element_t *metp = ds[i].met_element_procs; - void *ds_data = ds[i].data; - - int code = (*metp->action)(ds_data, ms); - if (code < 0) - return -1; - code = (*metp->done)(ds_data, ms); - if (code < 0) - return -1; - } - { - gs_rect extant_rect; - gx_device_bbox_bbox(&bdev, &extant_rect); - dprintf4(mem, "Bounding box: [%g %g %g %g]\n", - extant_rect.p.x, extant_rect.p.y, extant_rect.q.x, extant_rect.q.y); - } - gs_grestore(pgs); - gs_free_object(ms->memory, ds[0].data, "Canvas_done"); -#endif - - - gs_free_object(ms->memory, aCanvas->RenderTransform, "Canvas_done"); - gs_free_object(ms->memory, aCanvas->Clip, "Canvas_done"); - gs_free_object(ms->memory, aCanvas->OpacityMask, "Canvas_done"); - gs_free_object(ms->memory, aCanvas->Name, "Canvas_done"); - gs_free_object(ms->memory, aCanvas->EdgeMode, "Canvas_done"); - gs_free_object(ms->memory, aCanvas->FixedPage, "Canvas_done"); - gs_free_object(ms->memory, aCanvas->Key, "Canvas_done"); - gs_free_object(ms->memory, aCanvas, "Canvas_done"); - - return 0; -} - - -const met_element_t met_element_procs_Canvas = { - "Canvas", - { - Canvas_cook, - Canvas_action, - Canvas_done - } -}; - -private int -Canvas_RenderTransform_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - *ppdata = NULL; - return 0; -} - -private int -Canvas_RenderTransform_action(void *data, met_state_t *ms) -{ - return 0; -} - -private int -Canvas_RenderTransform_done(void *data, met_state_t *ms) -{ - if (data != 0) - return gs_throw(-1, "bad food"); - return 0; /* incomplete */ -} - -const met_element_t met_element_procs_Canvas_RenderTransform = { - "Canvas_RenderTransform", - { - Canvas_RenderTransform_cook, - Canvas_RenderTransform_action, - Canvas_RenderTransform_done - } -}; - -private int -MatrixTransform_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_MatrixTransform *aMatrixTransform = - (CT_MatrixTransform *)gs_alloc_bytes(ms->memory, - sizeof(CT_MatrixTransform), - "MatrixTransform_cook"); - int i; - - memset(aMatrixTransform, 0, sizeof(CT_MatrixTransform)); - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - - if(!met_cmp_and_set(&aMatrixTransform->Matrix, attr[i], attr[i+1], "Matrix")) - ; - // NB: x:Key iff in a Resource Dictionary - else - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - /* copy back the data for the parser. */ - *ppdata = aMatrixTransform; - return 0; -} - -private int -MatrixTransform_action(void *data, met_state_t *ms) -{ - CT_MatrixTransform *aMatrixTransform = data; - gs_state *pgs = ms->pgs; - int code; - gs_matrix canvas_mat; - - if (aMatrixTransform->Matrix == 0) - return gs_throw(-1, "Matix missing"); - - if ((code = met_get_transform(&canvas_mat, aMatrixTransform->Matrix)) < 0) - return gs_rethrow(code, "transform failed"); - - if ((code = gs_concat(pgs, &canvas_mat)) < 0) - return gs_rethrow(code, "concat failed"); - - return 0; -} - -private int -MatrixTransform_done(void *data, met_state_t *ms) -{ - CT_MatrixTransform *aMatrixTransform = data; - gs_free_object(ms->memory, aMatrixTransform->Matrix, "MatrixTransform_done"); - gs_free_object(ms->memory, aMatrixTransform, "MatrixTransform_done"); - return 0; -} - -const met_element_t met_element_procs_MatrixTransform = { - "MatrixTransform", - { - MatrixTransform_cook, - MatrixTransform_action, - MatrixTransform_done - } -}; - diff --git a/met/metcomplex.h b/met/metcomplex.h deleted file mode 100644 index 583ae64f0..000000000 --- a/met/metcomplex.h +++ /dev/null @@ -1,346 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ -/* $Id$*/ - -/* metcomplex.h */ - -/* metro complex types */ - -#ifndef metcomplex_INCLUDED -# define metcomplex_INCLUDED - -#include "metsimple.h" - -typedef struct CT_ArcSegment_s { - char *Point; - char *Size; - ST_Double RotationAngle; - ST_Boolean IsLargeArc; - char *SweepDirection; - ST_Boolean IsStroked; -} CT_ArcSegment; - - -typedef enum { - GradientStops, -} CT_CP_GradientStops; - -typedef ST_Name CT_LinkTarget; - -typedef struct CT_CP_LinkTargets_s { - CT_LinkTarget LinkTarget; - struct CT_CP_LinkTarget_s *next; -} CT_CP_LinkTarget; - -typedef struct CT_Canvas_s { - char *RenderTransform; - char *Clip; - double Opacity; - char *OpacityMask; - char *Name; - char *EdgeMode; - char *FixedPage; /* NB wrong see schema */ - char *Key; /* NB wrong see schema */ - /* NB missing fields see schema */ -} CT_Canvas; - -typedef struct CT_Glyphs_s { - int BidiLevel; - char *CaretStops; - ST_UnicodeString DeviceFontName; - char *Fill; - ST_GEZero FontRenderingEmSize; - char *FontUri; /* NB wrong see schema */ - ST_Double OriginX; - ST_Double OriginY; - ST_Boolean IsSideWays; - char *Indices; - char *UnicodeString; - char *StyleSimulations; - char *RenderTransform; - char *Clip; - ST_ZeroOne Opacity; - char *OpacityMask; - struct { - unsigned BidiLevel : 1; - unsigned OriginX : 1; - unsigned OriginY : 1; - unsigned FontRenderingEmSize : 1; - unsigned IsSideWays : 1; - unsigned Opacity : 1; - } avail; - -} CT_Glyphs; - -typedef struct CT_MatrixTransform_s { - char *Matrix; -} CT_MatrixTransform; - -typedef struct CT_SolidColorBrush_s { - ST_ZeroOne Opacity; - ST_Name Key; /* NB wrong see schema */ - char *Color; -} CT_SolidColorBrush; - -typedef struct CT_LinearGradientBrush_s { - ST_ZeroOne Opacity; - ST_Name Key; - ST_ClrIntMode ColorInterpolationMode; - ST_SpreadMethod SpreadMethod; - ST_Name MappingMode; - struct CT_GradientStop_s *GradientStops; - ST_RscRefMatrix Transform; - ST_Point StartPoint; - ST_Point EndPoint; -} CT_LinearGradientBrush; - -typedef struct CT_RadialGradientBrush_s { - ST_ZeroOne Opacity; - ST_Name Key; - ST_ClrIntMode ColorInterpolationMode; - ST_SpreadMethod SpreadMethod; - ST_Name MappingMode; - struct CT_GradientStop_s *GradientStops; - ST_RscRefMatrix Transform; - ST_Point Center; - ST_Point GradientOrigin; - ST_GEZero RadiusX; - ST_GEZero RadiusY; -} CT_RadialGradientBrush; - -typedef struct CT_VisualBrush_s { - ST_ZeroOne Opacity; - ST_Name Key; /* NB wrong see schema */ - ST_RscRefMatrix Transform; - ST_ViewBox Viewbox; - ST_ViewBox Viewport; - ST_Stretch Fill; /* NB check this */ - ST_TileMode TileMode; - ST_ViewUnits ViewboxUnits; - ST_ViewUnits ViewportUnits; - ST_RscRef Visual; -} CT_VisualBrush; - -/* NB refactor common fields in brushes */ -typedef struct CT_ImageBrush_s { - ST_ZeroOne Opacity; - char *Key; /* NB wrong see schema */ - char *Transform; - char *Viewbox; - char *Viewport; - ST_Stretch Fill; /* NB check this */ - char *TileMode; - char *ViewboxUnits; - char *ViewportUnits; - char *ImageSource; /* NB wrong */ -} CT_ImageBrush; - -typedef struct CT_PathGeometry_s { - ST_AbbrGeom Figures; - char *FillRule; - ST_RscRefMatrix Transform; - /* nb incomplete */ -} CT_PathGeometry; - -/* NB wrong, see schema */ -typedef struct CT_ResourceDictionary_s { - ST_Name anyURI; - union { - CT_Canvas Canvas; - CT_Glyphs Glyphs; - /* nb - uncomment and unravel circular - definitions - exercise for the reader. - CT_PATH Path */ - CT_SolidColorBrush SolidColorBrush; - CT_LinearGradientBrush LinearGradientBrush; - CT_RadialGradientBrush RadialGradientBrush; - CT_VisualBrush VisualBrush; - CT_ImageBrush ImageBrush; - CT_MatrixTransform MatrixTransform; - CT_PathGeometry PathGeometry; - } res; - ST_Name choice; /* nb the selector is yet another string */ -} CT_ResourceDictionary; - -/* NB check */ -typedef struct CT_CP_Brush_s { - union { - CT_SolidColorBrush SolidColorBrush; - CT_ImageBrush ImageBrush; - CT_VisualBrush VisualBrush; - CT_LinearGradientBrush LinearGradientBrush; - CT_ResourceDictionary RadialGradientBrush; - } Brush; - ST_Name choice; -} CT_CP_Brush; - -typedef struct CT_CP_Resources_s { - CT_ResourceDictionary ResourceDictionary; -} CT_CP_Resources; - -typedef struct CT_CP_Transform_s { - CT_MatrixTransform MatrixTransform; - struct CT_CP_Transform_s *next; -} CT_CP_Transform; - - -typedef struct CT_DocumentReference_s { - ST_Name anyURI; -} CT_DocumentReference; - - -typedef struct CT_PageContent_s { - ST_Name anyUri; /* nb wrong */ - ST_GEOne Width; - ST_GEOne Height; - CT_CP_LinkTarget LinkTargets; -} CT_PageContent; - -typedef struct CT_FixedDocument_s { - CT_PageContent PageContent; - struct CT_FixedDocument_s *next; -} CT_FixedDocument; - -typedef struct CT_FixedDocumentSequence_s { - CT_DocumentReference DocumentReference; - struct CT_FixedDocumentSequence_s *next; -} CT_FixedDocumentSequence; - - -typedef struct CT_GradientStop_s { - ST_Color Color; - ST_ZeroOne Offset; - struct CT_GradientStop_s *next; -} CT_GradientStop; - -/* nb line segment variants have the same structure */ -typedef struct CT_PolyLineSegment_s { - char *Points; - ST_Boolean isStroked; - struct { - unsigned Points : 1; - unsigned isStroked : 1; - } avail; -} CT_PolyLineSegment; - -typedef struct CT_PolyQuadraticBezierSegment_s { - char *Points; - ST_Boolean isStroked; -} CT_PolyQuadraticBezierSegment; - -typedef struct CT_PolyBezierSegment_s { - char *Points; - ST_Boolean isStroked; -} CT_PolyBezierSegment; - -typedef struct CT_PathFigure_s { - ST_Boolean isClosed; - char *StartPoint; - ST_Boolean isFilled; - union { - CT_ArcSegment ArcSegment; - CT_PolyBezierSegment PolyBezierSegment; - CT_PolyLineSegment PolyLineSegment; - CT_PolyQuadraticBezierSegment PolyQuadraticBezierSegment; - } seg; - ST_Name choice; -} CT_PathFigure; - -typedef struct CT_CP_Geometry { - CT_PathGeometry PathGeometry; -} CT_CP_Geometry; - -typedef struct CT_Path_s { - char *Data; - char *Fill; - ST_RscRefMatrix RenderTransform; - ST_RscRefAbbrGeomF Clip; - ST_ZeroOne Opacity; - ST_RscRef OpacityMask; - char *Stroke; - ST_EvenArrayPos StrokeDashArray; - ST_DashCap StrokeDashCap; - ST_Double StrokeDashOffset; - ST_LineCap StrokeEndLineCap; - ST_LineCap StrokeStartLineCap; - ST_LineJoin StrokeLineJoin; - ST_GEOne StrokeMiterLimit; - ST_GEZero StrokeThickness; - ST_Name Name; - CT_CP_Transform Path_RenderTransform; - CT_CP_Geometry Path_Clip; - CT_CP_Brush Path_OpacityMask; - CT_CP_Brush Path_Fill; - CT_CP_Brush Path_Stroke; - CT_CP_Geometry Path_Data; - /* incomplete see schema */ - struct { - unsigned Data : 1; - unsigned Fill : 1; - unsigned RenderTransform : 1; - unsigned Clip : 1; - unsigned Opacity : 1; - unsigned OpacityMask : 1; - unsigned Stroke : 1; - unsigned StrokeDashArray : 1; - unsigned StrokeDashCap : 1; - unsigned StrokeDashOffset : 1; - unsigned StrokeEndLineCap : 1; - unsigned StrokeStartLineCap : 1; - unsigned StrokeLineJoin : 1; - unsigned StrokeMiterLimit : 1; - unsigned StrokeThickness : 1; - unsigned Name : 1; - unsigned Path_RenderTransform : 1; - unsigned Path_Clip : 1; - unsigned Path_OpacityMask : 1; - unsigned Path_Fill : 1; - unsigned Path_Stroke : 1; - unsigned Path_Data : 1; - } avail; -} CT_Path; - -typedef struct CT_FixedPage_s { - ST_GEOne Width; - ST_GEOne Height; - char *ContentBox; - char *BleedBox; - ST_Matrix RenderTransform; - /* nb - not sure about xml:lang */ - ST_Name Name; - /* nb parts missing */ - union { - CT_Canvas Canvas; - CT_Glyphs Glyphs; - CT_Path Path; - } vis; - ST_Name choice; - struct { - unsigned Width : 1; - unsigned Height : 1; - unsigned ContentBox : 1; - unsigned BleedBox : 1; - unsigned RenderTransform : 1; - unsigned Name : 1; - } avail; -} CT_FixedPage; - -typedef struct CT_CP_Visual_s { - union { - CT_Canvas Canvas; - CT_Glyphs Glyphs; - CT_Path Path; - } vis; - ST_Name choice; -} CT_CP_Visual; - -#endif /* metcomplex_INCLUDED */ diff --git a/met/metelement.c b/met/metelement.c deleted file mode 100644 index 1acee5451..000000000 --- a/met/metelement.c +++ /dev/null @@ -1,103 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ -/* $Id:*/ - -/* metelement.c */ - -#include "memory_.h" -#include "metelement.h" - -/* generate table entries */ -#define ENTRY(element)\ - &met_element_procs_ ## element - -/* table of elements (not the periodic table) - these should be in - alpha order. */ -const met_element_t *met_element_table[] = { - ENTRY(ArcSegment), - ENTRY(Canvas), - ENTRY(Canvas_Clip), - ENTRY(Canvas_OpacityMask), - ENTRY(Canvas_RenderTransform), - ENTRY(Canvas_Resources), - ENTRY(DocumentReference), - ENTRY(FixedDocument), - ENTRY(FixedDocumentSequence), - ENTRY(FixedPage), - ENTRY(FixedPage_RenderTransform), - ENTRY(FixedPage_Resources), - ENTRY(Glyphs), - ENTRY(Glyphs_Clip), - ENTRY(Glyphs_Fill), - ENTRY(Glyphs_OpacityMask), - ENTRY(Glyphs_RenderTransform), - ENTRY(GradientStop), - ENTRY(ImageBrush), - ENTRY(ImageBrush_Transform), - ENTRY(LinearGradientBrush), - ENTRY(LinearGradientBrush_GradientStops), - ENTRY(LinearGradientBrush_Transform), - ENTRY(LinkTarget), - ENTRY(MatrixTransform), - ENTRY(PageContent), - ENTRY(PageContent_LinkTargets), - ENTRY(Path), - ENTRY(Path_Clip), - ENTRY(Path_Data), - ENTRY(Path_Fill), - ENTRY(Path_OpacityMask), - ENTRY(Path_RenderTransform), - ENTRY(Path_Stroke), - ENTRY(PathFigure), - ENTRY(PathGeometry), - ENTRY(PathGeometry_Transform), - ENTRY(PolyBezierSegment), - ENTRY(PolyLineSegment), - ENTRY(PolyQuadraticBezierSegment), - ENTRY(RadialGradientBrush), - ENTRY(RadialGradientBrush_GradientStops), - ENTRY(RadialGradientBrush_Transform), - ENTRY(ResourceDictionary), - ENTRY(SolidColorBrush), - ENTRY(VisualBrush), - ENTRY(VisualBrush_Transform), - ENTRY(VisualBrush_Visual), - 0 -}; - -#undef ENTRY - -met_element_procs_t * -met_get_element_definition(const char *element) -{ - int index = 0; - /* gcc'ism */ - char elstr[strlen(element) + 1]; - char *pelstr; - /* the schema uses a period in element names, when "cooked" these - become underscores */ - strcpy(elstr, element); - pelstr = strchr(elstr, '.'); - if (pelstr) - *pelstr = '_'; - - while (true) { - const met_element_t *metdef = met_element_table[index]; - if (!metdef) - /* end of table, element not found */ - return NULL; - if (!strcmp(elstr, metdef->element)) - return &metdef->procs; - index++; - } -} - diff --git a/met/metelement.h b/met/metelement.h deleted file mode 100644 index 36218050f..000000000 --- a/met/metelement.h +++ /dev/null @@ -1,93 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ -/* $Id:*/ - -/* metelement.h */ - -#ifndef metelement_INCLUDED -# define metelement_INCLUDED - -#include "metstate.h" - -/* implementation procedures for commands */ - -typedef struct met_element_procs_s { - /* allocate memory and "cook" the associated C struct */ - int (*init)(void **data, met_state_t *ms, const char *el, const char **attr); - /* actual parsing - cook the c struct */ - int (*action)(void *data, met_state_t *ms); - /* end element action */ - int (*done)(void *data, met_state_t *ms); -} met_element_procs_t; - -typedef struct met_element_s { - char element[40]; - met_element_procs_t procs; -} met_element_t; - -met_element_procs_t *met_get_element_definition(const char *element); - -/* generate externs */ -#define EXTERNS(element)\ - extern const met_element_t met_element_procs_ ## element - -EXTERNS(ArcSegment); -EXTERNS(Canvas); -EXTERNS(Canvas_Clip); -EXTERNS(Canvas_OpacityMask); -EXTERNS(Canvas_RenderTransform); -EXTERNS(Canvas_Resources); -EXTERNS(DocumentReference); -EXTERNS(FixedDocument); -EXTERNS(FixedDocumentSequence); -EXTERNS(FixedPage); -EXTERNS(FixedPage_RenderTransform); -EXTERNS(FixedPage_Resources); -EXTERNS(Glyphs); -EXTERNS(Glyphs_Clip); -EXTERNS(Glyphs_Fill); -EXTERNS(Glyphs_OpacityMask); -EXTERNS(Glyphs_RenderTransform); -EXTERNS(GradientStop); -EXTERNS(ImageBrush); -EXTERNS(ImageBrush_Transform); -EXTERNS(LinearGradientBrush); -EXTERNS(LinearGradientBrush_GradientStops); -EXTERNS(LinearGradientBrush_Transform); -EXTERNS(LinkTarget); -EXTERNS(MatrixTransform); -EXTERNS(PageContent); -EXTERNS(PageContent_LinkTargets); -EXTERNS(Path); -EXTERNS(Path_Clip); -EXTERNS(Path_Data); -EXTERNS(Path_Fill); -EXTERNS(Path_OpacityMask); -EXTERNS(Path_RenderTransform); -EXTERNS(Path_Stroke); -EXTERNS(PathFigure); -EXTERNS(PathGeometry); -EXTERNS(PathGeometry_Transform); -EXTERNS(PolyBezierSegment); -EXTERNS(PolyLineSegment); -EXTERNS(PolyQuadraticBezierSegment); -EXTERNS(RadialGradientBrush); -EXTERNS(RadialGradientBrush_GradientStops); -EXTERNS(RadialGradientBrush_Transform); -EXTERNS(ResourceDictionary); -EXTERNS(SolidColorBrush); -EXTERNS(VisualBrush); -EXTERNS(VisualBrush_Transform); -EXTERNS(VisualBrush_Visual); -#undef EXTERNS - -#endif /* metelement_INCLUDED */ diff --git a/met/metglyphs.c b/met/metglyphs.c deleted file mode 100644 index 23a9f1515..000000000 --- a/met/metglyphs.c +++ /dev/null @@ -1,692 +0,0 @@ -/* Portions Copyright (C) 2007 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id$*/ - -/* metglyphs.c */ - -#include "memory_.h" -#include "gp.h" -#include "gserror.h" -#include "gsmemory.h" -#include "metcomplex.h" -#include "metelement.h" -#include "metgstate.h" -#include "metsimple.h" -#include "metutil.h" -#include "gspath.h" -#include "gspaint.h" -#include "gsutil.h" -#include "gsccode.h" -#include "gsgdata.h" -#include "gxfont.h" -#include "gxfont42.h" -#include <stdlib.h> /* nb for atof */ -#include "plfont.h" -#include "gscoord.h" -#include "gstext.h" -#include "zipparse.h" -#include <wchar.h> /* unicode */ -#include <locale.h> -#include "ctype_.h" -/* utilities for fonts */ - -/* utf8 string to wchar_t array conversion - * - * max input num wptr array elements - * wcnt output num wchar's written - * wptr wchar_t* array for output - * inptr input string containing utf-8 - * returns 0 on OK -1 on error - * - * NB: Portability uses mbrtowc() - * - */ -int met_utf8_to_wchars(const int max_out, int *wcnt, const wchar_t *wptr_in, const char *inptr_in) -{ - mbstate_t ps; - wchar_t *wptr = wptr_in; - char *inptr = inptr_in; - - /* NB: only tested for UTF-8, specs says utf-16 but all input is utf8 to date - */ - setlocale(LC_ALL,""); - memset(&ps, 0, sizeof(ps)); - memset(wptr, 0, *wcnt*sizeof(wchar_t)); - - // NB: strlen(inptr) ? this assumes a null will be hit in time and that output array is big enough - *wcnt = 0; - while (*inptr) { - int cnt = mbrtowc(wptr, inptr, 5, &ps); - if (cnt < 0) - return gs_throw1(-1, "mbrtowc(%d) utf8 decode failed", cnt); - inptr += cnt; - ++wptr; - ++(*wcnt); - - if(*wcnt > max_out) - return gs_throw2(-1, "max output array size exceeded %d > %d", *wcnt, max_out); - } - return 0; -} - - -/* load the TrueType data from a file to memory */ -private byte * -load_tt_font(zip_part_t *part, gs_memory_t *mem) { - byte *pfont_data; - int len = zip_part_length(part); - int size = -1; - - zip_part_seek(part, 0, 0); - - pfont_data = gs_alloc_bytes(mem, len+6, "xps_tt_load_font data"); - if ( pfont_data == 0 ) { - return NULL; - } - - // zip_part_length BUG, length is long, read is correct !! - size = zip_part_read(pfont_data + 6, len, part); - if ( size != len ) { - dprintf2("BUG! zip_part_length != zip_part_read %d, %d\n", len, size); - } - - /* XOR unobfuscation of XPS fonts via GUID in fontname xor against first 32 bytes */ - { - byte key[16]; - byte *data = pfont_data + 6; - - int partnamelen = strlen(part->name); - char *p = &part->name[partnamelen]; - bool high = false; - int i = 0; - byte num; - - for (; p > part->name && *p != '.'; --p) - /* skip extension */ ; - - for (; p > part->name && *p != '/'; --p) { - if ( isxdigit(*p) ) { - byte c = isdigit(*p) ? *p - 48 : tolower(*p) - 'a' + 10; - if (high) { - num += c << 4; - key[i] = num; - ++i; - } - else - num = c; - high = ! high; - } - } - if (i == 16 ) { - for (i=0; i < 16; ++i) - data[i] = data[i] ^ key[i]; - for (i=0; i < 16; ++i) - data[16+i] = data[16+i] ^ key[i]; - } - /* else no obfuscation */ - } - - //if (part->parent->inline_mode) - zip_part_free_all(part); - return pfont_data; -} - - -/* find a font (keyed by uri) in the font dictionary. */ -private bool -find_font(met_state_t *ms, ST_Name FontUri) -{ - void *data; /* ignored */ - return pl_dict_find(&ms->font_dict, FontUri, strlen(FontUri), &data); -} - -/* add a font (keyed by uri) to the dictionary */ -private bool -put_font(met_state_t *ms, ST_Name FontUri, pl_font_t *plfont) -{ - return (pl_dict_put(&ms->font_dict, - FontUri, strlen(FontUri), plfont) == 0); -} - -/* get a font - the font should exist */ -private pl_font_t * -get_font(met_state_t *ms, ST_Name FontUri) -{ - void *pdata; - pl_font_t *pf; - if (pl_dict_find(&ms->font_dict, FontUri, strlen(FontUri), &pdata)) { - pf = (pl_font_t *)pdata; - return pf; - } else - return NULL; -} - -/* a constructor for a plfont type42 suitable for metro. nb needs - memory cleanup on error. */ -private pl_font_t * -new_plfont(gs_font_dir *pdir, gs_memory_t *mem, byte *pfont_data) -{ - pl_font_t *pf; - gs_font_type42 *p42; - int code; - - if ((pf = pl_alloc_font(mem, "pf new_plfont(pl_font_t)")) == NULL) - return pf; - /* dispense with the structure descriptor */ - if ((p42 = gs_alloc_struct(mem, gs_font_type42, &st_gs_font_type42, - "p42 new_plfont(pl_font_t)")) == NULL) - return (pl_font_t *)p42; - code = pl_fill_in_font((gs_font *)p42, pf, pdir, mem, "" /* font_name */); - if (code < 0) { - return NULL; - } - /* nb this can be set up to leave the data in the file */ - pf->header = pfont_data; - /* nb shouldn't be used */ - pf->header_size = 0; - /* this needs to be fixed wrt all languages */ - pf->storage = 0; - pf->scaling_technology = plfst_TrueType; - pf->font_type = plft_Unicode; - /* nb not sure */ - pf->large_sizes = true; - pf->offsets.GT = 0; - pf->is_xl_format = false; - pf->data_are_permanent = false; - /* not used */ - memset(pf->character_complement, 0, 8); - pl_fill_in_tt_font(p42, pf->header, gs_next_ids(mem, 1)); - code = gs_definefont(pdir, (gs_font *)p42); - if (code < 0) - return NULL; - return pf; -} - - - -/* element constructor */ -private int -Glyphs_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_Glyphs *aGlyphs = - (CT_Glyphs *)gs_alloc_bytes(ms->memory, - sizeof(CT_Glyphs), - "Glyphs_cook"); - int i; - - memset(aGlyphs, 0, sizeof(CT_Glyphs)); - -#define MYSET(field, value) \ - met_cmp_and_set((field), attr[i], attr[i+1], (value)) - - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - if (!MYSET(&aGlyphs->CaretStops, "CaretStops")) - ; - else if (!MYSET(&aGlyphs->Fill, "Fill")) - ; - else if (!MYSET(&aGlyphs->FontUri, "FontUri")) - ; - else if (!MYSET(&aGlyphs->Indices, "Indices")) - ; - else if (!MYSET(&aGlyphs->UnicodeString, "UnicodeString")) - ; - else if (!MYSET(&aGlyphs->StyleSimulations, "StyleSimulations")) - ; - else if (!MYSET(&aGlyphs->RenderTransform, "RenderTransform")) - ; - else if (!MYSET(&aGlyphs->Clip, "Clip")) - ; - else if (!MYSET(&aGlyphs->OpacityMask, "OpacityMask")) - ; - else if (!strcmp(attr[i], "OriginX")) { - aGlyphs->OriginX = atof(attr[i+1]); - aGlyphs->avail.OriginX = 1; - } - else if (!strcmp(attr[i], "OriginY")) { - aGlyphs->OriginY = atof(attr[i+1]); - aGlyphs->avail.OriginY = 1; - } - else if (!strcmp(attr[i], "FontRenderingEmSize")) { - aGlyphs->FontRenderingEmSize = atof(attr[i+1]); - aGlyphs->avail.FontRenderingEmSize = 1; - } else { - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - } -#undef MYSET - - /* copy back the data for the parser. */ - *ppdata = aGlyphs; - return 0; -} - -private int -set_rgb_text_color(gs_state *pgs, CT_Glyphs *aGlyphs) -{ - ST_RscRefColor color; - /* character path a glyph child element to specify the fill. - Regular character use the Glyph attribute */ - if (met_currentcharpathmode(pgs)) { - color = met_currentfillcolor(pgs); - /* if char path a fill color must be set */ - if (color == NULL) { - return gs_throw(-1, "char path color fill not set"); - } - } else { - color = aGlyphs->Fill; - } - if (color == NULL) { - gs_warn("fill color not set falling back to black"); - return gs_setgray(pgs, 0); - } else { - /* nb rgb only */ - rgb_t rgbcolor = met_hex2rgb(color); - return gs_setrgbcolor(pgs, (floatp)rgbcolor.r, (floatp)rgbcolor.g, - (floatp)rgbcolor.b); - } - /* unreached */ - return gs_throw(-1, "Unreached"); -} - - - -private bool is_semi_colon(char c) {return c == ';';} -private bool is_colon(char c) {return c == ':';} - -/* nb hack temporary static buffer for glyphs */ -private gs_glyph glyphs[1024]; -private float advance[1024]; -private float uOffset[1024]; -private float vOffset[1024]; - -private bool iscomma(char c) {return c == ',';} - -/* no error return - * glyph - * advance integer in 100 em units - * uOffset not used - * vOffset not used - * - */ -private void -get_glyph_advance(char *index, gs_font *pfont, gs_glyph unicode, - gs_glyph *glyph, float *advance, - float *uOffset, float *vOffset ) -{ - char *args[strlen(index)]; - int num = 0; - char *p; - float metrics[4]; - - *advance = *uOffset = *vOffset = 0.0f; - - if ((p = strchr(index, ','))) { - num = met_split(index, args, iscomma); - if (p != index) { /* chr, width */ - if (num-- > 0) - *glyph = atoi(args[0]); - if (num-- > 0) - *advance = atoi(args[1]) / 100.0f; - else { - gs_type42_get_metrics((gs_font_type42 *)pfont, *glyph, metrics); - // NB: type 1 fonts will need - //(pfont->data.get_metrics)(pfont, *glyph, metrics); - *advance = metrics[2]; - } - if (num-- > 0) - *uOffset = atoi(args[2]); - if (num-- > 0) - *vOffset = atoi(args[3]); - } - else { /* ,num */ - *glyph = (*pfont->procs.encode_char)(pfont, unicode, 0); - if (num-- > 0) - *advance = atoi(args[0])/ 100.0f; - else { - gs_type42_get_metrics((gs_font_type42 *)pfont, *glyph, metrics); - *advance = metrics[2]; - } - if (num-- > 0) - *uOffset = atoi(args[1]); - if (num-- > 0) - *vOffset = atoi(args[2]); - } - } - else { - *glyph = atoi(index); - gs_type42_get_metrics((gs_font_type42 *)pfont, *glyph, metrics); - *advance = metrics[2]; - } -} - -private int -get_text_draw_op(gs_state *pgs) -{ - if (met_currentcharpathmode(pgs)) - return TEXT_DO_TRUE_CHARPATH; - else - return TEXT_DO_DRAW; -} - -private int -build_text_params(gs_text_params_t *text, pl_font_t *pcf, - ST_UnicodeString UnicodeString, ST_Indices Indices, - uint text_operation) -{ - int code = 0; - - if (!Indices) { - /* this would be the hallaluah case */ - text->operation = TEXT_FROM_STRING | text_operation | TEXT_RETURN_WIDTH; - text->data.bytes = UnicodeString; - text->size = strlen(UnicodeString); - } else { - /* the non halaluah case */ - gs_font *pfont = pcf->pfont; - char expindstr[strlen(Indices) * 2 + 1]; - char *args[strlen(Indices) * 2 + 1]; - char **pargs = args; - int cnt = 0; - int glyph_index = 0; - int combine_cnt = 0; - int wcnt = strlen(UnicodeString); - wchar_t wstr[strlen(UnicodeString)]; - bool has_widths = (bool)strchr(Indices, ',');/* pre scan for advance width usage */ - - - if ((code = met_utf8_to_wchars(wcnt, &wcnt, &wstr[0], &UnicodeString[0])) != 0) - gs_rethrow(code, "utf8 to wchar conversion failed"); - - met_expand(expindstr, Indices, ';', 'Z'); - cnt = met_split(expindstr, args, is_semi_colon); - while (*pargs) { - /* if the argument is empty try the unicode string */ - if (**pargs == 'Z') { - if (wcnt > glyph_index) { - gs_point point; - - glyphs[glyph_index] = - (*pfont->procs.encode_char)(pfont, wstr[glyph_index+combine_cnt], 0); - - if (has_widths) { - (*pcf->char_width)(pcf, NULL, wstr[glyph_index+combine_cnt], &point); - advance[glyph_index] = point.x; - } - ++glyph_index; - } - else - /* punt */ - glyphs[glyph_index++] = 0; - } else { - char *p = 0; - - if ((*pargs) && (p = strchr(*pargs, '('))) { - /* parse (a:b) combine_cnt += a-b */ - char colon_str[100]; - char *paren[3]; - int a, b; - - *pargs = p+1; - met_expand(colon_str, *pargs, ';', 'Z'); - if ( 2 != (cnt = met_split(colon_str, paren, is_colon))) - return gs_throw(-1, "xps parse unbalanced expression (a:b) missing ) "); - - a = atoi(paren[0]); - b = atoi(paren[1]); - - combine_cnt += a - b; - p = strchr(*pargs, ')'); - *pargs = p+1; - } - - get_glyph_advance(*pargs, pfont, - (gs_glyph)wstr[glyph_index+combine_cnt], - &glyphs[glyph_index], &advance[glyph_index], - &uOffset[glyph_index], &vOffset[glyph_index]); - ++glyph_index; - } - pargs++; - } - while (wcnt > glyph_index+combine_cnt) { - glyphs[glyph_index] = - (*pfont->procs.encode_char)(pfont, wstr[glyph_index+combine_cnt], 0); - if (has_widths) { /* need advance widths, out of index */ - gs_point point; - (*pcf->char_width)(pcf, NULL, wstr[glyph_index+combine_cnt], &point); - advance[glyph_index] = point.x; - } else - advance[glyph_index] = 0.0; - uOffset[glyph_index] = 0.0; - vOffset[glyph_index] = 0.0; - ++glyph_index; - } - text->operation = TEXT_FROM_GLYPHS | text_operation | TEXT_RETURN_WIDTH; - text->data.glyphs = glyphs; - text->size = glyph_index; - - if (has_widths) { - text->x_widths = advance; - text->y_widths = uOffset; // NB: wrong better be zeroed for now. - text->widths_size = glyph_index; - text->operation |= TEXT_REPLACE_WIDTHS; - } - } - return 0; -} - -/* action associated with this element. */ -private int -Glyphs_action(void *data, met_state_t *ms) -{ - /* initialize to render characters normally, not outlines */ - met_setcharpathmode(ms->pgs, false); - return 0; -} - -private int -Glyphs_done(void *data, met_state_t *ms) -{ - - /* load the font */ - CT_Glyphs *aGlyphs = data; - ST_Name fname = aGlyphs->FontUri; /* font uri */ - gs_memory_t *mem = ms->memory; - gs_state *pgs = ms->pgs; - pl_font_t *pcf = NULL; /* current font */ - gs_font_dir *pdir = ms->font_dir; - FILE *in; /* tt font file */ - int code = 0; - gs_matrix font_mat; - zip_part_t *part; - - if (!fname) { - return gs_throw(-1, "no font is defined"); - } - - /* nb cleanup on error. if it is not in the font dictionary, - get the data, build a plfont structure add it to the font - dictionary */ - if (!find_font(ms, fname)) { - byte *pdata = 0; - if (0 && - !strcmp(aGlyphs->FontUri, "/font_0.TTF")) { - /* HACK pulls in a fixed font file */ - uint len, size; - if ((in = fopen(aGlyphs->FontUri, gp_fmode_rb)) == NULL) - return gs_throw1(-1, "file open failed %s", aGlyphs->FontUri); - len = (fseek(in, 0L, SEEK_END), ftell(in)); - size = 6 + len; - rewind(in); - pdata = gs_alloc_bytes(mem, size, "foo"); - if (!pdata) - return -1; - fread(pdata + 6, 1, len, in); - fclose(in); - } else { - part = find_zip_part_by_name(ms->pzip, aGlyphs->FontUri); - if (part == NULL) - return gs_throw1(-1, "Can't find zip part %s", aGlyphs->FontUri); - - /* load the font header */ - if ((pdata = load_tt_font(part, mem)) == NULL) - return gs_throw(-1, "Can't load ttf"); - } - /* create a plfont */ - if ((pcf = new_plfont(pdir, mem, pdata)) == NULL) - return gs_throw(-1, "new_plfont failed"); - /* add the font to the font dictionary keyed on uri */ - if (!put_font(ms, fname, pcf)) - return gs_throw(-1, "font dictionary insert failed"); - } - /* shouldn't fail since we added it if it wasn't in the dict */ - if ((pcf = get_font(ms, fname)) == NULL) - return gs_throw(-1, "get_font"); - - if ((code = gs_setfont(pgs, pcf->pfont)) != 0) - return gs_rethrow(code, "gs_setfont"); - - /* if a render transformation is specified we use it otherwise the - font matrix starts out as identity, later it will be - concatenated to the graphics state ctm after scaling for point - size. */ - if ((code = met_get_transform(&font_mat, aGlyphs->RenderTransform)) < 0) - return gs_rethrow(code, "render transform failed"); - - /* move the character "cursor". Note the render transform - apparently applies to the coordinates of the origin argument as - well as the font, so we transform the origin values by the font - matrix! */ - { - gs_point pt; - if ((code = gs_point_transform(aGlyphs->OriginX, aGlyphs->OriginY, - &font_mat, &pt)) != 0) - return gs_rethrow(code, "gs_point_transform"); - if ((code = gs_moveto(pgs, pt.x, pt.y)) != 0) - return gs_rethrow(code, "gs_moveto"); - } - - /* save the current ctm and the current color */ - gs_gsave(pgs); - - /* set the text color */ - if ((code = set_rgb_text_color(pgs, aGlyphs)) < 0) - /* clean up */ - return gs_rethrow(code, "set rgb text color"); - - /* flip y metro goes down the page */ - if ((code = gs_matrix_scale(&font_mat, aGlyphs->FontRenderingEmSize, - (-aGlyphs->FontRenderingEmSize), &font_mat)) != 0) - return gs_rethrow(code, "gs_matrix_scale"); - - /* finally! */ - if ((code = gs_concat(pgs, &font_mat)) != 0) - return gs_rethrow(code, "gs_concat"); - { - gs_text_params_t text; - gs_text_enum_t *penum; - - if ((code = build_text_params(&text, pcf, - aGlyphs->UnicodeString, - aGlyphs->Indices, - get_text_draw_op(pgs))) != 0) - return gs_rethrow(code, "build_text_params"); - if ((code = gs_text_begin(pgs, &text, mem, &penum)) != 0) - return gs_rethrow(code, "gs_text_begin"); - if ((code = gs_text_process(penum)) != 0) - return gs_rethrow(code, "gs_text_process"); - gs_text_release(penum, "Glyphs_action()"); - } - - if (met_currentcharpathmode(pgs)) { - if ((code = gs_eofill(pgs)) < 0) - return gs_rethrow(code, "eofill failed"); - } - - /* restore the ctm */ - gs_grestore(pgs); - - - gs_free_object(ms->memory, aGlyphs->CaretStops, "Glyphs_done"); - gs_free_object(ms->memory, aGlyphs->Fill, "Glyphs_done"); - gs_free_object(ms->memory, aGlyphs->FontUri, "Glyphs_done"); - gs_free_object(ms->memory, aGlyphs->Indices, "Glyphs_done"); - gs_free_object(ms->memory, aGlyphs->UnicodeString, "Glyphs_done"); - gs_free_object(ms->memory, aGlyphs->StyleSimulations, "Glyphs_done"); - gs_free_object(ms->memory, aGlyphs->RenderTransform, "Glyphs_done"); - gs_free_object(ms->memory, aGlyphs->Clip, "Glyphs_done"); - gs_free_object(ms->memory, aGlyphs->OpacityMask, "Glyphs_done"); - gs_free_object(ms->memory, aGlyphs, "Glyphs_done"); - return 0; /* incomplete */ -} - - -const met_element_t met_element_procs_Glyphs = { - "Glyphs", - { - Glyphs_cook, - Glyphs_action, - Glyphs_done - } -}; - -/* element constructor */ -private int -Glyphs_Fill_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_CP_Brush *aGlyphs_Fill = - (CT_CP_Brush *)gs_alloc_bytes(ms->memory, - sizeof(CT_CP_Brush), - "Glyphs_Fill_cook"); - int i; - - memset(aGlyphs_Fill, 0, sizeof(CT_CP_Brush)); - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - - } - - /* copy back the data for the parser. */ - *ppdata = aGlyphs_Fill; - return 0; -} - -/* action associated with this element */ -private int -Glyphs_Fill_action(void *data, met_state_t *ms) -{ - /* CT_CP_Brush *aGlyphs_Fill = data; */ - met_setcharpathmode(ms->pgs, true); - return 0; -} - -private int -Glyphs_Fill_done(void *data, met_state_t *ms) -{ - - gs_free_object(ms->memory, data, "Glyphs_Fill_done"); - return 0; /* incomplete */ -} - - -const met_element_t met_element_procs_Glyphs_Fill = { - "Glyphs_Fill", - { - Glyphs_Fill_cook, - Glyphs_Fill_action, - Glyphs_Fill_done - } -}; diff --git a/met/metgstate.c b/met/metgstate.c deleted file mode 100644 index 4b633455c..000000000 --- a/met/metgstate.c +++ /dev/null @@ -1,294 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ -/*$Id: */ - -/* metgstate.c */ -/* metro graphics state operators */ - -#include "std.h" -#include "metsimple.h" -#include "metstate.h" -#include "metgstate.h" -#include "metutil.h" -#include "gxstate.h" /* for gs_state_copy_reason_t */ -#include "string_.h" -#include "ctype_.h" - -typedef struct metgstate_s { - char *Stroke; - char *Fill; - ST_ZeroOne Opacity; - char *FillRule; - bool isClosed; - bool charpathmode; - char *CharFill; - met_path_child_t child; - void *VisualBrush; - gs_memory_t *pmem; - met_state_t *ms; -} metgstate_t; - -private void * -met_gstate_alloc(gs_memory_t *pmem) -{ - metgstate_t *pmg = (metgstate_t *)gs_alloc_bytes(pmem, - sizeof(metgstate_t), - "met_gstate_alloc"); - memset(pmg, 0, sizeof(metgstate_t)); - pmg->pmem = pmem; - return pmg; -} - -private int -met_gstate_copy_for(void *pto, void *pfrom, gs_state_copy_reason_t reason) -{ - /* reason is ignored for now */ - metgstate_t *pt = pto; - metgstate_t *pf = pfrom; - - /* free old prior to deep copy */ - gs_free_object(pf->pmem, pt->Stroke, "met_gstate_free"); - gs_free_object(pf->pmem, pt->Fill, "met_gstate_free"); - gs_free_object(pf->pmem, pt->FillRule, "met_gstate_free"); - gs_free_object(pf->pmem, pt->CharFill, "met_gstate_free"); - - /* struct copy */ - *pt = *pf; - - /* deep copy */ - pt->Stroke = met_strdup(pf->pmem, pf->Stroke, "met_gstate_copy_for"); - pt->Fill = met_strdup(pf->pmem, pf->Fill, "met_gstate_copy_for"); - pt->FillRule = met_strdup(pf->pmem, pf->FillRule, "met_gstate_copy_for"); - pt->CharFill = met_strdup(pf->pmem, pf->CharFill, "met_gstate_copy_for"); - - return 0; -} - -private void -met_gstate_free(void *pold, gs_memory_t *pmem) -{ - metgstate_t *pmetgs = (metgstate_t *)pold; - gs_free_object(pmem, pmetgs->Stroke, "met_gstate_free"); - gs_free_object(pmem, pmetgs->Fill, "met_gstate_free"); - gs_free_object(pmem, pmetgs->FillRule, "met_gstate_free"); - gs_free_object(pmem, pmetgs->CharFill, "met_gstate_free"); - // TODO free gradientstops - gs_free_object(pmem, pmetgs, "met_gstate_free"); -} - -private const ST_RscRefColor met_pattern = "xxx"; - -ST_RscRefColor -met_currentstrokecolor(gs_state *pgs) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - return pmg->Stroke; -} - -void -met_setstrokecolor(gs_state *pgs, const ST_RscRefColor color) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - - gs_free_object(pmg->pmem, pmg->Stroke, "met_setstrokecolor"); - pmg->Stroke = met_strdup(pmg->pmem, color, "met_setstrokecolor"); -} - -ST_RscRefColor -met_currentfillcolor(gs_state *pgs) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - return pmg->Fill; -} - -void -met_setfillcolor(gs_state *pgs, const ST_RscRefColor color) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - gs_free_object(pmg->pmem, pmg->Fill, "met_setfillcolor"); - pmg->Fill = met_strdup(pmg->pmem, color, "met_setfillcolor"); -} - -void -met_setpatternstroke(gs_state *pgs) -{ - met_setstrokecolor(pgs, met_pattern); -} - -void -met_setpatternfill(gs_state *pgs) -{ - met_setfillcolor(pgs, met_pattern); -} - - -void -met_setfillrule(gs_state *pgs, const ST_FillRule fill) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - gs_free_object(pmg->pmem, pmg->FillRule, "met_setfillrulecolor"); - pmg->FillRule = met_strdup(pmg->pmem, fill, "met_setfillrulecolor"); -} - -ST_FillRule -met_currentfillrule(gs_state *pgs) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - return pmg->FillRule; -} - -void -met_setopacity(gs_state *pgs, const ST_ZeroOne opacity) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - pmg->Opacity = opacity; -} - -ST_ZeroOne -met_currentopacity(gs_state *pgs) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - return pmg->Opacity; -} - -met_path_t -met_currentpathtype(gs_state *pgs) -{ - if (met_currentstrokecolor(pgs) && met_currentfillcolor(pgs)) - return met_stroke_and_fill; - if (met_currentfillcolor(pgs)) - return met_fill_only; - if (met_currentstrokecolor(pgs)) - return met_stroke_only; - return met_path_undefined; -} - -/* if set all paths should be closed */ -void -met_setclosepath(gs_state *pgs, bool close) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - pmg->isClosed = close; -} - -bool met_currentclosepath(gs_state *pgs) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - return pmg->isClosed; -} - -bool met_currenteofill(gs_state *pgs) -{ - /* if not set even odd */ - if (!met_currentfillrule(pgs)) - return true; - - return (!strcasecmp(met_currentfillrule(pgs), "EvenOdd")); -} - -met_path_child_t met_currentpathchild(gs_state *pgs) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - return pmg->child; -} - -void met_setpathchild(gs_state *pgs, met_path_child_t child) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - pmg->child = child; -} - -bool -met_iscolorpattern(gs_state *pgs, ST_RscRefColor color) -{ - if (!color) - return false; - return !strcmp(color, met_pattern); -} - -void -met_setcharpathmode(gs_state *pgs, bool mode) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - pmg->charpathmode = mode; -} - -bool -met_currentcharpathmode(gs_state *pgs) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - return pmg->charpathmode; -} - -void -met_setcharfillcolor(gs_state *pgs, ST_RscRefColor color) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - pmg->CharFill = color; -} - -ST_RscRefColor met_currentcharfillcolor(gs_state *pgs) -{ - metgstate_t *pmg = gs_state_client_data(pgs); - return pmg->CharFill; -} - -private metgstate_t * -client_data(gs_state *pgs) -{ - return gs_state_client_data(pgs); -} - -/* nb should be a resource type */ -void -met_setvisualbrush(gs_state *pgs, void *vb) -{ - client_data(pgs)->VisualBrush = vb; -} - -void *met_currentvisualbrush(gs_state *pgs) -{ - return client_data(pgs)->VisualBrush; -} - -private const gs_state_client_procs met_gstate_procs = { - met_gstate_alloc, - 0, - met_gstate_free, - met_gstate_copy_for -}; - - -/* constructor for gstate */ -void -met_gstate_init(gs_state *pgs, gs_memory_t *pmem, met_state_t *ms) -{ - metgstate_t *pmg = met_gstate_alloc(pmem); - pmg->Stroke = 0; - pmg->Opacity = 0; - pmg->FillRule = 0; - pmg->isClosed = 0; - pmg->charpathmode = 0; - pmg->CharFill = 0; - pmg->child = met_none; - pmg->pmem = pmem; - pmg->VisualBrush = 0; - pmg->ms = ms; - gs_state_set_client(pgs, pmg, &met_gstate_procs, false); -} - -met_state_t * -met_state_from_gstate(gs_state *pgs) -{ - return client_data(pgs)->ms; -} - diff --git a/met/metgstate.h b/met/metgstate.h deleted file mode 100644 index 626abc3a6..000000000 --- a/met/metgstate.h +++ /dev/null @@ -1,90 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ -/*$Id: */ - -/* metgstate.h */ - -/* a state that "tags" along with the graphics state */ - -#ifndef metgstate_INCLUDED -# define metgstate_INCLUDED - -#include "gstypes.h" -#include "gsstate.h" -#include "metsimple.h" - -met_state_t *met_state_from_gstate(gs_state *pgs); - -/* constructor */ -void met_gstate_init(gs_state *pgs, gs_memory_t *pmem, met_state_t *ms); - -/* operators */ - -ST_RscRefColor met_currentstrokecolor(gs_state *pgs); -void met_setstrokecolor(gs_state *pgs, const ST_RscRefColor color); - -ST_RscRefColor met_currentfillcolor(gs_state *pgs); -void met_setfillcolor(gs_state *pgs, const ST_RscRefColor color); - -ST_RscRefColor met_currentcharfillcolor(gs_state *pgs); -void met_setcharfillcolor(gs_state *pgs, ST_RscRefColor color); - -ST_ZeroOne met_currentopacity(gs_state *pgs); -void met_setopacity(gs_state *pgs, const ST_ZeroOne opacity); - -ST_FillRule met_currentfillrule(gs_state *pgs); -void met_setfillrule(gs_state *pgs, const ST_FillRule fill); - -/* true if even-odd */ -bool met_currenteofill(gs_state *pgs); - -typedef enum { - met_stroke_only, - met_fill_only, - met_stroke_and_fill, - met_path_undefined -} met_path_t; - -met_path_t met_currentpathtype(gs_state *pgs); - -/* if set all paths should be closed */ -void met_setclosepath(gs_state *pgs, bool close); -bool met_currentclosepath(gs_state *pgs); - -/* since we are not using a tree this identifies if path.fill, - path.stroke or neither is active */ -typedef enum { - met_fill, - met_stroke, - met_none -} met_path_child_t; - -met_path_child_t met_currentpathchild(gs_state *pgs); -void met_setpathchild(gs_state *pgs, met_path_child_t child); - -/* set to stroke or fill with the current pattern */ -void met_setpatternstroke(gs_state *pgs); -void met_setpatternfill(gs_state *pgs); - -/* check if currentstrokecolor or currentfill color has returned a - pattern */ -bool met_iscolorpattern(gs_state *pgs, ST_RscRefColor color); - -/* if set make an font outline path to be filled */ -void met_setcharpathmode(gs_state *pgs, bool mode); -bool met_currentcharpathmode(gs_state *pgs); - -/* nb should be a resource type */ -void met_setvisualbrush(gs_state *pgs, void *vb); -void *met_currentvisualbrush(gs_state *pgs); - -#endif /* metgstate_INCLUDED */ diff --git a/met/metimage.c b/met/metimage.c deleted file mode 100644 index 3b529dde0..000000000 --- a/met/metimage.c +++ /dev/null @@ -1,536 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id$*/ - -/* image related elements */ - -/* element constructor */ - -#include "memory_.h" -#include "gsmemory.h" -#include "gsmatrix.h" -#include "gp.h" -#include "metcomplex.h" -#include "metelement.h" -#include "metutil.h" -#include "math_.h" -#include "metimage.h" -#include "metgstate.h" -#include "ctype_.h" -#include "gsimage.h" -#include "gscspace.h" -#include "gsptype1.h" -#include "gscoord.h" -#include "gscolor2.h" -#include <stdlib.h> /* nb for atof */ -#include "strimpl.h" -#include "scommon.h" -#include "jpeglib_.h" /* for jpeg filter */ -#include "sdct.h" -#include "sjpeg.h" -#include "zipparse.h" -#include "gxstate.h" /* for gs_state_memory() */ -#include "gdebug.h" -#include "gsutil.h" - -private int -ImageBrush_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_ImageBrush *aImageBrush = - (CT_ImageBrush *)gs_alloc_bytes(ms->memory, - sizeof(CT_ImageBrush), - "ImageBrush_cook"); - int i; - - memset(aImageBrush, 0, sizeof(CT_ImageBrush)); - -#define MYSET(field, value) \ - met_cmp_and_set((field), attr[i], attr[i+1], (value)) - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - if (!MYSET(&aImageBrush->Key, "Key")) - ; - else if (!MYSET(&aImageBrush->Transform, "Transform")) - ; - else if (!MYSET(&aImageBrush->Viewbox, "Viewbox")) - ; - else if (!MYSET(&aImageBrush->Viewport, "Viewport")) - ; - else if (!MYSET(&aImageBrush->Fill, "Fill")) - ; - else if (!MYSET(&aImageBrush->TileMode, "TileMode")) - ; - else if (!MYSET(&aImageBrush->ViewboxUnits, "ViewboxUnits")) - ; - else if (!MYSET(&aImageBrush->ViewportUnits, "ViewportUnits")) - ; - else if (!MYSET(&aImageBrush->ImageSource, "ImageSource")) - ; - else { - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - } - - /* copy back the data for the parser. */ - *ppdata = aImageBrush; - return 0; -} - -/* temporary code to read raster format. reads the whole works. NB - */ -private int -readdata(gs_memory_t *mem, zip_state_t *pzip, ST_Name ImageSource, byte **bufp, int *lenp) -{ - byte *buf; - ulong len = 0; - zip_part_t *part = find_zip_part_by_name(pzip, ImageSource); - - if (part == NULL) - return gs_throw1(-1,"Image part not found %s", ImageSource); - - len = zip_part_length(part); - - buf = gs_alloc_bytes(mem, len, "xps_readdata buffer"); - if ( buf == 0 ) { - return -1; - } - - zip_part_seek(part, 0, 0); - if ( len != zip_part_read(buf, len, part) ) { - return gs_throw(-1, "zip_part_read len wrong"); - } - - *bufp = buf; - *lenp = len; -#define NO_PNG_TO_JPEG_HACK 1 -#ifndef NO_PNG_TO_JPEG_HACK - /* NB: this converts PNG to JPEGS on the fly using /tmp/foo.png and /tmp/foo.jpg - * NB: also converts TIFF to jpg - * NB: file name extension detection is weak, - * file data inspection would be much better. - */ - - { - const char *ctif_convert = "/usr/bin/convert /tmp/foo.tif /tmp/foo.jpg"; - const char *ctif = "/tmp/foo.tif"; - const char *cpng_convert = "/usr/bin/convert /tmp/foo.png /tmp/foo.jpg"; - const char *cpng = "/tmp/foo.png"; - char *imgStr; - char *convertStr; - bool doit = false; - - if (0 == strncasecmp(&ImageSource[strlen(ImageSource) -5], "tiff", 4 )) { - imgStr = ctif; - convertStr = ctif_convert; - doit = true; - } - - else if (0 == strncasecmp(&ImageSource[strlen(ImageSource) -4], "png", 3 )); { - imgStr = cpng; - convertStr = cpng_convert; - doit = true; - } - - if (doit) { - FILE *in = fopen(imgStr, "w"); - fwrite(buf, 1, len, in); - fclose(in); - - system( convertStr ); - - in = fopen("/tmp/foo.jpg", "r"); - if (in == NULL) - return gs_throw(-1, "/tmp/foo.jpg file open failed"); - len = (fseek(in, 0L, SEEK_END), ftell(in)); - rewind(in); - gs_free_object(mem, buf, "readdata"); - buf = gs_alloc_bytes(mem, len, "readdata"); - if (!buf) - return -1; - fread(buf, 1, len, in); - fclose(in); - *bufp = buf; - *lenp = len; - } - } -#endif - /* NB no deletion of images, - * NB should process once and use many not read many - */ - - return 0; -} - -int -met_PaintPattern(const gs_client_color *pcc, gs_state *pgs) -{ - gs_memory_t *mem = gs_state_memory(pgs); - const gs_client_pattern *ppat = gs_getpattern(pcc); - const met_pattern_t *pmpat = ppat->client_data; - int code; - - /* if it's a gradient brush */ - if (!pmpat->raster_image) - { - gs_gsave(pgs); - if (pmpat->linear) - code = LinearGradientBrush_paint(pmpat->linear, pgs); - if (pmpat->radial) - code = RadialGradientBrush_paint(pmpat->radial, pgs); - if (pmpat->visual) - code = VisualBrush_paint(pmpat->visual, pgs); - gs_grestore(pgs); - if (code < 0) - return gs_rethrow(code, "could not paint gradient pattern"); - return gs_okay; - } - - const xps_image_t *pmim = pmpat->raster_image; - const byte *pdata = pmim->samples; - gs_image_enum *penum; - gs_color_space color_space; - gs_image_t image; - uint imbytes = pmim->stride * pmim->height; - uint used; - - - if (gs_debug_c('b')) - dprintf5("paint_image cs=%d n=%d bpc=%d w=%d h=%d\n", - pmim->colorspace, pmim->comps, pmim->bits, pmim->width, pmim->height); - - /* should be just save the ctm */ - gs_gsave(pgs); - gs_scale(pgs, 96.0/pmim->xres, 96.0/pmim->yres); - - switch (pmim->colorspace) - { - case XPS_GRAY: - gs_cspace_init_DeviceGray(mem, &color_space); - break; - case XPS_RGB: - gs_cspace_init_DeviceRGB(mem, &color_space); - break; - case XPS_CMYK: - gs_cspace_init_DeviceCMYK(mem, &color_space); - break; - default: - return gs_throw(-1, "cannot handle images with alpha channels"); - } - - gs_image_t_init(&image, &color_space); - image.ColorSpace = &color_space; - image.BitsPerComponent = pmim->bits; - image.Width = pmim->width; - image.Height = pmim->height; - - penum = gs_image_enum_alloc(mem, "met_PaintPattern"); - if (!penum) - return gs_throw(-1, "gs_enum_allocate failed"); - - if ((code = gs_image_init(penum, &image, false, pgs)) < 0) - return gs_throw(code, "gs_image_init failed"); - - if ((code = gs_image_next(penum, pdata, imbytes, &used)) < 0) - return gs_throw(code, "gs_image_next failed"); - - if (imbytes < used) - return gs_throw2(-1, "not enough image data (image=%d used=%d)", imbytes, used); - if (imbytes > used) - return gs_throw2(0, "too much image data (image=%d used=%d)", imbytes, used); - - gs_image_cleanup(penum, pgs); - gs_free_object(mem, penum, "px_paint_pattern"); - gs_grestore(pgs); - - return gs_okay; -} - - - -/* - * Strip alpha channel from an image - */ -private void -xps_strip_alpha(xps_image_t *image) -{ - int cs = image->colorspace; - int n = image->comps; - int y, x, k; - byte *sp, *dp; - - if (image->bits != 8) - { - gs_warn1("cannot strip alpha from %dbpc images", image->bits); - return; - } - - if ((cs != XPS_GRAY_A) && (cs != XPS_RGB_A) && (cs != XPS_CMYK_A)) - return; - - for (y = 0; y < image->height; y++) - { - sp = image->samples + image->width * n * y; - dp = image->samples + image->width * (n - 1) * y; - for (x = 0; x < image->width; x++) - { - for (k = 0; k < n - 1; k++) - *dp++ = *sp++; - sp++; - } - } - - image->colorspace --; - image->comps --; - image->stride = (n - 1) * image->width; -} - -/* - * Switch on file magic to decode an image. - */ - -private int -xps_decode_image(gs_memory_t *mem, byte *rbuf, int rlen, xps_image_t *image) -{ - int error; - - if (rbuf[0] == 0xff && rbuf[1] == 0xd8) - error = xps_decode_jpeg(mem, rbuf, rlen, image); - else if (memcmp(rbuf, "\211PNG\r\n\032\n", 8) == 0) - error = xps_decode_png(mem, rbuf, rlen, image); - else if (memcmp(rbuf, "MM", 2) == 0) - error = xps_decode_tiff(mem, rbuf, rlen, image); - else if (memcmp(rbuf, "II", 2) == 0) - error = xps_decode_tiff(mem, rbuf, rlen, image); - else - error = gs_throw(-1, "unknown image file format"); - - if (error) - return gs_rethrow(error, "could not decode image"); - - /* NB: strip out alpha until we can handle it */ - xps_strip_alpha(image); - return gs_okay; -} - - -/* NB for the demo we render and set the pattern in the graphics - state */ -private int -make_pattern(ST_Name ImageSource, met_pattern_t *metpat, met_state_t *ms) -{ - byte *rbuf; /* raster buffer */ - int rlen; - int code; - gs_client_pattern gspat; - gs_client_color gscolor; - gs_memory_t *mem = ms->memory; - - code = readdata(mem, ms->pzip, ImageSource, &rbuf, &rlen); - if (code < 0) - return gs_rethrow(code, "read image data failed"); - - code = xps_decode_image(mem, rbuf, rlen, metpat->raster_image); - if (code < 0) - { - gs_free_object(mem, rbuf, "readdata"); - return gs_rethrow(code, "decode image data failed"); - } - - gs_free_object(mem, rbuf, "readdata"); - - gs_pattern1_init(&gspat); - uid_set_UniqueID(&gspat.uid, gs_next_ids(mem, 1)); - gspat.PaintType = 1; - gspat.TilingType = 1; - - /* NB: Viewbox(0,0,0,0) appears to be legal, adjust to sane value */ - metpat->Viewbox.q.x = max( metpat->Viewbox.q.x, 1 ); - metpat->Viewbox.q.y = max( metpat->Viewbox.q.y, 1 ); - - gspat.BBox.p.x = 0; - gspat.BBox.p.y = 0; - gspat.BBox.q.x = metpat->Viewbox.q.x - metpat->Viewbox.p.x; - gspat.BBox.q.y = metpat->Viewbox.q.y - metpat->Viewbox.p.y; - - gspat.XStep = metpat->Viewbox.q.x - metpat->Viewbox.p.x; - gspat.YStep = metpat->Viewbox.q.y - metpat->Viewbox.p.y; - gspat.PaintProc = met_PaintPattern; - gspat.client_data = (void *)metpat; - { - gs_matrix mat; - gs_color_space cs; - gs_state *pgs = ms->pgs; - gs_rect vbox = metpat->Viewbox; - gs_rect vport = metpat->Viewport; - gs_gsave(pgs); - /* resolution scaling is done when the pattern is painted */ - /* translate the viewbox to the origin, scale the viewbox to - the viewport and translate the viewbox back. */ - gs_make_translation(vport.p.x, vport.p.y, &mat); - { - /* NB: don't scale smaller than a pixel */ - double scalex = max((1.00/( metpat->raster_image->xres)), - ((vport.q.x - vport.p.x) / (vbox.q.x - vbox.p.x))); - double scaley = max((1.00/( metpat->raster_image->yres)), - ((vport.q.y - vport.p.y) / (vbox.q.y - vbox.p.y))); - gs_matrix_scale(&mat, scalex, scaley, &mat); - } - gs_matrix_translate(&mat, -vbox.p.x, vbox.p.y, &mat); - - /* nb defaults to RGB */ - gs_cspace_init_DeviceRGB(mem, &cs); - gs_setcolorspace(pgs, &cs); - gs_makepattern(&gscolor, &gspat, &mat, pgs, NULL); - gs_grestore(pgs); - gs_setpattern(pgs, &gscolor); - { - met_path_child_t parent = met_currentpathchild(pgs); - if (parent == met_fill) - met_setpatternfill(pgs); - else if (parent == met_stroke) - met_setpatternstroke(pgs); - else { - gs_throw(-1, "pattern has no context"); - return -1; - } - } - } - return 0; -} - - - -private bool is_Data_delimeter(char b) -{ - return (b == ',') || (isspace(b)); -} - -/* action associated with this element */ -private int -ImageBrush_action(void *data, met_state_t *ms) -{ - /* create the pattern dictionary entry */ - CT_ImageBrush *aImageBrush = data; - met_pattern_t *pat = (met_pattern_t *)gs_alloc_bytes(ms->memory, - sizeof(met_pattern_t), "ImageBrush_action"); - xps_image_t *pim = (xps_image_t *)gs_alloc_bytes(ms->memory, - sizeof(xps_image_t), "ImageBrush_action"); - - - if (!pat || !pim) - return -1; - - pat->raster_image = pim; - /* nb gcc'isms ahead */ - if (aImageBrush->Transform) { - char transstring[strlen(aImageBrush->Transform)]; - strcpy(transstring, aImageBrush->Transform); - /* nb wasteful */ - char *args[strlen(aImageBrush->Transform)]; - char **pargs = args; - met_split(transstring, args, is_Data_delimeter); - /* nb checking */ - pat->Transform.xx = atof(pargs[0]); - pat->Transform.xy = atof(pargs[1]); - pat->Transform.yx = atof(pargs[2]); - pat->Transform.yy = atof(pargs[3]); - pat->Transform.tx = atof(pargs[4]); - pat->Transform.ty = atof(pargs[5]); - } - - if (aImageBrush->Viewbox) { - char viewbox[strlen(aImageBrush->Viewbox)]; - strcpy(viewbox, aImageBrush->Viewbox); - /* nb wasteful */ - char *args[strlen(aImageBrush->Viewbox)]; - char **pargs = args; - met_split(viewbox, args, is_Data_delimeter); - pat->Viewbox.p.x = atof(pargs[0]); - pat->Viewbox.p.y = atof(pargs[1]); - pat->Viewbox.q.x = pat->Viewbox.p.x + atof(pargs[2]); - pat->Viewbox.q.y = pat->Viewbox.p.y + atof(pargs[3]); - /* the spec says if the viewbox extant is zero in both - directions take a point sample. We are not exactly sure - what this means. Here is one interpretation. */ - if ((pat->Viewbox.p.x == pat->Viewbox.q.x) && - (pat->Viewbox.p.y == pat->Viewbox.q.y)) { - pat->Viewbox.q.x = pat->Viewbox.p.x + 1.0; - pat->Viewbox.q.y = pat->Viewbox.q.y + 1.0; - } - - } - if (aImageBrush->Viewport) { - /* do ever feel like your doing the same thing over and over - again... */ - char viewport[strlen(aImageBrush->Viewport)]; - strcpy(viewport, aImageBrush->Viewport); - /* nb wasteful */ - char *args[strlen(aImageBrush->Viewbox)]; - char **pargs = args; - met_split(viewport, args, is_Data_delimeter); - pat->Viewport.p.x = atof(pargs[0]); - pat->Viewport.p.y = atof(pargs[1]); - pat->Viewport.q.x = pat->Viewport.p.x + atof(pargs[2]); - pat->Viewport.q.y = pat->Viewport.p.y + atof(pargs[3]); - } - - if (aImageBrush->Transform) { - char transform[strlen(aImageBrush->Transform)]; - char *args[strlen(aImageBrush->Transform)]; - strcpy(transform, aImageBrush->Transform); - char **pargs = args; - met_split(transform, args, is_Data_delimeter); - pat->Transform.xx = atof(pargs[0]); - pat->Transform.xy = atof(pargs[1]); - pat->Transform.yx = atof(pargs[2]); - pat->Transform.yy = atof(pargs[3]); - pat->Transform.tx = atof(pargs[4]); - pat->Transform.ty = atof(pargs[5]); - } - make_pattern(aImageBrush->ImageSource, pat, ms); - - return 0; -} - -private int -ImageBrush_done(void *data, met_state_t *ms) -{ - CT_ImageBrush *aImageBrush = (CT_ImageBrush *)data; - - gs_free_object(ms->memory, aImageBrush->Key, "ImageBrush_done"); - gs_free_object(ms->memory, aImageBrush->Transform, "ImageBrush_done"); - gs_free_object(ms->memory, aImageBrush->Viewbox, "ImageBrush_done"); - gs_free_object(ms->memory, aImageBrush->Viewport, "ImageBrush_done"); - gs_free_object(ms->memory, aImageBrush->Fill, "ImageBrush_done"); - gs_free_object(ms->memory, aImageBrush->TileMode, "ImageBrush_done"); - gs_free_object(ms->memory, aImageBrush->ViewboxUnits, "ImageBrush_done"); - gs_free_object(ms->memory, aImageBrush->ViewportUnits, "ImageBrush_done"); - gs_free_object(ms->memory, aImageBrush->ImageSource, "ImageBrush_done"); - gs_free_object(ms->memory, aImageBrush, "ImageBrush_done"); - - return 0; /* incomplete */ -} - - -const met_element_t met_element_procs_ImageBrush = { - "ImageBrush", - { - ImageBrush_cook, - ImageBrush_action, - ImageBrush_done - } -}; - - diff --git a/met/metimage.h b/met/metimage.h deleted file mode 100644 index f0be981d0..000000000 --- a/met/metimage.h +++ /dev/null @@ -1,58 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id$*/ - -/* metro image interface */ - -#ifndef metimage_INCLUDED -# define metimage_INCLUDED - -#include "gsmatrix.h" - -/* type for the information derived directly from the raster file format */ - -enum { XPS_GRAY, XPS_GRAY_A, XPS_RGB, XPS_RGB_A, XPS_CMYK, XPS_CMYK_A }; - -typedef struct xps_image_s xps_image_t; - -struct xps_image_s -{ - int width; - int height; - int stride; - int colorspace; - int comps; - int bits; - int xres; - int yres; - byte *samples; -}; - -int xps_decode_jpeg(gs_memory_t *mem, byte *rbuf, int rlen, xps_image_t *image); -int xps_decode_png(gs_memory_t *mem, byte *rbuf, int rlen, xps_image_t *image); -int xps_decode_tiff(gs_memory_t *mem, byte *rbuf, int rlen, xps_image_t *image); - -typedef struct met_pattern_s { - void *linear; - void *radial; - void *visual; - xps_image_t *raster_image; - gs_matrix Transform; - gs_rect Viewbox; - gs_rect Viewport; -} met_pattern_t; - -int LinearGradientBrush_paint(void *data, gs_state *pgs); -int RadialGradientBrush_paint(void *data, gs_state *pgs); -int VisualBrush_paint(void *data, gs_state *pgs); -#endif /* metimage_INCLUDED */ diff --git a/met/metpage.c b/met/metpage.c deleted file mode 100644 index 79f7a9e82..000000000 --- a/met/metpage.c +++ /dev/null @@ -1,123 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id$ */ - -/* metro page related elements */ - -#include "memory_.h" -#include "gstypes.h" -#include "gsstate.h" -#include "gscoord.h" -#include "gsmemory.h" -#include "gsparam.h" -#include "gsdevice.h" -#include "gspaint.h" -#include "gserror.h" -#include "metcomplex.h" -#include "metelement.h" -#include "metutil.h" -#include <stdlib.h> /* nb for atof */ - -private int -FixedPage_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_FixedPage *aFixedPage = - (CT_FixedPage *)gs_alloc_bytes(ms->memory, - sizeof(CT_FixedPage), - "FixedPage_cook"); - int i; - memset(aFixedPage, 0, sizeof(CT_FixedPage)); - for(i = 0; attr[i]; i += 2) { - if (!strcmp(attr[i], "Width")) - aFixedPage->Width = atof(attr[i+1]); - else if (!strcmp(attr[i], "Height")) - aFixedPage->Height = atof(attr[i+1]); /* nb wrong - assumes the datatype */ - else if (!MYSET(&aFixedPage->ContentBox, "ContentBox")) - ; - else if (!MYSET(&aFixedPage->BleedBox, "BleedBox")) - ; - else { - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - } - *ppdata = aFixedPage; - return 0; /* incomplete */ -} - -private int -FixedPage_action(void *data, met_state_t *ms) -{ - - CT_FixedPage *aFixedPage = data; - - gs_state *pgs = ms->pgs; - gx_device *dev = gs_currentdevice(pgs); - gs_memory_t *mem = ms->memory; - gs_param_float_array fa; - float fv[2]; - gs_c_param_list list; - int code; - - fa.data = fv; - fa.persistent = false; - - /* nb review handling of error codes for parameter writing */ - gs_c_param_list_write(&list, mem); - fv[0] = aFixedPage->Width / 96.0 * 72.0; - fv[1] = aFixedPage->Height / 96.0 * 72.0; - fa.size = 2; - code = param_write_float_array((gs_param_list *)&list, ".MediaSize", &fa); - gs_c_param_list_write(&list, mem); - if ( code >= 0 ) { - gs_c_param_list_read(&list); - code = gs_putdeviceparams(dev, (gs_param_list *)&list); - } - gs_c_param_list_release(&list); - - /* nb this is for the demo it is wrong and should be removed */ - gs_initgraphics(pgs); - - gs_initmatrix(pgs); - /* 96 dpi default - and put the origin at the top of the page */ - code = gs_scale(pgs, 72.0/96.0, -72.0/96.0); - if (code < 0) - return code; - code = gs_translate(pgs, 0.0, -aFixedPage->Height); - if (code < 0) - return code; - code = gs_erasepage(pgs); - return code; -} - -private int -FixedPage_done(void *data, met_state_t *ms) -{ - CT_FixedPage *aFixedPage = data; - (ms->end_page)(ms, 1 /* Copies */, true /* flush */); - - gs_free_object(ms->memory, aFixedPage->ContentBox, "FixedPage_done"); - gs_free_object(ms->memory, aFixedPage->BleedBox, "FixedPage_done"); - gs_free_object(ms->memory, aFixedPage, "FixedPage_done"); - return 0; -} - - -const met_element_t met_element_procs_FixedPage = { - "FixedPage", - { - FixedPage_cook, - FixedPage_action, - FixedPage_done - } -}; diff --git a/met/metparse.c b/met/metparse.c deleted file mode 100644 index 26b03e754..000000000 --- a/met/metparse.c +++ /dev/null @@ -1,322 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id$*/ - -/* metro parser module */ - -#include <expat.h> -#include "memory_.h" -#include "metparse.h" -#include "metelement.h" -#include "metcomplex.h" -#include "metrecorder.h" -#include "gdebug.h" -#include "gserror.h" - -/* have expat use the gs memory manager. */ - - -/* NB global - needed for expat callbacks */ -gs_memory_t *gs_mem_ptr = NULL; - -/* memory callbacks */ -private void * -met_expat_alloc(size_t size) -{ - return gs_alloc_bytes(gs_mem_ptr, size, "met_expat_alloc"); -} - -private void -met_expat_free(void *ptr) -{ - return gs_free_object(gs_mem_ptr, ptr, "met_expat_free"); -} - -private void * -met_expat_realloc(void *ptr, size_t size) -{ - return gs_resize_object(gs_mem_ptr, ptr, size, "met_expat_free"); -} - -/* used to set an error in the midst of a callback */ -private void -met_set_error(met_parser_state_t *st, int error_code) -{ - st->error_code = error_code; - /* this effectively will stop the parsing even if the buffer is - not complete */ - XML_SetElementHandler(st->parser, 0, 0); - st->error_code = error_code; - return; -} - - -#define INDENT (st->depth * 4) - -#ifdef DEBUG -private void -parse_trace(const char *el, const char **attr, int indent) -{ - /* nothing to do if not debugging parser flag */ - if (!gs_debug_c('i')) - return; - /* assume empty attribute means close element */ - if (!attr) - dprintf4("%*s%s:%d\n", indent + 1, "/", el, indent / 4); - else - dprintf3("%*s:%d\n", indent + strlen(el), el, indent / 4); - /* print the attributes if we have any. aren't closing out the element */ - if (attr) { - int i; - for (i = 0; attr[i]; i += 2) - dprintf3("%*s='%.256s'\n", - indent + strlen(attr[i]), - attr[i], attr[i + 1]); - } -} -#else -#define parse_trace(a, b, c) /* null */ -#endif - -/* check an element has an implementation */ -private bool -element_ok(met_element_procs_t *metp, const char *el) -{ - if (!metp) { - gs_warn1("element: %s is not in the definition table", el); - return false; - } else if (!metp->init || !metp->action || !metp->done) { - gs_warn1("element: %s has incomplete implementation", el); - return false; - } - return true; -} -/* start and end callbacks NB DOC */ -private void -met_start(void *data, const char *el, const char **attr) -{ - met_parser_state_t *st = data; - gs_memory_t *mem = st->memory; - met_element_procs_t *metp = met_get_element_definition(el); - bool record_my_children = false; - int code; - - parse_trace(el, attr, INDENT); - - if (element_ok(metp, el)) { - /* add and element and its cooked data to the history list. - Point element to it's slot in the history list. */ - data_element_t *element = &st->element_history[st->last_element]; - /* stuff in the procedure definitions */ - element->met_element_procs = metp; - /* selector to pick a procedure */ - element->sel = met_action; - /* call the cook procedure, it initializes the cooked data */ - code = (*metp->init)(&element->cooked_data, st->mets, el, attr); - if (code < 0) { - gs_rethrow1(code, "%s init failed", el); - met_set_error(st, code); - } - /* start recording */ - if (code == 1) { /* nb record me return value */ - record_my_children = true; - if (st->recording) { - gs_rethrow(code, "Fatal recursive recording not supported"); - met_set_error(st, code); - } - } - - if (st->recording) { - met_record(mem, element, el, /* open */ true, st->depth); - } else { - /* only cook if we are recording */ - code = (*metp->action)(element->cooked_data, st->mets); - if (code < 0) { - gs_rethrow1(code, "%s action failed", el); - met_set_error(st, code); - } - } - st->last_element++; - } - st->depth++; - if (record_my_children) { - st->recording = true; - st->depth_at_record_start = st->depth; - dprintf2("starting recording at %s stack pos %d\n", el, st->depth); - } -} - -private void -met_end(void *data, const char *el) -{ - /* nb annoyingly we look this up again just as we did when - starting to process the element */ - met_element_procs_t *metp = met_get_element_definition(el); - met_parser_state_t *st = data; - gs_memory_t *mem = st->memory; - int code = 0; - - st->depth--; - parse_trace(el, NULL, INDENT); - - if (element_ok(metp, el)) { - data_element_t element; - st->last_element--; - element = st->element_history[st->last_element]; - if (st->recording) { - element.sel = met_done; - code = met_record(mem, &element, el, false /* open */, st->depth); - /* just free the cooked resource, the recorder made a copy. */ - gs_free_object(mem, element.cooked_data, "met parser"); - /* check if we have returned to the depth */ - } else { - code = (*metp->done)(element.cooked_data, st->mets); - } - if (code < 0) { - gs_rethrow1(code, "%s done failed", el); - met_set_error(st, code); - } - } - - if (st->recording && (st->depth == st->depth_at_record_start)) { - if (code >= 0) { - dprintf2("stopping recording at %s stack pos %d\n", el, st->depth); - code = met_store(st->mets); - if (code >= 0) { - st->recording = false; - } - } - } - -} - -/* allocate the parser, and set the global memory pointer see above */ -met_parser_state_t * -met_process_alloc(gs_memory_t *memory) -{ - /* memory procedures */ - const XML_Memory_Handling_Suite memprocs = { - met_expat_alloc, met_expat_realloc, met_expat_free - }; - - /* NB should have a structure descriptor */ - met_parser_state_t *stp = - (met_parser_state_t *)gs_alloc_bytes(memory, - sizeof(met_parser_state_t), - "met_process_alloc"); - XML_Parser p; - /* NB set the static mem ptr used by expat callbacks */ - gs_mem_ptr = memory; - - if (!stp) - return NULL; - - p = XML_ParserCreate_MM(NULL /* encoding */, - &memprocs, - NULL /* name space separator */); - if (!p) - return NULL; - - stp->memory = memory; - stp->parser = p; - stp->depth = 0; - stp->error_code = 0; - stp->last_element = 0; - stp->recording = false; - /* set up the start end callbacks */ - XML_SetElementHandler(p, met_start, met_end); - XML_SetUserData(p, stp); - return stp; -} - -/* free the parser and corresponding expat parser */ -void -met_process_release(met_parser_state_t *st) -{ - XML_ParserFree(st->parser); - gs_free_object(st->memory, st, "met_process_release"); -} - -private void -met_unset_error_code(met_parser_state_t *st) -{ - /* restore handlers */ - XML_SetElementHandler(st->parser, met_start, met_end); - st->error_code = 0; -} - -int -met_process(met_parser_state_t *st, met_state_t *mets, void *pzip, stream_cursor_read *pr) -{ - const byte *p = pr->ptr; - const byte *rlimit = pr->limit; - uint avail = rlimit - p; - XML_Parser parser = st->parser; - static bool started = false; - /* expat hack - it is not possible to parse multiple xml documents - without restarting the parser. For expat a document ends with - the closing of the opening element. We create an artificial - opening and closing (see met_process_shutdown for close) to - parse multiple xml documents. NB This should be handled with - additional calls from the language switching api not with a - static. */ - /* NB metro state within parser state see metparse.h */ - st->mets = mets; - - if (!started) { - const char *start = "<JOB>"; - if (XML_Parse(parser, start, strlen(start), 0) == XML_STATUS_ERROR) { - return gs_rethrow1(-1, "xml parse error at <job>: %s", - XML_ErrorString(XML_GetErrorCode(parser))); - } - started = true; - } - - - if (XML_Parse(parser, p + 1, avail, 0 /* done? */) == XML_STATUS_ERROR) { - return gs_rethrow2(-1, "xml parse error at line %d: %s", - XML_GetCurrentLineNumber(parser), - XML_ErrorString(XML_GetErrorCode(parser))); - } else if (st->error_code < 0) { - int code = st->error_code; - met_unset_error_code(st); - return gs_rethrow(code, "xml processing failed"); - } - /* nb for now we assume the parser has consumed exactly what we gave it. */ - pr->ptr = p + avail; - return 0; -} - -/* expat need explicit shutdown */ -int -met_process_shutdown(met_parser_state_t *st) -{ - XML_Parser parser = st->parser; - /* end the artificial bracketing */ - - const char *end = "</JOB>"; - if (XML_Parse(parser, end, strlen(end), 0) == XML_STATUS_ERROR) { - return gs_rethrow2(-1, "xml parse error at line %d: %s", - XML_GetCurrentLineNumber(parser), - XML_ErrorString(XML_GetErrorCode(parser))); - } - - if (XML_Parse(parser, 0 /* data buffer */, - 0 /* buffer length */, - 1 /* done? */ ) == XML_STATUS_ERROR) { - return gs_rethrow2(-1, "xml parse error at line %d: %s", - XML_GetCurrentLineNumber(parser), - XML_ErrorString(XML_GetErrorCode(parser))); - } - return 0; -} diff --git a/met/metparse.h b/met/metparse.h deleted file mode 100644 index 4fb5f8421..000000000 --- a/met/metparse.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id$*/ - -/* metro parser interface */ - -#ifndef metparse_INCLUDED -# define metparse_INCLUDED - -#include "metstate.h" /* nb this should be separated out - reconsider */ -#include "metelement.h" - -/* the size of the input buffer to be used by the parser */ -#define MET_PARSER_MIN_INPUT_SIZE 8192 - -typedef struct met_parser_state_s met_parser_state_t; - -/* data types for recording */ - -/* we just store the all the procs when recording an element and the - following selector is used to determine which procedure to call. A - union might be better for this, but not much difference. Also we - really only need distinguish between cook/action vs. done to establish the right playback. */ - -typedef enum {met_cook, met_action, met_done} met_selector; - -/* an element and its associated cooked data */ -typedef struct met_cooked_element_s { - met_selector sel; - met_element_procs_t *met_element_procs; - void *cooked_data; -} data_element_t; /* nb rename me met_ */ - -struct met_parser_state_s { - gs_memory_t *memory; - int error_code; /* error detected in a callback */ - int depth; - void *parser; - data_element_t element_history[20]; /* nb should not have depth limitation */ - int last_element; - int depth_at_record_start; - int recording; - met_state_t *mets; /* nb this should be separated out - reconsider */ -}; - -/* Allocate a parser state. */ -met_parser_state_t *met_process_alloc(gs_memory_t *memory); - -/* Release a parser state. */ -void met_process_release(met_parser_state_t *st); - -/* Initialize the parser state. */ -void met_process_init(met_parser_state_t *st); - -/* Process a buffer of metro/XML. */ -int met_process(met_parser_state_t *st, met_state_t *pxs, - void *pzip, stream_cursor_read *pr); - -/* shutdown the parser */ -int met_process_shutdown(met_parser_state_t *st); - -#endif /* metparse_INCLUDED */ diff --git a/met/metpath.c b/met/metpath.c deleted file mode 100644 index 1a0683f0c..000000000 --- a/met/metpath.c +++ /dev/null @@ -1,1053 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id$ */ - -/* path related elements */ - -#include "memory_.h" -#include "gsmemory.h" -#include "gsmatrix.h" -#include "gserror.h" -#include "metcomplex.h" -#include "metelement.h" -#include "metgstate.h" -#include "metutil.h" -#include "gscoord.h" -#include "gspath.h" -#include "gspaint.h" -#include "math_.h" -#include "ctype_.h" -#include <stdlib.h> /* nb for atof */ - - - -/* this function is passed to the split routine (see below) */ -private bool is_Data_delimeter(char b) -{ - return (b == ',') || (isspace(b)); -} - -/* convert an xml point to a gs point. nb lame */ -private gs_point -getPoint(const char *metPoint) -{ - gs_point pt; - /* gcc'ism */ - char pstr[strlen(metPoint) + 1]; - char *p = pstr; - char *args[2]; - char ch; - while ((ch = *metPoint)) { - if (!isspace(ch)) - *p++ = ch; - metPoint++; - } - *p = '\0'; /* null terminate p */ - - met_split(pstr, args, is_Data_delimeter); - pt.x = atof(args[0]); - pt.y = atof(args[1]); - return pt; -} - -/* CT_PathFigure */ -private int -PathFigure_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_PathFigure *aPathFigure = - (CT_PathFigure *)XPS_ALLOC(ms, sizeof(CT_PathFigure)); - - int i; - memset(aPathFigure, 0, sizeof(CT_PathFigure)); - - - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - if (!strcmp(attr[i], "IsClosed")) - aPathFigure->isClosed = !strcmp(attr[i+1], "true"); - else if (!strcmp(attr[i], "isFilled")) - aPathFigure->isFilled = !strcmp(attr[i+1], "true"); - else if (!MYSET(&aPathFigure->StartPoint, "StartPoint")) - ; - else { - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - } - /* copy back the data for the parser. */ - *ppdata = aPathFigure; - return 0; -} - -/* action associated with this element */ -private int -PathFigure_action(void *data, met_state_t *ms) -{ - CT_PathFigure *aPathFigure = data; - int code; - - /* nb not sure what to make of PathFigure->isFilled. Maybe a - mistake in the spec. */ - - /* tell the graphics state to close or not close future paths */ - met_setclosepath(ms->pgs, aPathFigure->isClosed); - - /* we do these now */ - if (aPathFigure->StartPoint) { - gs_point start = getPoint(aPathFigure->StartPoint); - gs_state *pgs = ms->pgs; - code = gs_moveto(pgs, start.x, start.y); - if (code < 0) { - return code; - } - } - return 0; -} - -private int -PathFigure_done(void *data, met_state_t *ms) -{ - CT_PathFigure *aPathFigure = data; - gs_free_object(ms->memory, aPathFigure->StartPoint, "PathFigure_done"); - gs_free_object(ms->memory, aPathFigure, "PathFigure_done"); - return 0; -} - -const met_element_t met_element_procs_PathFigure = { - "PathFigure", - { - PathFigure_cook, - PathFigure_action, - PathFigure_done - } -}; - -/* CT_Path */ -private int -Path_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_Path *aPath = - (CT_Path *)gs_alloc_bytes(ms->memory, - sizeof(CT_Path), - "Path_cook"); - int i; - /* hack for treeless demo */ - memset(aPath, 0, sizeof(CT_Path)); - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - if (!met_cmp_and_set(&aPath->Stroke, - attr[i], attr[i+1], "Stroke")) - ; - else if (!met_cmp_and_set(&aPath->Data, - attr[i], attr[i+1], "Data")) - ; - else if (!met_cmp_and_set(&aPath->Fill, - attr[i], attr[i+1], "Fill")) - ; - else if (!strcmp(attr[i], "StrokeThickness")) - aPath->StrokeThickness = atof(attr[i+1]); - - else { - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - } - /* copy back the data for the parser. */ - *ppdata = aPath; - return 0; -} - -/* action associated with this element */ -private int -Path_action(void *data, met_state_t *ms) -{ - CT_Path *aPath = data; - int code = 0; - - met_setstrokecolor(ms->pgs, aPath->Stroke); - met_setfillcolor(ms->pgs, aPath->Fill); - code = gs_setlinewidth(ms->pgs, aPath->StrokeThickness); - - if (code < 0) - gs_rethrow(code, "setlinewidth failed"); - - if (aPath->Data) { - gs_state *pgs = ms->pgs; - /* gcc ism */ - char pathcopy[strlen(aPath->Data) + 1]; - /* the number of argument will be less than the length of the - data. NB wasteful. */ - char *args[strlen(aPath->Data)]; - char **pargs = args; - bool moveto; - strcpy(pathcopy, aPath->Data); - met_split(pathcopy, args, is_Data_delimeter); - /* nb implement the spec for Data - this just prints some test - examples, sans error checking. */ - moveto = false; - while (*pargs) { - gs_point pt; - char arg = toupper(**pargs); - if (arg == 'Z') { - gs_closepath(pgs); - pargs++; - } else if (arg == 'F') { - /* nb set fill rule */ - pargs++; - } else if (arg == 'M' || arg == 'L') { - moveto = (arg == 'M'); - pargs++; - while (*pargs) { - if (isalpha(**pargs)) { - break; - } - pt.x = atof(*pargs++); - pt.y = atof(*pargs++); - if (moveto) - code = gs_moveto(pgs, pt.x, pt.y); - else - code = gs_lineto(pgs, pt.x, pt.y); - if (code < 0) - return code; - } - } else if (arg == 'C') { - gs_point cpt0, cpt1, cpt2; - *pargs++; - while (*pargs) { - if (isalpha(**pargs)) { - break; - } - cpt0.x = atof(*pargs++); cpt0.y = atof(*pargs++); - cpt1.x = atof(*pargs++); cpt1.y = atof(*pargs++); - cpt2.x = atof(*pargs++); cpt2.y = atof(*pargs++); - code = gs_curveto(pgs, cpt0.x, cpt0.y, cpt1.x, cpt1.y, - cpt2.x, cpt2.y); - if (code < 0) - return code; - } - } else { - *pargs++; - dprintf("unknown operator continuing\n"); - } - } - } - return code; -} - - -/* element constructor */ -private int -PathGeometry_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_PathGeometry *aPathGeometry = - (CT_PathGeometry *)gs_alloc_bytes(ms->memory, - sizeof(CT_PathGeometry), - "PathGeometry_cook"); - int i; - - memset(aPathGeometry, 0, sizeof(CT_PathGeometry)); - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - if (!met_cmp_and_set(&aPathGeometry->FillRule, - attr[i], attr[i+1], "FillRule")) - ; - else { - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - - } - /* copy back the data for the parser. */ - *ppdata = aPathGeometry; - return 0; -} - -/* action associated with this element */ -private int -PathGeometry_action(void *data, met_state_t *ms) -{ - CT_PathGeometry *aPathGeometry = data; - met_setfillrule(ms->pgs, aPathGeometry->FillRule); - return 0; -} - -private int -PathGeometry_done(void *data, met_state_t *ms) -{ - CT_PathGeometry *aPathGeometry = data; - - gs_free_object(ms->memory, aPathGeometry->FillRule, "PathGeometry_done"); - gs_free_object(ms->memory, aPathGeometry, "PathGeometry_done"); - return 0; -} - -const met_element_t met_element_procs_PathGeometry = { - "PathGeometry", - { - PathGeometry_cook, - PathGeometry_action, - PathGeometry_done - } -}; - -private int -set_color(gs_state *pgs, bool forstroke) -{ - int code = 0; - ST_RscRefColor (*color)(gs_state *); - ST_RscRefColor met_color; - - if (forstroke) - color = met_currentstrokecolor; - else - color = met_currentfillcolor; - - - met_color = ((*color)(pgs)); - - /* if this is a pattern nothing to do */ - if (met_iscolorpattern(pgs, met_color)) - return 0; - - if (met_color) { - rgb_t rgb = met_hex2rgb(met_color); - /* nb rgb color */ - code = gs_setrgbcolor(pgs, (floatp)rgb.r, - (floatp)rgb.g, (floatp)rgb.b); - } else { - code = gs_setnullcolor(pgs); - } - return code; -} - -private int -Path_done(void *data, met_state_t *ms) -{ - gs_state *pgs = ms->pgs; - int code; - CT_Path *aPath = (CT_Path *)data; - met_path_t pathtype = met_currentpathtype(pgs); - /* this loop executes once */ - int (*fill)(gs_state *); - - if (met_currenteofill(pgs)) - fill = gs_eofill; - else - fill = gs_fill; - - do { - /* case of stroke and file... uses a gsave/grestore to keep - the path */ - if (pathtype == met_stroke_and_fill) { - /* set the color before gsave to be consistent with the - solo stroke and fill cases below we only use the gsave - to preserve the path. */ - if ((code = set_color(pgs, false /* is stroke */)) < 0) - break; - if ((code = gs_gsave(pgs)) < 0) - break; - if ((code = gs_eofill(pgs)) < 0) - break; - /* nb should try to clean up gsave on error in set_color - or gs_eofill... */ - if ((code = gs_grestore(pgs)) < 0) - break; - if ((code = set_color(pgs, true /* is stroke */)) < 0) - break; - if ((code = gs_stroke(pgs)) < 0) - break; - /* just fill or stroke not both */ - } else if (pathtype == met_fill_only) { - if ((code = set_color(pgs, false /* is stroke */)) < 0) - break; - if ((code = gs_eofill(pgs)) < 0) - break; - } else if (pathtype == met_stroke_only) { - if ((code = set_color(pgs, true /* is stroke */)) < 0) - break; - if ((code = gs_stroke(pgs)) < 0) - break; - } else { - // gs_throw(-1, "Unknown path operation"); - // code = -1; - gs_warn("unknown path operation"); - code = 0; - } - - - } while (0); - - gs_free_object(ms->memory, aPath->Stroke, "Path_done"); - gs_free_object(ms->memory, aPath->Data, "Path_done"); - gs_free_object(ms->memory, aPath->Fill, "Path_done"); - gs_free_object(ms->memory, aPath, "Path_done"); - if (code < 0) - return gs_rethrow(code, "Path done failed"); - else - return 0; -} - -const met_element_t met_element_procs_Path = { - "Path", - { - Path_cook, - Path_action, - Path_done - } -}; - -/* CT_Path */ - -/* PolyLineSegment */ -private int -PolyLineSegment_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_PolyLineSegment *aPolyLineSegment = - (CT_PolyLineSegment *)gs_alloc_bytes(ms->memory, - sizeof(CT_PolyLineSegment), - "PolyLineSegment_cook"); - - int i; - memset(aPolyLineSegment, 0, sizeof(CT_PolyLineSegment)); - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - if (!MYSET(&aPolyLineSegment->Points, "Points")) - ; - else { - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - } - - /* copy back the data for the parser. */ - *ppdata = aPolyLineSegment; - return 0; -} - -/* action associated with this element */ -private int -PolyLineSegment_action(void *data, met_state_t *ms) -{ - CT_PolyLineSegment *aPolyLineSegment = data; - gs_state *pgs = ms->pgs; - int code = 0; - if (aPolyLineSegment->Points) { - char pstr[strlen(aPolyLineSegment->Points) + 1]; - /* the number of argument will be less than the length of the - data. NB wasteful. */ - char *args[strlen(aPolyLineSegment->Points)]; - char **pargs = args; - strcpy(pstr, aPolyLineSegment->Points); - met_split(pstr, args, is_Data_delimeter); - while (*pargs) { - gs_point pt; - pt.x = atof(*pargs++); - - if (!*pargs) { - dprintf("point does not have two coordinate\n"); - break; - } - - pt.y = atof(*pargs++); - code = gs_lineto(pgs, pt.x, pt.y); - if (code < 0) - return code; - } - } - if (met_currentclosepath(pgs)) - code = gs_closepath(ms->pgs); - return code; -} - -private int -PolyLineSegment_done(void *data, met_state_t *ms) -{ - CT_PolyLineSegment *aPolyLineSegment = data; - - gs_free_object(ms->memory, aPolyLineSegment->Points, "PolyLineSegment_done"); - gs_free_object(ms->memory, aPolyLineSegment, "PolyLineSegment_done"); - return 0; -} - -const met_element_t met_element_procs_PolyLineSegment = { - "PolyLineSegment", - { - PolyLineSegment_cook, - PolyLineSegment_action, - PolyLineSegment_done - } -}; - -/* element constructor */ -private int -Path_Fill_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_CP_Brush *aPath_Fill = - (CT_CP_Brush *)gs_alloc_bytes(ms->memory, - sizeof(CT_CP_Brush), - "Path_Fill_cook"); - int i; - - memset(aPath_Fill, 0, sizeof(CT_CP_Brush)); - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - - } - - /* copy back the data for the parser. */ - *ppdata = aPath_Fill; - return 0; -} - -/* action associated with this element */ -private int -Path_Fill_action(void *data, met_state_t *ms) -{ - /* CT_CP_Brush *aPath_Fill = data; */ - met_setpathchild(ms->pgs, met_fill); - return 0; -} - -private int -Path_Fill_done(void *data, met_state_t *ms) -{ - gs_free_object(ms->memory, data, "Path_Fill_done"); - return 0; -} - -const met_element_t met_element_procs_Path_Fill = { - "Path_Fill", - { - Path_Fill_cook, - Path_Fill_action, - Path_Fill_done - } -}; - -/* element constructor */ -private int -SolidColorBrush_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_SolidColorBrush *aSolidColorBrush = - (CT_SolidColorBrush *)gs_alloc_bytes(ms->memory, - sizeof(CT_SolidColorBrush), - "SolidColorBrush_cook"); - - int i; - - memset(aSolidColorBrush, 0, sizeof(CT_SolidColorBrush)); - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - if (!MYSET(&aSolidColorBrush->Color, "Color")) - ; - else { - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - } - /* copy back the data for the parser. */ - *ppdata = aSolidColorBrush; - return 0; -} - -/* action associated with this element */ -private int -SolidColorBrush_action(void *data, met_state_t *ms) -{ - CT_SolidColorBrush *aSolidColorBrush = data; - met_setfillcolor(ms->pgs, aSolidColorBrush->Color); - return 0; -} - -private int -SolidColorBrush_done(void *data, met_state_t *ms) -{ - CT_SolidColorBrush *aSolidColorBrush = data; - - gs_free_object(ms->memory, aSolidColorBrush->Color, "SolidColorBrush_done"); - gs_free_object(ms->memory, aSolidColorBrush, "SolidColorBrush_done"); - return 0; -} - -const met_element_t met_element_procs_SolidColorBrush = { - "SolidColorBrush", - { - SolidColorBrush_cook, - SolidColorBrush_action, - SolidColorBrush_done - } -}; - -private int -Path_Stroke_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_CP_Brush *aPath_Stroke = - (CT_CP_Brush *)gs_alloc_bytes(ms->memory, - sizeof(CT_CP_Brush), - "Path_Stroke_cook"); - - int i; - - memset(aPath_Stroke, 0, sizeof(CT_CP_Brush)); - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - - } - - /* copy back the data for the parser. */ - *ppdata = aPath_Stroke; - return 0; -} - -/* action associated with this element */ -private int -Path_Stroke_action(void *data, met_state_t *ms) -{ - /* CT_CP_Brush *aPath_Stroke = data; */ - met_setpathchild(ms->pgs, met_stroke); - return 0; - -} - -private int -Path_Stroke_done(void *data, met_state_t *ms) -{ - - gs_free_object(ms->memory, data, "Path_Stroke_done"); - return 0; /* incomplete */ -} - - -const met_element_t met_element_procs_Path_Stroke = { - "Path_Stroke", - { - Path_Stroke_cook, - Path_Stroke_action, - Path_Stroke_done - } -}; - -/* element constructor */ -private int -ArcSegment_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_ArcSegment *aArcSegment = - (CT_ArcSegment *)gs_alloc_bytes(ms->memory, - sizeof(CT_ArcSegment), - "ArcSegment_cook"); - int i; - - memset(aArcSegment, 0, sizeof(CT_ArcSegment)); - - /* set defaults */ - aArcSegment->IsStroked = true; - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - if (!MYSET(&aArcSegment->Point, "Point")) - ; - else if (!MYSET(&aArcSegment->Size, "Size")) - ; - else if (!MYSET(&aArcSegment->SweepDirection, "SweepDirection")) - ; - else if (!strcmp(attr[i], "RotationAngle")) - aArcSegment->RotationAngle = atof(attr[i+1]); - else if (!strcmp(attr[i], "IsLargeArc")) - aArcSegment->IsLargeArc = !strcmp(attr[i+1], "true"); - else if (!strcmp(attr[i], "IsStroked")) - aArcSegment->IsStroked = !strcmp(attr[i+1], "true"); - else { - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - } - - /* copy back the data for the parser. */ - *ppdata = aArcSegment; - return 0; -} - -/* given two vectors find the angle between */ -private double -angle_between(const gs_point u, const gs_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; - return sign * acos(udotv / (magu * magv)); -} - -/* ArcSegment pretty much follows the SVG algorithm for converting an - arc in endpoint representation to an arc in centerpoint - representation. Once in centerpoint it can be given to the - graphics library in the form of a postscript arc. */ -private int -ArcSegment_action(void *data, met_state_t *ms) -{ - CT_ArcSegment *aArcSegment = data; - gs_state *pgs = ms->pgs; - gs_point start, end, size, midpoint, halfdis, thalfdis, tcenter, center; - double sign, rot, start_angle, delta_angle; - int code; - bool isLargeArc, isClockwise; - - /* should be available */ - if ((code = gs_currentpoint(pgs, &start)) < 0) - return gs_rethrow(code, "missing start point"); - - /* get the end point */ - end = getPoint(aArcSegment->Point); - - /* get the radii - M$ calls these the "size" */ - size = getPoint(aArcSegment->Size); - - /* set the large arc flag */ - isLargeArc = aArcSegment->IsLargeArc; - - /* set cw flag, nb probably should ignore case */ - if (!strcmp(aArcSegment->SweepDirection, "Counterclockwise")) - isClockwise = false; - else - isClockwise = true; - sign = (isClockwise == isLargeArc ? -1.0 : 1.0); - - /* get the rotation angle. */ - rot = aArcSegment->RotationAngle; - - /* get the distance of the radical line */ - halfdis.x = (start.x - end.x) / 2.0; - halfdis.y = (start.y - end.y) / 2.0; - -#define SQR(x) ((x)*(x)) - - /* rotate the halfdis vector so x axis parallel ellipse x axis */ - { - gs_matrix rotmat; - double correction; - gs_make_rotation(-rot, &rotmat); - if ((code = gs_distance_transform(halfdis.x, halfdis.y, &rotmat, &thalfdis)) < 0) - gs_rethrow(code, "transform failed"); - /* correct radii if necessary */ - correction = (SQR(thalfdis.x) / SQR(size.x)) + (SQR(thalfdis.y) / SQR(size.y)); - if (correction > 1.0) { - size.x *= sqrt(correction); - size.y *= sqrt(correction); - } - } - -#define MULTOFSQUARES(x, y) (SQR((x)) * SQR((y))) - { - - double scale_num = (MULTOFSQUARES(size.x, size.y)) - - (MULTOFSQUARES(size.x, thalfdis.y)) - - (MULTOFSQUARES(size.y, thalfdis.x)); - double scale_denom = MULTOFSQUARES(size.x, thalfdis.y) + MULTOFSQUARES(size.y, thalfdis.x); - double scale = sign * sqrt(((scale_num / scale_denom) < 0) ? 0 : (scale_num / scale_denom)); - /* translated center */ - tcenter.x = scale * ((size.x * thalfdis.y)/size.y); - tcenter.y = scale * ((-size.y * thalfdis.x)/size.x); - - /* of the original radical line */ - midpoint.x = (end.x + start.x) / 2.0; - midpoint.y = (end.y + start.y) / 2.0; - - center.x = tcenter.x + midpoint.x; - center.y = tcenter.y + midpoint.y; - { - gs_point coord1, coord2, coord3, coord4; - coord1.x = 1; - coord1.y = 0; - coord2.x = (thalfdis.x - tcenter.x) / size.x; - coord2.y = (thalfdis.y - tcenter.y) / size.y; - coord3.x = (thalfdis.x - tcenter.x) / size.x; - coord3.y = (thalfdis.y - tcenter.y) / size.y; - coord4.x = (-thalfdis.x - tcenter.x) / size.x; - coord4.y = (-thalfdis.y - tcenter.y) / size.y; - start_angle = angle_between(coord1, coord2); - delta_angle = angle_between(coord3, coord4); - if (delta_angle < 0 && !isClockwise) - delta_angle += (degrees_to_radians * 360); - if (delta_angle > 0 && isClockwise) - delta_angle -= (degrees_to_radians * 360); - - } - } - - { - gs_matrix save_ctm; - gs_currentmatrix(pgs, &save_ctm); - gs_translate(pgs, center.x, center.y); - gs_rotate(pgs, rot); - gs_scale(pgs, size.x, size.y); - - if ((code = gs_arcn(pgs, 0, 0, 1, - radians_to_degrees * start_angle, - radians_to_degrees * (start_angle + delta_angle))) < 0) - return gs_rethrow(code, "arc failed"); - - - /* restore the ctm */ - gs_setmatrix(pgs, &save_ctm); - } - return 0; -} - -private int -ArcSegment_done(void *data, met_state_t *ms) -{ - CT_ArcSegment *aArcSegment = (CT_ArcSegment *)data; - - gs_free_object(ms->memory, aArcSegment->Point, "ArcSegment_done"); - gs_free_object(ms->memory, aArcSegment->Size, "ArcSegment_done"); - gs_free_object(ms->memory, aArcSegment->SweepDirection, "ArcSegment_done"); - gs_free_object(ms->memory, aArcSegment, "ArcSegment_done"); - return 0; -} - - -const met_element_t met_element_procs_ArcSegment = { - "ArcSegment", - { - ArcSegment_cook, - ArcSegment_action, - ArcSegment_done - } -}; - - -/* element constructor */ -private int -PolyBezierSegment_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_PolyBezierSegment *aPolyBezierSegment = - (CT_PolyBezierSegment *)gs_alloc_bytes(ms->memory, - sizeof(CT_PolyBezierSegment), - "PolyBezierSegment_cook"); - int i; - - memset(aPolyBezierSegment, 0, sizeof(CT_PolyBezierSegment)); - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - if (!MYSET(&aPolyBezierSegment->Points, "Points")) - ; - else { - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - } - /* copy back the data for the parser. */ - *ppdata = aPolyBezierSegment; - return 0; -} - -/* action associated with this element. NB very similar to other - LineSegment routines refactor. */ -private int -PolyBezierSegment_action(void *data, met_state_t *ms) -{ - CT_PolyBezierSegment *aPolyBezierSegment = data; - gs_state *pgs = ms->pgs; - int code = 0; - if (aPolyBezierSegment->Points) { - char pstr[strlen(aPolyBezierSegment->Points) + 1]; - /* the number of argument will be less than the length of the - data. NB wasteful. */ - char *args[strlen(aPolyBezierSegment->Points)]; - char **pargs = args; - int points_parsed = 0; - strcpy(pstr, aPolyBezierSegment->Points); - met_split(pstr, args, is_Data_delimeter); - while (*pargs) { - gs_point pt[3]; /* the two control point and the end point */ - - pt[points_parsed % 3].x = atof(*pargs++); - - if (!*pargs) { - dprintf("point does not have two coordinate\n"); - break; - } - pt[points_parsed % 3].y = atof(*pargs++); - points_parsed++; - if (points_parsed % 3 == 0) { - code = gs_curveto(pgs, pt[0].x, pt[0].y, - pt[1].x, pt[1].y, - pt[2].x, pt[2].y); - if (code < 0) - return code; - } - } - } - if (met_currentclosepath(pgs)) - code = gs_closepath(ms->pgs); - return code; -} - -private int -PolyBezierSegment_done(void *data, met_state_t *ms) -{ - CT_PolyBezierSegment *aPolyBezierSegment = data; - - gs_free_object(ms->memory, aPolyBezierSegment->Points, "PolyBezierSegment_done"); - gs_free_object(ms->memory, aPolyBezierSegment, "PolyBezierSegment_done"); - return 0; -} - - -const met_element_t met_element_procs_PolyBezierSegment = { - "PolyBezierSegment", - { - PolyBezierSegment_cook, - PolyBezierSegment_action, - PolyBezierSegment_done - } -}; - - -/* element constructor */ -private int -PolyQuadraticBezierSegment_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_PolyQuadraticBezierSegment *aPolyQuadraticBezierSegment = - (CT_PolyQuadraticBezierSegment *)gs_alloc_bytes(ms->memory, - sizeof(CT_PolyQuadraticBezierSegment), - "PolyQuadraticBezierSegment_cook"); - int i; - - memset(aPolyQuadraticBezierSegment, 0, sizeof(CT_PolyQuadraticBezierSegment)); - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - if (!MYSET(&aPolyQuadraticBezierSegment->Points, "Points")) - ; - else { - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - } - - /* copy back the data for the parser. */ - *ppdata = aPolyQuadraticBezierSegment; - return 0; -} - - -/* NB code duplication with Segments ahead */ - -/* action associated with this element */ -private int -PolyQuadraticBezierSegment_action(void *data, met_state_t *ms) -{ - CT_PolyQuadraticBezierSegment *aPolyQuadraticBezierSegment = data; - gs_state *pgs = ms->pgs; - int code = 0; - if (aPolyQuadraticBezierSegment->Points) { - char pstr[strlen(aPolyQuadraticBezierSegment->Points) + 1]; - /* the number of argument will be less than the length of the - data. NB wasteful. */ - char *args[strlen(aPolyQuadraticBezierSegment->Points)]; - char **pargs = args; - int points_parsed = 0; - strcpy(pstr, aPolyQuadraticBezierSegment->Points); - met_split(pstr, args, is_Data_delimeter); - while (*pargs) { - gs_point pt[2]; /* control point and end point */ - - pt[points_parsed % 2].x = atof(*pargs++); - - if (!*pargs) { - dprintf("point does not have two coordinate\n"); - break; - } - pt[points_parsed % 2].y = atof(*pargs++); - points_parsed++; - if (points_parsed % 2 == 0) { - gs_point start_pt; - code = gs_currentpoint(pgs, &start_pt); - if (code < 0) - gs_rethrow(code, "currentpoint failed"); - code = gs_curveto(pgs, - (start_pt.x + 2 * pt[0].x) / 3, - (start_pt.x + 2 * pt[0].y) / 3, - (pt[1].x + 2 * pt[0].x) / 3, - (pt[1].y + 2 * pt[0].y) / 3, - pt[1].x, pt[1].y); - if (code < 0) - return gs_rethrow(code, "curveto failied"); - } - } - } - if (met_currentclosepath(pgs)) - code = gs_closepath(ms->pgs); - return code; -} - -private int -PolyQuadraticBezierSegment_done(void *data, met_state_t *ms) -{ - CT_PolyQuadraticBezierSegment *aPolyQuadraticBezierSegment = data; - - gs_free_object(ms->memory, aPolyQuadraticBezierSegment->Points, - "PolyQuadraticBezierSegment_done"); - gs_free_object(ms->memory, aPolyQuadraticBezierSegment, "PolyQuadraticBezierSegment_done"); - return 0; -} - - -const met_element_t met_element_procs_PolyQuadraticBezierSegment = { - "PolyQuadraticBezierSegment", - { - PolyQuadraticBezierSegment_cook, - PolyQuadraticBezierSegment_action, - PolyQuadraticBezierSegment_done - } -}; - -/* Path.Data has no attributes, must contain a PathGeometry - */ -Path_Data_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - *ppdata = NULL; - return 0; -} - -private int -Path_Data_action(void *data, met_state_t *ms) -{ - return 0; -} - -private int -Path_Data_done(void *data, met_state_t *ms) -{ - if (data != 0) - return gs_throw(-1, "bad food"); - return 0; -} - -const met_element_t met_element_procs_Path_Data = { - "Path_Data", - { - Path_Data_cook, - Path_Data_action, - Path_Data_done - } -}; diff --git a/met/metrecorder.c b/met/metrecorder.c deleted file mode 100644 index aeffe13bb..000000000 --- a/met/metrecorder.c +++ /dev/null @@ -1,123 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id$*/ - -/* record and playback cooked elements */ - -#include "metrecorder.h" -#include "gserror.h" -#include "string_.h" -#include "metutil.h" - -typedef struct metrecord_s metrecord_t; - -struct metrecord_s { - data_element_t *data; - struct metrecord_s *next; - /* NB should be debugging */ - bool open; - char *element; - int depth; - -}; - -/* NB static fixme */ - -private metrecord_t *head = NULL; -private metrecord_t *tail = NULL; - -int -met_record(gs_memory_t *mem, const data_element_t *data, const char *xmlel, bool open, int depth) -{ - metrecord_t *node = (metrecord_t *)gs_alloc_bytes(mem, - sizeof(metrecord_t), "met record node"); - data_element_t *el = (data_element_t *)gs_alloc_bytes(mem, - sizeof(met_element_t), "met data element"); - void *cooked_data = gs_alloc_bytes(mem, - gs_object_size(mem, data->cooked_data), "met record cooked data"); - - if (!node || !data || !el) { - return gs_throw(-1, "memory error recording"); - } - - *el = *data; - memcpy(cooked_data, data->cooked_data, - gs_object_size(mem, data->cooked_data)); - el->cooked_data = cooked_data; - node->data = el; - node->open = open; - node->element = met_strdup(mem, xmlel, "met_record"); - node->depth = depth; - if (head == NULL) { - head = tail = node; - } else { - tail = tail->next = node; - } - return 0; -} - -int -met_playback(met_state_t *ms) -{ - metrecord_t *node = ms->current_resource; - int code = 0; - - if (node == NULL) { - return gs_throw(-1, "playback list is empty"); - } - - do { - data_element_t *data = node->data; - met_element_procs_t *procs = data->met_element_procs; - met_selector sel = data->sel; - - switch (sel) { - case met_cook: - /* nb should clean up but shouldn't happen */ - return gs_throw(-1, "fatal cooking in playback"); - break; - - case met_action: - if (gs_debug_c('i')) dprintf2("%d:opening %s\n", node->depth, node->element); - code = (*procs->action)(data->cooked_data, ms); - break; - case met_done: - if (gs_debug_c('i')) dprintf2("%d:closing %s\n", node->depth, node->element); - code = (*procs->done)(data->cooked_data, ms); - break; - default: - /* nb should clean up but shouldn't happen */ - return gs_throw(-1, "playback error unknown operation"); - } - - if (code < 0) - return gs_rethrow(code, "playback error"); - if (node == tail) - break; - node = node->next; - } while (1); - - return code; -} - -int -met_store(met_state_t *ms) -{ - int code = 0; - if (code == 0) { - ms->current_resource = head; - head = NULL; - return code; - } - return gs_throw(code, "failed to store resource"); -} diff --git a/met/metrecorder.h b/met/metrecorder.h deleted file mode 100644 index 1865bd4ff..000000000 --- a/met/metrecorder.h +++ /dev/null @@ -1,29 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id$*/ - -/* metro recorder interface */ - -#ifndef metrecorder_INCLUDED -# define metrecorder_INCLUDED - -#include "metparse.h" - -/* record a cooked resource */ -int met_record(gs_memory_t *mem, const data_element_t *data, const char *el, bool open, int depth); -/* play it back */ -int met_playback(met_state_t *ms); -/* store it in the state */ -int met_store(met_state_t *ms); - -#endif /* metrecorder_INCLUDED */ diff --git a/met/metsimple.h b/met/metsimple.h deleted file mode 100644 index 73956b9b8..000000000 --- a/met/metsimple.h +++ /dev/null @@ -1,68 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ -/* $Id:*/ - -/* metsimple.h */ - -/* metro simple types, NB work to be done on checking -- patterns, - collapsing whitespace etc. */ - -#ifndef metsimple_INCLUDED -# define metsimple_INCLUDED - -#include "std.h" - -typedef char * ST_AbbrGeom; -typedef char * ST_AbbrGeomF; -typedef char * ST_Array; -typedef char * ST_BleedBox; -typedef bool ST_Boolean; -typedef char * ST_CaretStops; -typedef char * ST_ClrIntMode; -typedef char * ST_Color; -typedef char * ST_CombineMode; -typedef char * ST_ContentBox; -typedef char * ST_DashCap; -typedef double ST_Double; -typedef char * ST_EdgeMode; -typedef char * ST_EvenArrayPos; -typedef char * ST_FillRule; -typedef double ST_GEOne; -typedef double ST_GEZero; -typedef char * ST_Indices; -typedef char * ST_LineCap; -typedef char * ST_LineJoin; -typedef char * ST_MappingMode; -typedef char * ST_Matrix; /* NB orig. def. was a union of MatrixDepr and MatrixBare */ -typedef char * ST_MatrixDepr; -typedef char * ST_MatrixBare; -typedef char * ST_Name; /* NB really an xsd ID type */ -typedef char * ST_Point; -typedef char * ST_Points; -typedef char * ST_RscRef; -typedef char * ST_RscRefAbbrGeomF; /* NB union ST_AbbrGeomF and ST_RscRef */ -typedef char * ST_RscRefColor; /* NB union ST_Color and ST_RscRef */ -typedef char * ST_RscRefMatrix; /* NB another union */ -typedef char * ST_SpreadMethod; -typedef char * ST_Stretch; -typedef char * ST_StyleSimulations; -typedef char * ST_SweepDirection; -typedef char * ST_TileMode; -typedef char * ST_UnicodeString; -typedef char * ST_ViewBox; -typedef char * ST_ViewUnits; -typedef double ST_ZeroOne; - -/* accessors */ - - -#endif /* metsimple_INCLUDED */ diff --git a/met/metstate.c b/met/metstate.c deleted file mode 100644 index e264bfd21..000000000 --- a/met/metstate.c +++ /dev/null @@ -1,85 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id$*/ - -#include "std.h" -#include "metsimple.h" -#include "metcomplex.h" -#include "metstate.h" -#include "metutil.h" -#include "metgstate.h" -#include "plfont.h" - -/* allocate a metro state */ -met_state_t * -met_state_alloc(gs_memory_t *mem) -{ - met_state_t *pmets = - (met_state_t *)gs_alloc_bytes(mem, - sizeof(met_state_t), - "met_state_alloc"); - if (pmets == 0) - return 0; - pmets->memory = mem; - /* nb belongs there should be a metro state initialization - function somewhere */ - pl_dict_init(&pmets->font_dict, mem, pl_free_font); - pmets->font_dir = gs_font_dir_alloc(mem); - pmets->current_resource = 0; - pmets->GradientStops = NULL; - return pmets; -} - -/* release a metro state */ -void -met_state_release(met_state_t *pmets) -{ - gs_free_object(pmets->memory, pmets, "met_state_release"); -} - -void -met_state_init(met_state_t *pmet, gs_state *pgs) -{ - pmet->pgs = pgs; - met_gstate_init(pgs, pmet->memory, pmet); -} - - -/* nb where should this really belong? */ - -void met_cleargradientstops(met_state_t *ms) -{ - ms->GradientStops = NULL; -} - -void met_appendgradientstop(met_state_t *ms, void *stop) -{ - CT_GradientStop *iter; - iter = ms->GradientStops; - if (!iter) - { - ms->GradientStops = stop; - } - else - { - while (iter->next) - iter = iter->next; - iter->next = stop; - } -} - -void *met_currentgradientstops(met_state_t *ms) -{ - return ms->GradientStops; -} - diff --git a/met/metstate.h b/met/metstate.h deleted file mode 100644 index 5aa453fe8..000000000 --- a/met/metstate.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id$*/ - -/* metro state */ - -#ifndef metstate_INCLUDED -# define metstate_INCLUDED - -#include "stdpre.h" -#include "std.h" -#include "gstypes.h" -#include "gsstate.h" -#include "gsmemory.h" -#include "gsfont.h" -#include "pltop.h" /* for pjls pointer */ -#include "pldict.h" - -typedef struct met_state_s met_state_t; - -struct met_state_s { - gs_memory_t *memory; - void *pzip; - gs_state *pgs; - void *client_data; - pl_interp_instance_t *pjls; /* probably not used */ - int (*end_page)(met_state_t *pxs, int num_copies, int flush); - int entries_recorded; - pl_dict_t font_dict; - pl_dict_t pattern_dict; - gs_font_dir *font_dir; - void *current_resource; - void *GradientStops; -}; - -/* allocate a metro state */ -met_state_t *met_state_alloc(gs_memory_t *mem); - -/* release a metro state */ -void met_state_release(met_state_t *met); - -/* inialize the metro state */ -void met_state_init(met_state_t *met, gs_state *gs_state); - -void *met_currentgradientstops(met_state_t *ms); -void met_cleargradientstops(met_state_t *ms); -void met_appendgradientstop(met_state_t *ms, void *stop); - -#endif /* metstate_INCLUDED */ diff --git a/met/mettop.c b/met/mettop.c deleted file mode 100644 index 1097b7c86..000000000 --- a/met/mettop.c +++ /dev/null @@ -1,466 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ -/*$Id$*/ - -/* Top-level API implementation of METRO */ - -#include "memory_.h" -#include "metstate.h" -#include "metparse.h" -#include "zipparse.h" -#include "pltop.h" -#include "gsstate.h" -#include "gserrors.h" -#include "gspaint.h" - -/* ------------ METRO wrapper handling here ------- */ - - -/* ------------ METRO wrapper handling done ------- */ - - -/************************************************************/ -/******** Language wrapper implementation (see pltop.h) *****/ -/************************************************************/ - -/* - * METRO interpeter: derived from pl_interp_t - */ -typedef struct met_interp_s { - pl_interp_t pl; /* common part: must be first */ - gs_memory_t *pmemory; /* memory allocator to use */ -} met_interp_t; - -/* - * MET interpreter instance: derived from pl_interp_instance_t - */ -typedef struct met_interp_instance_s { - pl_interp_instance_t pl; /* common part: must be first */ - gs_memory_t *pmemory; /* memory allocator to use */ - met_parser_state_t *pst; /* parser state */ - zip_state_t *pzip; /* zip state */ - met_state_t *pmets; /* interp state */ - gs_state *pgs; /* grafix state */ - pl_page_action_t pre_page_action; /* action before page out */ - void *pre_page_closure; /* closure to call pre_page_action with */ - pl_page_action_t post_page_action; /* action before page out */ - void *post_page_closure;/* closure to call post_page_action with */ -} met_interp_instance_t; - - -/* Get implemtation's characteristics */ -const pl_interp_characteristics_t * /* always returns a descriptor */ -met_impl_characteristics( - const pl_interp_implementation_t *pimpl /* implementation of interpereter to alloc */ -) -{ - /* version and build date are not currently used */ -#define METVERSION NULL -#define METBUILDDATE NULL - static pl_interp_characteristics_t met_characteristics = { - "METRO", -#ifndef PARSE_XML_HACK - "PK", /* NB string to recognized metro file */ -#else - "<", /* NB string to recognized metro file */ -#endif - "Artifex", - METVERSION, - METBUILDDATE, - MET_PARSER_MIN_INPUT_SIZE, /* Minimum input size */ - }; - return &met_characteristics; -} - -/* Don't need to do anything to MET interpreter */ -private int /* ret 0 ok, else -ve error code */ -met_impl_allocate_interp( - pl_interp_t **ppinterp, /* RETURNS abstract interpreter struct */ - const pl_interp_implementation_t *pimpl, /* implementation of interpereter to alloc */ - gs_memory_t *pmem /* allocator to allocate interp from */ -) -{ - static pl_interp_t interp; /* there's only one interpreter */ - - /* There's only one MET interp, so return the static */ - *ppinterp = &interp; - return 0; /* success */ -} - -/* - * End-of-page called back by METRO - */ -private int -met_end_page_top(met_state_t *pmets, - int num_copies, - int flush -) -{ - met_interp_instance_t *pmeti = (met_interp_instance_t *)(pmets->client_data); - pl_interp_instance_t *pinstance = (pl_interp_instance_t *)pmeti; - int code = 0; - - /* do pre-page action */ - if (pmeti->pre_page_action) { - code = pmeti->pre_page_action(pinstance, pmeti->pre_page_closure); - if (code < 0) - return code; - if (code != 0) - return 0; /* code > 0 means abort w/no error */ - } - - /* output the page */ - code = gs_output_page(pmeti->pgs, num_copies, flush); - if (code < 0) - return code; - - /* do post-page action */ - if (pmeti->post_page_action) { - code = pmeti->post_page_action(pinstance, pmeti->post_page_closure); - if (code < 0) - return code; - } - return 0; -} - -/* Do per-instance interpreter allocation/init. No device is set yet */ -private int /* ret 0 ok, else -ve error code */ -met_impl_allocate_interp_instance( - pl_interp_instance_t **ppinstance, /* RETURNS instance struct */ - pl_interp_t *pinterp, /* dummy interpreter */ - gs_memory_t *pmem /* allocator to allocate instance from */ -) -{ - /* Allocate everything up front */ - met_interp_instance_t *pmeti /****** SHOULD HAVE A STRUCT DESCRIPTOR ******/ - = (met_interp_instance_t *)gs_alloc_bytes( pmem, - sizeof(met_interp_instance_t), - "met_allocate_interp_instance(met_interp_instance_t)" - ); - gs_state *pgs = gs_state_alloc(pmem); - met_parser_state_t *pst = met_process_alloc(pmem); /* parser init, cheap */ - met_state_t *pmets = met_state_alloc(pmem); /* inits interp state */ - /* If allocation error, deallocate & return NB this doesn't - make sense see all languages. */ - if (!pmeti || !pgs || !pst || !pmets) { - if (!pmeti) - gs_free_object(pmem, pmeti, "met_impl_allocate_interp_instance(met_interp_instance_t)"); - if (!pgs) - gs_state_free(pgs); - if (!pst) - met_process_release(pst); - if (!pmets) - met_state_release(pmets); - return gs_error_VMerror; - } - - /* Setup pointers to allocated mem within instance */ - pmeti->pmemory = pmem; - pmeti->pgs = pgs; - pmeti->pmets = pmets; - pmeti->pst = pst; - - /* zero-init pre/post page actions for now */ - pmeti->pre_page_action = 0; - pmeti->post_page_action = 0; - - /* General init of met_state */ - met_state_init(pmets, pgs); - pmets->client_data = pmeti; - pmets->end_page = met_end_page_top; - - pmeti->pzip = zip_init_instance(pmem); - pmets->pzip = pmeti->pzip; - - /* Return success */ - *ppinstance = (pl_interp_instance_t *)pmeti; - return 0; -} - -/* Set a client language into an interperter instance */ -private int /* ret 0 ok, else -ve error code */ -met_impl_set_client_instance( - pl_interp_instance_t *pinstance, /* interp instance to use */ - pl_interp_instance_t *pclient, /* client to set */ - pl_interp_instance_clients_t which_client -) -{ - met_interp_instance_t *pmeti = (met_interp_instance_t *)pinstance; - if ( which_client == PJL_CLIENT ) - pmeti->pmets->pjls = pclient; - /* ignore unknown clients */ - return 0; -} - -/* Set an interpreter instance's pre-page action */ -private int /* ret 0 ok, else -ve err */ -met_impl_set_pre_page_action( - pl_interp_instance_t *pinstance, /* interp instance to use */ - pl_page_action_t action, /* action to execute (rets 1 to abort w/o err) */ - void *closure /* closure to call action with */ -) -{ - met_interp_instance_t *pmeti = (met_interp_instance_t *)pinstance; - pmeti->pre_page_action = action; - pmeti->pre_page_closure = closure; - return 0; -} - -/* Set an interpreter instance's post-page action */ -private int /* ret 0 ok, else -ve err */ -met_impl_set_post_page_action( - pl_interp_instance_t *pinstance, /* interp instance to use */ - pl_page_action_t action, /* action to execute */ - void *closure /* closure to call action with */ -) -{ - met_interp_instance_t *pmeti = (met_interp_instance_t *)pinstance; - pmeti->post_page_action = action; - pmeti->post_page_closure = closure; - return 0; -} - -/* Set a device into an interperter instance */ -private int /* ret 0 ok, else -ve error code */ -met_impl_set_device( - pl_interp_instance_t *pinstance, /* interp instance to use */ - gx_device *pdevice /* device to set (open or closed) */ -) -{ - int code; - met_interp_instance_t *pmeti = (met_interp_instance_t *)pinstance; - enum {Sbegin, Ssetdevice, Sinitg, Sgsave, Serase, Sdone} stage; - stage = Sbegin; - gs_opendevice(pdevice); - - /* Set the device into the gstate */ - stage = Ssetdevice; - if ((code = gs_setdevice_no_erase(pmeti->pgs, pdevice)) < 0) /* can't erase yet */ - goto pisdEnd; - - /* Init XL graphics */ - stage = Sinitg; - /* NB met initialize graphics ?? */ - - gs_setaccuratecurves(pmeti->pgs, true); /* NB not sure */ - - /* gsave and grestore (among other places) assume that */ - /* there are at least 2 gstates on the graphics stack. */ - /* Ensure that now. */ - stage = Sgsave; - if ( (code = gs_gsave(pmeti->pgs)) < 0) - goto pisdEnd; - - stage = Serase; - if ( (code = gs_erasepage(pmeti->pgs)) < 0 ) - goto pisdEnd; - - stage = Sdone; /* success */ - - /* Unwind any errors */ - pisdEnd: - switch (stage) { - case Sdone: /* don't undo success */ - break; - - case Serase: /* gs_erasepage failed */ - /* undo gsave */ - gs_grestore_only(pmeti->pgs); /* destroys gs_save stack */ - /* fall thru to next */ - case Sgsave: /* gsave failed */ - case Sinitg: - /* undo setdevice */ - gs_nulldevice(pmeti->pgs); - /* fall thru to next */ - - case Ssetdevice: /* gs_setdevice failed */ - case Sbegin: /* nothing left to undo */ - break; - } - return code; -} - -private int -met_impl_get_device_memory( - pl_interp_instance_t *pinstance, /* interp instance to use */ - gs_memory_t **ppmem) -{ - return 0; -} - -/* Prepare interp instance for the next "job" */ -private int /* ret 0 ok, else -ve error code */ -met_impl_init_job( - pl_interp_instance_t *pinstance /* interp instance to start job in */ -) -{ - met_interp_instance_t *pmeti = (met_interp_instance_t *)pinstance; - /* do something with pmeti to stop the compiler unused var warning */ - if (!pmeti) - return -1; - else - return 0; -} - -/* Parse a cursor-full of data */ -private int /* ret 0 or +ve if ok, else -ve error code */ -met_impl_process( - pl_interp_instance_t *pinstance, /* interp instance to process data job in */ - stream_cursor_read *pcursor /* data to process */ -) -{ - met_interp_instance_t *pmeti = (met_interp_instance_t *)pinstance; - int code = 0; - - if (pmeti->pzip->zip_mode) - code = zip_process(pmeti->pst, pmeti->pmets, pmeti->pzip, pcursor); - else - code = met_process(pmeti->pst, pmeti->pmets, pmeti->pzip, pcursor); - - return code; -} - -/* Skip to end of job ret 1 if done, 0 ok but EOJ not found, else -ve error code */ -private int -met_impl_flush_to_eoj( - pl_interp_instance_t *pinstance, /* interp instance to flush for */ - stream_cursor_read *pcursor /* data to process */ -) -{ - /* assume met can be pjl embedded, probably a bad assumption */ - const byte *p = pcursor->ptr; - const byte *prlimit = pcursor->limit; - - /* Skip to, but leave UEL in buffer for PJL to find later */ - for (; p < prlimit; ++p) - if (p[1] == '\033') { - uint avail = prlimit - p; - - if (memcmp(p + 1, "\033%-12345X", min(avail, 9))) - continue; - if (avail < 9) - break; - pcursor->ptr = p; - return 1; /* found eoj */ - } - pcursor->ptr = p; - return 0; /* need more */ -} - -/* Parser action for end-of-file */ -private int /* ret 0 or +ve if ok, else -ve error code */ -met_impl_process_eof( - pl_interp_instance_t *pinstance /* interp instance to process data job in */ -) -{ - /* met_interp_instance_t *pmeti = (met_interp_instance_t *)pinstance; */ - return 0; -} - -/* Report any errors after running a job */ -private int /* ret 0 ok, else -ve error code */ -met_impl_report_errors( - pl_interp_instance_t *pinstance, /* interp instance to wrap up job in */ - int code, /* prev termination status */ - long file_position, /* file position of error, -1 if unknown */ - bool force_to_cout /* force errors to cout */ -) -{ - return 0; -} - -/* Wrap up interp instance after a "job" */ -private int /* ret 0 ok, else -ve error code */ -met_impl_dnit_job( - pl_interp_instance_t *pinstance /* interp instance to wrap up job in */ -) -{ - met_interp_instance_t *pmeti = (met_interp_instance_t *)pinstance; - /* do something with pmeti to stop the compiler unused var warning */ - - if (!pmeti) - return -1; - else { - // NB lets free some stuff. - zip_end_job(pmeti->pst, pmeti->pmets, pmeti->pzip); - } - return 0; -} - -/* Remove a device from an interperter instance */ -private int /* ret 0 ok, else -ve error code */ -met_impl_remove_device( - pl_interp_instance_t *pinstance /* interp instance to use */ -) -{ - int code = 0; /* first error status encountered */ - int error; - met_interp_instance_t *pmeti = (met_interp_instance_t *)pinstance; - /* return to original gstate */ - gs_grestore_only(pmeti->pgs); /* destroys gs_save stack */ - /* Deselect device */ - /* NB */ - error = gs_nulldevice(pmeti->pgs); - if (code >= 0) - code = error; - - return code; -} - -/* Deallocate a interpreter instance */ -private int /* ret 0 ok, else -ve error code */ -met_impl_deallocate_interp_instance( - pl_interp_instance_t *pinstance /* instance to dealloc */ -) -{ - met_interp_instance_t *pmeti = (met_interp_instance_t *)pinstance; - gs_memory_t *pmem = pmeti->pmemory; - - met_process_shutdown(pmeti->pst); - met_process_release(pmeti->pst); - met_state_release(pmeti->pmets); - gs_free_object(pmem, pmeti, "met_impl_deallocate_interp_instance(met_interp_instance_t)"); - return 0; -} - -/* Do static deinit of MET interpreter */ -private int /* ret 0 ok, else -ve error code */ -met_impl_deallocate_interp( - pl_interp_t *pinterp /* interpreter to deallocate */ -) -{ - /* nothing to do */ - return 0; -} - - -/* Parser implementation descriptor */ -const pl_interp_implementation_t xps_implementation = { - met_impl_characteristics, - met_impl_allocate_interp, - met_impl_allocate_interp_instance, - met_impl_set_client_instance, - met_impl_set_pre_page_action, - met_impl_set_post_page_action, - met_impl_set_device, - met_impl_init_job, - met_impl_process, - met_impl_flush_to_eoj, - met_impl_process_eof, - met_impl_report_errors, - met_impl_dnit_job, - met_impl_remove_device, - met_impl_deallocate_interp_instance, - met_impl_deallocate_interp, - met_impl_get_device_memory, -}; - diff --git a/met/mettparse.c b/met/mettparse.c deleted file mode 100644 index 065fa7651..000000000 --- a/met/mettparse.c +++ /dev/null @@ -1,344 +0,0 @@ -#include "fitz.h" -#include "samus.h" - -#include <expat.h> - -#define XMLBUFLEN 4096 - -struct sa_xmlitem_s -{ - char *name; - char **atts; - sa_xmlitem *up; - sa_xmlitem *down; - sa_xmlitem *next; -}; - -struct sa_xmlparser_s -{ - fz_error *error; - sa_xmlitem *root; - sa_xmlitem *head; - int nexted; - int downed; -}; - -static void dropitem(sa_xmlitem *item) -{ - sa_xmlitem *next; - while (item) - { - next = item->next; - if (item->down) - dropitem(item->down); - fz_free(item); - item = next; - } -} - -static void onopentag(void *zp, const char *name, const char **atts) -{ - struct sa_xmlparser_s *sp = zp; - sa_xmlitem *item; - sa_xmlitem *tail; - int namelen; - int attslen; - int textlen; - char *p; - int i; - - if (sp->error) - return; - - /* count size to alloc */ - - namelen = strlen(name) + 1; - attslen = sizeof(char*); - textlen = 0; - for (i = 0; atts[i]; i++) - { - attslen += sizeof(char*); - textlen += strlen(atts[i]) + 1; - } - - item = fz_malloc(sizeof(sa_xmlitem) + attslen + namelen + textlen); - if (!item) - { - sp->error = fz_outofmem; - return; - } - - /* copy strings to new memory */ - - item->atts = (char**) (((char*)item) + sizeof(sa_xmlitem)); - item->name = ((char*)item) + sizeof(sa_xmlitem) + attslen; - p = ((char*)item) + sizeof(sa_xmlitem) + attslen + namelen; - - strcpy(item->name, name); - for (i = 0; atts[i]; i++) - { - item->atts[i] = p; - strcpy(item->atts[i], atts[i]); - p += strlen(p) + 1; - } - - item->atts[i] = 0; - - /* link item into tree */ - - item->up = sp->head; - item->down = nil; - item->next = nil; - - if (!sp->head) - { - sp->root = item; - sp->head = item; - return; - } - - if (!sp->head->down) - { - sp->head->down = item; - sp->head = item; - return; - } - - tail = sp->head->down; - while (tail->next) - tail = tail->next; - tail->next = item; - sp->head = item; -} - -static void onclosetag(void *zp, const char *name) -{ - struct sa_xmlparser_s *sp = zp; - - if (sp->error) - return; - - if (sp->head) - sp->head = sp->head->up; -} - -static inline int isxmlspace(int c) -{ - return c == ' ' || c == '\t' || c == '\r' || c == '\n'; -} - -static void ontext(void *zp, const char *buf, int len) -{ - struct sa_xmlparser_s *sp = zp; - int i; - - if (sp->error) - return; - - for (i = 0; i < len; i++) - { - if (!isxmlspace(buf[i])) - { - char *tmp = fz_malloc(len + 1); - const char *atts[] = {"", tmp, 0}; - if (!tmp) - { - sp->error = fz_outofmem; - return; - } - memcpy(tmp, buf, len); - tmp[len] = 0; - onopentag(zp, "", atts); - onclosetag(zp, ""); - fz_free(tmp); - return; - } - } -} - -fz_error * -sa_openxml(sa_xmlparser **spp, fz_stream *file, int ns) -{ - fz_error *error = nil; - sa_xmlparser *sp; - XML_Parser xp; - char *buf; - int len; - - sp = fz_malloc(sizeof(sa_xmlparser)); - if (!sp) - return fz_outofmem; - - sp->error = nil; - sp->root = nil; - sp->head = nil; - sp->downed = 0; - sp->nexted = 0; - - if (ns) - xp = XML_ParserCreateNS(nil, ns); - else - xp = XML_ParserCreate(nil); - if (!xp) - { - fz_free(sp); - return fz_outofmem; - } - - XML_SetUserData(xp, sp); - XML_SetParamEntityParsing(xp, XML_PARAM_ENTITY_PARSING_NEVER); - - XML_SetStartElementHandler(xp, onopentag); - XML_SetEndElementHandler(xp, onclosetag); - XML_SetCharacterDataHandler(xp, ontext); - - while (1) - { - buf = XML_GetBuffer(xp, XMLBUFLEN); - - len = fz_read(file, buf, XMLBUFLEN); - if (len < 0) - { - error = fz_ioerror(file); - goto cleanup; - } - - if (!XML_ParseBuffer(xp, len, len == 0)) - { - error = fz_throw("ioerror: xml: %s", - XML_ErrorString(XML_GetErrorCode(xp))); - goto cleanup; - } - - if (sp->error) - { - error = sp->error; - sp->error = nil; - goto cleanup; - } - - if (len == 0) - break; - } - - sp->head = nil; - *spp = sp; - return nil; - -cleanup: - if (sp->root) - dropitem(sp->root); - fz_free(sp); - XML_ParserFree(xp); - return error; -} - -void -sa_closexml(sa_xmlparser *sp) -{ - if (sp->root) - dropitem(sp->root); - fz_free(sp); -} - -static void indent(int n) -{ - while (n--) - printf(" "); -} - -void -sa_debugxml(sa_xmlitem *item, int level) -{ - int i; - - while (item) - { - indent(level); - - if (strlen(item->name) == 0) - printf("%s\n", item->atts[1]); - else - { - printf("<%s", item->name); - - for (i = 0; item->atts[i]; i += 2) - printf(" %s=\"%s\"", item->atts[i], item->atts[i+1]); - - if (item->down) - { - printf(">\n"); - sa_debugxml(item->down, level + 1); - indent(level); - printf("</%s>\n", item->name); - } - else - printf(" />\n"); - } - - item = item->next; - } -} - -sa_xmlitem * -sa_xmlnext(sa_xmlparser *sp) -{ - if (sp->downed) - return nil; - - if (!sp->head) - { - sp->head = sp->root; - return sp->head; - } - - if (!sp->nexted) - { - sp->nexted = 1; - return sp->head; - } - - if (sp->head->next) - { - sp->head = sp->head->next; - return sp->head; - } - - return nil; -} - -void -sa_xmldown(sa_xmlparser *sp) -{ - if (!sp->downed && sp->head && sp->head->down) - sp->head = sp->head->down; - else - sp->downed ++; - sp->nexted = 0; -} - -void -sa_xmlup(sa_xmlparser *sp) -{ - if (!sp->downed && sp->head && sp->head->up) - sp->head = sp->head->up; - else - sp->downed --; -} - -char * -sa_xmlname(sa_xmlitem *item) -{ - return item->name; -} - -char * -sa_xmlatt(sa_xmlitem *item, char *att) -{ - int i; - for (i = 0; item->atts[i]; i += 2) - if (!strcmp(item->atts[i], att)) - return item->atts[i + 1]; - return nil; -} - diff --git a/met/mettree.h b/met/mettree.h deleted file mode 100644 index bf1ae2934..000000000 --- a/met/mettree.h +++ /dev/null @@ -1,15 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ -/* $Id:*/ - -/* mettree.h */ - diff --git a/met/metundone.c b/met/metundone.c deleted file mode 100644 index a8c12fc25..000000000 --- a/met/metundone.c +++ /dev/null @@ -1,122 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id: */ - -/* metro undone elments. - - Remove an UNDONE_STUB from the list. - - Generate a template - use the template with instructions below or - make your own. - -*/ - -#include "metelement.h" - -#define UNDONE_STUB(element)\ - const met_element_t met_element_procs_ ## element = {\ - #element, { NULL, NULL, NULL } } - -//UNDONE_STUB(Canvas_Clip); -UNDONE_STUB(Canvas_OpacityMask); -//UNDONE_STUB(Canvas_RenderTransform); -UNDONE_STUB(Canvas_Resources); -UNDONE_STUB(DocumentReference); -UNDONE_STUB(FixedDocument); -UNDONE_STUB(FixedDocumentSequence); -UNDONE_STUB(FixedPage_RenderTransform); -UNDONE_STUB(FixedPage_Resources); -UNDONE_STUB(Glyphs_Clip); -UNDONE_STUB(Glyphs_OpacityMask); -UNDONE_STUB(Glyphs_RenderTransform); -// UNDONE_STUB(GradientStop); -UNDONE_STUB(ImageBrush_Transform); -// UNDONE_STUB(LinearGradientBrush); -UNDONE_STUB(LinearGradientBrush_GradientStops); -UNDONE_STUB(LinearGradientBrush_Transform); -UNDONE_STUB(LinkTarget); -//UNDONE_STUB(MatrixTransform); -UNDONE_STUB(PageContent); -UNDONE_STUB(PageContent_LinkTargets); -UNDONE_STUB(Path_Clip); -//UNDONE_STUB(Path_Data); -UNDONE_STUB(Path_OpacityMask); -UNDONE_STUB(Path_RenderTransform); -UNDONE_STUB(PathGeometry_Transform); -// UNDONE_STUB(RadialGradientBrush); -UNDONE_STUB(RadialGradientBrush_GradientStops); -UNDONE_STUB(RadialGradientBrush_Transform); -UNDONE_STUB(ResourceDictionary); -UNDONE_STUB(VisualBrush_Transform); -UNDONE_STUB(VisualBrush_Visual); - -#undef UNDONE_STUB - -#if 0 - -/* the following is a template for an element implemenation. Copy the - template and then replace the word ELEMENT (case matters) with the - name of the element - i.e. FixedPage, Path, etc. This fills in the - boilerplate of the template - - ------------- BEGIN TEMPLATE --------------- */ - -/* element constructor */ -private int -ELEMENT_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_ELEMENT *aELEMENT = - (CT_ELEMENT *)gs_alloc_bytes(ms->memory, - sizeof(CT_ELEMENT), - "ELEMENT_cook"); - int i; - - memset(aELEMENT, 0, sizeof(CT_ELEMENT)); - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - - } - - /* copy back the data for the parser. */ - *ppdata = aELEMENT; - return 0; -} - -/* action associated with this element */ -private int -ELEMENT_action(void *data, met_state_t *ms) -{ - CT_ELEMENT *aELEMENT = data; - return 0; -} - -private int -ELEMENT_done(void *data, met_state_t *ms) -{ - - gs_free_object(ms->memory, data, "ELEMENT_done"); - return 0; /* incomplete */ -} - - -const met_element_t met_element_procs_ELEMENT = { - "ELEMENT", - { - ELEMENT_cook, - ELEMENT_action, - ELEMENT_done - } -}; - -#endif /* 0 */ diff --git a/met/metutil.c b/met/metutil.c deleted file mode 100644 index 7fe417e88..000000000 --- a/met/metutil.c +++ /dev/null @@ -1,135 +0,0 @@ -/* Portions Copyright (C) 2007 artofcode LLC. - Portions Copyright (C) 1996, 2001 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ -/* $Id$ */ - -/* metutil.c */ - -#include "metutil.h" -#include "string_.h" -#include <stdlib.h> -#include "ctype_.h" -#include "gserror.h" - -char * -met_strdup(gs_memory_t *mem, const char *str, const char *client) -{ - char *s = NULL; - if ( str ) - s = (char*) gs_alloc_bytes(mem, strlen(str) + 1, client); - if ( s ) - strcpy(s, str); - return s; -} - -int -met_cmp_and_set(char **field, const char *lhs, const char *rhs, const char *attr_name) -{ - /* nb memory hack */ - extern gs_memory_t *gs_mem_ptr; - int cmp = strcmp(lhs, attr_name); - if (cmp == 0) - *field = met_strdup(gs_mem_ptr, rhs, attr_name); - return cmp; -} - -int -met_split(char *b, char **args, bool (*delimfunc)(char c)) -{ - int cnt = 0; - - while (*b != (char)NULL) { - while (delimfunc(*b)) - *b++ = (char)NULL; - *args++ = b; - cnt++; - while((*b != (char)NULL) && (!delimfunc(*b))) - b++; - } - *args = NULL; - - return cnt; -} - - -/* utility to expand empty arguments in a string with a sentinel value */ -char * -met_expand(char *s1, const char *s2, const char delimiter, const char sentinel) -{ - char *s = s1; - char last_char = '\0'; - while (*s2 != '\0') { - if ((*s2 == delimiter) && - (last_char == '\0' || last_char == delimiter)) - *s++ = sentinel; - last_char = *s2; - *s++ = *s2++; - } - /* add the null terminator */ - *s = *s2; - return s1; -} - -/* I am sure there is a better (more robust) meme for this... */ -rgb_t -met_hex2rgb(char *hexstring) -{ - const char *hextable = "0123456789ABCDEF"; - rgb_t rgb; - char *hexstringp = hexstring; - /* nb need to look into color specification */ - if (strlen(hexstring) == 9) - hexstringp += 2; - -#define HEXTABLEINDEX(chr) (strchr(hextable, (toupper(chr))) - hextable) - rgb.r = HEXTABLEINDEX(hexstringp[1]) * 16 + - HEXTABLEINDEX(hexstringp[2]); - rgb.g = HEXTABLEINDEX(hexstringp[3]) * 16 + - HEXTABLEINDEX(hexstringp[4]); - rgb.b = HEXTABLEINDEX(hexstringp[5]) * 16 + - HEXTABLEINDEX(hexstringp[6]); - rgb.r /= 256.0; rgb.g /= 256.0; rgb.b /= 256.0; - return rgb; -} - - -/* these operators set the gs graphics state and don't effect the - metro client state */ -private bool is_Data_delimeter(char b) -{ - return (b == ',') || (isspace(b)); -} - -int -met_get_transform(gs_matrix *gsmat, ST_RscRefMatrix metmat) -{ - if (!metmat) { - gs_make_identity(gsmat); - } else { - char transstring[strlen(metmat)]; - strcpy(transstring, metmat); - /* nb wasteful */ - char *args[strlen(metmat)]; - char **pargs = args; - - if ( 6 != met_split(transstring, args, is_Data_delimeter)) - return gs_throw(-1, "Canvas RenderTransform number of args"); - /* nb checking for sane arguments */ - gsmat->xx = atof(pargs[0]); - gsmat->xy = atof(pargs[1]); - gsmat->yx = atof(pargs[2]); - gsmat->yy = atof(pargs[3]); - gsmat->tx = atof(pargs[4]); - gsmat->ty = atof(pargs[5]); - } - return 0; -} - diff --git a/met/metutil.h b/met/metutil.h deleted file mode 100644 index 2ff558eb5..000000000 --- a/met/metutil.h +++ /dev/null @@ -1,64 +0,0 @@ -/* Portions Copyright (C) 2007 artofcode LLC. - Portions Copyright (C) 1996, 2001 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ -/* $Id$*/ - -/* metutil.h */ - -/* the obligatory metro utilities */ - -#ifndef metutil_INCLUDED -# define metutil_INCLUDED - -#include "stdpre.h" /* for bool */ -#include "gsmemory.h" -#include "gsmatrix.h" -#include "metsimple.h" - -/* utility for splitting up strings - destroys argument and client - must determine supply a large enough argument list to support all - of the parameters. The delimeter function should return true if - the character is a delimeter. The C language library iswhite() - could be used as a delimeter function. Returns number of args. */ - - -int met_split(char *b, char **args, bool (*delimfunc)(char c)); - -/* utility to expand empty arguments in a string with a sentinel value */ -char * -met_expand(char *s1, const char *s2, const char delimiter, const char sentinel); - - -/* strcmp(lhs, attr) || strcpy(*field, rhs) saves keystrokes */ -int met_cmp_and_set(char **field, const char *lhs, const char *rhs, const char *attr_name); - -/* nb we agreed these fields should be handled by hashing the strings - change me */ -#define MYSET(field, value) \ - met_cmp_and_set((field), attr[i], attr[i+1], (value)) - -/* nb should use a gs type but this is expedient for now. Convert an - rgb hex string to an rgb triple */ -typedef struct rgb_s { - double r; - double g; - double b; -} rgb_t; - -rgb_t met_hex2rgb(char *hexstring); - -char *met_strdup(gs_memory_t *mem, const char *str, const char *client); - -int met_get_transform(gs_matrix *gsmat, ST_RscRefMatrix metmat); - - -#define XPS_ALLOC(ctx, size) gs_alloc_bytes(ctx->memory, size, __FUNCTION__) - -#endif /* metutil_INCLUDED */ diff --git a/met/metvector.c b/met/metvector.c deleted file mode 100644 index 38f478d00..000000000 --- a/met/metvector.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ -/* $Id:*/ - -#include "metelement.h" - -/* XML style data type for a path -</Path> - Data="ST_RscRefAbbrGeomF [0..1]" - Fill="ST_RscRefColor [0..1]" - RenderTransform="ST_RscRefMatrix [0..1]" - Clip="ST_RscRefAbbrGeomF [0..1]" - Opacity="ST_ZeroOne [0..1]" - OpacityMask="ST_RscRef [0..1]" - Stroke="ST_RscRefColor [0..1]" - StrokeDashArray="ST_EvenArrayPos [0..1]" - StrokeDashCap="ST_DashCap [0..1]" - StrokeDashOffset="ST_Double [0..1]" - StrokeEndLineCap="ST_LineCap [0..1]" - StrokeStartLineCap="ST_LineCap [0..1]" - StrokeLineJoin="ST_LineJoin [0..1]" - StrokeMiterLimit="ST_GEOne [0..1]" - StrokeThickness="ST_GEZero [0..1]" - Name="ST_Name [0..1]" - FixedPage.NavigateUri="xs:anyURI [0..1]" - xml:lang="[0..1]" - x:Key="[0..1]"> - <Path.RenderTransform> ... </Path.RenderTransform> [0..1] - <Path.Clip> ... </Path.Clip> [0..1] - <Path.OpacityMask> ... </Path.OpacityMask> [0..1] - <Path.Fill> ... </Path.Fill> [0..1] - <Path.Stroke> ... </Path.Stroke> [0..1] - <Path.Data> ... </Path.Data> [0..1] -</Path> - -*/ - diff --git a/met/mt_png.c b/met/mt_png.c deleted file mode 100644 index c36a9b701..000000000 --- a/met/mt_png.c +++ /dev/null @@ -1,194 +0,0 @@ -#include "std.h" -#include "gsmemory.h" -#include "stream.h" -#include "strimpl.h" -#include "gsstate.h" - -#include "png_.h" - -#include "mt_error.h" -#include "metimage.h" - -/* - * PNG using libpng directly (no gs wrappers) - */ - -struct mt_png_io_s -{ - byte *ptr; - byte *lim; -}; - -private void mt_png_read(png_structp png, png_bytep data, png_size_t length) -{ - struct mt_png_io_s *io = png_get_io_ptr(png); - if (io->ptr + length > io->lim) - png_error(png, "Read Error"); - memcpy(data, io->ptr, length); - io->ptr += length; -} - -private png_voidp mt_png_malloc(png_structp png, png_size_t size) -{ - gs_memory_t *mem = png_get_mem_ptr(png); - return gs_alloc_bytes(mem, size, "libpng"); -} - -private void mt_png_free(png_structp png, png_voidp ptr) -{ - gs_memory_t *mem = png_get_mem_ptr(png); - gs_free_object(mem, ptr, "libpng"); -} - -int mt_decode_png(gs_memory_t *mem, byte *rbuf, int rlen, met_image_t *image) -{ - png_structp png; - png_infop info; - struct mt_png_io_s io; - int npasses; - int pass; - int y; - - /* - * Set up PNG structs and input source - */ - - io.ptr = rbuf; - io.lim = rbuf + rlen; - - png = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, - NULL, NULL, NULL, - mem, mt_png_malloc, mt_png_free); - - if (!png) - return mt_throw(-1, "png_create_read_struct"); - - info = png_create_info_struct(png); - if (!info) - return mt_throw(-1, "png_create_info_struct"); - - png_set_read_fn(png, &io, mt_png_read); - - /* - * Jump to here on errors. - */ - - if (setjmp(png_jmpbuf(png))) - { - png_destroy_read_struct(&png, &info, NULL); - return mt_throw(-1, "png reading failed"); - } - - /* - * Read PNG header - */ - - png_read_info(png, info); - - image->width = png_get_image_width(png, info); - image->height = png_get_image_height(png, info); - image->bits = png_get_bit_depth(png, info); - - if (png_get_interlace_type(png, info) == PNG_INTERLACE_ADAM7) - { - npasses = png_set_interlace_handling(png); - } - else - { - npasses = 1; - } - - /* - * Ask PNG to transform some types of images for us. - * NB: what about color-keyed transparency? - */ - - if (png_get_color_type(png, info) == PNG_COLOR_TYPE_PALETTE) - { - png_set_palette_to_rgb(png); /* aliases to png_expand() */ - image->bits = 8; - } - - if (png_get_color_type(png, info) & PNG_COLOR_MASK_ALPHA) - { - png_set_strip_alpha(png); - } - - if (image->bits == 16) - { - png_set_strip_16(png); - image->bits = 8; - } - - switch (png_get_color_type(png, info)) - { - case PNG_COLOR_TYPE_GRAY: - image->comps = 1; - image->colorspace = MT_GRAY; - break; - - case PNG_COLOR_TYPE_PALETTE: - case PNG_COLOR_TYPE_RGB: - image->comps = 3; - image->colorspace = MT_RGB; - break; - - case PNG_COLOR_TYPE_GRAY_ALPHA: - image->comps = 1; - image->colorspace = MT_GRAY; - break; - - case PNG_COLOR_TYPE_RGB_ALPHA: - image->comps = 3; - image->colorspace = MT_RGB; - break; - - default: - return mt_throw(-1, "cannot handle this png color type"); - } - - image->stride = (image->width * image->comps * image->bits + 7) / 8; - - /* - * Extract DPI, default to 96 dpi - */ - - image->xres = 96; - image->yres = 96; - - if (info->valid & PNG_INFO_pHYs) - { - png_uint_32 xres, yres; - int unit; - png_get_pHYs(png, info, &xres, &yres, &unit); - if (unit == PNG_RESOLUTION_METER) - { - image->xres = xres * 0.0254 + 0.5; - image->yres = yres * 0.0254 + 0.5; - } - } - - /* - * Read rows, filling transformed output into image buffer. - */ - /* NB: 2* allocation hack covers up bad stride on paletted images output as rgba - */ - image->samples = gs_alloc_bytes(mem, 2 * image->stride * image->height, "decodepng"); - - for (pass = 0; pass < npasses; pass++) - { - for (y = 0; y < image->height; y++) - { - png_read_row(png, image->samples + (y * image->stride), NULL); - } - } - - /* - * Clean up memory. - */ - - png_destroy_read_struct(&png, &info, NULL); - - return mt_okay; -} - diff --git a/met/xps_clip.c b/met/xps_clip.c deleted file mode 100644 index d04c8b8f6..000000000 --- a/met/xps_clip.c +++ /dev/null @@ -1,98 +0,0 @@ -/* Copyright (C) 2007 artofcode LLC. - - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id:$ */ - -#include <stdlib.h> /* for atof */ -#include "memory_.h" -#include "ctype_.h" -#include "metcomplex.h" -#include "metstate.h" -#include "metelement.h" -#include "metutil.h" -#include "metparse.h" -#include "gserror.h" -#include "gscoord.h" -#include "gxfixed.h" /* for gdevbbox.h stuff */ -#include "gxdevcli.h" /* for gdevbbox.h stuff */ -#include "gdevbbox.h" -#include "metgstate.h" - - - -private int -Canvas_Clip_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_MatrixTransform *aClip = - (CT_MatrixTransform *)gs_alloc_bytes(ms->memory, - sizeof(CT_MatrixTransform), - "Canvas_Clip_cook"); - int i; - - memset(aClip, 0, sizeof(CT_MatrixTransform)); - -#define MYSET(field, value) \ - met_cmp_and_set((field), attr[i], attr[i+1], (value)) - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - - if(!MYSET(&aClip, "MatrixTransform")) - ; - else - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - /* parse attributes, filling in the zeroed out C struct */ - -#undef MYSET - /* copy back the data for the parser. */ - *ppdata = aClip; - return 0; -} - -private int -Canvas_Clip_action(void *data, met_state_t *ms) -{ - /* - CT_MatrixTransform *aClip = data; - gs_state *pgs = ms->pgs; - int code; - gs_matrix canvas_mat; - - */ - - - return 0; -} - -private int -Canvas_Clip_done(void *data, met_state_t *ms) -{ - CT_MatrixTransform *aClip = data; - gs_state *pgs = ms->pgs; - int code; - - // if((code = gs_clippath(pgs)) < 0) - // return gs_rethrow(code, "Canvas_Clip failed"); - - gs_free_object(ms->memory, data, "Canvas_Clip_done"); - return 0; /* incomplete */ -} - -const met_element_t met_element_procs_Canvas_Clip = { - "Canvas_Clip", - { - Canvas_Clip_cook, - Canvas_Clip_action, - Canvas_Clip_done - } -}; diff --git a/met/xps_gradient_brush.c b/met/xps_gradient_brush.c deleted file mode 100644 index 7e2bfcf71..000000000 --- a/met/xps_gradient_brush.c +++ /dev/null @@ -1,370 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id: */ - -/* gradient brush */ - -/* a big puddle of puke needed for the headers */ -#include "memory_.h" -#include "gsmemory.h" -#include "gsmatrix.h" -#include "gp.h" -#include "metcomplex.h" -#include "metelement.h" -#include "metutil.h" -#include "metstate.h" -#include "metgstate.h" -#include "math_.h" -#include "ctype_.h" -#include "gsimage.h" -#include "metimage.h" -#include "gscspace.h" -#include "gscolor2.h" -#include "gsptype1.h" -#include <stdlib.h> /* nb for atof */ -#include "zipparse.h" -#include "xps_gradient_draw.h" -#include "gxstate.h" -#include "gsutil.h" - -extern int met_PaintPattern(const gs_client_color *pcc, gs_state *pgs); - -/* - * Cooking just extracts the string attributes and puts them into a C struct. - */ - -private int -LinearGradientBrush_cook(void **ppdata, met_state_t *ms, - const char *el, const char **attr) -{ - CT_LinearGradientBrush *brush; - int i; - - brush = (CT_LinearGradientBrush *) gs_alloc_bytes(ms->memory, - sizeof(CT_LinearGradientBrush), - "LinearGradientBrush_cook"); - if (!brush) - return gs_throw(-1, "out of memory: CT_LinearGradientBrush"); - - memset(brush, 0, sizeof(CT_LinearGradientBrush)); - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) - { - if (!strcmp(attr[i], "Opacity")) - brush->Opacity = atof(attr[i+1]); - else if (!MYSET(&brush->ColorInterpolationMode, "ColorInterpolationMode")) - ; - else if (!MYSET(&brush->SpreadMethod, "SpreadMethod")) - ; - else if (!MYSET(&brush->MappingMode, "MappingMode")) - ; - else if (!MYSET(&brush->Transform, "Transform")) - ; - else if (!MYSET(&brush->StartPoint, "StartPoint")) - ; - else if (!MYSET(&brush->EndPoint, "EndPoint")) - ; - else { - gs_throw2(-1, "unsupported attribute %s=%s\n", - attr[i], attr[i+1]); - } - } - - /* what about child LinearGradientBrush.Transform */ - - /* for child LinearGradientBrush.GradientStops*/ - met_cleargradientstops(ms); - - *ppdata = brush; - return gs_okay; -} - -private int -RadialGradientBrush_cook(void **ppdata, met_state_t *ms, - const char *el, const char **attr) -{ - CT_RadialGradientBrush *brush; - int i; - - brush = (CT_RadialGradientBrush *) gs_alloc_bytes(ms->memory, - sizeof(CT_RadialGradientBrush), - "RadialGradientBrush_cook"); - if (!brush) - return gs_throw(-1, "out of memory: CT_RadialGradientBrush"); - - memset(brush, 0, sizeof(CT_RadialGradientBrush)); - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) - { - if (!strcmp(attr[i], "Opacity")) - brush->Opacity = atof(attr[i+1]); - else if (!strcmp(attr[i], "RadiusY")) - brush->RadiusY = atof(attr[i+1]); - else if (!strcmp(attr[i], "RadiusX")) - brush->RadiusX = atof(attr[i+1]); - else if (!MYSET(&brush->ColorInterpolationMode, "ColorInterpolationMode")) - ; - else if (!MYSET(&brush->SpreadMethod, "SpreadMethod")) - ; - else if (!MYSET(&brush->MappingMode, "MappingMode")) - ; - else if (!MYSET(&brush->Transform, "Transform")) - ; - else if (!MYSET(&brush->Center, "Center")) - ; - else if (!MYSET(&brush->GradientOrigin, "GradientOrigin")) - ; - else { - gs_throw2(-1, "unsupported attribute %s=%s\n", - attr[i], attr[i+1]); - } - } - - /* what about child RadialGradientBrush.Transform */ - - /* for child RadialGradientBrush.GradientStops */ - met_cleargradientstops(ms); - - dputs("radial gradient cook\n"); - - *ppdata = brush; - return gs_okay; -} - -private int LinearGradientBrush_done(void *data, met_state_t *ms) -{ - // no you don't! we're still around inside the pattern - // gs_free_object(ms->memory, data, "LinearGradientBrush_done"); - return gs_okay; -} - -private int RadialGradientBrush_done(void *data, met_state_t *ms) -{ - // no you don't! we're still around inside the pattern - // gs_free_object(ms->memory, data, "RadialGradientBrush_done"); - dputs("radial gradient done\n"); - return gs_okay; -} - - -/* - * The paint procedures are called from the pattern struct, for now - * located in metimage.c - */ - -int LinearGradientBrush_paint(void *data, gs_state *pgs) -{ - CT_LinearGradientBrush *brush = data; - CT_GradientStop *stop; - int nstops; - - double stops[4 * 32]; - double start[2]; - double end[2]; - int spread; - int code; - - nstops = 0; - for (stop = met_currentgradientstops(met_state_from_gstate(pgs)); stop; stop = stop->next) - { - rgb_t rgb = met_hex2rgb(stop->Color); - stops[nstops * 4 + 0] = stop->Offset; - stops[nstops * 4 + 1] = rgb.r; - stops[nstops * 4 + 2] = rgb.g; - stops[nstops * 4 + 3] = rgb.b; - nstops ++; - } - - sscanf(brush->StartPoint, "%lg,%lg", &start[0], &start[1]); - sscanf(brush->EndPoint, "%lg,%lg", &end[0], &end[1]); - - if (!brush->SpreadMethod) - spread = XPS_PAD; - else if (!strcmp(brush->SpreadMethod, "Pad")) - spread = XPS_PAD; - else if (!strcmp(brush->SpreadMethod, "Reflect")) - spread = XPS_REFLECT; - else if (!strcmp(brush->SpreadMethod, "Repeat")) - spread = XPS_REPEAT; - else - spread = XPS_PAD; - - code = xps_draw_linear_gradient(gs_state_memory(pgs), pgs, - start, end, spread, stops, nstops); - if (code < 0) - return gs_rethrow(code, "could not draw linear gradient brush"); - - return gs_okay; -} - -int RadialGradientBrush_paint(void *data, gs_state *pgs) -{ - CT_RadialGradientBrush *brush = data; - CT_GradientStop *stop; - double stops[4 * 32]; - int nstops; - double center[2]; - double origin[2]; - double radiusx, radiusy; - int spread; - - int code; - - nstops = 0; - for (stop = met_currentgradientstops(met_state_from_gstate(pgs)); stop; stop = stop->next) - { - rgb_t rgb = met_hex2rgb(stop->Color); - stops[nstops * 4 + 0] = stop->Offset; - stops[nstops * 4 + 1] = rgb.r; - stops[nstops * 4 + 2] = rgb.g; - stops[nstops * 4 + 3] = rgb.b; - nstops ++; - } - - sscanf(brush->Center, "%lg,%lg", ¢er[0], ¢er[1]); - sscanf(brush->GradientOrigin, "%lg,%lg", &origin[0], &origin[1]); - - radiusx = brush->RadiusX; - radiusy = brush->RadiusY; - - if (!brush->SpreadMethod) - spread = XPS_PAD; - else if (!strcmp(brush->SpreadMethod, "Pad")) - spread = XPS_PAD; - else if (!strcmp(brush->SpreadMethod, "Reflect")) - spread = XPS_REFLECT; - else if (!strcmp(brush->SpreadMethod, "Repeat")) - spread = XPS_REPEAT; - else - spread = XPS_PAD; - - code = xps_draw_radial_gradient(gs_state_memory(pgs), pgs, - center, origin, radiusx, radiusy, - spread, stops, nstops); - if (code < 0) - return gs_rethrow(code, "could not draw radial gradient brush"); - - return gs_okay; -} - - -/* - * The action methods just create a pattern structure for later painting. - */ - -private int CommonGradientBrush_action(void *data, met_state_t *ms, int type) -{ - gs_memory_t *mem = ms->memory; - gs_state *pgs = ms->pgs; - gs_matrix mat; - gs_color_space cs; - gs_client_pattern gspat; - gs_client_color gscolor; - - met_pattern_t *metpat = - (met_pattern_t *)gs_alloc_bytes(ms->memory, - sizeof(met_pattern_t), "GradientBrush_action"); - metpat->visual = NULL; - metpat->linear = NULL; - metpat->radial = NULL; - metpat->raster_image = NULL; - metpat->Viewbox.p.x = 0; metpat->Viewbox.p.y = 0; - metpat->Viewbox.q.x = 0; metpat->Viewbox.q.y = 0; - metpat->Viewport.p.x = 0; metpat->Viewport.p.y = 0; - metpat->Viewport.q.x = 0; metpat->Viewport.q.y = 0; - metpat->Transform.xx = 1.0; metpat->Transform.xy = 0.0; - metpat->Transform.yx = 0.0; metpat->Transform.yy = 1.0; - metpat->Transform.tx = 0.0; metpat->Transform.ty = 0.0; - - if (type == 'L') - metpat->linear = data; - else - metpat->radial = data; - - gs_pattern1_init(&gspat); - - uid_set_UniqueID(&gspat.uid, gs_next_ids(mem, 1)); - gspat.PaintType = 1; - gspat.TilingType = 1; - - /* there is no Viewbox */ - gspat.BBox.p.x = -1000; - gspat.BBox.p.y = -1000; - gspat.BBox.q.x = 1000; - gspat.BBox.q.y = 1000; - - /* there is no tiling */ - gspat.XStep = 2000; - gspat.YStep = 2000; - - gspat.PaintProc = met_PaintPattern; - gspat.client_data = (void *)metpat; - - gs_gsave(pgs); - gs_make_identity(&mat); - gs_cspace_init_DeviceRGB(mem, &cs); - gs_setcolorspace(pgs, &cs); - gs_makepattern(&gscolor, &gspat, &mat, pgs, NULL); - gs_grestore(pgs); - - gs_setpattern(pgs, &gscolor); - { - met_path_child_t parent = met_currentpathchild(pgs); - if (parent == met_fill) - met_setpatternfill(pgs); - else if (parent == met_stroke) - met_setpatternstroke(pgs); - else - return gs_throw(-1, "pattern has no context"); - } - - dputs("xxx gradient action\n"); - - return gs_okay; -} - -private int LinearGradientBrush_action(void *data, met_state_t *ms) -{ - return CommonGradientBrush_action(data, ms, 'L'); -} - -private int RadialGradientBrush_action(void *data, met_state_t *ms) -{ - return CommonGradientBrush_action(data, ms, 'R'); -} - - -/* - * Descriptor structs with callbacks for the parser. - */ - -const met_element_t met_element_procs_LinearGradientBrush = { - "LinearGradientBrush", - { - LinearGradientBrush_cook, - LinearGradientBrush_action, - LinearGradientBrush_done - } -}; - -const met_element_t met_element_procs_RadialGradientBrush = { - "RadialGradientBrush", - { - RadialGradientBrush_cook, - RadialGradientBrush_action, - RadialGradientBrush_done - } -}; - diff --git a/met/xps_gradient_draw.c b/met/xps_gradient_draw.c deleted file mode 100644 index 0d8fac53f..000000000 --- a/met/xps_gradient_draw.c +++ /dev/null @@ -1,358 +0,0 @@ -#include "std.h" -#include "gsmemory.h" -#include "gsstate.h" -#include "gscoord.h" - -#include "gxpath.h" /* gsshade.h depends on it */ -#include "gxfixed.h" /* gsshade.h depends on it */ -#include "gsshade.h" -#include "gsfunc.h" -#include "gsfunc3.h" /* we use stitching and exponential interp */ - -#include "gserror.h" -#include "xps_gradient_draw.h" - -/* - * Create a Function object to map [0..1] to RGB colors - * based on the GradientStops array of (offset, red, green, blue) tuples. - */ - -private int -xps_make_function(gs_memory_t *mem, gs_function_t **funcp, - double *stops, int nstops) -{ - gs_function_1ItSg_params_t sparams; - gs_function_ElIn_params_t lparams; - gs_function_t *sfunc; - gs_function_t *lfunc; - - float *domain, *range, *c0, *c1, *bounds, *encode; - const gs_function_t **functions; - - int code; - int k; - int i; - - k = nstops - 1; /* number of intervals / functions */ - - domain = (void*) gs_alloc_bytes(mem, 2 * sizeof(float), "Domain"); - domain[0] = 0.0; - domain[1] = 1.0; - sparams.m = 1; - sparams.Domain = domain; - - range = (void*) gs_alloc_bytes(mem, 6 * sizeof(float), "Range"); - range[0] = 0.0; - range[1] = 1.0; - range[2] = 0.0; - range[3] = 1.0; - range[4] = 0.0; - range[5] = 1.0; - sparams.n = 3; - sparams.Range = range; - - sparams.k = k; - functions = (void*) gs_alloc_bytes(mem, k * sizeof(void*), "Functions"); - bounds = (void*) gs_alloc_bytes(mem, (k - 1) * sizeof(float), "Bounds"); - encode = (void*) gs_alloc_bytes(mem, (k * 2) * sizeof(float), "Encode"); - - sparams.Functions = functions; - sparams.Bounds = bounds; - sparams.Encode = encode; - - for (i = 0; i < k; i++) - { - domain = (void*) gs_alloc_bytes(mem, 2 * sizeof(float), "Domain"); - domain[0] = 0.0; - domain[1] = 1.0; - lparams.m = 1; - lparams.Domain = domain; - - range = (void*) gs_alloc_bytes(mem, 6 * sizeof(float), "Range"); - range[0] = 0.0; - range[1] = 1.0; - range[2] = 0.0; - range[3] = 1.0; - range[4] = 0.0; - range[5] = 1.0; - lparams.n = 3; - lparams.Range = range; - - c0 = (void*) gs_alloc_bytes(mem, 3 * sizeof(float), "C0"); - c0[0] = stops[(i + 0) * 4 + 1]; - c0[1] = stops[(i + 0) * 4 + 2]; - c0[2] = stops[(i + 0) * 4 + 3]; - lparams.C0 = c0; - - c1 = (void*) gs_alloc_bytes(mem, 3 * sizeof(float), "C1"); - c1[0] = stops[(i + 1) * 4 + 1]; - c1[1] = stops[(i + 1) * 4 + 2]; - c1[2] = stops[(i + 1) * 4 + 3]; - lparams.C1 = c1; - - lparams.N = 1; - - code = gs_function_ElIn_init(&lfunc, &lparams, mem); - if (code < 0) - return gs_throw(-1, "gs_function_ElIn_init failed"); - - functions[i] = lfunc; - - if (i > 0) - bounds[i - 1] = stops[(i + 0) * 4 + 0]; - - encode[i * 2 + 0] = 0.0; - encode[i * 2 + 1] = 1.0; - } - - code = gs_function_1ItSg_init(&sfunc, &sparams, mem); - if (code < 0) - return gs_throw(-1, "gs_function_1ItSg_init failed"); - - *funcp = sfunc; - - return gs_okay; -} - -/* - * Linear gradients map to Axial shadings. - */ - -private int -xps_draw_one_linear_gradient(gs_memory_t *mem, gs_state *pgs, - gs_function_t *func, int extend, - double *p0, double *p1) -{ - gs_imager_state *pis = (gs_imager_state*)pgs; - gx_device *dev = gs_currentdevice(pgs); - gs_shading_t *shading; - gs_shading_A_params_t params; - gs_color_space colorspace; - gs_fixed_rect rect; - int code; - - gs_shading_A_params_init(¶ms); - { - gs_cspace_init_DeviceRGB(mem, &colorspace); - - params.ColorSpace = &colorspace; - - params.Coords[0] = p0[0]; - params.Coords[1] = p0[1]; - params.Coords[2] = p1[0]; - params.Coords[3] = p1[1]; - - params.Extend[0] = extend; - params.Extend[1] = extend; - - params.Function = func; - } - - code = gs_shading_A_init(&shading, ¶ms, mem); - if (code < 0) - return gs_throw(-1, "gs_shading_A_init failed"); - - rect.p.x = int2fixed(-10000); - rect.p.y = int2fixed(-10000); - rect.q.x = int2fixed(10000); - rect.q.y = int2fixed(10000); - - code = gs_shading_fill_path_adjusted(shading, NULL, &rect, dev, pis, false); - if (code < 0) - { - gs_free_object(mem, shading, "gs_shading_A"); - return gs_throw(-1, "gs_shading_fill_path_adjusted failed"); - } - - gs_free_object(mem, shading, "gs_shading_A"); - - return gs_okay; -} - - -/* - * Radial gradients map more or less to Radial shadings. - * The inner circle is always a point. - * The outer circle is actually an ellipse, - * mess with the transform to squash the circle into the right aspect. - */ - -private int -xps_draw_one_radial_gradient(gs_memory_t *mem, gs_state *pgs, - gs_function_t *func, int extend, - double *pt0, double rad0, - double *pt1, double rad1) -{ - gs_imager_state *pis = (gs_imager_state*)pgs; - gx_device *dev = gs_currentdevice(pgs); - gs_shading_t *shading; - gs_shading_R_params_t params; - gs_color_space colorspace; - gs_fixed_rect rect; - int code; - - gs_shading_R_params_init(¶ms); - { - gs_cspace_init_DeviceRGB(mem, &colorspace); - - params.ColorSpace = &colorspace; - - params.Coords[0] = pt0[0]; - params.Coords[1] = pt0[1]; - params.Coords[2] = rad0; - params.Coords[3] = pt1[0]; - params.Coords[4] = pt1[1]; - params.Coords[5] = rad1; - - params.Extend[0] = extend; - params.Extend[1] = extend; - - params.Function = func; - } - - code = gs_shading_R_init(&shading, ¶ms, mem); - if (code < 0) - return gs_throw(-1, "gs_shading_R_init failed"); - - rect.p.x = int2fixed(-10000); - rect.p.y = int2fixed(-10000); - rect.q.x = int2fixed(10000); - rect.q.y = int2fixed(10000); - - code = gs_shading_fill_path_adjusted(shading, NULL, &rect, dev, pis, false); - if (code < 0) - { - gs_free_object(mem, shading, "gs_shading_R"); - return gs_throw(-1, "gs_shading_fill_path_adjusted failed"); - } - - gs_free_object(mem, shading, "gs_shading_R"); - - return gs_okay; -} - -/* - * We need to loop and create many shading objects to account - * for the Repeat and Reflect SpreadMethods. - */ - -int -xps_draw_linear_gradient(gs_memory_t *mem, gs_state *pgs, - double *pt0, double *pt1, - int spread, double *stops, int nstops) -{ - gs_function_t *func; - int code; - int i; - - float dx = pt1[0] - pt0[0]; - float dy = pt1[1] - pt0[1]; - - code = xps_make_function(mem, &func, stops, nstops); - if (code < 0) - return gs_rethrow(code, "could not make gradient function"); - - if (spread == XPS_PAD) - { - code = xps_draw_one_linear_gradient(mem, pgs, func, true, pt0, pt1); - if (code < 0) - { - gs_free_object(mem, func, "gs_function"); - return gs_rethrow(code, "could not draw axial gradient"); - } - } - else - { - pt0[0] -= 10 * dx; pt0[1] -= 10 * dy; - pt1[0] -= 10 * dx; pt1[1] -= 10 * dy; - - for (i = 0; i < 20; i++) - { - if (spread == XPS_REFLECT && (i & 1)) - code = xps_draw_one_linear_gradient(mem, pgs, func, false, pt1, pt0); - else - code = xps_draw_one_linear_gradient(mem, pgs, func, false, pt0, pt1); - if (code < 0) - { - gs_free_object(mem, func, "gs_function"); - return gs_rethrow(code, "could not draw axial gradient"); - } - - pt0[0] += dx; pt0[1] += dy; - pt1[0] += dx; pt1[1] += dy; - } - } - - gs_free_object(mem, func, "gs_function"); - return gs_okay; -} - -int -xps_draw_radial_gradient(gs_memory_t *mem, gs_state *pgs, - double *pt0, double *pt1, double xrad, double yrad, - int spread, double *stops, int nstops) -{ - gs_function_t *func; - float invscale; - float rad0, rad1; - float dx, dy; - int code; - int i; - - gs_gsave(pgs); - - /* scale the ctm to make ellipses */ - gs_scale(pgs, 1.0, yrad / xrad); - - invscale = xrad / yrad; - pt0[1] *= invscale; - pt1[1] *= invscale; - - code = xps_make_function(mem, &func, stops, nstops); - if (code < 0) - return gs_rethrow(code, "could not make gradient function"); - - rad0 = 0.0; - rad1 = xrad; - - dx = pt1[0] - pt0[0]; - dy = pt1[1] - pt0[1]; - - if (spread == XPS_PAD) - { - code = xps_draw_one_radial_gradient(mem, pgs, func, true, pt0, rad0, pt1, rad1); - if (code < 0) - { - gs_free_object(mem, func, "gs_function"); - gs_grestore(pgs); - return gs_rethrow(code, "could not draw axial gradient"); - } - } - else - { - for (i = 0; i < 10; i++) - { - if (spread == XPS_REFLECT && (i & 1)) - code = xps_draw_one_radial_gradient(mem, pgs, func, false, pt1, rad1, pt0, rad0); - else - code = xps_draw_one_radial_gradient(mem, pgs, func, false, pt0, rad0, pt1, rad1); - - if (code < 0) - { - gs_free_object(mem, func, "gs_function"); - gs_grestore(pgs); - return gs_rethrow(code, "could not draw axial gradient"); - } - - rad0 = rad1; - rad1 += xrad; - - pt0[0] += dx; pt0[1] += dy; - pt1[0] += dx; pt1[1] += dy; - } - } - - gs_free_object(mem, func, "gs_function"); - gs_grestore(pgs); - return gs_okay; -} diff --git a/met/xps_gradient_draw.h b/met/xps_gradient_draw.h deleted file mode 100644 index a1f2a8c9f..000000000 --- a/met/xps_gradient_draw.h +++ /dev/null @@ -1,13 +0,0 @@ - -enum { XPS_PAD, XPS_REPEAT, XPS_REFLECT }; - -int -xps_draw_linear_gradient(gs_memory_t *mem, gs_state *pgs, - double *pt0, double *pt1, - int spread, double *stops, int nstops); - -int -xps_draw_radial_gradient(gs_memory_t *mem, gs_state *pgs, - double *pt0, double *pt1, double xrad, double yrad, - int spread, double *stops, int nstops); - diff --git a/met/xps_gradient_stop.c b/met/xps_gradient_stop.c deleted file mode 100644 index 2eb55393a..000000000 --- a/met/xps_gradient_stop.c +++ /dev/null @@ -1,93 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id: */ - -/* gradient stops */ - -/* meh. */ -#include "memory_.h" -#include "gsmemory.h" -#include "gsmatrix.h" -#include "gp.h" -#include "metcomplex.h" -#include "metelement.h" -#include "metutil.h" -#include "metstate.h" -#include "metgstate.h" -#include "math_.h" -#include "ctype_.h" -#include "gsimage.h" -#include "metimage.h" -#include "gscspace.h" -#include "gscolor2.h" -#include "gsptype1.h" -#include <stdlib.h> /* nb for atof */ -#include "zipparse.h" -#include "xps_gradient_draw.h" -#include "gxstate.h" -#include "gsutil.h" - -private int -GradientStop_cook(void **ppdata, met_state_t *ms, - const char *el, const char **attr) -{ - CT_GradientStop *stop; - int i; - - stop = (CT_GradientStop *) gs_alloc_bytes(ms->memory, sizeof(CT_GradientStop), - "GradientStop_cook"); - if (!stop) - return gs_throw(-1, "out of memory: CT_GradientStop"); - - stop->Color = (char*)"#000000"; - stop->Offset = 0.0; - stop->next = NULL; - - for (i = 0; attr[i]; i += 2) - { - if (!strcmp(attr[i], "Color")) - stop->Color = met_strdup(ms->memory, attr[i+1], "Gradient color"); - if (!strcmp(attr[i], "Offset")) - stop->Offset = atof(attr[i+1]); - } - - dprintf2("GradientStop %s %g\n", stop->Color, stop->Offset); - - *ppdata = stop; - - met_appendgradientstop(ms, stop); - - return 0; -} - -private int -GradientStop_done(void *data, met_state_t *ms) -{ - return 0; -} - -private int -GradientStop_action(void *data, met_state_t *ms, int type) -{ - return 0; -} - -const met_element_t met_element_procs_GradientStop = { - "GradientStop", - { - GradientStop_cook, - GradientStop_action, - GradientStop_done - } -}; - diff --git a/met/xps_image_jpeg.c b/met/xps_image_jpeg.c deleted file mode 100644 index f05239828..000000000 --- a/met/xps_image_jpeg.c +++ /dev/null @@ -1,103 +0,0 @@ -#include "std.h" -#include "gsmemory.h" -#include "stream.h" -#include "strimpl.h" -#include "gsstate.h" -#include "jpeglib_.h" -#include "sdct.h" -#include "sjpeg.h" -#include "metimage.h" -#include "gserror.h" - -static int xps_report_error(stream_state * st, const char *str) -{ - (void) gs_throw1(-1, "%s", str); - return 0; -} - -int xps_decode_jpeg(gs_memory_t *mem, byte *rbuf, int rlen, xps_image_t *image) -{ - jpeg_decompress_data jddp; - stream_DCT_state state; - stream_cursor_read rp; - stream_cursor_write wp; - int code; - int wlen; - byte *wbuf; - - s_init_state((stream_state*)&state, &s_DCTD_template, mem); - state.report_error = xps_report_error; - - s_DCTD_template.set_defaults((stream_state*)&state); - - state.jpeg_memory = mem; - state.data.decompress = &jddp; - - jddp.template = s_DCTD_template; - jddp.memory = mem; - jddp.scanline_buffer = NULL; - - if ((code = gs_jpeg_create_decompress(&state)) < 0) - return gs_throw(-1, "cannot gs_jpeg_create_decompress"); - - s_DCTD_template.init((stream_state*)&state); - - rp.ptr = rbuf - 1; - rp.limit = rbuf + rlen - 1; - - /* read the header only by not having a write buffer */ - wp.ptr = 0; - wp.limit = 0; - - code = s_DCTD_template.process((stream_state*)&state, &rp, &wp, true); - if (code != 1) - return gs_throw(-1, "premature EOF or error in jpeg"); - - image->width = jddp.dinfo.output_width; - image->height = jddp.dinfo.output_height; - image->comps = jddp.dinfo.output_components; - image->bits = 8; - image->stride = image->width * image->comps; - - if (image->comps == 1) - image->colorspace = XPS_GRAY; - if (image->comps == 3) - image->colorspace = XPS_RGB; - if (image->comps == 4) - image->colorspace = XPS_CMYK; - - if (jddp.dinfo.density_unit == 1) - { - image->xres = jddp.dinfo.X_density; - image->yres = jddp.dinfo.Y_density; - } - else if (jddp.dinfo.density_unit == 2) - { - image->xres = jddp.dinfo.X_density * 2.54; - image->yres = jddp.dinfo.Y_density * 2.54; - } - else - { - image->xres = 96; - image->yres = 96; - } - - wlen = image->stride * image->height; - wbuf = gs_alloc_bytes(mem, wlen, "decodejpeg"); - if (!wbuf) - return gs_throw1(-1, "out of memory allocating samples: %d", wlen); - - image->samples = wbuf; - - wp.ptr = wbuf - 1; - wp.limit = wbuf + wlen - 1; - - code = s_DCTD_template.process((stream_state*)&state, &rp, &wp, true); - if (code != EOFC) - return gs_throw1(-1, "error in jpeg (code = %d)", code); - - gs_jpeg_destroy(&state); - - return gs_okay; -} - diff --git a/met/xps_image_png.c b/met/xps_image_png.c deleted file mode 100644 index 9b8334177..000000000 --- a/met/xps_image_png.c +++ /dev/null @@ -1,191 +0,0 @@ -#include "std.h" -#include "gsmemory.h" -#include "stream.h" -#include "strimpl.h" -#include "gsstate.h" -#include "png_.h" -#include "metimage.h" -#include "gserror.h" - -/* - * PNG using libpng directly (no gs wrappers) - */ - -struct xps_png_io_s -{ - byte *ptr; - byte *lim; -}; - -private void xps_png_read(png_structp png, png_bytep data, png_size_t length) -{ - struct xps_png_io_s *io = png_get_io_ptr(png); - if (io->ptr + length > io->lim) - png_error(png, "Read Error"); - memcpy(data, io->ptr, length); - io->ptr += length; -} - -private png_voidp xps_png_malloc(png_structp png, png_size_t size) -{ - gs_memory_t *mem = png_get_mem_ptr(png); - return gs_alloc_bytes(mem, size, "libpng"); -} - -private void xps_png_free(png_structp png, png_voidp ptr) -{ - gs_memory_t *mem = png_get_mem_ptr(png); - gs_free_object(mem, ptr, "libpng"); -} - -int xps_decode_png(gs_memory_t *mem, byte *rbuf, int rlen, xps_image_t *image) -{ - png_structp png; - png_infop info; - struct xps_png_io_s io; - int npasses; - int pass; - int y; - - /* - * Set up PNG structs and input source - */ - - io.ptr = rbuf; - io.lim = rbuf + rlen; - - png = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, - NULL, NULL, NULL, - mem, xps_png_malloc, xps_png_free); - if (!png) - return gs_throw(-1, "png_create_read_struct"); - - info = png_create_info_struct(png); - if (!info) - return gs_throw(-1, "png_create_info_struct"); - - png_set_read_fn(png, &io, xps_png_read); - - /* - * Jump to here on errors. - */ - - if (setjmp(png_jmpbuf(png))) - { - png_destroy_read_struct(&png, &info, NULL); - return gs_throw(-1, "png reading failed"); - } - - /* - * Read PNG header - */ - - png_read_info(png, info); - - image->width = png_get_image_width(png, info); - image->height = png_get_image_height(png, info); - image->bits = png_get_bit_depth(png, info); - - if (png_get_interlace_type(png, info) == PNG_INTERLACE_ADAM7) - { - npasses = png_set_interlace_handling(png); - } - else - { - npasses = 1; - } - - if (image->bits == 16) - { - png_set_strip_16(png); - image->bits = 8; - } - - switch (png_get_color_type(png, info)) - { - case PNG_COLOR_TYPE_GRAY: - image->comps = 1; - image->colorspace = XPS_GRAY; - break; - - case PNG_COLOR_TYPE_PALETTE: - /* ask libpng to expand palettes to rgb triplets */ - png_set_palette_to_rgb(png); - image->bits = 8; - - /* libpng will expand to rgba if there is a tRNS chunk */ - if (png_get_valid(png, info, PNG_INFO_tRNS)) - { - image->comps = 4; - image->colorspace = XPS_RGB_A; - } - else - { - image->comps = 3; - image->colorspace = XPS_RGB; - } - break; - - case PNG_COLOR_TYPE_RGB: - image->comps = 3; - image->colorspace = XPS_RGB; - break; - - case PNG_COLOR_TYPE_GRAY_ALPHA: - image->comps = 2; - image->colorspace = XPS_GRAY_A; - break; - - case PNG_COLOR_TYPE_RGB_ALPHA: - image->comps = 4; - image->colorspace = XPS_RGB_A; - break; - - default: - return gs_throw(-1, "cannot handle this png color type"); - } - - image->stride = (image->width * image->comps * image->bits + 7) / 8; - - /* - * Extract DPI, default to 96 dpi - */ - - image->xres = 96; - image->yres = 96; - - if (info->valid & PNG_INFO_pHYs) - { - png_uint_32 xres, yres; - int unit; - png_get_pHYs(png, info, &xres, &yres, &unit); - if (unit == PNG_RESOLUTION_METER) - { - image->xres = xres * 0.0254 + 0.5; - image->yres = yres * 0.0254 + 0.5; - } - } - - /* - * Read rows, filling transformed output into image buffer. - */ - - image->samples = gs_alloc_bytes(mem, image->stride * image->height, "decodepng"); - - for (pass = 0; pass < npasses; pass++) - { - for (y = 0; y < image->height; y++) - { - png_read_row(png, image->samples + (y * image->stride), NULL); - } - } - - /* - * Clean up memory. - */ - - png_destroy_read_struct(&png, &info, NULL); - - return gs_okay; -} - diff --git a/met/xps_image_tiff.c b/met/xps_image_tiff.c deleted file mode 100644 index 4dcdbc842..000000000 --- a/met/xps_image_tiff.c +++ /dev/null @@ -1,1024 +0,0 @@ -#include "std.h" -#include "gsmemory.h" -#include "stream.h" -#include "strimpl.h" -#include "gsstate.h" -#include "jpeglib_.h" -#include "sdct.h" -#include "sjpeg.h" -#include "srlx.h" -#include "slzwx.h" -#include "szlibx.h" -#include "scfx.h" -#include "memory_.h" -#include "metimage.h" -#include "gserror.h" - -/* - * TIFF image loader. Should be enough to support TIFF files in XPS. - * Baseline TIFF 6.0 plus CMYK, LZW, Flate and JPEG support. - * Limited bit depths (1,2,4,8). - * Limited planar configurations (1=chunky). - * No tiles (easy fix if necessary). - * TODO: RGBPal images - */ - -typedef struct xps_tiff_s xps_tiff_t; - -struct xps_tiff_s -{ - /* "file" */ - byte *bp, *rp, *ep; - - /* byte order */ - unsigned order; - - /* where we can find the strips of image data */ - unsigned rowsperstrip; - unsigned *stripoffsets; - unsigned *stripbytecounts; - - /* colormap */ - unsigned *colormap; - - /* assorted tags */ - unsigned subfiletype; - unsigned photometric; - unsigned compression; - unsigned imagewidth; - unsigned imagelength; - unsigned samplesperpixel; - unsigned bitspersample; - unsigned planar; - unsigned extrasamples; - unsigned xresolution; - unsigned yresolution; - unsigned resolutionunit; - unsigned fillorder; - unsigned g3opts; - unsigned g4opts; - unsigned predictor; - - unsigned ycbcrsubsamp[2]; - - byte *jpegtables; /* point into "file" buffer */ - unsigned jpegtableslen; -}; - -enum -{ - TII = 0x4949, /* 'II' */ - TMM = 0x4d4d, /* 'MM' */ - TBYTE = 1, - TASCII = 2, - TSHORT = 3, - TLONG = 4, - TRATIONAL = 5 -}; - -#define NewSubfileType 254 -#define ImageWidth 256 -#define ImageLength 257 -#define BitsPerSample 258 -#define Compression 259 -#define PhotometricInterpretation 262 -#define FillOrder 266 -#define StripOffsets 273 -#define SamplesPerPixel 277 -#define RowsPerStrip 278 -#define StripByteCounts 279 -#define XResolution 282 -#define YResolution 283 -#define PlanarConfiguration 284 -#define T4Options 292 -#define T6Options 293 -#define ResolutionUnit 296 -#define Predictor 317 -#define ColorMap 320 -#define TileWidth 322 -#define TileLength 323 -#define TileOffsets 324 -#define TileByteCounts 325 -#define ExtraSamples 338 -#define JPEGTables 347 -#define YCbCrSubSampling 520 - -static const byte bitrev[256] = -{ - 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, - 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, - 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, - 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, - 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, - 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, - 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, - 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, - 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, - 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, - 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, - 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, - 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, - 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, - 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, - 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, - 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, - 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, - 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, - 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, - 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, - 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, - 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, - 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, - 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, - 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, - 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, - 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, - 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, - 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, - 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, - 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff -}; - -private int -xps_report_error(stream_state * st, const char *str) -{ - (void) gs_throw1(-1, "%s", str); - return 0; -} - -private inline int -readbyte(xps_tiff_t *tiff) -{ - if (tiff->rp < tiff->ep) - return *tiff->rp++; - return EOF; -} - -private inline unsigned -readshort(xps_tiff_t *tiff) -{ - unsigned a = readbyte(tiff); - unsigned b = readbyte(tiff); - if (tiff->order == TII) - return (b << 8) | a; - return (a << 8) | b; -} - -private inline unsigned -readlong(xps_tiff_t *tiff) -{ - unsigned a = readbyte(tiff); - unsigned b = readbyte(tiff); - unsigned c = readbyte(tiff); - unsigned d = readbyte(tiff); - if (tiff->order == TII) - return (d << 24) | (c << 16) | (b << 8) | a; - return (a << 24) | (b << 16) | (c << 8) | d; -} - -private int -xps_decode_tiff_uncompressed(gs_memory_t *mem, xps_tiff_t *tiff, byte *rp, byte *rl, byte *wp, byte *wl) -{ - memcpy(wp, tiff->rp, wl - wp); - return gs_okay; -} - -private int -xps_decode_tiff_packbits(gs_memory_t *mem, xps_tiff_t *tiff, byte *rp, byte *rl, byte *wp, byte *wl) -{ - stream_RLD_state state; - stream_cursor_read scr; - stream_cursor_write scw; - int code; - - s_init_state((stream_state*)&state, &s_RLD_template, mem); - state.report_error = xps_report_error; - - s_RLD_template.set_defaults((stream_state*)&state); - s_RLD_template.init((stream_state*)&state); - - scr.ptr = rp - 1; - scr.limit = rl - 1; - scw.ptr = wp - 1; - scw.limit = wl - 1; - - code = s_RLD_template.process((stream_state*)&state, &scr, &scw, true); - if (code == ERRC) - return gs_throw1(-1, "error in packbits data (code = %d)", code); - - return gs_okay; -} - -private int -xps_decode_tiff_lzw(gs_memory_t *mem, xps_tiff_t *tiff, byte *rp, byte *rl, byte *wp, byte *wl) -{ - stream_LZW_state state; - stream_cursor_read scr; - stream_cursor_write scw; - int code; - - s_init_state((stream_state*)&state, &s_LZWD_template, mem); - state.report_error = xps_report_error; - - s_LZWD_template.set_defaults((stream_state*)&state); - - /* old-style TIFF 5.0 reversed bit order, late change */ - if (rp[0] == 0 && rp[1] & 0x01) - { - state.EarlyChange = 0; - state.FirstBitLowOrder = 1; - } - - /* new-style TIFF 6.0 normal bit order, early change */ - else - { - state.EarlyChange = 1; - state.FirstBitLowOrder = 0; - } - - s_LZWD_template.init((stream_state*)&state); - - scr.ptr = rp - 1; - scr.limit = rl - 1; - scw.ptr = wp - 1; - scw.limit = wl - 1; - - code = s_LZWD_template.process((stream_state*)&state, &scr, &scw, true); - if (code == ERRC) - { - s_LZWD_template.release((stream_state*)&state); - return gs_throw1(-1, "error in lzw data (code = %d)", code); - } - - s_LZWD_template.release((stream_state*)&state); - - return gs_okay; -} - -private int -xps_decode_tiff_flate(gs_memory_t *mem, xps_tiff_t *tiff, byte *rp, byte *rl, byte *wp, byte *wl) -{ - stream_zlib_state state; - stream_cursor_read scr; - stream_cursor_write scw; - int code; - - s_init_state((stream_state*)&state, &s_zlibD_template, mem); - state.report_error = xps_report_error; - - s_zlibD_template.set_defaults((stream_state*)&state); - - s_zlibD_template.init((stream_state*)&state); - - scr.ptr = rp - 1; - scr.limit = rl - 1; - scw.ptr = wp - 1; - scw.limit = wl - 1; - - code = s_zlibD_template.process((stream_state*)&state, &scr, &scw, true); - if (code == ERRC) - { - s_zlibD_template.release((stream_state*)&state); - return gs_throw1(-1, "error in flate data (code = %d)", code); - } - - s_zlibD_template.release((stream_state*)&state); - return gs_okay; -} - -private int -xps_decode_tiff_fax(gs_memory_t *mem, xps_tiff_t *tiff, int comp, byte *rp, byte *rl, byte *wp, byte *wl) -{ - stream_CFD_state state; - stream_cursor_read scr; - stream_cursor_write scw; - int code; - - s_init_state((stream_state*)&state, &s_CFD_template, mem); - state.report_error = xps_report_error; - - s_CFD_template.set_defaults((stream_state*)&state); - - state.EndOfLine = false; - state.EndOfBlock = false; - state.Columns = tiff->imagewidth; - state.Rows = tiff->imagelength; - state.BlackIs1 = tiff->photometric == 0; - - state.K = 0; - if (comp == 4) - state.K = -1; - if (comp == 2) - state.EncodedByteAlign = true; - - s_CFD_template.init((stream_state*)&state); - - scr.ptr = rp - 1; - scr.limit = rl - 1; - scw.ptr = wp - 1; - scw.limit = wl - 1; - - code = s_CFD_template.process((stream_state*)&state, &scr, &scw, true); - if (code == ERRC) - { - s_CFD_template.release((stream_state*)&state); - return gs_throw1(-1, "error in fax data (code = %d)", code); - } - - s_CFD_template.release((stream_state*)&state); - return gs_okay; -} - -/* - * We need more find control over JPEG decoding parameters than - * the s_DCTD_template filter will give us. So we abuse the - * filter, and take control after the filter setup (which sets up - * the memory manager and error handling) and call the gs_jpeg - * wrappers directly for doing the actual decoding. - */ - -private int -xps_decode_tiff_jpeg(gs_memory_t *mem, xps_tiff_t *tiff, byte *rp, byte *rl, byte *wp, byte *wl) -{ - stream_DCT_state state; /* used by gs_jpeg_* wrappers */ - jpeg_decompress_data jddp; - struct jpeg_source_mgr *srcmgr; - JSAMPROW scanlines[1]; - int stride; - int code; - - /* - * Set up the JPEG and DCT filter voodoo. - */ - - s_init_state((stream_state*)&state, &s_DCTD_template, mem); - state.report_error = xps_report_error; - s_DCTD_template.set_defaults((stream_state*)&state); - - state.jpeg_memory = mem; - state.data.decompress = &jddp; - - jddp.template = s_DCTD_template; - jddp.memory = mem; - jddp.scanline_buffer = NULL; - - if ((code = gs_jpeg_create_decompress(&state)) < 0) - return gs_throw(-1, "error in gs_jpeg_create_decompress"); - - s_DCTD_template.init((stream_state*)&state); - - srcmgr = jddp.dinfo.src; - - /* - * Read the abbreviated table file. - */ - - if (tiff->jpegtables) - { - srcmgr->next_input_byte = tiff->jpegtables; - srcmgr->bytes_in_buffer = tiff->jpegtableslen; - - code = gs_jpeg_read_header(&state, FALSE); - if (code != JPEG_HEADER_TABLES_ONLY) - return gs_throw(-1, "error in jpeg table data"); - } - - /* - * Read the image jpeg header. - */ - - srcmgr->next_input_byte = rp; - srcmgr->bytes_in_buffer = rl - rp; - - if ((code = gs_jpeg_read_header(&state, TRUE)) < 0) - return gs_throw(-1, "error in jpeg_read_header"); - - /* when TIFF says RGB and libjpeg says YCbCr, libjpeg is wrong */ - if (tiff->photometric == 2 && jddp.dinfo.jpeg_color_space == JCS_YCbCr) - { - jddp.dinfo.jpeg_color_space = JCS_RGB; - } - - /* - * Decode the strip image data. - */ - - if ((code = gs_jpeg_start_decompress(&state)) < 0) - return gs_throw(-1, "error in jpeg_start_decompress"); - - stride = jddp.dinfo.output_width * jddp.dinfo.output_components; - - while (wp + stride <= wl && jddp.dinfo.output_scanline < jddp.dinfo.output_height) - { - scanlines[0] = wp; - code = gs_jpeg_read_scanlines(&state, scanlines, 1); - if (code < 0) - return gs_throw(01, "error in jpeg_read_scanlines"); - wp += stride; - } - - /* - * Clean up. - */ - - if ((code = gs_jpeg_finish_decompress(&state)) < 0) - return gs_throw(-1, "error in jpeg_finish_decompress"); - - gs_jpeg_destroy(&state); - - return gs_okay; -} - -private inline int -getcomp(byte *line, int x, int bpc) -{ - switch (bpc) - { - case 1: return line[x / 8] >> (7 - (x % 8)) & 0x01; - case 2: return line[x / 4] >> ((3 - (x % 4)) * 2) & 0x03; - case 4: return line[x / 2] >> ((1 - (x % 2)) * 4) & 0x0f; - case 8: return line[x]; - } - return 0; -} - -private inline void -putcomp(byte *line, int x, int bpc, int value) -{ - int maxval = (1 << bpc) - 1; - - // clear bits first - switch (bpc) - { - case 1: line[x / 8] &= ~(maxval << (7 - (x % 8))); break; - case 2: line[x / 4] &= ~(maxval << ((3 - (x % 4)) * 2)); break; - case 4: line[x / 2] &= ~(maxval << ((1 - (x % 2)) * 4)); break; - } - - switch (bpc) - { - case 1: line[x / 8] |= value << (7 - (x % 8)); break; - case 2: line[x / 4] |= value << ((3 - (x % 4)) * 2); break; - case 4: line[x / 2] |= value << ((1 - (x % 2)) * 4); break; - case 8: line[x] = value; break; - } -} - -private void -xps_unpredict_tiff(byte *line, int width, int comps, int bits) -{ - byte left[32]; - int i, k, v; - - for (k = 0; k < comps; k++) - left[k] = 0; - - for (i = 0; i < width; i++) - { - for (k = 0; k < comps; k++) - { - v = getcomp(line, i * comps + k, bits); - v = v + left[k]; - v = v % (1 << bits); - putcomp(line, i * comps + k, bits, v); - left[k] = v; - } - } -} - -private void -xps_invert_tiff(byte *line, int width, int comps, int bits) -{ - int i, k, v; - int m = (1 << bits) - 1; - - for (i = 0; i < width; i++) - { - for (k = 0; k < comps; k++) - { - v = getcomp(line, i * comps + k, bits); - v = m - v; - putcomp(line, i * comps + k, bits, v); - } - } -} - -private int -xps_expand_colormap(gs_memory_t *mem, xps_tiff_t *tiff, xps_image_t *image) -{ - int maxval = 1 << image->bits; - byte *samples; - byte *src, *dst; - int stride; - int x, y; - - /* colormap has first all red, then all green, then all blue values */ - /* colormap values are 0..65535, bits is 4 or 8 */ - /* image can be with or without extrasamples: comps is 1 or 2 */ - - if (image->comps != 1 && image->comps != 2) - return gs_throw(-1, "invalid number of samples for RGBPal"); - - if (image->bits != 4 && image->bits != 8) - return gs_throw(-1, "invalid number of bits for RGBPal"); - - stride = image->width * (image->comps + 2); - - samples = gs_alloc_bytes(mem, stride * image->height, "samples"); - if (!samples) - return gs_throw(-1, "out of memory: samples"); - - for (y = 0; y < image->height; y++) - { - src = image->samples + (image->stride * y); - dst = samples + (stride * y); - - for (x = 0; x < image->width; x++) - { - if (tiff->extrasamples) - { - int c = getcomp(src, x * 2, image->bits); - int a = getcomp(src, x * 2 + 1, image->bits); - *dst++ = tiff->colormap[c + 0] >> 8; - *dst++ = tiff->colormap[c + maxval] >> 8; - *dst++ = tiff->colormap[c + maxval * 2] >> 8; - *dst++ = a << (8 - image->bits); - } - else - { - int c = getcomp(src, x, image->bits); - *dst++ = tiff->colormap[c + 0] >> 8; - *dst++ = tiff->colormap[c + maxval] >> 8; - *dst++ = tiff->colormap[c + maxval * 2] >> 8; - } - } - } - - gs_free_object(mem, image->samples, "samples"); - - image->bits = 8; - image->stride = stride; - image->samples = samples; - - return gs_okay; -} - -private int -xps_decode_tiff_strips(gs_memory_t *mem, xps_tiff_t *tiff, xps_image_t *image) -{ - int error; - - /* switch on compression to create a filter */ - /* feed each strip to the filter */ - /* read out the data and pack the samples into an xps_image */ - - /* type 32773 / packbits -- nothing special (same row-padding as PDF) */ - /* type 2 / ccitt rle -- no EOL, no RTC, rows are byte-aligned */ - /* type 3 and 4 / g3 and g4 -- each strip starts new section */ - /* type 5 / lzw -- each strip is handled separately */ - - byte *wp; - unsigned row; - unsigned strip; - unsigned i; - - if (!tiff->rowsperstrip || !tiff->stripoffsets || !tiff->rowsperstrip) - return gs_throw(-1, "no image data in tiff; maybe it is tiled"); - - if (tiff->planar != 1) - return gs_throw(-1, "image data is not in chunky format"); - - image->width = tiff->imagewidth; - image->height = tiff->imagelength; - image->comps = tiff->samplesperpixel; - image->bits = tiff->bitspersample; - image->stride = (image->width * image->comps * image->bits + 7) / 8; - - switch (tiff->photometric) - { - case 0: /* WhiteIsZero -- inverted */ - image->colorspace = XPS_GRAY; - break; - case 1: /* BlackIsZero */ - image->colorspace = XPS_GRAY; - break; - case 2: /* RGB */ - image->colorspace = XPS_RGB; - break; - case 3: /* RGBPal */ - image->colorspace = XPS_RGB; - break; - case 5: /* CMYK */ - image->colorspace = XPS_CMYK; - break; - case 6: /* YCbCr */ - /* it's probably a jpeg ... we let jpeg convert to rgb */ - image->colorspace = XPS_RGB; - break; - default: - return gs_throw1(-1, "unknown photometric: %d", tiff->photometric); - } - - switch (tiff->resolutionunit) - { - case 2: - image->xres = tiff->xresolution; - image->yres = tiff->yresolution; - case 3: - image->xres = tiff->xresolution * 2.54 + 0.5; - image->yres = tiff->yresolution * 2.54 + 0.5; - default: - image->xres = 96; - image->yres = 96; - } - - image->samples = gs_alloc_bytes(mem, image->stride * image->height, "samples"); - if (!image->samples) - return gs_throw(-1, "could not allocate image samples"); - - memset(image->samples, 0x55, image->stride * image->height); - - wp = image->samples; - - strip = 0; - for (row = 0; row < tiff->imagelength; row += tiff->rowsperstrip) - { - unsigned offset = tiff->stripoffsets[strip]; - unsigned rlen = tiff->stripbytecounts[strip]; - unsigned wlen = image->stride * tiff->rowsperstrip; - byte *rp = tiff->bp + offset; - - if (wp + wlen > image->samples + image->stride * image->height) - wlen = image->samples + image->stride * image->height - wp; - - if (rp + rlen > tiff->ep) - return gs_throw(-1, "strip extends beyond the end of the file"); - - /* the bits are in un-natural order */ - if (tiff->fillorder == 2) - for (i = 0; i < rlen; i++) - rp[i] = bitrev[rp[i]]; - - switch (tiff->compression) - { - case 1: - error = xps_decode_tiff_uncompressed(mem, tiff, rp, rp + rlen, wp, wp + wlen); - break; - case 2: - error = xps_decode_tiff_fax(mem, tiff, 2, rp, rp + rlen, wp, wp + wlen); - break; - case 3: - error = xps_decode_tiff_fax(mem, tiff, 3, rp, rp + rlen, wp, wp + wlen); - break; - case 4: - error = xps_decode_tiff_fax(mem, tiff, 4, rp, rp + rlen, wp, wp + wlen); - break; - case 5: - error = xps_decode_tiff_lzw(mem, tiff, rp, rp + rlen, wp, wp + wlen); - break; - case 6: - error = gs_throw(-1, "deprecated JPEG in TIFF compression not supported"); - break; - case 7: - error = xps_decode_tiff_jpeg(mem, tiff, rp, rp + rlen, wp, wp + wlen); - break; - case 8: - error = xps_decode_tiff_flate(mem, tiff, rp, rp + rlen, wp, wp + wlen); - break; - case 32773: - error = xps_decode_tiff_packbits(mem, tiff, rp, rp + rlen, wp, wp + wlen); - break; - default: - error = gs_throw1(-1, "unknown TIFF compression: %d", tiff->compression); - } - - if (error) - return gs_rethrow1(error, "could not decode strip %d", row / tiff->rowsperstrip); - - /* scramble the bits back into original order */ - if (tiff->fillorder == 2) - for (i = 0; i < rlen; i++) - rp[i] = bitrev[rp[i]]; - - wp += image->stride * tiff->rowsperstrip; - strip ++; - } - - /* Predictor (only for LZW and Flate) */ - if ((tiff->compression == 5 || tiff->compression == 8) && tiff->predictor == 2) - { - byte *p = image->samples; - for (i = 0; i < image->height; i++) - { - xps_unpredict_tiff(p, image->width, tiff->samplesperpixel, image->bits); - p += image->stride; - } - } - - /* RGBPal */ - if (tiff->photometric == 3 && tiff->colormap) - { - error = xps_expand_colormap(mem, tiff, image); - if (error) - return gs_rethrow(error, "could not expand colormap"); - } - - /* WhiteIsZero .. invert */ - if (tiff->photometric == 0) - { - byte *p = image->samples; - for (i = 0; i < image->height; i++) - { - xps_invert_tiff(p, image->width, image->comps, image->bits); - p += image->stride; - } - } - - /* Premultiplied transparency */ - if (tiff->extrasamples == 1) - { - image->colorspace ++; - } - - /* Non-pre-multiplied transparency */ - if (tiff->extrasamples == 2) - { - image->colorspace ++; - } - - return gs_okay; -} - -private void -xps_read_tiff_tag_value(unsigned *p, xps_tiff_t *tiff, unsigned type, unsigned ofs, unsigned n) -{ - tiff->rp = tiff->bp + ofs; - if (tiff->rp > tiff->ep) - tiff->rp = tiff->bp; - - while (n--) - { - switch (type) - { - case TRATIONAL: - *p = readlong(tiff); - *p = *p / readlong(tiff); - p ++; - break; - case TBYTE: *p++ = readbyte(tiff); break; - case TSHORT: *p++ = readshort(tiff); break; - case TLONG: *p++ = readlong(tiff); break; - default: *p++ = 0; break; - } - } -} - -private int -xps_read_tiff_tag(gs_memory_t *mem, xps_tiff_t *tiff, unsigned offset) -{ - unsigned tag; - unsigned type; - unsigned count; - unsigned value; - - tiff->rp = tiff->bp + offset; - - tag = readshort(tiff); - type = readshort(tiff); - count = readlong(tiff); - - if ((type == TBYTE && count <= 4) || - (type == TSHORT && count <= 2) || - (type == TLONG && count <= 1)) - value = tiff->rp - tiff->bp; - else - value = readlong(tiff); - - switch (tag) - { - case NewSubfileType: - xps_read_tiff_tag_value(&tiff->subfiletype, tiff, type, value, 1); - break; - case ImageWidth: - xps_read_tiff_tag_value(&tiff->imagewidth, tiff, type, value, 1); - break; - case ImageLength: - xps_read_tiff_tag_value(&tiff->imagelength, tiff, type, value, 1); - break; - case BitsPerSample: - xps_read_tiff_tag_value(&tiff->bitspersample, tiff, type, value, 1); - break; - case Compression: - xps_read_tiff_tag_value(&tiff->compression, tiff, type, value, 1); - break; - case PhotometricInterpretation: - xps_read_tiff_tag_value(&tiff->photometric, tiff, type, value, 1); - break; - case FillOrder: - xps_read_tiff_tag_value(&tiff->fillorder, tiff, type, value, 1); - break; - case SamplesPerPixel: - xps_read_tiff_tag_value(&tiff->samplesperpixel, tiff, type, value, 1); - break; - case RowsPerStrip: - xps_read_tiff_tag_value(&tiff->rowsperstrip, tiff, type, value, 1); - break; - case XResolution: - xps_read_tiff_tag_value(&tiff->xresolution, tiff, type, value, 1); - break; - case YResolution: - xps_read_tiff_tag_value(&tiff->yresolution, tiff, type, value, 1); - break; - case PlanarConfiguration: - xps_read_tiff_tag_value(&tiff->planar, tiff, type, value, 1); - break; - case T4Options: - xps_read_tiff_tag_value(&tiff->g3opts, tiff, type, value, 1); - break; - case T6Options: - xps_read_tiff_tag_value(&tiff->g4opts, tiff, type, value, 1); - break; - case Predictor: - xps_read_tiff_tag_value(&tiff->predictor, tiff, type, value, 1); - break; - case ResolutionUnit: - xps_read_tiff_tag_value(&tiff->resolutionunit, tiff, type, value, 1); - break; - case YCbCrSubSampling: - xps_read_tiff_tag_value(tiff->ycbcrsubsamp, tiff, type, value, 2); - break; - case ExtraSamples: - xps_read_tiff_tag_value(&tiff->extrasamples, tiff, type, value, 1); - break; - - case JPEGTables: - tiff->jpegtables = tiff->bp + value; - tiff->jpegtableslen = count; - break; - - case StripOffsets: - tiff->stripoffsets = (unsigned*) gs_alloc_bytes(mem, count * sizeof(unsigned), "StripOffsets"); - if (!tiff->stripoffsets) - return gs_throw(-1, "could not allocate strip offsets"); - xps_read_tiff_tag_value(tiff->stripoffsets, tiff, type, value, count); - break; - - case StripByteCounts: - tiff->stripbytecounts = (unsigned*) gs_alloc_bytes(mem, count * sizeof(unsigned), "StripByteCounts"); - if (!tiff->stripbytecounts) - return gs_throw(-1, "could not allocate strip byte counts"); - xps_read_tiff_tag_value(tiff->stripbytecounts, tiff, type, value, count); - break; - - case ColorMap: - tiff->colormap = (unsigned*) gs_alloc_bytes(mem, count * sizeof(unsigned), "ColorMap"); - if (!tiff->colormap) - return gs_throw(-1, "could not allocate color map"); - xps_read_tiff_tag_value(tiff->colormap, tiff, type, value, count); - break; - - case TileWidth: - case TileLength: - case TileOffsets: - case TileByteCounts: - return gs_throw(-1, "tiled tiffs not supported"); - - default: - /* - printf("unknown tag: %d t=%d n=%d\n", tag, type, count); - */ - break; - } - - return gs_okay; -} - -int -xps_decode_tiff(gs_memory_t *mem, byte *buf, int len, xps_image_t *image) -{ - int error; - xps_tiff_t tiffst; - xps_tiff_t *tiff = &tiffst; - - unsigned version; - unsigned offset; - unsigned count; - unsigned i; - - memset(tiff, 0, sizeof(xps_tiff_t)); - - tiff->bp = buf; - tiff->rp = buf; - tiff->ep = buf + len; - - /* tag defaults, where applicable */ - tiff->bitspersample = 1; - tiff->compression = 1; - tiff->samplesperpixel = 1; - tiff->resolutionunit = 2; - tiff->rowsperstrip = 0xFFFFFFFF; - tiff->fillorder = 1; - tiff->planar = 1; - tiff->subfiletype = 0; - tiff->predictor = 1; - tiff->ycbcrsubsamp[0] = 2; - tiff->ycbcrsubsamp[1] = 2; - - /* - * Read IFH - */ - - /* get byte order marker */ - tiff->order = TII; - tiff->order = readshort(tiff); - if (tiff->order != TII && tiff->order != TMM) - gs_throw(-1, "not a TIFF file, wrong magic marker"); - - /* check version */ - version = readshort(tiff); - if (version != 42) - gs_throw(-1, "not a TIFF file, wrong version marker"); - - /* get offset of IFD */ - offset = readlong(tiff); - - /* - * Read IFD - */ - - tiff->rp = tiff->bp + offset; - - count = readshort(tiff); - - offset += 2; - for (i = 0; i < count; i++) - { - error = xps_read_tiff_tag(mem, tiff, offset); - if (error) - return gs_rethrow(error, "could not read TIFF header tag"); - offset += 12; - } - - // xps_debug_tiff(mem, tiff); - - /* - * Decode the image strips - */ - - if (tiff->rowsperstrip > tiff->imagelength) - tiff->rowsperstrip = tiff->imagelength; - - error = xps_decode_tiff_strips(mem, tiff, image); - if (error) - return gs_rethrow(error, "could not decode image data"); - - /* - * Clean up scratch memory - */ - - if (tiff->colormap) gs_free_object(mem, tiff->colormap, "ColorMap"); - if (tiff->stripoffsets) gs_free_object(mem, tiff->stripoffsets, "StripOffsets"); - if (tiff->stripbytecounts) gs_free_object(mem, tiff->stripbytecounts, "StripByteCounts"); - - return gs_okay; -} - -private void -xps_debug_tiff(gs_memory_t *mem, xps_tiff_t *tiff) -{ - int n; - - dputs("TIFF <<\n"); - dprintf1("\t/NewSubfileType %u\n", tiff->subfiletype); - dprintf1("\t/PhotometricInterpretation %u\n", tiff->photometric); - dprintf1("\t/Compression %u\n", tiff->compression); - dprintf1("\t/ImageWidth %u\n", tiff->imagewidth); - dprintf1("\t/ImageLength %u\n", tiff->imagelength); - dprintf1("\t/BitsPerSample %u\n", tiff->bitspersample); - dprintf1("\t/SamplesPerPixel %u\n", tiff->samplesperpixel); - dprintf1("\t/PlanarConfiguration %u\n", tiff->planar); - dprintf1("\t/ExtraSamples %u\n", tiff->extrasamples); - dprintf1("\t/ColorMap $%p\n", tiff->colormap); - dprintf1("\t/XResolution %u\n", tiff->xresolution); - dprintf1("\t/YResolution %u\n", tiff->yresolution); - dprintf1("\t/ResolutionUnit %u\n", tiff->resolutionunit); - dprintf1("\t/FillOrder %u\n", tiff->fillorder); - dprintf1("\t/T4Options %u\n", tiff->g3opts); - dprintf1("\t/T6Options %u\n", tiff->g4opts); - dprintf1("\t/Predictor %u\n", tiff->predictor); - dprintf1("\t/JPEGTables %u\n", tiff->jpegtableslen); - dprintf2("\t/YCbCrSubSampling %u %u\n", tiff->ycbcrsubsamp[0], tiff->ycbcrsubsamp[1]); - - n = (tiff->imagelength + tiff->rowsperstrip - 1) / tiff->rowsperstrip; - - dprintf1("\t/RowsPerStrip %u\n", tiff->rowsperstrip); - - if (tiff->stripoffsets) - dprintf1("\t/StripOffsets %u\n", n); - - if (tiff->stripbytecounts) - dprintf1("\t/StripByteCounts %u\n", n); - - dputs(">>\n"); -} - diff --git a/met/xps_visual_brush.c b/met/xps_visual_brush.c deleted file mode 100644 index 8b7c1a02c..000000000 --- a/met/xps_visual_brush.c +++ /dev/null @@ -1,257 +0,0 @@ -/* Portions Copyright (C) 2001 artofcode LLC. - Portions Copyright (C) 1996, 2001, 2005 Artifex Software Inc. - Portions Copyright (C) 1988, 2000 Aladdin Enterprises. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/*$Id: */ - -/* visual brush */ - -#include "metcomplex.h" -#include "metelement.h" -#include "metimage.h" -#include "metgstate.h" -#include "metrecorder.h" -#include "metutil.h" -#include "gserror.h" -#include "gsmatrix.h" -#include "gscspace.h" -#include "gsptype1.h" -#include "gsutil.h" -#include "gscolor2.h" -#include "ctype_.h" -#include "string_.h" -#include "std.h" -#include <stdlib.h> /* nb for atof */ - -int -VisualBrush_paint(void *data, gs_state *pgs) -{ - int code; - met_state_t *ms = data; - gs_state *saved_pgs = ms->pgs; - ms->pgs = pgs; - code = met_playback(data); - ms->pgs = saved_pgs; - return code; -} - -/* element constructor */ -private int -VisualBrush_cook(void **ppdata, met_state_t *ms, const char *el, const char **attr) -{ - CT_VisualBrush *aVisualBrush = - (CT_VisualBrush *)gs_alloc_bytes(ms->memory, - sizeof(CT_VisualBrush), - "VisualBrush_cook"); - int i; - - memset(aVisualBrush, 0, sizeof(CT_VisualBrush)); - - /* parse attributes, filling in the zeroed out C struct */ -#define MYSET(field, value) \ - met_cmp_and_set((field), attr[i], attr[i+1], (value)) - - /* parse attributes, filling in the zeroed out C struct */ - for(i = 0; attr[i]; i += 2) { - if (!MYSET(&aVisualBrush->Key, "Key")) - ; - else if (!MYSET(&aVisualBrush->Transform, "Transform")) - ; - else if (!MYSET(&aVisualBrush->Viewbox, "Viewbox")) - ; - else if (!MYSET(&aVisualBrush->Viewport, "Viewport")) - ; - else if (!MYSET(&aVisualBrush->Fill, "Fill")) - ; - else if (!MYSET(&aVisualBrush->TileMode, "TileMode")) - ; - else if (!MYSET(&aVisualBrush->ViewboxUnits, "ViewboxUnits")) - ; - else if (!MYSET(&aVisualBrush->ViewportUnits, "ViewportUnits")) - ; - else { - gs_warn2("unsupported attribute %s=%s", - attr[i], attr[i+1]); - } - } - - /* copy back the data for the parser. */ - *ppdata = aVisualBrush; - /* record me */ - return 1; -} - -private bool is_Data_delimeter(char b) -{ - return (b == ',') || (isspace(b)); -} - -/* action associated with this element */ -private int -VisualBrush_action(void *data, met_state_t *ms) -{ - return 0; -} - -extern int met_PaintPattern(const gs_client_color *pcc, gs_state *pgs); - -private int -VisualBrush_done(void *data, met_state_t *ms) -{ - - CT_VisualBrush *aVisualBrush = data; - gs_memory_t *mem = ms->memory; - gs_client_pattern gspat; - gs_client_color gscolor; - - met_pattern_t *pat = - (met_pattern_t *)gs_alloc_bytes(ms->memory, - sizeof(met_pattern_t), "GradientBrush_action"); - memset(pat, 0, sizeof(*pat)); - - gs_pattern1_init(&gspat); - uid_set_UniqueID(&gspat.uid, gs_next_ids(mem, 1)); - gspat.PaintType = 1; - gspat.TilingType = 1; - - /* nb gcc'isms ahead */ - if (aVisualBrush->Transform) { - char transstring[strlen(aVisualBrush->Transform)]; - strcpy(transstring, aVisualBrush->Transform); - /* nb wasteful */ - char *args[strlen(aVisualBrush->Transform)]; - char **pargs = args; - met_split(transstring, args, is_Data_delimeter); - /* nb checking */ - pat->Transform.xx = atof(pargs[0]); - pat->Transform.xy = atof(pargs[1]); - pat->Transform.yx = atof(pargs[2]); - pat->Transform.yy = atof(pargs[3]); - pat->Transform.tx = atof(pargs[4]); - pat->Transform.ty = atof(pargs[5]); - } - - if (aVisualBrush->Viewbox) { - char viewbox[strlen(aVisualBrush->Viewbox)]; - strcpy(viewbox, aVisualBrush->Viewbox); - /* nb wasteful */ - char *args[strlen(aVisualBrush->Viewbox)]; - char **pargs = args; - met_split(viewbox, args, is_Data_delimeter); - pat->Viewbox.p.x = atof(pargs[0]); - pat->Viewbox.p.y = atof(pargs[1]); - pat->Viewbox.q.x = pat->Viewbox.p.x + atof(pargs[2]); - pat->Viewbox.q.y = pat->Viewbox.p.y + atof(pargs[3]); - /* the spec says if the viewbox extant is zero in both - directions take a point sample. We are not exactly sure - what this means. Here is one interpretation. */ - if ((pat->Viewbox.p.x == pat->Viewbox.q.x) && - (pat->Viewbox.p.y == pat->Viewbox.q.y)) { - pat->Viewbox.q.x = pat->Viewbox.p.x + 1.0; - pat->Viewbox.q.y = pat->Viewbox.q.y + 1.0; - } - - } - if (aVisualBrush->Viewport) { - /* do ever feel like your doing the same thing over and over - again... */ - char viewport[strlen(aVisualBrush->Viewport)]; - strcpy(viewport, aVisualBrush->Viewport); - /* nb wasteful */ - char *args[strlen(aVisualBrush->Viewbox)]; - char **pargs = args; - met_split(viewport, args, is_Data_delimeter); - pat->Viewport.p.x = atof(pargs[0]); - pat->Viewport.p.y = atof(pargs[1]); - pat->Viewport.q.x = pat->Viewport.p.x + atof(pargs[2]); - pat->Viewport.q.y = pat->Viewport.p.y + atof(pargs[3]); - } - - if (aVisualBrush->Transform) { - char transform[strlen(aVisualBrush->Transform)]; - char *args[strlen(aVisualBrush->Transform)]; - strcpy(transform, aVisualBrush->Transform); - char **pargs = args; - met_split(transform, args, is_Data_delimeter); - pat->Transform.xx = atof(pargs[0]); - pat->Transform.xy = atof(pargs[1]); - pat->Transform.yx = atof(pargs[2]); - pat->Transform.yy = atof(pargs[3]); - pat->Transform.tx = atof(pargs[4]); - pat->Transform.ty = atof(pargs[5]); - } - - /* NB: Viewbox(0,0,0,0) appears to be legal, adjust to sane value */ - pat->Viewbox.q.x = max( pat->Viewbox.q.x, 1 ); - pat->Viewbox.q.y = max( pat->Viewbox.q.y, 1 ); - - gspat.BBox.p.x = 0; - gspat.BBox.p.y = 0; - gspat.BBox.q.x = pat->Viewbox.q.x - pat->Viewbox.p.x; - gspat.BBox.q.y = pat->Viewbox.q.y - pat->Viewbox.p.y; - - gspat.XStep = pat->Viewbox.q.x - pat->Viewbox.p.x; - gspat.YStep = pat->Viewbox.q.y - pat->Viewbox.p.y; - gspat.PaintProc = met_PaintPattern; - gspat.client_data = (void *)pat; - { - gs_matrix mat; - gs_color_space cs; - gs_state *pgs = ms->pgs; - gs_rect vbox = pat->Viewbox; - gs_rect vport = pat->Viewport; - gs_gsave(pgs); - /* resolution scaling is done when the pattern is painted */ - /* translate the viewbox to the origin, scale the viewbox to - the viewport and translate the viewbox back. */ - gs_make_translation(vport.p.x, vport.p.y, &mat); - { - /* NB: don't scale smaller than a pixel */ - double scalex = (vport.q.x - vport.p.x) / (vbox.q.x - vbox.p.x); - double scaley = (vport.q.y - vport.p.y) / (vbox.q.y - vbox.p.y); - gs_matrix_scale(&mat, scalex, scaley, &mat); - } - gs_matrix_translate(&mat, -vbox.p.x, vbox.p.y, &mat); - - /* nb defaults to RGB */ - gs_cspace_init_DeviceRGB(mem, &cs); - gs_setcolorspace(pgs, &cs); - gs_makepattern(&gscolor, &gspat, &mat, pgs, NULL); - gs_grestore(pgs); - gs_setpattern(pgs, &gscolor); - { - met_path_child_t parent = met_currentpathchild(pgs); - if (parent == met_fill) - met_setpatternfill(pgs); - else if (parent == met_stroke) - met_setpatternstroke(pgs); - else { - gs_throw(-1, "pattern has no context"); - return -1; - } - } - } - - /* nb metro state pointer */ - pat->visual = ms; - gs_free_object(ms->memory, data, "VisualBrush_done"); - return 0; /* incomplete */ -} - - -const met_element_t met_element_procs_VisualBrush = { - "VisualBrush", - { - VisualBrush_cook, - VisualBrush_action, - VisualBrush_done - } -}; diff --git a/met/zipparse.c b/met/zipparse.c deleted file mode 100644 index 7401fd58a..000000000 --- a/met/zipparse.c +++ /dev/null @@ -1,593 +0,0 @@ -#include "assert.h" -#include "gserrors.h" -#include "memory_.h" -#include "zipparse.h" - -#include "pltop.h" /* NB hack to enable disable zip/xml parsing */ - -private inline int -stream_has(stream_cursor_read *pr, unsigned int cnt) -{ - return( pr->limit - pr->ptr >= cnt ); -} - - -private inline byte -read_byte(stream_cursor_read *pr) -{ - pr->ptr++; - return *pr->ptr; -} - -private inline unsigned int -read2(stream_cursor_read *pr, unsigned short *a) -{ - if (stream_has(pr, 2)) { - *a = read_byte(pr) | (read_byte(pr) << 8) ; - // dprintf2(gs_mem_ptr, "read2 %0hd:%0hx\n", *a, *a); - } - else - return eNeedData; - return 0; -} - -private inline unsigned long -read4(stream_cursor_read *pr, unsigned long *a) -{ - if (stream_has(pr, 4)) { - *a = read_byte(pr) | - (read_byte(pr) << 8) | - (read_byte(pr) << 16) | - (read_byte(pr) << 24); - // dprintf2(gs_mem_ptr, "read4 %0ld:%0lx\n", *a, *a); - } - else - return eNeedData; - return 0; -} - - -private int -zip_new_block(zip_state_t *pzip, zip_part_t *part) -{ - int code = 0; - zip_block_t *blk; - - if (pzip->free_list) { - blk = pzip->free_list; - pzip->free_list = blk->next; - blk->next = NULL; - blk->writeoffset = 0; - } - else { - blk = (zip_block_t *) gs_alloc_bytes(pzip->memory, - sizeof(zip_block_t), - "zip_new_block"); - if (blk == NULL) - return gs_error_VMerror; - blk->writeoffset = 0; - blk->next = NULL; - } - assert(part->write); - assert(part->write->writeoffset == ZIP_BLOCK_SIZE); - - memset(blk->data, 0xF0, ZIP_BLOCK_SIZE); - - if (part->tail) - part->tail->next = blk; - part->tail = blk; - - return code; -} - -private int -zip_init_part(zip_state_t *pzip) -{ - zip_part_t *part = (zip_part_t *)gs_alloc_bytes(pzip->memory, size_of(zip_part_t), - "zip_init_part"); - - part->parent = pzip; /* back pointer */ - pzip->num_files++; - pzip->parts[pzip->num_files - 1] = part; - pzip->part_read_state = 0; - part->tail = part->head = part->csaved = part->metasize = part->namesize = 0; - zip_new_block(pzip, part); - part->head = part->curr = part->tail; - part->keep_it = false; /* read once by default */ - part->buf = NULL; - part->zs = NULL; - part->newfile = true; - - return 0; -} - - -/* Can return eNeedData, eExitLanguage, error, 0 - */ -private int -zip_read_part(zip_state_t *pzip, stream_cursor_read *pr) -{ - unsigned long id; - unsigned short shortInt; - unsigned long longInt; - int code = 0; - zip_part_t *part =0; - int i; - - switch( pzip->part_read_state ) { - case 0: - if ((code = read4(pr, &id)) != 0) - return code; - if (id == 0x04034b50) { - if ((code = zip_init_part(pzip)) != 0 ) - return code; - part = pzip->parts[pzip->num_files - 1]; - } else { // if (id == 0x02014b50) - // end of archive - pzip->part_read_state = 20; - return 0; - } - pzip->part_read_state++; - - case 1: /* version to extract*/ - if ((code = read2(pr, &shortInt)) != 0) - return code; - pzip->part_read_state++; - - case 2: /* general*/ - part = pzip->parts[pzip->num_files - 1]; - if ((code = read2(pr, &part->gp_bitflag)) != 0) - return code; - pzip->part_read_state++; - - case 3: /* method */ - part = pzip->parts[pzip->num_files - 1]; - if ((code = read2(pr, &part->comp_method)) != 0) - return code; - pzip->part_read_state++; - - case 4: /* last mod file time */ - if ((code = read2(pr, &shortInt)) != 0) - return code; - pzip->part_read_state++; - - case 5: /* last mod file date */ - if ((code = read2(pr, &shortInt)) != 0) - return code; - pzip->part_read_state++; - - case 6: /* crc-32 */ - if ((code = read4(pr, &longInt)) != 0) - return code; - pzip->part_read_state++; - - case 7: /* csize */ - part = pzip->parts[pzip->num_files - 1]; - if ((code = read4(pr, &part->csize)) != 0) - return code; - pzip->part_read_state++; - - case 8: /* usize */ - part = pzip->parts[pzip->num_files - 1]; - if ((code = read4(pr, &part->usize)) != 0) - return code; - pzip->part_read_state++; - - case 9: /* namesize */ - part = pzip->parts[pzip->num_files - 1]; - if ((code = read2(pr, &part->namesize)) != 0) - return code; - pzip->part_read_state++; - - case 10: /* metasize */ - part = pzip->parts[pzip->num_files - 1]; - if ((code = read2(pr, &part->metasize)) != 0) - return code; - pzip->part_read_state++; - - case 11: - part = pzip->parts[pzip->num_files - 1]; - if (stream_has(pr, part->namesize)) { - part->name = gs_alloc_bytes(pzip->memory, part->namesize + 1, "pzip part name"); - if (part->name == NULL) - return gs_throw(-1, "out of memory"); - memcpy(part->name, pr->ptr +1, part->namesize); - part->name[part->namesize] = 0; - pr->ptr += part->namesize; - pzip->part_read_state++; - } - else - return eNeedData; - case 12: - part = pzip->parts[pzip->num_files - 1]; - if (stream_has(pr, part->metasize)) { - pr->ptr += part->metasize; - pzip->part_read_state++; - } - else if (part->metasize){ - part->metasize -= pr->limit - pr->ptr; - pr->ptr = pr->limit; - return eNeedData; - } - case 13: - pzip->read_state = 1; /* read file after this header */ - pzip->part_read_state = 0; /* next call looks for header */ - break; - - case 20: - /* read extra foo after last file - [archive decryption header] (EFS) - [archive extra data record] (EFS) - [central directory] - [zip64 end of central directory record] - [zip64 end of central directory locator] - [end of central directory record] - */ - for ( i = pr->limit - pr->ptr; i > 4; --i, pr->ptr++ ) { - if ( pr->ptr[1] == 0x50 && - pr->ptr[2] == 0x4b && - pr->ptr[3] == 0x05 && - pr->ptr[4] == 0x06 ) { - pzip->part_read_state++; - pr->ptr += 4; - break; - } - } - break; - case 21: - - if (stream_has(pr, 18) == 0 ) - return eNeedData; - pr->ptr += 16; - if (stream_has(pr, 3)) { - read2(pr, &part->skip_len); - pzip->part_read_state++; - } else { - pr->ptr = pr->limit - 1; - pzip->part_read_state = 0; /* reset for next zip file */ - return -102; // e_ExitLanguage; - } - case 22: - if (stream_has(pr, part->skip_len) == 0 ) - pr->ptr += part->skip_len; - - - pzip->part_read_state = 0; /* reset for next zip file */ - - return -102; // e_ExitLanguage; - - default: - return gs_throw(-1, "coding error"); - } - - return code; -} - - -private int -zip_init_write_stream(zip_state_t *pzip, zip_part_t *part) -{ - if (part->zs == NULL) { - part->zs = gs_alloc_bytes(pzip->memory, size_of(z_stream), "zip z_stream"); - if (part->zs == NULL) - return gs_throw(-1, "out of memory"); - part->zs->zalloc = 0; - part->zs->zfree = 0; - part->zs->opaque = 0; - } - return 0; -} - -private int -zip_decompress_data(zip_state_t *pzip, stream_cursor_read *pin ) -{ - int code = 0; - zip_part_t *part = pzip->parts[pzip->read_part]; - z_stream *zs = 0; - long rlen = pin->limit - pin->ptr - 1; - long wlen = 0; - byte *wptr = NULL; - - int rstart = pin->ptr; - long len; - int status; - - /* add to tail of part's block list */ - wptr = &part->tail->data[part->tail->writeoffset]; - - if (ZIP_BLOCK_SIZE <= part->tail->writeoffset + 1) { - if ((code = zip_new_block(pzip, part))) - return gs_throw(code, "zip_new_block"); - wptr = &part->tail->data[part->tail->writeoffset]; - wlen = ZIP_BLOCK_SIZE; - } - else - wlen = ((ZIP_BLOCK_SIZE - 1) - part->tail->writeoffset) + 1; - - zip_init_write_stream(pzip, part); - - if (part->comp_method == 0) { - int left = part->csize - part->csaved; - if (left == 0) - return eEndOfStream; - rlen = min(left, min(rlen, wlen)); - memcpy(wptr, pin->ptr+1, rlen); - part->tail->writeoffset += rlen; - part->csaved += rlen; - pin->ptr += rlen; - if (part->csize && part->csaved == part->csize) - return eEndOfStream; - } - else { /* 8 == flate */ - zs = part->zs; - zs->next_in = pin->ptr + 1; - zs->avail_in = rlen; - zs->next_out = wptr; - zs->avail_out = wlen; - - if (part->newfile) /* init for new file */ - inflateInit2(part->zs, -15); /* neg zip, 15bit window */ - - status = inflate(zs, Z_NO_FLUSH); - - part->csaved += zs->next_in - pin->ptr - 1; // update comressed read for zips with csize - pin->ptr = zs->next_in - 1; - part->tail->writeoffset += zs->next_out - wptr; - - switch (status) { - case Z_OK: - if (pin->ptr + 1 < pin->limit) - code = 0; - else - code = pin->ptr > rstart ? 0 : 1; - part->newfile = false; - - if (part->csize && part->csaved == part->csize) { - /* recursive call - * NB: need to test the end of part/end of file/no csize case. */ - code = zip_decompress_data(pzip, pin); - } - break; - - case Z_STREAM_END: - part->newfile = true; - inflateEnd(zs); - code = eEndOfStream; // was: EOFC; - break; - - default: - code = ERRC; - gs_throw(code, "inflate error"); - } - } - return code; -} - -/* returns zero on ok else error, swallows status returns - */ -int -zip_decomp_process(met_parser_state_t *st, met_state_t *mets, zip_state_t *pzip, - stream_cursor_read *pr) -{ - int code = 0; - zip_part_t *rpart = NULL; - - /* update reading pointer - * NB: client should be able to choose a different file to read - * currently just serially sends file after file. - */ - - if (pzip->read_part < 0 && pzip->num_files > 0) - pzip->read_part = 0; - if (pzip->read_part >= pzip->num_files ) - return code; // Nothing to do til we have some data. - - rpart = pzip->parts[pzip->read_part]; - - /* decompress and send data to parser */ - code = zip_decompress_data(pzip, pr); - if (code == eEndOfStream) { // good end of input stream - code = 0; - - /* determine if the xps should be parsed and call the xml parser - */ - if ( pzip->inline_mode ) - zip_page(st, mets, pzip, rpart); - - /* setup to read next part */ - pzip->read_part++; - pzip->read_state = 2; - } - else if (code == eWriteStall) { /* write stall on output */ - long len = rpart->s.r.limit - rpart->s.r.ptr; - if ( len && rpart->buf -1 != rpart->s.r.ptr ) - memmove(rpart->buf, rpart->s.r.ptr, len); - rpart->s.r.ptr = rpart->buf -1; - rpart->s.r.limit = rpart->buf + ( len - 1 ); - - code = 0; /* let it be read */ - } - if (code == eNeedData) - code = 0; - return code; -} - - -/* - * code == eNeedData is returned as 0 here. - */ -int -zip_process(met_parser_state_t *st, met_state_t *mets, zip_state_t *pzip, stream_cursor_read *pr) -{ - int code = 0; - zip_part_t *rpart = NULL; - zip_part_t *wpart = NULL; - int last_len = pr->limit - pr->ptr; - - while (pr->limit - pr->ptr > 4 && code == 0) { - - switch (pzip->read_state) { - case 0: /* local file header and skip of end of zip file records */ - if ((code = zip_read_part(pzip, pr)) != 0) { - return code; - } - /* 0 : more header to read - * 1 : file to read - * 3 : end of file - */ - break; - case 1: /* file data */ - /* We don't save compressed data since the 'standard' XPS files don't have lengths - */ - - case 2: /* optional Data descriptor */ - wpart = pzip->parts[pzip->num_files - 1]; - if (wpart && wpart->csaved && wpart->csaved == wpart->csize ) { - /* have count and fall through */ - - if (wpart->gp_bitflag & 1 << 3) { - /* Skip Data descriptor */ - if (stream_has(pr, 12) == 0) { - pzip->read_state = 2; - return 0; - } - pr->ptr += 12; - } - pzip->read_state = 0; - break; - } - else if (pzip->read_state == 2 && wpart->gp_bitflag & 1 << 3) { - /* else end of stream goto after decompress */ - if ( pr->ptr[1] == 0x50 && - pr->ptr[2] == 0x4b && - pr->ptr[3] == 0x07 && - pr->ptr[4] == 0x08 ) { - /* check for split archive marker in the middle of the file - * spec says it must be first ? - */ - if (stream_has(pr, 16) == 0) - return 0; - pr->ptr += 16; - } - else { - if (stream_has(pr, 12) == 0) - return 0; - pr->ptr += 12; - } - pzip->read_state = 0; - break; - } - - case 3: - - if ((code = zip_decomp_process(st, mets, pzip, pr)) != 0 ) - return code; - break; - - case 4: - default : - break; - //pzip->read_state = 0; - } - } - if (code == eNeedData) - return 0; - return code; -} - -private int -zip_initialize(zip_state_t *pzip) -{ - int i = 0; - - if (pzip->memory == 0) - return -1; - -#ifdef PARSE_XML_HACK - pzip->zip_mode = false; -#else - pzip->zip_mode = true; -#endif - - pzip->inline_mode = false; /* false == buffer entire job in ram! */ - - pzip->need_dir = false; - pzip->needfiledata = false; - pzip->read_state = 0; - pzip->part_read_state = 0; - pzip->read_part = -1; - pzip->num_files = 0; - for (i=0; i < 5000; i++) - pzip->parts[i] = 0; - - return 0; -} - -private bool -is_font(char *name) -{ - int pos = strlen(name) - 4; - if (name && pos > 0 ) - return strncasecmp("TTF", &name[pos], 3); - else - return false; -} - -int -zip_end_job(met_parser_state_t *st, met_state_t *mets, zip_state_t *pzip) -{ - int i = 0; //pzip->firstPage; - int code = 0; - - - if (!pzip->inline_mode) { - for (; i < 5000; i++) { - if (pzip->parts[i]) { - code = zip_page(st, mets, pzip, pzip->parts[i]); - if (code) { - gs_rethrow(code, "delayed zip_page"); - break; - } - } - } - } - - for (i=0; i < 5000; i++) { - if (pzip->parts[i]) { - if ( is_font(pzip->parts[i]->name) ) { - char buf[256]; - buf[0] = '/'; - buf[1] = 0; - strncpy(&buf[1], pzip->parts[i]->name, strlen(pzip->parts[i]->name)); - buf[strlen(pzip->parts[i]->name) + 1] = 0; - pl_dict_undef(&mets->font_dict, buf, strlen(buf)); - } - zip_part_free_all(pzip->parts[i]); - - // need destructor here. - gs_free_object(pzip->memory, pzip->parts[i]->name, "zip_part_free struct"); - gs_free_object(pzip->memory, pzip->parts[i]->buf, "zip_part_free struct"); - gs_free_object(pzip->memory, pzip->parts[i]->zs, "zip_part_free struct"); - gs_free_object(pzip->memory, pzip->parts[i], "zip_part_free struct"); - pzip->parts[i] = 0; - } - } - pzip->read_part = -1; - - return zip_initialize(pzip); -} - -zip_state_t * -zip_init_instance(gs_memory_t *mem) -{ - zip_state_t *pzip; - - pzip = gs_alloc_bytes(mem, sizeof(zip_state_t), "zip_init_instance alloc zip_state_t"); - pzip->memory = mem; - zip_initialize(pzip); - pzip->free_blk_list_len = 0; - pzip->free_list = NULL; - - - return pzip; -} diff --git a/met/zipparse.h b/met/zipparse.h deleted file mode 100644 index 549100f3e..000000000 --- a/met/zipparse.h +++ /dev/null @@ -1,128 +0,0 @@ - - -/* Portions Copyright (C) 2005 artofcode LLC. - Portions Copyright (C) 2005 Artifex Software Inc. - This software is based in part on the work of the Independent JPEG Group. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ -/*$Id$*/ - -#include "scommon.h" -#include "szlibxx.h" -#include "gserror.h" -#include "metparse.h" - -/* linked list block size */ -#define ZIP_BLOCK_SIZE 2000 -#define ZIP_BLOCK_MAX ZIP_BLOCK_SIZE-1 -#define PZIP_FREE_BLK_MAX_LEN 10 - - -typedef struct zip_block_s zip_block_t; -struct zip_block_s -{ - long writeoffset; // either end of data or last written byte - - byte data[ZIP_BLOCK_SIZE]; - zip_block_t *next; -}; - -typedef struct zip_state_s zip_state_t; - -typedef struct zip_part_s -{ - zip_state_t *parent; - - unsigned short gp_bitflag; - unsigned short comp_method; - long csize; /* compressed size */ - long usize; /* uncompressed size */ - - unsigned short metasize; /* meta not saved */ - unsigned short namesize; - unsigned long skip_len; - byte *name; /* file name missing leading / */ - - long csaved; /* compressed saved max is csize */ - - zip_block_t *head; /* head */ - zip_block_t *curr; /* current read position */ - zip_block_t *tail; /* save uncompressed to tail */ - - bool keep_it; /* don't delete after decompress/read */ - - /* compressed buffer and its stream */ - byte *buf; /* write buffer */ - stream_cursor s; /* uncompressed stream */ - z_stream *zs; /* zlib stream, 1 per file ? */ - bool newfile; /* end of compressed stream triggers new file */ -} zip_part_t; - - -struct zip_state_s -{ - gs_memory_t *memory; - bool zip_mode; - bool inline_mode; /* should be true; set to false reads entire job then processes */ - bool need_dir; - bool needfiledata; - int read_state; - int part_read_state; - - - int num_files; - - int read_part; /* file being read */ - zip_part_t *parts[5000]; /* sk: perhaps a list */ - - zip_part_t *head; // NB linked list would be better than array - zip_part_t *curr; // internal issue - zip_part_t *tail; - - - int free_blk_list_len; - zip_block_t *free_list; - -}; - -typedef enum zip_error_status_code_s { - eNeedData = 42, - eEndOfStream = 911, - eWriteStall = 912, -} zip_error_status_code_t; - - -int -zip_process(met_parser_state_t *st, met_state_t *mets, zip_state_t *pzip, stream_cursor_read *pr); - -int -zip_page( met_parser_state_t *st, met_state_t *mets, zip_state_t *pzip, zip_part_t *rpart ); - - -/* zip file access routines */ - -zip_part_t * -find_zip_part_by_name(zip_state_t *pzip, char *name); - -int -zip_read_blk_next_blk(zip_part_t *rpart); - -int -zip_part_length(zip_part_t *rpart); - -int -zip_part_seek(zip_part_t *rpart, long offset, int whence); - -int -zip_part_read( byte *dest, int rlen, zip_part_t *rpart ); - -int -zip_part_free_all( zip_part_t *part ); - -int -zip_end_job(met_parser_state_t *st, met_state_t *mets, zip_state_t *pzip); diff --git a/met/zippart.c b/met/zippart.c deleted file mode 100644 index da80e9a32..000000000 --- a/met/zippart.c +++ /dev/null @@ -1,328 +0,0 @@ -/* Copyright (C) 2005, 2006 Artifex Software Inc. - All Rights Reserved. - - This software is distributed under license and may not be copied, modified - or distributed except as expressly authorized under the terms of that - license. Refer to licensing information at http://www.artifex.com/ or - contact Artifex Software, Inc., 101 Lucas Valley Road #110, - San Rafael, CA 94903, (415)492-9861, for further information. */ - -/* $Id$ */ - -#include "gx.h" -#include "zipparse.h" -#include "assert.h" -#include "gserrors.h" -#include "gsmemory.h" - - -/* compile switch for debuging zip compression - * writes the exploded zip file to /tmp/XPS so you might want to create the directory - */ -static const int ziptestmode = 1; - - - -/* NB: needed features: unicode, esc characters, directories aren't supported.*/ -zip_part_t * -find_zip_part_by_name(zip_state_t *pzip, char *name) -{ - int i; - // NB: needs linked list parts interface - - for (i=0; i<5000 && i < pzip->num_files; i++) - if (pzip->parts[i]) - if (name[0] == '/') { - if (!strncmp(name+1, pzip->parts[i]->name, strlen(name) - 1)) - return( pzip->parts[i] ); - } - else - if (!strncmp(name, pzip->parts[i]->name, strlen(name))) - return( pzip->parts[i] ); - - return NULL; -} - -/* move curr read block to next block updating read stream - * - * do - * read all avail limit is block size or end of data - * while (!zip_read_blk_next_blk(rpart)) - */ -int -zip_read_blk_next_blk(zip_part_t *rpart) -{ - rpart->curr = rpart->curr->next; - if (rpart->curr) { - rpart->s.r.ptr = &rpart->curr->data[0] - 1; - rpart->s.r.limit = &rpart->curr->data[rpart->curr->writeoffset-1]; - } - else { - rpart->curr = rpart->head; /* let's not leave a bad pointer */ - return -1; - } - return 0; -} - - -/* length of all the data in a zip file, or XPS part */ -int -zip_part_length(zip_part_t *rpart) -{ - int len = 0; - zip_block_t *blk; - - blk = rpart->head; - while (blk->next) { - len += blk->writeoffset; - if (blk->writeoffset != ZIP_BLOCK_SIZE) { - ; - dprintf2("Wasted Space! zip_part_length != zip_part_read %ld, %d\n", - blk->writeoffset, ZIP_BLOCK_SIZE); - } - - blk = blk->next; - } - len += blk->writeoffset; - return len; -} - -/* SEEK_SET, SEEK_CUR, SEEK_END are all supported. - * readonly usage, so seek beyond EOF is ignored. - */ -int -zip_part_seek(zip_part_t *rpart, long offset, int whence) -{ - zip_block_t *blk; - - if (whence == SEEK_END) { - /* SEEK to end of file is legal, beyond isn't - * so this will either move back from end of file or to EOF - */ - return zip_part_seek( rpart, zip_part_length(rpart) + offset, SEEK_SET ); - } - else if (whence == SEEK_CUR) { // sk foo untested. - long extra = rpart->s.r.ptr - ( &blk->data[0] - 1); - blk = rpart->curr; - offset += extra; - - do { - if ( offset >= ZIP_BLOCK_SIZE ) - offset -= ZIP_BLOCK_SIZE; - else - break; - blk = blk->next; - } while (blk->next); - rpart->curr = blk; - } - else if (whence == SEEK_SET) { // sk foo tested. - blk = rpart->head; - do { - if ( offset >= ZIP_BLOCK_SIZE ) - offset -= ZIP_BLOCK_SIZE; - else - break; - blk = blk->next; - } while (blk->next) ; - rpart->curr = blk; - } - else - return -1; - - rpart->s.r.limit = &rpart->curr->data[rpart->curr->writeoffset] - 1; - if ( offset < rpart->curr->writeoffset ) - rpart->s.r.ptr = &rpart->curr->data[offset] - 1; - else - rpart->s.r.ptr = &rpart->curr->data[rpart->curr->writeoffset] - 1; - - return 0; -} - -/* copy rlen bytes from zip_part into dest - * return number of bytes copied. - * - * spans linked list of part data blocks. - * only returns less for rlen on end of list data - * entire part is availiable, all pieces are concatinated - * prior to first read. - */ -int -zip_part_read( byte *dest, int rlen, zip_part_t *rpart ) -{ - int error = 0; - int have = rpart->s.r.limit - rpart->s.r.ptr; - int copied = 0; - - while (rlen > 0) { - if ( have > 0 ) { - have = min(have, rlen); - memcpy( dest, rpart->s.r.ptr + 1, have ); - rlen -= have; - copied += have; - dest += have; - } - if (rlen > 0) { - if (zip_read_blk_next_blk(rpart)) { - break; // early end of data, client must check return count - } - have = rpart->s.r.limit - rpart->s.r.ptr; - } - else - break; - } - return copied; -} - - -/* This is test code to test the read stream interface */ - -private int -zip_page_test( zip_state_t *pzip, zip_part_t *rpart ) -{ - static int called_counter = 0; - int error; - - called_counter++; - - if (0) { /* test small reads of the whole part */ - byte buf[100]; - if ((error = zip_part_seek(rpart, 0, 0)) != 0) - return gs_rethrow(error, "seek set 0 error"); - uint len = zip_part_length(rpart); - while (len) { - len -= zip_part_read(&buf[0], 100, rpart); - } - zip_part_free_all(rpart); - } - - if (1) { - char buf[4]; - if ((error = zip_part_seek(rpart, 0, 0)) != 0) - return gs_rethrow(error, "seek set 0 error"); - int size = zip_part_read(&buf, 4, rpart); - if ( size != 4 ) - dprintf("bad len\n"); - } - - if (1) { - char fname[256]; - FILE *fp = 0; - char *ptr = rpart->name; - int i = 0; - int index = -1; - - - mkdir("/tmp/XPS", 0777); - - strcpy(fname, "/tmp/XPS/"); - for (i = strlen(fname); *ptr != 0; i++, ptr++) - if (*ptr == '/') - fname[i] = '-'; - else - fname[i] = *ptr; - fname[i]=0; - - dprintf1("Zip File Name %s\n", fname); - - if ((fp = fopen(fname, "w")) == NULL) - return gs_throw1(-1, "couldn't open %s", fname); - - if ((error = zip_part_seek(rpart, 0, 0)) != 0) - return gs_rethrow(error, "seek failed"); - do { - do { - uint avail = rpart->s.r.limit - rpart->s.r.ptr; - fwrite(rpart->s.r.ptr + 1, 1, avail, fp); - rpart->s.r.ptr += avail; - } - while (rpart->s.r.ptr + 1 < rpart->s.r.limit); - } - while ( 0 == zip_read_blk_next_blk(rpart) ); - fclose(fp); - } - -} - -int -zip_page( met_parser_state_t *st, met_state_t *mets, zip_state_t *pzip, zip_part_t *rpart ) -{ - static int page = 0; - static int start_page = 0; /* hack to skip a few pages */ - - long len = 0; - int error = 0; - char *p = &rpart->name[strlen(rpart->name) - 5]; - - if ( gs_debug_c('i') ) - dprintf1("End of part %s\n", rpart->name ); - - /* NB: its not cool to string compare to find FixedPages to parse thats - * what rels are for... - */ - - /* feed met_process a Page */ - if ( !strncmp(p, "fpage", 5 ) || (!strncmp(rpart->name, "FixedPage_", 10) && - strncmp(p+1, "rels", 4 ))) { - - ++page; - - if ( page < start_page ) - return 0; - - if ( ziptestmode ) { - zip_page_test(pzip, rpart); - } - - if (0 < zip_part_length(rpart)) { - error = zip_part_seek(rpart, 0, 0); - if (error) return error; - do { - do { - error = met_process(st, mets, pzip, &rpart->s.r); - if (error) - return gs_rethrow(error, "page processing failed"); - } - while (rpart->s.r.ptr + 1 < rpart->s.r.limit); - } - while ( 0 == zip_read_blk_next_blk(rpart) ); - } - else - dprintf1("Zero length part %s\n", rpart->name ); - /* auto deletion of FixedPage after parsing */ - //if ( pzip->inline_mode == false ) - // zip_part_free_all( rpart ); - // can't delete - } - else if ( 0 && ziptestmode ) { - zip_page_test(pzip, rpart); - } - - return error; -} - - -int -zip_part_free_all( zip_part_t *part ) -{ - zip_block_t *next = part->head; - zip_block_t *this = part->head; - zip_state_t *pzip = part->parent; - - while (next) { - this = next; - next = next->next; - - if (pzip->free_blk_list_len < PZIP_FREE_BLK_MAX_LEN) { - this->next = pzip->free_list; - pzip->free_list = this; - pzip->free_blk_list_len++; - } - else - gs_free_object(pzip->memory, this, "zip_part_free block"); - } - part->head = 0; - part->curr = 0; - part->tail = 0; - - return 0; -} diff --git a/met/zipstate.h b/met/zipstate.h deleted file mode 100644 index 2a8b2cd38..000000000 --- a/met/zipstate.h +++ /dev/null @@ -1 +0,0 @@ -/* DEAD */ |