]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix font sizes in SVG output
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Sat, 4 Jul 2015 06:45:24 +0000 (08:45 +0200)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Sun, 5 Jul 2015 15:19:38 +0000 (17:19 +0200)
doc/news/changes.h
include/deal.II/grid/grid_out.h
source/grid/grid_out.cc

index a3b6646cac9b5183f24cc18d1513dd58be14eb2f..48f83dbceec22c2b92db3771415bb38defa87536 100644 (file)
@@ -547,6 +547,14 @@ inconvenience this causes.
   (Guido Kanschat, 2015/07/05)
   </li>
 
+  <li>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.
+  <br>
+  (Guido Kanschat, 2015/07/04)
+  </li>
+  
   <li>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.
index 859e35b9c6636f314c0108876f85b22cc12f05e7..05021a2b498d097b45016eb8dcecb7cdfb628b79 100644 (file)
@@ -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;
index 33950009553c6e254c7b86d9af0efa3f84f8d3ce..c3278c3a2ec454d90a6bf4f84d207c9afb596ee3 100644 (file)
@@ -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<unsigned int>(.5 + (height/100.) * 1.75);
-  cell_label_font_size = static_cast<unsigned int>((int)(.5 + (height/100.) * 2.75) * 9. * (min_level_min_vertex_distance / std::min(x_dimension, y_dimension)));
+  cell_label_font_size = static_cast<unsigned int>(.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<unsigned int>(.5 + height * .025);
 
       out << " <text x=\"" << x_offset << "\" y=\"" << static_cast<unsigned int>(.5 + height * .0525) << '\"'
-          << " style=\"font-weight:100; fill:lightsteelblue; text-anchor:start; font-family:Courier; font-size:" << static_cast<unsigned int>(.5 + height * .045) << "\">"
+          << " style=\"font-weight:100; fill:lightsteelblue; text-anchor:start; font-family:Courier; font-size:" << static_cast<unsigned int>(.5 + height * .045) << "px\">"
           << "deal.II" << "</text>" << '\n';
 
       // out << " <text x=\"" << x_offset + static_cast<unsigned int>(.5 + height * .045 * 4.75) << "\" y=\"" << static_cast<unsigned int>(.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<unsigned int>(.5 + cell_label_font_size * pow(.5, (float)cell->level() - 4. + 3.5 * distance_factor));
+
               out << "  <text"
                   << " x=\"" << static_cast<unsigned int>(.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<unsigned int>(.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<unsigned int>(.5 + cell_label_font_size * pow(.5, (float)cell->level() - 4. + 3.5 * distance_factor))
-                  << "\">";
+                  << "\" y=\"" << static_cast<unsigned int>(.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 << " <text x=\"" << width + additional_width + static_cast<unsigned int>(.5 + (height/100.) * 1.25)
           << "\" y=\"" << static_cast<unsigned int>(.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"
           << "</text>" << '\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 << "  <text x=\"" << width + additional_width + static_cast<unsigned int>(.5 + (height/100.) * 2.)
               << "\" y=\"" << static_cast<unsigned int>(.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 << "  <text x=\"" << width + additional_width + static_cast<unsigned int>(.5 + (height/100.) * 2.)
               << "\" y=\"" << static_cast<unsigned int>(.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 << "  <text x=\"" << width + additional_width + static_cast<unsigned int>(.5 + (height/100.) * 2.)
               << "\" y=\"" << static_cast<unsigned int>(.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 << "  <text x= \"" << width + additional_width + static_cast<unsigned int>(.5 + (height/100.) * 2.)
               << "\" y=\"" << static_cast<unsigned int>(.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 << "  <text x= \"" << width + additional_width + static_cast<unsigned int>(.5 + (height/100.) * 2.)
               << "\" y=\""       << static_cast<unsigned int>(.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"
               << "</text>" << '\n';
         }
@@ -2177,7 +2183,7 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const
     {
       out << "  <text x=\"" << width + additional_width
           << "\" y=\"" << static_cast<unsigned int>(.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 << "°</text>" << '\n';
     }
 
@@ -2189,7 +2195,7 @@ void GridOut::write_svg(const Triangulation<2,2> &tria, std::ostream &out) const
 
       out << " <text x=\"" << width + additional_width
           << "\" y=\""     << static_cast<unsigned int>(.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 << "  <text x=\"" << width + additional_width + 1.5 * element_width
               << "\" y=\"" << static_cast<unsigned int>(.5 + (height/100.) * (margin_in_percent + 29)) + (n-index-1 + .5) * element_height + static_cast<unsigned int>(.5 + font_size * .35) << "\""
-              << " style=\"text-anchor:start; font-size:" << static_cast<unsigned int>(.5 + font_size);
+              << " style=\"text-anchor:start; font-size:" << static_cast<unsigned int>(.5 + font_size) << "px";
 
           if (index == 0 || index == n-1) out << "; font-weight:bold";
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.