summaryrefslogtreecommitdiff
path: root/libspectre
diff options
context:
space:
mode:
authorCarlos Garcia Campos <carlosgc@gnome.org>2014-09-03 17:20:33 +0200
committerCarlos Garcia Campos <carlosgc@gnome.org>2014-09-03 17:20:33 +0200
commitebbff50f9a32725e6533130e235ebabbb1cd6e84 (patch)
tree2338dc16bfce027375a44aed1eb950872b7342f8 /libspectre
parentc0b7b178d455f00b21e6317376ab49324bddb340 (diff)
Revert "Rotate documents correctly"
Diffstat (limited to 'libspectre')
-rw-r--r--libspectre/spectre-device.c58
-rw-r--r--libspectre/spectre-exporter-pdf.c4
-rw-r--r--libspectre/spectre-gs.c65
-rw-r--r--libspectre/spectre-gs.h6
4 files changed, 31 insertions, 102 deletions
diff --git a/libspectre/spectre-device.c b/libspectre/spectre-device.c
index 8fb7f93..a527d86 100644
--- a/libspectre/spectre-device.c
+++ b/libspectre/spectre-device.c
@@ -181,12 +181,10 @@ spectre_device_render (SpectreDevice *device,
char *fmt;
char *text_alpha, *graph_alpha;
char *size = NULL;
- char *resolution;
+ char *resolution, *set;
char *dsp_format, *dsp_handle;
char *width_points = NULL;
char *height_points = NULL;
- int scaled_width;
- int scaled_height;
gs = spectre_gs_new ();
if (!gs)
@@ -206,14 +204,8 @@ spectre_device_render (SpectreDevice *device,
return SPECTRE_STATUS_RENDER_ERROR;
}
- if (rc->orientation == SPECTRE_ORIENTATION_PORTRAIT ||
- rc->orientation == SPECTRE_ORIENTATION_REVERSE_PORTRAIT) {
- scaled_width = (int) ((width * rc->x_scale) + 0.5);
- scaled_height = (int) ((height * rc->y_scale) + 0.5);
- } else {
- scaled_width = (int) ((height * rc->y_scale) + 0.5);
- scaled_height = (int) ((width * rc->x_scale) + 0.5);
- }
+ width = (int) ((width * rc->x_scale) + 0.5);
+ height = (int) ((height * rc->y_scale) + 0.5);
if (rc->use_platform_fonts == FALSE)
n_args++;
@@ -232,19 +224,10 @@ spectre_device_render (SpectreDevice *device,
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", scaled_width, scaled_height);
-
- if (rc->orientation == SPECTRE_ORIENTATION_PORTRAIT ||
- rc->orientation == SPECTRE_ORIENTATION_REVERSE_PORTRAIT) {
- args[arg++] = resolution = _spectre_strdup_printf ("-r%fx%f",
- rc->x_scale * rc->x_dpi,
- rc->y_scale * rc->y_dpi);
- } else {
- args[arg++] = resolution = _spectre_strdup_printf ("-r%fx%f",
- rc->y_scale * rc->y_dpi,
- rc->x_scale * rc->x_dpi);
- }
-
+ args[arg++] = size =_spectre_strdup_printf ("-g%dx%d", width, height);
+ args[arg++] = resolution = _spectre_strdup_printf ("-r%fx%f",
+ rc->x_scale * rc->x_dpi,
+ rc->y_scale * rc->y_dpi);
args[arg++] = dsp_format = _spectre_strdup_printf ("-dDisplayFormat=%d",
DISPLAY_COLORS_RGB |
DISPLAY_DEPTH_8 |
@@ -271,18 +254,10 @@ spectre_device_render (SpectreDevice *device,
args[arg++] = "-dNOPLATFONTS";
if (rc->width != -1 && rc->height != -1) {
- if (rc->orientation == SPECTRE_ORIENTATION_PORTRAIT ||
- rc->orientation == SPECTRE_ORIENTATION_REVERSE_PORTRAIT) {
- args[arg++] = width_points = _spectre_strdup_printf ("-dDEVICEWIDTHPOINTS=%d",
- rc->width);
- args[arg++] = height_points = _spectre_strdup_printf ("-dDEVICEHEIGHTPOINTS=%d",
- rc->height);
- } else {
- args[arg++] = width_points = _spectre_strdup_printf ("-dDEVICEWIDTHPOINTS=%d",
- rc->height);
- args[arg++] = height_points = _spectre_strdup_printf ("-dDEVICEHEIGHTPOINTS=%d",
- rc->width);
- }
+ args[arg++] = width_points = _spectre_strdup_printf ("-dDEVICEWIDTHPOINTS=%d",
+ rc->width);
+ args[arg++] = height_points = _spectre_strdup_printf ("-dDEVICEHEIGHTPOINTS=%d",
+ rc->height);
args[arg++] = "-dFIXEDMEDIA";
}
@@ -301,7 +276,16 @@ spectre_device_render (SpectreDevice *device,
return SPECTRE_STATUS_RENDER_ERROR;
}
- if (!spectre_gs_send_page (gs, device->doc, page, x, y, width, height, spectre_render_context_get_rotation (rc))) {
+ 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, x, y)) {
spectre_gs_free (gs);
return SPECTRE_STATUS_RENDER_ERROR;
}
diff --git a/libspectre/spectre-exporter-pdf.c b/libspectre/spectre-exporter-pdf.c
index dcf1fa2..17a4900 100644
--- a/libspectre/spectre-exporter-pdf.c
+++ b/libspectre/spectre-exporter-pdf.c
@@ -66,7 +66,6 @@ spectre_exporter_pdf_begin (SpectreExporter *exporter,
if (!spectre_gs_process (exporter->gs,
doc->filename,
0, 0,
- 0,
doc->beginprolog,
doc->endprolog)) {
spectre_gs_free (exporter->gs);
@@ -78,7 +77,6 @@ spectre_exporter_pdf_begin (SpectreExporter *exporter,
if (!spectre_gs_process (exporter->gs,
doc->filename,
0, 0,
- 0,
doc->beginsetup,
doc->endsetup)) {
spectre_gs_free (exporter->gs);
@@ -102,7 +100,6 @@ spectre_exporter_pdf_do_page (SpectreExporter *exporter,
if (!spectre_gs_process (exporter->gs,
doc->filename,
0, 0,
- 0,
doc->pages[page_index].begin,
doc->pages[page_index].end)) {
spectre_gs_free (exporter->gs);
@@ -126,7 +123,6 @@ spectre_exporter_pdf_end (SpectreExporter *exporter)
ret = spectre_gs_process (exporter->gs,
doc->filename,
0, 0,
- 0,
doc->begintrailer,
doc->endtrailer);
spectre_gs_free (exporter->gs);
diff --git a/libspectre/spectre-gs.c b/libspectre/spectre-gs.c
index adbc7ef..93444a4 100644
--- a/libspectre/spectre-gs.c
+++ b/libspectre/spectre-gs.c
@@ -79,7 +79,6 @@ spectre_gs_process (SpectreGS *gs,
const char *filename,
int x,
int y,
- int rotation,
long begin,
long end)
{
@@ -118,20 +117,6 @@ spectre_gs_process (SpectreGS *gs,
}
}
- if (rotation != 0) {
- char *set;
-
- set = _spectre_strdup_printf ("%d rotate", rotation);
- error = gsapi_run_string_continue (ghostscript_instance, set, strlen (set),
- 0, &exit_code);
- error = error == e_NeedInput ? 0 : error;
- free (set);
- if (error != e_NeedInput && critic_error_code (error)) {
- fclose (fd);
- return FALSE;
- }
- }
-
while (left > 0 && !critic_error_code (error)) {
size_t to_read = BUFFER_SIZE;
@@ -221,21 +206,17 @@ spectre_gs_send_string (SpectreGS *gs,
}
int
-spectre_gs_send_page (SpectreGS *gs,
- struct document *doc,
- unsigned int page_index,
- int x,
- int y,
- int crop_width,
- int crop_height,
- int rotation)
+spectre_gs_send_page (SpectreGS *gs,
+ struct document *doc,
+ unsigned int page_index,
+ int x,
+ int y)
{
int xoffset = 0, yoffset = 0;
int page_urx, page_ury, page_llx, page_lly;
int bbox_urx, bbox_ury, bbox_llx, bbox_lly;
int doc_xoffset = 0, doc_yoffset = 0;
int page_xoffset = 0, page_yoffset = 0;
- int tmp_xoffset, tmp_yoffset;
if (psgetpagebbox (doc, page_index, &bbox_urx, &bbox_ury, &bbox_llx, &bbox_lly)) {
psgetpagebox (doc, page_index,
@@ -249,42 +230,18 @@ spectre_gs_send_page (SpectreGS *gs,
}
}
- switch (rotation) {
- default:
- tmp_xoffset = xoffset + x;
- tmp_yoffset = yoffset + y;
- break;
- case 90:
- tmp_xoffset = - (yoffset + y + crop_height);
- tmp_yoffset = xoffset + x;
- break;
- case 180:
- tmp_xoffset = - (xoffset + x + crop_width);
- tmp_yoffset = - (yoffset + y + crop_height);
- break;
- case 270:
- tmp_xoffset = yoffset + y;
- tmp_yoffset = - (xoffset + x + crop_width);
- break;
- }
-
if (doc->numpages > 0) {
- page_xoffset = tmp_xoffset;
- page_yoffset = tmp_yoffset;
+ page_xoffset = xoffset + x;
+ page_yoffset = yoffset + y;
} else {
- doc_xoffset = tmp_xoffset;
- doc_yoffset = tmp_yoffset;
+ doc_xoffset = xoffset + x;
+ doc_yoffset = yoffset + y;
}
-
- if (!spectre_gs_send_string (gs, "/setpagedevice { pop } bind def"))
- return FALSE;
-
if (!spectre_gs_process (gs,
doc->filename,
doc_xoffset,
doc_yoffset,
- 0,
doc->beginprolog,
doc->endprolog))
return FALSE;
@@ -292,7 +249,6 @@ spectre_gs_send_page (SpectreGS *gs,
if (!spectre_gs_process (gs,
doc->filename,
0, 0,
- 0,
doc->beginsetup,
doc->endsetup))
return FALSE;
@@ -308,7 +264,6 @@ spectre_gs_send_page (SpectreGS *gs,
doc->filename,
page_xoffset,
page_yoffset,
- rotation,
doc->pages[i].begin,
doc->pages[i].end))
return FALSE;
@@ -319,7 +274,6 @@ spectre_gs_send_page (SpectreGS *gs,
doc->filename,
page_xoffset,
page_yoffset,
- rotation,
doc->pages[page_index].begin,
doc->pages[page_index].end))
return FALSE;
@@ -328,7 +282,6 @@ spectre_gs_send_page (SpectreGS *gs,
if (!spectre_gs_process (gs,
doc->filename,
0, 0,
- 0,
doc->begintrailer,
doc->endtrailer))
return FALSE;
diff --git a/libspectre/spectre-gs.h b/libspectre/spectre-gs.h
index 947bbd5..b673ce8 100644
--- a/libspectre/spectre-gs.h
+++ b/libspectre/spectre-gs.h
@@ -46,7 +46,6 @@ int spectre_gs_process (SpectreGS *gs,
const char *filename,
int x,
int y,
- int rotation,
long begin,
long end);
int spectre_gs_send_string (SpectreGS *gs,
@@ -55,10 +54,7 @@ int spectre_gs_send_page (SpectreGS *gs,
struct document *doc,
unsigned int page_index,
int x,
- int y,
- int crop_width,
- int crop_height,
- int rotation);
+ int y);
void spectre_gs_cleanup (SpectreGS *gs,
SpectreGSCleanupFlag flag);
void spectre_gs_free (SpectreGS *gs);