A library for working with phylogenetic and population genetic data.
v0.27.0
image.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2020 Lucas Czech
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Contact:
19  Lucas Czech <lucas.czech@h-its.org>
20  Exelixis Lab, Heidelberg Institute for Theoretical Studies
21  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
22 */
23 
32 
35 
36 #include <ostream>
37 #include <stdexcept>
38 
39 namespace genesis {
40 namespace utils {
41 
42 // =================================================================================================
43 // Svg Image
44 // =================================================================================================
45 
46 // -------------------------------------------------------------
47 // Constructors and Rule of Five
48 // -------------------------------------------------------------
49 
51  std::string const& href
52 )
53  : href( href )
54 {}
55 
57  std::string const& href,
58  SvgPoint const& position
59 )
60  : href( href )
61  , position( position )
62 {}
63 
65  std::string const& href,
66  SvgPoint const& position,
67  SvgSize const& size
68 )
69  : href( href )
70  , position( position )
71  , size( size )
72 {}
73 
75  std::string const& href,
76  double x, double y,
77  double w, double h
78 )
79  : href( href )
80  , position( SvgPoint( x, y ) )
81  , size( SvgSize( w, h ) )
82 {}
83 
84 // -------------------------------------------------------------
85 // Members
86 // -------------------------------------------------------------
87 
89 {
90  return SvgBox( position, size.width, size.height );
91 }
92 
93 void SvgImage::write( std::ostream& out, size_t indent, SvgDrawingOptions const& options ) const
94 {
95  (void) options;
96 
98  out << "<image";
99 
100  if( ! id.empty() ) {
101  out << svg_attribute( "id", id );
102  }
103 
104  out << svg_attribute( "x", position.x );
105  out << svg_attribute( "y", position.y );
106 
107  if( size.width != 0.0 || size.height != 0.0 ) {
108  out << svg_attribute( "width", size.width );
109  out << svg_attribute( "height", size.height );
110  }
111 
112  out << svg_attribute( "xlink:href", href );
113 
114  transform.write( out );
115 
116  switch( rendering ) {
117  case ImageRendering::kNone: {
118  // Nothing to do.
119  break;
120  }
121  case ImageRendering::kAuto: {
122  out << svg_attribute( "style", "image-rendering:auto" );
123  // out << svg_attribute( "image-rendering", "auto" );
124  break;
125  }
127  out << svg_attribute( "style", "image-rendering:optimizeSpeed" );
128  // out << svg_attribute( "image-rendering", "optimizeSpeed" );
129  break;
130  }
132  out << svg_attribute( "style", "image-rendering:optimizeQuality" );
133  // out << svg_attribute( "image-rendering", "optimizeQuality" );
134  break;
135  }
137  out << svg_attribute( "style", "image-rendering:smooth" );
138  // out << svg_attribute( "image-rendering", "smooth" );
139  break;
140  }
142  out << svg_attribute( "style", "image-rendering:crisp-edges" );
143  // out << svg_attribute( "image-rendering", "crisp-edges" );
144  break;
145  }
147  out << svg_attribute( "style", "image-rendering:pixelated" );
148  // out << svg_attribute( "image-rendering", "pixelated" );
149  break;
150  }
152  out << svg_attribute( "style", "image-rendering:inherit" );
153  // out << svg_attribute( "image-rendering", "inherit" );
154  break;
155  }
157  out << svg_attribute( "style", "image-rendering:initial" );
158  // out << svg_attribute( "image-rendering", "initial" );
159  break;
160  }
161  case ImageRendering::kUnset: {
162  out << svg_attribute( "style", "image-rendering:unset" );
163  // out << svg_attribute( "image-rendering", "unset" );
164  break;
165  }
166  }
167 
168  out << " />\n";
169 }
170 
171 } // namespace utils
172 } // namespace genesis
genesis::utils::SvgImage::ImageRendering::kAuto
@ kAuto
genesis::utils::SvgPoint::x
double x
Definition: utils/formats/svg/helper.hpp:58
genesis::utils::indent
std::string indent(std::string const &text, std::string const &indentation)
Indent each line of text with indentation and return the result.
Definition: string.cpp:522
genesis::utils::SvgPoint::y
double y
Definition: utils/formats/svg/helper.hpp:59
genesis::utils::SvgBox
Definition: utils/formats/svg/helper.hpp:116
genesis::utils::SvgImage::size
SvgSize size
Definition: image.hpp:131
genesis::utils::SvgImage::write
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: image.cpp:93
genesis::utils::SvgTransform::write
void write(std::ostream &out) const
Definition: attributes.cpp:304
genesis::utils::SvgDocument::indentation_string
static std::string indentation_string
Definition: svg/document.hpp:59
genesis::utils::SvgPoint
Definition: utils/formats/svg/helper.hpp:51
string.hpp
Provides some commonly used string utility functions.
document.hpp
genesis::utils::SvgImage::ImageRendering::kSmooth
@ kSmooth
genesis::utils::SvgImage::ImageRendering::kOptimizeSpeed
@ kOptimizeSpeed
genesis::utils::SvgImage::ImageRendering::kPixelated
@ kPixelated
genesis::utils::SvgImage::SvgImage
SvgImage(std::string const &href)
Definition: image.cpp:50
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::utils::SvgImage::rendering
ImageRendering rendering
Definition: image.hpp:134
genesis::utils::svg_attribute
std::string svg_attribute(std::string const &name, T const &value, std::string const &unit="")
Definition: utils/formats/svg/helper.hpp:218
genesis::utils::SvgImage::ImageRendering::kUnset
@ kUnset
genesis::utils::SvgImage::href
std::string href
Definition: image.hpp:128
genesis::utils::SvgImage::ImageRendering::kInherit
@ kInherit
image.hpp
genesis::utils::SvgSize
Definition: utils/formats/svg/helper.hpp:66
genesis::utils::repeat
std::string repeat(std::string const &word, size_t times)
Take a string and repeat it a given number of times.
Definition: string.cpp:758
genesis::utils::SvgImage::ImageRendering::kOptimizeQuality
@ kOptimizeQuality
genesis::utils::SvgImage::bounding_box
SvgBox bounding_box() const
Definition: image.cpp:88
genesis::utils::SvgSize::width
double width
Definition: utils/formats/svg/helper.hpp:73
genesis::utils::SvgImage::ImageRendering::kCrispEdges
@ kCrispEdges
genesis::utils::SvgImage::ImageRendering::kInitial
@ kInitial
genesis::utils::SvgSize::height
double height
Definition: utils/formats/svg/helper.hpp:74
genesis::utils::SvgDrawingOptions
Definition: utils/formats/svg/helper.hpp:202
genesis::utils::SvgImage::transform
SvgTransform transform
Definition: image.hpp:133
genesis::utils::SvgImage::ImageRendering::kNone
@ kNone
genesis::utils::SvgImage::position
SvgPoint position
Definition: image.hpp:130