ENERGY MONITOR
0.2
Loading...
Searching...
No Matches
pdfWrapper.h
Go to the documentation of this file.
1
#pragma once
2
3
#pragma comment
4
5
#include <string>
6
#include <PDFWriter.h>
7
#include <PDFPage.h>
8
#include <PageContentContext.h>
9
#include <PDFFormXObject.h>
10
#include <ResourcesDictionary.h>
11
#include <PDFUsedFont.h>
12
13
15
16
17
26
#define A4_Width 595
27
#define A4_Height 842
28
29
#define LEFT(n)(n)
30
#define TOP(n)(A4_Height - n)
31
#define standardFont "resources/OpenSans-Italic.ttf"
32
33
class
pdf_wrap
{
34
PDFWriter pdfWriter;
35
PDFPage* page;
36
PageContentContext* pageContentContext;
37
PDFUsedFont* font;
38
39
struct
{
40
int
r
= 0;
41
int
g
= 0;
42
int
b
= 0;
43
int
a
= 1;
44
}fontStyle;
45
46
unsigned
int
pos_x = 0;
47
unsigned
int
pos_y = 0;
48
49
50
public
:
51
int
left_padding
= 30;
52
int
top_padding
= 30;
53
float
font_size
= 5;
54
int
interline_gap
=
font_size
*4;
55
56
57
void
init
(std::string fileLocation){
58
pdfWriter.StartPDF(fileLocation,ePDFVersion13);
59
font = pdfWriter.GetFontForFile(
standardFont
);
60
}
61
62
void
end
(){
63
pdfWriter.EndPDF();
64
}
65
66
void
newPage
(){
67
page =
new
PDFPage();
68
page->SetMediaBox(PDFRectangle(0,0,
A4_Width
,
A4_Height
));
69
pageContentContext = pdfWriter.StartPageContentContext(page);
70
pos_x = 0;
71
pos_y = 0;
72
}
73
74
void
endPage
(){
75
pdfWriter.EndPageContentContext(pageContentContext);
76
pdfWriter.WritePageAndRelease(page);
77
}
78
79
void
textPiece_start
(){
80
pageContentContext->BT();
81
pageContentContext->Tf(font,
font_size
);
82
pageContentContext->k(fontStyle.r,fontStyle.g,fontStyle.b,fontStyle.a);
83
}
84
85
void
addText
(std::string text){
86
pageContentContext->Tj(text);
87
PDFUsedFont::TextMeasures textDimensions = font->CalculateTextDimensions(text,
font_size
);
88
pos_x += textDimensions.xMax;
89
}
90
91
void
textPiece_end
(){
92
pageContentContext->ET();
93
}
94
95
void
newLine
(){
96
pos_x =
LEFT
(
left_padding
);
97
pos_y -=
interline_gap
;
98
pageContentContext->Tm(1,0,0,1,
LEFT
(
left_padding
), pos_y);
99
}
100
101
void
setFontStyle
(
float
size,
int
r
,
int
g
,
int
b
,
int
a
){
102
pageContentContext->Tf(font,size);
103
font_size
= size;
104
pageContentContext->k(
r
,
g
,
b
,
a
);
105
fontStyle.r =
r
;
106
fontStyle.g =
g
;
107
fontStyle.b =
b
;
108
fontStyle.a =
a
;
109
pageContentContext->TL(
font_size
);
110
}
111
112
void
setCursor
(
int
x,
int
y){
113
pageContentContext->Tm(1, 0, 0, 1, x, y);
114
pos_x = x;
115
pos_y = y;
116
}
117
118
119
int
get_posX
(){
120
return
pos_x;
121
}
122
123
int
get_posY
(){
124
return
pos_y;
125
}
126
127
void
center_text
(std::string word){
128
PDFUsedFont::TextMeasures textDimensions = font->CalculateTextDimensions(word,
font_size
);
129
pageContentContext->Td(
A4_Width
/2 - textDimensions.width/2 -
left_padding
, 0);
130
addText
(word);
131
pageContentContext->Td(-(
A4_Width
/2 - textDimensions.width/2 -
left_padding
), 0);
132
}
133
};
134
pdf_wrap
Definition
pdfWrapper.h:33
pdf_wrap::init
void init(std::string fileLocation)
Definition
pdfWrapper.h:57
pdf_wrap::get_posY
int get_posY()
Definition
pdfWrapper.h:123
pdf_wrap::r
int r
Definition
pdfWrapper.h:40
pdf_wrap::newPage
void newPage()
Definition
pdfWrapper.h:66
pdf_wrap::g
int g
Definition
pdfWrapper.h:41
pdf_wrap::center_text
void center_text(std::string word)
Definition
pdfWrapper.h:127
pdf_wrap::a
int a
Definition
pdfWrapper.h:43
pdf_wrap::endPage
void endPage()
Definition
pdfWrapper.h:74
pdf_wrap::setCursor
void setCursor(int x, int y)
Definition
pdfWrapper.h:112
pdf_wrap::textPiece_end
void textPiece_end()
Definition
pdfWrapper.h:91
pdf_wrap::addText
void addText(std::string text)
Definition
pdfWrapper.h:85
pdf_wrap::b
int b
Definition
pdfWrapper.h:42
pdf_wrap::top_padding
int top_padding
Definition
pdfWrapper.h:52
pdf_wrap::end
void end()
Definition
pdfWrapper.h:62
pdf_wrap::interline_gap
int interline_gap
Definition
pdfWrapper.h:54
pdf_wrap::newLine
void newLine()
Definition
pdfWrapper.h:95
pdf_wrap::get_posX
int get_posX()
Definition
pdfWrapper.h:119
pdf_wrap::font_size
float font_size
Definition
pdfWrapper.h:53
pdf_wrap::setFontStyle
void setFontStyle(float size, int r, int g, int b, int a)
Definition
pdfWrapper.h:101
pdf_wrap::textPiece_start
void textPiece_start()
Definition
pdfWrapper.h:79
pdf_wrap::left_padding
int left_padding
Definition
pdfWrapper.h:51
standardFont
#define standardFont
Definition
pdfWrapper.h:31
A4_Height
#define A4_Height
Definition
pdfWrapper.h:27
A4_Width
#define A4_Width
Definition
pdfWrapper.h:26
LEFT
#define LEFT(n)
Definition
pdfWrapper.h:29
EPE_ENERGY_MONITOR
src
core
data_IO
pdfWrapper.h
Generated by
1.10.0