A toolkit for working with phylogenetic data.
v0.19.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
image.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2017 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 
38 namespace genesis {
39 namespace utils {
40 
41 // =================================================================================================
42 // Svg Image
43 // =================================================================================================
44 
45 // -------------------------------------------------------------
46 // Constructors and Rule of Five
47 // -------------------------------------------------------------
48 
50  std::string const& href
51 )
52  : href( href )
53 {}
54 
56  std::string const& href,
57  SvgPoint const& position
58 )
59  : href( href )
60  , position( position )
61 {}
62 
64  std::string const& href,
65  SvgPoint const& position,
66  SvgSize const& size
67 )
68  : href( href )
69  , position( position )
70  , size( size )
71 {}
72 
74  std::string const& href,
75  double x, double y,
76  double w, double h
77 )
78  : href( href )
79  , position( SvgPoint( x, y ) )
80  , size( SvgSize( w, h ) )
81 {}
82 
83 // -------------------------------------------------------------
84 // Members
85 // -------------------------------------------------------------
86 
88 {
89  return SvgBox( position, size.width, size.height );
90 }
91 
92 void SvgImage::write( std::ostream& out, size_t indent, SvgDrawingOptions const& options ) const
93 {
94  (void) options;
95 
96  out << repeat( SvgDocument::indentation_string, indent );
97  out << "<image";
98 
99  if( ! id.empty() ) {
100  out << svg_attribute( "id", id );
101  }
102 
103  out << svg_attribute( "x", position.x );
104  out << svg_attribute( "y", position.y );
105 
106  if( size.width != 0.0 || size.height != 0.0 ) {
107  out << svg_attribute( "width", size.width );
108  out << svg_attribute( "height", size.height );
109  }
110 
111  out << svg_attribute( "xlink:href", href );
112 
113  transform.write( out );
114  out << " />\n";
115 }
116 
117 } // namespace utils
118 } // namespace genesis
SvgTransform transform
Definition: image.hpp:113
SvgBox bounding_box() const
Definition: image.cpp:87
std::string svg_attribute(std::string const &name, T const &value, std::string const &unit="")
std::string repeat(std::string const &word, size_t times)
Take a string and repeat it a given number of times.
Definition: string.cpp:377
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:231
SvgImage(std::string const &href)
Definition: image.cpp:49
Provides some commonly used string utility functions.
void write(std::ostream &out) const
Definition: attributes.cpp:304
static std::string indentation_string
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: image.cpp:92