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 for (
auto* _plotter : plotters) {
50 _plotter->bins_style(0).line_width = a_line_width;
51 _plotter->inner_frame_style().line_width = a_line_width;
52 _plotter->grid_style().line_width = a_line_width;
53 _plotter->x_axis().line_style().width = a_line_width;
54 _plotter->x_axis().ticks_style().width = a_line_width;
55 _plotter->y_axis().line_style().width = a_line_width;
56 _plotter->y_axis().ticks_style().width = a_line_width;
57 _plotter->z_axis().line_style().width = a_line_width;
58 _plotter->z_axis().ticks_style().width = a_line_width;
61 _plotter->title_style().line_width = a_line_width;
62 _plotter->infos_style().line_width = a_line_width;
63 _plotter->title_box_style().line_width = a_line_width;
65 _plotter->x_axis().labels_style().line_width = a_line_width;
66 _plotter->x_axis().mag_style().line_width = a_line_width;
67 _plotter->x_axis().title_style().line_width = a_line_width;
69 _plotter->y_axis().labels_style().line_width = a_line_width;
70 _plotter->y_axis().mag_style().line_width = a_line_width;
71 _plotter->y_axis().title_style().line_width = a_line_width;
73 _plotter->z_axis().labels_style().line_width = a_line_width;
74 _plotter->z_axis().mag_style().line_width = a_line_width;
75 _plotter->z_axis().title_style().line_width = a_line_width;
81void regions_style(tools::sg::plots& a_plots,
float a_plotter_scale = 1) {
87 float ww_wc = a_plots.width;
88 float wh_wc = a_plots.height;
89 float rw_wc = ww_wc/a_plots.cols;
90 float rh_wc = wh_wc/a_plots.rows;
94 float wfac = (rw_wc/ww_wc)*cooking;
95 float hfac = (rh_wc/wh_wc)*cooking;
97 float label_cooking = 1.6f;
99 if((a_plots.cols.value()>=4)&&(a_plots.cols.value()>a_plots.rows.value())) label_cooking = 0.9f;
101 float title_cooking = 1.1f;
103 a_plots.plotter_scale = a_plotter_scale;
105 std::vector<tools::sg::plotter*> plotters;
106 a_plots.plotters(plotters);
107 for (
auto* _plotter : plotters) {
108 _plotter->left_margin = _plotter->left_margin * wfac;
109 _plotter->right_margin = _plotter->right_margin * wfac;
110 _plotter->bottom_margin = _plotter->bottom_margin * hfac;
111 _plotter->top_margin = _plotter->top_margin * hfac;
113 _plotter->x_axis().tick_length = _plotter->x_axis().tick_length * wfac;
114 _plotter->y_axis().tick_length = _plotter->y_axis().tick_length * hfac;
116 _plotter->title_to_axis = _plotter->title_to_axis * hfac;
117 _plotter->title_height = _plotter->title_height * hfac * title_cooking;
119 _plotter->x_axis().label_height = _plotter->x_axis().label_height * hfac * label_cooking;
120 _plotter->y_axis().label_height = _plotter->y_axis().label_height * hfac * label_cooking;
126bool load_embeded_styles(tools::xml::styles& a_styles) {
129 const char** lines = viewplot_fonts_google_style(linen);
130 for(
unsigned int index=0;index<linen;index++) {
131 std::string s = lines[index];
132 tools::replace(s,
"@@double_quote@@",
"\"");
133 tools::replace(s,
"@@back_slash@@",
"\\");
136 return toolx::xml::load_style_string(a_styles,ss);
152#if defined(TOOLS_USE_FREETYPE)
156 fState.Message(
kVL1,
"... using high resolution with Freetype fonts",
"");
161 static toolx::sg::text_freetype ttf;
162 ttf.add_embedded_font(tools::sg::font_lato_regular_ttf(),tools::font::lato_regular_ttf);
163 ttf.add_embedded_font(tools::sg::font_roboto_bold_ttf(),tools::font::roboto_bold_ttf);
164 fViewer = std::make_unique<tools::viewplot>(
G4cout, ttf,
165 fPlotParameters.GetColumns(),
166 fPlotParameters.GetRows(),
167 fPlotParameters.GetWidth(),
168 fPlotParameters.GetHeight());
169 fViewer->plots().view_border =
false;
170 load_embeded_styles(fViewer->styles());
171 fViewer->styles().add_colormap(
"default",tools::sg::style_default_colormap());
172 fViewer->styles().add_colormap(
"ROOT",tools::sg::style_ROOT_colormap());
175 fState.Message(
kVL1,
"... using low resolution with Hershey fonts",
"");
176 fViewer = std::make_unique<tools::viewplot>(
G4cout,
177 fPlotParameters.GetColumns(),
178 fPlotParameters.GetRows(),
179 fPlotParameters.GetWidth(),
180 fPlotParameters.GetHeight());
181 fViewer->plots().view_border =
false;
190G4bool G4PlotManager::WritePage()
192 fState.
Message(
kVL4,
"write a page in",
"plot file", fFileName);
194#if defined(TOOLS_USE_FREETYPE)
195 HD_style(fViewer->plots(), 5);
196 regions_style(fViewer->plots(), fPlotParameters.
GetScale());
199 G4bool result = fViewer->write_page();
201 Warn(
"Cannot write a page in the plot file " + fFileName,
202 fkClass,
"WritePage");
206 fViewer->plots().init_sg();
209 fState.Message(
kVL3,
"write a page in",
"plot file", fFileName);
221 fState.Message(
kVL4,
"open",
"plot file", fileName);
224 fFileName = fileName;
226 G4bool result = fViewer->open_file(fileName);
228 Warn(
"Cannot open plot file " + fileName, fkClass,
"OpenFile");
231 fState.Message(
kVL1,
"open",
"plot file", fileName);
239 fState.Message(
kVL4,
"close",
"plot file", fFileName);
241 G4bool result = fViewer->close_file();
243 Warn(
"Cannot close the plot file", fkClass,
"CloseFile");
246 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)