Skip to content

Commit 97ee37a

Browse files
committed
Move to stable poppler-cpp api
1 parent 2bcee10 commit 97ee37a

File tree

7 files changed

+683
-773
lines changed

7 files changed

+683
-773
lines changed

Makefile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
SOURCES = main.cpp rectangle.cpp coordconv.cpp
2-
OBJECTS = $(SOURCES:.cpp=.o)
3-
41
CXXFLAGS ?= -Wall -O0 -g
2+
include ::= $(shell pkg-config --cflags poppler-cpp)
3+
LDLIBS ::= -lX11 $(shell pkg-config --libs poppler-cpp)
4+
5+
spdf: main.o coordconv.o
6+
$(CXX) $(LDLIBS) $^ -o $@
57

6-
spdf: $(OBJECTS)
7-
$(CXX) -lpoppler -lX11 $(OBJECTS) -o $@
8+
main.o: main.cpp config.hpp
9+
$(CXX) -std=c++20 $(CXXFLAGS) $(include) -c $< -o $@
810

9-
%.o: %.cpp config.hpp
10-
$(CXX) -std=c++17 $(CXXFLAGS) -I/usr/include/poppler -c $< -o $@
11+
coordconv.o: coordconv.cpp
12+
$(CXX) -std=c++20 $(CXXFLAGS) $(include) -c $< -o $@
1113

12-
config.h:
14+
config.hpp:
1315
cp config.def.hpp config.hpp
1416

1517
clean:
16-
rm -f spdf $(OBJECTS)
18+
rm -f spdf *.o

