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_COMMON_H__
9 #define __ABG_VIZ_COMMON_H__
10 
11 #include <sstream> //stringstream
12 #include <string>
13 #include <tuple>
14 #include <array>
15 
16 namespace abigail
17 {
18 
19 /// Utility function, like regex_replace.
20 void
21 string_replace(std::string&, const std::string&, const std::string&);
22 
23 
24 /// Measurement abstraction type, conversion function.
25 enum class units
26 {
27   // NB: 1 pixel = .264583 mm
28   millimeter,		// mm
29   pixel			// px
30 };
31 
32 std::string
33 units_to_string(units);
34 
35 typedef unsigned short	units_type;
36 
37 
38 /**
39   Page/Canvas/Drawing area description.
40   Size, origin location in 2D (x,y), heigh, width
41 
42   ANSI Letter mm == (units::millimeter, 215.9, 279.4);
43   ANSI Letter pixels == (units::pixel, 765, 990);
44   ISO A4 mm == (units::millimeter, 210, 297);
45   ISO A4 pixels == (units::pixel, 744.09, 1052.36);
46  */
47 struct canvas
48 {
49   units			_M_units;
50   units_type		_M_width;
51   units_type		_M_height;
52 };
53 
54 /// Useful canvas constants.
55 extern const canvas	ansi_letter_canvas;
56 extern const canvas	iso_a4_canvas;
57 
58 
59 /// Color, conversion function.
60 enum class color
61 {
62   white,
63   gray25,		// gainsboro
64   gray75,		// slategray
65   black
66 };
67 
68 std::string
69 color_to_string(color);
70 
71 
72 /**
73   Character rendering, type, fonts, styles.
74 
75   Expect to keep changing the output, so use this abstraction to set
76   styling defaults, so that one can just assign types instead of doing
77   a bunch of search-and-replace operations when changing type
78   characteristics.
79  */
80 struct typography
81 {
82   enum anchor { start, middle };
83 
84   std::string		_M_face;	// System font name
85   unsigned short	_M_size;	// Display size
86   color			_M_color;
87   std::string		_M_attributes;	// Any other attributes
88 
89   std::string
90   to_attribute(anchor) const;
91 
92   std::string
93   anchor_to_string(anchor) const;
94 };
95 
96 /// Useful typography constants.
97 extern const typography arial_typo;
98 extern const typography source_code_pro_typo;
99 extern const typography roboto_light_typo;
100 
101 
102 /// Datum consolidating style preferences.
103 struct style
104 {
105   color	       		_M_text_color;
106   color	       		_M_fill_color;
107   std::string		_M_attributes;
108 };
109 
110 
111 }// end namespace abigail
112 
113 #endif //__ABG_VIZ_COMMON_H__
114