zathura-ps-0.2.2/0000755000175000001440000000000012144004647012463 5ustar mockuserszathura-ps-0.2.2/zathura-ps.desktop0000644000175000001440000000203312144004647016152 0ustar mockusers[Desktop Entry] Version=1.0 Type=Application Name=Zathura Comment=A minimalistic document viewer Comment[ca]=Un visualitzador de documents minimalista Comment[de]=Ein minimalistischer Dokumenten-Betrachter Comment[el]=Ένας ελαφρύς προβολέας κειμένων Comment[eo]=Malpeza dokumento spektanto Comment[es_CL]=Un visor de documentos minimalista Comment[fr]=Un visionneur de document minimaliste Comment[he]=מציג מסמכים מינימליסטי Comment[id_ID]=Pembaca dokumen minimalis Comment[it]=Un visualizzatore di documenti minimalista Comment[pl]=Minimalistyczna przeglądarka dokumentów Comment[pt_BR]=Um visualizador de documentos minimalista Comment[ru]=Минималистичный просмотрщик документов Comment[tr]=Minimalist bir belge görüntüleyicisi Comment[uk_UA]=Легкий переглядач документів Exec=zathura %f Terminal=false NoDisplay=true Categories=Office;Viewer; MimeType=application/postscript;application/eps;application/x-eps;image/eps;image/x-eps; zathura-ps-0.2.2/Doxyfile0000644000175000001440000000116212144004647014171 0ustar mockusers# See LICENSE file for license and copyright information # General information PROJECT_NAME = zathura-ps OUTPUT_DIRECTORY = ./doc/ OUTPUT_LANGUAGE = English TAB_SIZE = 2 EXTRACT_ALL = YES OPTIMIZE_OUTPUT_FOR_C = YES DOXYFILE_ENCODING = UTF-8 TYPEDEF_HIDES_STRUCT = YES # Warning and progress messages QUIET = YES WARNINGS = YES WARN_IF_UNDOCUMENTED = YES # Input files INPUT = FILE_PATTERNS = *.h *.c RECURSIVE = YES # Output files GENERATE_HTML = YES GENERATE_LATEX = NO GENERATE_RTF = NO GENERATE_XML = NO SOURCE_BROWSER = YES zathura-ps-0.2.2/ps.h0000644000175000001440000000522212144004647013257 0ustar mockusers/* See LICENSE file for license and copyright information */ #ifndef PS_H #define PS_H #include #include #include #if HAVE_CAIRO #include #endif /** * Open a PostScript document * * @param document Zathura document * @return ZATHURA_ERROR_OK if no error occured otherwise see * zathura_error_t */ zathura_error_t ps_document_open(zathura_document_t* document); /** * Closes and frees the internal document structure * * @param document Zathura document * @return ZATHURA_ERROR_OK if no error occured otherwise see * zathura_error_t */ zathura_error_t ps_document_free(zathura_document_t* document, SpectreDocument* spectre_document); /** * Saves the document to the given path * * @param document Zathura document * @param path File path * @return ZATHURA_ERROR_OK when no error occured, otherwise see * zathura_error_t */ zathura_error_t ps_document_save_as(zathura_document_t* document, SpectreDocument* spectre_document, const char* path); /** * Returns a list of document information entries of the document * * @param document Zathura document * @param error Set to an error value (see zathura_error_t) if an * error occured * @return List of information entries or NULL if an error occurred */ girara_list_t* ps_document_get_information(zathura_document_t* document, SpectreDocument* spectre_document, zathura_error_t* error); /** * Returns a reference to a page * * @param page Page object * @return ZATHURA_ERROR_OK if no error occured otherwise see * zathura_error_t */ zathura_error_t ps_page_init(zathura_page_t* page, SpectrePage* spectre_page); /** * Renders a page and returns a allocated image buffer which has to be freed * with zathura_image_buffer_free * * @param page Page * @param error Set to an error value (see zathura_error_t) if an * error occured * @return Image buffer or NULL if an error occurred */ zathura_image_buffer_t* ps_page_render(zathura_page_t* page, SpectrePage* spectre_page, zathura_error_t* error); #if HAVE_CAIRO /** * Renders a page onto a cairo object * * @param page Page * @param cairo Cairo object * @param printing Set to true if page should be rendered for printing * @return ZATHURA_ERROR_OK if no error occured otherwise see * zathura_error_t */ zathura_error_t ps_page_render_cairo(zathura_page_t* page, SpectrePage* spectre_page, cairo_t* cairo, bool printing); #endif /** * Frees a PostScript page * * @param page Page * @return ZATHURA_ERROR_OK if no error occured otherwise see * zathura_error_t */ zathura_error_t ps_page_clear(zathura_page_t* page, SpectrePage* spectre_page); #endif // PS_H zathura-ps-0.2.2/common.mk0000644000175000001440000000017612144004647014310 0ustar mockusers# See LICENSE file for license and copyright information ifeq "$(VERBOSE)" "0" ECHO=@echo QUIET=@ else ECHO=@\# QUIET= endif zathura-ps-0.2.2/LICENSE0000644000175000001440000000154112144004647013471 0ustar mockusersCopyright (c) 2011-2012 pwmt.org This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. t 3. This notice may not be removed or altered from any source distribution. zathura-ps-0.2.2/ps.c0000644000175000001440000002266312144004647013262 0ustar mockusers/* See LICENSE file for license and copyright information */ #include #include #include #include #if HAVE_CAIRO #include #endif #include "ps.h" /* forward declaration */ static const char* get_extension(const char* path); void register_functions(zathura_plugin_functions_t* functions) { functions->document_open = (zathura_plugin_document_open_t) ps_document_open; functions->document_free = (zathura_plugin_document_free_t) ps_document_free; functions->page_init = (zathura_plugin_page_init_t) ps_page_init; functions->page_clear = (zathura_plugin_page_clear_t) ps_page_clear; functions->page_render = (zathura_plugin_page_render_t) ps_page_render; functions->document_save_as = (zathura_plugin_document_save_as_t) ps_document_save_as; functions->document_get_information = (zathura_plugin_document_get_information_t) ps_document_get_information; #if HAVE_CAIRO functions->page_render_cairo = (zathura_plugin_page_render_cairo_t) ps_page_render_cairo; #endif } ZATHURA_PLUGIN_REGISTER( "ps", VERSION_MAJOR, VERSION_MINOR, VERSION_REV, register_functions, ZATHURA_PLUGIN_MIMETYPES({ "application/postscript", "application/eps", "application/x-eps", "image/eps", "image/x-eps" }) ) zathura_error_t ps_document_open(zathura_document_t* document) { zathura_error_t error = ZATHURA_ERROR_OK; if (document == NULL) { error = ZATHURA_ERROR_UNKNOWN; goto error_ret; } SpectreDocument* spectre_document = spectre_document_new(); if (spectre_document == NULL) { error = ZATHURA_ERROR_OUT_OF_MEMORY; goto error_free; } spectre_document_load(spectre_document, zathura_document_get_path(document)); if (spectre_document_status(spectre_document) != SPECTRE_STATUS_SUCCESS) { error = ZATHURA_ERROR_UNKNOWN; goto error_free; } zathura_document_set_data(document, spectre_document); zathura_document_set_number_of_pages(document, spectre_document_get_n_pages(spectre_document)); return error; error_free: if (spectre_document != NULL) { spectre_document_free(spectre_document); } error_ret: return error; } zathura_error_t ps_document_free(zathura_document_t* document, SpectreDocument* spectre_document) { if (document == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } if (spectre_document != NULL) { spectre_document_free(spectre_document); zathura_document_set_data(document, NULL); } return ZATHURA_ERROR_OK; } zathura_error_t ps_document_save_as(zathura_document_t* document, SpectreDocument* spectre_document, const char* path) { if (document == NULL || spectre_document == NULL || path == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } const char* extension = get_extension(path); if (extension != NULL && g_strcmp0(extension, "pdf") == 0) { spectre_document_save_to_pdf(spectre_document, path); } else { spectre_document_save(spectre_document, path); } if (spectre_document_status(spectre_document) != SPECTRE_STATUS_SUCCESS) { return ZATHURA_ERROR_UNKNOWN; } else { return ZATHURA_ERROR_OK; } } girara_list_t* ps_document_get_information(zathura_document_t* document, SpectreDocument* spectre_document, zathura_error_t* error) { if (document == NULL || spectre_document == NULL) { if (error != NULL) { *error = ZATHURA_ERROR_INVALID_ARGUMENTS; } return NULL; } girara_list_t* list = zathura_document_information_entry_list_new(); if (list == NULL) { return NULL; } /* get document information */ zathura_document_information_entry_t* entry = NULL; const char* creator = spectre_document_get_creator(spectre_document); entry = zathura_document_information_entry_new(ZATHURA_DOCUMENT_INFORMATION_CREATOR, creator); girara_list_append(list, entry); const char* title = spectre_document_get_title(spectre_document); entry = zathura_document_information_entry_new(ZATHURA_DOCUMENT_INFORMATION_TITLE, title); girara_list_append(list, entry); const char* author = spectre_document_get_for(spectre_document); entry = zathura_document_information_entry_new(ZATHURA_DOCUMENT_INFORMATION_AUTHOR, author); girara_list_append(list, entry); const char* creation_date = spectre_document_get_creation_date(spectre_document); entry = zathura_document_information_entry_new(ZATHURA_DOCUMENT_INFORMATION_CREATION_DATE, creation_date); girara_list_append(list, entry); return list; } zathura_error_t ps_page_init(zathura_page_t* page, SpectrePage* spectre_page) { if (page == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } zathura_document_t* document = zathura_page_get_document(page); SpectreDocument* spectre_document = zathura_document_get_data(document); SpectrePage* ps_page = spectre_document_get_page(spectre_document, zathura_page_get_index(page)); if (ps_page == NULL) { return ZATHURA_ERROR_UNKNOWN; } int page_width; int page_height; spectre_page_get_size(ps_page, &(page_width), &(page_height)); zathura_page_set_width(page, page_width); zathura_page_set_height(page, page_height); zathura_page_set_data(page, ps_page); return ZATHURA_ERROR_OK; } zathura_error_t ps_page_clear(zathura_page_t* page, SpectrePage* spectre_page) { if (page == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } if (spectre_page != NULL) { spectre_page_free(spectre_page); } return ZATHURA_ERROR_OK; } zathura_image_buffer_t* ps_page_render(zathura_page_t* page, SpectrePage* spectre_page, zathura_error_t* error) { if (page == NULL) { if (error != NULL) { *error = ZATHURA_ERROR_INVALID_ARGUMENTS; } goto error_ret; } zathura_document_t* document = zathura_page_get_document(page); if (document == NULL || spectre_page == NULL) { goto error_ret; } /* calculate sizes */ double scale = zathura_document_get_scale(document); unsigned int page_width = scale * zathura_page_get_width(page); unsigned int page_height = scale * zathura_page_get_height(page); /* create image buffer */ zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); if (image_buffer == NULL) { if (error != NULL) { *error = ZATHURA_ERROR_OUT_OF_MEMORY; } goto error_ret; } SpectreRenderContext* context = spectre_render_context_new(); if (context == NULL) { goto error_ret; } spectre_render_context_set_scale(context, scale, scale); spectre_render_context_set_rotation(context, 0); unsigned char* page_data = NULL; int row_length; spectre_page_render(spectre_page, context, &page_data, &row_length); spectre_render_context_free(context); if (page_data == NULL || spectre_page_status(spectre_page) != SPECTRE_STATUS_SUCCESS) { if (page_data != NULL) { free(page_data); } goto error_ret; } for (unsigned int y = 0; y < page_height; y++) { for (unsigned int x = 0; x < page_width; x++) { unsigned char *s = page_data + y * row_length + x * 4; guchar* p = image_buffer->data + y * image_buffer->rowstride + x * 3; p[0] = s[0]; p[1] = s[1]; p[2] = s[2]; } } free(page_data); return image_buffer; error_ret: if (error != NULL && *error == ZATHURA_ERROR_OK) { *error = ZATHURA_ERROR_UNKNOWN; } return NULL; } #if HAVE_CAIRO zathura_error_t ps_page_render_cairo(zathura_page_t* page, SpectrePage* spectre_page, cairo_t* cairo, bool GIRARA_UNUSED(printing)) { if (page == NULL || cairo == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } SpectrePage* ps_page = (SpectrePage*) zathura_page_get_data(page);; cairo_surface_t* surface = cairo_get_target(cairo); if (ps_page == NULL || surface == NULL || cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS || cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_IMAGE) { return ZATHURA_ERROR_UNKNOWN; } int rowstride = cairo_image_surface_get_stride(surface); unsigned char* image = cairo_image_surface_get_data(surface); unsigned int page_width = cairo_image_surface_get_width(surface); unsigned int page_height = cairo_image_surface_get_height(surface); SpectreRenderContext* context = spectre_render_context_new(); if (context == NULL) { return ZATHURA_ERROR_UNKNOWN; } double scalex = ((double) page_width) / zathura_page_get_width(page); double scaley = ((double) page_height) / zathura_page_get_height(page); spectre_render_context_set_scale(context, scalex, scaley); unsigned char* page_data = NULL; int row_length; spectre_page_render(ps_page, context, &page_data, &row_length); spectre_render_context_free(context); if (page_data == NULL || spectre_page_status(ps_page) != SPECTRE_STATUS_SUCCESS) { if (page_data != NULL) { free(page_data); } return ZATHURA_ERROR_UNKNOWN; } for (unsigned int y = 0; y < page_height; y++) { for (unsigned int x = 0; x < page_width; x++) { unsigned char *s = page_data + y * row_length + x * 4; guchar* p = image + y * rowstride + x * 4; p[0] = s[0]; p[1] = s[1]; p[2] = s[2]; p[3] = s[3]; } } free(page_data); return ZATHURA_ERROR_OK; } #endif static const char* get_extension(const char* path) { if (path == NULL) { return NULL; } unsigned int i = strlen(path); for (; i > 0; i--) { if (*(path + i) != '.') { continue; } else { break; } } if (i == 0) { return NULL; } return path + i + 1; } zathura-ps-0.2.2/config.mk0000644000175000001440000000273512144004647014270 0ustar mockusers# See LICENSE file for license and copyright information VERSION_MAJOR = 0 VERSION_MINOR = 2 VERSION_REV = 2 VERSION = ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV} # minimum required zathura version ZATHURA_MIN_VERSION = 0.2.0 ZATHURA_VERSION_CHECK ?= $(shell pkg-config --atleast-version=$(ZATHURA_MIN_VERSION) zathura; echo $$?) ZATHURA_GTK_VERSION ?= $(shell pkg-config --variable=GTK_VERSION zathura) # paths PREFIX ?= /usr LIBDIR ?= ${PREFIX}/lib DESKTOPPREFIX ?= ${PREFIX}/share/applications # libs CAIRO_INC ?= $(shell pkg-config --cflags cairo) CAIRO_LIB ?= $(shell pkg-config --libs cairo) GLIB_INC ?= $(shell pkg-config --cflags glib-2.0) GLIB_LIB ?= $(shell pkg-config --libs glib-2.0) SPECTRE_INC ?= $(shell pkg-config --cflags libspectre) SPECTRE_LIB ?= $(shell pkg-config --libs libspectre) GIRARA_INC ?= $(shell pkg-config --cflags girara-gtk${ZATHURA_GTK_VERSION}) GIRARA_LIB ?= $(shell pkg-config --libs girara-gtk${ZATHURA_GTK_VERSION}) ZATHURA_INC ?= $(shell pkg-config --cflags zathura) PLUGINDIR ?= $(shell pkg-config --variable=plugindir zathura) ifeq (,${PLUGINDIR}) PLUGINDIR = ${LIBDIR}/zathura endif INCS = ${GLIB_INC} ${SPECTRE_INC} ${GIRARA_INC} ${ZATHURA_INC} LIBS = ${GLIB_LIB} ${SPECTRE_LIB} ${GIRARA_LIB} # flags CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS) # debug DFLAGS ?= -g # build with cairo support? WITH_CAIRO ?= 1 # compiler CC ?= gcc LD ?= ld # set to something != 0 if you want verbose build output VERBOSE ?= 0 zathura-ps-0.2.2/AUTHORS0000644000175000001440000000027312144004647013535 0ustar mockuserszathura-ps is written by: Moritz Lipp Sebastian Ramacher Other contributors are (in alphabetical order): Pavel Borzenkov zathura-ps-0.2.2/Makefile0000644000175000001440000000524312144004647014127 0ustar mockusers# See LICENSE file for license and copyright information include config.mk include common.mk PROJECT = zathura-ps PLUGIN = ps SOURCE = $(shell find . -iname "*.c") HEADER = $(shell find . -iname "*.h") OBJECTS = ${SOURCE:.c=.o} DOBJECTS = ${SOURCE:.c=.do} ifneq "$(WITH_CAIRO)" "0" CPPFLAGS += -DHAVE_CAIRO INCS += $(CAIRO_INC) LIBS += $(CAIRO_LIB) endif CPPFLAGS += "-DVERSION_MAJOR=${VERSION_MAJOR}" CPPFLAGS += "-DVERSION_MINOR=${VERSION_MINOR}" CPPFLAGS += "-DVERSION_REV=${VERSION_REV}" all: options ${PLUGIN}.so zathura-version-check: ifneq ($(ZATHURA_VERSION_CHECK), 0) $(error "The minimum required version of zathura is ${ZATHURA_MIN_VERSION}") endif $(QUIET)touch zathura-version-check options: $(ECHO) ${PLUGIN} build options: $(ECHO) "CFLAGS = ${CFLAGS}" $(ECHO) "LDFLAGS = ${LDFLAGS}" $(ECHO) "DFLAGS = ${DFLAGS}" $(ECHO) "CC = ${CC}" %.o: %.c $(ECHO) CC $< @mkdir -p .depend $(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep %.do: %.c $(ECHO) CC $< @mkdir -p .depend $(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep ${OBJECTS}: config.mk zathura-version-check ${DOBJECTS}: config.mk zathura-version-check ${PLUGIN}.so: ${OBJECTS} $(ECHO) LD $@ $(QUIET)${CC} -shared ${LDFLAGS} -o $@ $(OBJECTS) ${LIBS} ${PLUGIN}-debug.so: ${DOBJECTS} $(ECHO) LD $@ $(QUIET)${CC} -shared ${LDFLAGS} -o $@ $(DOBJECTS) ${LIBS} clean: $(QUIET)rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so doc .depend \ ${PROJECT}-${VERSION}.tar.gz ${PLUGIN}-debug.so zathura-version-check debug: options ${PLUGIN}-debug.so dist: clean $(QUIET)mkdir -p ${PROJECT}-${VERSION} $(QUIET)cp -R LICENSE Makefile config.mk common.mk Doxyfile \ ${HEADER} ${SOURCE} AUTHORS ${PROJECT}.desktop \ ${PROJECT}-${VERSION} $(QUIET)tar -cf ${PROJECT}-${VERSION}.tar ${PROJECT}-${VERSION} $(QUIET)gzip ${PROJECT}-${VERSION}.tar $(QUIET)rm -rf ${PROJECT}-${VERSION} doc: clean $(QUIET)doxygen Doxyfile install: all $(ECHO) installing ${PLUGIN} plugin $(QUIET)mkdir -p ${DESTDIR}${PLUGINDIR} $(QUIET)cp -f ${PLUGIN}.so ${DESTDIR}${PLUGINDIR} $(QUIET)mkdir -m 755 -p ${DESTDIR}${DESKTOPPREFIX} $(ECHO) installing desktop file $(QUIET)install -m 644 ${PROJECT}.desktop ${DESTDIR}${DESKTOPPREFIX} uninstall: $(ECHO) uninstalling ${PLUGIN} plugin $(QUIET)rm -f ${DESTDIR}${PLUGINDIR}/${PLUGIN}.so $(QUIET)rmdir --ignore-fail-on-non-empty ${DESTDIR}${PLUGINDIR} 2> /dev/null $(ECHO) removing desktop file $(QUIET)rm -f ${DESTDIR}${DESKTOPPREFIX}/${PROJECT}.desktop $(QUIET)rmdir --ignore-fail-on-non-empty ${DESTDIR}${DESKTOPPREFIX} 2> /dev/null -include $(wildcard .depend/*.dep) .PHONY: all options clean debug doc dist install uninstall