34#if defined(TOOLS_USE_FREETYPE)
35#include "toolx/sg/text_freetype"
36#include "toolx/xml/xml_style"
37#include "tools/xml/wrap_viewplot_fonts_google_style"
39#include "tools/font/lato_regular_ttf"
40#include "tools/font/roboto_bold_ttf"
46void HD_style(tools::sg::plots& a_plots,
float a_line_width) {
47 std::vector<tools::sg::plotter*> plotters;
48 a_plots.plotters(plotters);
49 tools_vforcit(tools::sg::plotter*,plotters,it) {
50 tools::sg::plotter* _plotter = *it;
51 _plotter->bins_style(0).line_width = a_line_width;
52 _plotter->inner_frame_style().line_width = a_line_width;
53 _plotter->grid_style().line_width = a_line_width;
54 _plotter->x_axis().line_style().width = a_line_width;
55 _plotter->x_axis().ticks_style().width = a_line_width;
56 _plotter->y_axis().line_style().width = a_line_width;
57 _plotter->y_axis().ticks_style().width = a_line_width;
58 _plotter->z_axis().line_style().width = a_line_width;
59 _plotter->z_axis().ticks_style().width = a_line_width;
62 _plotter->title_style().line_width = a_line_width;
63 _plotter->infos_style().line_width = a_line_width;
64 _plotter->title_box_style().line_width = a_line_width;
66 _plotter->x_axis().labels_style().line_width = a_line_width;
67 _plotter->x_axis().mag_style().line_width = a_line_width;
68 _plotter->x_axis().title_style().line_width = a_line_width;
70 _plotter->y_axis().labels_style().line_width = a_line_width;
71 _plotter->y_axis().mag_style().line_width = a_line_width;
72 _plotter->y_axis().title_style().line_width = a_line_width;
74 _plotter->z_axis().labels_style().line_width = a_line_width;
75 _plotter->z_axis().mag_style().line_width = a_line_width;
76 _plotter->z_axis().title_style().line_width = a_line_width;
82void regions_style(tools::sg::plots& a_plots,
float a_plotter_scale = 1) {
88 float ww_wc = a_plots.width;
89 float wh_wc = a_plots.height;
90 float rw_wc = ww_wc/a_plots.cols;
91 float rh_wc = wh_wc/a_plots.rows;
95 float wfac = (rw_wc/ww_wc)*cooking;
96 float hfac = (rh_wc/wh_wc)*cooking;
98 float label_cooking = 1.6f;
100 if((a_plots.cols.value()>=4)&&(a_plots.cols.value()>a_plots.rows.value())) label_cooking = 0.9f;
102 float title_cooking = 1.1f;
104 a_plots.plotter_scale = a_plotter_scale;
106 std::vector<tools::sg::plotter*> plotters;
107 a_plots.plotters(plotters);
108 tools_vforcit(tools::sg::plotter*,plotters,it) {
109 tools::sg::plotter* _plotter = *it;
111 _plotter->left_margin = _plotter->left_margin * wfac;
112 _plotter->right_margin = _plotter->right_margin * wfac;
113 _plotter->bottom_margin = _plotter->bottom_margin * hfac;
114 _plotter->top_margin = _plotter->top_margin * hfac;
116 _plotter->x_axis().tick_length = _plotter->x_axis().tick_length * wfac;
117 _plotter->y_axis().tick_length = _plotter->y_axis().tick_length * hfac;
119 _plotter->title_to_axis = _plotter->title_to_axis * hfac;
120 _plotter->title_height = _plotter->title_height * hfac * title_cooking;
122 _plotter->x_axis().label_height = _plotter->x_axis().label_height * hfac * label_cooking;
123 _plotter->y_axis().label_height = _plotter->y_axis().label_height * hfac * label_cooking;
130bool load_embeded_styles(tools::xml::styles& a_styles) {
133 const char** lines = viewplot_fonts_google_style(linen);
134 for(
unsigned int index=0;index<linen;index++) {
135 std::string s = lines[index];
136 tools::replace(s,
"@@double_quote@@",
"\"");
137 tools::replace(s,
"@@back_slash@@",
"\\");
140 return toolx::xml::load_style_string(a_styles,ss);
156#if defined(TOOLS_USE_FREETYPE)
160 fState.
Message(
kVL1,
"... using high resolution with Freetype fonts",
"");
165 static toolx::sg::text_freetype ttf;
166 ttf.add_embedded_font(tools::sg::font_lato_regular_ttf(),tools::font::lato_regular_ttf);
167 ttf.add_embedded_font(tools::sg::font_roboto_bold_ttf(),tools::font::roboto_bold_ttf);
168 fViewer = std::make_unique<tools::viewplot>(
G4cout, ttf,
173 fViewer->plots().view_border =
false;
174 load_embeded_styles(fViewer->styles());
175 fViewer->styles().add_colormap(
"default",tools::sg::style_default_colormap());
176 fViewer->styles().add_colormap(
"ROOT",tools::sg::style_ROOT_colormap());
179 fState.
Message(
kVL1,
"... using low resolution with Hershey fonts",
"");
180 fViewer = std::make_unique<tools::viewplot>(
G4cout,
185 fViewer->plots().view_border =
false;
194G4bool G4PlotManager::WritePage()
196 fState.
Message(
kVL4,
"write a page in",
"plot file", fFileName);
198#if defined(TOOLS_USE_FREETYPE)
199 HD_style(fViewer->plots(), 5);
200 regions_style(fViewer->plots(), fPlotParameters.
GetScale());
203 G4bool result = fViewer->write_page();
205 Warn(
"Cannot write a page in the plot file " + fFileName,
206 fkClass,
"WritePage");
210 fViewer->plots().init_sg();
213 fState.
Message(
kVL3,
"write a page in",
"plot file", fFileName);
225 fState.
Message(
kVL4,
"open",
"plot file", fileName);
228 fFileName = fileName;
230 G4bool result = fViewer->open_file(fileName);
232 Warn(
"Cannot open plot file " + fileName, fkClass,
"OpenFile");
235 fState.
Message(
kVL1,
"open",
"plot file", fileName);
243 fState.
Message(
kVL4,
"close",
"plot file", fFileName);
245 G4bool result = fViewer->close_file();
247 Warn(
"Cannot close the plot file", fkClass,
"CloseFile");
250 fState.
Message(
kVL1,
"close",
"plot file", fFileName);
G4GLOB_DLL std::ostream G4cout
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
G4bool OpenFile(const G4String &fileName)
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)