-
Notifications
You must be signed in to change notification settings - Fork 5
/
page_view.cc
34 lines (28 loc) · 961 Bytes
/
page_view.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
// Copyright
#include <stdio.h>
#include "page_view.h"
namespace pdfsketch {
PageView::PageView(const char* pdf_doc, size_t pdf_doc_length)
: doc_(pdf_doc, pdf_doc_length) {
top_fixed_to_top_ = true;
bot_fixed_to_top_ = false;
left_fixed_to_left_ = true;
right_fixed_to_left_ = false;
SetSize(Size(doc_.GetPageWidth(1), doc_.GetPageHeight(1)));
}
void PageView::DrawRect(cairo_t* cr, const Rect& rect) {
printf("PageView::Draw called %f %f\n", size_.width_, size_.height_);
if (doc_.GetPageWidth(1) < 1 || doc_.GetPageHeight(1) < 1) {
printf("page too small. Avoiding divide by 0\n");
return;
}
double scale_x = size_.width_ / doc_.GetPageWidth(1);
double scale_y = size_.height_ / doc_.GetPageHeight(1);
cairo_save(cr);
cairo_scale(cr, scale_x, scale_y);
doc_.RenderPage(1, false, cr);
cairo_restore(cr);
cairo_move_to(cr, 0.0, 0.0);
cairo_line_to(cr, size_.width_, size_.height_);
}
} // namespace pdfsketch