📄 pslib.c
字号:
/* * (c) Copyright 2001 Vilson G鋜tner, Uwe Steinmann. * (c) Copyright 2002-2004 Uwe Steinmann. * All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *//* $Id: */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include <stdlib.h>#include <stdarg.h>#include <stdio.h>#include <string.h>#include <time.h>#include <math.h>#include <sys/types.h>#include <sys/stat.h>#ifndef WIN32#include <strings.h>#include <sys/select.h>#include <unistd.h>#endif#include <ctype.h>#ifdef WIN32#include <windows.h>#include <winbase.h>#endif#include "ps_intern.h"#include "ps_memory.h"#include "ps_error.h"#include "ps_fontenc.h"#include "ps_inputenc.h"#ifdef HAVE_LIBPNG# include "png.h"#endif#ifdef HAVE_LIBJPEG# include "jpeglib.h"#endif#ifdef HAVE_LIBGIF# include "gif_lib.h"#endif#ifdef HAVE_LIBTIFF# include "tiffio.h"#endif#ifndef DISABLE_BMP# include "bmp.h"#endif/* ps_writeproc_file() {{{ * Default output function */static size_tps_writeproc_file(PSDoc *p, void *data, size_t size){ return fwrite(data, 1, size, p->fp);}/* }}} *//* ps_writeproc_buffer() {{{ * Default output function for memory */static size_tps_writeproc_buffer(PSDoc *p, void *data, size_t size){ return str_buffer_write(p, p->sb, data, size);}/* }}} *//* _ps_delete_font() {{{ */void _ps_delete_font(PSDoc *psdoc, PSFont *psfont) { if(NULL == psdoc) { ps_error(psdoc, PS_RuntimeError, _("PSDoc is null.")); return; } if(psfont == NULL) { ps_error(psdoc, PS_RuntimeError, _("PSFont is null.")); return; } if(psfont->psdoc != psdoc) { ps_error(psdoc, PS_RuntimeError, _("This PSFont was created for a different document.")); return; } /* Free hash table with char info */ if(psfont->metrics->gadobechars) { ADOBEINFO *ai; char *p ; ght_iterator_t iterator; for(ai = ght_first(psfont->metrics->gadobechars, &iterator, (void **) &p); ai != NULL; ai = ght_next(psfont->metrics->gadobechars, &iterator, (void **) &p)) { LIG *lig, *ligtmp; KERN *k, *ktmp; PCC *np, *nptmp; lig = ai->ligs; while(lig != NULL) { if(lig->succ) psdoc->free(psdoc, lig->succ); if(lig->sub) psdoc->free(psdoc, lig->sub); ligtmp = lig->next; psdoc->free(psdoc, lig); lig = ligtmp; } /* for (lig=ai->ligs; lig; lig = ligtmp) { if(lig->succ) psdoc->free(psdoc, lig->succ); if(lig->sub) psdoc->free(psdoc, lig->sub); ligtmp = lig->next; psdoc->free(psdoc, lig); } */ k = ai->kerns; while(k != NULL) { if(k->succ) psdoc->free(psdoc, k->succ); ktmp = k->next; psdoc->free(psdoc, k); k = ktmp; } for (np=ai->pccs; np; np = nptmp) { if(np->partname) psdoc->free(psdoc, np->partname); nptmp = np->next; psdoc->free(psdoc, np); } if(ai->kern_equivs) psdoc->free(psdoc, ai->kern_equivs); psdoc->free(psdoc, ai->adobename); psdoc->free(psdoc, ai); } ght_finalize(psfont->metrics->gadobechars); } if(psfont->metrics->fontenc) { ght_finalize(psfont->metrics->fontenc); } if(psfont->metrics->fontname) { psdoc->free(psdoc, psfont->metrics->fontname); } if(psfont->metrics->codingscheme) { psdoc->free(psdoc, psfont->metrics->codingscheme); } if(psfont->metrics) { psdoc->free(psdoc, psfont->metrics); } if(psfont->encoding) { psdoc->free(psdoc, psfont->encoding); } /* FIXME: There is much more to free (e.g. the font metrics) than * just the font structure. */ psdoc->free(psdoc, psfont);}/* }}} *//* _ps_delete_image() {{{ */void _ps_delete_image(PSDoc *psdoc, PSImage *psimage) { if(NULL == psdoc) { ps_error(psdoc, PS_RuntimeError, _("PSDoc is null.")); return; } if(NULL == psimage) { ps_error(psdoc, PS_RuntimeError, _("PSImage is null.")); return; } if(psimage->type) psdoc->free(psdoc, psimage->type); if(psimage->data) psdoc->free(psdoc, psimage->data); if(psimage->name) psdoc->free(psdoc, psimage->name); if(psimage->palette) psdoc->free(psdoc, psimage->palette); psdoc->free(psdoc, psimage);}/* }}} *//* _ps_delete_pattern() {{{ */void _ps_delete_pattern(PSDoc *psdoc, PSPattern *pspattern) { if(NULL == psdoc) { ps_error(psdoc, PS_RuntimeError, _("PSDoc is null.")); return; } if(NULL == pspattern) { ps_error(psdoc, PS_RuntimeError, _("PSPattern is null.")); return; } if(pspattern->name) psdoc->free(psdoc, pspattern->name); psdoc->free(psdoc, pspattern);}/* }}} *//* _ps_delete_spotcolor() {{{ */void _ps_delete_spotcolor(PSDoc *psdoc, PSSpotColor *spotcolor) { if(NULL == psdoc) { ps_error(psdoc, PS_RuntimeError, _("PSDoc is null.")); return; } if(NULL == spotcolor) { ps_error(psdoc, PS_RuntimeError, _("PSSpotColor is null.")); return; } if(spotcolor->name) psdoc->free(psdoc, spotcolor->name); psdoc->free(psdoc, spotcolor);}/* }}} *//* _ps_delete_shading() {{{ */void _ps_delete_shading(PSDoc *psdoc, PSShading *psshading) { if(NULL == psdoc) { ps_error(psdoc, PS_RuntimeError, _("PSDoc is null.")); return; } if(NULL == psshading) { ps_error(psdoc, PS_RuntimeError, _("PSShading is null.")); return; } if(psshading->name) psdoc->free(psdoc, psshading->name); psdoc->free(psdoc, psshading);}/* }}} *//* _ps_delete_gstate() {{{ */void _ps_delete_gstate(PSDoc *psdoc, PSGState *gstate) { if(NULL == psdoc) { ps_error(psdoc, PS_RuntimeError, _("PSDoc is null.")); return; } if(NULL == gstate) { ps_error(psdoc, PS_RuntimeError, _("PSGState is null.")); return; } if(gstate->name) psdoc->free(psdoc, gstate->name); psdoc->free(psdoc, gstate);}/* }}} *//* _ps_register_font|image|pattern() {{{ * Register font, image with PS document * Returns the font, image id which is the index within the * internal font, image * array + 1. Returns 0 in case of an error. */#define PS_REGISTER_RESOURCE(resname, restype) \static int \_ps_register_##resname(PSDoc *p, restype *resname) \{ \ int i; \ \ i = 0; \ while(i < p->resname##cnt && p->resname##s[i] != NULL) { \ i++; \ } \ if(i >= p->resname##cnt) { \ if(NULL == (p->resname##s = p->realloc(p, p->resname##s, (p->resname##cnt+5) * sizeof(restype *), _("Could not enlarge memory for internal resource array.")))) { \ return 0; \ } \ memset((void *)&p->resname##s[p->resname##cnt], 0, 5*sizeof(restype *)); \ p->resname##cnt += 5; \ } \ p->resname##s[i] = resname; \ return(i+1); \}#define PS_UNREGISTER_RESOURCE(resname, restype) \static void \_ps_unregister_##resname(PSDoc *p, int id) \{ \ if(id > p->resname##cnt || id < 1) { \ ps_error(p, PS_Warning, _("Trying to unregister a resource which does not exist.")); \ return; \ } \ if(p->resname##s[id-1] != NULL) { \ _ps_delete_##resname(p, p->resname##s[id-1]); \ p->resname##s[id-1] = NULL; \ } else { \ ps_error(p, PS_Warning, _("Trying to unregister a resource which does not exist.")); \ } \}#define PS_FIND_RESOURCE(resname, restype) \static int \_ps_find_##resname(PSDoc *p, restype *ptr) \{ \ int i; \ \ i = 0; \ while(i < p->resname##cnt) { \ if(p->resname##s[i] == ptr) \ return(i+1); \ i++; \ } \ return(0); \}#define PS_FIND_RESOURCE_BY_NAME(resname, restype) \static int \_ps_find_##resname##_by_name(PSDoc *p, const char *name) \{ \ int i; \ \ i = 0; \ while(i < p->resname##cnt) { \ if(p->resname##s[i] && (0 == strcmp(p->resname##s[i]->name, name))) \ return(i+1); \ i++; \ } \ return(0); \}#define PS_GET_RESOURCE(resname, restype) \static restype * \_ps_get_##resname(PSDoc *p, int id) \{ \ if(id > p->resname##cnt || id < 1) { \ ps_error(p, PS_Warning, _("Trying to get a resource which does not exist.")); \ return NULL; \ } \ return(p->resname##s[id-1]); \}PS_REGISTER_RESOURCE(font, PSFont)PS_UNREGISTER_RESOURCE(font, PSFont)PS_FIND_RESOURCE(font, PSFont)PS_FIND_RESOURCE_BY_NAME(font, PSFont)PS_GET_RESOURCE(font, PSFont)PS_REGISTER_RESOURCE(image, PSImage)PS_UNREGISTER_RESOURCE(image, PSImage)PS_FIND_RESOURCE(image, PSImage)PS_FIND_RESOURCE_BY_NAME(image, PSImage)PS_GET_RESOURCE(image, PSImage)PS_REGISTER_RESOURCE(pattern, PSPattern)PS_UNREGISTER_RESOURCE(pattern, PSPattern)PS_FIND_RESOURCE(pattern, PSPattern)PS_FIND_RESOURCE_BY_NAME(pattern, PSPattern)PS_GET_RESOURCE(pattern, PSPattern)PS_REGISTER_RESOURCE(shading, PSShading)PS_UNREGISTER_RESOURCE(shading, PSShading)PS_FIND_RESOURCE(shading, PSShading)PS_FIND_RESOURCE_BY_NAME(shading, PSShading)PS_GET_RESOURCE(shading, PSShading)PS_REGISTER_RESOURCE(spotcolor, PSSpotColor)PS_UNREGISTER_RESOURCE(spotcolor, PSSpotColor)PS_FIND_RESOURCE(spotcolor, PSSpotColor)PS_FIND_RESOURCE_BY_NAME(spotcolor, PSSpotColor)PS_GET_RESOURCE(spotcolor, PSSpotColor)PS_REGISTER_RESOURCE(gstate, PSGState)PS_UNREGISTER_RESOURCE(gstate, PSGState)PS_FIND_RESOURCE(gstate, PSGState)PS_FIND_RESOURCE_BY_NAME(gstate, PSGState)PS_GET_RESOURCE(gstate, PSGState)/* }}} *//* ps_output_shading_dict() {{{ * Outputs a shading dictionary. */static void ps_output_shading_dict(PSDoc *psdoc, PSShading *psshading) { ps_printf(psdoc, "<<\n"); ps_printf(psdoc, " /ShadingType %d\n", psshading->type); if(psshading->type == 3) ps_printf(psdoc, " /Coords [%.2f %.2f %.2f %.2f %.2f %.2f]\n", psshading->x0, psshading->y0, psshading->r0, psshading->x1, psshading->y1, psshading->r1); else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -