diff --git a/cmake/modules/FindLibSpectre.cmake b/cmake/modules/FindLibSpectre.cmake new file mode 100644 index 000000000..8dcdacb1a --- /dev/null +++ b/cmake/modules/FindLibSpectre.cmake @@ -0,0 +1,62 @@ +# - Try to find the libspectre PS library +# Once done this will define +# +# LIBSPECTRE_FOUND - system has libspectre +# LIBSPECTRE_INCLUDE_DIR - the libspectre include directory +# LIBSPECTRE_LIBRARY - Link this to use libspectre +# + +# Copyright (c) 2006-2007, Pino Toscano, +# Copyright (c) 2008, Albert Astals Cid, +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +if(LIBSPECTRE_INCLUDE_DIR AND LIBSPECTRE_LIBRARY) + + # in cache already + set(LIBSPECTRE_FOUND TRUE) + +else(LIBSPECTRE_INCLUDE_DIR AND LIBSPECTRE_LIBRARY) + +# use pkg-config to get the directories and then use these values +# in the FIND_PATH() and FIND_LIBRARY() calls +INCLUDE(UsePkgConfig) + +PKGCONFIG(libspectre _SpectreIncDir _SpectreLinkDir _SpectreLinkFlags _SpectreCflags) + +if(_SpectreLinkFlags) + # find again pkg-config, to query it about libspectre version + FIND_PROGRAM(PKGCONFIG_EXECUTABLE NAMES pkg-config PATHS /usr/bin/ /usr/local/bin ) + + # query pkg-config asking for a libspectre >= LIBSPECTRE_MINIMUM_VERSION + EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS --atleast-version=${LIBSPECTRE_MINIMUM_VERSION} libspectre RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull ) + if(_return_VALUE STREQUAL "0") + set(LIBSPECTRE_FOUND TRUE) + endif(_return_VALUE STREQUAL "0") +endif(_SpectreLinkFlags) + +if (LIBSPECTRE_FOUND) + set(LIBSPECTRE_LIBRARY ${_SpectreLinkFlags}) + + # the cflags for libspectre can contain more than one include path + separate_arguments(_SpectreCflags) + foreach(_includedir ${_SpectreCflags}) + string(REGEX REPLACE "-I(.+)" "\\1" _includedir "${_includedir}") + set(LIBSPECTRE_INCLUDE_DIR ${LIBSPECTRE_INCLUDE_DIR} ${_includedir}) + endforeach(_includedir) + + set(CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_LIBRARIES) +else (LIBSPECTRE_FOUND) + if (LIBSPECTRE_FIND_REQUIRED) + message(FATAL_ERROR "Could NOT find libspectre") + endif (LIBSPECTRE_FIND_REQUIRED) + message(STATUS "Could not find OPTIONAL package libspectre") +endif (LIBSPECTRE_FOUND) + +# ensure that they are cached +set(LIBSPECTRE_INCLUDE_DIR ${LIBSPECTRE_INCLUDE_DIR} CACHE INTERNAL "The libspectre include path") +set(LIBSPECTRE_LIBRARY ${LIBSPECTRE_LIBRARY} CACHE INTERNAL "The libspectre library") + +endif(LIBSPECTRE_INCLUDE_DIR AND LIBSPECTRE_LIBRARY) diff --git a/generators/CMakeLists.txt b/generators/CMakeLists.txt index 85eb7a5ef..72731d440 100644 --- a/generators/CMakeLists.txt +++ b/generators/CMakeLists.txt @@ -1,12 +1,12 @@ include (MacroLogFeature) -set(LIBGS_MINIMUM_VERSION "8.56") +set(LIBSPECTRE_MINIMUM_VERSION "0.2") macro_optional_find_package(Poppler) macro_log_feature(POPPLER_FOUND "Poppler-Qt4" "A PDF rendering library" "http://poppler.freedesktop.org" FALSE "0.5.4" "Support for PDF files in okular.") -macro_optional_find_package(LIBGS) -macro_log_feature(LIBGS_FOUND "libgs, Ghostscript libraries" "A PostScript renderining library" "http://www.cs.wisc.edu/~ghost" FALSE "${LIBGS_MINIMUM_VERSION}" "Support for PS files in okular.") +macro_optional_find_package(LibSpectre) +macro_log_feature(LIBSPECTRE_FOUND "libspectre" "A PostScript rendering library" "http://libspectre.freedesktop.org/wiki/" FALSE "${LIBSPECTRE_MINIMUM_VERSION}" "Support for PS files in okular.") macro_optional_find_package(CHM) macro_log_feature(CHM_FOUND "CHM" "A library for dealing with Microsoft ITSS/CHM format files" "http://www.jedrea.com/chmlib" FALSE "" "Support CHM files in okular.") @@ -30,9 +30,9 @@ if(POPPLER_FOUND) add_subdirectory(poppler) endif(POPPLER_FOUND) -if(LIBGS_FOUND) +if(LIBSPECTRE_FOUND) add_subdirectory(spectre) -endif(LIBGS_FOUND) +endif(LIBSPECTRE_FOUND) add_subdirectory( kimgio ) diff --git a/generators/spectre/libspectre/CMakeLists.txt b/generators/spectre/libspectre/CMakeLists.txt deleted file mode 100644 index ce384a813..000000000 --- a/generators/spectre/libspectre/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/.. - ${CMAKE_CURRENT_BINARY_DIR}/.. -) - -set(spectreOkular_SRCS - ps.c - spectre-device.c - spectre-document.c - spectre-exporter.c - spectre-exporter-pdf.c - spectre-exporter-ps.c - spectre-gs.c - spectre-page.c - spectre-render-context.c - spectre-status.c - spectre-utils.c -) - -kde4_add_library(spectreOkular SHARED ${spectreOkular_SRCS}) - -target_link_libraries(spectreOkular ${LIBGS_LIBRARY} ) - -set_target_properties(spectreOkular PROPERTIES VERSION 1.0.0 SOVERSION 1 ) - -install(TARGETS spectreOkular DESTINATION ${LIB_INSTALL_DIR}) diff --git a/generators/spectre/libspectre/ghostscript/LICENSE b/generators/spectre/libspectre/ghostscript/LICENSE deleted file mode 100644 index ba994da70..000000000 --- a/generators/spectre/libspectre/ghostscript/LICENSE +++ /dev/null @@ -1,53 +0,0 @@ - - The files in the src, lib, toolbin, examples, doc and man - directories (folders) and any subdirectories (sub-folders) - thereof are part of GPL Ghostscript. - - The files in the Resource directory and any subdirectories thereof - are also part of GPL Ghostscript, with the explicit exception of - the files in the CMap subdirectory. The CMap files are copyright - Adobe Systems Incorporated and covered by a separate license - which permits only verbatim distribution. - - GPL Ghostscript is free software; you can redistribute it and/or - modify it under the terms of version 2 of the GNU General Public - License as published by the Free Software Foundation. - - GPL Ghostscript 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 - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program so you can know your rights and responsibilities. - It should be in a file named doc/COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place Fifth Floor, Boston, MA - 02110-1301, USA. - - --- - - GPL Ghostscript contains an implementation of techniques covered - by US Patents 5,055,942 and 5,917,614, and corresponding - international patents. These patents are licensed for use with - GPL Ghostscript under the following grant: - - Whereas, Raph Levien (hereinafter "Inventor") has obtained patent - protection for related technology (hereinafter "Patented - Technology"), Inventor wishes to aid the the GNU free software - project in achieving its goals, and Inventor also wishes to - increase public awareness of Patented Technology, Inventor hereby - grants a fully paid up, nonexclusive, royalty free license to - practice the patents listed below ("the Patents") if and only if - practiced in conjunction with software distributed under the - terms of any version of the GNU General Public License as - published by the Free Software Foundation, 51 Franklin Street, Suite - 330, Boston, MA 02111. Inventor reserves all other rights, - including without limitation, licensing for software not - distributed under the GNU General Public License. - - 5055942 Photographic image reproduction device using digital - halftoning to screen images allowing adjustable coarseness - - 5917614 Method and apparatus for error diffusion screening of - images with improved smoothness in highlight and shadow - regions diff --git a/generators/spectre/libspectre/ghostscript/gdevdsp.h b/generators/spectre/libspectre/ghostscript/gdevdsp.h deleted file mode 100644 index 8273fd0b2..000000000 --- a/generators/spectre/libspectre/ghostscript/gdevdsp.h +++ /dev/null @@ -1,266 +0,0 @@ -/* Copyright (C) 2001-2006 Artifex Software, Inc. - All Rights Reserved. - - This software is provided AS-IS with no warranty, either express or - implied. - - 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., 7 Mt. Lassen Drive - Suite A-134, - San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information. -*/ -/* $Id$ */ -/* gdevdsp.h - callback structure for DLL based display device */ - -#ifndef gdevdsp_INCLUDED -# define gdevdsp_INCLUDED - -/* - * The callback structure must be provided by calling the - * Ghostscript APIs in the following order: - * gsapi_new_instance(&minst); - * gsapi_set_display_callback(minst, callback); - * gsapi_init_with_args(minst, argc, argv); - * - * Supported parameters and default values are: - * -sDisplayHandle=16#04d2 or 1234 string - * Caller supplied handle as a decimal or hexadecimal number - * in a string. On 32-bit platforms, it may be set - * using -dDisplayHandle=1234 for backward compatibility. - * Included as first parameter of all callback functions. - * - * -dDisplayFormat=0 long - * Color format specified using bitfields below. - * Included as argument of display_size() and display_presize() - * These can only be changed when the device is closed. - * - * The second parameter of all callback functions "void *device" - * is the address of the Ghostscript display device instance. - * The arguments "void *handle" and "void *device" together - * uniquely identify an instance of the display device. - * - * A typical sequence of callbacks would be - * open, presize, memalloc, size, sync, page - * presize, memfree, memalloc, size, sync, page - * preclose, memfree, close - * The caller should not access the image buffer: - * - before the first sync - * - between presize and size - * - after preclose - * If opening the device fails, you might see the following: - * open, presize, memalloc, memfree, close - * - */ - -#define DISPLAY_VERSION_MAJOR 2 -#define DISPLAY_VERSION_MINOR 0 - -#define DISPLAY_VERSION_MAJOR_V1 1 /* before separation format was added */ -#define DISPLAY_VERSION_MINOR_V1 0 - -/* The display format is set by a combination of the following bitfields */ - -/* Define the color space alternatives */ -typedef enum { - DISPLAY_COLORS_NATIVE = (1<<0), - DISPLAY_COLORS_GRAY = (1<<1), - DISPLAY_COLORS_RGB = (1<<2), - DISPLAY_COLORS_CMYK = (1<<3), - DISPLAY_COLORS_SEPARATION = (1<<19) -} DISPLAY_FORMAT_COLOR; -#define DISPLAY_COLORS_MASK 0x8000fL - -/* Define whether alpha information, or an extra unused bytes is included */ -/* DISPLAY_ALPHA_FIRST and DISPLAY_ALPHA_LAST are not implemented */ -typedef enum { - DISPLAY_ALPHA_NONE = (0<<4), - DISPLAY_ALPHA_FIRST = (1<<4), - DISPLAY_ALPHA_LAST = (1<<5), - DISPLAY_UNUSED_FIRST = (1<<6), /* e.g. Mac xRGB */ - DISPLAY_UNUSED_LAST = (1<<7) /* e.g. Windows BGRx */ -} DISPLAY_FORMAT_ALPHA; -#define DISPLAY_ALPHA_MASK 0x00f0L - -/* Define the depth per component for DISPLAY_COLORS_GRAY, - * DISPLAY_COLORS_RGB and DISPLAY_COLORS_CMYK, - * or the depth per pixel for DISPLAY_COLORS_NATIVE - * DISPLAY_DEPTH_2 and DISPLAY_DEPTH_12 have not been tested. - */ -typedef enum { - DISPLAY_DEPTH_1 = (1<<8), - DISPLAY_DEPTH_2 = (1<<9), - DISPLAY_DEPTH_4 = (1<<10), - DISPLAY_DEPTH_8 = (1<<11), - DISPLAY_DEPTH_12 = (1<<12), - DISPLAY_DEPTH_16 = (1<<13) - /* unused (1<<14) */ - /* unused (1<<15) */ -} DISPLAY_FORMAT_DEPTH; -#define DISPLAY_DEPTH_MASK 0xff00L - - -/* Define whether Red/Cyan should come first, - * or whether Blue/Black should come first - */ -typedef enum { - DISPLAY_BIGENDIAN = (0<<16), /* Red/Cyan first */ - DISPLAY_LITTLEENDIAN = (1<<16) /* Blue/Black first */ -} DISPLAY_FORMAT_ENDIAN; -#define DISPLAY_ENDIAN_MASK 0x00010000L - -/* Define whether the raster starts at the top or bottom of the bitmap */ -typedef enum { - DISPLAY_TOPFIRST = (0<<17), /* Unix, Mac */ - DISPLAY_BOTTOMFIRST = (1<<17) /* Windows */ -} DISPLAY_FORMAT_FIRSTROW; -#define DISPLAY_FIRSTROW_MASK 0x00020000L - - -/* Define whether packing RGB in 16-bits should use 555 - * or 565 (extra bit for green) - */ -typedef enum { - DISPLAY_NATIVE_555 = (0<<18), - DISPLAY_NATIVE_565 = (1<<18) -} DISPLAY_FORMAT_555; -#define DISPLAY_555_MASK 0x00040000L - -/* Define the row alignment, which must be equal to or greater than - * the size of a pointer. - * The default (DISPLAY_ROW_ALIGN_DEFAULT) is the size of a pointer, - * 4 bytes (DISPLAY_ROW_ALIGN_4) on 32-bit systems or 8 bytes - * (DISPLAY_ROW_ALIGN_8) on 64-bit systems. - */ -typedef enum { - DISPLAY_ROW_ALIGN_DEFAULT = (0<<20), - /* DISPLAY_ROW_ALIGN_1 = (1<<20), */ /* not currently possible */ - /* DISPLAY_ROW_ALIGN_2 = (2<<20), */ /* not currently possible */ - DISPLAY_ROW_ALIGN_4 = (3<<20), - DISPLAY_ROW_ALIGN_8 = (4<<20), - DISPLAY_ROW_ALIGN_16 = (5<<20), - DISPLAY_ROW_ALIGN_32 = (6<<20), - DISPLAY_ROW_ALIGN_64 = (7<<20) -} DISPLAY_FORMAT_ROW_ALIGN; -#define DISPLAY_ROW_ALIGN_MASK 0x00700000L - - -#ifndef display_callback_DEFINED -#define display_callback_DEFINED -typedef struct display_callback_s display_callback; -#endif - -/* - * Note that for Windows, the display callback functions are - * cdecl, not stdcall. This differs from those in iapi.h. - */ - -struct display_callback_s { - /* Size of this structure */ - /* Used for checking if we have been handed a valid structure */ - int size; - - /* Major version of this structure */ - /* The major version number will change if this structure changes. */ - int version_major; - - /* Minor version of this structure */ - /* The minor version number will change if new features are added - * without changes to this structure. For example, a new color - * format. - */ - int version_minor; - - /* New device has been opened */ - /* This is the first event from this device. */ - int (*display_open)(void *handle, void *device); - - /* Device is about to be closed. */ - /* Device will not be closed until this function returns. */ - int (*display_preclose)(void *handle, void *device); - - /* Device has been closed. */ - /* This is the last event from this device. */ - int (*display_close)(void *handle, void *device); - - /* Device is about to be resized. */ - /* Resize will only occur if this function returns 0. */ - /* raster is byte count of a row. */ - int (*display_presize)(void *handle, void *device, - int width, int height, int raster, unsigned int format); - - /* Device has been resized. */ - /* New pointer to raster returned in pimage */ - int (*display_size)(void *handle, void *device, int width, int height, - int raster, unsigned int format, unsigned char *pimage); - - /* flushpage */ - int (*display_sync)(void *handle, void *device); - - /* showpage */ - /* If you want to pause on showpage, then don't return immediately */ - int (*display_page)(void *handle, void *device, int copies, int flush); - - /* Notify the caller whenever a portion of the raster is updated. */ - /* This can be used for cooperative multitasking or for - * progressive update of the display. - * This function pointer may be set to NULL if not required. - */ - int (*display_update)(void *handle, void *device, int x, int y, - int w, int h); - - /* Allocate memory for bitmap */ - /* This is provided in case you need to create memory in a special - * way, e.g. shared. If this is NULL, the Ghostscript memory device - * allocates the bitmap. This will only called to allocate the - * image buffer. The first row will be placed at the address - * returned by display_memalloc. - */ - void *(*display_memalloc)(void *handle, void *device, unsigned long size); - - /* Free memory for bitmap */ - /* If this is NULL, the Ghostscript memory device will free the bitmap */ - int (*display_memfree)(void *handle, void *device, void *mem); - - /* Added in V2 */ - /* When using separation color space (DISPLAY_COLORS_SEPARATION), - * give a mapping for one separation component. - * This is called for each new component found. - * It may be called multiple times for each component. - * It may be called at any time between display_size - * and display_close. - * The client uses this to map from the separations to CMYK - * and hence to RGB for display. - * GS must only use this callback if version_major >= 2. - * The unsigned short c,m,y,k values are 65535 = 1.0. - * This function pointer may be set to NULL if not required. - */ - int (*display_separation)(void *handle, void *device, - int component, const char *component_name, - unsigned short c, unsigned short m, - unsigned short y, unsigned short k); -}; - -/* This is the V1 structure, before separation format was added */ -struct display_callback_v1_s { - int size; - int version_major; - int version_minor; - int (*display_open)(void *handle, void *device); - int (*display_preclose)(void *handle, void *device); - int (*display_close)(void *handle, void *device); - int (*display_presize)(void *handle, void *device, - int width, int height, int raster, unsigned int format); - int (*display_size)(void *handle, void *device, int width, int height, - int raster, unsigned int format, unsigned char *pimage); - int (*display_sync)(void *handle, void *device); - int (*display_page)(void *handle, void *device, int copies, int flush); - int (*display_update)(void *handle, void *device, int x, int y, - int w, int h); - void *(*display_memalloc)(void *handle, void *device, unsigned long size); - int (*display_memfree)(void *handle, void *device, void *mem); -}; - -#define DISPLAY_CALLBACK_V1_SIZEOF sizeof(struct display_callback_v1_s) - -#endif /* gdevdsp_INCLUDED */ diff --git a/generators/spectre/libspectre/ghostscript/iapi.h b/generators/spectre/libspectre/ghostscript/iapi.h deleted file mode 100644 index a82aad3aa..000000000 --- a/generators/spectre/libspectre/ghostscript/iapi.h +++ /dev/null @@ -1,300 +0,0 @@ -/* Copyright (C) 2001-2006 Artifex Software, Inc. - All Rights Reserved. - - This software is provided AS-IS with no warranty, either express or - implied. - - 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., 7 Mt. Lassen Drive - Suite A-134, - San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information. -*/ - -/* $Id$ */ - -/* - * Public API for Ghostscript interpreter - * for use both as DLL and for static linking. - * - * Should work for Windows, OS/2, Linux, Mac. - * - * DLL exported functions should be as similar as possible to imain.c - * You will need to include "ierrors.h". - * - * Current problems: - * 1. Ghostscript does not support multiple instances. - * 2. Global variables in gs_main_instance_default() - * and gsapi_instance_counter - */ - -/* Exported functions may need different prefix - * GSDLLEXPORT marks functions as exported - * GSDLLAPI is the calling convention used on functions exported - * by Ghostscript - * GSDLLCALL is used on callback functions called by Ghostscript - * When you include this header file in the caller, you may - * need to change the definitions by defining these - * before including this header file. - * Make sure you get the calling convention correct, otherwise your - * program will crash either during callbacks or soon after returning - * due to stack corruption. - */ - -#ifndef iapi_INCLUDED -# define iapi_INCLUDED - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(_WINDOWS_) || defined(__WINDOWS__) -# ifndef _Windows -# define _Windows -# endif -#endif - -#ifdef _Windows -# ifndef GSDLLEXPORT -# define GSDLLEXPORT __declspec(dllexport) -# endif -# ifndef GSDLLAPI -# define GSDLLAPI __stdcall -# endif -# ifndef GSDLLCALL -# define GSDLLCALL __stdcall -# endif -#endif /* _Windows */ - -#if defined(OS2) && defined(__IBMC__) -# ifndef GSDLLAPI -# define GSDLLAPI _System -# endif -# ifndef GSDLLCALL -# define GSDLLCALL _System -# endif -#endif /* OS2 && __IBMC */ - -#ifdef __MACOS__ -# pragma export on -#endif - -#ifndef GSDLLEXPORT -# define GSDLLEXPORT -#endif -#ifndef GSDLLAPI -# define GSDLLAPI -#endif -#ifndef GSDLLCALL -# define GSDLLCALL -#endif - -#if defined(__IBMC__) -# define GSDLLAPIPTR * GSDLLAPI -# define GSDLLCALLPTR * GSDLLCALL -#else -# define GSDLLAPIPTR GSDLLAPI * -# define GSDLLCALLPTR GSDLLCALL * -#endif - -#ifndef display_callback_DEFINED -# define display_callback_DEFINED -typedef struct display_callback_s display_callback; -#endif - -typedef struct gsapi_revision_s { - const char *product; - const char *copyright; - long revision; - long revisiondate; -} gsapi_revision_t; - - -/* Get version numbers and strings. - * This is safe to call at any time. - * You should call this first to make sure that the correct version - * of the Ghostscript is being used. - * pr is a pointer to a revision structure. - * len is the size of this structure in bytes. - * Returns 0 if OK, or if len too small (additional parameters - * have been added to the structure) it will return the required - * size of the structure. - */ -GSDLLEXPORT int GSDLLAPI -gsapi_revision(gsapi_revision_t *pr, int len); - -/* - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - * Ghostscript supports only one instance. - * The current implementation uses a global static instance - * counter to make sure that only a single instance is used. - * If you try to create two instances, the second attempt - * will return < 0 and set pinstance to NULL. - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - */ -/* Create a new instance of Ghostscript. - * This instance is passed to most other API functions. - * The caller_handle will be provided to callback functions. - */ - -GSDLLEXPORT int GSDLLAPI -gsapi_new_instance(void **pinstance, void *caller_handle); - -/* - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - * Ghostscript supports only one instance. - * The current implementation uses a global static instance - * counter to make sure that only a single instance is used. - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - */ -/* Destroy an instance of Ghostscript - * Before you call this, Ghostscript must have finished. - * If Ghostscript has been initialised, you must call gsapi_exit() - * before gsapi_delete_instance. - */ -GSDLLEXPORT void GSDLLAPI -gsapi_delete_instance(void *instance); - -/* Set the callback functions for stdio - * The stdin callback function should return the number of - * characters read, 0 for EOF, or -1 for error. - * The stdout and stderr callback functions should return - * the number of characters written. - * If a callback address is NULL, the real stdio will be used. - */ -GSDLLEXPORT int GSDLLAPI -gsapi_set_stdio(void *instance, - int (GSDLLCALLPTR stdin_fn)(void *caller_handle, char *buf, int len), - int (GSDLLCALLPTR stdout_fn)(void *caller_handle, const char *str, int len), - int (GSDLLCALLPTR stderr_fn)(void *caller_handle, const char *str, int len)); - -/* Set the callback function for polling. - * This is used for handling window events or cooperative - * multitasking. This function will only be called if - * Ghostscript was compiled with CHECK_INTERRUPTS - * as described in gpcheck.h. - * The polling function should return 0 if all is well, - * and negative if it wants ghostscript to abort. - * The polling function must be fast. - */ -GSDLLEXPORT int GSDLLAPI gsapi_set_poll(void *instance, - int (GSDLLCALLPTR poll_fn)(void *caller_handle)); - -/* Set the display device callback structure. - * If the display device is used, this must be called - * after gsapi_new_instance() and before gsapi_init_with_args(). - * See gdevdisp.h for more details. - */ -GSDLLEXPORT int GSDLLAPI gsapi_set_display_callback( - void *instance, display_callback *callback); - - -/* Initialise the interpreter. - * This calls gs_main_init_with_args() in imainarg.c - * 1. If quit or EOF occur during gsapi_init_with_args(), - * the return value will be e_Quit. This is not an error. - * You must call gsapi_exit() and must not call any other - * gsapi_XXX functions. - * 2. If usage info should be displayed, the return value will be e_Info - * which is not an error. Do not call gsapi_exit(). - * 3. Under normal conditions this returns 0. You would then - * call one or more gsapi_run_*() functions and then finish - * with gsapi_exit(). - */ -GSDLLEXPORT int GSDLLAPI gsapi_init_with_args(void *instance, - int argc, char **argv); - -/* - * The gsapi_run_* functions are like gs_main_run_* except - * that the error_object is omitted. - * If these functions return <= -100, either quit or a fatal - * error has occured. You then call gsapi_exit() next. - * The only exception is gsapi_run_string_continue() - * which will return e_NeedInput if all is well. - */ - -GSDLLEXPORT int GSDLLAPI -gsapi_run_string_begin(void *instance, - int user_errors, int *pexit_code); - -GSDLLEXPORT int GSDLLAPI -gsapi_run_string_continue(void *instance, - const char *str, unsigned int length, int user_errors, int *pexit_code); - -GSDLLEXPORT int GSDLLAPI -gsapi_run_string_end(void *instance, - int user_errors, int *pexit_code); - -GSDLLEXPORT int GSDLLAPI -gsapi_run_string_with_length(void *instance, - const char *str, unsigned int length, int user_errors, int *pexit_code); - -GSDLLEXPORT int GSDLLAPI -gsapi_run_string(void *instance, - const char *str, int user_errors, int *pexit_code); - -GSDLLEXPORT int GSDLLAPI -gsapi_run_file(void *instance, - const char *file_name, int user_errors, int *pexit_code); - - -/* Exit the interpreter. - * This must be called on shutdown if gsapi_init_with_args() - * has been called, and just before gsapi_delete_instance(). - */ -GSDLLEXPORT int GSDLLAPI -gsapi_exit(void *instance); - -/* Visual Tracer */ -/* This function is only for debug purpose clients */ -struct vd_trace_interface_s; -GSDLLEXPORT void GSDLLAPI -gsapi_set_visual_tracer(struct vd_trace_interface_s *I); - - -/* function prototypes */ -typedef int (GSDLLAPIPTR PFN_gsapi_revision)( - gsapi_revision_t *pr, int len); -typedef int (GSDLLAPIPTR PFN_gsapi_new_instance)( - void **pinstance, void *caller_handle); -typedef void (GSDLLAPIPTR PFN_gsapi_delete_instance)( - void *instance); -typedef int (GSDLLAPIPTR PFN_gsapi_set_stdio)(void *instance, - int (GSDLLCALLPTR stdin_fn)(void *caller_handle, char *buf, int len), - int (GSDLLCALLPTR stdout_fn)(void *caller_handle, const char *str, int len), - int (GSDLLCALLPTR stderr_fn)(void *caller_handle, const char *str, int len)); -typedef int (GSDLLAPIPTR PFN_gsapi_set_poll)(void *instance, - int(GSDLLCALLPTR poll_fn)(void *caller_handle)); -typedef int (GSDLLAPIPTR PFN_gsapi_set_display_callback)( - void *instance, display_callback *callback); -typedef int (GSDLLAPIPTR PFN_gsapi_init_with_args)( - void *instance, int argc, char **argv); -typedef int (GSDLLAPIPTR PFN_gsapi_run_string_begin)( - void *instance, int user_errors, int *pexit_code); -typedef int (GSDLLAPIPTR PFN_gsapi_run_string_continue)( - void *instance, const char *str, unsigned int length, - int user_errors, int *pexit_code); -typedef int (GSDLLAPIPTR PFN_gsapi_run_string_end)( - void *instance, int user_errors, int *pexit_code); -typedef int (GSDLLAPIPTR PFN_gsapi_run_string_with_length)( - void *instance, const char *str, unsigned int length, - int user_errors, int *pexit_code); -typedef int (GSDLLAPIPTR PFN_gsapi_run_string)( - void *instance, const char *str, - int user_errors, int *pexit_code); -typedef int (GSDLLAPIPTR PFN_gsapi_run_file)(void *instance, - const char *file_name, int user_errors, int *pexit_code); -typedef int (GSDLLAPIPTR PFN_gsapi_exit)(void *instance); -typedef void (GSDLLAPIPTR PFN_gsapi_set_visual_tracer) - (struct vd_trace_interface_s *I); - - -#ifdef __MACOS__ -#pragma export off -#endif - -#ifdef __cplusplus -} /* extern 'C' protection */ -#endif - -#endif /* iapi_INCLUDED */ diff --git a/generators/spectre/libspectre/ghostscript/ierrors.h b/generators/spectre/libspectre/ghostscript/ierrors.h deleted file mode 100644 index 083028b8d..000000000 --- a/generators/spectre/libspectre/ghostscript/ierrors.h +++ /dev/null @@ -1,153 +0,0 @@ -/* Copyright (C) 2001-2006 Artifex Software, Inc. - All Rights Reserved. - - This software is provided AS-IS with no warranty, either express or - implied. - - 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., 7 Mt. Lassen Drive - Suite A-134, - San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information. -*/ - -/* $Id$ */ -/* Definition of error codes */ - -#ifndef ierrors_INCLUDED -# define ierrors_INCLUDED - -/* - * DO NOT USE THIS FILE IN THE GRAPHICS LIBRARY. - * THIS FILE IS PART OF THE POSTSCRIPT INTERPRETER. - * USE gserrors.h IN THE LIBRARY. - */ - -/* - * A procedure that may return an error always returns - * a non-negative value (zero, unless otherwise noted) for success, - * or negative for failure. - * We use ints rather than an enum to avoid a lot of casting. - */ - -/* Define the error name table */ -extern const char *const gs_error_names[]; - - /* ------ PostScript Level 1 errors ------ */ - -#define e_unknownerror (-1) /* unknown error */ -#define e_dictfull (-2) -#define e_dictstackoverflow (-3) -#define e_dictstackunderflow (-4) -#define e_execstackoverflow (-5) -#define e_interrupt (-6) -#define e_invalidaccess (-7) -#define e_invalidexit (-8) -#define e_invalidfileaccess (-9) -#define e_invalidfont (-10) -#define e_invalidrestore (-11) -#define e_ioerror (-12) -#define e_limitcheck (-13) -#define e_nocurrentpoint (-14) -#define e_rangecheck (-15) -#define e_stackoverflow (-16) -#define e_stackunderflow (-17) -#define e_syntaxerror (-18) -#define e_timeout (-19) -#define e_typecheck (-20) -#define e_undefined (-21) -#define e_undefinedfilename (-22) -#define e_undefinedresult (-23) -#define e_unmatchedmark (-24) -#define e_VMerror (-25) /* must be the last Level 1 error */ - -#define LEVEL1_ERROR_NAMES\ - "unknownerror", "dictfull", "dictstackoverflow", "dictstackunderflow",\ - "execstackoverflow", "interrupt", "invalidaccess", "invalidexit",\ - "invalidfileaccess", "invalidfont", "invalidrestore", "ioerror",\ - "limitcheck", "nocurrentpoint", "rangecheck", "stackoverflow",\ - "stackunderflow", "syntaxerror", "timeout", "typecheck", "undefined",\ - "undefinedfilename", "undefinedresult", "unmatchedmark", "VMerror" - - /* ------ Additional Level 2 errors (also in DPS) ------ */ - -#define e_configurationerror (-26) -#define e_undefinedresource (-27) -#define e_unregistered (-28) - -#define LEVEL2_ERROR_NAMES\ - "configurationerror", "undefinedresource", "unregistered" - - /* ------ Additional DPS errors ------ */ - -#define e_invalidcontext (-29) -/* invalidid is for the NeXT DPS extension. */ -#define e_invalidid (-30) - -#define DPS_ERROR_NAMES\ - "invalidcontext", "invalidid" - -#define ERROR_NAMES\ - LEVEL1_ERROR_NAMES, LEVEL2_ERROR_NAMES, DPS_ERROR_NAMES - - /* ------ Pseudo-errors used internally ------ */ - -/* - * Internal code for a fatal error. - * gs_interpret also returns this for a .quit with a positive exit code. - */ -#define e_Fatal (-100) - -/* - * Internal code for the .quit operator. - * The real quit code is an integer on the operand stack. - * gs_interpret returns this only for a .quit with a zero exit code. - */ -#define e_Quit (-101) - -/* - * Internal code for a normal exit from the interpreter. - * Do not use outside of interp.c. - */ -#define e_InterpreterExit (-102) - -/* - * Internal code that indicates that a procedure has been stored in the - * remap_proc of the graphics state, and should be called before retrying - * the current token. This is used for color remapping involving a call - * back into the interpreter -- inelegant, but effective. - */ -#define e_RemapColor (-103) - -/* - * Internal code to indicate we have underflowed the top block - * of the e-stack. - */ -#define e_ExecStackUnderflow (-104) - -/* - * Internal code for the vmreclaim operator with a positive operand. - * We need to handle this as an error because otherwise the interpreter - * won't reload enough of its state when the operator returns. - */ -#define e_VMreclaim (-105) - -/* - * Internal code for requesting more input from run_string. - */ -#define e_NeedInput (-106) - -/* - * Internal code for a normal exit when usage info is displayed. - * This allows Window versions of Ghostscript to pause until - * the message can be read. - */ -#define e_Info (-110) - -/* - * Define which error codes require re-executing the current object. - */ -#define ERROR_IS_INTERRUPT(ecode)\ - ((ecode) == e_interrupt || (ecode) == e_timeout) - -#endif /* ierrors_INCLUDED */ diff --git a/generators/spectre/libspectre/ps.c b/generators/spectre/libspectre/ps.c deleted file mode 100644 index 098a9e2ec..000000000 --- a/generators/spectre/libspectre/ps.c +++ /dev/null @@ -1,2232 +0,0 @@ -/* - * ps.c -- Postscript scanning and copying routines. - * Copyright (C) 1992 Timothy O. Theisen - * Copyright (C) 2004 Jose E. Marchesi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU gv; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA - * - * Author: Tim Theisen Systems Programmer - * Internet: tim@cs.wisc.edu Department of Computer Sciences - * UUCP: uwvax!tim University of Wisconsin-Madison - * Phone: (608)262-0438 1210 West Dayton Street - * FAX: (608)262-9777 Madison, WI 53706 - * - * Changes submitted by Maurizio Loreti distributed on the public - * domain: - * - * - Code for handle bzip2 compressed files. - */ - -/* - * Added the ps_io_*() routines, rewrote readline(), modified - * pscopyuntil() and pscopydoc() and eliminated pscopy(). - * The modifications mainly aim at - * - elimination of the (line length <= 255) constraint since - * there are just too many documents ignoring this requirement. - * - acceptance of '\r' as line terminator as suggested by - * Martin Buck (martin-2.buck@student.uni-ulm.de). - * Johannes Plass, 04/96 (plass@thep.physik.uni-mainz.de) - * -*/ - -/* - * > Believe it or not--even Adobe doesn't know how to produce correct - * > PS-files. Their Acrobat Reader sometimes starts including other files - * > with %%BeginFile instead of %%BeginFile: and even more often ends them - * > with just %%EOF instead of %%EndFile. - * > Martin Buck, martin-2.buck@student.uni-ulm.de - * - * Therefore we use Martin's ACROREAD_WORKAROUND (thanks for the patch, Martin). - * ###jp### 04/96 - * - */ -#define USE_ACROREAD_WORKAROUND - -#include - -#include -#include - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif -#ifndef BUFSIZ -#define BUFSIZ 1024 -#endif -#include - -#include "spectre-utils.h" - -#include "ps.h" - -#ifdef BSD4_2 -#define memset(a,b,c) bzero(a,c) -#endif - -#define BEGINMESSAGE(txt) -#define ENDMESSAGE(txt) -#define INFMESSAGE(txt) -#define IMESSAGE(it) -#define INFIMESSAGE(txt,it) -#define FMESSAGE(ft) -#define INFFMESSAGE(txt,ft) -#define SMESSAGE(st) -#define INFSMESSAGE(txt,st) -#define IIMESSAGE(it1,it2) -#define INFIIMESSAGE(txt,it1,it2) - -#define PS_malloc(sss) malloc ((size_t)(sss) ) -#define PS_calloc(ccc,sss) calloc ((size_t)(ccc),(size_t)(sss) ) -#define PS_realloc(ppp,sss) realloc ((void*) (ppp),(size_t)(sss) ) -#define PS_free(ppp) free ((void*) (ppp) ) -#define PS_cfree(ppp) cfree ((void*) (ppp) ) -#define PS_XtMalloc(sss) malloc ((size_t)(sss) ) -#define PS_XtRealloc(ppp,sss) realloc ((void*) (ppp),(size_t)(sss) ) -#define PS_XtFree(ppp) free ((void*) (ppp) ) - - -/* We use this helper function for providing proper */ -/* case and colon :-) insensitive DSC matching */ -static int dsc_strncmp(s1, s2, n) - char *s1; - char *s2; - size_t n; -{ - char *tmp; - - if (_spectre_strncasecmp(s1, s2, n) == 0) - return 0; - if (s2[n-1] == ':'){ - tmp = (char *) PS_malloc(n*sizeof(char)); - strncpy(tmp, s2, (n-1)); - tmp[n-1]=' '; - if (_spectre_strncasecmp(s1, tmp, n) == 0){ - PS_free(tmp); - return 0; - } - PS_free(tmp); - } - - return 1; -} - -/* length calculates string length at compile time */ -/* can only be used with character constants */ -#define length(a) (sizeof((a))-1) -#define iscomment(a, b) (dsc_strncmp((a), (b), length((b))) == 0) -#define DSCcomment(a) ((a)[0] == '%' && (a)[1] == '%') - -/* list of standard paper sizes from Adobe's PPD. */ - -static struct documentmedia papersizes[] = { - {"BBox", 0, 0}, - {"Letter", 612, 792}, - {"LetterSmall", 612, 792}, - {"Legal", 612, 1008}, - {"Statement", 396, 612}, - {"Tabloid", 792, 1224}, - {"Ledger", 1224, 792}, - {"Executive", 540, 720}, - {"A0", 2384, 3370}, - {"A1", 1684, 2384}, - {"A2", 1191, 1684}, - {"A3", 842, 1191}, - {"A4", 595, 842}, - {"A4Small", 595, 842}, - {"A5", 420, 595}, - {"B4", 729, 1032}, - {"B5", 516, 729}, - {"Folio", 612, 936}, - {"Quarto", 610, 780}, - {"10x14", 720, 1008}, - { NULL, 0, 0} -}; - -#if NeedFunctionPrototypes -# define PT(aaa) aaa -#else -# define PT(aaa) () -#endif - -typedef enum { - False = 0, - True -} Boolean; - -/*--------------------------------------------------*/ -/* Declarations for ps_io_*() routines. */ - -typedef struct FileDataStruct_ *FileData; - -typedef struct FileDataStruct_ { - FILE *file; /* file */ - int filepos; /* file position corresponding to the start of the line */ - char *buf; /* buffer */ - int buf_size; /* size of buffer */ - int buf_end; /* last char in buffer given as offset to buf */ - int line_begin; /* start of the line given as offset to buf */ - int line_end; /* end of the line given as offset to buf */ - int line_len; /* length of line, i.e. (line_end-line_begin) */ - char line_termchar; /* char exchanged for a '\0' at end of line */ - int status; /* 0 = okay, 1 = failed */ -} FileDataStruct; - -static FileData ps_io_init PT((FILE *)); -static void ps_io_exit PT((FileData)); -static char *ps_io_fgetchars PT((FileData, int)); -static int ps_io_fseek PT((FileData, int)); -static int ps_io_ftell PT((FileData)); - -static char *readline PT((FileData, char **, long *, unsigned int *)); -static char *gettextline PT((char *)); -static char *ps_gettext PT((char *,char **)); -static int blank PT((char *)); -static char *pscopyuntil PT((FileData,FILE *,long,long,char *)); - -static char *skipped_line = "% ps_io_fgetchars: skipped line"; -static char *empty_string = ""; - -/*--------------------------------------------------*/ - -/* - * psscan -- scan the PostScript file for document structuring comments. - * - * This scanner is designed to retrieve the information necessary for - * the ghostview previewer. It will scan files that conform to any - * version (1.0, 2.0, 2.1, or 3.0) of the document structuring conventions. - * It does not really care which version of comments the file contains. - * (The comments are largely upward compatible.) It will scan a number - * of non-conforming documents. (You could have part of the document - * conform to V2.0 and the rest conform to V3.0. It would be similar - * to the DC-2 1/2+, it would look funny but it can still fly.) - * - * This routine returns a pointer to the document structure. - * The structure contains the information relevant to previewing. - * These include EPSF flag (to tell if the file is a encapsulated figure), - * Page Media (for the Page Size), Bounding Box (to minimize backing - * pixmap size or determine window size for encapsulated PostScript), - * Orientation of Paper (for default transformation matrix), and - * Page Order. The title and CreationDate are also retrieved to - * help identify the document. - * - * The following comments are examined: - * - * Header section: - * Must start with %!PS-Adobe-. Version numbers ignored. - * - * %!PS-Adobe-* [EPSF*] (changed EPSF-* to EPSF* to do XFig a favor ...###jp###) - * %%BoundingBox: |(atend) - * %%CreationDate: - * %%Creator: - * %%Orientation: Portrait|Landscape|(atend) - * %%Pages: []|(atend) - * %%PageOrder: Ascend|Descend|Special|(atend) - * %%Title: - * %%DocumentMedia: - * %%DocumentPaperSizes: - * %%EndComments - * - * Note: Either the 3.0 or 2.0 syntax for %%Pages is accepted. - * Also either the 2.0 %%DocumentPaperSizes or the 3.0 - * %%DocumentMedia comments are accepted as well. - * - * The header section ends either explicitly with %%EndComments or - * implicitly with any line that does not begin with %X where X is - * a not whitespace character. - * - * If the file is encapsulated PostScript the optional Preview section - * is next: - * - * %%BeginPreview - * %%EndPreview - * - * This section explicitly begins and ends with the above comments. - * - * Next the Defaults section for version 3 page defaults: - * - * %%BeginDefaults - * %%PageBoundingBox: - * %%PageOrientation: Portrait|Landscape - * %%PageMedia: - * %%EndDefaults - * - * This section explicitly begins and ends with the above comments. - * - * The prolog section either explicitly starts with %%BeginProlog or - * implicitly with any nonblank line. - * - * %%BeginProlog - * %%EndProlog - * - * The Prolog should end with %%EndProlog, however the proglog implicitly - * ends when %%BeginSetup, %%Page, %%Trailer or %%EOF are encountered. - * - * The Setup section is where the version 2 page defaults are found. - * This section either explicitly begins with %%BeginSetup or implicitly - * with any nonblank line after the Prolog. - * - * %%BeginSetup - * %%PageBoundingBox: - * %%PageOrientation: Portrait|Landscape - * %%PaperSize: - * %%EndSetup - * - * The Setup should end with %%EndSetup, however the setup implicitly - * ends when %%Page, %%Trailer or %%EOF are encountered. - * - * Next each page starts explicitly with %%Page and ends implicitly with - * %%Page or %%Trailer or %%EOF. The following comments are recognized: - * - * %%Page: - * %%PageBoundingBox: |(atend) - * %%PageOrientation: Portrait|Landscape - * %%PageMedia: - * %%PaperSize: - * - * The trailer section start explicitly with %%Trailer and end with %%EOF. - * The following comment are examined with the proper (atend) notation - * was used in the header: - * - * %%Trailer - * %%BoundingBox: |(atend) - * %%Orientation: Portrait|Landscape|(atend) - * %%Pages: []|(atend) - * %%PageOrder: Ascend|Descend|Special|(atend) - * %%EOF - * - * - * + A DC-3 received severe damage to one of its wings. The wing was a total - * loss. There was no replacement readily available, so the mechanic - * installed a wing from a DC-2. - */ - -/*-----------------------------------------------------------*/ - -#define CHECK_MALLOCED(aaa) - -/*###########################################################*/ -/* psscan */ -/*###########################################################*/ - -struct document * -psscan(const char *filename, int scanstyle) -{ - struct document *doc; - FILE *file; - int bb_set = NONE; - int pages_set = NONE; - int page_order_set = NONE; - int orientation_set = NONE; - int page_bb_set = NONE; - int page_media_set = NONE; - int preread; /* flag which tells the readline isn't needed */ - int i; - unsigned int maxpages = 0; - unsigned int nextpage = 1; /* Next expected page */ - unsigned int thispage; - int ignore = 0; /* whether to ignore page ordinals */ - char *label; - char *line; - /* 255 characters + 1 newline + 1 NULL */ - char text[PSLINELENGTH]; /* Temporary storage for text */ - long position; /* Position of the current line */ - long beginsection; /* Position of the beginning of the section */ - unsigned int line_len; /* Length of the current line */ - unsigned int section_len; /* Place to accumulate the section length */ - char *next_char; /* 1st char after text returned by ps_gettext() */ - char *cp; - Media dmp; - FileData fd; - int respect_eof; /* Derived from the scanstyle argument. - If set to 0 EOF comments will be ignored, - if set to 1 they will be taken seriously. - Purpose; Out there are many documents which - include other DSC conforming documents without - without enclosing them by 'BeginDocument' and - 'EndDocument' comments. This may cause fake EOF - comments to appear in the body of a page. - Similarly, if respect_eof is set to false - 'Trailer' comments are ignored except of the - last one found in the document. - */ - int ignore_dsc; /* Derived from scanstyle. - If set the document structure will be ignored. - */ - BEGINMESSAGE(psscan) - - respect_eof = (scanstyle & SCANSTYLE_IGNORE_EOF) ? 0 : 1; - ignore_dsc = (scanstyle & SCANSTYLE_IGNORE_DSC) ? 1 : 0; - - if (ignore_dsc) { - INFMESSAGE(ignoring DSC) - ENDMESSAGE(psscan) - return(NULL); - } - - file = fopen (filename, "r"); - if (!file) { - return NULL; - } - - fd = ps_io_init(file); - if (!readline(fd,&line, &position, &line_len)) { - fprintf(stderr, "Warning: empty file.\n"); - ENDMESSAGE(psscan) - ps_io_exit(fd); - fclose (file); - return(NULL); - } - - /* HP printer job language data follows. Some printer drivers add pjl - * commands to switch a pjl printer to postscript mode. If no PS header - * follows, this seems to be a real pjl file. */ - if(iscomment(line, "\033%-12345X@PJL")) { - /* read until first DSC comment */ - while(readline(fd, &line, &position, &line_len) && (line[0] != '%')) ; - if(line[0] != '%') { - fprintf(stderr, "psscan error: input files seems to be a PJL file.\n"); - ENDMESSAGE(psscan) - ps_io_exit(fd); - fclose (file); - return (NULL); - } - } - - /* Header comments */ - - /* Header should start with "%!PS-Adobe-", but some programms omit - * parts of this or add a ^D at the beginning. */ - if ((iscomment(line,"%!PS") || iscomment(line, "\004%!PS"))) { - INFMESSAGE(found "PS-Adobe-" comment) - - doc = (struct document *) PS_malloc(sizeof(struct document)); - CHECK_MALLOCED(doc); - memset(doc, 0, sizeof(struct document)); - - /* ignore possible leading ^D */ - if (*line == '\004') { - position++; - line_len--; - } - - doc->ref_count = 1; - doc->filename = _spectre_strdup (filename); - doc->beginheader = position; - section_len = line_len; - - text[0] = '\0'; - sscanf(line, "%%!%256s %*s", text); - doc->format = _spectre_strdup (text); - - text[0] = '\0'; - sscanf(line, "%*s %256s", text); - doc->epsf = iscomment(text, "EPSF"); - } else { - /* There are postscript documents that do not have - %PS at the beginning, usually unstructured. We should GS decide - For instance, the tech reports at this university: - - http://svrc.it.uq.edu.au/Bibliography/svrc-tr.html?94-45 - - add ugly PostScript before the actual document. - - GS and gv is - able to display them correctly as unstructured PS. - - In a way, this makes sense, a program PostScript does not need - the !PS at the beginning. - */ - doc = (struct document *) PS_malloc(sizeof(struct document)); - CHECK_MALLOCED(doc); - memset(doc, 0, sizeof(struct document)); - doc->ref_count = 1; - doc->filename = _spectre_strdup (filename); - doc->default_page_orientation = NONE; - doc->orientation = NONE; - } - - preread = 0; - while (preread || readline(fd, &line, &position, &line_len)) { - if (!preread) section_len += line_len; - preread = 0; - if (line[0] != '%' || - iscomment(line+1, "%EndComments") || - line[1] == ' ' || line[1] == '\t' || line[1] == '\n' || - !isprint(line[1])) { - break; - } else if (line[1] != '%') { - /* Do nothing */ - } else if (doc->title == NULL && iscomment(line+2, "Title:")) { - doc->title = gettextline(line+length("%%Title:")); - } else if (doc->date == NULL && iscomment(line+2, "CreationDate:")) { - doc->date = gettextline(line+length("%%CreationDate:")); - } else if (doc->languagelevel == NULL && iscomment(line+2, "LanguageLevel:")) { - doc->languagelevel = gettextline(line+length("%%LanguageLevel:")); - } else if(doc->creator == NULL && iscomment(line + 2, "Creator:")) { - doc->creator = gettextline(line + length("%%Creator:")); - } else if(doc->fortext == NULL && iscomment(line + 2, "For:")) { - doc->fortext = gettextline(line + length("%%For:")); - } else if (bb_set == NONE && iscomment(line+2, "BoundingBox:")) { - sscanf(line+length("%%BoundingBox:"), "%256s", text); - if (strcmp(text, "(atend)") == 0) { - bb_set = ATEND; - } else { - if (sscanf(line+length("%%BoundingBox:"), "%d %d %d %d", - &(doc->boundingbox[LLX]), - &(doc->boundingbox[LLY]), - &(doc->boundingbox[URX]), - &(doc->boundingbox[URY])) == 4) - bb_set = 1; - else { - float fllx, flly, furx, fury; - if (sscanf(line+length("%%BoundingBox:"), "%f %f %f %f", - &fllx, &flly, &furx, &fury) == 4) { - bb_set = 1; - doc->boundingbox[LLX] = fllx; - doc->boundingbox[LLY] = flly; - doc->boundingbox[URX] = furx; - doc->boundingbox[URY] = fury; - if (fllx < doc->boundingbox[LLX]) - doc->boundingbox[LLX]--; - if (flly < doc->boundingbox[LLY]) - doc->boundingbox[LLY]--; - if (furx > doc->boundingbox[URX]) - doc->boundingbox[URX]++; - if (fury > doc->boundingbox[URY]) - doc->boundingbox[URY]++; - } - } - } - } else if (orientation_set == NONE && - iscomment(line+2, "Orientation:")) { - sscanf(line+length("%%Orientation:"), "%256s", text); - if (strcmp(text, "(atend)") == 0 || strcmp(text, "atend") == 0) { - orientation_set = ATEND; - } else if (strcmp(text, "Portrait") == 0) { - doc->orientation = PORTRAIT; - orientation_set = 1; - } else if (strcmp(text, "Landscape") == 0) { - doc->orientation = LANDSCAPE; - orientation_set = 1; - } else if (strcmp(text, "Seascape") == 0) { - doc->orientation = SEASCAPE; - orientation_set = 1; - } else if (strcmp(text, "UpsideDown") == 0) { - doc->orientation = UPSIDEDOWN; - orientation_set = 1; - } - } else if (page_order_set == NONE && iscomment(line+2, "PageOrder:")) { - sscanf(line+length("%%PageOrder:"), "%256s", text); - if (strcmp(text, "(atend)") == 0 || strcmp(text, "atend") == 0) { - page_order_set = ATEND; - } else if (strcmp(text, "Ascend") == 0) { - doc->pageorder = ASCEND; - page_order_set = 1; - } else if (strcmp(text, "Descend") == 0) { - doc->pageorder = DESCEND; - page_order_set = 1; - } else if (strcmp(text, "Special") == 0) { - doc->pageorder = SPECIAL; - page_order_set = 1; - } - } else if (pages_set == NONE && iscomment(line+2, "Pages:")) { - sscanf(line+length("%%Pages:"), "%256s", text); - if (strcmp(text, "(atend)") == 0 || strcmp(text, "atend") == 0) { - pages_set = ATEND; - } else { - switch (sscanf(line+length("%%Pages:"), "%d %d", - &maxpages, &i)) { - case 2: - if (page_order_set == NONE) { - if (i == -1) { - doc->pageorder = DESCEND; - page_order_set = 1; - } else if (i == 0) { - doc->pageorder = SPECIAL; - page_order_set = 1; - } else if (i == 1) { - doc->pageorder = ASCEND; - page_order_set = 1; - } - } - case 1: - if (maxpages > 0) { - doc->pages = (struct page *) PS_calloc(maxpages, - sizeof(struct page)); - CHECK_MALLOCED(doc->pages); - } - } - } - } else if (doc->nummedia == NONE && - iscomment(line+2, "DocumentMedia:")) { - float w, h; - doc->media = (Media) - PS_malloc(sizeof (MediaStruct)); - CHECK_MALLOCED(doc->media); - doc->media[0].name = ps_gettext(line+length("%%DocumentMedia:"), - &next_char); - if (doc->media[0].name != NULL) { - if (sscanf(next_char, "%f %f", &w, &h) == 2) { - doc->media[0].width = w + 0.5; - doc->media[0].height = h + 0.5; - } - if (doc->media[0].width != 0 && doc->media[0].height != 0) - doc->nummedia = 1; - else - PS_free(doc->media[0].name); - } - preread=1; - while (readline(fd, &line, &position, &line_len) && - DSCcomment(line) && iscomment(line+2, "+")) { - section_len += line_len; - doc->media = (Media) - PS_realloc(doc->media, - (doc->nummedia+1)* - sizeof (MediaStruct)); - CHECK_MALLOCED(doc->media); - doc->media[doc->nummedia].name = ps_gettext(line+length("%%+"), - &next_char); - if (doc->media[doc->nummedia].name != NULL) { - if (sscanf(next_char, "%f %f", &w, &h) == 2) { - doc->media[doc->nummedia].width = w + 0.5; - doc->media[doc->nummedia].height = h + 0.5; - } - if (doc->media[doc->nummedia].width != 0 && - doc->media[doc->nummedia].height != 0) doc->nummedia++; - else - PS_free(doc->media[doc->nummedia].name); - } - } - section_len += line_len; - if (doc->nummedia != 0) doc->default_page_media = doc->media; - } else if (doc->nummedia == NONE && - iscomment(line+2, "DocumentPaperSizes:")) { - - doc->media = (Media) - PS_malloc(sizeof (MediaStruct)); - CHECK_MALLOCED(doc->media); - doc->media[0].name = ps_gettext(line+length("%%DocumentPaperSizes:"), - &next_char); - if (doc->media[0].name != NULL) { - doc->media[0].width = 0; - doc->media[0].height = 0; - for (i=0; papersizes[i].name; i++) { - dmp = &papersizes[i]; - /* Note: Paper size comment uses down cased paper size - * name. Case insensitive compares are only used for - * PaperSize comments. - */ - if (_spectre_strcasecmp(doc->media[0].name, dmp->name) == 0) { - PS_free(doc->media[0].name); - doc->media[0].name = (char *)PS_malloc(strlen(dmp->name)+1); - CHECK_MALLOCED(doc->media[0].name); - strcpy(doc->media[0].name, dmp->name); - doc->media[0].width = dmp->width; - doc->media[0].height = dmp->height; - break; - } - } - if (doc->media[0].width != 0 && doc->media[0].height != 0) - doc->nummedia = 1; - else - PS_free(doc->media[0].name); - } - while ((cp = ps_gettext(next_char, &next_char))) { - doc->media = (Media) - PS_realloc(doc->media, - (doc->nummedia+1)* - sizeof (MediaStruct)); - CHECK_MALLOCED(doc->media); - doc->media[doc->nummedia].name = cp; - doc->media[doc->nummedia].width = 0; - doc->media[doc->nummedia].height = 0; - for (i=0; papersizes[i].name; i++) { - dmp = &papersizes[i]; - /* Note: Paper size comment uses down cased paper size - * name. Case insensitive compares are only used for - * PaperSize comments. - */ - if (_spectre_strcasecmp(doc->media[doc->nummedia].name, - dmp->name) == 0) { - PS_free(doc->media[doc->nummedia].name); - doc->media[doc->nummedia].name = - (char *)PS_malloc(strlen(dmp->name)+1); - CHECK_MALLOCED(doc->media[doc->nummedia].name); - strcpy(doc->media[doc->nummedia].name, dmp->name); - doc->media[doc->nummedia].width = dmp->width; - doc->media[doc->nummedia].height = dmp->height; - break; - } - } - if (doc->media[doc->nummedia].width != 0 && - doc->media[doc->nummedia].height != 0) doc->nummedia++; - else - PS_free(doc->media[doc->nummedia].name); - } - preread=1; - while (readline(fd, &line, &position, &line_len) && - DSCcomment(line) && iscomment(line+2, "+")) { - section_len += line_len; - next_char = line + length("%%+"); - while ((cp = ps_gettext(next_char, &next_char))) { - doc->media = (Media) - PS_realloc(doc->media, - (doc->nummedia+1)* - sizeof (MediaStruct)); - CHECK_MALLOCED(doc->media); - doc->media[doc->nummedia].name = cp; - doc->media[doc->nummedia].width = 0; - doc->media[doc->nummedia].height = 0; - for (i=0; papersizes[i].name; i++) { - dmp = &papersizes[i]; - /* Note: Paper size comment uses down cased paper size - * name. Case insensitive compares are only used for - * PaperSize comments. - */ - if (_spectre_strcasecmp(doc->media[doc->nummedia].name, - dmp->name) == 0) { - doc->media[doc->nummedia].width = dmp->width; - doc->media[doc->nummedia].height = dmp->height; - break; - } - } - if (doc->media[doc->nummedia].width != 0 && - doc->media[doc->nummedia].height != 0) doc->nummedia++; - else - PS_free(doc->media[doc->nummedia].name); - } - } - section_len += line_len; - if (doc->nummedia != 0) doc->default_page_media = doc->media; - } - } - - if (DSCcomment(line) && iscomment(line+2, "EndComments")) { - readline(fd, &line, &position, &line_len); - section_len += line_len; - } - doc->endheader = position; - doc->lenheader = section_len - line_len; - - /* Optional Preview comments for encapsulated PostScript files */ - - beginsection = position; - section_len = line_len; - while (blank(line) && readline(fd, &line, &position, &line_len)) { - section_len += line_len; - } - - if (doc->epsf && DSCcomment(line) && iscomment(line+2, "BeginPreview")) { - doc->beginpreview = beginsection; - beginsection = 0; - while (readline(fd, &line, &position, &line_len) && - !(DSCcomment(line) && iscomment(line+2, "EndPreview"))) { - section_len += line_len; - } - section_len += line_len; - readline(fd, &line, &position, &line_len); - section_len += line_len; - doc->endpreview = position; - doc->lenpreview = section_len - line_len; - } - - /* Page Defaults for Version 3.0 files */ - - if (beginsection == 0) { - beginsection = position; - section_len = line_len; - } - while (blank(line) && readline(fd, &line, &position, &line_len)) { - section_len += line_len; - } - - if (DSCcomment(line) && iscomment(line+2, "BeginDefaults")) { - doc->begindefaults = beginsection; - beginsection = 0; - while (readline(fd, &line, &position, &line_len) && - !(DSCcomment(line) && iscomment(line+2, "EndDefaults"))) { - section_len += line_len; - if (!DSCcomment(line)) { - /* Do nothing */ - } else if (doc->default_page_orientation == NONE && - iscomment(line+2, "PageOrientation:")) { - sscanf(line+length("%%PageOrientation:"), "%256s", text); - if (strcmp(text, "Portrait") == 0) { - doc->default_page_orientation = PORTRAIT; - } else if (strcmp(text, "Landscape") == 0) { - doc->default_page_orientation = LANDSCAPE; - } else if (strcmp(text, "Seascape") == 0) { - doc->default_page_orientation = SEASCAPE; - } else if (strcmp(text, "UpsideDown") == 0) { - doc->default_page_orientation = UPSIDEDOWN; - } - } else if (page_media_set == NONE && - iscomment(line+2, "PageMedia:")) { - cp = ps_gettext(line+length("%%PageMedia:"), NULL); - for (dmp = doc->media, i=0; inummedia; i++, dmp++) { - if (strcmp(cp, dmp->name) == 0) { - doc->default_page_media = dmp; - page_media_set = 1; - break; - } - } - PS_free(cp); - } else if (page_bb_set == NONE && - iscomment(line+2, "PageBoundingBox:")) { - if (sscanf(line+length("%%PageBoundingBox:"), "%d %d %d %d", - &(doc->default_page_boundingbox[LLX]), - &(doc->default_page_boundingbox[LLY]), - &(doc->default_page_boundingbox[URX]), - &(doc->default_page_boundingbox[URY])) == 4) - page_bb_set = 1; - else { - float fllx, flly, furx, fury; - if (sscanf(line+length("%%PageBoundingBox:"), "%f %f %f %f", - &fllx, &flly, &furx, &fury) == 4) { - page_bb_set = 1; - doc->default_page_boundingbox[LLX] = fllx; - doc->default_page_boundingbox[LLY] = flly; - doc->default_page_boundingbox[URX] = furx; - doc->default_page_boundingbox[URY] = fury; - if (fllx < doc->default_page_boundingbox[LLX]) - doc->default_page_boundingbox[LLX]--; - if (flly < doc->default_page_boundingbox[LLY]) - doc->default_page_boundingbox[LLY]--; - if (furx > doc->default_page_boundingbox[URX]) - doc->default_page_boundingbox[URX]++; - if (fury > doc->default_page_boundingbox[URY]) - doc->default_page_boundingbox[URY]++; - } - } - } - } - section_len += line_len; - readline(fd, &line, &position, &line_len); - section_len += line_len; - doc->enddefaults = position; - doc->lendefaults = section_len - line_len; - } - - /* Document Prolog */ - - if (beginsection == 0) { - beginsection = position; - section_len = line_len; - } - while (blank(line) && readline(fd, &line, &position, &line_len)) { - section_len += line_len; - } - - if (!(DSCcomment(line) && - (iscomment(line+2, "BeginSetup") || - iscomment(line+2, "Page:") || - iscomment(line+2, "Trailer") || - iscomment(line+2, "EOF")))) { - doc->beginprolog = beginsection; - beginsection = 0; - preread = 1; - - while ((preread || - readline(fd, &line, &position, &line_len)) && - !(DSCcomment(line) && - (iscomment(line+2, "EndProlog") || - iscomment(line+2, "BeginSetup") || - iscomment(line+2, "Page:") || - iscomment(line+2, "Trailer") || - iscomment(line+2, "EOF")))) { - if (!preread) section_len += line_len; - preread = 0; - } - section_len += line_len; - if (DSCcomment(line) && iscomment(line+2, "EndProlog")) { - readline(fd, &line, &position, &line_len); - section_len += line_len; - } - doc->endprolog = position; - doc->lenprolog = section_len - line_len; - } - - /* Document Setup, Page Defaults found here for Version 2 files */ - - if (beginsection == 0) { - beginsection = position; - section_len = line_len; - } - while (blank(line) && readline(fd, &line, &position, &line_len)) { - section_len += line_len; - } - - if (!(DSCcomment(line) && - (iscomment(line+2, "Page:") || - iscomment(line+2, "Trailer") || - (respect_eof && iscomment(line+2, "EOF"))))) { - doc->beginsetup = beginsection; - beginsection = 0; - preread = 1; - while ((preread || - readline(fd, &line, &position, &line_len)) && - !(DSCcomment(line) && - (iscomment(line+2, "EndSetup") || - iscomment(line+2, "Page:") || - iscomment(line+2, "Trailer") || - (respect_eof && iscomment(line+2, "EOF"))))) { - if (!preread) section_len += line_len; - preread = 0; - if (!DSCcomment(line)) { - /* Do nothing */ - } else if (doc->default_page_orientation == NONE && - iscomment(line+2, "PageOrientation:")) { - sscanf(line+length("%%PageOrientation:"), "%256s", text); - if (strcmp(text, "Portrait") == 0) { - doc->default_page_orientation = PORTRAIT; - } else if (strcmp(text, "Landscape") == 0) { - doc->default_page_orientation = LANDSCAPE; - } else if (strcmp(text, "Seascape") == 0) { - doc->default_page_orientation = SEASCAPE; - } else if (strcmp(text, "UpsideDown") == 0) { - doc->default_page_orientation = UPSIDEDOWN; - } - } else if (page_media_set == NONE && - iscomment(line+2, "PaperSize:")) { - cp = ps_gettext(line+length("%%PaperSize:"), NULL); - for (dmp = doc->media, i=0; inummedia; i++, dmp++) { - /* Note: Paper size comment uses down cased paper size - * name. Case insensitive compares are only used for - * PaperSize comments. - */ - if (_spectre_strcasecmp(cp, dmp->name) == 0) { - doc->default_page_media = dmp; - page_media_set = 1; - break; - } - } - PS_free(cp); - } else if (page_bb_set == NONE && - iscomment(line+2, "PageBoundingBox:")) { - if (sscanf(line+length("%%PageBoundingBox:"), "%d %d %d %d", - &(doc->default_page_boundingbox[LLX]), - &(doc->default_page_boundingbox[LLY]), - &(doc->default_page_boundingbox[URX]), - &(doc->default_page_boundingbox[URY])) == 4) - page_bb_set = 1; - else { - float fllx, flly, furx, fury; - if (sscanf(line+length("%%PageBoundingBox:"), "%f %f %f %f", - &fllx, &flly, &furx, &fury) == 4) { - page_bb_set = 1; - doc->default_page_boundingbox[LLX] = fllx; - doc->default_page_boundingbox[LLY] = flly; - doc->default_page_boundingbox[URX] = furx; - doc->default_page_boundingbox[URY] = fury; - if (fllx < doc->default_page_boundingbox[LLX]) - doc->default_page_boundingbox[LLX]--; - if (flly < doc->default_page_boundingbox[LLY]) - doc->default_page_boundingbox[LLY]--; - if (furx > doc->default_page_boundingbox[URX]) - doc->default_page_boundingbox[URX]++; - if (fury > doc->default_page_boundingbox[URY]) - doc->default_page_boundingbox[URY]++; - } - } - } - } - section_len += line_len; - if (DSCcomment(line) && iscomment(line+2, "EndSetup")) { - readline(fd, &line, &position, &line_len); - section_len += line_len; - } - doc->endsetup = position; - doc->lensetup = section_len - line_len; - } - - /* BEGIN Windows NT fix ###jp### - Mark Pfeifer (pfeiferm%ppddev@comet.cmis.abbott.com) told me - about problems when viewing Windows NT 3.51 generated postscript - files with gv. He found that the relevant postscript files - show important postscript code after the '%%EndSetup' and before - the first page comment '%%Page: x y'. - */ - if (doc->beginsetup) { - while (!(DSCcomment(line) && - (iscomment(line+2, "EndSetup") || - (iscomment(line+2, "Page:") || - iscomment(line+2, "Trailer") || - (respect_eof && iscomment(line+2, "EOF"))))) && - (readline(fd, &line, &position, &line_len))) { - section_len += line_len; - doc->lensetup = section_len - line_len; - doc->endsetup = position; - } - } - /* END Windows NT fix ###jp##*/ - - /* Individual Pages */ - - if (beginsection == 0) { - beginsection = position; - section_len = line_len; - } - while (blank(line) && readline(fd, &line, &position, &line_len)) { - section_len += line_len; - } - - -newpage: - while (DSCcomment(line) && iscomment(line+2, "Page:")) { - if (maxpages == 0) { - maxpages = 1; - doc->pages = (struct page *) PS_calloc(maxpages, sizeof(struct page)); - CHECK_MALLOCED(doc->pages); - } - label = ps_gettext(line+length("%%Page:"), &next_char); - if (sscanf(next_char, "%d", &thispage) != 1) thispage = 0; - if (nextpage == 1) { - ignore = thispage != 1; - } - if (!ignore && thispage != nextpage) { - PS_free(label); - doc->numpages--; - goto continuepage; - } - nextpage++; - if (doc->numpages == maxpages) { - maxpages++; - doc->pages = (struct page *) - PS_realloc(doc->pages, maxpages*sizeof (struct page)); - CHECK_MALLOCED(doc->pages); - - } - memset(&(doc->pages[doc->numpages]), 0, sizeof(struct page)); - page_bb_set = NONE; - doc->pages[doc->numpages].label = label; - if (beginsection) { - doc->pages[doc->numpages].begin = beginsection; - beginsection = 0; - } else { - doc->pages[doc->numpages].begin = position; - section_len = line_len; - } -continuepage: - while (readline(fd, &line, &position, &line_len) && - !(DSCcomment(line) && - (iscomment(line+2, "Page:") || - iscomment(line+2, "Trailer") || - (respect_eof && iscomment(line+2, "EOF"))))) { - section_len += line_len; - if (!DSCcomment(line)) { - /* Do nothing */ - } else if (doc->pages[doc->numpages].orientation == NONE && - iscomment(line+2, "PageOrientation:")) { - sscanf(line+length("%%PageOrientation:"), "%256s", text); - if (strcmp(text, "Portrait") == 0) { - doc->pages[doc->numpages].orientation = PORTRAIT; - } else if (strcmp(text, "Landscape") == 0) { - doc->pages[doc->numpages].orientation = LANDSCAPE; - } else if (strcmp(text, "Seascape") == 0) { - doc->pages[doc->numpages].orientation = SEASCAPE; - } else if (strcmp(text, "UpsideDown") == 0) { - doc->pages[doc->numpages].orientation = UPSIDEDOWN; - } - } else if (doc->pages[doc->numpages].media == NULL && - iscomment(line+2, "PageMedia:")) { - cp = ps_gettext(line+length("%%PageMedia:"), NULL); - for (dmp = doc->media, i=0; inummedia; i++, dmp++) { - if (strcmp(cp, dmp->name) == 0) { - doc->pages[doc->numpages].media = dmp; - break; - } - } - PS_free(cp); - } else if (doc->pages[doc->numpages].media == NULL && - iscomment(line+2, "PaperSize:")) { - cp = ps_gettext(line+length("%%PaperSize:"), NULL); - for (dmp = doc->media, i=0; inummedia; i++, dmp++) { - /* Note: Paper size comment uses down cased paper size - * name. Case insensitive compares are only used for - * PaperSize comments. - */ - if (_spectre_strcasecmp(cp, dmp->name) == 0) { - doc->pages[doc->numpages].media = dmp; - break; - } - } - PS_free(cp); - } else if ((page_bb_set == NONE || page_bb_set == ATEND) && - iscomment(line+2, "PageBoundingBox:")) { - sscanf(line+length("%%PageBoundingBox:"), "%256s", text); - if (strcmp(text, "(atend)") == 0 || strcmp(text, "atend") == 0) { - page_bb_set = ATEND; - } else { - if (sscanf(line+length("%%PageBoundingBox:"), "%d %d %d %d", - &(doc->pages[doc->numpages].boundingbox[LLX]), - &(doc->pages[doc->numpages].boundingbox[LLY]), - &(doc->pages[doc->numpages].boundingbox[URX]), - &(doc->pages[doc->numpages].boundingbox[URY])) == 4) - { - if (page_bb_set == NONE) page_bb_set = 1; - } - else { - float fllx, flly, furx, fury; - if (sscanf(line+length("%%PageBoundingBox:"), - "%f %f %f %f", - &fllx, &flly, &furx, &fury) == 4) { - if (page_bb_set == NONE) page_bb_set = 1; - doc->pages[doc->numpages].boundingbox[LLX] = fllx; - doc->pages[doc->numpages].boundingbox[LLY] = flly; - doc->pages[doc->numpages].boundingbox[URX] = furx; - doc->pages[doc->numpages].boundingbox[URY] = fury; - if (fllx < - doc->pages[doc->numpages].boundingbox[LLX]) - doc->pages[doc->numpages].boundingbox[LLX]--; - if (flly < - doc->pages[doc->numpages].boundingbox[LLY]) - doc->pages[doc->numpages].boundingbox[LLY]--; - if (furx > - doc->pages[doc->numpages].boundingbox[URX]) - doc->pages[doc->numpages].boundingbox[URX]++; - if (fury > - doc->pages[doc->numpages].boundingbox[URY]) - doc->pages[doc->numpages].boundingbox[URY]++; - } - } - } - } - } - section_len += line_len; - doc->pages[doc->numpages].end = position; - doc->pages[doc->numpages].len = section_len - line_len; - doc->numpages++; - } - - /* Document Trailer */ - - if (beginsection) { - doc->begintrailer = beginsection; - beginsection = 0; - } else { - doc->begintrailer = position; - section_len = line_len; - } - - preread = 1; - while ((preread || - readline(fd, &line, &position, &line_len)) && - !(respect_eof && DSCcomment(line) && iscomment(line+2, "EOF"))) { - if (!preread) section_len += line_len; - preread = 0; - if (!DSCcomment(line)) { - /* Do nothing */ - } else if (iscomment(line+2, "Page:")) { - PS_free(ps_gettext(line+length("%%Page:"), &next_char)); - if (sscanf(next_char, "%d", &thispage) != 1) thispage = 0; - if (!ignore && thispage == nextpage) { - if (doc->numpages > 0) { - doc->pages[doc->numpages-1].end = position; - doc->pages[doc->numpages-1].len += section_len - line_len; - } else { - if (doc->endsetup) { - doc->endsetup = position; - doc->endsetup += section_len - line_len; - } else if (doc->endprolog) { - doc->endprolog = position; - doc->endprolog += section_len - line_len; - } - } - goto newpage; - } - } else if (!respect_eof && iscomment(line+2, "Trailer")) { - /* What we thought was the start of the trailer was really */ - /* the trailer of an EPS on the page. */ - /* Set the end of the page to this trailer and keep scanning. */ - if (doc->numpages > 0) { - doc->pages[ doc->numpages-1 ].end = position; - doc->pages[ doc->numpages-1 ].len += section_len - line_len; - } - doc->begintrailer = position; - section_len = line_len; - } else if (bb_set == ATEND && iscomment(line+2, "BoundingBox:")) { - if (sscanf(line+length("%%BoundingBox:"), "%d %d %d %d", - &(doc->boundingbox[LLX]), - &(doc->boundingbox[LLY]), - &(doc->boundingbox[URX]), - &(doc->boundingbox[URY])) != 4) { - float fllx, flly, furx, fury; - if (sscanf(line+length("%%BoundingBox:"), "%f %f %f %f", - &fllx, &flly, &furx, &fury) == 4) { - doc->boundingbox[LLX] = fllx; - doc->boundingbox[LLY] = flly; - doc->boundingbox[URX] = furx; - doc->boundingbox[URY] = fury; - if (fllx < doc->boundingbox[LLX]) - doc->boundingbox[LLX]--; - if (flly < doc->boundingbox[LLY]) - doc->boundingbox[LLY]--; - if (furx > doc->boundingbox[URX]) - doc->boundingbox[URX]++; - if (fury > doc->boundingbox[URY]) - doc->boundingbox[URY]++; - } - } - } else if (orientation_set == ATEND && - iscomment(line+2, "Orientation:")) { - sscanf(line+length("%%Orientation:"), "%256s", text); - if (strcmp(text, "Portrait") == 0) { - doc->orientation = PORTRAIT; - } else if (strcmp(text, "Landscape") == 0) { - doc->orientation = LANDSCAPE; - } else if (strcmp(text, "Seascape") == 0) { - doc->orientation = SEASCAPE; - } else if (strcmp(text, "UpsideDown") == 0) { - doc->orientation = UPSIDEDOWN; - } - } else if (page_order_set == ATEND && iscomment(line+2, "PageOrder:")) { - sscanf(line+length("%%PageOrder:"), "%256s", text); - if (strcmp(text, "Ascend") == 0) { - doc->pageorder = ASCEND; - } else if (strcmp(text, "Descend") == 0) { - doc->pageorder = DESCEND; - } else if (strcmp(text, "Special") == 0) { - doc->pageorder = SPECIAL; - } - } else if (pages_set == ATEND && iscomment(line+2, "Pages:")) { - if (sscanf(line+length("%%Pages:"), "%*u %d", &i) == 1) { - if (page_order_set == NONE) { - if (i == -1) doc->pageorder = DESCEND; - else if (i == 0) doc->pageorder = SPECIAL; - else if (i == 1) doc->pageorder = ASCEND; - } - } - } - } - section_len += line_len; - if (DSCcomment(line) && iscomment(line+2, "EOF")) { - readline(fd, &line, &position, &line_len); - section_len += line_len; - } - doc->endtrailer = position; - doc->lentrailer = section_len - line_len; - -#if 0 - section_len = line_len; - preread = 1; - while (preread || - readline(fd, &line, &position, &line_len)) { - if (!preread) section_len += line_len; - preread = 0; - if (DSCcomment(line) && iscomment(line+2, "Page:")) { - PS_free(ps_gettext(line+length("%%Page:"), &next_char)); - if (sscanf(next_char, "%d", &thispage) != 1) thispage = 0; - if (!ignore && thispage == nextpage) { - if (doc->numpages > 0) { - doc->pages[doc->numpages-1].end = position; - doc->pages[doc->numpages-1].len += doc->lentrailer + - section_len - line_len; - } else { - if (doc->endsetup) { - doc->endsetup = position; - doc->endsetup += doc->lentrailer + - section_len - line_len; - } else if (doc->endprolog) { - doc->endprolog = position; - doc->endprolog += doc->lentrailer + - section_len - line_len; - } - } - goto newpage; - } - } - } -#endif - ENDMESSAGE(psscan) - ps_io_exit(fd); - fclose (file); - return doc; -} - -/*###########################################################*/ -/* - * psfree -- free dynamic storage associated with document structure. - */ -/*###########################################################*/ - -static void -psfree(doc) - struct document *doc; -{ - int i; - - BEGINMESSAGE(psfree) - if (doc) { - for (i=0; inumpages; i++) { - if (doc->pages[i].label) PS_free(doc->pages[i].label); - } - for (i=0; inummedia; i++) { - if (doc->media[i].name) PS_free(doc->media[i].name); - } - if (doc->format) PS_free(doc->format); - if (doc->filename) PS_free(doc->filename); - if (doc->creator) PS_free(doc->creator); - if (doc->fortext) PS_free(doc->fortext); - if (doc->title) PS_free(doc->title); - if (doc->date) PS_free(doc->date); - if (doc->pages) PS_free(doc->pages); - if (doc->media) PS_free(doc->media); - if (doc->languagelevel) PS_free(doc->languagelevel); - PS_free(doc); - } - ENDMESSAGE(psfree) -} - -void -psdocdestroy (struct document *doc) -{ - if (!doc) - return; - - assert (doc->ref_count > 0); - - doc->ref_count--; - if (doc->ref_count) - return; - - psfree (doc); -} - -struct document * -psdocreference (struct document *doc) -{ - if (!doc) - return NULL; - - assert (doc->ref_count > 0); - - doc->ref_count++; - - return doc; -} - -/*----------------------------------------------------------*/ -/* - * gettextline -- skip over white space and return the rest of the line. - * If the text begins with '(' return the text string - * using ps_gettext(). - */ -/*----------------------------------------------------------*/ - -static char * -gettextline(line) - char *line; -{ - char *cp; - - BEGINMESSAGE(gettextline) - while (*line && (*line == ' ' || *line == '\t')) line++; - if (*line == '(') { - ENDMESSAGE(gettextline) - return ps_gettext(line, NULL); - } else { - if (strlen(line) == 0) {ENDMESSAGE(gettextline) return NULL;} - cp = (char *) PS_malloc(strlen(line)); - CHECK_MALLOCED(cp); - strncpy(cp, line, strlen(line)-1); - cp[strlen(line)-1] = '\0'; - ENDMESSAGE(gettextline) - return cp; - } -} - -/*----------------------------------------------------------*/ -/* - * ps_gettext -- return the next text string on the line. - * return NULL if nothing is present. - */ -/*----------------------------------------------------------*/ - -static char * -ps_gettext(line, next_char) - char *line; - char **next_char; -{ - char text[PSLINELENGTH]; /* Temporary storage for text */ - char *cp; - int quoted=0; - - BEGINMESSAGE(ps_gettext) - while (*line && (*line == ' ' || *line == '\t')) line++; - cp = text; - if (*line == '(') { - int level = 0; - quoted=1; - line++; - while (*line && !(*line == ')' && level == 0 )) { - if (cp - text >= PSLINELENGTH - 1) - break; - if (*line == '\\') { - if (*(line+1) == 'n') { - *cp++ = '\n'; - line += 2; - } else if (*(line+1) == 'r') { - *cp++ = '\r'; - line += 2; - } else if (*(line+1) == 't') { - *cp++ = '\t'; - line += 2; - } else if (*(line+1) == 'b') { - *cp++ = '\b'; - line += 2; - } else if (*(line+1) == 'f') { - *cp++ = '\f'; - line += 2; - } else if (*(line+1) == '\\') { - *cp++ = '\\'; - line += 2; - } else if (*(line+1) == '(') { - *cp++ = '('; - line += 2; - } else if (*(line+1) == ')') { - *cp++ = ')'; - line += 2; - } else if (*(line+1) >= '0' && *(line+1) <= '9') { - if (*(line+2) >= '0' && *(line+2) <= '9') { - if (*(line+3) >= '0' && *(line+3) <= '9') { - *cp++ = ((*(line+1) - '0')*8 + *(line+2) - '0')*8 + - *(line+3) - '0'; - line += 4; - } else { - *cp++ = (*(line+1) - '0')*8 + *(line+2) - '0'; - line += 3; - } - } else { - *cp++ = *(line+1) - '0'; - line += 2; - } - } else { - line++; - *cp++ = *line++; - } - } else if (*line == '(') { - level++; - *cp++ = *line++; - } else if (*line == ')') { - level--; - *cp++ = *line++; - } else { - *cp++ = *line++; - } - } - /* Delete trailing ')' */ - if (*line == ')') - { - line++; - } - } else { - while (*line && !(*line == ' ' || *line == '\t' || *line == '\n')) { - if (cp - text >= PSLINELENGTH - 2) - break; - *cp++ = *line++; - } - } - *cp = '\0'; - if (next_char) *next_char = line; - if (!quoted && strlen(text) == 0) {ENDMESSAGE(ps_gettext) return NULL;} - cp = (char *) PS_malloc(strlen(text)+1); - CHECK_MALLOCED(cp); - strcpy(cp, text); - ENDMESSAGE(ps_gettext) - return cp; -} - -/*----------------------------------------------------------*/ -/* ps_io_init */ -/*----------------------------------------------------------*/ - -#define FD_FILE (fd->file) -#define FD_FILEPOS (fd->filepos) -#define FD_LINE_BEGIN (fd->line_begin) -#define FD_LINE_END (fd->line_end) -#define FD_LINE_LEN (fd->line_len) -#define FD_LINE_TERMCHAR (fd->line_termchar) -#define FD_BUF (fd->buf) -#define FD_BUF_END (fd->buf_end) -#define FD_BUF_SIZE (fd->buf_size) -#define FD_STATUS (fd->status) - -#define FD_STATUS_OKAY 0 -#define FD_STATUS_BUFTOOLARGE 1 -#define FD_STATUS_NOMORECHARS 2 - -#define LINE_CHUNK_SIZE 4096 -#define MAX_PS_IO_FGETCHARS_BUF_SIZE 57344 -#define BREAK_PS_IO_FGETCHARS_BUF_SIZE 49152 - -static FileData ps_io_init(file) - FILE *file; -{ - FileData fd; - size_t size = sizeof(FileDataStruct); - - BEGINMESSAGE(ps_io_init) - - fd = (FileData) PS_XtMalloc(size); - memset((void*) fd ,0,(size_t)size); - - rewind(file); - FD_FILE = file; - FD_FILEPOS = ftell(file); - FD_BUF_SIZE = (2*LINE_CHUNK_SIZE)+1; - FD_BUF = PS_XtMalloc(FD_BUF_SIZE); - FD_BUF[0] = '\0'; - ENDMESSAGE(ps_io_init) - return(fd); -} - -/*----------------------------------------------------------*/ -/* ps_io_exit */ -/*----------------------------------------------------------*/ - -static void -ps_io_exit(fd) - FileData fd; -{ - BEGINMESSAGE(ps_io_exit) - PS_XtFree(FD_BUF); - PS_XtFree(fd); - ENDMESSAGE(ps_io_exit) -} - -/*----------------------------------------------------------*/ -/* ps_io_fseek */ -/*----------------------------------------------------------*/ - -static int -ps_io_fseek(fd,offset) - FileData fd; - int offset; -{ - int status; - BEGINMESSAGE(ps_io_fseek) - status=fseek(FD_FILE,(long)offset,SEEK_SET); - FD_BUF_END = FD_LINE_BEGIN = FD_LINE_END = FD_LINE_LEN = 0; - FD_FILEPOS = offset; - FD_STATUS = FD_STATUS_OKAY; - ENDMESSAGE(ps_io_fseek) - return(status); -} - -/*----------------------------------------------------------*/ -/* ps_io_ftell */ -/*----------------------------------------------------------*/ - -static int -ps_io_ftell(fd) - FileData fd; -{ - BEGINMESSAGE(ps_io_ftell) - IMESSAGE(FD_FILEPOS) - ENDMESSAGE(ps_io_ftell) - return(FD_FILEPOS); -} - -/*----------------------------------------------------------*/ -/* ps_io_fgetchars */ -/*----------------------------------------------------------*/ - -#ifdef USE_MEMMOVE_CODE -static void ps_memmove (d, s, l) - char *d; - const char *s; - unsigned l; -{ - if (s < d) for (s += l, d += l; l; --l) *--d = *--s; - else if (s != d) for (; l; --l) *d++ = *s++; -} -#else -# define ps_memmove memmove -#endif - -static char * ps_io_fgetchars(fd,num) - FileData fd; - int num; -{ - char *eol=NULL,*tmp; - size_t size_of_char = sizeof(char); - - BEGINMESSAGE(ps_io_fgetchars) - - if (FD_STATUS != FD_STATUS_OKAY) { - INFMESSAGE(aborting since status not okay) - ENDMESSAGE(ps_io_fgetchars) - return(NULL); - } - - FD_BUF[FD_LINE_END] = FD_LINE_TERMCHAR; /* restoring char previously exchanged against '\0' */ - FD_LINE_BEGIN = FD_LINE_END; - -#if 0 - { - int fp = (int)(ftell(FD_FILE)); - if (num<0) { INFMESSAGE(reading line) } - else { INFMESSAGE(reading specified num of chars) } - IIMESSAGE(FD_BUF_SIZE,FD_BUF_END) - IIMESSAGE(FD_LINE_BEGIN,FD_LINE_END) - INFIMESSAGE(unparsed:,FD_BUF_END-FD_LINE_END) - IMESSAGE(fp) - IIMESSAGE(FD_FILEPOS,fp-(FD_BUF_END-FD_LINE_END)) - } -#endif /* 0 */ - - do { - if (num<0) { /* reading whole line */ - if (FD_BUF_END-FD_LINE_END) { - /* strpbrk is faster but fails on lines with embedded NULLs - eol = strpbrk(FD_BUF+FD_LINE_END,"\n\r"); - */ - tmp = FD_BUF + FD_BUF_END; - eol = FD_BUF + FD_LINE_END; - while (eol < tmp && *eol != '\n' && *eol != '\r') eol++; - if (eol >= tmp) eol = NULL; - if (eol) { - if (*eol=='\r' && *(eol+1)=='\n') eol += 2; - else eol++; - break; - } - } - } else { /* reading specified num of chars */ - if (FD_BUF_END >= FD_LINE_BEGIN+num) { - eol = FD_BUF+FD_LINE_BEGIN+num; - break; - } - } - - INFMESSAGE(no end of line yet) - - if (FD_BUF_END - FD_LINE_BEGIN > BREAK_PS_IO_FGETCHARS_BUF_SIZE) { - INFMESSAGE(breaking line artificially) - eol = FD_BUF + FD_BUF_END - 1; - break; - } - - while (FD_BUF_SIZE < FD_BUF_END+LINE_CHUNK_SIZE+1) { - if (FD_BUF_SIZE > MAX_PS_IO_FGETCHARS_BUF_SIZE) { - /* we should never get here, since the line is broken - artificially after BREAK_PS_IO_FGETCHARS_BUF_SIZE bytes. */ - INFMESSAGE(buffer became to large) - ENDMESSAGE(ps_io_fgetchars) - fprintf(stderr, "gv: ps_io_fgetchars: Fatal Error: buffer became too large.\n"); - exit(-1); - } - if (FD_LINE_BEGIN) { - INFMESSAGE(moving line to begin of buffer) - ps_memmove((void*)FD_BUF,(void*)(FD_BUF+FD_LINE_BEGIN), - ((size_t)(FD_BUF_END-FD_LINE_BEGIN+1))*size_of_char); - FD_BUF_END -= FD_LINE_BEGIN; - FD_LINE_BEGIN = 0; - } else { - INFMESSAGE(enlarging buffer) - /* - FD_BUF_SIZE = FD_BUF_END+LINE_CHUNK_SIZE+1; - */ - FD_BUF_SIZE = FD_BUF_SIZE+LINE_CHUNK_SIZE+1; - IMESSAGE(FD_BUF_SIZE) - FD_BUF = PS_XtRealloc(FD_BUF,FD_BUF_SIZE); - } - } - - FD_LINE_END = FD_BUF_END; - /* read() seems to fail sometimes (? ? ?) so we always use fread ###jp###,07/31/96*/ - FD_BUF_END += fread(FD_BUF+FD_BUF_END,size_of_char,LINE_CHUNK_SIZE,FD_FILE); - - FD_BUF[FD_BUF_END] = '\0'; - if (FD_BUF_END-FD_LINE_END == 0) { - INFMESSAGE(failed to read more chars) - ENDMESSAGE(ps_io_fgetchars) - FD_STATUS = FD_STATUS_NOMORECHARS; - return(NULL); - } - } - while (1); - - FD_LINE_END = eol - FD_BUF; - FD_LINE_LEN = FD_LINE_END - FD_LINE_BEGIN; - FD_LINE_TERMCHAR = FD_BUF[FD_LINE_END]; - FD_BUF[FD_LINE_END] = '\0'; -#ifdef USE_FTELL_FOR_FILEPOS - if (FD_LINE_END==FD_BUF_END) { - INFMESSAGE(### using ftell to get FD_FILEPOS) - /* - For VMS we cannot assume that the record is FD_LINE_LEN bytes long - on the disk. For stream_lf and stream_cr that is true, but not for - other formats, since VAXC/DECC converts the formatting into a single \n. - eg. variable format files have a 2-byte length and padding to an even - number of characters. So, we use ftell for each record. - This still will not work if we need to fseek to a \n or \r inside a - variable record (ftell always returns the start of the record in this - case). - (Tim Adye, adye@v2.rl.ac.uk) - */ - FD_FILEPOS = ftell(FD_FILE); - } else -#endif /* USE_FTELL_FOR_FILEPOS */ - FD_FILEPOS += FD_LINE_LEN; - -#if 0 - SMESSAGE(FD_BUF+FD_LINE_BEGIN) - IIMESSAGE(FD_LINE_BEGIN,FD_LINE_END) - IIMESSAGE(FD_BUF_END,FD_LINE_LEN) -#endif - - ENDMESSAGE(ps_io_fgetchars) - return(FD_BUF+FD_LINE_BEGIN); -} - -/*----------------------------------------------------------*/ -/* - readline() - Read the next line in the postscript file. - Automatically skip over data (as indicated by - %%BeginBinary/%%EndBinary or %%BeginData/%%EndData - comments.) - Also, skip over included documents (as indicated by - %%BeginDocument/%%EndDocument comments.) -*/ -/*----------------------------------------------------------*/ - -static char * readline (fd, lineP, positionP, line_lenP) - FileData fd; - char **lineP; - long *positionP; - unsigned int *line_lenP; -{ - unsigned int nbytes=0; - int skipped=0; - int nesting_level=0; - char *line; - - BEGINMESSAGE(readline) - - if (positionP) *positionP = FD_FILEPOS; - line = ps_io_fgetchars(fd,-1); - if (!line) { - INFMESSAGE(could not get line) - *line_lenP = 0; - *lineP = empty_string; - ENDMESSAGE(readline) - return(NULL); - } - - *line_lenP = FD_LINE_LEN; - -#define IS_COMMENT(comment) \ - (DSCcomment(line) && iscomment(line+2,(comment))) -#define IS_BEGIN(comment) \ - (iscomment(line+7,(comment))) -#define IS_END(comment) \ - (iscomment(line+5,(comment))) -#define SKIP_WHILE(cond) \ - while (readline(fd, &line, NULL, &nbytes) && (cond)) *line_lenP += nbytes;\ - skipped=1; -#define SKIP_UNTIL_1(comment) { \ - INFMESSAGE(skipping until comment) \ - SKIP_WHILE((!IS_COMMENT(comment))) \ - INFMESSAGE(completed skipping until comment) \ - } -#define SKIP_UNTIL_2(comment1,comment2) { \ - INFMESSAGE(skipping until comment1 or comment2)\ - SKIP_WHILE((!IS_COMMENT(comment1) && !IS_COMMENT(comment2)))\ - INFMESSAGE(completed skipping until comment1 or comment2)\ - } - -#if 0 - if ((scanstyle&SCANSTYLE_MISSING_BEGINDOCUMENT) && - (line[0] == '%') && - (*line_lenP > 11) && - (iscomment(line,"%!PS-Adobe-") || iscomment(line + 1,"%!PS-Adobe-"))) { - char *c=line+11; - while (*c && !isspace(*c)) c++; - if (isspace(*c)) while (*c && isspace(*c)) c++; - /* don't skip EPSF files */ - printf("line in question: %s\n",line); - if (strncmp(c,"EPSF",4)) { - printf("skipping starts here: %s\n",line); - SKIP_UNTIL_1("EOF") - *line_lenP += nbytes; - readline(fd, &line, NULL, &nbytes); - printf("skipping ends here: %s\n",line); - } - } - else -#endif - if (!IS_COMMENT("Begin")) {} /* Do nothing */ - else if IS_BEGIN("Document:") { /* Skip the EPS without handling its content */ - nesting_level=1; - line = ps_io_fgetchars(fd,-1); - if (line) *line_lenP += FD_LINE_LEN; - while (line) { - if (IS_COMMENT("Begin") && IS_BEGIN("Document:")) - nesting_level++; - else if (IS_COMMENT("End") && IS_END("Document")) - nesting_level--; - if (nesting_level == 0) break; - line = ps_io_fgetchars(fd,-1); - if (line) *line_lenP += FD_LINE_LEN; - } - } - else if IS_BEGIN("Feature:") SKIP_UNTIL_1("EndFeature") -#ifdef USE_ACROREAD_WORKAROUND - else if IS_BEGIN("File") SKIP_UNTIL_2("EndFile","EOF") -#else - else if IS_BEGIN("File") SKIP_UNTIL_1("EndFile") -#endif - else if IS_BEGIN("Font") SKIP_UNTIL_1("EndFont") - else if IS_BEGIN("ProcSet") SKIP_UNTIL_1("EndProcSet") - else if IS_BEGIN("Resource") SKIP_UNTIL_1("EndResource") - else if IS_BEGIN("Data:") { - int num; - char text[101]; - INFMESSAGE(encountered "BeginData:") - if (FD_LINE_LEN > 100) FD_BUF[100] = '\0'; - text[0] = '\0'; - if (sscanf(line+length("%%BeginData:"), "%d %*s %100s", &num, text) >= 1) { - if (strcmp(text, "Lines") == 0) { - INFIMESSAGE(number of lines to skip:,num) - while (num) { - line = ps_io_fgetchars(fd,-1); - if (line) *line_lenP += FD_LINE_LEN; - num--; - } - } else { - int read_chunk_size = LINE_CHUNK_SIZE; - INFIMESSAGE(number of chars to skip:,num) - while (num>0) { - if (num <= LINE_CHUNK_SIZE) read_chunk_size=num; - line = ps_io_fgetchars(fd,read_chunk_size); - if (line) *line_lenP += FD_LINE_LEN; - num -= read_chunk_size; - } - } - } - SKIP_UNTIL_1("EndData") - } - else if IS_BEGIN("Binary:") { - int num; - INFMESSAGE(encountered "BeginBinary:") - if (sscanf(line+length("%%BeginBinary:"), "%d", &num) == 1) { - int read_chunk_size = LINE_CHUNK_SIZE; - INFIMESSAGE(number of chars to skip:,num) - while (num>0) { - if (num <= LINE_CHUNK_SIZE) read_chunk_size=num; - line = ps_io_fgetchars(fd,read_chunk_size); - if (line) *line_lenP += FD_LINE_LEN; - num -= read_chunk_size; - } - SKIP_UNTIL_1("EndBinary") - } - } - - if (skipped) { - INFMESSAGE(skipped lines) - *line_lenP += nbytes; - *lineP = skipped_line; - } else { - *lineP = FD_BUF+FD_LINE_BEGIN; - } - - ENDMESSAGE(readline) - return(FD_BUF+FD_LINE_BEGIN); -} - -/*###########################################################*/ -/* - * pscopyuntil -- copy lines of Postscript from a section of one file - * to another file until a particular comment is reached. - * Automatically switch to binary copying whenever - * %%BeginBinary/%%EndBinary or %%BeginData/%%EndData - * comments are encountered. - */ -/*###########################################################*/ - -char * -pscopyuntil(fd, to, begin, end, comment) - FileData fd; - FILE *to; - long begin; /* set negative to avoid initial seek */ - long end; - char *comment; -{ - char *line; - int comment_length; - - BEGINMESSAGE(pscopyuntil) - if (comment) { - INFSMESSAGE(will copy until,comment) - comment_length = strlen(comment); - } - else { - INFMESSAGE(will copy until specified file position) - comment_length = 0; - } - if (begin >= 0) ps_io_fseek(fd, begin); - while (ps_io_ftell(fd) < end) { - line = ps_io_fgetchars(fd,-1); - if (!line) break; - if (comment && strncmp(line, comment, comment_length) == 0) { - char *cp = (char *) PS_malloc(strlen(line)+1); - INFSMESSAGE(encountered specified,comment) - CHECK_MALLOCED(cp); - strcpy(cp, line); - ENDMESSAGE(pscopyuntil) - return cp; - } - fputs(line, to); - if (!IS_COMMENT("Begin")) {} /* Do nothing */ - else if IS_BEGIN("Data:") { - int num; - char text[101]; - INFMESSAGE(encountered "BeginData:") - if (FD_LINE_LEN > 100) FD_BUF[100] = '\0'; - text[0] = '\0'; - if (sscanf(line+length("%%BeginData:"), "%d %*s %100s", &num, text) >= 1) { - if (strcmp(text, "Lines") == 0) { - INFIMESSAGE(number of lines:,num) - while (num) { - line = ps_io_fgetchars(fd,-1); - if (line) fputs(line,to); - num--; - } - } else { - int read_chunk_size = LINE_CHUNK_SIZE; - INFIMESSAGE(number of chars:,num) - while (num>0) { - if (num <= LINE_CHUNK_SIZE) read_chunk_size=num; - line = ps_io_fgetchars(fd,read_chunk_size); - if (line) fwrite(line,sizeof(char),FD_LINE_LEN, to); - num -= read_chunk_size; - } - } - } - } - else if IS_BEGIN("Binary:") { - int num; - INFMESSAGE(encountered "BeginBinary:") - if (sscanf(line+length("%%BeginBinary:"), "%d", &num) == 1) { - int read_chunk_size = LINE_CHUNK_SIZE; - INFIMESSAGE(number of chars:,num) - while (num>0) { - if (num <= LINE_CHUNK_SIZE) read_chunk_size=num; - line = ps_io_fgetchars(fd,read_chunk_size); - if (line) fwrite(line, sizeof (char),FD_LINE_LEN, to); - num -= read_chunk_size; - } - } - } - } - ENDMESSAGE(pscopyuntil) - return NULL; -} - -/*----------------------------------------------------------*/ -/* blank */ -/* Check whether the line contains nothing but white space. */ -/*----------------------------------------------------------*/ - -static int blank(line) - char *line; -{ - char *cp = line; - - BEGINMESSAGE(blank) - while (*cp == ' ' || *cp == '\t') cp++; - ENDMESSAGE(blank) - return *cp == '\n' || *cp== '\r' || (*cp == '%' && (line[0] != '%' || line[1] != '%')); -} - -void -pscopy (FILE *from, FILE *to, Document d, long begin, long end) -{ - FileData fd; - - fd = ps_io_init(from); - pscopyuntil(fd, to, begin, end, NULL); - ps_io_exit(fd); -} - -void -pscopyheaders (FILE *from, FILE *to, Document d) -{ - char *comment; - Boolean pages_written = False; - int here; - FileData fd; - - fd = ps_io_init(from); - - here = d->beginheader; - while ((comment=pscopyuntil(fd,to,here,d->endheader,"%%Pages:"))) { - SMESSAGE(comment) - here = ps_io_ftell(fd); - if (pages_written) { - PS_free(comment); - continue; - } - fputs("%%Pages: (atend)\n", to); - pages_written = True; - PS_free(comment); - } - - if (!pages_written && !d->epsf) - fputs("%%Pages: (atend)\n", to); - - pscopyuntil(fd, to, d->beginpreview, d->endpreview,NULL); - pscopyuntil(fd, to, d->begindefaults, d->enddefaults,NULL); - pscopyuntil(fd, to, d->beginprolog, d->endprolog,NULL); - pscopyuntil(fd, to, d->beginsetup, d->endsetup,NULL); - - ps_io_exit(fd); -} - -void -pscopypage (FILE *from, FILE *to, Document d, unsigned int page, unsigned int n_page) -{ - FileData fd; - char *comment; - - fd = ps_io_init(from); - - comment = pscopyuntil(fd,to,d->pages[page].begin,d->pages[page].end, "%%Page:"); - fprintf(to, "%%%%Page: %s %d\n",d->pages[page].label, n_page); - PS_free(comment); - pscopyuntil(fd, to, -1, d->pages[page].end,NULL); - - ps_io_exit(fd); -} - -void -pscopytrailer (FILE *from, FILE *to, Document d, unsigned int n_pages) -{ - FileData fd; - Boolean pages_written = False; - char *comment; - int here; - - fd = ps_io_init(from); - - here = d->begintrailer; - if (!d->epsf) { - pscopyuntil(fd, to, here, here + strlen ("%%Trailer") + 1, NULL); - here = ps_io_ftell(fd); - fprintf(to, "%%%%Pages: %d\n",n_pages); - } - - while ((comment = pscopyuntil(fd, to, here, d->endtrailer, "%%Pages:"))) { - here = ps_io_ftell(fd); - if (pages_written) { - PS_free(comment); - continue; - } - pages_written = True; - PS_free(comment); - } - - ps_io_exit(fd); -} - -/*##########################################################*/ -/* pscopydoc */ -/* Copy the headers, marked pages, and trailer to fp */ -/*##########################################################*/ - -void -pscopydoc(dest_file,src_filename,d,pagelist) - FILE *dest_file; - char *src_filename; - Document d; - char *pagelist; -{ - FILE *src_file; - char text[PSLINELENGTH]; - char *comment; - Boolean pages_written = False; - Boolean pages_atend = False; - int pages; - int page = 1; - int i, j; - int here; - FileData fd; - - BEGINMESSAGE(pscopydoc) - - INFSMESSAGE(copying from file, src_filename) - src_file = fopen(src_filename, "r"); - fd = ps_io_init(src_file); - - i=0; - pages=0; - while (pagelist[i]) { if (pagelist[i]=='*') pages++; i++; } - INFIMESSAGE(number of pages to be copied,pages) - - here = d->beginheader; - while ((comment=pscopyuntil(fd,dest_file,here,d->endheader,"%%Pages:"))) { - SMESSAGE(comment) - here = ps_io_ftell(fd); - if (pages_written || pages_atend) { - PS_free(comment); - continue; - } - sscanf(comment+length("%%Pages:"), "%256s", text); - if (strcmp(text, "(atend)") == 0) { - fputs(comment, dest_file); - pages_atend = True; - } else { - switch (sscanf(comment+length("%%Pages:"), "%*d %d", &i)) { - case 1: - fprintf(dest_file, "%%%%Pages: %d %d\n", pages, i); - break; - default: - fprintf(dest_file, "%%%%Pages: %d\n", pages); - break; - } - pages_written = True; - } - PS_free(comment); - } - pscopyuntil(fd, dest_file, d->beginpreview, d->endpreview,NULL); - pscopyuntil(fd, dest_file, d->begindefaults, d->enddefaults,NULL); - pscopyuntil(fd, dest_file, d->beginprolog, d->endprolog,NULL); - pscopyuntil(fd, dest_file, d->beginsetup, d->endsetup,NULL); - - for (i = 0; i < d->numpages; i++) { - if (d->pageorder == DESCEND) j = (d->numpages - 1) - i; - else j = i; - if (pagelist[j]=='*') { - comment = pscopyuntil(fd,dest_file,d->pages[i].begin,d->pages[i].end, "%%Page:"); - fprintf(dest_file, "%%%%Page: %s %d\n",d->pages[i].label, page++); - PS_free(comment); - pscopyuntil(fd, dest_file, -1, d->pages[i].end,NULL); - } - } - - here = d->begintrailer; - while ((comment = pscopyuntil(fd, dest_file, here, d->endtrailer, "%%Pages:"))) { - here = ps_io_ftell(fd); - if (pages_written) { - PS_free(comment); - continue; - } - switch (sscanf(comment+length("%%Pages:"), "%*d %d", &i)) { - case 1: - fprintf(dest_file, "%%%%Pages: %d %d\n", pages, i); - break; - default: - fprintf(dest_file, "%%%%Pages: %d\n", pages); - break; - } - pages_written = True; - PS_free(comment); - } - fclose(src_file); - ps_io_exit(fd); - - ENDMESSAGE(pscopydoc) -} -#undef length - - -/* From Evince */ -#define DEFAULT_PAGE_SIZE 1 - -void -psgetpagebox (const struct document *doc, int page, int *urx, int *ury, int *llx, int *lly) -{ - int new_llx = 0; - int new_lly = 0; - int new_urx = 0; - int new_ury = 0; - int new_pagesize = -1; - - if (new_pagesize == -1) { - new_pagesize = DEFAULT_PAGE_SIZE; - if (doc) { - /* If we have a document: - * We use -- the page size (if specified) - * or the doc. size (if specified) - * or the page bbox (if specified) - * or the bounding box - */ - if ((page >= 0) && (doc->numpages > page) && - (doc->pages) && (doc->pages[page].media)) { - new_pagesize = doc->pages[page].media - doc->media; - } else if (doc->default_page_media != NULL) { - new_pagesize = doc->default_page_media - doc->media; - } else if ((page >= 0) && - (doc->numpages > page) && - (doc->pages) && - (doc->pages[page].boundingbox[URX] > - doc->pages[page].boundingbox[LLX]) && - (doc->pages[page].boundingbox[URY] > - doc->pages[page].boundingbox[LLY])) { - new_pagesize = -1; - } else if ((doc->boundingbox[URX] > doc->boundingbox[LLX]) && - (doc->boundingbox[URY] > doc->boundingbox[LLY])) { - new_pagesize = -1; - } - } - } - - /* Compute bounding box */ - if (doc && (doc->epsf || new_pagesize == -1)) { /* epsf or bbox */ - if ((page >= 0) && - (doc->pages) && - (doc->pages[page].boundingbox[URX] > - doc->pages[page].boundingbox[LLX]) && - (doc->pages[page].boundingbox[URY] > - doc->pages[page].boundingbox[LLY])) { - /* use page bbox */ - new_llx = doc->pages[page].boundingbox[LLX]; - new_lly = doc->pages[page].boundingbox[LLY]; - new_urx = doc->pages[page].boundingbox[URX]; - new_ury = doc->pages[page].boundingbox[URY]; - } else if ((doc->boundingbox[URX] > doc->boundingbox[LLX]) && - (doc->boundingbox[URY] > doc->boundingbox[LLY])) { - /* use doc bbox */ - new_llx = doc->boundingbox[LLX]; - new_lly = doc->boundingbox[LLY]; - new_urx = doc->boundingbox[URX]; - new_ury = doc->boundingbox[URY]; - } - } else { - if (new_pagesize < 0) - new_pagesize = DEFAULT_PAGE_SIZE; - new_llx = new_lly = 0; - if (doc && doc->media && - (new_pagesize < doc->nummedia)) { - new_urx = doc->media[new_pagesize].width; - new_ury = doc->media[new_pagesize].height; - } else { - new_urx = papersizes[new_pagesize].width; - new_ury = papersizes[new_pagesize].height; - } - } - - if (new_urx <= new_llx) - new_urx = papersizes[12].width; - if (new_ury <= new_lly) - new_ury = papersizes[12].height; - - *urx = new_urx; - *ury = new_ury; - *llx = new_llx; - *lly = new_lly; -} diff --git a/generators/spectre/libspectre/ps.h b/generators/spectre/libspectre/ps.h deleted file mode 100644 index 3b869e4cc..000000000 --- a/generators/spectre/libspectre/ps.h +++ /dev/null @@ -1,215 +0,0 @@ -/* - * ps.h -- Include file for PostScript routines. - * Copyright (C) 1992 Timothy O. Theisen - * Copyright (C) 2004 Jose E. Marchesi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU gv; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA - * - * Author: Tim Theisen Systems Programmer - * Internet: tim@cs.wisc.edu Department of Computer Sciences - * UUCP: uwvax!tim University of Wisconsin-Madison - * Phone: (608)262-0438 1210 West Dayton Street - * FAX: (608)262-9777 Madison, WI 53706 -*/ - -#ifndef PS_H -#define PS_H - -#include -#include - -SPECTRE_BEGIN_DECLS - -#ifndef NeedFunctionPrototypes -#if defined(FUNCPROTO) || defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) -#define NeedFunctionPrototypes 1 -#else -#define NeedFunctionPrototypes 0 -#endif /* __STDC__ */ -#endif /* NeedFunctionPrototypes */ - -/* Constants used to index into the bounding box array. */ - -#define LLX 0 -#define LLY 1 -#define URX 2 -#define URY 3 - - /* Constants used to store keywords that are scanned. */ - /* NONE is not a keyword, it tells when a field was not set */ - -/* -enum {ATEND = -1, NONE = 0, PORTRAIT, LANDSCAPE, ASCEND, DESCEND, SPECIAL}; -*/ - -#define ATEND (-1) -#define NONE 0 -#define PORTRAIT 1 -#define LANDSCAPE 2 -#define SEASCAPE 3 -#define UPSIDEDOWN 4 -#define ASCEND 5 -#define DESCEND 6 -#define SPECIAL 7 -#define AUTOMATIC 8 - -#define PSLINELENGTH 257 /* 255 characters + 1 newline + 1 NULL */ - -/*############################################## - media - ##############################################*/ -typedef struct documentmedia { - char *name; - int width; - int height; -} MediaStruct, *Media; - - -typedef struct document { - unsigned int ref_count; - -#ifdef GV_CODE - int structured; /* toc will be useful */ - int labels_useful; /* page labels are distinguishable, hence useful */ -#endif - char *format; /* Postscript format */ - char *filename; /* Document filename */ - int epsf; /* Encapsulated PostScript flag. */ - char *title; /* Title of document. */ - char *date; /* Creation date. */ - char *creator; /* Program that created the file */ - char *fortext; - char *languagelevel; - int pageorder; /* ASCEND, DESCEND, SPECIAL */ - long beginheader, endheader; /* offsets into file */ - unsigned int lenheader; - long beginpreview, endpreview; - unsigned int lenpreview; - long begindefaults, enddefaults; - unsigned int lendefaults; - long beginprolog, endprolog; - unsigned int lenprolog; - long beginsetup, endsetup; - unsigned int lensetup; - long begintrailer, endtrailer; - unsigned int lentrailer; - int boundingbox[4]; - int default_page_boundingbox[4]; - int orientation; /* PORTRAIT, LANDSCAPE */ - int default_page_orientation; /* PORTRAIT, LANDSCAPE */ - unsigned int nummedia; - struct documentmedia *media; - Media default_page_media; - unsigned int numpages; - struct page *pages; -} *Document; - -struct page { - char *label; - int boundingbox[4]; - struct documentmedia *media; - int orientation; /* PORTRAIT, LANDSCAPE */ - long begin, end; /* offsets into file */ - unsigned int len; -}; - - /* scans a PostScript file and return a pointer to the document - structure. Returns NULL if file does not Conform to commenting - conventions . */ - -#define SCANSTYLE_NORMAL 0 -#define SCANSTYLE_IGNORE_EOF (1<<0) -#define SCANSTYLE_IGNORE_DSC (1<<1) - -Document psscan ( -#if NeedFunctionPrototypes - const char *, - int /* scanstyle */ -#endif -); - -void psdocdestroy ( -#if NeedFunctionPrototypes - struct document * -#endif -); - -Document psdocreference ( -#if NeedFunctionPrototypes - struct document * -#endif -); - -extern void pscopydoc ( -#if NeedFunctionPrototypes - FILE *, - char *, - Document, - char * -#endif -); - -void psgetpagebox ( -#if NeedFunctionPrototypes - const struct document *, - int, - int *, - int *, - int *, - int * -#endif -); - -void pscopy ( -#if NeedFunctionPrototypes - FILE *, - FILE *, - Document, - long, - long -#endif -); - -void pscopyheaders ( -#if NeedFunctionPrototypes - FILE *, - FILE *, - Document -#endif -); - -void pscopypage ( -#if NeedFunctionPrototypes - FILE *, - FILE *, - Document, - unsigned int, - unsigned int -#endif -); - -void pscopytrailer ( -#if NeedFunctionPrototypes - FILE *, - FILE *, - Document, - unsigned int -#endif -); - -SPECTRE_END_DECLS - -#endif /* PS_H */ diff --git a/generators/spectre/libspectre/spectre-device.c b/generators/spectre/libspectre/spectre-device.c deleted file mode 100644 index eb9a1ba2f..000000000 --- a/generators/spectre/libspectre/spectre-device.c +++ /dev/null @@ -1,301 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include - -#include "spectre-device.h" -#include "spectre-gs.h" -#include "spectre-utils.h" -#include "spectre-private.h" - -/* ghostscript stuff */ -#include "ghostscript/gdevdsp.h" - -struct SpectreDevice { - struct document *doc; - - int width, height; - int row_length; /*! Size of a horizontal row (y-line) in the image buffer */ - unsigned char *gs_image; /*! Image buffer we received from Ghostscript library */ - unsigned char *user_image; - int page_called; -}; - -static int -spectre_open (void *handle, void *device) -{ - return 0; -} - -static int -spectre_preclose (void *handle, void *device) -{ - return 0; -} - -static int -spectre_close (void *handle, void *device) -{ - return 0; -} - -static int -spectre_presize (void *handle, void *device, int width, int height, - int raster, unsigned int format) -{ - SpectreDevice *sd; - - if (!handle) - return 0; - - sd = (SpectreDevice *)handle; - sd->width = width; - sd->height = height; - sd->row_length = raster; - sd->gs_image = NULL; - sd->user_image = malloc (sd->row_length * sd->height); - - return 0; -} - -static int -spectre_size (void *handle, void *device, int width, int height, int raster, - unsigned int format, unsigned char *pimage) -{ - SpectreDevice *sd; - - if (!handle) - return 0; - - sd = (SpectreDevice *)handle; - sd->gs_image = pimage; - - return 0; -} - -static int -spectre_sync (void *handle, void *device) -{ - return 0; -} - -static int -spectre_page (void *handle, void * device, int copies, int flush) -{ - SpectreDevice *sd; - - if (!handle) - return 0; - - sd = (SpectreDevice *)handle; - sd->page_called = TRUE; - memcpy (sd->user_image, sd->gs_image, sd->row_length * sd->height); - - return 0; -} - -static int -spectre_update (void *handle, void *device, int x, int y, int w, int h) -{ - SpectreDevice *sd; - int i; - - if (!handle) - return 0; - - sd = (SpectreDevice *)handle; - if (!sd->gs_image || sd->page_called || !sd->user_image) - return 0; - - for (i = y; i < y + h; ++i) { - memcpy (sd->user_image + sd->row_length * i + x * 4, - sd->gs_image + sd->row_length * i + x * 4, w * 4); - } - - return 0; -} - -static display_callback spectre_device = { - sizeof (display_callback), - DISPLAY_VERSION_MAJOR, - DISPLAY_VERSION_MINOR, - &spectre_open, - &spectre_preclose, - &spectre_close, - &spectre_presize, - &spectre_size, - &spectre_sync, - &spectre_page, - &spectre_update -}; - -SpectreDevice * -spectre_device_new (struct document *doc) -{ - SpectreDevice *device; - - device = calloc (1, sizeof (SpectreDevice)); - if (!device) - return NULL; - - device->doc = psdocreference (doc); - - return device; -} - -SpectreStatus -spectre_device_render (SpectreDevice *device, - unsigned int page, - SpectreRenderContext *rc, - unsigned char **page_data, - int *row_length) -{ - SpectreGS *gs; - char **args; - int n_args = 12; - int arg = 0; - int success; - char *text_alpha, *graph_alpha; - char *size = NULL; - char *resolution, *set; - char *dsp_format, *dsp_handle; - int urx, ury, llx, lly; - int page_width, page_height; - double x_scale, y_scale; - int width, height; - - gs = spectre_gs_new (); - if (!gs) - return SPECTRE_STATUS_NO_MEMORY; - - if (!spectre_gs_create_instance (gs, device)) { - spectre_gs_cleanup (gs, CLEANUP_DELETE_INSTANCE); - spectre_gs_free (gs); - - return SPECTRE_STATUS_RENDER_ERROR; - } - - if (!spectre_gs_set_display_callback (gs, &spectre_device)) { - spectre_gs_cleanup (gs, CLEANUP_DELETE_INSTANCE); - spectre_gs_free (gs); - - return SPECTRE_STATUS_RENDER_ERROR; - } - - psgetpagebox (device->doc, page, - &urx, &ury, &llx, &lly); - - page_width = (urx - llx); - page_height = (ury - lly); - - if (rc->width == -1 || rc->height == -1) { - width = page_width * rc->scale; - height = page_height * rc->scale; - } else { - width = rc->width; - height = rc->height; - } - - if (rc->scale == 1.0 && (width != page_width || height != page_height)) { - x_scale = width / (double)page_width; - y_scale = height / (double)page_height; - } else { - x_scale = y_scale = rc->scale; - } - - if (rc->use_platform_fonts == FALSE) - n_args++; - - args = calloc (sizeof (char *), n_args); - args[arg++] = "libspectre"; /* This value doesn't really matter */ - args[arg++] = "-dMaxBitmap=10000000"; - args[arg++] = "-dDELAYSAFER"; - args[arg++] = "-dNOPAUSE"; - args[arg++] = "-dNOPAGEPROMPT"; - args[arg++] = "-sDEVICE=display"; - args[arg++] = text_alpha =_spectre_strdup_printf("-dTextAlphaBits=%d", - rc->text_alpha_bits); - args[arg++] = graph_alpha = _spectre_strdup_printf("-dGraphicsAlphaBits=%d", - rc->graphic_alpha_bits); - args[arg++] = size =_spectre_strdup_printf ("-g%dx%d", width, height); - args[arg++] = resolution = _spectre_strdup_printf ("-r%fx%f", - x_scale * rc->x_dpi, - y_scale * rc->y_dpi); - args[arg++] = dsp_format = _spectre_strdup_printf ("-dDisplayFormat=%d", - DISPLAY_COLORS_RGB | - DISPLAY_UNUSED_LAST | - DISPLAY_DEPTH_8 | - DISPLAY_LITTLEENDIAN | - DISPLAY_TOPFIRST); - args[arg++] = dsp_handle = _spectre_strdup_printf ("-sDisplayHandle=16#%llx", - (unsigned long long int)device); - if (rc->use_platform_fonts == FALSE) - args[arg++] = "-dNOPLATFONTS"; - - success = spectre_gs_run (gs, n_args, args); - free (text_alpha); - free (graph_alpha); - free (size); - free (resolution); - free (dsp_format); - free (dsp_handle); - free (args); - if (!success) { - spectre_gs_free (gs); - return SPECTRE_STATUS_RENDER_ERROR; - } - - set = _spectre_strdup_printf ("<< /Orientation %d >> setpagedevice .locksafe", - rc->orientation); - if (!spectre_gs_send_string (gs, set)) { - free (set); - spectre_gs_free (gs); - return SPECTRE_STATUS_RENDER_ERROR; - } - free (set); - - if (!spectre_gs_send_page (gs, device->doc, page)) { - spectre_gs_free (gs); - return SPECTRE_STATUS_RENDER_ERROR; - } - - *page_data = device->user_image; - *row_length = device->row_length; - - spectre_gs_free (gs); - - return SPECTRE_STATUS_SUCCESS; -} - -void -spectre_device_free (SpectreDevice *device) -{ - if (!device) - return; - - if (device->doc) { - psdocdestroy (device->doc); - device->doc = NULL; - } - - free (device); -} diff --git a/generators/spectre/libspectre/spectre-device.h b/generators/spectre/libspectre/spectre-device.h deleted file mode 100644 index 473c78161..000000000 --- a/generators/spectre/libspectre/spectre-device.h +++ /dev/null @@ -1,45 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef SPECTRE_DEVICE_H -#define SPECTRE_DEVICE_H - -#include -#include -#include - -#include "ps.h" - -SPECTRE_BEGIN_DECLS - -typedef struct SpectreDevice SpectreDevice; - -SpectreDevice *spectre_device_new (struct document *doc); -SpectreStatus spectre_device_render (SpectreDevice *device, - unsigned int page, - SpectreRenderContext *rc, - unsigned char **page_data, - int *row_length); -void spectre_device_free (SpectreDevice *device); - - -SPECTRE_END_DECLS - -#endif /* SPECTRE_DEVICE_H */ diff --git a/generators/spectre/libspectre/spectre-document.c b/generators/spectre/libspectre/spectre-document.c deleted file mode 100644 index 8427ec43c..000000000 --- a/generators/spectre/libspectre/spectre-document.c +++ /dev/null @@ -1,348 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include - -/* For stat */ -#include -#include -#include - -#include "spectre-document.h" -#include "spectre-private.h" -#include "spectre-exporter.h" - -struct SpectreDocument -{ - struct document *doc; - - SpectreStatus status; - - int structured; -}; - -SpectreDocument * -spectre_document_new (void) -{ - SpectreDocument *doc; - - doc = calloc (1, sizeof (SpectreDocument)); - return doc; -} - -void -spectre_document_load (SpectreDocument *document, - const char *filename) -{ - if (document->doc && strcmp (filename, document->doc->filename) == 0) { - document->status = SPECTRE_STATUS_SUCCESS; - return; - } - - if (document->doc) { - psdocdestroy (document->doc); - document->doc = NULL; - } - - document->doc = psscan (filename, SCANSTYLE_NORMAL); - if (!document->doc) { - /* FIXME: OOM | INVALID_PS */ - document->status = SPECTRE_STATUS_LOAD_ERROR; - return; - } - - document->structured = ((!document->doc->epsf && document->doc->numpages > 0) || - (document->doc->epsf && document->doc->numpages > 1)); - - if (document->status != SPECTRE_STATUS_SUCCESS) - document->status = SPECTRE_STATUS_SUCCESS; -} - -void -spectre_document_free (SpectreDocument *document) -{ - if (!document) - return; - - if (document->doc) { - psdocdestroy (document->doc); - document->doc = NULL; - } - - free (document); -} - -SpectreStatus -spectre_document_status (SpectreDocument *document) -{ - return document->status; -} - -unsigned int -spectre_document_get_n_pages (SpectreDocument *document) -{ - if (!document->doc) { - document->status = SPECTRE_STATUS_DOCUMENT_NOT_LOADED; - return 0; - } - - return document->structured ? document->doc->numpages : 1; -} - -SpectreOrientation -spectre_document_get_orientation (SpectreDocument *document) -{ - int doc_orientation; - - if (!document->doc) { - document->status = SPECTRE_STATUS_DOCUMENT_NOT_LOADED; - return SPECTRE_ORIENTATION_PORTRAIT; - } - - doc_orientation = document->doc->orientation != NONE ? - document->doc->orientation : document->doc->default_page_orientation; - - switch (doc_orientation) { - default: - case PORTRAIT: - return SPECTRE_ORIENTATION_PORTRAIT; - case LANDSCAPE: - return SPECTRE_ORIENTATION_LANDSCAPE; - case SEASCAPE: - return SPECTRE_ORIENTATION_REVERSE_LANDSCAPE; - case UPSIDEDOWN: - return SPECTRE_ORIENTATION_REVERSE_PORTRAIT; - } -} - -const char * -spectre_document_get_title (SpectreDocument *document) -{ - if (!document->doc) { - document->status = SPECTRE_STATUS_DOCUMENT_NOT_LOADED; - return NULL; - } - - return document->doc->title; -} - -const char * -spectre_document_get_creator (SpectreDocument *document) -{ - if (!document->doc) { - document->status = SPECTRE_STATUS_DOCUMENT_NOT_LOADED; - return NULL; - } - - return document->doc->creator; -} - -const char * -spectre_document_get_for (SpectreDocument *document) -{ - if (!document->doc) { - document->status = SPECTRE_STATUS_DOCUMENT_NOT_LOADED; - return NULL; - } - - return document->doc->fortext; -} - -const char * -spectre_document_get_creation_date (SpectreDocument *document) -{ - if (!document->doc) { - document->status = SPECTRE_STATUS_DOCUMENT_NOT_LOADED; - return NULL; - } - - return document->doc->date; -} - -const char * -spectre_document_get_format (SpectreDocument *document) -{ - if (!document->doc) { - document->status = SPECTRE_STATUS_DOCUMENT_NOT_LOADED; - return NULL; - } - - return document->doc->format; -} - -int -spectre_document_is_eps (SpectreDocument *document) -{ - if (!document->doc) { - document->status = SPECTRE_STATUS_DOCUMENT_NOT_LOADED; - return FALSE; - } - - return document->doc->epsf; -} - -unsigned int -spectre_document_get_language_level (SpectreDocument *document) -{ - if (!document->doc) { - document->status = SPECTRE_STATUS_DOCUMENT_NOT_LOADED; - return 0; - } - - return document->doc->languagelevel ? atoi (document->doc->languagelevel) : 0; -} - -SpectrePage * -spectre_document_get_page (SpectreDocument *document, - unsigned int page_index) -{ - SpectrePage *page; - - if (page_index >= spectre_document_get_n_pages (document)) { - document->status = SPECTRE_STATUS_INVALID_PAGE; - return NULL; - } - - page = _spectre_page_new (page_index, document->doc); - if (!page) { - document->status = SPECTRE_STATUS_NO_MEMORY; - return NULL; - } - - if (document->status != SPECTRE_STATUS_SUCCESS) - document->status = SPECTRE_STATUS_SUCCESS; - - return page; -} - -SpectrePage * -spectre_document_get_page_by_label (SpectreDocument *document, - const char *label) -{ - unsigned int i; - int page_index = -1; - - if (!label) { - document->status = SPECTRE_STATUS_INVALID_PAGE; - return NULL; - } - - for (i = 0; i < document->doc->numpages; i++) { - if (strcmp (document->doc->pages[i].label, label) == 0) { - page_index = i; - break; - } - } - - if (page_index == -1) { - document->status = SPECTRE_STATUS_INVALID_PAGE; - return NULL; - } - - return spectre_document_get_page (document, page_index); -} - -void -spectre_document_save (SpectreDocument *document, - const char *filename) -{ - struct stat stat_buf; - FILE *from; - FILE *to; - - if (stat (document->doc->filename, &stat_buf) != 0) { - document->status = SPECTRE_STATUS_SAVE_ERROR; - return; - } - - from = fopen (document->doc->filename, "r"); - if (!from) { - document->status = SPECTRE_STATUS_SAVE_ERROR; - return; - } - - to = fopen (filename, "w"); - if (!to) { - document->status = SPECTRE_STATUS_SAVE_ERROR; - fclose (from); - return; - } - - pscopy (from, to, document->doc, 0, stat_buf.st_size - 1); - - fclose (from); - fclose (to); - - document->status = SPECTRE_STATUS_SUCCESS; -} - -void -spectre_document_save_to_pdf (SpectreDocument *document, - const char *filename) -{ - SpectreExporter *exporter; - SpectreStatus status; - unsigned int i; - - exporter = spectre_exporter_new (document, SPECTRE_EXPORTER_FORMAT_PDF); - if (!exporter) { - document->status = SPECTRE_STATUS_NO_MEMORY; - return; - } - - status = spectre_exporter_begin (exporter, filename); - if (status) { - document->status = status == SPECTRE_STATUS_NO_MEMORY ? - SPECTRE_STATUS_NO_MEMORY : SPECTRE_STATUS_SAVE_ERROR; - spectre_exporter_free (exporter); - return; - } - - for (i = 0; i < spectre_document_get_n_pages (document); i++) { - status = spectre_exporter_do_page (exporter, i); - if (status) - break; - } - - if (status) { - document->status = status == SPECTRE_STATUS_NO_MEMORY ? - SPECTRE_STATUS_NO_MEMORY : SPECTRE_STATUS_SAVE_ERROR; - spectre_exporter_free (exporter); - return; - } - - status = spectre_exporter_end (exporter); - spectre_exporter_free (exporter); - - if (status) { - document->status = status == SPECTRE_STATUS_NO_MEMORY ? - SPECTRE_STATUS_NO_MEMORY : SPECTRE_STATUS_SAVE_ERROR; - } else { - document->status = SPECTRE_STATUS_SUCCESS; - } -} - -struct document * -_spectre_document_get_doc (SpectreDocument *document) -{ - return document->doc; -} diff --git a/generators/spectre/libspectre/spectre-document.h b/generators/spectre/libspectre/spectre-document.h deleted file mode 100644 index d530631ec..000000000 --- a/generators/spectre/libspectre/spectre-document.h +++ /dev/null @@ -1,146 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef SPECTRE_DOCUMENT_H -#define SPECTRE_DOCUMENT_H - -#include -#include -#include - -SPECTRE_BEGIN_DECLS - -/*! This is the object that represents a PostScript document. */ -typedef struct SpectreDocument SpectreDocument; - -/*! Creates a document */ -SpectreDocument *spectre_document_new (void); - -/*! Loads a the given file into the document. This function can fail - @param document the document where the file will be loaded - @param filename the file to loa - @see spectre_document_status -*/ -void spectre_document_load (SpectreDocument *document, - const char *filename); - -/*! Returns the document status - @param document the document whose status will be returned -*/ -SpectreStatus spectre_document_status (SpectreDocument *document); - -/*! Frees the document - @param document the document that will be freed -*/ -void spectre_document_free (SpectreDocument *document); - -/*! Returns the number of pages of the document. This function can fail - @param document the document whose pages number will be returned - @see spectre_document_status -*/ -unsigned int spectre_document_get_n_pages (SpectreDocument *document); - -/*! Returns the orientation of the document. This function can fail - @param document the document whose orientation will be returned - @see spectre_document_status -*/ -SpectreOrientation spectre_document_get_orientation (SpectreDocument *document); - -/*! Returns the title of the document. It returns a null const char * if - the document specifies no title. This function can fail - @param document the document whose title will be returned - @see spectre_document_status -*/ -const char *spectre_document_get_title (SpectreDocument *document); - -/*! Returns the creator of the document. It returns a null const char * if - the document specifies no creator. This function can fail - @param document the document whose creator will be returned - @see spectre_document_status -*/ -const char *spectre_document_get_creator (SpectreDocument *document); - -/*! Returns the for of the document. It returns a null const char * if - the document specifies no for. This function can fail - @param document the document whose for will be returned - @see spectre_document_status -*/ -const char *spectre_document_get_for (SpectreDocument *document); - -/*! Returns the creation date of the document. The date is copied verbatim from - the document, so no format can be assumed on it. It returns a null const char * if - the document specifies no creation date. This function can fail - @param document the document whose creation date will be returned - @see spectre_document_status -*/ -const char *spectre_document_get_creation_date (SpectreDocument *document); - -/*! Returns the format of the document. This function can fail - @param document the document whose format will be returned - @see spectre_document_status -*/ -const char *spectre_document_get_format (SpectreDocument *document); - -/*! Returns if the document is a Encapsulated PostScript file. This function can fail - @param document the document to query - @see spectre_document_status -*/ -int spectre_document_is_eps (SpectreDocument *document); - -/*! Returns the PostScript language level of the document. It returns 0 if no - language level was defined on the file. This function can fail - @param document the document whose language level will be returned - @see spectre_document_status -*/ -unsigned int spectre_document_get_language_level (SpectreDocument *document); - -/*! Returns a page of the document. This function can fail - @param document the document whose page will be returned - @param page_index the page index to get. First page has index 0. - @see spectre_document_status -*/ -SpectrePage *spectre_document_get_page (SpectreDocument *document, - unsigned int page_index); - -/*! Returns a page of the document referenced by label. This function can fail - @param document the document whose page will be returned - @param label the label of the page to get. - @see spectre_document_status -*/ -SpectrePage *spectre_document_get_page_by_label (SpectreDocument *document, - const char *label); - -/*! Save document as filename. This function can fail - @param document the document that will be saved - @param filename the path where document will be saved - @see spectre_document_status -*/ -void spectre_document_save (SpectreDocument *document, - const char *filename); -/* Save document as a pdf document. This function can fail - @param document the document that will be saved - @param filename the path where document will be saved as pdf - @see spectre_document_status -*/ -void spectre_document_save_to_pdf (SpectreDocument *document, - const char *filename); -SPECTRE_END_DECLS - -#endif /* SPECTRE_DOCUMENT_H */ diff --git a/generators/spectre/libspectre/spectre-exporter-pdf.c b/generators/spectre/libspectre/spectre-exporter-pdf.c deleted file mode 100644 index fbced767d..000000000 --- a/generators/spectre/libspectre/spectre-exporter-pdf.c +++ /dev/null @@ -1,105 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include "spectre-private.h" -#include "spectre-utils.h" - -static SpectreStatus -spectre_exporter_pdf_begin (SpectreExporter *exporter, - const char *filename) -{ - char *args[8]; - int arg = 0; - char *output_file; - - exporter->gs = spectre_gs_new (); - if (!spectre_gs_create_instance (exporter->gs, NULL)) { - spectre_gs_cleanup (exporter->gs, CLEANUP_DELETE_INSTANCE); - spectre_gs_free (exporter->gs); - exporter->gs = NULL; - - return SPECTRE_STATUS_EXPORTER_ERROR; - } - - args[arg++] = "-dMaxBitmap=10000000"; - args[arg++] = "-dBATCH"; - args[arg++] = "-dNOPAUSE"; - args[arg++] = "-dSAFER"; - args[arg++] = "-sDEVICE=pdfwrite"; - args[arg++] = output_file = _spectre_strdup_printf ("-sOutputFile=%s", - filename); - args[arg++] = "-c"; - args[arg++] = ".setpdfwrite"; - - if (!spectre_gs_run (exporter->gs, 8, args)) { - free (output_file); - spectre_gs_free (exporter->gs); - exporter->gs = NULL; - - return SPECTRE_STATUS_EXPORTER_ERROR; - } - - free (output_file); - - return SPECTRE_STATUS_SUCCESS; -} - -static SpectreStatus -spectre_exporter_pdf_do_page (SpectreExporter *exporter, - unsigned int page_index) -{ - if (!spectre_gs_send_page (exporter->gs, exporter->doc, page_index)) { - spectre_gs_free (exporter->gs); - exporter->gs = NULL; - - return SPECTRE_STATUS_EXPORTER_ERROR; - } - - return SPECTRE_STATUS_SUCCESS; -} - -static SpectreStatus -spectre_exporter_pdf_end (SpectreExporter *exporter) -{ - spectre_gs_free (exporter->gs); - exporter->gs = NULL; - - return SPECTRE_STATUS_SUCCESS; -} - -SpectreExporter * -_spectre_exporter_pdf_new (struct document *doc) -{ - SpectreExporter *exporter; - - exporter = calloc (1, sizeof (SpectreExporter)); - if (!exporter) - return NULL; - - exporter->doc = psdocreference (doc); - - exporter->begin = spectre_exporter_pdf_begin; - exporter->do_page = spectre_exporter_pdf_do_page; - exporter->end = spectre_exporter_pdf_end; - - return exporter; -} diff --git a/generators/spectre/libspectre/spectre-exporter-ps.c b/generators/spectre/libspectre/spectre-exporter-ps.c deleted file mode 100644 index 46d630a19..000000000 --- a/generators/spectre/libspectre/spectre-exporter-ps.c +++ /dev/null @@ -1,88 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include "spectre-private.h" - -static SpectreStatus -spectre_exporter_ps_begin (SpectreExporter *exporter, - const char *filename) -{ - exporter->from = fopen (exporter->doc->filename, "r"); - if (!exporter->from) - return SPECTRE_STATUS_EXPORTER_ERROR; - - exporter->to = fopen (filename, "w"); - if (!exporter->to) { - fclose (exporter->from); - exporter->from = NULL; - return SPECTRE_STATUS_EXPORTER_ERROR; - } - - pscopyheaders (exporter->from, exporter->to, exporter->doc); - - return SPECTRE_STATUS_SUCCESS; -} - -static SpectreStatus -spectre_exporter_ps_do_page (SpectreExporter *exporter, - unsigned int page_index) -{ - if (exporter->doc->numpages <= 0) - return SPECTRE_STATUS_SUCCESS; - - pscopypage (exporter->from, exporter->to, exporter->doc, - page_index, exporter->n_pages++); - - return SPECTRE_STATUS_SUCCESS; -} - -static SpectreStatus -spectre_exporter_ps_end (SpectreExporter *exporter) -{ - pscopytrailer (exporter->from, exporter->to, exporter->doc, - exporter->n_pages); - - fclose (exporter->from); - exporter->from = NULL; - fclose (exporter->to); - exporter->to = NULL; - - return SPECTRE_STATUS_SUCCESS; -} - -SpectreExporter * -_spectre_exporter_ps_new (struct document *doc) -{ - SpectreExporter *exporter; - - exporter = calloc (1, sizeof (SpectreExporter)); - if (!exporter) - return NULL; - - exporter->doc = psdocreference (doc); - - exporter->begin = spectre_exporter_ps_begin; - exporter->do_page = spectre_exporter_ps_do_page; - exporter->end = spectre_exporter_ps_end; - - return exporter; -} diff --git a/generators/spectre/libspectre/spectre-exporter.c b/generators/spectre/libspectre/spectre-exporter.c deleted file mode 100644 index 3d696aff6..000000000 --- a/generators/spectre/libspectre/spectre-exporter.c +++ /dev/null @@ -1,100 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include "spectre-exporter.h" -#include "spectre-private.h" - -SpectreExporter * -spectre_exporter_new (SpectreDocument *document, - SpectreExporterFormat format) -{ - struct document *doc; - - if (!document) - return NULL; - - doc = _spectre_document_get_doc (document); - - switch (format) { - case SPECTRE_EXPORTER_FORMAT_PS: - return _spectre_exporter_ps_new (doc); - case SPECTRE_EXPORTER_FORMAT_PDF: - return _spectre_exporter_pdf_new (doc); - } - - return NULL; -} - -void -spectre_exporter_free (SpectreExporter *exporter) -{ - if (!exporter) - return; - - if (exporter->doc) { - psdocdestroy (exporter->doc); - exporter->doc = NULL; - } - - if (exporter->gs) { - spectre_gs_free (exporter->gs); - exporter->gs = NULL; - } - - if (exporter->from) { - fclose (exporter->from); - exporter->from = NULL; - } - - if (exporter->to) { - fclose (exporter->to); - exporter->to = NULL; - } - - free (exporter); -} - -SpectreStatus -spectre_exporter_begin (SpectreExporter *exporter, - const char *filename) -{ - if (exporter->begin) - return exporter->begin (exporter, filename); - - return SPECTRE_STATUS_SUCCESS; -} - -SpectreStatus -spectre_exporter_do_page (SpectreExporter *exporter, - unsigned int page_index) -{ - return exporter->do_page (exporter, page_index); -} - -SpectreStatus -spectre_exporter_end (SpectreExporter *exporter) -{ - if (exporter->end) - return exporter->end (exporter); - - return SPECTRE_STATUS_SUCCESS; -} diff --git a/generators/spectre/libspectre/spectre-exporter.h b/generators/spectre/libspectre/spectre-exporter.h deleted file mode 100644 index aed8c7b27..000000000 --- a/generators/spectre/libspectre/spectre-exporter.h +++ /dev/null @@ -1,49 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef SPECTRE_EXPORTER_H -#define SPECTRE_EXPORTER_H - -#include -#include -#include - -SPECTRE_BEGIN_DECLS - -typedef enum { - SPECTRE_EXPORTER_FORMAT_PS, - SPECTRE_EXPORTER_FORMAT_PDF -} SpectreExporterFormat; - -typedef struct SpectreExporter SpectreExporter; - -SpectreExporter *spectre_exporter_new (SpectreDocument *document, - SpectreExporterFormat format); -void spectre_exporter_free (SpectreExporter *exporter); -SpectreStatus spectre_exporter_begin (SpectreExporter *exporter, - const char *filename); -SpectreStatus spectre_exporter_do_page (SpectreExporter *exporter, - unsigned int page_index); -SpectreStatus spectre_exporter_end (SpectreExporter *exporter); - - -SPECTRE_END_DECLS - -#endif /* SPECTRE_EXPORTER_H */ diff --git a/generators/spectre/libspectre/spectre-gs.c b/generators/spectre/libspectre/spectre-gs.c deleted file mode 100644 index 81ea704c4..000000000 --- a/generators/spectre/libspectre/spectre-gs.c +++ /dev/null @@ -1,278 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include - -#include "spectre-gs.h" -#include "spectre-utils.h" - -/* ghostscript stuff */ -#include "ghostscript/iapi.h" -#include "ghostscript/ierrors.h" - -#define BUFFER_SIZE 32768 - -struct SpectreGS { - void *ghostscript_instance; -}; - -static int -critic_error_code (int code) -{ - if (code >= 0) - return FALSE; - - if (code <= -100) { - switch (code) { - case e_Fatal: - fprintf (stderr, "fatal internal error %d", code); - return TRUE; - break; - - case e_ExecStackUnderflow: - fprintf (stderr, "stack overflow %d", code); - return TRUE; - break; - - /* no error or not important */ - default: - return FALSE; - } - } else { - const char *errors[] = { "", ERROR_NAMES }; - int x = (-1) * code; - - if (x < (int) (sizeof (errors) / sizeof (const char*))) { - fprintf (stderr, "%s %d\n", errors[x], code); - } - return TRUE; - } -} - -static int -spectre_gs_process (SpectreGS *gs, - const char *filename, - int x, - int y, - long begin, - long end) -{ - FILE *fd; - int error; - static char buf[BUFFER_SIZE]; - unsigned int read; - int wrote; - size_t left = end - begin; - void *ghostscript_instance = gs->ghostscript_instance; - - fd = fopen (filename, "r"); - if (!fd) { - return FALSE; - } - - fseek (fd, begin, SEEK_SET); - - gsapi_run_string_begin (ghostscript_instance, 0, &error); - if (critic_error_code (error)) { - fclose (fd); - return FALSE; - } - - if (x != 0 && y != 0) { - char *set; - - set = _spectre_strdup_printf ("%d %d translate\n", -x, -y); - gsapi_run_string_continue (ghostscript_instance, set, strlen (set), - 0, &error); - free (set); - if (critic_error_code (error)) { - fclose (fd); - return FALSE; - } - } - - while (left > 0 && !critic_error_code (error)) { - size_t to_read = BUFFER_SIZE; - - if (left < to_read) - to_read = left; - - read = fread (buf, sizeof (char), to_read, fd); - wrote = gsapi_run_string_continue (ghostscript_instance, - buf, read, 0, &error); - left -= read; - } - - fclose (fd); - if (critic_error_code (error)) - return FALSE; - - gsapi_run_string_end (ghostscript_instance, 0, &error); - if (critic_error_code (error)) - return FALSE; - - return TRUE; -} - -SpectreGS * -spectre_gs_new (void) -{ - SpectreGS *gs; - - gs = calloc (1, sizeof (SpectreGS)); - - return gs; -} - -int -spectre_gs_create_instance (SpectreGS *gs, - void *caller_handle) -{ - int error; - - error = gsapi_new_instance (&gs->ghostscript_instance, caller_handle); - - return !critic_error_code (error); -} - -int -spectre_gs_set_display_callback (SpectreGS *gs, - void *callback) -{ - int error; - - error = gsapi_set_display_callback (gs->ghostscript_instance, - callback); - return !critic_error_code (error); -} - -int -spectre_gs_run (SpectreGS *gs, - int n_args, - char **args) -{ - int error; - - error = gsapi_init_with_args (gs->ghostscript_instance, n_args, args); - - return !critic_error_code (error); -} - -int -spectre_gs_send_string (SpectreGS *gs, - const char *str) -{ - int error; - - gsapi_run_string_with_length (gs->ghostscript_instance, - str, strlen (str), 0, &error); - - return !critic_error_code (error); -} - -int -spectre_gs_send_page (SpectreGS *gs, - struct document *doc, - unsigned int page_index) -{ - int doc_llx = 0, doc_lly = 0; - int page_llx = 0, page_lly = 0; - - if ((doc->boundingbox[URX] > doc->boundingbox[LLX]) && - (doc->boundingbox[URY] > doc->boundingbox[LLY])) { - doc_llx = doc->boundingbox[LLX]; - doc_lly = doc->boundingbox[LLY]; - } - - if (doc->numpages > 0 && - (doc->pages[page_index].boundingbox[URX] > - doc->pages[page_index].boundingbox[LLX]) && - (doc->pages[page_index].boundingbox[URY] > - doc->pages[page_index].boundingbox[LLY])) { - /* Do not translate twice */ - if (doc->pages[page_index].boundingbox[LLX] != doc_llx && - doc->pages[page_index].boundingbox[LLY] != doc_lly) { - page_llx = doc->pages[page_index].boundingbox[LLX]; - page_lly = doc->pages[page_index].boundingbox[LLY]; - } - } - - if (!spectre_gs_process (gs, - doc->filename, - doc_llx, doc_lly, - doc->beginprolog, - doc->endprolog)) - return FALSE; - - if (!spectre_gs_process (gs, - doc->filename, - 0, 0, - doc->beginsetup, - doc->endsetup)) - return FALSE; - - if (doc->numpages > 0) { - if (!spectre_gs_process (gs, - doc->filename, - page_llx, page_lly, - doc->pages[page_index].begin, - doc->pages[page_index].end)) - return FALSE; - } - - if (!spectre_gs_process (gs, - doc->filename, - 0, 0, - doc->begintrailer, - doc->endtrailer)) - return FALSE; - - return TRUE; -} - -void -spectre_gs_cleanup (SpectreGS *gs, - SpectreGSCleanupFlag flag) -{ - if (gs->ghostscript_instance == NULL) - return; - - if (flag & CLEANUP_EXIT) - gsapi_exit (gs->ghostscript_instance); - - if (flag & CLEANUP_DELETE_INSTANCE) - gsapi_delete_instance (gs->ghostscript_instance); - - gs->ghostscript_instance = NULL; -} - -void -spectre_gs_free (SpectreGS *gs) -{ - if (!gs) - return; - - spectre_gs_cleanup (gs, - CLEANUP_DELETE_INSTANCE | - CLEANUP_EXIT); - free (gs); -} diff --git a/generators/spectre/libspectre/spectre-gs.h b/generators/spectre/libspectre/spectre-gs.h deleted file mode 100644 index df0ad4f04..000000000 --- a/generators/spectre/libspectre/spectre-gs.h +++ /dev/null @@ -1,56 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef SPECTRE_GS_H -#define SPECTRE_GS_H - -#include - -#include "ps.h" - -SPECTRE_BEGIN_DECLS - -typedef enum { - CLEANUP_DELETE_INSTANCE = 1 << 0, - CLEANUP_EXIT = 1 << 1 -} SpectreGSCleanupFlag; - -typedef struct SpectreGS SpectreGS; - -SpectreGS *spectre_gs_new (void); -int spectre_gs_create_instance (SpectreGS *gs, - void *caller_handle); -int spectre_gs_set_display_callback (SpectreGS *gs, - void *callback); -int spectre_gs_run (SpectreGS *gs, - int n_args, - char **args); -int spectre_gs_send_string (SpectreGS *gs, - const char *str); -int spectre_gs_send_page (SpectreGS *gs, - struct document *doc, - unsigned int page_index); -void spectre_gs_cleanup (SpectreGS *gs, - SpectreGSCleanupFlag flag); -void spectre_gs_free (SpectreGS *gs); - -SPECTRE_END_DECLS - -#endif /* SPECTRE_GS_H */ diff --git a/generators/spectre/libspectre/spectre-macros.h b/generators/spectre/libspectre/spectre-macros.h deleted file mode 100644 index 65152bc53..000000000 --- a/generators/spectre/libspectre/spectre-macros.h +++ /dev/null @@ -1,47 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef SPECTRE_MACROS_H -#define SPECTRE_MACROS_H - -#ifdef __cplusplus -# define SPECTRE_BEGIN_DECLS extern "C" { -# define SPECTRE_END_DECLS } -#else -# define SPECTRE_BEGIN_DECLS -# define SPECTRE_END_DECLS -#endif - -#ifndef TRUE -# define TRUE 1 -#endif -#ifndef FALSE -# define FALSE 0 -#endif - -#ifndef NULL -# ifdef __cplusplus -# define NULL (0L) -# else /* !__cplusplus */ -# define NULL ((void*) 0) -# endif /* !__cplusplus */ -#endif - -#endif /* SPECTRE_MACROS_H */ diff --git a/generators/spectre/libspectre/spectre-page.c b/generators/spectre/libspectre/spectre-page.c deleted file mode 100644 index ca9c73cdc..000000000 --- a/generators/spectre/libspectre/spectre-page.c +++ /dev/null @@ -1,146 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include - -#include "spectre-page.h" - -#include "spectre-device.h" -#include "spectre-private.h" - -struct SpectrePage -{ - struct document *doc; - - SpectreStatus status; - - unsigned int index; -}; - -SpectrePage * -_spectre_page_new (unsigned int page_index, - struct document *doc) -{ - SpectrePage *page; - - page = calloc (1, sizeof (SpectrePage)); - if (!page) - return NULL; - - page->index = page_index; - page->doc = psdocreference (doc); - - return page; -} - -void -spectre_page_free (SpectrePage *page) -{ - if (!page) - return; - - if (page->doc) { - psdocdestroy (page->doc); - page->doc = NULL; - } - - free (page); -} - -SpectreStatus -spectre_page_status (SpectrePage *page) -{ - return page->status; -} - -unsigned int -spectre_page_get_index (SpectrePage *page) -{ - return page->index; -} - -const char * -spectre_page_get_label (SpectrePage *page) -{ - return page->doc->numpages > 0 ? page->doc->pages[page->index].label : NULL; -} - -SpectreOrientation -spectre_page_get_orientation (SpectrePage *page) -{ - int page_orientation = NONE; - - if (page->doc->numpages > 0) { - page_orientation = page->doc->pages[page->index].orientation != NONE ? - page->doc->pages[page->index].orientation : - page->doc->default_page_orientation; - } - - if (page_orientation == NONE) - page_orientation = page->doc->orientation; - - switch (page_orientation) { - default: - case PORTRAIT: - return SPECTRE_ORIENTATION_PORTRAIT; - case LANDSCAPE: - return SPECTRE_ORIENTATION_LANDSCAPE; - case SEASCAPE: - return SPECTRE_ORIENTATION_REVERSE_LANDSCAPE; - case UPSIDEDOWN: - return SPECTRE_ORIENTATION_REVERSE_PORTRAIT; - } -} - -void -spectre_page_get_size (SpectrePage *page, - int *width, - int *height) -{ - int urx, ury, llx, lly; - - psgetpagebox (page->doc, page->index, - &urx, &ury, &llx, &lly); - - if (width) - *width = urx - llx; - if (height) - *height = ury - lly; -} - -void -spectre_page_render (SpectrePage *page, - SpectreRenderContext *rc, - unsigned char **page_data, - int *row_length) -{ - SpectreDevice *device; - - if (!rc) - return; - - device = spectre_device_new (page->doc); - - page->status = spectre_device_render (device, page->index, rc, - page_data, row_length); - - spectre_device_free (device); -} diff --git a/generators/spectre/libspectre/spectre-page.h b/generators/spectre/libspectre/spectre-page.h deleted file mode 100644 index 7a1becd59..000000000 --- a/generators/spectre/libspectre/spectre-page.h +++ /dev/null @@ -1,93 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef SPECTRE_PAGE_H -#define SPECTRE_PAGE_H - -#include -#include -#include - -SPECTRE_BEGIN_DECLS - -typedef enum { - SPECTRE_ORIENTATION_PORTRAIT /*! Vertical orientation */, - SPECTRE_ORIENTATION_LANDSCAPE /*! Horizontal orientation */, - SPECTRE_ORIENTATION_REVERSE_PORTRAIT /*! Inverse vertical orientation */, - SPECTRE_ORIENTATION_REVERSE_LANDSCAPE /*! Inverse horizontal orientation, - also known as Seascape */ -} SpectreOrientation; - -/*! This is the object that represents a page of a PostScript document. - They can not be created directly and can only be obtained from - ::spectre_document_get_page */ -typedef struct SpectrePage SpectrePage; - -/*! Returns the status of the given page - @param page The page whose status will be returned -*/ -SpectreStatus spectre_page_status (SpectrePage *page); - -/*! Frees the memory of the given page - @param page The page whose memory will be freed -*/ -void spectre_page_free (SpectrePage *page); - -/*! Returns the index of the page inside the document. First page has index 0 - @param page The page whose index will be returned -*/ -unsigned int spectre_page_get_index (SpectrePage *page); - -/*! Returns the label of the page inside the document. - @param page The page whose label will be returned -*/ -const char *spectre_page_get_label (SpectrePage *page); - -/*! Returns the orientation of the page - @param page The page whose orientation will be returned -*/ -SpectreOrientation spectre_page_get_orientation (SpectrePage *page); - -/*! Returns the size of the page - @param page The page whose size will be returned - @param width The page width will be returned here - @param height The page height will be returned here -*/ -void spectre_page_get_size (SpectrePage *page, - int *width, - int *height); - -/*! Renders the page to RGB32 format. This function can fail - @param page The page to renderer - @param rc The rendering context specifying how the page has to be rendered - @param page_data A pointer that will point to the image data - if the call succeeds - @param row_length The length of an image row will be returned here. It can - happen that row_length is different than width * 4 - @see spectre_page_status -*/ -void spectre_page_render (SpectrePage *page, - SpectreRenderContext *rc, - unsigned char **page_data, - int *row_length); - -SPECTRE_END_DECLS - -#endif /* SPECTRE_PAGE_H */ diff --git a/generators/spectre/libspectre/spectre-private.h b/generators/spectre/libspectre/spectre-private.h deleted file mode 100644 index 09ce12013..000000000 --- a/generators/spectre/libspectre/spectre-private.h +++ /dev/null @@ -1,73 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef SPECTRE_PRIVATE_H -#define SPECTRE_PRIVATE_H - -#include "spectre-macros.h" -#include "spectre-status.h" -#include "spectre-document.h" -#include "spectre-page.h" -#include "spectre-exporter.h" -#include "spectre-gs.h" -#include "ps.h" - -SPECTRE_BEGIN_DECLS - -struct SpectreRenderContext { - double scale; - SpectreOrientation orientation; - double x_dpi; - double y_dpi; - int width; - int height; - int text_alpha_bits; - int graphic_alpha_bits; - int use_platform_fonts; -}; - -struct SpectreExporter { - struct document *doc; - - /* PDF specific */ - SpectreGS *gs; - - /* PS specific */ - FILE *from; - FILE *to; - int n_pages; - - - SpectreStatus (* begin) (SpectreExporter *exporter, - const char *filename); - SpectreStatus (* do_page) (SpectreExporter *exporter, - unsigned int page_index); - SpectreStatus (* end) (SpectreExporter *exporter); -}; - -SpectrePage *_spectre_page_new (unsigned int page_index, - struct document *doc); -struct document *_spectre_document_get_doc (SpectreDocument *document); -SpectreExporter *_spectre_exporter_ps_new (struct document *doc); -SpectreExporter *_spectre_exporter_pdf_new (struct document *doc); - -SPECTRE_END_DECLS - -#endif /* SPECTRE_PRIVATE_H */ diff --git a/generators/spectre/libspectre/spectre-render-context.c b/generators/spectre/libspectre/spectre-render-context.c deleted file mode 100644 index 3bca432be..000000000 --- a/generators/spectre/libspectre/spectre-render-context.c +++ /dev/null @@ -1,210 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2; or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not; write to the Free Software - * Foundation; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include "spectre-render-context.h" -#include "spectre-page.h" -#include "spectre-private.h" - -SpectreRenderContext * -spectre_render_context_new (void) -{ - SpectreRenderContext *rc; - - rc = malloc (sizeof (SpectreRenderContext)); - - rc->scale = 1.0; - rc->orientation = 0; - rc->x_dpi = 72.0; - rc->y_dpi = 72.0; - rc->width = -1; - rc->height = -1; - rc->text_alpha_bits = 4; - rc->graphic_alpha_bits = 2; - rc->use_platform_fonts = TRUE; - - return rc; -} - -void -spectre_render_context_free (SpectreRenderContext *rc) -{ - if (!rc) - return; - - free (rc); -} - -void -spectre_render_context_set_scale (SpectreRenderContext *rc, - double scale) -{ - if (!rc) - return; - - rc->scale = scale; -} - -double -spectre_render_context_get_scale (SpectreRenderContext *rc) -{ - if (!rc) - return 1.0; - - return rc->scale; -} - -void -spectre_render_context_set_rotation (SpectreRenderContext *rc, - unsigned int rotation) -{ - if (!rc) - return; - - rotation %= 360; - - if (rotation >= 0 && rotation < 90) - rc->orientation = SPECTRE_ORIENTATION_PORTRAIT; - else if (rotation >= 90 && rotation < 180) - rc->orientation = SPECTRE_ORIENTATION_LANDSCAPE; - else if (rotation >= 180 && rotation < 270) - rc->orientation = SPECTRE_ORIENTATION_REVERSE_PORTRAIT; - else if (rotation >= 270 && rotation < 360) - rc->orientation = SPECTRE_ORIENTATION_REVERSE_LANDSCAPE; -} - -unsigned int -spectre_render_context_get_rotation (SpectreRenderContext *rc) -{ - if (!rc) - return 0; - - switch (rc->orientation) { - default: - case SPECTRE_ORIENTATION_PORTRAIT: - return 0; - case SPECTRE_ORIENTATION_LANDSCAPE: - return 90; - case SPECTRE_ORIENTATION_REVERSE_PORTRAIT: - return 180; - case SPECTRE_ORIENTATION_REVERSE_LANDSCAPE: - return 270; - } - - return 0; -} - -void -spectre_render_context_set_resolution (SpectreRenderContext *rc, - double x_dpi, - double y_dpi) -{ - if (!rc) - return; - - rc->x_dpi = x_dpi; - rc->y_dpi = y_dpi; -} - -void -spectre_render_context_get_resolution (SpectreRenderContext *rc, - double *x_dpi, - double *y_dpi) -{ - if (!rc) - return; - - if (x_dpi) - *x_dpi = rc->x_dpi; - if (y_dpi) - *y_dpi = rc->y_dpi; -} - -void -spectre_render_context_set_page_size (SpectreRenderContext *rc, - int width, - int height) -{ - if (!rc) - return; - - rc->width = width; - rc->height = height; -} - -void -spectre_render_context_get_page_size (SpectreRenderContext *rc, - int *width, - int *height) -{ - if (!rc) - return; - - if (width) - *width = rc->width; - if (height) - *height = rc->height; -} - -void -spectre_render_context_set_use_platform_fonts (SpectreRenderContext *rc, - int use_platform_fonts) -{ - if (!rc) - return; - - rc->use_platform_fonts = use_platform_fonts; -} - -int -spectre_render_context_get_use_platform_fonts (SpectreRenderContext *rc) -{ - if (!rc) - return 0; - - return rc->use_platform_fonts; -} - -void -spectre_render_context_set_antialias_bits (SpectreRenderContext *rc, - int graphics_bits, - int text_bits) -{ - if (!rc) - return; - - rc->graphic_alpha_bits = graphics_bits; - rc->text_alpha_bits = text_bits; -} - -void -spectre_render_context_get_antialias_bits (SpectreRenderContext *rc, - int *graphics_bits, - int *text_bits) -{ - if (!rc) - return; - - if (graphics_bits) - *graphics_bits = rc->graphic_alpha_bits; - if (text_bits) - *text_bits = rc->text_alpha_bits; -} diff --git a/generators/spectre/libspectre/spectre-render-context.h b/generators/spectre/libspectre/spectre-render-context.h deleted file mode 100644 index 578401cad..000000000 --- a/generators/spectre/libspectre/spectre-render-context.h +++ /dev/null @@ -1,133 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2; or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not; write to the Free Software - * Foundation; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef SPECTRE_RENDER_CONTEXT_H -#define SPECTRE_RENDER_CONTEXT_H - -#include - -SPECTRE_BEGIN_DECLS - -/*! This object defines how a page will be rendered */ -typedef struct SpectreRenderContext SpectreRenderContext; - -/*! Creates a rendering context */ -SpectreRenderContext *spectre_render_context_new (void); - -/*! Frees a rendering context - @param rc The rendering context to free -*/ -void spectre_render_context_free (SpectreRenderContext *rc); - -/*! Sets the scale. The default is 1 - @param rc The rendering context to modify - @param scale The scale to use when rendering. 2 is twice as big -*/ -void spectre_render_context_set_scale (SpectreRenderContext *rc, - double scale); - -/*! Gets the scale - @param rc The rendering context to query -*/ -double spectre_render_context_get_scale (SpectreRenderContext *rc); - -/*! Sets the rotation. The default is 0 - @param rc The rendering context to modify - @param rotation The rotation to use when rendering. Usually 0, 90, 180 or 270 -*/ -void spectre_render_context_set_rotation (SpectreRenderContext *rc, - unsigned int rotation); - -/*! Gets the rotation - @param rc The rendering context to query -*/ -unsigned int spectre_render_context_get_rotation (SpectreRenderContext *rc); - -/*! Sets the resolution. The default is 72 for both directions - @param rc The rendering context to modify - @param x_dpi the horizontal resolution to set - @param y_dpi the vertical resolution to set -*/ -void spectre_render_context_set_resolution (SpectreRenderContext *rc, - double x_dpi, - double y_dpi); - -/*! Gets the resolution - @param rc The rendering context to query - @param x_dpi the horizontal resolution will be stored here - @param y_dpi the vertical resolution will be stored here -*/ -void spectre_render_context_get_resolution (SpectreRenderContext *rc, - double *x_dpi, - double *y_dpi); - -/*! Sets the page size in pixels - @param rc The rendering context to modify - @param width the width of the page - @param height the height of the page -*/ -void spectre_render_context_set_page_size (SpectreRenderContext *rc, - int width, - int height); - -/*! Gets the page size in pixels - @param rc The rendering context to query - @param width the width of the page will be stored here - @param height the height of the page will be stored here -*/ -void spectre_render_context_get_page_size (SpectreRenderContext *rc, - int *width, - int *height); - -/*! Sets wheter to use the platform fonts when rendering or not. The default is TRUE - @param rc The rendering context to modify - @param use_platform_fonts should platform fonts be used when rendering? -*/ -void spectre_render_context_set_use_platform_fonts (SpectreRenderContext *rc, - int use_platform_fonts); - -/*! Gets wheter to use the platform fonts when rendering or not - @param rc The rendering context to query -*/ -int spectre_render_context_get_use_platform_fonts (SpectreRenderContext *rc); - -/*! Sets the antialias options for graphics and texts. The default is 4 for graphics and 2 for text - @param rc The rendering context to modify - @param graphics_bits The number of antialias bits to use for graphics. - Typically 4 for antialias and 1 for no antialias - @param text_bits The number of antialias bits to use for text. - Typically 2 for antialias and 1 for no antialias -*/ -void spectre_render_context_set_antialias_bits (SpectreRenderContext *rc, - int graphics_bits, - int text_bits); - -/*! Gets the antialias options for graphics and texts - @param rc The rendering context to query - @param graphics_bits The number of antialias bits to use for graphics will be stored here - @param text_bits The number of antialias bits to use for text will be stored here -*/ -void spectre_render_context_get_antialias_bits (SpectreRenderContext *rc, - int *graphics_bits, - int *text_bits); - -SPECTRE_END_DECLS - -#endif /* SPECTRE_PAGE_H */ diff --git a/generators/spectre/libspectre/spectre-status.c b/generators/spectre/libspectre/spectre-status.c deleted file mode 100644 index e17369020..000000000 --- a/generators/spectre/libspectre/spectre-status.c +++ /dev/null @@ -1,46 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "spectre-status.h" - -const char * -spectre_status_to_string (SpectreStatus status) -{ - switch (status) { - case SPECTRE_STATUS_SUCCESS: - return "success"; - case SPECTRE_STATUS_NO_MEMORY: - return "out of memory"; - case SPECTRE_STATUS_LOAD_ERROR: - return "error loading document"; - case SPECTRE_STATUS_DOCUMENT_NOT_LOADED: - return "document is not loaded"; - case SPECTRE_STATUS_INVALID_PAGE: - return "page is invalid"; - case SPECTRE_STATUS_RENDER_ERROR: - return "render error"; - case SPECTRE_STATUS_EXPORTER_ERROR: - return "exporter error"; - case SPECTRE_STATUS_SAVE_ERROR: - return "save error"; - } - - return "unknown error status"; -} diff --git a/generators/spectre/libspectre/spectre-status.h b/generators/spectre/libspectre/spectre-status.h deleted file mode 100644 index 58918cd2c..000000000 --- a/generators/spectre/libspectre/spectre-status.h +++ /dev/null @@ -1,58 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef SPECTRE_STATUS_H -#define SPECTRE_STATUS_H - -#include - -SPECTRE_BEGIN_DECLS - -/*! Defines the error status of a Spectre object */ -typedef enum _SpectreStatus { - SPECTRE_STATUS_SUCCESS /*! No error */ = 0, - SPECTRE_STATUS_NO_MEMORY /*! There has been a problem - allocating memory */, - SPECTRE_STATUS_LOAD_ERROR /*! There has been a problem - loading the postcript file */, - SPECTRE_STATUS_DOCUMENT_NOT_LOADED /*! A function that needs the - document to be loaded has been - called and the document has not - been loaded or there was an - error when loading it */, - SPECTRE_STATUS_INVALID_PAGE /*! The request page number - is not in the document page - range */, - SPECTRE_STATUS_RENDER_ERROR /*! There has been a problem - rendering the page */, - SPECTRE_STATUS_EXPORTER_ERROR /*! There has been a problem - exporting the document */, - SPECTRE_STATUS_SAVE_ERROR /*! There has been a problem - saving the document */ -} SpectreStatus; - -/*! Gets a textual description of the given status - @param status the status whose textual description will be returned -*/ -const char *spectre_status_to_string (SpectreStatus status); - -SPECTRE_END_DECLS - -#endif /* SPECTRE_STATUS_H */ diff --git a/generators/spectre/libspectre/spectre-utils.c b/generators/spectre/libspectre/spectre-utils.c deleted file mode 100644 index 209443b0b..000000000 --- a/generators/spectre/libspectre/spectre-utils.c +++ /dev/null @@ -1,111 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#define _GNU_SOURCE -#include -#include -#include - -#include "spectre-utils.h" - -static char * -spectre_strdup_vprintf (const char *format, - va_list args) -{ - char *string = NULL; - int len = vasprintf (&string, format, args); - - if (len < 0) - string = NULL; - - return string; -} - -char * -_spectre_strdup_printf (const char *format, ...) -{ - char *buffer; - va_list args; - - va_start (args, format); - buffer = spectre_strdup_vprintf (format, args); - va_end (args); - - return buffer; -} - -char * -_spectre_strdup (const char *str) -{ - size_t len; - char *copy; - - if (!str) - return NULL; - - len = strlen (str) + 1; - - copy = malloc (len); - if (!copy) - return NULL; - - memcpy (copy, str, len); - - return copy; -} - -#define TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c)) -int -_spectre_strncasecmp (const char *s1, - const char *s2, - size_t n) -{ - int c1, c2; - - while (n && *s1 && *s2) { - n -= 1; - c1 = (int)(unsigned char) TOLOWER (*s1); - c2 = (int)(unsigned char) TOLOWER (*s2); - if (c1 != c2) - return (c1 - c2); - s1++; - s2++; - } - - return (n) ? (((int) (unsigned char) *s1) - ((int) (unsigned char) *s2)) : 0; -} - -int -_spectre_strcasecmp (const char *s1, - const char *s2) -{ - int c1, c2; - - while (*s1 && *s2) { - c1 = (int)(unsigned char) TOLOWER (*s1); - c2 = (int)(unsigned char) TOLOWER (*s2); - if (c1 != c2) - return (c1 - c2); - s1++; - s2++; - } - - return (((int)(unsigned char) *s1) - ((int)(unsigned char) *s2)); -} diff --git a/generators/spectre/libspectre/spectre-utils.h b/generators/spectre/libspectre/spectre-utils.h deleted file mode 100644 index 29c4bb451..000000000 --- a/generators/spectre/libspectre/spectre-utils.h +++ /dev/null @@ -1,41 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef SPECTRE_UTILS_H -#define SPECTRE_UTILS_H - -#include - -#include - -SPECTRE_BEGIN_DECLS - -char *_spectre_strdup_printf (const char *format, ...); -char *_spectre_strdup (const char *str); -int _spectre_strncasecmp (const char *s1, - const char *s2, - size_t n); -int _spectre_strcasecmp (const char *s1, - const char *s2); - -SPECTRE_END_DECLS - -#endif /* SPECTRE_UTILS_H */ - diff --git a/generators/spectre/libspectre/spectre.h b/generators/spectre/libspectre/spectre.h deleted file mode 100644 index c656c7a4d..000000000 --- a/generators/spectre/libspectre/spectre.h +++ /dev/null @@ -1,30 +0,0 @@ -/* This file is part of Libspectre. - * - * Copyright (C) 2007 Albert Astals Cid - * Copyright (C) 2007 Carlos Garcia Campos - * - * Libspectre is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Libspectre 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef SPECTRE_H -#define SPECTRE_H - -#include -#include -#include -#include -#include - -#endif /* SPECTRE_H */ diff --git a/generators/spectre/rendererthread.cpp b/generators/spectre/rendererthread.cpp index 8a996476f..7d14be221 100644 --- a/generators/spectre/rendererthread.cpp +++ b/generators/spectre/rendererthread.cpp @@ -37,7 +37,7 @@ GSRendererThread::~GSRendererThread() void GSRendererThread::setMagnify(double magnify) { - spectre_render_context_set_scale(m_renderContext, magnify); + spectre_render_context_set_scale(m_renderContext, magnify, magnify); } void GSRendererThread::setPlatformFonts(bool pfonts)