From 8f8fda2d68bf01dc17f592a6d7b05e906f2e5d38 Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Sat, 4 Jul 2015 08:45:24 +0200 Subject: [PATCH] Fix font sizes in SVG output --- doc/news/changes.h | 8 ++++++ include/deal.II/grid/grid_out.h | 23 ++++++++--------- source/grid/grid_out.cc | 44 +++++++++++++++++++-------------- 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/doc/news/changes.h b/doc/news/changes.h index a3b6646cac..48f83dbcee 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -547,6 +547,14 @@ inconvenience this causes. (Guido Kanschat, 2015/07/05) +
  • Improved: The font scaling in GridOut::write_svg() was broken, + since the units were missing. It has been fixed and an additional + parameter GridOutFlags::Svg::cell_font_scaling has been introduced + for tuning. +
    + (Guido Kanschat, 2015/07/04) +
  • +
  • New: GridGenerator::cheese() for a mesh with many holes; GridGenerator::simplex() for simplices in 2 and 3 dimensions; GridGenerator::hyper_cross() for crosses in 2 and 3 dimensions. diff --git a/include/deal.II/grid/grid_out.h b/include/deal.II/grid/grid_out.h index 859e35b9c6..05021a2b49 100644 --- a/include/deal.II/grid/grid_out.h +++ b/include/deal.II/grid/grid_out.h @@ -664,17 +664,18 @@ namespace GridOutFlags /// The factor determining the vertical distance between levels (default = 0.3) float level_height_factor; - /** - * Cell labeling (fixed order). - * - * The following booleans determine which properties of the cell shall be - * displayed as text in the middle of each cell. - */ - bool label_level_number; // default: true - bool label_cell_index; // default: true - bool label_material_id; // default: false - bool label_subdomain_id; // default: false - bool label_level_subdomain_id; // default: false + /// Scaling of the font for cell annotations. Defaults to 1. + float cell_font_scaling; + /// Write level number into each cell. Defaults to true + bool label_level_number; + /// Write cell index into each cell. Defaults to true + bool label_cell_index; + /// Write material id of each cell. Defaults to false + bool label_material_id; + /// Write subdomain id of each cell. Defaults to false + bool label_subdomain_id; + /// Write level subdomain id of each cell. Defaults to false + bool label_level_subdomain_id; /// Draw a colorbar next to the plotted grid with respect to the chosen coloring of the cells bool draw_colorbar; diff --git a/source/grid/grid_out.cc b/source/grid/grid_out.cc index 3395000955..c3278c3a2e 100644 --- a/source/grid/grid_out.cc +++ b/source/grid/grid_out.cc @@ -368,6 +368,7 @@ namespace GridOutFlags coloring(coloring), convert_level_number_to_height(convert_level_number_to_height), level_height_factor(0.3f), + cell_font_scaling(1.f), label_level_number(label_level_number), label_cell_index(label_cell_index), label_material_id(label_material_id), @@ -1424,11 +1425,10 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const unsigned int min_level, max_level; - // Svg files require an underlying drawing grid. - // We set the number of height elements of this - // grid to 4000 and adapt the number of width - // elements with respect to the bounding box of - // the given triangulation. + // Svg files require an underlying drawing grid. The size of this + // grid is provided in the parameters height and width. Each of them + // may be zero, such that it is computed from the other. Obviously, + // both of them zero does not produce reasonable output. unsigned int height = svg_flags.height; unsigned int width = svg_flags.width; Assert (height != 0 || width != 0, ExcMessage("You have to set at least one of width and height")); @@ -1714,7 +1714,11 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const unsigned int additional_width = 0; // font size for date, time, legend, and colorbar unsigned int font_size = static_cast(.5 + (height/100.) * 1.75); - cell_label_font_size = static_cast((int)(.5 + (height/100.) * 2.75) * 9. * (min_level_min_vertex_distance / std::min(x_dimension, y_dimension))); + cell_label_font_size = static_cast(.5 + + (height * .15 + * svg_flags.cell_font_scaling + * min_level_min_vertex_distance + / std::min(x_dimension, y_dimension))); if (svg_flags.draw_legend && (svg_flags.label_level_number || svg_flags.label_cell_index || svg_flags.label_material_id || svg_flags.label_subdomain_id || svg_flags.label_level_subdomain_id )) { @@ -1856,7 +1860,7 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const else x_offset = static_cast(.5 + height * .025); out << " (.5 + height * .0525) << '\"' - << " style=\"font-weight:100; fill:lightsteelblue; text-anchor:start; font-family:Courier; font-size:" << static_cast(.5 + height * .045) << "\">" + << " style=\"font-weight:100; fill:lightsteelblue; text-anchor:start; font-family:Courier; font-size:" << static_cast(.5 + height * .045) << "px\">" << "deal.II" << "" << '\n'; // out << " (.5 + height * .045 * 4.75) << "\" y=\"" << static_cast(.5 + height * .0525) << '\"' @@ -1991,11 +1995,13 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const projection_decomposition = GridOut::svg_project_point(point, camera_position, camera_direction, camera_horizontal, camera_focus); + const unsigned int font_size_this_cell = static_cast(.5 + cell_label_font_size * pow(.5, (float)cell->level() - 4. + 3.5 * distance_factor)); + out << " (.5 + ((projection_decomposition[0] - x_min_perspective) / x_dimension_perspective) * (width - (width/100.) * 2. * margin_in_percent) + ((width/100.) * margin_in_percent)) - << "\" y=\"" << static_cast(.5 + height - (height/100.) * margin_in_percent - ((projection_decomposition[1] - y_min_perspective) / y_dimension_perspective) * (height - (height/100.) * 2. * margin_in_percent)) - << "\" style=\"font-size:" << static_cast(.5 + cell_label_font_size * pow(.5, (float)cell->level() - 4. + 3.5 * distance_factor)) - << "\">"; + << "\" y=\"" << static_cast(.5 + height - (height/100.) * margin_in_percent - ((projection_decomposition[1] - y_min_perspective) / y_dimension_perspective) * (height - (height/100.) * 2. * margin_in_percent) + 0.5 * font_size_this_cell) + << "\" style=\"font-size:" << font_size_this_cell + << "px\">"; if (svg_flags.label_level_number) { @@ -2103,7 +2109,7 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const out << " (.5 + (height/100.) * 1.25) << "\" y=\"" << static_cast(.5 + (height/100.) * margin_in_percent + (++line_offset) * 1.5 * font_size) << "\" style=\"text-anchor:start; font-weight:bold; font-size:" << font_size - << "\">" << "cell label" + << "px\">" << "cell label" << "" << '\n'; if (svg_flags.label_level_number) @@ -2111,7 +2117,7 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const out << " (.5 + (height/100.) * 2.) << "\" y=\"" << static_cast(.5 + (height/100.) * margin_in_percent + (++line_offset) * 1.5 * font_size) << "\" style=\"text-anchor:start; font-style:oblique; font-size:" << font_size - << "\">" << "level_number"; + << "px\">" << "level_number"; if (svg_flags.label_cell_index || svg_flags.label_material_id || svg_flags.label_subdomain_id || svg_flags.label_level_subdomain_id) out << ','; @@ -2124,7 +2130,7 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const out << " (.5 + (height/100.) * 2.) << "\" y=\"" << static_cast(.5 + (height/100.) * margin_in_percent + (++line_offset) * 1.5 * font_size ) << "\" style=\"text-anchor:start; font-style:oblique; font-size:" << font_size - << "\">" + << "px\">" << "cell_index"; if (svg_flags.label_material_id || svg_flags.label_subdomain_id || svg_flags.label_level_subdomain_id) @@ -2138,7 +2144,7 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const out << " (.5 + (height/100.) * 2.) << "\" y=\"" << static_cast(.5 + (height/100.) * margin_in_percent + (++line_offset) * 1.5 * font_size ) << "\" style=\"text-anchor:start; font-style:oblique; font-size:" << font_size - << "\">" + << "px\">" << "material_id"; if (svg_flags.label_subdomain_id || svg_flags.label_level_subdomain_id) @@ -2152,7 +2158,7 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const out << " (.5 + (height/100.) * 2.) << "\" y=\"" << static_cast(.5 + (height/100.) * margin_in_percent + (++line_offset) * 1.5 * font_size ) << "\" style=\"text-anchor:start; font-style:oblique; font-size:" << font_size - << "\">" + << "px\">" << "subdomain_id"; if (svg_flags.label_level_subdomain_id) @@ -2166,7 +2172,7 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const out << " (.5 + (height/100.) * 2.) << "\" y=\"" << static_cast(.5 + (height/100.) * margin_in_percent + (++line_offset) * 1.5 * font_size ) << "\" style=\"text-anchor:start; font-style:oblique; font-size:" << font_size - << "\">" + << "px\">" << "level_subdomain_id" << "" << '\n'; } @@ -2177,7 +2183,7 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const { out << " (.5 + (height/100.) * margin_in_percent + 10.75 * font_size) - << "\" style=\"text-anchor:start; font-size:" << font_size << "\">" + << "\" style=\"text-anchor:start; font-size:" << font_size << "px\">" << "azimuth: " << svg_flags.azimuth_angle << "°, polar: " << svg_flags.polar_angle << "°" << '\n'; } @@ -2189,7 +2195,7 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const out << " (.5 + (height/100.) * (margin_in_percent + 29.) - (font_size/1.25)) - << "\" style=\"text-anchor:start; font-weight:bold; font-size:" << font_size << "\">"; + << "\" style=\"text-anchor:start; font-weight:bold; font-size:" << font_size << "px\">"; switch (svg_flags.coloring) { @@ -2245,7 +2251,7 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const out << " (.5 + (height/100.) * (margin_in_percent + 29)) + (n-index-1 + .5) * element_height + static_cast(.5 + font_size * .35) << "\"" - << " style=\"text-anchor:start; font-size:" << static_cast(.5 + font_size); + << " style=\"text-anchor:start; font-size:" << static_cast(.5 + font_size) << "px"; if (index == 0 || index == n-1) out << "; font-weight:bold"; -- 2.39.5