dotfiles/sent/sent-pdf.diff

81 lines
2.1 KiB
Diff

diff -u sent/config.def.h sent-pdf/config.def.h
--- sent/config.def.h 2020-05-12 20:32:04.628425521 +0200
+++ sent-pdf/config.def.h 2020-05-23 16:04:44.927236722 +0200
@@ -47,6 +47,7 @@
{ XK_n, advance, {.i = +1} },
{ XK_p, advance, {.i = -1} },
{ XK_r, reload, {0} },
+ { XK_g, pdf, {0} },
};
static Filter filters[] = {
diff -u sent/config.mk sent-pdf/config.mk
--- sent/config.mk 2020-05-12 20:32:04.628425521 +0200
+++ sent-pdf/config.mk 2020-05-23 16:04:44.927236722 +0200
@@ -12,7 +12,7 @@
# includes and libs
INCS = -I. -I/usr/include -I/usr/include/freetype2 -I${X11INC}
-LIBS = -L/usr/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11
+LIBS = -L/usr/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11 -lcairo
# OpenBSD (uncomment)
#INCS = -I. -I${X11INC} -I${X11INC}/freetype2
# FreeBSD (uncomment)
diff -u sent/sent.c sent-pdf/sent.c
--- sent/sent.c 2020-05-23 16:05:29.244073472 +0200
+++ sent-pdf/sent.c 2020-05-23 16:04:44.928237147 +0200
@@ -19,6 +19,10 @@
#include <X11/Xutil.h>
#include <X11/Xft/Xft.h>
+#include <cairo/cairo.h>
+#include <cairo/cairo-xlib.h>
+#include <cairo/cairo-pdf.h>
+
#include "arg.h"
#include "util.h"
#include "drw.h"
@@ -97,6 +101,7 @@
static void reload(const Arg *arg);
static void load(FILE *fp);
static void advance(const Arg *arg);
+static void pdf();
static void quit(const Arg *arg);
static void resize(int width, int height);
static void run();
@@ -476,6 +481,34 @@
}
void
+pdf()
+{
+ const Arg next = { .i = 1 };
+ const Arg first = { .i = -(slidecount-1) };
+ cairo_surface_t *cs;
+
+ char filename[20];
+ sprintf(filename, "%s.pdf", fname);
+ cairo_surface_t *pdf = cairo_pdf_surface_create(filename, xw.w, xw.h);
+
+ cairo_t *cr = cairo_create(pdf);
+
+ idx = -1;
+ for (int i = 0; i < slidecount; ++i) {
+ cs = cairo_xlib_surface_create(xw.dpy, xw.win, xw.vis, xw.w, xw.h);
+ advance(&next);
+ cairo_set_source_surface(cr, cs, 0.0, 0.0);
+ cairo_paint(cr);
+ cairo_show_page(cr);
+ cairo_surface_destroy(cs);
+ }
+
+ cairo_destroy(cr);
+ cairo_surface_destroy(pdf);
+ advance(&first);
+}
+
+void
quit(const Arg *arg)
{
running = 0;