1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/*
* pdf viewer, for framebuffer devices
*
* (c) 1998-2016 Gerd Hoffmann <gerd@kraxel.org>
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <math.h>
#include <signal.h>
#include <ctype.h>
#include <locale.h>
#include <wchar.h>
#include <setjmp.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <linux/kd.h>
#include <linux/vt.h>
#include <linux/fb.h>
#include <poppler.h>
#include "vt.h"
#include "fbtools.h"
#include "drmtools.h"
/* ---------------------------------------------------------------------- */
gfxstate *gfx;
int debug;
PopplerDocument *doc;
PopplerPage *page;
cairo_surface_t *surface;
cairo_t *context;
/* ---------------------------------------------------------------------- */
static jmp_buf fb_fatal_cleanup;
static void catch_exit_signal(int signal)
{
siglongjmp(fb_fatal_cleanup,signal);
}
static void exit_signals_init(void)
{
struct sigaction act,old;
int termsig;
memset(&act,0,sizeof(act));
act.sa_handler = catch_exit_signal;
sigemptyset(&act.sa_mask);
sigaction(SIGINT, &act,&old);
sigaction(SIGQUIT,&act,&old);
sigaction(SIGTERM,&act,&old);
sigaction(SIGABRT,&act,&old);
sigaction(SIGTSTP,&act,&old);
sigaction(SIGBUS, &act,&old);
sigaction(SIGILL, &act,&old);
sigaction(SIGSEGV,&act,&old);
if (0 == (termsig = sigsetjmp(fb_fatal_cleanup,0)))
return;
/* cleanup */
gfx->cleanup_display();
console_switch_cleanup();
fprintf(stderr,"Oops: %s\n",strsignal(termsig));
exit(42);
}
/* ---------------------------------------------------------------------- */
static void cleanup_and_exit(int code)
{
gfx->cleanup_display();
console_switch_cleanup();
exit(code);
}
static void console_switch_redraw(void)
{
/* TODO */
}
int main(int argc, char *argv[])
{
GError *err = NULL;
bool framebuffer = false;
double w,h;
setlocale(LC_ALL,"");
if (argc < 2) {
fprintf(stderr, "usage: %s <pdf-file>\n", argv[0]);
exit(1);
}
doc = poppler_document_new_from_file(argv[1], NULL, &err);
if (!doc) {
fprintf(stderr, "loading %s failed: %s\n", argv[1], err->message);
exit(1);
}
/* gfx init */
gfx = drm_init(NULL, NULL);
if (!gfx) {
framebuffer = true;
gfx = fb_init(NULL, NULL, 0);
}
if (!gfx) {
fprintf(stderr, "graphics init failed\n");
exit(1);
}
exit_signals_init();
signal(SIGTSTP,SIG_IGN);
if (console_switch_init(console_switch_redraw) < 0) {
fprintf(stderr, "NOTICE: No vt switching available on terminal.\n");
fprintf(stderr, "NOTICE: Not started from linux console? CONFIG_VT=n?\n");
if (framebuffer) {
fprintf(stderr, "WARNING: Running on framebuffer and can't manage access.\n");
fprintf(stderr, "WARNING: Other processes (fbcon too) can write to display.\n");
fprintf(stderr, "WARNING: Also can't properly cleanup on exit.\n");
}
}
surface = cairo_image_surface_create_for_data(gfx->mem,
CAIRO_FORMAT_ARGB32,
gfx->hdisplay,
gfx->vdisplay,
gfx->stride);
context = cairo_create(surface);
cairo_set_source_rgb(context, 1, 1, 1);
cairo_paint(context);
page = poppler_document_get_page(doc, 0);
poppler_page_get_size(page, &w, &h);
fprintf(stderr, "page: %.1lf x %.1lf\n", w, h);
poppler_page_render(page, context);
cairo_show_page(context);
sleep(5);
cleanup_and_exit(0);
return 0;
}
|