MeshLib
 
Loading...
Searching...
No Matches
MRPdf.h
Go to the documentation of this file.
1#pragma once
2#include "MRMeshFwd.h"
3#if !defined( __EMSCRIPTEN__) && !defined( MRMESH_NO_PDF )
4#include <filesystem>
5
6#include "hpdf.h"
7
8namespace MR
9{
10
15{
16 HPDF_REAL titleSize = 18.f;
17 HPDF_REAL textSize = 14.f;
27 std::string fontName = "Helvetica";
28};
29
33class Pdf
34{
35public:
37 MRMESH_API Pdf( const std::filesystem::path& documentPath, const PdfParameters& params = PdfParameters() );
38 MRMESH_API Pdf( Pdf&& other ) noexcept;
39 MRMESH_API Pdf& operator=( Pdf other ) noexcept; // Sic, passing by value.
42
43 Pdf( const Pdf& rhs ) = delete;
44 Pdf& operator = ( const Pdf& rhs ) = delete;
45
54 MRMESH_API void addText( const std::string& text, bool isTitle = false );
55
65 MRMESH_API void addImageFromFile( const std::filesystem::path& imagePath, const std::string& caption = {},
66 const std::vector<std::pair<double, std::string>>& valuesMarks = {} );
67
70
73
74 void setCursorPosX( HPDF_REAL posX ) { cursorX_ = posX; };
75 void setCursorPosY( HPDF_REAL posY ) { cursorY_ = posY; };
76 float getCursorPosX() const { return cursorX_; };
77 float getCursorPosY() const { return cursorY_; };
78
80 operator bool() const { return state_.document != 0; };
81
82private:
83 struct State
84 {
85 HPDF_Doc document = nullptr;
86 HPDF_Page activePage = nullptr;
87 HPDF_Font activeFont = nullptr;
88 };
89 State state_;
90
91 std::filesystem::path filename_;
92
93 PdfParameters params_;
94
95 HPDF_REAL cursorX_ = 0;
96 HPDF_REAL cursorY_ = 0;
97
98 bool checkDocument() const { return state_.document && state_.activePage; };
99};
100
101}
102#endif
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
Definition MRPdf.h:34
Pdf(const Pdf &rhs)=delete
MRMESH_API ~Pdf()
Dtor. Automatically do close.
float getCursorPosY() const
Definition MRPdf.h:77
MRMESH_API Pdf & operator=(Pdf other) noexcept
float getCursorPosX() const
Definition MRPdf.h:76
MRMESH_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...
void setCursorPosY(HPDF_REAL posY)
Definition MRPdf.h:75
MRMESH_API Pdf(const std::filesystem::path &documentPath, const PdfParameters &params=PdfParameters())
Ctor.
void setCursorPosX(HPDF_REAL posX)
Definition MRPdf.h:74
MRMESH_API Pdf(Pdf &&other) noexcept
MRMESH_API void newPage()
Add new pageand move cursor on it.
MRMESH_API void addText(const std::string &text, bool isTitle=false)
MRMESH_API void close()
Save and close document. After this impossible add anything in document.
Definition MRCameraOrientationPlugin.h:7
Parameters of document style.
Definition MRPdf.h:15
HPDF_REAL textSize
Definition MRPdf.h:17
std::string fontName
Font name list of available fonts: Courier (-Bold, -Oblique, -BoldOblique) Helvetica (-Bold,...
Definition MRPdf.h:27
HPDF_REAL titleSize
Definition MRPdf.h:16