1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 // -*- mode: C++ -*- 3 // 4 // Copyright (C) 2013-2020 Red Hat, Inc. 5 6 /// @file 7 8 #ifndef __ABG_VIZ_SVG_H__ 9 #define __ABG_VIZ_SVG_H__ 10 11 #include <abg-viz-common.h> 12 13 namespace abigail 14 { 15 16 /** 17 Row displaying one element of member data. 18 19 Wide open background spaces, what do they look like, what do the 20 things in the foreground look like? Rectangle, for one. 21 22 Some characteristics: 23 - horizontal label (text anchor = start ie left). 24 - background box 25 - text data (text anchor = middle ie centered). 26 */ 27 struct row 28 { 29 std::string _M_id; 30 const style& _M_style; 31 32 units_type _M_offset; 33 units_type _M_size; 34 units_type _M_align; 35 }; 36 37 /// Useful row constants. Maybe just do enum->value map. 38 extern const style primary_row_sty; 39 extern const style base_row_sty; 40 extern const style member_row_sty; 41 extern const style implementation_row_sty; 42 43 44 /** 45 SVG "array" style notation for size/layout/alignment. 46 47 This is a compact SVG representation of class layout. 48 49 It is composed of a minimum of three data points for each member or 50 base of a class: 51 52 - offset index 53 - size 54 - align 55 56 Including annotations for holes, padding, and 57 implementation-specified and otherwise invisible objects. 58 59 It's constructed by creating vertical columns for each of the data 60 points specified above, and filling in horizontal rows for each of 61 the class components. 62 */ 63 struct svg 64 { 65 66 private: 67 68 const std::string _M_title; 69 const canvas& _M_canvas; 70 const typography& _M_typo; 71 72 const units_type _M_x_size = 3; // Number of columns 73 units_type _M_x_space; // Column spacing. 74 units_type _M_x_origin; // X origin 75 76 units_type _M_y_size; // Number of rows 77 units_type _M_y_space; // Row spacing. 78 units_type _M_y_origin; // Y origin 79 80 std::ostringstream _M_sstream; 81 82 // static const units_type _M_stroke_width = 1; 83 // static const units_type _M_text_padding = 10; 84 85 public: 86 87 svg(const std::string &__title, 88 const canvas& __cv = ansi_letter_canvas, 89 const typography& __typo = arial_typo) _M_titlesvg90 : _M_title(__title), _M_canvas(__cv), _M_typo(__typo), _M_y_size(0) 91 { 92 // Offsets require: typo, canvas units, size. 93 _M_x_space = 40; 94 _M_y_space = 40; 95 _M_x_origin = _M_x_space * 1; 96 _M_y_origin = _M_y_space * 2; 97 } 98 99 // Empty when the output buffer is. 100 bool emptysvg101 empty() { return _M_sstream.str().empty(); } 102 103 void 104 start_element(); 105 106 void 107 finish_element(); 108 109 void 110 add_title(); 111 112 void 113 add_y_row(const row&); 114 115 void 116 add_y_lines(); 117 118 void 119 add_y_label(); 120 121 void 122 write(); 123 124 void startsvg125 start() 126 { 127 this->start_element(); 128 this->add_title(); 129 } 130 131 void finishsvg132 finish() 133 { 134 this->add_y_label(); 135 this->add_y_lines(); 136 this->finish_element(); 137 this->write(); 138 } 139 }; 140 141 // XXX connect external xml file to input. 142 // parse input, pick apart elements, attributes. 143 144 }// end namespace abigail 145 146 #endif //__ABG_VIZ_SVG_H__ 147