okular needs libspectre >= 0.2 as of now

Packagers start your engines!

svn path=/trunk/KDE/kdegraphics/okular/; revision=768911
This commit is contained in:
Albert Astals Cid 2008-01-30 22:08:44 +00:00
parent 87fe7f277a
commit bde413ac5e
31 changed files with 68 additions and 5755 deletions

View file

@ -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, <pino@kde.org>
# Copyright (c) 2008, Albert Astals Cid, <aacid@kde.org>
#
# 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)

View file

@ -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 )

View file

@ -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})

View file

@ -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

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

File diff suppressed because it is too large Load diff

View file

@ -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 <libspectre/spectre-macros.h>
#include <stdio.h>
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 */

View file

@ -1,301 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#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);
}

View file

@ -1,45 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <libspectre/spectre-macros.h>
#include <libspectre/spectre-render-context.h>
#include <libspectre/spectre-status.h>
#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 */

View file

@ -1,348 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
/* For stat */
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#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;
}

View file

@ -1,146 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <libspectre/spectre-macros.h>
#include <libspectre/spectre-status.h>
#include <libspectre/spectre-page.h>
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 */

View file

@ -1,105 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <stdlib.h>
#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;
}

View file

@ -1,88 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <stdlib.h>
#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;
}

View file

@ -1,100 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <stdlib.h>
#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;
}

View file

@ -1,49 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <libspectre/spectre-macros.h>
#include <libspectre/spectre-document.h>
#include <libspectre/spectre-status.h>
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 */

View file

@ -1,278 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#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);
}

View file

@ -1,56 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <libspectre/spectre-macros.h>
#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 */

View file

@ -1,47 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 */

View file

@ -1,146 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <stdio.h>
#include <stdlib.h>
#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);
}

View file

@ -1,93 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <libspectre/spectre-macros.h>
#include <libspectre/spectre-status.h>
#include <libspectre/spectre-render-context.h>
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 */

View file

@ -1,73 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 */

View file

@ -1,210 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <stdlib.h>
#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;
}

View file

@ -1,133 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <libspectre/spectre-macros.h>
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 */

View file

@ -1,46 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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";
}

View file

@ -1,58 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <libspectre/spectre-macros.h>
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 */

View file

@ -1,111 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#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));
}

View file

@ -1,41 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <stdarg.h>
#include <libspectre/spectre-macros.h>
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 */

View file

@ -1,30 +0,0 @@
/* This file is part of Libspectre.
*
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
*
* 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 <libspectre/spectre-status.h>
#include <libspectre/spectre-document.h>
#include <libspectre/spectre-render-context.h>
#include <libspectre/spectre-page.h>
#include <libspectre/spectre-exporter.h>
#endif /* SPECTRE_H */

View file

@ -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)