config.def.hpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1+
2+
#include <climits>
3+
4+
#include <X11/Xutil.h>
5+
#include <X11/keysym.h>
6+
7+
#define AnyMask UINT_MAX
8+
#define EmptyMask 0
9+
10+
enum Action {
11+
QUIT,
12+
NEXT,
13+
PREV,
14+
FIRST,
15+
LAST,
16+
FIT_PAGE,
17+
FIT_WIDTH,
18+
DOWN,
19+
UP,
20+
BACK,
21+
RELOAD,
22+
GOTO_PAGE,
23+
SEARCH,
24+
PAGE,
25+
MAGNIFY,
26+
ROTATE_CW,
27+
ROTATE_CCW
28+
};
29+
30+
struct Shortcut {
31+
unsigned mask;
32+
KeySym ksym;
33+
Action action;
34+
};
35+
136
/*
237
* Background color, X11 color name (see:
338
* https://en.wikipedia.org/wiki/X11_color_names).
@@ -20,11 +55,8 @@ static Shortcut shortcuts[] = {{AnyMask, XK_q, QUIT},
2055
{EmptyMask, XK_w, FIT_WIDTH},
2156
{EmptyMask, XK_Down, DOWN},
2257
{EmptyMask, XK_Up, UP},
23-
{EmptyMask, XK_Page_Down, PG_DOWN},
24-
{EmptyMask, XK_Page_Up, PG_UP},
2558
{EmptyMask, XK_b, BACK},
2659
{AnyMask, XK_r, RELOAD},
27-
{ControlMask, XK_c, COPY},
2860
{AnyMask, XK_g, GOTO_PAGE},
2961
{AnyMask, XK_s, SEARCH},
3062
{EmptyMask, XK_slash, SEARCH},

coordconv.cpp

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,40 @@
11
#include <algorithm>
22

3-
#include "coordconv.h"
3+
#include "coordconv.hpp"
44

5-
CoordConv::CoordConv(const Page *p, const Rectangle &r, bool i, int rotation)
5+
CoordConv::CoordConv(const poppler::page *p, const srect &r, bool i,
6+
int rotation)
67
: rect(r), inverty(i) {
7-
auto pbox = p->getCropBox();
8+
auto pbox = p->page_rect();
89

9-
auto width = pbox->x2 - pbox->x1;
10-
auto height = pbox->y2 - pbox->y1;
11-
12-
if (abs(p->getRotate() - rotation) % 180 != 0)
13-
std::swap(width, height);
14-
15-
xscale = (width) / double(rect.width);
16-
yscale = (height) / double(rect.height);
10+
xscale = (pbox.width()) / double(rect.width());
11+
yscale = (pbox.height()) / double(rect.height());
1712
}
1813

19-
double CoordConv::to_pdf_x(int x) const { return (x - rect.x) * xscale; }
14+
double CoordConv::to_pdf_x(int x) const { return (x - rect.x()) * xscale; }
2015

2116
double CoordConv::to_pdf_y(int y) const {
2217
if (inverty)
23-
return (rect.height - (y - rect.y)) * yscale;
24-
return (y - rect.y) * yscale;
18+
return (rect.height() - (y - rect.y())) * yscale;
19+
return (y - rect.y()) * yscale;
2520
}
2621

27-
Rectangle CoordConv::to_pdf(const Rectangle &r) const {
28-
return {(int)to_pdf_x(r.x), (int)to_pdf_y(r.y),
29-
(int)(to_pdf_x(r.x + r.width) - to_pdf_x(r.x)),
30-
(int)(to_pdf_y(r.y + r.height) - to_pdf_y(r.y))};
22+
srect CoordConv::to_pdf(const srect &r) const {
23+
return {(int)to_pdf_x(r.x()), (int)to_pdf_y(r.y()),
24+
(int)(to_pdf_x(r.x() + r.width()) - to_pdf_x(r.x())),
25+
(int)(to_pdf_y(r.y() + r.height()) - to_pdf_y(r.y()))};
3126
}
3227

33-
double CoordConv::to_screen_x(int x) const { return x / xscale + rect.x; }
28+
double CoordConv::to_screen_x(int x) const { return x / xscale + rect.x(); }
3429

3530
double CoordConv::to_screen_y(int y) const {
3631
if (inverty)
37-
return rect.y + rect.height - y / yscale;
38-
return y / yscale + rect.y;
32+
return rect.y() + rect.height() - y / yscale;
33+
return y / yscale + rect.y();
3934
}
4035

41-
Rectangle CoordConv::to_screen(const Rectangle &r) const {
42-
return {(int)to_screen_x(r.x), (int)to_screen_y(r.y),
43-
(int)(to_screen_x(r.x + r.width) - to_screen_x(r.x)),
44-
(int)(to_screen_y(r.y + r.height) - to_screen_y(r.y))};
36+
srect CoordConv::to_screen(const srectf &r) const {
37+
return {(int)to_screen_x(r.x()), (int)to_screen_y(r.y()),
38+
(int)(to_screen_x(r.x() + r.width()) - to_screen_x(r.x())),
39+
(int)(to_screen_y(r.y() + r.height()) - to_screen_y(r.y()))};
4540
}

coordconv.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#ifndef SCALER_H
22
#define SCALER_H
33

4-
#include "rectangle.h"
5-
#include <poppler/Page.h>
4+
#include "rectangle.hpp"
5+
#include <poppler-page.h>
66

77
struct CoordConv {
8-
CoordConv(const Page *p, const Rectangle &r, bool i, int rotation);
8+
CoordConv(const poppler::page *p, const srect &r, bool i, int rotation);
99
double to_pdf_x(int x) const;
1010
double to_pdf_y(int y) const;
11-
Rectangle to_pdf(const Rectangle &r) const;
11+
srect to_pdf(const srect &r) const;
1212
double to_screen_x(int x) const;
1313
double to_screen_y(int y) const;
14-
Rectangle to_screen(const Rectangle &r) const;
14+
srect to_screen(const srectf &r) const;
1515

1616
private:
1717
double xscale, yscale;
18-
Rectangle rect;
18+
srect rect;
1919
bool inverty;
2020
};
2121

0 commit comments

Comments
 (0)