-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutline.cc
68 lines (60 loc) · 1.6 KB
/
outline.cc
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
#include "outline.h"
#include <iostream>
#include <QDebug>
using namespace std;
class Outline::Private {
public:
Outline_t outline;
document_t* document{nullptr};
~Private(){
document = nullptr;
}
};
Outline::Outline() {
d = new Private;
}
void load_section_cur(Section §ion, Poppler::OutlineItem &item) {
section.title = item.name();
auto dest = item.destination();
if (dest) section.link.page = dest->pageNumber();
for (auto i : item.children()) {
Section sub;
load_section_cur(sub, i);
section.children.push_back(sub);
}
}
void Outline::load_outlie() {
d->outline.clear();
auto items = d->document->outline();
if (items.isEmpty()) {
cout << "no outine available.";
}
for (auto i : items) {
Section cur_section;
load_section_cur(cur_section, i);
if (cur_section.link.page == -1) {
// TODO:
// maybe exit from here.
}
d->outline.push_back(cur_section);
}
}
void display_section_recur(const Section §, int depth = 0) {
return;
for (int i = 0; i < depth; i++) cout << " "; // use indent as layer indicator.
qDebug() << QString("page %3, l%1: %2")
.arg(depth)
.arg(sect.title)
.arg(sect.link.page);
for (auto sub : sect.children) {
display_section_recur(sub, depth + 1);
}
}
void Outline::display_outline() {
for (auto sec : d->outline) {
display_section_recur(sec);
}
}
void Outline::setDocument(document_t * doc) {
d->document = doc;
}