A library for working with phylogenetic and population genetic data.
v0.32.0
image.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2022 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 <lczech@carnegiescience.edu>
20  Department of Plant Biology, Carnegie Institution For Science
21  260 Panama Street, Stanford, CA 94305, USA
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  // We compute the large box that takes rotated corners into account.
92 }
93 
94 void SvgImage::write( std::ostream& out, size_t indent, SvgDrawingOptions const& options ) const
95 {
96  (void) options;
97 
99  out << "<image";
100 
101  if( ! id.empty() ) {
102  out << svg_attribute( "id", id );
103  }
104 
105  out << svg_attribute( "x", position.x );
106  out << svg_attribute( "y", position.y );
107 
108  if( size.width != 0.0 || size.height != 0.0 ) {
109  out << svg_attribute( "width", size.width );
110  out << svg_attribute( "height", size.height );
111  }
112 
113  out << svg_attribute( "xlink:href", href );
114 
115  transform.write( out );
116 
117  switch( rendering ) {
118  case ImageRendering::kNone: {
119  // Nothing to do.
120  break;
121  }
122  case ImageRendering::kAuto: {
123  out << svg_attribute( "style", "image-rendering:auto" );
124  // out << svg_attribute( "image-rendering", "auto" );
125  break;
126  }
128  out << svg_attribute( "style", "image-rendering:optimizeSpeed" );
129  // out << svg_attribute( "image-rendering", "optimizeSpeed" );
130  break;
131  }
133  out << svg_attribute( "style", "image-rendering:optimizeQuality" );
134  // out << svg_attribute( "image-rendering", "optimizeQuality" );
135  break;
136  }
138  out << svg_attribute( "style", "image-rendering:smooth" );
139  // out << svg_attribute( "image-rendering", "smooth" );
140  break;
141  }
143  out << svg_attribute( "style", "image-rendering:crisp-edges" );
144  // out << svg_attribute( "image-rendering", "crisp-edges" );
145  break;
146  }
148  out << svg_attribute( "style", "image-rendering:pixelated" );
149  // out << svg_attribute( "image-rendering", "pixelated" );
150  break;
151  }
153  out << svg_attribute( "style", "image-rendering:inherit" );
154  // out << svg_attribute( "image-rendering", "inherit" );
155  break;
156  }
158  out << svg_attribute( "style", "image-rendering:initial" );
159  // out << svg_attribute( "image-rendering", "initial" );
160  break;
161  }
162  case ImageRendering::kUnset: {
163  out << svg_attribute( "style", "image-rendering:unset" );
164  // out << svg_attribute( "image-rendering", "unset" );
165  break;
166  }
167  }
168 
169  out << " />\n";
170 }
171 
172 } // namespace utils
173 } // namespace genesis
genesis::utils::SvgImage::ImageRendering::kAuto
@ kAuto
genesis::utils::SvgPoint::x
double x
Definition: utils/formats/svg/helper.hpp:69
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:719
genesis::utils::SvgPoint::y
double y
Definition: utils/formats/svg/helper.hpp:70
genesis::utils::SvgTransform::apply
SvgPoint apply(SvgPoint const &p) const
Apply all transformations to a point, and return the new transformed coordinate.
Definition: attributes.cpp:363
genesis::utils::SvgBox
Definition: utils/formats/svg/helper.hpp:127
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:94
genesis::utils::SvgTransform::write
void write(std::ostream &out) const
Definition: attributes.cpp:394
genesis::utils::SvgDocument::indentation_string
static std::string indentation_string
Definition: svg/document.hpp:60
genesis::utils::SvgPoint
Definition: utils/formats/svg/helper.hpp:57
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:229
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:77
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:1001
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:84
genesis::utils::SvgImage::ImageRendering::kCrispEdges
@ kCrispEdges
genesis::utils::SvgImage::ImageRendering::kInitial
@ kInitial
genesis::utils::SvgSize::height
double height
Definition: utils/formats/svg/helper.hpp:85
genesis::utils::SvgDrawingOptions
Definition: utils/formats/svg/helper.hpp:213
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