+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <libgnomecanvas/libgnomecanvas.h>
#include <zlib.h>
#include <math.h>
-#include <gdk/gdkx.h>
-#include <X11/Xlib.h>
#include <locale.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <poppler/glib/poppler.h>
+#ifndef WIN32
+ #include <gdk/gdkx.h>
+ #include <X11/Xlib.h>
+#endif
+
#include "xournal.h"
#include "xo-interface.h"
#include "xo-support.h"
GList *pagelist, *layerlist, *itemlist, *list;
GtkWidget *dialog;
- f = gzopen(filename, "w");
+ f = gzopen(filename, "wb");
if (f==NULL) return FALSE;
chk_attach_names();
success = FALSE;
if (bgpdf.status != STATUS_NOT_INIT && bgpdf.file_contents != NULL)
{
- tmpf = fopen(tmpfn, "w");
+ tmpf = fopen(tmpfn, "wb");
if (tmpf != NULL && fwrite(bgpdf.file_contents, 1, bgpdf.file_length, tmpf) == bgpdf.file_length)
success = TRUE;
fclose(tmpf);
else
gzprintf(f, "#%08x", item->brush.color_rgba);
tmpstr = g_markup_escape_text(item->text, -1);
- gzprintf(f, "\">%s</text>\n", tmpstr);
+ gzputs(f, "\">");
+ gzputs(f, tmpstr); // gzprintf() can't handle > 4095 bytes
+ gzputs(f, "</text>\n");
g_free(tmpstr);
}
}
}
// 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()
if (ptr == text) break;
text_len -= (ptr - text);
text = ptr;
- if (!finite(ui.cur_path.coords[n])) {
+ 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;
}
}
g_free(tmpfn);
- f = gzopen(filename, "r");
+ f = gzopen(filename, "rb");
if (f==NULL) return FALSE;
if (filename[0]=='/') {
if (ui.default_path != NULL) g_free(ui.default_path);
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 ||
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;
struct Background *attempt_screenshot_bg(void)
{
+#ifndef WIN32
struct Background *bg;
GdkPixbuf *pix;
XEvent x_event;
bg->filename = new_refstring(NULL);
bg->file_domain = DOMAIN_ATTACH;
return bg;
+#else
+ // not implemented under WIN32
+ return FALSE;
+#endif
}
/************** pdf annotation ***************/
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; }
poppler_page_get_size(pdfpage, &width, &height);
scaled_width = (int) (req->dpi * width/72);
scaled_height = (int) (req->dpi * height/72);
- pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
- FALSE, 8, scaled_width, scaled_height);
- poppler_page_render_to_pixbuf(
+
+ 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);
}
ui.width_maximum_multiplier = 1.25;
ui.button_switch_mapping = FALSE;
ui.autoload_pdf_xoj = FALSE;
+ ui.poppler_force_cairo = FALSE;
// the default UI vertical order
ui.vertical_order[0][0] = 1;
update_keyval("general", "autosave_prefs",
_(" auto-save preferences on exit (true/false)"),
g_strdup(ui.auto_save_prefs?"true":"false"));
+ update_keyval("general", "poppler_force_cairo",
+ _(" force PDF rendering through cairo (slower but nicer) (true/false)"),
+ g_strdup(ui.poppler_force_cairo?"true":"false"));
update_keyval("paper", "width",
_(" the default page width, in points (1/72 in)"),
if (str!=NULL) { g_free(ui.shorten_menu_items); ui.shorten_menu_items = str; }
parse_keyval_float("general", "highlighter_opacity", &ui.hiliter_opacity, 0., 1.);
parse_keyval_boolean("general", "autosave_prefs", &ui.auto_save_prefs);
+ parse_keyval_boolean("general", "poppler_force_cairo", &ui.poppler_force_cairo);
parse_keyval_float("paper", "width", &ui.default_page.width, 1., 5000.);
parse_keyval_float("paper", "height", &ui.default_page.height, 1., 5000.);