alaCarte Maps
Renderer for OpenStreetMap tiles
render_canvas.hpp
Go to the documentation of this file.
1 
21 #ifndef RENDER_CANVAS_HPP
22 #define RENDER_CANVAS_HPP
23 
24 #include "settings.hpp"
25 
26 #include <cairo.h>
27 
28 #include "server/tile.hpp"
29 
31 struct CairoLayer
32 {
33  cairo_t* cr;
34  cairo_surface_t* surface;
35 
37  : cr(NULL)
38  , surface(NULL)
39  {
40  }
41 
43  {
44  if (surface)
45  cairo_surface_destroy(surface);
46  if (cr)
47  cairo_destroy(cr);
48  }
49 
50  void clear()
51  {
52  cairo_save(cr);
53 
54  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
55  cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
56  cairo_paint(cr);
57 
58  cairo_restore(cr);
59  }
60 };
61 
62 
64 {
65 public:
67  enum {
68  LAYER_FILL = 0,
73  LAYER_NUM
74  };
75 
76  virtual ~RenderCanvas() = default;
77 
79  virtual void clear() = 0;
81  virtual CairoLayer* getImageLayers() = 0;
83  virtual CairoLayer& getSliceLayer() = 0;
85  virtual Tile::ImageType copySliceImage() = 0;
86 };
87 
89 {
90 public:
92 
96  shared_ptr<RenderCanvas> getCanvas(TileIdentifier::Format type)
97  {
98  shared_ptr<RenderCanvas> canvas;
99  switch(type)
100  {
101  case TileIdentifier::Format::PNG:
102  canvas = pngCanvas;
103  break;
104  case TileIdentifier::Format::SVG:
105  canvas = svgCanvas;
106  break;
107  default:
108  break;
109  }
110 
111  return canvas;
112  }
113 
114 private:
115  shared_ptr<RenderCanvas> svgCanvas;
116  shared_ptr<RenderCanvas> pngCanvas;
117 };
118 
119 #endif
cairo_surface_t * surface
cairo_t * cr
Format
Enumeration which contains all supported image formats.
shared_ptr< RenderCanvas > svgCanvas
shared_ptr< RenderCanvas > getCanvas(TileIdentifier::Format type)
Returns an empty shared_ptr if format is not supported.
shared_ptr< RenderCanvas > pngCanvas
shared_ptr< std::vector< uint8_t > > ImageType
Definition: tile.hpp:33
This file is part of alaCarte.