Accepting request 342961 from home:badshah400:branches:X11:common:Factory

- Add libspectre-rotate-documents-correctly.patch to fix documents
  being rotated incorrectly; patch taken from upstream bug
  report (fdo#76450,boo#898327).

  I have tested the patched builds and it really fixes the problem for
  both single and multi-page ps and eps files.

  \begin{rant}
  Upstream has been downright negligent so far in not incorporating
  this patch volunteered by a user in the fdo bug report, and
  Fedora, for instance, already ships this patch. Basically for the
  last year, eps files have been unusable in evince because of this
  issue depsite the fix being available for most part during that
  time. Please consider this despite not being upstreamed.
  
  Boy, did that feel good!
  \end{rant}

OBS-URL: https://build.opensuse.org/request/show/342961
OBS-URL: https://build.opensuse.org/package/show/X11:common:Factory/libspectre?expand=0&rev=21
This commit is contained in:
Bjørn Lie 2015-11-08 12:37:08 +00:00 committed by Git OBS Bridge
parent 3f0310a39f
commit a535eb1ed1
3 changed files with 160 additions and 0 deletions

View File

@ -0,0 +1,150 @@
From adb610d22582f0598f6e5c699c08e7495767de28 Mon Sep 17 00:00:00 2001
From: Marek Kasik <mkasik@redhat.com>
Date: Wed, 7 Jan 2015 18:35:16 +0100
Subject: [PATCH] Rotate documents correctly
Rotate result of rendering given by ghostscript.
https://bugs.freedesktop.org/show_bug.cgi?id=76450
---
libspectre/spectre-device.c | 97 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 95 insertions(+), 2 deletions(-)
diff --git a/libspectre/spectre-device.c b/libspectre/spectre-device.c
index a527d86..537f337 100644
--- a/libspectre/spectre-device.c
+++ b/libspectre/spectre-device.c
@@ -99,7 +99,7 @@ spectre_sync (void *handle, void *device)
}
static int
-spectre_page (void *handle, void * device, int copies, int flush)
+spectre_page (void *handle, void *device, int copies, int flush)
{
SpectreDevice *sd;
@@ -162,6 +162,33 @@ spectre_device_new (struct document *doc)
return device;
}
+#define PIXEL_SIZE 4
+#define ROW_ALIGN 32
+
+static void
+swap_pixels (unsigned char *data,
+ size_t pixel_a_start,
+ size_t pixel_b_start)
+{
+ unsigned char value;
+ size_t i;
+
+ for (i = 0; i < PIXEL_SIZE; i++) {
+ value = data[pixel_a_start + i];
+ data[pixel_a_start + i] = data[pixel_b_start + i];
+ data[pixel_b_start + i] = value;
+ }
+}
+
+static void
+copy_pixel (unsigned char *dest,
+ unsigned char *src,
+ size_t dest_pixel_start,
+ size_t src_pixel_start)
+{
+ memcpy (dest + dest_pixel_start, src + src_pixel_start, PIXEL_SIZE);
+}
+
SpectreStatus
spectre_device_render (SpectreDevice *device,
unsigned int page,
@@ -185,6 +212,10 @@ spectre_device_render (SpectreDevice *device,
char *dsp_format, *dsp_handle;
char *width_points = NULL;
char *height_points = NULL;
+ unsigned char *user_image;
+ size_t stride, padding;
+ int i, j;
+
gs = spectre_gs_new ();
if (!gs)
@@ -277,7 +308,7 @@ spectre_device_render (SpectreDevice *device,
}
set = _spectre_strdup_printf ("<< /Orientation %d >> setpagedevice .locksafe",
- rc->orientation);
+ SPECTRE_ORIENTATION_PORTRAIT);
if (!spectre_gs_send_string (gs, set)) {
free (set);
spectre_gs_free (gs);
@@ -293,6 +324,68 @@ spectre_device_render (SpectreDevice *device,
*page_data = device->user_image;
*row_length = device->row_length;
+ switch (rc->orientation)
+ {
+ default:
+ case SPECTRE_ORIENTATION_PORTRAIT:
+ break;
+ case SPECTRE_ORIENTATION_REVERSE_PORTRAIT:
+ for (j = 0; j < height / 2; ++j) {
+ for (i = 0; i < width; ++i) {
+ swap_pixels (device->user_image,
+ device->row_length * j + PIXEL_SIZE * i,
+ device->row_length * (height - 1 - j) + PIXEL_SIZE * (width - 1 - i));
+ }
+ }
+ if (height % 2 == 1) {
+ for (i = 0; i < width / 2; ++i) {
+ swap_pixels (device->user_image,
+ device->row_length * (height / 2) + PIXEL_SIZE * i,
+ device->row_length * (height - 1 - height / 2) + PIXEL_SIZE * (width - 1 - i));
+ }
+ }
+ break;
+ case SPECTRE_ORIENTATION_LANDSCAPE:
+ case SPECTRE_ORIENTATION_REVERSE_LANDSCAPE:
+ if (height % ROW_ALIGN > 0) {
+ padding = (ROW_ALIGN - height % ROW_ALIGN) * PIXEL_SIZE;
+ stride = height * PIXEL_SIZE + padding;
+ user_image = malloc (width * stride);
+
+ for (j = 0; j < width; ++j)
+ memset (user_image + j * stride + stride - padding, 0, padding);
+ }
+ else {
+ stride = height * PIXEL_SIZE;
+ user_image = malloc (width * stride);
+ }
+
+ if (rc->orientation == SPECTRE_ORIENTATION_LANDSCAPE) {
+ for (j = 0; j < height; ++j) {
+ for (i = 0; i < width; ++i) {
+ copy_pixel (user_image,
+ device->user_image,
+ stride * i + PIXEL_SIZE * (height - 1 - j),
+ device->row_length * j + PIXEL_SIZE * i);
+ }
+ }
+ } else {
+ for (j = 0; j < height; ++j) {
+ for (i = 0; i < width; ++i) {
+ copy_pixel (user_image,
+ device->user_image,
+ stride * (width - 1 - i) + PIXEL_SIZE * j,
+ device->row_length * j + PIXEL_SIZE * i);
+ }
+ }
+ }
+
+ free (device->user_image);
+ *page_data = user_image;
+ *row_length = stride;
+ break;
+ }
+
spectre_gs_free (gs);
return SPECTRE_STATUS_SUCCESS;
--
2.1.0

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Sun Nov 8 06:46:01 UTC 2015 - badshah400@gmail.com
- Add libspectre-rotate-documents-correctly.patch to fix documents
being rotated incorrectly; patch taken from upstream bug
report (fdo#76450,boo#898327).
-------------------------------------------------------------------
Wed Nov 4 15:02:34 UTC 2015 - dimstar@opensuse.org

View File

@ -29,6 +29,8 @@ Source0: http://libspectre.freedesktop.org/releases/%{name}-%{version}.ta
Patch0: libspectre-gs-9.18.patch
%define debug_package_requires libspectre1 = %{version}-%{release}
# Need ghostscript-devel >= 9.18 due to libspectre-gs-9.18 patch
# PATCH-FIX-UPSTREAM libspectre-rotate-documents-correctly.patch fdo#76450 boo#898327 badshah400@gmail.com -- Fix documents not rotated correctly
Patch1: libspectre-rotate-documents-correctly.patch
BuildRequires: ghostscript-devel
BuildRequires: ghostscript-library
BuildRequires: pkg-config
@ -67,6 +69,7 @@ Postscript documents.
if zypper vcmp $(rpm -q --qf '%%{version}' ghostscript-devel) 9.18 | grep -e "\(newer\|matches\)"; then
%patch0 -p1
fi
%patch1 -p1
%build
%configure --disable-static --enable-shared