⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pslib.c

📁 PSlib是一个用来生成PostScript文件的类库。提供了一个生成PostScript文件的简单方法。
💻 C
📖 第 1 页 / 共 5 页
字号:
				ps_printf(psdoc, "[ /Separation (%s)\n", spotcolor->name);				switch(spotcolor->colorspace) {					case PS_COLORSPACE_GRAY:						ps_printf(psdoc, "  /DeviceGray { 1 %f sub mul 1 exch sub }\n", spotcolor->c1);						break;					case PS_COLORSPACE_RGB: {						float max;						max = (spotcolor->c1 > spotcolor->c2) ? spotcolor->c1 : spotcolor->c2;						max = (max > spotcolor->c3) ? max : spotcolor->c3;						ps_printf(psdoc, "  /DeviceRGB { 1 exch sub dup dup %f exch sub %f mul add exch dup dup %f exch sub %f mul add exch dup %f exch sub %f mul add }\n", max, spotcolor->c1, max, spotcolor->c2, max, spotcolor->c3);						break;					}					case PS_COLORSPACE_CMYK:							ps_printf(psdoc, "  /DeviceCMYK { dup %f mul exch dup %f mul exch dup %f mul exch %f mul }\n", spotcolor->c1, spotcolor->c2, spotcolor->c3, spotcolor->c4);						break;				}				ps_printf(psdoc, "] setcolorspace\n");				ps_printf(psdoc, "%f setcolor\n", currentcolor->c2);				break;			}		}	}}/* }}} *//* PS_open_fp() {{{ * Associates an already open file with the PostScript document created * with PS_new(). */PSLIB_API int PSLIB_CALLPS_open_fp(PSDoc *psdoc, FILE *fp) {	if(NULL == fp) {		ps_error(psdoc, PS_Warning, _("File pointer is NULL. Use PS_open_mem() to create file in memory."));		return(-1);	}	psdoc->fp = fp;	psdoc->closefp = ps_false;	psdoc->writeproc = ps_writeproc_file;	psdoc->page = 0;	psdoc->doc_open = ps_true;	ps_enter_scope(psdoc, PS_SCOPE_DOCUMENT);	return(0);}/* }}} *//* PS_open_file() {{{ * Associates a file to the PostScript document created with PS_new(). */PSLIB_API int PSLIB_CALLPS_open_file(PSDoc *psdoc, const char *filename) {	FILE *fp;	if(filename == NULL || filename[0] == '\0' || (filename[0] == '-' && filename[1] == '\0')) {		PS_open_mem(psdoc, NULL);		return 0;	} else {		fp = fopen(filename, "w");		if(NULL == fp) {			ps_error(psdoc, PS_IOError, _("Could not open file '%s'."), filename);			return -1;		}		if(0 > PS_open_fp(psdoc, fp)) {			fclose(fp);			return(-1);		}		psdoc->closefp = ps_true;	}	return 0;}/* }}} *//* PS_open_mem() {{{ * Create document in memory. Actually you are just passing a write procedure * which is used instead of the internal procedure. */PSLIB_API int PSLIB_CALLPS_open_mem(PSDoc *p, size_t (*writeproc)(PSDoc *p, void *data, size_t size)) {	if (writeproc == NULL) {		p->sb = str_buffer_new(p, 1000);		p->writeproc = ps_writeproc_buffer;	} else {		p->writeproc = writeproc;	}	p->fp = NULL;	p->page = 0;	p->doc_open = ps_true;	ps_enter_scope(p, PS_SCOPE_DOCUMENT);	return 0;}/* }}} *//* _output_bookmarks() {{{ * */void _output_bookmarks(PSDoc *psdoc, DLIST *bookmarks) {	PS_BOOKMARK *bm;	for(bm = dlst_last(bookmarks); bm != NULL; bm = dlst_prev(bm)) {		char *str;		ps_printf(psdoc, "[ /Page %d /Title (", bm->page);		str = bm->text;		while(*str != '\0') {			unsigned char index = (unsigned char) *str;			/* Everything below 32, above 127 and '(' and ')' should be output			 * as octal values.			 */			if(index < 32 || index > 127 || index == '(' || index == ')' || index == '\\') {				ps_printf(psdoc, "\\%03o", index);			} else {				ps_putc(psdoc, *str);			}			str++;		}		ps_printf(psdoc, ") /Count %d /OUT pdfmark\n", (bm->open == 0) ? bm->children->count : -bm->children->count);		if(bm->children->count)			_output_bookmarks(psdoc, bm->children);	}}/* }}} *//* PS_close() {{{ * Closes a PostScript document. It closes the actual file only if the * document was opened with PS_open_file(). This function does not * free resources. Use PS_delete() to do that. */PSLIB_API void PSLIB_CALLPS_close(PSDoc *psdoc) {	/* End page if it is still open */	if(psdoc->page_open == ps_true) {		ps_error(psdoc, PS_Warning, _("Ending last page of document."));		PS_end_page(psdoc);	}	if(!ps_check_scope(psdoc, PS_SCOPE_DOCUMENT)) {		ps_error(psdoc, PS_RuntimeError, _("%s must be called within 'document' scope."), __FUNCTION__);		return;	}	/* Write the trailer if the document was not close before */	if(psdoc->doc_open == ps_true) {		ps_printf(psdoc, "%%%%Trailer\n");		ps_printf(psdoc, "end\n");		if(psdoc->bookmarks->count > 0) {			_output_bookmarks(psdoc, psdoc->bookmarks);		}		ps_printf(psdoc, "%%%%Pages: %d\n", psdoc->page);		ps_printf(psdoc, "%%%%BoundingBox: %s\n", psdoc->BoundingBox);		ps_printf(psdoc, "%%%%Orientation: %s\n", psdoc->Orientation);		ps_printf(psdoc, "%%%%EOF");		ps_leave_scope(psdoc, PS_SCOPE_DOCUMENT);	}	/* FIXME: Need to free the linked lists parameters, categories and values */	if((psdoc->closefp == ps_true) && (NULL != psdoc->fp)) {		fclose(psdoc->fp);		psdoc->fp = NULL;	}	psdoc->doc_open = ps_false;}/* }}} *//* PS_delete() {{{ * Frees all resources of a document. If the document was not closed before, * it will also be closed. */PSLIB_API void PSLIB_CALLPS_delete(PSDoc *psdoc) {	int i;	if(NULL == psdoc) {		ps_error(psdoc, PS_RuntimeError, _("PSDoc is null."));		return;	}	/* Make sure the document is closed */	if(psdoc->doc_open == ps_true) {		PS_close(psdoc);	}	if(psdoc->sb)		str_buffer_delete(psdoc, psdoc->sb);	/* Free the memory */	ps_del_resources(psdoc);	ps_del_parameters(psdoc);	ps_del_values(psdoc);	ps_del_bookmarks(psdoc, psdoc->bookmarks);	psdoc->bookmarks = NULL;	if(psdoc->Author) {		psdoc->free(psdoc, psdoc->Author);		psdoc->Author = NULL;	}	if(psdoc->Keywords) {		psdoc->free(psdoc, psdoc->Keywords);		psdoc->Keywords = NULL;	}	if(psdoc->Subject) {		psdoc->free(psdoc, psdoc->Subject);		psdoc->Subject = NULL;	}	if(psdoc->Title) {		psdoc->free(psdoc, psdoc->Title);		psdoc->Title = NULL;	}	if(psdoc->Creator) {		psdoc->free(psdoc, psdoc->Creator);		psdoc->Creator = NULL;	}	if(psdoc->BoundingBox) {		psdoc->free(psdoc, psdoc->BoundingBox);		psdoc->BoundingBox = NULL;	}	if(psdoc->Orientation) {		psdoc->free(psdoc, psdoc->Orientation);		psdoc->Orientation = NULL;	}	if(psdoc->CreationDate) {		psdoc->free(psdoc, psdoc->CreationDate);		psdoc->CreationDate = NULL;	}	/* Freeing font resources */	i = 0;	while(i < psdoc->fontcnt) {		if(psdoc->fonts[i]) {			_ps_delete_font(psdoc, psdoc->fonts[i]);		}		i++;	}	psdoc->free(psdoc, psdoc->fonts);	/* Freeing image resources */	i = 0;	while(i < psdoc->imagecnt) {		if(psdoc->images[i]) {			_ps_delete_image(psdoc, psdoc->images[i]);		}		i++;	}	psdoc->free(psdoc, psdoc->images);	/* Freeing pattern resources */	i = 0;	while(i < psdoc->patterncnt) {		if(psdoc->patterns[i]) {			_ps_delete_pattern(psdoc, psdoc->patterns[i]);		}		i++;	}	psdoc->free(psdoc, psdoc->patterns);	/* Freeing spotcolor resources */	i = 0;	while(i < psdoc->spotcolorcnt) {		if(psdoc->spotcolors[i]) {			_ps_delete_spotcolor(psdoc, psdoc->spotcolors[i]);		}		i++;	}	psdoc->free(psdoc, psdoc->spotcolors);	/* Freeing shading resources */	i = 0;	while(i < psdoc->shadingcnt) {		if(psdoc->shadings[i]) {			_ps_delete_shading(psdoc, psdoc->shadings[i]);		}		i++;	}	psdoc->free(psdoc, psdoc->shadings);	/* Freeing graphic state resources */	i = 0;	while(i < psdoc->gstatecnt) {		if(psdoc->gstates[i]) {			_ps_delete_gstate(psdoc, psdoc->gstates[i]);		}		i++;	}	psdoc->free(psdoc, psdoc->gstates);	if(psdoc->hdict)		hnj_hyphen_free(psdoc->hdict);	if(psdoc->hdictfilename)		psdoc->free(psdoc, psdoc->hdictfilename);	psdoc->free(psdoc, psdoc);}/* }}} *//* PS_set_parameter() {{{ * Sets all kind of parameters. Parameters are string values as opposed * to 'values' set by PS_set_value() which are of type float. * Some parameters change internal variables while other are just * stored in double linked list. If a value itself is a name value pair, * then this is called a resource. */PSLIB_API void PSLIB_CALLPS_set_parameter(PSDoc *psdoc, const char *name, const char *value) {	if(NULL == psdoc) {		ps_error(psdoc, PS_RuntimeError, _("PSDoc is null."));		return;	}	if((strcmp(name, "FontAFM") == 0) ||		 (strcmp(name, "FontOutline") == 0) ||		 (strcmp(name, "FontProtusion") == 0) ||		 (strcmp(name, "FontEncoding") == 0) ||		 (strcmp(name, "RightMarginKerning") == 0) ||		 (strcmp(name, "LeftMarginKerning") == 0)) {		char *res = ps_strdup(psdoc, value);		char *filename;		if ((filename = strchr(res, '=')) == NULL) {			psdoc->free(psdoc, res);			ps_error(psdoc, PS_Warning, _("Invalid resource"));			return;		}		*filename++ = '\0';		if (*filename == '=') {			filename++;		}		if(strcmp(name, "RightMarginKerning") == 0) {			ADOBEINFO *ai;			if(!psdoc->font || !psdoc->font->metrics) {				ps_error(psdoc, PS_RuntimeError, _("RightMarginKerning cannot be set without setting a font before."));				return;			}			ai = gfindadobe(psdoc->font->metrics->gadobechars, res);			if(ai)				ai->rkern = atoi(filename);		} else if(strcmp(name, "LeftMarginKerning") == 0) {			ADOBEINFO *ai;			if(!psdoc->font || !psdoc->font->metrics) {				ps_error(psdoc, PS_RuntimeError, _("LeftMarginKerning cannot be set without setting a font before."));				return;			}			ai = gfindadobe(psdoc->font->metrics->gadobechars, res);			if(ai)				ai->lkern = atoi(filename);		} else {			if(NULL == ps_add_resource(psdoc, name, res, filename, NULL)) {				ps_error(psdoc, PS_RuntimeError, _("Resource '%s' in category '%s' could not be registered."), res, name);			}		}		psdoc->free(psdoc, res);	} else if(strcmp(name, "SearchPath") == 0) {		if(NULL == ps_add_resource(psdoc, name, NULL, value, NULL)) {			ps_error(psdoc, PS_RuntimeError, _("Resource in category '%s' could not be registered."), name);		}	} else if(strcmp(name, "underline") == 0) {		if(strcmp(value, "true") == 0) {			psdoc->underline = ps_true;		} else {			psdoc->underline = ps_false;		}	} else if(strcmp(name, "overline") == 0) {		if(strcmp(value, "true") == 0) {			psdoc->overline = ps_true;		} else {			psdoc->overline = ps_false;		}	} else if(strcmp(name, "strikeout") == 0) {		if(strcmp(value, "true") == 0) {			psdoc->strikeout = ps_true;		} else {			psdoc->strikeout = ps_false;		}	} else if(strcmp(name, "warning") == 0) {		if(strcmp(value, "true") == 0) {			psdoc->warnings = ps_true;		} else {			psdoc->warnings = ps_false;		}	} else if(strcmp(name, "hyphendict") == 0) {		if((psdoc->hdict != NULL) && strcmp(value, psdoc->hdictfilename)) {			hnj_hyphen_free(psdoc->hdict);			psdoc->free(psdoc, psdoc->hdictfilename);		}		psdoc->hdict = hnj_hyphen_load(value);		if(!psdoc->hdict) {			ps_error(psdoc, PS_RuntimeError, _("Could not load hyphenation table '%s', turning hyphenation off."), value);			return;		} 		psdoc->hdictfilename = ps_strdup(psdoc, value);	} else if(strcmp(name, "inputencoding") == 0) {		ENCODING *enc;		if(NULL != (enc = ps_get_inputencoding(value))) {			psdoc->inputenc = enc;		} else {			ps_error(psdoc, PS_Warning, _("Input encoding '%s' could not be set."), value);		}		if(strcmp(value, "true") == 0) {			psdoc->warnings = ps_true;		} else {			psdoc->warnings = ps_false;		}	} else {		PS_PARAMETER *parameter;		/* Check if parameter already exists. If yes, reset it */		for(parameter = dlst_first(psdoc->parameters); parameter != NULL; parameter = dlst_next(parameter)) {			if (0 == strcmp(parameter->name, name)) {				psdoc->free(psdoc, parameter->value);				parameter->value = ps_strdup(psdoc, value);				return;			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -