X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fxo-file.c;h=082d399f36c3d4d26ae9bc7970d9a685ae091cb6;hb=69037d6ddbe7e90d13d8a7a088d8c209a926190e;hp=2ac09fd9964966b59871bbb80c12e0a02ea88bce;hpb=5b10083203ad4e798c25ed35110ab7e7440656b8;p=xournal.git
diff --git a/src/xo-file.c b/src/xo-file.c
index 2ac09fd..082d399 100644
--- a/src/xo-file.c
+++ b/src/xo-file.c
@@ -1,3 +1,18 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
#ifdef HAVE_CONFIG_H
# include
#endif
@@ -11,9 +26,15 @@
#include
#include
#include
-#include
-#include
#include
+#include
+#include
+#include
+
+#ifndef WIN32
+ #include
+ #include
+#endif
#include "xournal.h"
#include "xo-interface.h"
@@ -22,8 +43,9 @@
#include "xo-misc.h"
#include "xo-file.h"
#include "xo-paint.h"
+#include "xo-image.h"
-const char *tool_names[NUM_TOOLS] = {"pen", "eraser", "highlighter", "text", "", "selectrect", "vertspace", "hand"};
+const char *tool_names[NUM_TOOLS] = {"pen", "eraser", "highlighter", "text", "selectregion", "selectrect", "vertspace", "hand", "image"};
const char *color_names[COLOR_MAX] = {"black", "blue", "red", "green",
"gray", "lightblue", "lightgreen", "magenta", "orange", "yellow", "white"};
const char *bgtype_names[3] = {"solid", "pixmap", "pdf"};
@@ -65,6 +87,47 @@ void chk_attach_names(void)
}
}
+/* Write image to file: returns true on success, false on error.
+ The image is written as a base64 encoded PNG. */
+
+gboolean write_image(gzFile f, Item *item)
+{
+ gchar *base64_str;
+
+ if (item->image_png == NULL) {
+ if (!gdk_pixbuf_save_to_buffer(item->image, &item->image_png, &item->image_png_len, "png", NULL, NULL)) {
+ item->image_png_len = 0; // failed for some reason, so forget it
+ return FALSE;
+ }
+ }
+
+ base64_str = g_base64_encode(item->image_png, item->image_png_len);
+ gzputs(f, base64_str);
+ g_free(base64_str);
+ return TRUE;
+}
+
+// create pixbuf from base64 encoded PNG, or return NULL on failure
+
+GdkPixbuf *read_pixbuf(const gchar *base64_str, gsize base64_strlen)
+{
+ gchar *base64_str2;
+ gchar *png_buf;
+ gsize png_buflen;
+ GdkPixbuf *pixbuf;
+
+ // We have to copy the string in order to null terminate it, sigh.
+ base64_str2 = g_memdup(base64_str, base64_strlen+1);
+ base64_str2[base64_strlen] = 0;
+ png_buf = g_base64_decode(base64_str2, &png_buflen);
+
+ pixbuf = pixbuf_from_buffer(png_buf, png_buflen);
+
+ g_free(png_buf);
+ g_free(base64_str2);
+ return pixbuf;
+}
+
// saves the journal to a file: returns true on success, false on error
gboolean save_journal(const char *filename)
@@ -75,14 +138,12 @@ gboolean save_journal(const char *filename)
struct Item *item;
int i, is_clone;
char *tmpfn, *tmpstr;
- gchar *pdfbuf;
- gsize pdflen;
gboolean success;
FILE *tmpf;
GList *pagelist, *layerlist, *itemlist, *list;
GtkWidget *dialog;
- f = gzopen(filename, "w");
+ f = gzopen(filename, "wb");
if (f==NULL) return FALSE;
chk_attach_names();
@@ -118,14 +179,16 @@ gboolean save_journal(const char *filename)
if (!gdk_pixbuf_save(pg->bg->pixbuf, tmpfn, "png", NULL, NULL)) {
dialog = gtk_message_dialog_new(GTK_WINDOW(winMain), GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
- "Could not write background '%s'. Continuing anyway.", tmpfn);
+ _("Could not write background '%s'. Continuing anyway."), tmpfn);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
g_free(tmpfn);
}
+ tmpstr = g_markup_escape_text(pg->bg->filename->s, -1);
gzprintf(f, "domain=\"%s\" filename=\"%s\" ",
- file_domain_names[pg->bg->file_domain], pg->bg->filename->s);
+ file_domain_names[pg->bg->file_domain], tmpstr);
+ g_free(tmpstr);
}
}
else if (pg->bg->type == BG_PDF) {
@@ -138,26 +201,26 @@ gboolean save_journal(const char *filename)
if (pg->bg->file_domain == DOMAIN_ATTACH) {
tmpfn = g_strdup_printf("%s.%s", filename, pg->bg->filename->s);
success = FALSE;
- if (bgpdf.status != STATUS_NOT_INIT &&
- g_file_get_contents(bgpdf.tmpfile_copy, &pdfbuf, &pdflen, NULL))
+ if (bgpdf.status != STATUS_NOT_INIT && bgpdf.file_contents != NULL)
{
- tmpf = fopen(tmpfn, "w");
- if (tmpf != NULL && fwrite(pdfbuf, 1, pdflen, tmpf) == pdflen)
+ tmpf = fopen(tmpfn, "wb");
+ if (tmpf != NULL && fwrite(bgpdf.file_contents, 1, bgpdf.file_length, tmpf) == bgpdf.file_length)
success = TRUE;
- g_free(pdfbuf);
fclose(tmpf);
}
if (!success) {
dialog = gtk_message_dialog_new(GTK_WINDOW(winMain), GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
- "Could not write background '%s'. Continuing anyway.", tmpfn);
+ _("Could not write background '%s'. Continuing anyway."), tmpfn);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
g_free(tmpfn);
}
+ tmpstr = g_markup_escape_text(pg->bg->filename->s, -1);
gzprintf(f, "domain=\"%s\" filename=\"%s\" ",
- file_domain_names[pg->bg->file_domain], pg->bg->filename->s);
+ file_domain_names[pg->bg->file_domain], tmpstr);
+ g_free(tmpstr);
}
gzprintf(f, "pageno=\"%d\" ", pg->bg->file_page_seq);
}
@@ -174,22 +237,35 @@ gboolean save_journal(const char *filename)
gzputs(f, color_names[item->brush.color_no]);
else
gzprintf(f, "#%08x", item->brush.color_rgba);
- gzprintf(f, "\" width=\"%.2f\">\n", item->brush.thickness);
+ gzprintf(f, "\" width=\"%.2f", item->brush.thickness);
+ if (item->brush.variable_width)
+ for (i=0;ipath->num_points-1;i++)
+ gzprintf(f, " %.2f", item->widths[i]);
+ gzprintf(f, "\">\n");
for (i=0;i<2*item->path->num_points;i++)
gzprintf(f, "%.2f ", item->path->coords[i]);
gzprintf(f, "\n\n");
}
if (item->type == ITEM_TEXT) {
+ tmpstr = g_markup_escape_text(item->font_name, -1);
gzprintf(f, "font_name, item->font_size, item->bbox.left, item->bbox.top);
+ tmpstr, item->font_size, item->bbox.left, item->bbox.top);
+ g_free(tmpstr);
if (item->brush.color_no >= 0)
gzputs(f, color_names[item->brush.color_no]);
else
gzprintf(f, "#%08x", item->brush.color_rgba);
tmpstr = g_markup_escape_text(item->text, -1);
- gzprintf(f, "\">%s\n", tmpstr);
+ gzputs(f, "\">");
+ gzputs(f, tmpstr); // gzprintf() can't handle > 4095 bytes
+ gzputs(f, "\n");
g_free(tmpstr);
-
+ }
+ if (item->type == ITEM_IMAGE) {
+ gzprintf(f, "",
+ item->bbox.left, item->bbox.top, item->bbox.right, item->bbox.bottom);
+ if (!write_image(f, item)) success = FALSE;
+ gzprintf(f, "\n");
}
}
gzprintf(f, "\n");
@@ -211,6 +287,7 @@ gboolean close_journal(void)
// free everything...
reset_selection();
+ reset_recognizer();
clear_redo_stack();
clear_undo_stack();
@@ -223,10 +300,16 @@ gboolean close_journal(void)
}
// sanitize a string containing floats, in case it may have , instead of .
+// also replace Windows-produced 1.#J by inf
void cleanup_numeric(char *s)
{
- while (*s!=0) { if (*s==',') *s='.'; s++; }
+ while (*s!=0) {
+ if (*s==',') *s='.';
+ if (*s=='1' && s[1]=='.' && s[2]=='#' && s[3]=='J')
+ { *s='i'; s[1]='n'; s[2]='f'; s[3]=' '; }
+ s++;
+ }
}
// the XML parser functions for open_journal()
@@ -240,7 +323,7 @@ struct Background *tmpBg_pdf;
GError *xoj_invalid(void)
{
- return g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Invalid file contents");
+ return g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, _("Invalid file contents"));
}
void xoj_parser_start_element(GMarkupParseContext *context,
@@ -248,9 +331,10 @@ void xoj_parser_start_element(GMarkupParseContext *context,
const gchar **attribute_values, gpointer user_data, GError **error)
{
int has_attr, i;
- char *ptr;
+ char *ptr, *tmpptr;
struct Background *tmpbg;
char *tmpbg_filename;
+ gdouble val;
GtkWidget *dialog;
if (!strcmp(element_name, "title") || !strcmp(element_name, "xournal")) {
@@ -333,7 +417,7 @@ void xoj_parser_start_element(GMarkupParseContext *context,
}
// there's also the case of hex (#rrggbbaa) colors
if (tmpPage->bg->color_no == COLOR_OTHER && **attribute_values == '#') {
- tmpPage->bg->color_rgba = strtol(*attribute_values + 1, &ptr, 16);
+ tmpPage->bg->color_rgba = strtoul(*attribute_values + 1, &ptr, 16);
if (*ptr!=0) *error = xoj_invalid();
}
has_attr |= 2;
@@ -389,7 +473,7 @@ void xoj_parser_start_element(GMarkupParseContext *context,
if (tmpPage->bg->pixbuf == NULL) {
dialog = gtk_message_dialog_new(GTK_WINDOW(winMain), GTK_DIALOG_MODAL,
GTK_MESSAGE_WARNING, GTK_BUTTONS_OK,
- "Could not open background '%s'. Setting background to white.",
+ _("Could not open background '%s'. Setting background to white."),
tmpbg_filename);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
@@ -438,6 +522,7 @@ void xoj_parser_start_element(GMarkupParseContext *context,
tmpItem->type = ITEM_STROKE;
tmpItem->path = NULL;
tmpItem->canvas_item = NULL;
+ tmpItem->widths = NULL;
tmpLayer->items = g_list_append(tmpLayer->items, tmpItem);
tmpLayer->nitems++;
// scan for tool, color, and width attributes
@@ -448,6 +533,20 @@ void xoj_parser_start_element(GMarkupParseContext *context,
cleanup_numeric((gchar *)*attribute_values);
tmpItem->brush.thickness = g_ascii_strtod(*attribute_values, &ptr);
if (ptr == *attribute_values) *error = xoj_invalid();
+ i = 0;
+ while (*ptr!=0) {
+ realloc_cur_widths(i+1);
+ ui.cur_widths[i] = g_ascii_strtod(ptr, &tmpptr);
+ if (tmpptr == ptr) break;
+ ptr = tmpptr;
+ i++;
+ }
+ tmpItem->brush.variable_width = (i>0);
+ if (i>0) {
+ tmpItem->brush.variable_width = TRUE;
+ tmpItem->widths = (gdouble *) g_memdup(ui.cur_widths, i*sizeof(gdouble));
+ ui.cur_path.num_points = i+1;
+ }
has_attr |= 1;
}
else if (!strcmp(*attribute_names, "color")) {
@@ -460,7 +559,7 @@ void xoj_parser_start_element(GMarkupParseContext *context,
}
// there's also the case of hex (#rrggbbaa) colors
if (tmpItem->brush.color_no == COLOR_OTHER && **attribute_values == '#') {
- tmpItem->brush.color_rgba = strtol(*attribute_values + 1, &ptr, 16);
+ tmpItem->brush.color_rgba = strtoul(*attribute_values + 1, &ptr, 16);
if (*ptr!=0) *error = xoj_invalid();
}
has_attr |= 2;
@@ -483,6 +582,8 @@ void xoj_parser_start_element(GMarkupParseContext *context,
// finish filling the brush info
tmpItem->brush.thickness_no = 0; // who cares ?
tmpItem->brush.tool_options = 0; // who cares ?
+ tmpItem->brush.ruler = FALSE;
+ tmpItem->brush.recognizer = FALSE;
if (tmpItem->brush.tool_type == TOOL_HIGHLIGHTER) {
if (tmpItem->brush.color_no >= 0)
tmpItem->brush.color_rgba &= ui.hiliter_alpha_mask;
@@ -537,7 +638,7 @@ void xoj_parser_start_element(GMarkupParseContext *context,
}
// there's also the case of hex (#rrggbbaa) colors
if (tmpItem->brush.color_no == COLOR_OTHER && **attribute_values == '#') {
- tmpItem->brush.color_rgba = strtol(*attribute_values + 1, &ptr, 16);
+ tmpItem->brush.color_rgba = strtoul(*attribute_values + 1, &ptr, 16);
if (*ptr!=0) *error = xoj_invalid();
}
has_attr |= 16;
@@ -548,6 +649,56 @@ void xoj_parser_start_element(GMarkupParseContext *context,
}
if (has_attr!=31) *error = xoj_invalid();
}
+ else if (!strcmp(element_name, "image")) { // start of a image item
+ if (tmpLayer == NULL || tmpItem != NULL) {
+ *error = xoj_invalid();
+ return;
+ }
+ tmpItem = (struct Item *)g_malloc0(sizeof(struct Item));
+ tmpItem->type = ITEM_IMAGE;
+ tmpItem->canvas_item = NULL;
+ tmpItem->image=NULL;
+ tmpItem->image_png = NULL;
+ tmpItem->image_png_len = 0;
+ tmpLayer->items = g_list_append(tmpLayer->items, tmpItem);
+ tmpLayer->nitems++;
+ // scan for x, y
+ has_attr = 0;
+ while (*attribute_names!=NULL) {
+ if (!strcmp(*attribute_names, "left")) {
+ if (has_attr & 1) *error = xoj_invalid();
+ cleanup_numeric((gchar *)*attribute_values);
+ tmpItem->bbox.left = g_ascii_strtod(*attribute_values, &ptr);
+ if (ptr == *attribute_values) *error = xoj_invalid();
+ has_attr |= 1;
+ }
+ else if (!strcmp(*attribute_names, "top")) {
+ if (has_attr & 2) *error = xoj_invalid();
+ cleanup_numeric((gchar *)*attribute_values);
+ tmpItem->bbox.top = g_ascii_strtod(*attribute_values, &ptr);
+ if (ptr == *attribute_values) *error = xoj_invalid();
+ has_attr |= 2;
+ }
+ else if (!strcmp(*attribute_names, "right")) {
+ if (has_attr & 4) *error = xoj_invalid();
+ cleanup_numeric((gchar *)*attribute_values);
+ tmpItem->bbox.right = g_ascii_strtod(*attribute_values, &ptr);
+ if (ptr == *attribute_values) *error = xoj_invalid();
+ has_attr |= 4;
+ }
+ else if (!strcmp(*attribute_names, "bottom")) {
+ if (has_attr & 8) *error = xoj_invalid();
+ cleanup_numeric((gchar *)*attribute_values);
+ tmpItem->bbox.bottom = g_ascii_strtod(*attribute_values, &ptr);
+ if (ptr == *attribute_values) *error = xoj_invalid();
+ has_attr |= 8;
+ }
+ else *error = xoj_invalid();
+ attribute_names++;
+ attribute_values++;
+ }
+ if (has_attr!=15) *error = xoj_invalid();
+ }
}
void xoj_parser_end_element(GMarkupParseContext *context,
@@ -583,6 +734,13 @@ void xoj_parser_end_element(GMarkupParseContext *context,
}
tmpItem = NULL;
}
+ if (!strcmp(element_name, "image")) {
+ if (tmpItem == NULL) {
+ *error = xoj_invalid();
+ return;
+ }
+ tmpItem = NULL;
+ }
}
void xoj_parser_text(GMarkupParseContext *context,
@@ -603,9 +761,15 @@ void xoj_parser_text(GMarkupParseContext *context,
if (ptr == text) break;
text_len -= (ptr - text);
text = ptr;
+ if (!finite_sized(ui.cur_path.coords[n])) {
+ if (n>=2) ui.cur_path.coords[n] = ui.cur_path.coords[n-2];
+ else ui.cur_path.coords[n] = 0;
+ }
n++;
}
- if (n<4 || n&1) { *error = xoj_invalid(); return; }
+ if (n<4 || n&1 ||
+ (tmpItem->brush.variable_width && (n!=2*ui.cur_path.num_points)))
+ { *error = xoj_invalid(); return; } // wrong number of points
tmpItem->path = gnome_canvas_points_new(n/2);
g_memmove(tmpItem->path->coords, ui.cur_path.coords, n*sizeof(double));
}
@@ -614,6 +778,9 @@ void xoj_parser_text(GMarkupParseContext *context,
g_memmove(tmpItem->text, text, text_len);
tmpItem->text[text_len]=0;
}
+ if (!strcmp(element_name, "image")) {
+ tmpItem->image = read_pixbuf(text, text_len);
+ }
}
gboolean user_wants_second_chance(char **filename)
@@ -624,24 +791,29 @@ gboolean user_wants_second_chance(char **filename)
dialog = gtk_message_dialog_new(GTK_WINDOW(winMain), GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_BUTTONS_YES_NO,
- "Could not open background '%s'.\nSelect another file?",
+ _("Could not open background '%s'.\nSelect another file?"),
*filename);
response = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
if (response != GTK_RESPONSE_YES) return FALSE;
- dialog = gtk_file_chooser_dialog_new("Open PDF", GTK_WINDOW (winMain),
+ dialog = gtk_file_chooser_dialog_new(_("Open PDF"), GTK_WINDOW (winMain),
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
-
+#ifdef FILE_DIALOG_SIZE_BUGFIX
+ gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400);
+#endif
+
filt_all = gtk_file_filter_new();
- gtk_file_filter_set_name(filt_all, "All files");
+ gtk_file_filter_set_name(filt_all, _("All files"));
gtk_file_filter_add_pattern(filt_all, "*");
filt_pdf = gtk_file_filter_new();
- gtk_file_filter_set_name(filt_pdf, "PDF files");
+ gtk_file_filter_set_name(filt_pdf, _("PDF files"));
gtk_file_filter_add_pattern(filt_pdf, "*.pdf");
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_pdf);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_all);
+ if (ui.default_path!=NULL) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), ui.default_path);
+
if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
gtk_widget_destroy(dialog);
return FALSE;
@@ -664,11 +836,25 @@ gboolean open_journal(char *filename)
gzFile f;
char buffer[1000];
int len;
- gchar *tmpfn;
+ gchar *tmpfn, *tmpfn2, *p, *q;
gboolean maybe_pdf;
- f = gzopen(filename, "r");
+ tmpfn = g_strdup_printf("%s.xoj", filename);
+ if (ui.autoload_pdf_xoj && g_file_test(tmpfn, G_FILE_TEST_EXISTS) &&
+ (g_str_has_suffix(filename, ".pdf") || g_str_has_suffix(filename, ".PDF")))
+ {
+ valid = open_journal(tmpfn);
+ g_free(tmpfn);
+ return valid;
+ }
+ g_free(tmpfn);
+
+ f = gzopen(filename, "rb");
if (f==NULL) return FALSE;
+ if (filename[0]=='/') {
+ if (ui.default_path != NULL) g_free(ui.default_path);
+ ui.default_path = g_path_get_dirname(filename);
+ }
context = g_markup_parse_context_new(&parser, 0, NULL, NULL);
valid = TRUE;
@@ -723,7 +909,21 @@ gboolean open_journal(char *filename)
else
tmpfn = g_strdup(tmpBg_pdf->filename->s);
valid = init_bgpdf(tmpfn, FALSE, tmpBg_pdf->file_domain);
- // in case the file name became invalid
+ // if file name is invalid: first try in xoj file's directory
+ if (!valid && tmpBg_pdf->file_domain != DOMAIN_ATTACH) {
+ p = g_path_get_dirname(filename);
+ q = g_path_get_basename(tmpfn);
+ tmpfn2 = g_strdup_printf("%s/%s", p, q);
+ g_free(p); g_free(q);
+ valid = init_bgpdf(tmpfn2, FALSE, tmpBg_pdf->file_domain);
+ if (valid) { // change the file name...
+ printf("substituting %s -> %s\n", tmpfn, tmpfn2);
+ g_free(tmpBg_pdf->filename->s);
+ tmpBg_pdf->filename->s = tmpfn2;
+ }
+ else g_free(tmpfn2);
+ }
+ // if file name is invalid: next prompt user
if (!valid && tmpBg_pdf->file_domain != DOMAIN_ATTACH)
if (user_wants_second_chance(&tmpfn)) {
valid = init_bgpdf(tmpfn, FALSE, tmpBg_pdf->file_domain);
@@ -737,7 +937,7 @@ gboolean open_journal(char *filename)
bgpdf.filename = refstring_ref(tmpBg_pdf->filename);
} else {
dialog = gtk_message_dialog_new(GTK_WINDOW(winMain), GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Could not open background '%s'.",
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not open background '%s'."),
tmpfn);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
@@ -755,6 +955,7 @@ gboolean open_journal(char *filename)
gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
make_canvas_items();
update_page_stuff();
+ rescale_bg_pixmaps(); // this requests the PDF pages if need be
gtk_adjustment_set_value(gtk_layout_get_vadjustment(GTK_LAYOUT(canvas)), 0);
return TRUE;
}
@@ -797,7 +998,7 @@ GList *attempt_load_gv_bg(char *filename)
char *pipename;
int buflen, remnlen, file_pageno;
- f = fopen(filename, "r");
+ f = fopen(filename, "rb");
if (f == NULL) return NULL;
buf = g_malloc(BUFSIZE); // a reasonable buffer size
if (fread(buf, 1, 4, f) !=4 ||
@@ -809,7 +1010,7 @@ GList *attempt_load_gv_bg(char *filename)
fclose(f);
pipename = g_strdup_printf(GS_CMDLINE, (double)GS_BITMAP_DPI, filename);
- gs_pipe = popen(pipename, "r");
+ gs_pipe = popen(pipename, "rb");
g_free(pipename);
bg_list = NULL;
@@ -855,13 +1056,12 @@ GList *attempt_load_gv_bg(char *filename)
struct Background *attempt_screenshot_bg(void)
{
+#ifndef WIN32
struct Background *bg;
GdkPixbuf *pix;
XEvent x_event;
- GError *error = NULL;
GdkWindow *window;
- int x,y,w,h, status;
- unsigned int tmp;
+ int x,y,w,h;
Window x_root, x_win;
x_root = gdk_x11_get_default_root_xwindow();
@@ -893,27 +1093,14 @@ struct Background *attempt_screenshot_bg(void)
bg->filename = new_refstring(NULL);
bg->file_domain = DOMAIN_ATTACH;
return bg;
+#else
+ // not implemented under WIN32
+ return FALSE;
+#endif
}
/************** pdf annotation ***************/
-/* free tmp directory */
-
-void end_bgpdf_shutdown(void)
-{
- if (bgpdf.tmpdir!=NULL) {
- if (bgpdf.tmpfile_copy!=NULL) {
- g_unlink(bgpdf.tmpfile_copy);
- g_free(bgpdf.tmpfile_copy);
- bgpdf.tmpfile_copy = NULL;
- }
- g_rmdir(bgpdf.tmpdir);
- g_free(bgpdf.tmpdir);
- bgpdf.tmpdir = NULL;
- }
- bgpdf.status = STATUS_NOT_INIT;
-}
-
/* cancel a request */
void cancel_bgpdf_request(struct BgPdfRequest *req)
@@ -922,46 +1109,67 @@ void cancel_bgpdf_request(struct BgPdfRequest *req)
list_link = g_list_find(bgpdf.requests, req);
if (list_link == NULL) return;
- if (list_link->prev == NULL && bgpdf.pid > 0) {
- // this is being processed: kill the child but don't remove the request yet
- if (bgpdf.status == STATUS_RUNNING) bgpdf.status = STATUS_ABORTED;
- kill(bgpdf.pid, SIGHUP);
-// printf("Cancelling a request - killing %d\n", bgpdf.pid);
- }
- else {
- // remove the request
- bgpdf.requests = g_list_delete_link(bgpdf.requests, list_link);
- g_free(req);
-// printf("Cancelling a request - no kill needed\n");
- }
+ // remove the request
+ bgpdf.requests = g_list_delete_link(bgpdf.requests, list_link);
+ g_free(req);
}
-/* sigchld callback */
+/* process a bg PDF request from the queue, and recurse */
-void bgpdf_child_handler(GPid pid, gint status, gpointer data)
+gboolean bgpdf_scheduler_callback(gpointer data)
{
struct BgPdfRequest *req;
struct BgPdfPage *bgpg;
- gchar *ppm_name;
GdkPixbuf *pixbuf;
- int npad, ret;
-
- if (bgpdf.requests == NULL) return;
+ GtkWidget *dialog;
+ PopplerPage *pdfpage;
+ gdouble height, width;
+ int scaled_height, scaled_width;
+ GdkPixmap *pixmap;
+ cairo_t *cr;
+
+ // if all requests have been cancelled, remove ourselves from main loop
+ if (bgpdf.requests == NULL) { bgpdf.pid = 0; return FALSE; }
+ if (bgpdf.status == STATUS_NOT_INIT)
+ { printf("DEBUG: BGPDF not initialized??\n"); bgpdf.pid = 0; return FALSE; }
+
req = (struct BgPdfRequest *)bgpdf.requests->data;
-
+
+ // use poppler to generate the page
pixbuf = NULL;
- // pdftoppm used to generate p-nnnnnn.ppm (6 digits); new versions produce variable width
- for (npad = 6; npad>0; npad--) {
- ppm_name = g_strdup_printf("%s/p-%0*d.ppm", bgpdf.tmpdir, npad, req->pageno);
- if (bgpdf.status != STATUS_ABORTED && bgpdf.status != STATUS_SHUTDOWN)
- pixbuf = gdk_pixbuf_new_from_file(ppm_name, NULL);
- ret = unlink(ppm_name);
- g_free(ppm_name);
- if (pixbuf != NULL || ret == 0) break;
+ pdfpage = poppler_document_get_page(bgpdf.document, req->pageno-1);
+ if (pdfpage) {
+// printf("DEBUG: Processing request for page %d at %f dpi\n", req->pageno, req->dpi);
+ set_cursor_busy(TRUE);
+ poppler_page_get_size(pdfpage, &width, &height);
+ scaled_width = (int) (req->dpi * width/72);
+ scaled_height = (int) (req->dpi * height/72);
+
+ if (ui.poppler_force_cairo) { // poppler -> cairo -> pixmap -> pixbuf
+ pixmap = gdk_pixmap_new(GTK_WIDGET(canvas)->window, scaled_width, scaled_height, -1);
+ cr = gdk_cairo_create(pixmap);
+ cairo_set_source_rgb(cr, 1., 1., 1.);
+ cairo_paint(cr);
+ cairo_scale(cr, scaled_width/width, scaled_height/height);
+ poppler_page_render(pdfpage, cr);
+ cairo_destroy(cr);
+ pixbuf = gdk_pixbuf_get_from_drawable(NULL, GDK_DRAWABLE(pixmap),
+ NULL, 0, 0, 0, 0, scaled_width, scaled_height);
+ g_object_unref(pixmap);
+ }
+ else { // directly poppler -> pixbuf: faster, but bitmap font bug
+ pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
+ FALSE, 8, scaled_width, scaled_height);
+ wrapper_poppler_page_render_to_pixbuf(
+ pdfpage, 0, 0, scaled_width, scaled_height,
+ req->dpi/72, 0, pixbuf);
+ }
+ g_object_unref(pdfpage);
+ set_cursor_busy(FALSE);
}
+ // process the generated pixbuf...
if (pixbuf != NULL) { // success
-// printf("success\n");
while (req->pageno > bgpdf.npages) {
bgpg = g_new(struct BgPdfPage, 1);
bgpg->pixbuf = NULL;
@@ -972,125 +1180,50 @@ void bgpdf_child_handler(GPid pid, gint status, gpointer data)
if (bgpg->pixbuf!=NULL) gdk_pixbuf_unref(bgpg->pixbuf);
bgpg->pixbuf = pixbuf;
bgpg->dpi = req->dpi;
- if (req->initial_request && bgpdf.create_pages) {
- bgpdf_create_page_with_bg(req->pageno, bgpg);
- // create page n, resize it, set its bg - all without any undo effect
- } else {
- if (!req->is_printing) bgpdf_update_bg(req->pageno, bgpg);
- // look for all pages with this bg, and update their bg pixmaps
- }
- }
- else {
-// printf("failed or aborted\n");
- bgpdf.create_pages = FALSE;
- req->initial_request = FALSE;
- }
-
- bgpdf.pid = 0;
- g_spawn_close_pid(pid);
-
- if (req->initial_request)
- req->pageno++; // try for next page
- else
- bgpdf.requests = g_list_delete_link(bgpdf.requests, bgpdf.requests);
-
- if (bgpdf.status == STATUS_SHUTDOWN) {
- end_bgpdf_shutdown();
- return;
- }
-
- bgpdf.status = STATUS_IDLE;
- if (bgpdf.requests != NULL) bgpdf_spawn_child();
-}
-
-/* spawn a child to process the head request */
-
-void bgpdf_spawn_child(void)
-{
- struct BgPdfRequest *req;
- GPid pid;
- gchar pageno_str[10], dpi_str[10];
- gchar *pdf_filename = bgpdf.tmpfile_copy;
- gchar *ppm_root = g_strdup_printf("%s/p", bgpdf.tmpdir);
- gchar *argv[]= PDFTOPPM_ARGV;
- GtkWidget *dialog;
-
- if (bgpdf.requests == NULL) return;
- req = (struct BgPdfRequest *)bgpdf.requests->data;
- if (req->pageno > bgpdf.npages+1 ||
- (!req->initial_request && req->pageno <= bgpdf.npages &&
- req->dpi == ((struct BgPdfPage *)g_list_nth_data(bgpdf.pages, req->pageno-1))->dpi))
- { // ignore this request - it's redundant, or in outer space
- bgpdf.pid = 0;
- bgpdf.status = STATUS_IDLE;
- bgpdf.requests = g_list_delete_link(bgpdf.requests, bgpdf.requests);
- g_free(ppm_root);
- if (bgpdf.requests != NULL) bgpdf_spawn_child();
- return;
- }
- g_snprintf(pageno_str, 10, "%d", req->pageno);
- g_snprintf(dpi_str, 10, "%d", req->dpi);
-/* printf("Processing request for page %d at %d dpi -- in %s\n",
- req->pageno, req->dpi, ppm_root); */
- if (!g_spawn_async(NULL, argv, NULL,
- G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
- NULL, NULL, &pid, NULL))
- {
- // couldn't spawn... abort this request, try next one maybe ?
-// printf("Couldn't spawn\n");
- bgpdf.pid = 0;
- bgpdf.status = STATUS_IDLE;
- bgpdf.requests = g_list_delete_link(bgpdf.requests, bgpdf.requests);
- g_free(ppm_root);
+ bgpg->pixel_height = scaled_height;
+ bgpg->pixel_width = scaled_width;
+ bgpdf_update_bg(req->pageno, bgpg); // update all pages that have this bg
+ } else { // failure
if (!bgpdf.has_failed) {
dialog = gtk_message_dialog_new(GTK_WINDOW(winMain), GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Unable to start PDF loader %s.", argv[0]);
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Unable to render one or more PDF pages."));
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
bgpdf.has_failed = TRUE;
- if (bgpdf.requests != NULL) bgpdf_spawn_child();
- return;
- }
+ }
-// printf("Spawned process %d\n", pid);
- bgpdf.pid = pid;
- bgpdf.status = STATUS_RUNNING;
- g_child_watch_add(pid, bgpdf_child_handler, NULL);
- g_free(ppm_root);
+ bgpdf.requests = g_list_delete_link(bgpdf.requests, bgpdf.requests);
+ if (bgpdf.requests != NULL) return TRUE; // remain in the idle loop
+ bgpdf.pid = 0;
+ return FALSE; // we're done
}
/* make a request */
-void add_bgpdf_request(int pageno, double zoom, gboolean printing)
+gboolean add_bgpdf_request(int pageno, double zoom)
{
struct BgPdfRequest *req, *cmp_req;
GList *list;
-
- if (bgpdf.status == STATUS_NOT_INIT || bgpdf.status == STATUS_SHUTDOWN)
- return; // don't accept requests in those modes...
+
+ if (bgpdf.status == STATUS_NOT_INIT)
+ return FALSE; // don't accept requests
req = g_new(struct BgPdfRequest, 1);
- req->is_printing = printing;
- if (printing) req->dpi = PDFTOPPM_PRINTING_DPI;
- else req->dpi = (int)floor(72*zoom+0.5);
-// printf("Enqueuing request for page %d at %d dpi\n", pageno, req->dpi);
- if (pageno >= 1) {
- // cancel any request this may supersede
- for (list = bgpdf.requests; list != NULL; ) {
- cmp_req = (struct BgPdfRequest *)list->data;
- list = list->next;
- if (!cmp_req->initial_request && cmp_req->pageno == pageno &&
- cmp_req->is_printing == printing)
- cancel_bgpdf_request(cmp_req);
- }
- req->pageno = pageno;
- req->initial_request = FALSE;
- } else {
- req->pageno = 1;
- req->initial_request = TRUE;
+ req->pageno = pageno;
+ req->dpi = 72*zoom;
+// printf("DEBUG: Enqueuing request for page %d at %f dpi\n", pageno, req->dpi);
+
+ // cancel any request this may supersede
+ for (list = bgpdf.requests; list != NULL; ) {
+ cmp_req = (struct BgPdfRequest *)list->data;
+ list = list->next;
+ if (cmp_req->pageno == pageno) cancel_bgpdf_request(cmp_req);
}
+
+ // make the request
bgpdf.requests = g_list_append(bgpdf.requests, req);
- if (!bgpdf.pid) bgpdf_spawn_child();
+ if (!bgpdf.pid) bgpdf.pid = g_idle_add(bgpdf_scheduler_callback, NULL);
+ return TRUE;
}
/* shutdown the PDF reader */
@@ -1100,103 +1233,122 @@ void shutdown_bgpdf(void)
GList *list;
struct BgPdfPage *pdfpg;
struct BgPdfRequest *req;
+
+ if (bgpdf.status == STATUS_NOT_INIT) return;
- if (bgpdf.status == STATUS_NOT_INIT || bgpdf.status == STATUS_SHUTDOWN) return;
+ // cancel all requests and free data structures
refstring_unref(bgpdf.filename);
for (list = bgpdf.pages; list != NULL; list = list->next) {
pdfpg = (struct BgPdfPage *)list->data;
if (pdfpg->pixbuf!=NULL) gdk_pixbuf_unref(pdfpg->pixbuf);
+ g_free(pdfpg);
}
g_list_free(bgpdf.pages);
- bgpdf.status = STATUS_SHUTDOWN;
- for (list = g_list_last(bgpdf.requests); list != NULL; ) {
+ for (list = bgpdf.requests; list != NULL; list = list->next) {
req = (struct BgPdfRequest *)list->data;
- list = list->prev;
- cancel_bgpdf_request(req);
+ g_free(req);
+ }
+ g_list_free(bgpdf.requests);
+
+ if (bgpdf.file_contents!=NULL) {
+ g_free(bgpdf.file_contents);
+ bgpdf.file_contents = NULL;
}
- if (!bgpdf.pid) end_bgpdf_shutdown();
- /* The above will ultimately remove all requests and kill the child if needed.
- The child will set status to STATUS_NOT_INIT, clear the requests list,
- empty tmpdir, ... except if there's no child! */
- /* note: it could look like there's a race condition here - if a child
- terminates and a new request is enqueued while we are destroying the
- queue - but actually the child handler callback is NOT a signal
- callback, so execution of this function is atomic */
+ if (bgpdf.document!=NULL) {
+ g_object_unref(bgpdf.document);
+ bgpdf.document = NULL;
+ }
+
+ bgpdf.status = STATUS_NOT_INIT;
}
+
+// initialize PDF background rendering
+
gboolean init_bgpdf(char *pdfname, gboolean create_pages, int file_domain)
{
- FILE *f;
- gchar *filebuf;
- gsize filelen;
+ int i, n_pages;
+ struct Background *bg;
+ struct Page *pg;
+ PopplerPage *pdfpage;
+ gdouble width, height;
+ gchar *uri;
if (bgpdf.status != STATUS_NOT_INIT) return FALSE;
- bgpdf.tmpfile_copy = NULL;
- bgpdf.tmpdir = mkdtemp(g_strdup(TMPDIR_TEMPLATE));
- if (!bgpdf.tmpdir) return FALSE;
- // make a local copy and check if it's a PDF
- if (!g_file_get_contents(pdfname, &filebuf, &filelen, NULL))
- { end_bgpdf_shutdown(); return FALSE; }
- if (filelen < 4 || strncmp(filebuf, "%PDF", 4))
- { g_free(filebuf); end_bgpdf_shutdown(); return FALSE; }
- bgpdf.tmpfile_copy = g_strdup_printf("%s/bg.pdf", bgpdf.tmpdir);
- f = fopen(bgpdf.tmpfile_copy, "w");
- if (f == NULL || fwrite(filebuf, 1, filelen, f) != filelen)
- { g_free(filebuf); end_bgpdf_shutdown(); return FALSE; }
- fclose(f);
- g_free(filebuf);
- bgpdf.status = STATUS_IDLE;
- bgpdf.pid = 0;
+
+ // make a copy of the file in memory and check it's a PDF
+ if (!g_file_get_contents(pdfname, &(bgpdf.file_contents), &(bgpdf.file_length), NULL))
+ return FALSE;
+ if (bgpdf.file_length < 4 || strncmp(bgpdf.file_contents, "%PDF", 4))
+ { g_free(bgpdf.file_contents); bgpdf.file_contents = NULL; return FALSE; }
+
+ // init bgpdf data structures and open poppler document
+ bgpdf.status = STATUS_READY;
bgpdf.filename = new_refstring((file_domain == DOMAIN_ATTACH) ? "bg.pdf" : pdfname);
bgpdf.file_domain = file_domain;
bgpdf.npages = 0;
bgpdf.pages = NULL;
bgpdf.requests = NULL;
- bgpdf.create_pages = create_pages;
+ bgpdf.pid = 0;
bgpdf.has_failed = FALSE;
- add_bgpdf_request(-1, ui.startup_zoom, FALSE); // request all pages
- return TRUE;
-}
-
-// create page n, resize it, set its bg
-void bgpdf_create_page_with_bg(int pageno, struct BgPdfPage *bgpg)
-{
- struct Page *pg;
- struct Background *bg;
- if (journal.npages < pageno) {
- bg = g_new(struct Background, 1);
- bg->canvas_item = NULL;
- } else {
- pg = (struct Page *)g_list_nth_data(journal.pages, pageno-1);
- bg = pg->bg;
- if (bg->type != BG_SOLID) return;
- // don't mess with a page the user has modified significantly...
+/* poppler_document_new_from_data() starts at 0.6.1, but we want to
+ be compatible with poppler 0.5.4 = latest in CentOS as of sept 2009 */
+ uri = g_filename_to_uri(pdfname, NULL, NULL);
+ if (!uri) uri = g_strdup_printf("file://%s", pdfname);
+ bgpdf.document = poppler_document_new_from_file(uri, NULL, NULL);
+ g_free(uri);
+/* with poppler 0.6.1 or later, can replace the above 4 lines by:
+ bgpdf.document = poppler_document_new_from_data(bgpdf.file_contents,
+ bgpdf.file_length, NULL, NULL);
+*/
+ if (bgpdf.document == NULL) { shutdown_bgpdf(); return FALSE; }
+
+ if (pdfname[0]=='/' && ui.filename == NULL) {
+ if (ui.default_path!=NULL) g_free(ui.default_path);
+ ui.default_path = g_path_get_dirname(pdfname);
}
+
+ if (!create_pages) return TRUE; // we're done
- bg->type = BG_PDF;
- bg->pixbuf = gdk_pixbuf_ref(bgpg->pixbuf);
- bg->filename = refstring_ref(bgpdf.filename);
- bg->file_domain = bgpdf.file_domain;
- bg->file_page_seq = pageno;
- bg->pixbuf_scale = ui.startup_zoom;
- bg->pixbuf_dpi = bgpg->dpi;
-
- if (journal.npages < pageno) {
- pg = new_page_with_bg(bg,
- gdk_pixbuf_get_width(bg->pixbuf)*72.0/bg->pixbuf_dpi,
- gdk_pixbuf_get_height(bg->pixbuf)*72.0/bg->pixbuf_dpi);
- journal.pages = g_list_append(journal.pages, pg);
- journal.npages++;
- } else {
- pg->width = gdk_pixbuf_get_width(bgpg->pixbuf)*72.0/bg->pixbuf_dpi;
- pg->height = gdk_pixbuf_get_height(bgpg->pixbuf)*72.0/bg->pixbuf_dpi;
- make_page_clipbox(pg);
- update_canvas_bg(pg);
+ // create pages with correct sizes if requested
+ n_pages = poppler_document_get_n_pages(bgpdf.document);
+ for (i=1; i<=n_pages; i++) {
+ pdfpage = poppler_document_get_page(bgpdf.document, i-1);
+ if (!pdfpage) continue;
+ if (journal.npages < i) {
+ bg = g_new(struct Background, 1);
+ bg->canvas_item = NULL;
+ pg = NULL;
+ } else {
+ pg = (struct Page *)g_list_nth_data(journal.pages, i-1);
+ bg = pg->bg;
+ }
+ bg->type = BG_PDF;
+ bg->filename = refstring_ref(bgpdf.filename);
+ bg->file_domain = bgpdf.file_domain;
+ bg->file_page_seq = i;
+ bg->pixbuf = NULL;
+ bg->pixbuf_scale = 0;
+ poppler_page_get_size(pdfpage, &width, &height);
+ g_object_unref(pdfpage);
+ if (pg == NULL) {
+ pg = new_page_with_bg(bg, width, height);
+ journal.pages = g_list_append(journal.pages, pg);
+ journal.npages++;
+ } else {
+ pg->width = width;
+ pg->height = height;
+ make_page_clipbox(pg);
+ update_canvas_bg(pg);
+ }
}
update_page_stuff();
+ rescale_bg_pixmaps(); // this actually requests the pages !!
+ return TRUE;
}
+
// look for all journal pages with given pdf bg, and update their bg pixmaps
void bgpdf_update_bg(int pageno, struct BgPdfPage *bgpg)
{
@@ -1208,7 +1360,8 @@ void bgpdf_update_bg(int pageno, struct BgPdfPage *bgpg)
if (pg->bg->type == BG_PDF && pg->bg->file_page_seq == pageno) {
if (pg->bg->pixbuf!=NULL) gdk_pixbuf_unref(pg->bg->pixbuf);
pg->bg->pixbuf = gdk_pixbuf_ref(bgpg->pixbuf);
- pg->bg->pixbuf_dpi = bgpg->dpi;
+ pg->bg->pixel_width = bgpg->pixel_width;
+ pg->bg->pixel_height = bgpg->pixel_height;
update_canvas_bg(pg);
}
}
@@ -1257,7 +1410,8 @@ void update_mru_menu(void)
for (i=0; icolor_no]));
+ _(" the default paper color"),
+ (ui.default_page.bg->color_no>=0)?
+ g_strdup(bgcolor_names[ui.default_page.bg->color_no]):
+ g_strdup_printf("#%08x", ui.default_page.bg->color_rgba));
update_keyval("paper", "style",
- " the default paper style (plain, lined, ruled, or graph)",
+ _(" the default paper style (plain, lined, ruled, or graph)"),
g_strdup(bgstyle_names[ui.default_page.bg->ruling]));
update_keyval("paper", "apply_all",
- " apply paper style changes to all pages (true/false)",
+ _(" apply paper style changes to all pages (true/false)"),
g_strdup(ui.bg_apply_all_pages?"true":"false"));
update_keyval("paper", "default_unit",
- " preferred unit (cm, in, px, pt)",
+ _(" preferred unit (cm, in, px, pt)"),
g_strdup(unit_names[ui.default_unit]));
update_keyval("paper", "print_ruling",
- " include paper ruling when printing or exporting to PDF (true/false)",
+ _(" include paper ruling when printing or exporting to PDF (true/false)"),
g_strdup(ui.print_ruling?"true":"false"));
- update_keyval("paper", "antialias_bg",
- " antialiased bitmap backgrounds (true/false)",
- g_strdup(ui.antialias_bg?"true":"false"));
update_keyval("paper", "progressive_bg",
- " progressive scaling of bitmap backgrounds (true/false)",
+ _(" just-in-time update of page backgrounds (true/false)"),
g_strdup(ui.progressive_bg?"true":"false"));
update_keyval("paper", "gs_bitmap_dpi",
- " bitmap resolution of PS/PDF backgrounds rendered using ghostscript (dpi)",
+ _(" bitmap resolution of PS/PDF backgrounds rendered using ghostscript (dpi)"),
g_strdup_printf("%d", GS_BITMAP_DPI));
update_keyval("paper", "pdftoppm_printing_dpi",
- " bitmap resolution of PDF backgrounds when printing with libgnomeprint (dpi)",
+ _(" bitmap resolution of PDF backgrounds when printing with libgnomeprint (dpi)"),
g_strdup_printf("%d", PDFTOPPM_PRINTING_DPI));
update_keyval("tools", "startup_tool",
- " selected tool at startup (pen, eraser, highlighter, selectrect, vertspace, hand)",
+ _(" selected tool at startup (pen, eraser, highlighter, selectregion, selectrect, vertspace, hand, image)"),
g_strdup(tool_names[ui.startuptool]));
- update_keyval("tools", "startup_ruler",
- " ruler mode at startup (true/false) (for pen or highlighter only)",
- g_strdup(ui.startupruler?"true":"false"));
update_keyval("tools", "pen_color",
- " default pen color",
- g_strdup(color_names[ui.default_brushes[TOOL_PEN].color_no]));
+ _(" default pen color"),
+ (ui.default_brushes[TOOL_PEN].color_no>=0)?
+ g_strdup(color_names[ui.default_brushes[TOOL_PEN].color_no]):
+ g_strdup_printf("#%08x", ui.default_brushes[TOOL_PEN].color_rgba));
update_keyval("tools", "pen_thickness",
- " default pen thickness (fine = 1, medium = 2, thick = 3)",
+ _(" default pen thickness (fine = 1, medium = 2, thick = 3)"),
g_strdup_printf("%d", ui.default_brushes[TOOL_PEN].thickness_no));
+ update_keyval("tools", "pen_ruler",
+ _(" default pen is in ruler mode (true/false)"),
+ g_strdup(ui.default_brushes[TOOL_PEN].ruler?"true":"false"));
+ update_keyval("tools", "pen_recognizer",
+ _(" default pen is in shape recognizer mode (true/false)"),
+ g_strdup(ui.default_brushes[TOOL_PEN].recognizer?"true":"false"));
update_keyval("tools", "eraser_thickness",
- " default eraser thickness (fine = 1, medium = 2, thick = 3)",
+ _(" default eraser thickness (fine = 1, medium = 2, thick = 3)"),
g_strdup_printf("%d", ui.default_brushes[TOOL_ERASER].thickness_no));
update_keyval("tools", "eraser_mode",
- " default eraser mode (standard = 0, whiteout = 1, strokes = 2)",
+ _(" default eraser mode (standard = 0, whiteout = 1, strokes = 2)"),
g_strdup_printf("%d", ui.default_brushes[TOOL_ERASER].tool_options));
update_keyval("tools", "highlighter_color",
- " default highlighter color",
- g_strdup(color_names[ui.default_brushes[TOOL_HIGHLIGHTER].color_no]));
+ _(" default highlighter color"),
+ (ui.default_brushes[TOOL_HIGHLIGHTER].color_no>=0)?
+ g_strdup(color_names[ui.default_brushes[TOOL_HIGHLIGHTER].color_no]):
+ g_strdup_printf("#%08x", ui.default_brushes[TOOL_HIGHLIGHTER].color_rgba));
update_keyval("tools", "highlighter_thickness",
- " default highlighter thickness (fine = 1, medium = 2, thick = 3)",
+ _(" default highlighter thickness (fine = 1, medium = 2, thick = 3)"),
g_strdup_printf("%d", ui.default_brushes[TOOL_HIGHLIGHTER].thickness_no));
+ update_keyval("tools", "highlighter_ruler",
+ _(" default highlighter is in ruler mode (true/false)"),
+ g_strdup(ui.default_brushes[TOOL_HIGHLIGHTER].ruler?"true":"false"));
+ update_keyval("tools", "highlighter_recognizer",
+ _(" default highlighter is in shape recognizer mode (true/false)"),
+ g_strdup(ui.default_brushes[TOOL_HIGHLIGHTER].recognizer?"true":"false"));
update_keyval("tools", "btn2_tool",
- " button 2 tool (pen, eraser, highlighter, text, selectrect, vertspace, hand)",
+ _(" button 2 tool (pen, eraser, highlighter, text, selectregion, selectrect, vertspace, hand, image)"),
g_strdup(tool_names[ui.toolno[1]]));
update_keyval("tools", "btn2_linked",
- " button 2 brush linked to primary brush (true/false) (overrides all other settings)",
+ _(" button 2 brush linked to primary brush (true/false) (overrides all other settings)"),
g_strdup((ui.linked_brush[1]==BRUSH_LINKED)?"true":"false"));
- update_keyval("tools", "btn2_ruler",
- " button 2 ruler mode (true/false) (for pen or highlighter only)",
- g_strdup(ui.ruler[1]?"true":"false"));
update_keyval("tools", "btn2_color",
- " button 2 brush color (for pen or highlighter only)",
- g_strdup((ui.toolno[1]=0)?
+ g_strdup(color_names[ui.brushes[1][ui.toolno[1]].color_no]):
+ g_strdup_printf("#%08x", ui.brushes[1][ui.toolno[1]].color_rgba)):
+ g_strdup("white"));
update_keyval("tools", "btn2_thickness",
- " button 2 brush thickness (pen, eraser, or highlighter only)",
+ _(" button 2 brush thickness (pen, eraser, or highlighter only)"),
g_strdup_printf("%d", (ui.toolno[1]=0)?
+ g_strdup(color_names[ui.brushes[2][ui.toolno[2]].color_no]):
+ g_strdup_printf("#%08x", ui.brushes[2][ui.toolno[2]].color_rgba)):
+ g_strdup("white"));
update_keyval("tools", "btn3_thickness",
- " button 3 brush thickness (pen, eraser, or highlighter only)",
+ _(" button 3 brush thickness (pen, eraser, or highlighter only)"),
g_strdup_printf("%d", (ui.toolno[2]color_no), bgcolor_names, COLOR_MAX);
- ui.default_page.bg->color_rgba = predef_bgcolors_rgba[ui.default_page.bg->color_no];
+ parse_keyval_enum_color("paper", "color",
+ &(ui.default_page.bg->color_no), &(ui.default_page.bg->color_rgba),
+ bgcolor_names, predef_bgcolors_rgba, COLOR_MAX);
parse_keyval_enum("paper", "style", &(ui.default_page.bg->ruling), bgstyle_names, 4);
parse_keyval_boolean("paper", "apply_all", &ui.bg_apply_all_pages);
parse_keyval_enum("paper", "default_unit", &ui.default_unit, unit_names, 4);
- parse_keyval_boolean("paper", "antialias_bg", &ui.antialias_bg);
parse_keyval_boolean("paper", "progressive_bg", &ui.progressive_bg);
parse_keyval_boolean("paper", "print_ruling", &ui.print_ruling);
parse_keyval_int("paper", "gs_bitmap_dpi", &GS_BITMAP_DPI, 1, 1200);
@@ -1793,16 +2055,21 @@ void load_config_from_file(void)
parse_keyval_enum("tools", "startup_tool", &ui.startuptool, tool_names, NUM_TOOLS);
ui.toolno[0] = ui.startuptool;
- if (ui.startuptool == TOOL_PEN || ui.startuptool == TOOL_HIGHLIGHTER) {
- parse_keyval_boolean("tools", "startup_ruler", &ui.startupruler);
- ui.ruler[0] = ui.startupruler;
- }
- parse_keyval_enum("tools", "pen_color", &(ui.brushes[0][TOOL_PEN].color_no), color_names, COLOR_MAX);
+ parse_keyval_enum_color("tools", "pen_color",
+ &(ui.brushes[0][TOOL_PEN].color_no), &(ui.brushes[0][TOOL_PEN].color_rgba),
+ color_names, predef_colors_rgba, COLOR_MAX);
parse_keyval_int("tools", "pen_thickness", &(ui.brushes[0][TOOL_PEN].thickness_no), 0, 4);
+ parse_keyval_boolean("tools", "pen_ruler", &(ui.brushes[0][TOOL_PEN].ruler));
+ parse_keyval_boolean("tools", "pen_recognizer", &(ui.brushes[0][TOOL_PEN].recognizer));
parse_keyval_int("tools", "eraser_thickness", &(ui.brushes[0][TOOL_ERASER].thickness_no), 1, 3);
parse_keyval_int("tools", "eraser_mode", &(ui.brushes[0][TOOL_ERASER].tool_options), 0, 2);
- parse_keyval_enum("tools", "highlighter_color", &(ui.brushes[0][TOOL_HIGHLIGHTER].color_no), color_names, COLOR_MAX);
+ parse_keyval_enum_color("tools", "highlighter_color",
+ &(ui.brushes[0][TOOL_HIGHLIGHTER].color_no), &(ui.brushes[0][TOOL_HIGHLIGHTER].color_rgba),
+ color_names, predef_colors_rgba, COLOR_MAX);
parse_keyval_int("tools", "highlighter_thickness", &(ui.brushes[0][TOOL_HIGHLIGHTER].thickness_no), 0, 4);
+ parse_keyval_boolean("tools", "highlighter_ruler", &(ui.brushes[0][TOOL_HIGHLIGHTER].ruler));
+ parse_keyval_boolean("tools", "highlighter_recognizer", &(ui.brushes[0][TOOL_HIGHLIGHTER].recognizer));
+ ui.brushes[0][TOOL_PEN].variable_width = ui.pressure_sensitivity;
for (i=0; i< NUM_STROKE_TOOLS; i++)
for (j=1; j<=NUM_BUTTONS; j++)
g_memmove(&(ui.brushes[j][i]), &(ui.brushes[0][i]), sizeof(struct Brush));
@@ -1813,13 +2080,13 @@ void load_config_from_file(void)
parse_keyval_enum("tools", "btn3_tool", &(ui.toolno[2]), tool_names, NUM_TOOLS);
if (parse_keyval_boolean("tools", "btn3_linked", &b))
ui.linked_brush[2] = b?BRUSH_LINKED:BRUSH_STATIC;
- for (i=1; i<=NUM_BUTTONS; i++)
- if (ui.toolno[i]==TOOL_PEN || ui.toolno[i]==TOOL_HIGHLIGHTER)
- ui.ruler[i] = ui.ruler[0];
if (ui.linked_brush[1]!=BRUSH_LINKED) {
if (ui.toolno[1]==TOOL_PEN || ui.toolno[1]==TOOL_HIGHLIGHTER) {
- parse_keyval_boolean("tools", "btn2_ruler", &(ui.ruler[1]));
- parse_keyval_enum("tools", "btn2_color", &(ui.brushes[1][ui.toolno[1]].color_no), color_names, COLOR_MAX);
+ parse_keyval_boolean("tools", "btn2_ruler", &(ui.brushes[1][ui.toolno[1]].ruler));
+ parse_keyval_boolean("tools", "btn2_recognizer", &(ui.brushes[1][ui.toolno[1]].recognizer));
+ parse_keyval_enum_color("tools", "btn2_color",
+ &(ui.brushes[1][ui.toolno[1]].color_no), &(ui.brushes[1][ui.toolno[1]].color_rgba),
+ color_names, predef_colors_rgba, COLOR_MAX);
}
if (ui.toolno[1]