zathura-ps-0.2.5/0000775000175000017500000000000013216732515014327 5ustar sebastiansebastianzathura-ps-0.2.5/LICENSE0000664000175000017500000000154113216732515015335 0ustar sebastiansebastianCopyright (c) 2011-2017 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.5/Makefile0000664000175000017500000000506513216732515015775 0ustar sebastiansebastian# See LICENSE file for license and copyright information include config.mk include common.mk PROJECT = zathura-ps PLUGIN = ps SOURCE = $(sort $(wildcard *.c)) HEADER = $(sort $(wildcard *.h)) OBJECTS = ${SOURCE:.c=.o} DOBJECTS = ${SOURCE:.c=.do} 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 zathura-ps-0.2.5/config.mk0000664000175000017500000000276413216732515016136 0ustar sebastiansebastian# See LICENSE file for license and copyright information VERSION_MAJOR = 0 VERSION_MINOR = 2 VERSION_REV = 5 VERSION = ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV} # minimum required zathura version ZATHURA_MIN_VERSION = 0.3.8 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} ${CAIRO_INC} ${ZATHURA_INC} LIBS = ${GLIB_LIB} ${SPECTRE_LIB} ${GIRARA_LIB} ${CAIRO_LIB} # compiler flags CFLAGS += -std=c11 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS) # linker flags LDFLAGS += -fPIC # debug DFLAGS ?= -g # compiler CC ?= gcc LD ?= ld # set to something != 0 if you want verbose build output VERBOSE ?= 0 zathura-ps-0.2.5/common.mk0000664000175000017500000000017613216732515016154 0ustar sebastiansebastian# See LICENSE file for license and copyright information ifeq "$(VERBOSE)" "0" ECHO=@echo QUIET=@ else ECHO=@\# QUIET= endif zathura-ps-0.2.5/Doxyfile0000664000175000017500000000116213216732515016035 0ustar sebastiansebastian# 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.5/plugin.h0000664000175000017500000000521413216732515016000 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #ifndef PS_H #define PS_H #include #include #include #include /** * Open a PostScript document * * @param document Zathura document * @return ZATHURA_ERROR_OK if no error occurred otherwise see * zathura_error_t */ GIRARA_HIDDEN 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 occurred otherwise see * zathura_error_t */ GIRARA_HIDDEN zathura_error_t ps_document_free(zathura_document_t* document, void* spectre_document); /** * Saves the document to the given path * * @param document Zathura document * @param path File path * @return ZATHURA_ERROR_OK when no error occurred, otherwise see * zathura_error_t */ GIRARA_HIDDEN zathura_error_t ps_document_save_as(zathura_document_t* document, void* 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 occurred * @return List of information entries or NULL if an error occurred */ GIRARA_HIDDEN girara_list_t* ps_document_get_information(zathura_document_t* document, void* spectre_document, zathura_error_t* error); /** * Returns a reference to a page * * @param page Page object * @return ZATHURA_ERROR_OK if no error occurred otherwise see * zathura_error_t */ GIRARA_HIDDEN zathura_error_t ps_page_init(zathura_page_t* 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 occurred * @return Image buffer or NULL if an error occurred */ GIRARA_HIDDEN zathura_image_buffer_t* ps_page_render(zathura_page_t* page, void* spectre_page, zathura_error_t* error); /** * 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 occurred otherwise see * zathura_error_t */ GIRARA_HIDDEN zathura_error_t ps_page_render_cairo(zathura_page_t* page, void* spectre_page, cairo_t* cairo, bool printing); /** * Frees a PostScript page * * @param page Page * @return ZATHURA_ERROR_OK if no error occurred otherwise see * zathura_error_t */ GIRARA_HIDDEN zathura_error_t ps_page_clear(zathura_page_t* page, void* spectre_page); #endif // PS_H zathura-ps-0.2.5/document.c0000664000175000017500000000452613216732515016320 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #include #include #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, void* data) { SpectreDocument* spectre_document = data; 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, void* data, const char* path) { SpectreDocument* spectre_document = data; 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; } zathura-ps-0.2.5/meta.c0000664000175000017500000000264213216732515015425 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #include "plugin.h" girara_list_t* ps_document_get_information(zathura_document_t* document, void* data, zathura_error_t* error) { SpectreDocument* spectre_document = data; 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-ps-0.2.5/page.c0000664000175000017500000000204013216732515015403 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #include "plugin.h" zathura_error_t ps_page_init(zathura_page_t* 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, void* data) { if (page == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } SpectrePage* spectre_page = data; if (spectre_page != NULL) { spectre_page_free(spectre_page); } return ZATHURA_ERROR_OK; } zathura-ps-0.2.5/plugin.c0000664000175000017500000000140113216732515015765 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #include "plugin.h" ZATHURA_PLUGIN_REGISTER_WITH_FUNCTIONS( "ps", VERSION_MAJOR, VERSION_MINOR, VERSION_REV, ZATHURA_PLUGIN_FUNCTIONS({ .document_open = ps_document_open, .document_free = ps_document_free, .page_init = ps_page_init, .page_clear = ps_page_clear, .page_render = ps_page_render, .document_save_as = ps_document_save_as, .document_get_information = ps_document_get_information, .page_render_cairo = ps_page_render_cairo, }), ZATHURA_PLUGIN_MIMETYPES({ "application/postscript", "application/eps", "application/x-eps", "image/eps", "image/x-eps" }) ) zathura-ps-0.2.5/render.c0000664000175000017500000000745313216732515015763 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #include #include #include #include "plugin.h" zathura_image_buffer_t* ps_page_render(zathura_page_t* page, void* data, zathura_error_t* error) { SpectrePage* spectre_page = data; 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; } zathura_error_t ps_page_render_cairo(zathura_page_t* page, void* data, cairo_t* cairo, bool GIRARA_UNUSED(printing)) { SpectrePage* ps_page = data; if (page == NULL || cairo == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } 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; } zathura-ps-0.2.5/AUTHORS0000664000175000017500000000027313216732515015401 0ustar sebastiansebastianzathura-ps is written by: Moritz Lipp Sebastian Ramacher Other contributors are (in alphabetical order): Pavel Borzenkov zathura-ps-0.2.5/zathura-ps.desktop0000664000175000017500000000203313216732515020016 0ustar sebastiansebastian[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 %U Terminal=false NoDisplay=true Categories=Office;Viewer; MimeType=application/postscript;application/eps;application/x-eps;image/eps;image/x-eps;