MeshLib
 
Loading...
Searching...
No Matches
MRPdf.h
Go to the documentation of this file.
1#pragma once
2
3#include "config.h"
4#ifndef MRIOEXTRAS_NO_PDF
5#include "exports.h"
6
7#include <hpdf.h>
8
9#include <filesystem>
10#include <vector>
11
12namespace MR
13{
14
19{
20 HPDF_REAL titleSize = 18.f;
21 HPDF_REAL textSize = 14.f;
31 std::string fontName = "Helvetica";
32};
33
37class Pdf
38{
39public:
41 MRIOEXTRAS_API Pdf( const std::filesystem::path& documentPath, const PdfParameters& params = PdfParameters() );
42 MRIOEXTRAS_API Pdf( Pdf&& other ) noexcept;
43 MRIOEXTRAS_API Pdf& operator=( Pdf other ) noexcept; // Sic, passing by value.
45 MRIOEXTRAS_API ~Pdf();
46
47 Pdf( const Pdf& rhs ) = delete;
48 Pdf& operator = ( const Pdf& rhs ) = delete;
49
58 MRIOEXTRAS_API void addText( const std::string& text, bool isTitle = false );
59
69 MRIOEXTRAS_API void addImageFromFile( const std::filesystem::path& imagePath, const std::string& caption = {},
70 const std::vector<std::pair<double, std::string>>& valuesMarks = {} );
71
73 MRIOEXTRAS_API void newPage();
74
76 MRIOEXTRAS_API void close();
77
78 void setCursorPosX( HPDF_REAL posX ) { cursorX_ = posX; };
79 void setCursorPosY( HPDF_REAL posY ) { cursorY_ = posY; };
80 float getCursorPosX() const { return cursorX_; };
81 float getCursorPosY() const { return cursorY_; };
82
84 operator bool() const { return state_.document != 0; };
85
86private:
87 struct State
88 {
89 HPDF_Doc document = nullptr;
90 HPDF_Page activePage = nullptr;
91 HPDF_Font activeFont = nullptr;
92 };
93 State state_;
94
95 std::filesystem::path filename_;
96
97 PdfParameters params_;
98
99 HPDF_REAL cursorX_ = 0;
100 HPDF_REAL cursorY_ = 0;
101
102 bool checkDocument() const { return state_.document && state_.activePage; };
103};
104
105}
106#endif
Definition MRPdf.h:38
Pdf(const Pdf &rhs)=delete
float getCursorPosY() const
Definition MRPdf.h:81
MRIOEXTRAS_API Pdf & operator=(Pdf other) noexcept
float getCursorPosX() const
Definition MRPdf.h:80
MRIOEXTRAS_API void addText(const std::string &text, bool isTitle=false)
MRIOEXTRAS_API void newPage()
Add new pageand move cursor on it.
void setCursorPosY(HPDF_REAL posY)
Definition MRPdf.h:79
MRIOEXTRAS_API Pdf(const std::filesystem::path &documentPath, const PdfParameters &params=PdfParameters())
Ctor.
void setCursorPosX(HPDF_REAL posX)
Definition MRPdf.h:78
MRIOEXTRAS_API void close()
Save and close document. After this impossible add anything in document.
MRIOEXTRAS_API ~Pdf()
Dtor. Automatically do close.
MRIOEXTRAS_API void addImageFromFile(const std::filesystem::path &imagePath, const std::string &caption={}, const std::vector< std::pair< double, std::string > > &valuesMarks={})
Add image from file in current cursor position. If image bigger than page size, autoscale image to pa...
MRIOEXTRAS_API Pdf(Pdf &&other) noexcept
Definition MRCameraOrientationPlugin.h:8
Parameters of document style.
Definition MRPdf.h:19
HPDF_REAL textSize
Definition MRPdf.h:21
std::string fontName
Font name list of available fonts: Courier (-Bold, -Oblique, -BoldOblique) Helvetica (-Bold,...
Definition MRPdf.h:31
HPDF_REAL titleSize
Definition MRPdf.h:20