1 /*
2  * The MIT License
3  *
4  * Copyright (c) 2016-2018, Torsten Paul <torsten.paul@gmx.de>,
5  *                          Marius Kintel <marius@kintel.net>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  */
25 #pragma once
26 
27 #include <string>
28 
29 namespace libsvg {
30 
31 // https://oreillymedia.github.io/Using_SVG/guide/units.html
32 //
33 // Points (pt)
34 //
35 // 1pt ≅ 1.3333px or user units (1px = 0.75pt)
36 // 1pt = 1/72in
37 //
38 // Picas (pc)
39 //
40 // 1pc = 16px or user units
41 // 1pc = 1/6in
42 //
43 enum class unit_t { UNDEFINED, NONE, PERCENT, EM, EX, PX, IN, CM, MM, PT, PC };
44 
45 enum class align_t { UNDEFINED, NONE, MIN, MID, MAX };
46 
47 struct length_struct {
48 	double number;
49 	std::string unit;
50 };
51 
52 struct length_t {
53 	double number;
54 	unit_t unit;
55 };
56 
57 struct viewbox_t {
58 	double x;
59 	double y;
60 	double width;
61 	double height;
62 	bool is_valid;
63 };
64 
65 struct alignment_t {
66 	align_t x;
67 	align_t y;
68 	bool defer;
69 	bool meet;
70 };
71 
72 double parse_double(const std::string& number);
73 const length_t parse_length(const std::string& value);
74 const viewbox_t parse_viewbox(const std::string& value);
75 const alignment_t parse_alignment(const std::string& value);
76 
77 std::ostream &operator<<(std::ostream &stream, const unit_t &unit);
78 std::ostream &operator<<(std::ostream &stream, const length_t &length);
79 std::ostream &operator<<(std::ostream &stream, const align_t &align);
80 
81 }
82