sent-pdf-2649e8d.diff - sites - public wiki contents of suckless.org | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
sent-pdf-2649e8d.diff (3314B) | |
--- | |
1 From 78a5f5d263c5209d685abbe657bbc5bd3f756994 Mon Sep 17 00:00:00 2001 | |
2 From: tuckerrrrrrrrrr <[email protected]> | |
3 Date: Sat, 14 Nov 2020 12:54:53 +0100 | |
4 Subject: [PATCH] Conversion to PDF | |
5 | |
6 Add the ability to convert presentations to PDF. Adds an additional | |
7 dependency: cairo. | |
8 --- | |
9 config.def.h | 1 + | |
10 config.mk | 7 +++++-- | |
11 sent.c | 42 ++++++++++++++++++++++++++++++++++++++---- | |
12 3 files changed, 44 insertions(+), 6 deletions(-) | |
13 | |
14 diff --git a/config.def.h b/config.def.h | |
15 index 60eb376..e68a099 100644 | |
16 --- a/config.def.h | |
17 +++ b/config.def.h | |
18 @@ -47,6 +47,7 @@ static Shortcut shortcuts[] = { | |
19 { XK_n, advance, {.i = +1} }, | |
20 { XK_p, advance, {.i = -1} }, | |
21 { XK_r, reload, {0} }, | |
22 + { XK_g, pdf, {0} }, | |
23 }; | |
24 | |
25 static Filter filters[] = { | |
26 diff --git a/config.mk b/config.mk | |
27 index d61c554..9174687 100644 | |
28 --- a/config.mk | |
29 +++ b/config.mk | |
30 @@ -7,14 +7,17 @@ VERSION = 1 | |
31 PREFIX = /usr/local | |
32 MANPREFIX = ${PREFIX}/share/man | |
33 | |
34 +PKG_CONFIG = pkg-config | |
35 + | |
36 X11INC = /usr/X11R6/include | |
37 X11LIB = /usr/X11R6/lib | |
38 | |
39 # includes and libs | |
40 INCS = -I. -I/usr/include -I/usr/include/freetype2 -I${X11INC} | |
41 -LIBS = -L/usr/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11 | |
42 +LIBS = -L/usr/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11 -lcairo | |
43 # OpenBSD (uncomment) | |
44 -#INCS = -I. -I${X11INC} -I${X11INC}/freetype2 | |
45 +INCS = -I. -I${X11INC} -I${X11INC}/freetype2 `${PKG_CONFIG} --cflags ca… | |
46 +LIBS += -L/usr/local/lib | |
47 # FreeBSD (uncomment) | |
48 #INCS = -I. -I/usr/local/include -I/usr/local/include/freetype2 -I${X11… | |
49 #LIBS = -L/usr/local/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11 | |
50 diff --git a/sent.c b/sent.c | |
51 index 9534fca..dc5cf89 100644 | |
52 --- a/sent.c | |
53 +++ b/sent.c | |
54 @@ -19,6 +19,10 @@ | |
55 #include <X11/Xutil.h> | |
56 #include <X11/Xft/Xft.h> | |
57 | |
58 +#include <cairo/cairo.h> | |
59 +#include <cairo/cairo-xlib.h> | |
60 +#include <cairo/cairo-pdf.h> | |
61 + | |
62 #include "arg.h" | |
63 #include "util.h" | |
64 #include "drw.h" | |
65 @@ -97,6 +101,7 @@ static void cleanup(int slidesonly); | |
66 static void reload(const Arg *arg); | |
67 static void load(FILE *fp); | |
68 static void advance(const Arg *arg); | |
69 +static void pdf(); | |
70 static void quit(const Arg *arg); | |
71 static void resize(int width, int height); | |
72 static void run(); | |
73 @@ -428,10 +433,6 @@ load(FILE *fp) | |
74 maxlines = 0; | |
75 memset((s = &slides[slidecount]), 0, sizeof(Slide)); | |
76 do { | |
77 - /* if there's a leading null, we can't do blen-… | |
78 - if (buf[0] == '\0') | |
79 - continue; | |
80 - | |
81 if (buf[0] == '#') | |
82 continue; | |
83 | |
84 @@ -479,6 +480,39 @@ advance(const Arg *arg) | |
85 } | |
86 } | |
87 | |
88 +void | |
89 +pdf() | |
90 +{ | |
91 + const Arg next = { .i = 1 }; | |
92 + Arg first; | |
93 + cairo_surface_t *cs; | |
94 + | |
95 + char filename[strlen(fname) + 5]; | |
96 + sprintf(filename, "%s.pdf", fname); | |
97 + cairo_surface_t *pdf = cairo_pdf_surface_create(filename, xw.w,… | |
98 + | |
99 + cairo_t *cr = cairo_create(pdf); | |
100 + | |
101 + first.i = -idx; | |
102 + advance(&first); | |
103 + | |
104 + cs = cairo_xlib_surface_create(xw.dpy, xw.win, xw.vis, xw.w, xw… | |
105 + cairo_set_source_surface(cr, cs, 0.0, 0.0); | |
106 + for (int i = 0; i < slidecount; ++i) { | |
107 + cairo_paint(cr); | |
108 + cairo_show_page(cr); | |
109 + cairo_surface_flush(cs); | |
110 + advance(&next); | |
111 + cairo_surface_mark_dirty(cs); | |
112 + } | |
113 + cairo_surface_destroy(cs); | |
114 + | |
115 + cairo_destroy(cr); | |
116 + cairo_surface_destroy(pdf); | |
117 + first.i = -(slidecount-1); | |
118 + advance(&first); | |
119 +} | |
120 + | |
121 void | |
122 quit(const Arg *arg) | |
123 { | |
124 -- | |
125 2.29.2 | |
126 |