Hello community, here is the log from the commit of package zathura-plugin-ps for openSUSE:Factory checked in at 2016-02-24 14:26:40 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/zathura-plugin-ps (Old) and /work/SRC/openSUSE:Factory/.zathura-plugin-ps.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "zathura-plugin-ps" Changes: -------- --- /work/SRC/openSUSE:Factory/zathura-plugin-ps/zathura-plugin-ps.changes 2014-11-24 11:09:30.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.zathura-plugin-ps.new/zathura-plugin-ps.changes 2016-02-24 14:26:41.000000000 +0100 @@ -1,0 +2,6 @@ +Wed Feb 24 08:29:29 UTC 2016 - mimi.vx@gmail.com + +- update to 0.2.2 +* Advertise URL support + +------------------------------------------------------------------- Old: ---- zathura-ps-0.2.2.tar.gz New: ---- zathura-ps-0.2.3.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ zathura-plugin-ps.spec ++++++ --- /var/tmp/diff_new_pack.Kl2GgL/_old 2016-02-24 14:26:42.000000000 +0100 +++ /var/tmp/diff_new_pack.Kl2GgL/_new 2016-02-24 14:26:42.000000000 +0100 @@ -1,7 +1,7 @@ # # spec file for package zathura-plugin-ps # -# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -18,7 +18,7 @@ %define realname zathura-ps Name: zathura-plugin-ps -Version: 0.2.2 +Version: 0.2.3 Release: 0 Summary: PS support for zathura via libspectre License: Zlib ++++++ zathura-ps-0.2.2.tar.gz -> zathura-ps-0.2.3.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/zathura-ps-0.2.2/config.mk new/zathura-ps-0.2.3/config.mk --- old/zathura-ps-0.2.2/config.mk 2013-05-12 23:29:11.000000000 +0200 +++ new/zathura-ps-0.2.3/config.mk 2015-12-22 23:49:30.000000000 +0100 @@ -2,7 +2,7 @@ VERSION_MAJOR = 0 VERSION_MINOR = 2 -VERSION_REV = 2 +VERSION_REV = 3 VERSION = ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV} # minimum required zathura version @@ -38,7 +38,7 @@ LIBS = ${GLIB_LIB} ${SPECTRE_LIB} ${GIRARA_LIB} # flags -CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS) +CFLAGS += -std=c11 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS) # debug DFLAGS ?= -g diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/zathura-ps-0.2.2/document.c new/zathura-ps-0.2.3/document.c --- old/zathura-ps-0.2.2/document.c 1970-01-01 01:00:00.000000000 +0100 +++ new/zathura-ps-0.2.3/document.c 2015-12-22 23:49:30.000000000 +0100 @@ -0,0 +1,107 @@ +/* See LICENSE file for license and copyright information */ + +#include <string.h> +#include <glib.h> + +#include "plugin.h" + +/* forward declaration */ +static const char* get_extension(const char* path); + +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; + } +} + +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; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/zathura-ps-0.2.2/meta.c new/zathura-ps-0.2.3/meta.c --- old/zathura-ps-0.2.2/meta.c 1970-01-01 01:00:00.000000000 +0100 +++ new/zathura-ps-0.2.3/meta.c 2015-12-22 23:49:30.000000000 +0100 @@ -0,0 +1,41 @@ +/* See LICENSE file for license and copyright information */ + +#include "plugin.h" + +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; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/zathura-ps-0.2.2/page.c new/zathura-ps-0.2.3/page.c --- old/zathura-ps-0.2.2/page.c 1970-01-01 01:00:00.000000000 +0100 +++ new/zathura-ps-0.2.3/page.c 2015-12-22 23:49:30.000000000 +0100 @@ -0,0 +1,43 @@ +/* See LICENSE file for license and copyright information */ + +#include "plugin.h" + +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; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/zathura-ps-0.2.2/plugin.c new/zathura-ps-0.2.3/plugin.c --- old/zathura-ps-0.2.2/plugin.c 1970-01-01 01:00:00.000000000 +0100 +++ new/zathura-ps-0.2.3/plugin.c 2015-12-22 23:49:30.000000000 +0100 @@ -0,0 +1,31 @@ +/* See LICENSE file for license and copyright information */ + +#include "plugin.h" + +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" + }) +) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/zathura-ps-0.2.2/plugin.h new/zathura-ps-0.2.3/plugin.h --- old/zathura-ps-0.2.2/plugin.h 1970-01-01 01:00:00.000000000 +0100 +++ new/zathura-ps-0.2.3/plugin.h 2015-12-22 23:49:30.000000000 +0100 @@ -0,0 +1,95 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef PS_H +#define PS_H + +#include <stdbool.h> +#include <libspectre/spectre.h> +#include <zathura/plugin-api.h> + +#if HAVE_CAIRO +#include <cairo.h> +#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 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/zathura-ps-0.2.2/ps.c new/zathura-ps-0.2.3/ps.c --- old/zathura-ps-0.2.2/ps.c 2013-05-12 23:29:11.000000000 +0200 +++ new/zathura-ps-0.2.3/ps.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,357 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#include <stdlib.h> -#include <girara/datastructures.h> -#include <string.h> -#include <glib.h> - -#if HAVE_CAIRO -#include <cairo.h> -#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; -} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/zathura-ps-0.2.2/ps.h new/zathura-ps-0.2.3/ps.h --- old/zathura-ps-0.2.2/ps.h 2013-05-12 23:29:11.000000000 +0200 +++ new/zathura-ps-0.2.3/ps.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,95 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#ifndef PS_H -#define PS_H - -#include <stdbool.h> -#include <libspectre/spectre.h> -#include <zathura/plugin-api.h> - -#if HAVE_CAIRO -#include <cairo.h> -#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 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/zathura-ps-0.2.2/render.c new/zathura-ps-0.2.3/render.c --- old/zathura-ps-0.2.2/render.c 1970-01-01 01:00:00.000000000 +0100 +++ new/zathura-ps-0.2.3/render.c 2015-12-22 23:49:30.000000000 +0100 @@ -0,0 +1,148 @@ +/* See LICENSE file for license and copyright information */ + +#include <glib.h> +#include <stdlib.h> + +#if HAVE_CAIRO +#include <cairo.h> +#endif + +#include "plugin.h" + +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 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/zathura-ps-0.2.2/zathura-ps.desktop new/zathura-ps-0.2.3/zathura-ps.desktop --- old/zathura-ps-0.2.2/zathura-ps.desktop 2013-05-12 23:29:11.000000000 +0200 +++ new/zathura-ps-0.2.3/zathura-ps.desktop 2015-12-22 23:49:30.000000000 +0100 @@ -17,7 +17,7 @@ Comment[ru]=Минималистичный просмотрщик документов Comment[tr]=Minimalist bir belge görüntüleyicisi Comment[uk_UA]=Легкий переглядач документів -Exec=zathura %f +Exec=zathura %U Terminal=false NoDisplay=true Categories=Office;Viewer;