summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Treglia <alessio@debian.org>2011-09-03 12:12:54 +0200
committerAlessio Treglia <alessio@debian.org>2011-09-03 12:12:54 +0200
commita25eb08be6af9cc6580f9731a1e515be120331fc (patch)
treed28f304fa76bb0175ae1d887cf4c4b27d8ac29ec
parent5c8211aeb400deaf51d30eddd0c92017db7b4422 (diff)
parent8227fe5bd1a0cee50359c2581184c32a371c754e (diff)
Merge commit 'upstream/3.1.90'
-rw-r--r--NEWS5
-rwxr-xr-xconfigure2
-rw-r--r--configure.ac2
-rw-r--r--src/book.c8
-rw-r--r--src/book.vala8
-rw-r--r--src/scanner.c18
-rw-r--r--src/simple-scan.c374
-rw-r--r--src/simple-scan.vala79
-rw-r--r--src/ui.c56
9 files changed, 465 insertions, 87 deletions
diff --git a/NEWS b/NEWS
index cba8c9e..e57ab59 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+Overview of changes in simple-scan 3.1.90
+
+ * Fix incorrect PDF generation, and add a --fix-pdf command line to fix broken
+ files generated by older versions
+
Overview of changes in simple-scan 3.1.5
* Fix compile warnings
diff --git a/configure b/configure
index 156ce45..50955bd 100755
--- a/configure
+++ b/configure
@@ -2739,7 +2739,7 @@ fi
# Define the identity of the package.
PACKAGE=simple-scan
- VERSION=3.1.5
+ VERSION=3.1.90
cat >>confdefs.h <<_ACEOF
diff --git a/configure.ac b/configure.ac
index 24afcd8..bacc0f4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,7 +1,7 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(configure.ac)
-AM_INIT_AUTOMAKE(simple-scan, 3.1.5)
+AM_INIT_AUTOMAKE(simple-scan, 3.1.90)
AM_CONFIG_HEADER(config.h)
AM_MAINTAINER_MODE
GNOME_MAINTAINER_MODE_DEFINES
diff --git a/src/book.c b/src/book.c
index 154b6d4..6b1b7b3 100644
--- a/src/book.c
+++ b/src/book.c
@@ -859,8 +859,8 @@ static void book_save_pdf (Book* self, GFile* file, GError** error) {
}
_tmp1_ = pdf_writer_new (stream);
writer = _tmp1_;
- pdf_writer_write_string (writer, "%%PDF-1.3\n");
- pdf_writer_write_string (writer, "%%\xe2\xe3\xcf\xd3\n");
+ pdf_writer_write_string (writer, "%PDF-1.3\n");
+ pdf_writer_write_string (writer, "%\xe2\xe3\xcf\xd3\n");
_tmp2_ = pdf_writer_start_object (writer);
catalog_number = _tmp2_;
_tmp3_ = g_strdup_printf ("%u 0 obj\n", catalog_number);
@@ -1501,7 +1501,7 @@ static void book_save_pdf (Book* self, GFile* file, GError** error) {
{
gchar* _tmp108_ = NULL;
gchar* _tmp109_;
- _tmp108_ = g_strdup_printf ("%010zu 0000 n\n", (gsize) offset);
+ _tmp108_ = g_strdup_printf ("%010zu 00000 n \n", (gsize) offset);
_tmp109_ = _tmp108_;
pdf_writer_write_string (writer, _tmp109_);
_g_free0 (_tmp109_);
@@ -1529,7 +1529,7 @@ static void book_save_pdf (Book* self, GFile* file, GError** error) {
_tmp118_ = _tmp117_;
pdf_writer_write_string (writer, _tmp118_);
_g_free0 (_tmp118_);
- pdf_writer_write_string (writer, "%%%%EOF\n");
+ pdf_writer_write_string (writer, "%%EOF\n");
_pdf_writer_unref0 (writer);
_g_object_unref0 (stream);
}
diff --git a/src/book.vala b/src/book.vala
index 1aed281..64f7c60 100644
--- a/src/book.vala
+++ b/src/book.vala
@@ -207,10 +207,10 @@ public class Book
var writer = new PDFWriter (stream);
/* Header */
- writer.write_string ("%%PDF-1.3\n");
+ writer.write_string ("%PDF-1.3\n");
/* Comment with binary as recommended so file is treated as binary */
- writer.write_string ("%%\xe2\xe3\xcf\xd3\n");
+ writer.write_string ("%\xe2\xe3\xcf\xd3\n");
/* Catalog */
var catalog_number = writer.start_object ();
@@ -464,7 +464,7 @@ public class Book
writer.write_string ("xref\n");
writer.write_string ("1 %zu\n".printf (writer.object_offsets.length ()));
foreach (var offset in writer.object_offsets)
- writer.write_string ("%010zu 0000 n\n".printf (offset));
+ writer.write_string ("%010zu 00000 n \n".printf (offset));
/* Trailer */
writer.write_string ("trailer\n");
@@ -476,7 +476,7 @@ public class Book
writer.write_string (">>\n");
writer.write_string ("startxref\n");
writer.write_string ("%zu\n".printf (xref_offset));
- writer.write_string ("%%%%EOF\n");
+ writer.write_string ("%%EOF\n");
}
public void save (string type, File file) throws Error
diff --git a/src/scanner.c b/src/scanner.c
index e7e83cc..c26d691 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -3293,7 +3293,7 @@ static gchar* string_replace (const gchar* self, const gchar* old, const gchar*
regex = _tmp3_;
if (_inner_error_ != NULL) {
if (_inner_error_->domain == G_REGEX_ERROR) {
- goto __catch8_g_regex_error;
+ goto __catch9_g_regex_error;
}
g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
g_clear_error (&_inner_error_);
@@ -3304,7 +3304,7 @@ static gchar* string_replace (const gchar* self, const gchar* old, const gchar*
if (_inner_error_ != NULL) {
_g_regex_unref0 (regex);
if (_inner_error_->domain == G_REGEX_ERROR) {
- goto __catch8_g_regex_error;
+ goto __catch9_g_regex_error;
}
_g_regex_unref0 (regex);
g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
@@ -3315,8 +3315,8 @@ static gchar* string_replace (const gchar* self, const gchar* old, const gchar*
_g_regex_unref0 (regex);
return result;
}
- goto __finally8;
- __catch8_g_regex_error:
+ goto __finally9;
+ __catch9_g_regex_error:
{
GError* e = NULL;
e = _inner_error_;
@@ -3324,7 +3324,7 @@ static gchar* string_replace (const gchar* self, const gchar* old, const gchar*
g_assert_not_reached ();
_g_error_free0 (e);
}
- __finally8:
+ __finally9:
if (_inner_error_ != NULL) {
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
g_clear_error (&_inner_error_);
@@ -5634,12 +5634,12 @@ void scanner_start (Scanner* self) {
_tmp0_ = g_thread_create (_scanner_scan_thread_gthread_func, self, TRUE, &_inner_error_);
_tmp1_ = _tmp0_;
if (_inner_error_ != NULL) {
- goto __catch9_g_error;
+ goto __catch10_g_error;
}
self->priv->thread = _tmp1_;
}
- goto __finally9;
- __catch9_g_error:
+ goto __finally10;
+ __catch10_g_error:
{
GError* e = NULL;
e = _inner_error_;
@@ -5647,7 +5647,7 @@ void scanner_start (Scanner* self) {
g_critical ("scanner.vala:1384: Unable to create thread: %s", e->message);
_g_error_free0 (e);
}
- __finally9:
+ __finally10:
if (_inner_error_ != NULL) {
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
g_clear_error (&_inner_error_);
diff --git a/src/simple-scan.c b/src/simple-scan.c
index 1f1f599..85943bf 100644
--- a/src/simple-scan.c
+++ b/src/simple-scan.c
@@ -15,9 +15,9 @@
#include <glib.h>
#include <glib-object.h>
#include <gudev/gudev.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include <float.h>
#include <math.h>
#include <sane/sane.h>
@@ -140,9 +140,12 @@ typedef struct _ScanOptionsPrivate ScanOptionsPrivate;
#define TYPE_SCAN_TYPE (scan_type_get_type ())
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
+#define _fclose0(var) ((var == NULL) ? NULL : (var = (fclose (var), NULL)))
+#define _g_match_info_free0(var) ((var == NULL) ? NULL : (var = (g_match_info_free (var), NULL)))
+#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
+#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_option_context_free0(var) ((var == NULL) ? NULL : (var = (g_option_context_free (var), NULL)))
#define _g_timer_destroy0(var) ((var == NULL) ? NULL : (var = (g_timer_destroy (var), NULL)))
-#define _fclose0(var) ((var == NULL) ? NULL : (var = (fclose (var), NULL)))
#define _application_unref0(var) ((var == NULL) ? NULL : (var = (application_unref (var), NULL)))
typedef struct _ParamSpecApplication ParamSpecApplication;
@@ -244,6 +247,8 @@ static gboolean application_show_version;
static gboolean application_show_version = FALSE;
static gboolean application_debug_enabled;
static gboolean application_debug_enabled = FALSE;
+static gchar* application_fix_pdf_filename;
+static gchar* application_fix_pdf_filename = NULL;
static GTimer* application_log_timer;
static GTimer* application_log_timer = NULL;
static FILE* application_log_file;
@@ -398,6 +403,7 @@ void page_save (Page* self, const gchar* type, GFile* file, GError** error);
void scanner_free (Scanner* self);
static void application_log_cb (const gchar* log_domain, GLogLevelFlags log_level, const gchar* message);
void scanner_redetect (Scanner* self);
+static void application_fix_pdf (const gchar* filename, GError** error);
gint application_main (gchar** args, int args_length1);
ScanDevice* scan_device_new (void);
ScanDevice* scan_device_construct (GType object_type);
@@ -406,7 +412,7 @@ static void application_finalize (Application* obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
-const GOptionEntry APPLICATION_options[3] = {{"version", 'v', 0, G_OPTION_ARG_NONE, &application_show_version, "Show release version", NULL}, {"debug", 'd', 0, G_OPTION_ARG_NONE, &application_debug_enabled, "Print debugging messages", NULL}, {NULL}};
+const GOptionEntry APPLICATION_options[4] = {{"version", 'v', 0, G_OPTION_ARG_NONE, &application_show_version, "Show release version", NULL}, {"debug", 'd', 0, G_OPTION_ARG_NONE, &application_debug_enabled, "Print debugging messages", NULL}, {"fix-pdf", (gchar) 0, 0, G_OPTION_ARG_STRING, &application_fix_pdf_filename, "Fix PDF files generated with older versions of Simple Scan", "FILENAME..."}, {NULL}};
static gpointer _scan_device_ref0 (gpointer self) {
return self ? scan_device_ref (self) : NULL;
@@ -747,7 +753,7 @@ static void application_scanner_page_info_cb (Application* self, Scanner* scanne
g_return_if_fail (self != NULL);
g_return_if_fail (scanner != NULL);
g_return_if_fail (info != NULL);
- g_debug ("simple-scan.vala:233: Page is %d pixels wide, %d pixels high, %d bits " \
+ g_debug ("simple-scan.vala:236: Page is %d pixels wide, %d pixels high, %d bits " \
"per pixel", info->width, info->height, info->depth);
_tmp0_ = application_append_page (self);
page = _tmp0_;
@@ -848,7 +854,7 @@ static void application_scan_cb (Application* self, SimpleScan* ui, const gchar*
g_return_if_fail (self != NULL);
g_return_if_fail (ui != NULL);
g_return_if_fail (options != NULL);
- g_debug ("simple-scan.vala:293: Requesting scan at %d dpi from device '%s'", options->dpi, device);
+ g_debug ("simple-scan.vala:296: Requesting scan at %d dpi from device '%s'", options->dpi, device);
_tmp0_ = scanner_is_scanning (self->priv->scanner);
if (!_tmp0_) {
Page* _tmp1_ = NULL;
@@ -918,7 +924,7 @@ static gchar* application_get_temporary_filename (Application* self, const gchar
GError* e = NULL;
e = _inner_error_;
_inner_error_ = NULL;
- g_warning ("simple-scan.vala:329: Error saving email attachment: %s", e->message);
+ g_warning ("simple-scan.vala:332: Error saving email attachment: %s", e->message);
result = NULL;
_g_error_free0 (e);
_g_free0 (path);
@@ -975,7 +981,7 @@ static void application_email_cb (Application* self, SimpleScan* ui, const gchar
GError* e = NULL;
e = _inner_error_;
_inner_error_ = NULL;
- g_warning ("simple-scan.vala:355: Unable to save email file: %s", e->message);
+ g_warning ("simple-scan.vala:358: Unable to save email file: %s", e->message);
_g_error_free0 (e);
_g_object_unref0 (file);
_g_free0 (path);
@@ -1050,7 +1056,7 @@ static void application_email_cb (Application* self, SimpleScan* ui, const gchar
GError* e = NULL;
e = _inner_error_;
_inner_error_ = NULL;
- g_warning ("simple-scan.vala:379: Unable to save email file: %s", e->message);
+ g_warning ("simple-scan.vala:382: Unable to save email file: %s", e->message);
_g_error_free0 (e);
_g_object_unref0 (file);
_g_free0 (path);
@@ -1083,7 +1089,7 @@ static void application_email_cb (Application* self, SimpleScan* ui, const gchar
}
}
}
- g_debug ("simple-scan.vala:389: Launching email client: %s", command_line);
+ g_debug ("simple-scan.vala:392: Launching email client: %s", command_line);
{
g_spawn_command_line_async (command_line, &_inner_error_);
if (_inner_error_ != NULL) {
@@ -1096,7 +1102,7 @@ static void application_email_cb (Application* self, SimpleScan* ui, const gchar
GError* e = NULL;
e = _inner_error_;
_inner_error_ = NULL;
- g_warning ("simple-scan.vala:396: Unable to start email: %s", e->message);
+ g_warning ("simple-scan.vala:399: Unable to start email: %s", e->message);
_g_error_free0 (e);
}
__finally6:
@@ -1209,6 +1215,243 @@ static void application_on_uevent (Application* self, GUdevClient* client, const
}
+static glong string_strnlen (gchar* str, glong maxlen) {
+ glong result = 0L;
+ gchar* _tmp0_ = NULL;
+ gchar* end;
+ _tmp0_ = memchr (str, 0, (gsize) maxlen);
+ end = _tmp0_;
+ if (end == NULL) {
+ result = maxlen;
+ return result;
+ } else {
+ result = (glong) (end - str);
+ return result;
+ }
+}
+
+
+static gchar* string_substring (const gchar* self, glong offset, glong len) {
+ gchar* result = NULL;
+ glong string_length = 0L;
+ gboolean _tmp0_ = FALSE;
+ gchar* _tmp3_ = NULL;
+ g_return_val_if_fail (self != NULL, NULL);
+ if (offset >= ((glong) 0)) {
+ _tmp0_ = len >= ((glong) 0);
+ } else {
+ _tmp0_ = FALSE;
+ }
+ if (_tmp0_) {
+ glong _tmp1_;
+ _tmp1_ = string_strnlen ((gchar*) self, offset + len);
+ string_length = _tmp1_;
+ } else {
+ gint _tmp2_;
+ _tmp2_ = strlen (self);
+ string_length = (glong) _tmp2_;
+ }
+ if (offset < ((glong) 0)) {
+ offset = string_length + offset;
+ g_return_val_if_fail (offset >= ((glong) 0), NULL);
+ } else {
+ g_return_val_if_fail (offset <= string_length, NULL);
+ }
+ if (len < ((glong) 0)) {
+ len = string_length - offset;
+ }
+ g_return_val_if_fail ((offset + len) <= string_length, NULL);
+ _tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
+ result = _tmp3_;
+ return result;
+}
+
+
+static void application_fix_pdf (const gchar* filename, GError** error) {
+ guint8* data = NULL;
+ gint data_length1 = 0;
+ gint _data_size_ = 0;
+ guint8* _tmp0_ = NULL;
+ size_t _tmp1_;
+ gchar* _tmp2_;
+ gchar* _tmp3_;
+ FILE* _tmp4_ = NULL;
+ FILE* _tmp5_;
+ FILE* fixed_file;
+ gint offset;
+ gint line_number;
+ gint xref_offset;
+ gint xref_line;
+ GRegex* _tmp6_ = NULL;
+ GRegex* xref_regex;
+ GMatchInfo* xref_match = NULL;
+ GString* _tmp7_ = NULL;
+ GString* line;
+ gchar* _tmp25_;
+ gchar* _tmp26_;
+ gint _tmp27_;
+ gboolean _tmp28_;
+ GError * _inner_error_ = NULL;
+ g_return_if_fail (filename != NULL);
+ g_file_get_contents (filename, (gchar**) (&_tmp0_), &_tmp1_, &_inner_error_);
+ data = (g_free (data), NULL);
+ data = _tmp0_;
+ data_length1 = _tmp1_;
+ _data_size_ = data_length1;
+ if (_inner_error_ != NULL) {
+ g_propagate_error (error, _inner_error_);
+ data = (g_free (data), NULL);
+ return;
+ }
+ _tmp2_ = g_strconcat (filename, ".fixed", NULL);
+ _tmp3_ = _tmp2_;
+ _tmp4_ = fopen (_tmp3_, "w");
+ _tmp5_ = _tmp4_;
+ _g_free0 (_tmp3_);
+ fixed_file = _tmp5_;
+ offset = 0;
+ line_number = 0;
+ xref_offset = 0;
+ xref_line = -1;
+ _tmp6_ = g_regex_new ("^\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d 0000 n$", 0, 0, &_inner_error_);
+ xref_regex = _tmp6_;
+ if (_inner_error_ != NULL) {
+ g_propagate_error (error, _inner_error_);
+ _fclose0 (fixed_file);
+ data = (g_free (data), NULL);
+ return;
+ }
+ _tmp7_ = g_string_new ("");
+ line = _tmp7_;
+ while (TRUE) {
+ gint end_offset;
+ gboolean _tmp8_ = FALSE;
+ if (!(offset < data_length1)) {
+ break;
+ }
+ end_offset = offset;
+ g_string_assign (line, "");
+ while (TRUE) {
+ guint8 c;
+ if (!(end_offset < data_length1)) {
+ break;
+ }
+ c = data[end_offset];
+ g_string_append_c (line, (gchar) c);
+ end_offset++;
+ if (c == ((guint8) '\n')) {
+ break;
+ }
+ }
+ if (g_strcmp0 (line->str, "startxref\n") == 0) {
+ xref_line = line_number;
+ }
+ if (line_number < 2) {
+ gboolean _tmp9_;
+ _tmp9_ = g_str_has_prefix (line->str, "%%");
+ _tmp8_ = _tmp9_;
+ } else {
+ _tmp8_ = FALSE;
+ }
+ if (_tmp8_) {
+ gchar* _tmp10_ = NULL;
+ gchar* _tmp11_;
+ xref_offset--;
+ _tmp10_ = string_substring (line->str, (glong) 1, (glong) (-1));
+ _tmp11_ = _tmp10_;
+ fprintf (fixed_file, "%s", _tmp11_);
+ _g_free0 (_tmp11_);
+ } else {
+ GMatchInfo* _tmp12_ = NULL;
+ gboolean _tmp13_;
+ _tmp13_ = g_regex_match (xref_regex, line->str, 0, &_tmp12_);
+ _g_match_info_free0 (xref_match);
+ xref_match = _tmp12_;
+ if (_tmp13_) {
+ const gchar* _tmp14_ = NULL;
+ gint _tmp15_;
+ _tmp14_ = g_match_info_get_string (xref_match);
+ _tmp15_ = atoi (_tmp14_);
+ fprintf (fixed_file, "%010d 00000 n \n", _tmp15_ + xref_offset);
+ } else {
+ gboolean _tmp16_ = FALSE;
+ if (xref_line > 0) {
+ _tmp16_ = line_number == (xref_line + 1);
+ } else {
+ _tmp16_ = FALSE;
+ }
+ if (_tmp16_) {
+ gint _tmp17_;
+ gchar* _tmp18_ = NULL;
+ gchar* _tmp19_;
+ _tmp17_ = atoi (line->str);
+ _tmp18_ = g_strdup_printf ("%d\n", _tmp17_ + xref_offset);
+ _tmp19_ = _tmp18_;
+ fprintf (fixed_file, "%s", _tmp19_);
+ _g_free0 (_tmp19_);
+ } else {
+ gboolean _tmp20_ = FALSE;
+ if (line_number == (xref_line + 2)) {
+ gboolean _tmp21_;
+ _tmp21_ = g_str_has_prefix (line->str, "%%%%");
+ _tmp20_ = _tmp21_;
+ } else {
+ _tmp20_ = FALSE;
+ }
+ if (_tmp20_) {
+ gchar* _tmp22_ = NULL;
+ gchar* _tmp23_;
+ _tmp22_ = string_substring (line->str, (glong) 2, (glong) (-1));
+ _tmp23_ = _tmp22_;
+ fprintf (fixed_file, "%s", _tmp23_);
+ _g_free0 (_tmp23_);
+ } else {
+ {
+ gint i;
+ i = offset;
+ {
+ gboolean _tmp24_;
+ _tmp24_ = TRUE;
+ while (TRUE) {
+ if (!_tmp24_) {
+ i++;
+ }
+ _tmp24_ = FALSE;
+ if (!(i < end_offset)) {
+ break;
+ }
+ fputc ((gchar) data[i], fixed_file);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ line_number++;
+ offset = end_offset;
+ }
+ _tmp25_ = g_strconcat (filename, "~", NULL);
+ _tmp26_ = _tmp25_;
+ _tmp27_ = g_rename (filename, _tmp26_);
+ _tmp28_ = _tmp27_ >= 0;
+ _g_free0 (_tmp26_);
+ if (_tmp28_) {
+ gchar* _tmp29_;
+ gchar* _tmp30_;
+ _tmp29_ = g_strconcat (filename, ".fixed", NULL);
+ _tmp30_ = _tmp29_;
+ g_rename (_tmp30_, filename);
+ _g_free0 (_tmp30_);
+ }
+ _g_string_free0 (line);
+ _g_match_info_free0 (xref_match);
+ _g_regex_unref0 (xref_regex);
+ _fclose0 (fixed_file);
+ data = (g_free (data), NULL);
+}
+
+
static void _application_log_cb_glog_func (const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message, gpointer self) {
application_log_cb (log_domain, log_levels, message);
}
@@ -1221,15 +1464,15 @@ gint application_main (gchar** args, int args_length1) {
GOptionContext* c;
GOptionGroup* _tmp2_ = NULL;
ScanDevice* device;
- GTimer* _tmp7_ = NULL;
- const gchar* _tmp8_ = NULL;
- gchar* _tmp9_ = NULL;
+ GTimer* _tmp8_ = NULL;
+ const gchar* _tmp9_ = NULL;
+ gchar* _tmp10_ = NULL;
gchar* path;
- const gchar* _tmp10_ = NULL;
- gchar* _tmp11_ = NULL;
- FILE* _tmp12_ = NULL;
- pid_t _tmp13_;
- Application* _tmp14_ = NULL;
+ const gchar* _tmp11_ = NULL;
+ gchar* _tmp12_ = NULL;
+ FILE* _tmp13_ = NULL;
+ pid_t _tmp14_;
+ Application* _tmp15_ = NULL;
Application* app;
GError * _inner_error_ = NULL;
setlocale (LC_ALL, "");
@@ -1278,40 +1521,91 @@ gint application_main (gchar** args, int args_length1) {
_g_option_context_free0 (c);
return result;
}
+ if (application_fix_pdf_filename != NULL) {
+ {
+ application_fix_pdf (application_fix_pdf_filename, &_inner_error_);
+ if (_inner_error_ != NULL) {
+ goto __catch8_g_error;
+ }
+ {
+ gint i;
+ i = 1;
+ {
+ gboolean _tmp4_;
+ _tmp4_ = TRUE;
+ while (TRUE) {
+ if (!_tmp4_) {
+ i++;
+ }
+ _tmp4_ = FALSE;
+ if (!(i < args_length1)) {
+ break;
+ }
+ application_fix_pdf (args[i], &_inner_error_);
+ if (_inner_error_ != NULL) {
+ goto __catch8_g_error;
+ }
+ }
+ }
+ }
+ }
+ goto __finally8;
+ __catch8_g_error:
+ {
+ GError* e = NULL;
+ e = _inner_error_;
+ _inner_error_ = NULL;
+ fprintf (stderr, "Error fixing PDF file: %s", e->message);
+ result = EXIT_FAILURE;
+ _g_error_free0 (e);
+ _g_option_context_free0 (c);
+ return result;
+ }
+ __finally8:
+ if (_inner_error_ != NULL) {
+ _g_option_context_free0 (c);
+ g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
+ g_clear_error (&_inner_error_);
+ return 0;
+ }
+ result = EXIT_SUCCESS;
+ _g_option_context_free0 (c);
+ return result;
+ }
device = NULL;
if (args_length1 > 1) {
- ScanDevice* _tmp4_ = NULL;
- gchar* _tmp5_;
+ ScanDevice* _tmp5_ = NULL;
gchar* _tmp6_;
- _tmp4_ = scan_device_new ();
+ gchar* _tmp7_;
+ _tmp5_ = scan_device_new ();
_scan_device_unref0 (device);
- device = _tmp4_;
- _tmp5_ = g_strdup (args[1]);
- _g_free0 (device->name);
- device->name = _tmp5_;
+ device = _tmp5_;
_tmp6_ = g_strdup (args[1]);
+ _g_free0 (device->name);
+ device->name = _tmp6_;
+ _tmp7_ = g_strdup (args[1]);
_g_free0 (device->label);
- device->label = _tmp6_;
+ device->label = _tmp7_;
}
- _tmp7_ = g_timer_new ();
+ _tmp8_ = g_timer_new ();
_g_timer_destroy0 (application_log_timer);
- application_log_timer = _tmp7_;
- _tmp8_ = g_get_user_cache_dir ();
- _tmp9_ = g_build_filename (_tmp8_, "simple-scan", NULL, NULL);
- path = _tmp9_;
+ application_log_timer = _tmp8_;
+ _tmp9_ = g_get_user_cache_dir ();
+ _tmp10_ = g_build_filename (_tmp9_, "simple-scan", NULL, NULL);
+ path = _tmp10_;
g_mkdir_with_parents (path, 0700);
- _tmp10_ = g_get_user_cache_dir ();
- _tmp11_ = g_build_filename (_tmp10_, "simple-scan", "simple-scan.log", NULL, NULL);
+ _tmp11_ = g_get_user_cache_dir ();
+ _tmp12_ = g_build_filename (_tmp11_, "simple-scan", "simple-scan.log", NULL, NULL);
_g_free0 (path);
- path = _tmp11_;
- _tmp12_ = fopen (path, "w");
+ path = _tmp12_;
+ _tmp13_ = fopen (path, "w");
_fclose0 (application_log_file);
- application_log_file = _tmp12_;
+ application_log_file = _tmp13_;
g_log_set_default_handler (_application_log_cb_glog_func, NULL);
- _tmp13_ = getpid ();
- g_debug ("simple-scan.vala:507: Starting Simple Scan %s, PID=%i", VERSION, (gint) _tmp13_);
- _tmp14_ = application_new (device);
- app = _tmp14_;
+ _tmp14_ = getpid ();
+ g_debug ("simple-scan.vala:586: Starting Simple Scan %s, PID=%i", VERSION, (gint) _tmp14_);
+ _tmp15_ = application_new (device);
+ app = _tmp15_;
application_start (app);
gtk_main ();
result = EXIT_SUCCESS;
diff --git a/src/simple-scan.vala b/src/simple-scan.vala
index 0ced7ad..cff06f8 100644
--- a/src/simple-scan.vala
+++ b/src/simple-scan.vala
@@ -13,6 +13,7 @@ public class Application
{
static bool show_version;
static bool debug_enabled;
+ static string? fix_pdf_filename = null;
public static const OptionEntry[] options =
{
{ "version", 'v', 0, OptionArg.NONE, ref show_version,
@@ -21,6 +22,8 @@ public class Application
{ "debug", 'd', 0, OptionArg.NONE, ref debug_enabled,
/* Help string for command line --debug flag */
N_("Print debugging messages"), null},
+ { "fix-pdf", 0, 0, OptionArg.STRING, ref fix_pdf_filename,
+ N_("Fix PDF files generated with older versions of Simple Scan"), "FILENAME..."},
{ null }
};
private static Timer log_timer;
@@ -455,6 +458,67 @@ public class Application
{
scanner.redetect ();
}
+
+ private static void fix_pdf (string filename) throws Error
+ {
+ uint8[] data;
+ FileUtils.get_data (filename, out data);
+
+ var fixed_file = FileStream.open (filename + ".fixed", "w");
+
+ var offset = 0;
+ var line_number = 0;
+ var xref_offset = 0;
+ var xref_line = -1;
+ var xref_regex = new Regex ("^\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d 0000 n$");
+ MatchInfo xref_match;
+ var line = new StringBuilder ();
+ while (offset < data.length)
+ {
+ var end_offset = offset;
+ line.assign ("");
+ while (end_offset < data.length)
+ {
+ var c = data[end_offset];
+ line.append_c ((char) c);
+ end_offset++;
+ if (c == '\n')
+ break;
+ }
+
+ if (line.str == "startxref\n")
+ xref_line = line_number;
+
+ /* Fix PDF header and binary comment */
+ if (line_number < 2 && line.str.has_prefix ("%%"))
+ {
+ xref_offset--;
+ fixed_file.printf ("%s", line.str.substring (1));
+ }
+
+ /* Fix xref format */
+ else if (xref_regex.match (line.str, 0, out xref_match))
+ fixed_file.printf ("%010d 00000 n \n", int.parse (xref_match.get_string ()) + xref_offset);
+
+ /* Fix xref offset */
+ else if (xref_line > 0 && line_number == xref_line + 1)
+ fixed_file.printf ("%d\n".printf (int.parse (line.str) + xref_offset));
+
+ /* Fix EOF marker */
+ else if (line_number == xref_line + 2 && line.str.has_prefix ("%%%%"))
+ fixed_file.printf ("%s", line.str.substring (2));
+
+ else
+ for (var i = offset; i < end_offset; i++)
+ fixed_file.putc ((char) data[i]);
+
+ line_number++;
+ offset = end_offset;
+ }
+
+ if (FileUtils.rename (filename, filename + "~") >= 0)
+ FileUtils.rename (filename + ".fixed", filename);
+ }
public static int main (string[] args)
{
@@ -487,6 +551,21 @@ public class Application
stderr.printf ("simple-scan %s\n", Config.VERSION);
return Posix.EXIT_SUCCESS;
}
+ if (fix_pdf_filename != null)
+ {
+ try
+ {
+ fix_pdf (fix_pdf_filename);
+ for (var i = 1; i < args.length; i++)
+ fix_pdf (args[i]);
+ }
+ catch (Error e)
+ {
+ stderr.printf ("Error fixing PDF file: %s", e.message);
+ return Posix.EXIT_FAILURE;
+ }
+ return Posix.EXIT_SUCCESS;
+ }
ScanDevice? device = null;
if (args.length > 1)
diff --git a/src/ui.c b/src/ui.c
index 121d780..93a4506 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -1191,11 +1191,11 @@ static gboolean simple_scan_save_document (SimpleScan* self, gboolean force_choo
{
book_save (self->priv->book, format, file, &_inner_error_);
if (_inner_error_ != NULL) {
- goto __catch10_g_error;
+ goto __catch11_g_error;
}
}
- goto __finally10;
- __catch10_g_error:
+ goto __finally11;
+ __catch11_g_error:
{
GError* e = NULL;
const gchar* _tmp16_ = NULL;
@@ -1212,7 +1212,7 @@ static gboolean simple_scan_save_document (SimpleScan* self, gboolean force_choo
_g_free0 (uri);
return result;
}
- __finally10:
+ __finally11:
if (_inner_error_ != NULL) {
_g_free0 (format);
_g_free0 (uri_lower);
@@ -1769,12 +1769,12 @@ static gchar* simple_scan_get_temporary_filename (SimpleScan* self, const gchar*
path = _tmp1_;
fd = _tmp2_;
if (_inner_error_ != NULL) {
- goto __catch11_g_error;
+ goto __catch12_g_error;
}
close (fd);
}
- goto __finally11;
- __catch11_g_error:
+ goto __finally12;
+ __catch12_g_error:
{
GError* e = NULL;
e = _inner_error_;
@@ -1786,7 +1786,7 @@ static gchar* simple_scan_get_temporary_filename (SimpleScan* self, const gchar*
_g_free0 (filename);
return result;
}
- __finally11:
+ __finally12:
if (_inner_error_ != NULL) {
_g_free0 (path);
_g_free0 (filename);
@@ -1820,11 +1820,11 @@ static void simple_scan_show_page_cb (SimpleScan* self, BookView* view, Page* pa
{
page_save (page, "tiff", file, &_inner_error_);
if (_inner_error_ != NULL) {
- goto __catch12_g_error;
+ goto __catch13_g_error;
}
}
- goto __finally12;
- __catch12_g_error:
+ goto __finally13;
+ __catch13_g_error:
{
GError* e = NULL;
const gchar* _tmp2_ = NULL;
@@ -1837,7 +1837,7 @@ static void simple_scan_show_page_cb (SimpleScan* self, BookView* view, Page* pa
_g_free0 (path);
return;
}
- __finally12:
+ __finally13:
if (_inner_error_ != NULL) {
_g_object_unref0 (file);
_g_free0 (path);
@@ -1857,11 +1857,11 @@ static void simple_scan_show_page_cb (SimpleScan* self, BookView* view, Page* pa
gtk_show_uri (_tmp3_, _tmp5_, _tmp6_, &_inner_error_);
_g_free0 (_tmp5_);
if (_inner_error_ != NULL) {
- goto __catch13_g_error;
+ goto __catch14_g_error;
}
}
- goto __finally13;
- __catch13_g_error:
+ goto __finally14;
+ __catch14_g_error:
{
GError* e = NULL;
const gchar* _tmp7_ = NULL;
@@ -1871,7 +1871,7 @@ static void simple_scan_show_page_cb (SimpleScan* self, BookView* view, Page* pa
simple_scan_show_error_dialog (self, _tmp7_, e->message);
_g_error_free0 (e);
}
- __finally13:
+ __finally14:
if (_inner_error_ != NULL) {
_g_object_unref0 (file);
_g_free0 (path);
@@ -2266,11 +2266,11 @@ void G_MODULE_EXPORT print_button_clicked_cb (GtkWidget* widget, SimpleScan* sel
{
gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, self->priv->window, &_inner_error_);
if (_inner_error_ != NULL) {
- goto __catch14_g_error;
+ goto __catch15_g_error;
}
}
- goto __finally14;
- __catch14_g_error:
+ goto __finally15;
+ __catch15_g_error:
{
GError* e = NULL;
e = _inner_error_;
@@ -2278,7 +2278,7 @@ void G_MODULE_EXPORT print_button_clicked_cb (GtkWidget* widget, SimpleScan* sel
g_warning ("ui.vala:1044: Error printing: %s", e->message);
_g_error_free0 (e);
}
- __finally14:
+ __finally15:
if (_inner_error_ != NULL) {
_g_object_unref0 (print);
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
@@ -2300,11 +2300,11 @@ void G_MODULE_EXPORT help_contents_menuitem_activate_cb (GtkWidget* widget, Simp
_tmp1_ = gtk_get_current_event_time ();
gtk_show_uri (_tmp0_, "ghelp:simple-scan", _tmp1_, &_inner_error_);
if (_inner_error_ != NULL) {
- goto __catch15_g_error;
+ goto __catch16_g_error;
}
}
- goto __finally15;
- __catch15_g_error:
+ goto __finally16;
+ __catch16_g_error:
{
GError* e = NULL;
const gchar* _tmp2_ = NULL;
@@ -2314,7 +2314,7 @@ void G_MODULE_EXPORT help_contents_menuitem_activate_cb (GtkWidget* widget, Simp
simple_scan_show_error_dialog (self, _tmp2_, e->message);
_g_error_free0 (e);
}
- __finally15:
+ __finally16:
if (_inner_error_ != NULL) {
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
g_clear_error (&_inner_error_);
@@ -2820,11 +2820,11 @@ static void simple_scan_load (SimpleScan* self) {
{
gtk_builder_add_from_file (self->priv->builder, filename, &_inner_error_);
if (_inner_error_ != NULL) {
- goto __catch16_g_error;
+ goto __catch17_g_error;
}
}
- goto __finally16;
- __catch16_g_error:
+ goto __finally17;
+ __catch17_g_error:
{
GError* e = NULL;
const gchar* _tmp3_ = NULL;
@@ -2838,7 +2838,7 @@ static void simple_scan_load (SimpleScan* self) {
exit (EXIT_FAILURE);
_g_error_free0 (e);
}
- __finally16:
+ __finally17:
if (_inner_error_ != NULL) {
_g_free0 (filename);
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);