1 | #include <sstream> |
---|---|
2 | #include "path_util.hpp" |
3 | #include "ostream_utility.hpp" |
4 | |
5 | void |
6 | extract_path_info(const fastuidraw::Path &path, |
7 | std::vector<fastuidraw::vec2> *out_pts, |
8 | std::vector<fastuidraw::vec2> *out_ctl_pts, |
9 | std::vector<fastuidraw::vec2> *out_arc_center_pts, |
10 | std::string *path_text) |
11 | { |
12 | using namespace fastuidraw; |
13 | |
14 | std::ostringstream str; |
15 | for (unsigned int c = 0, endc = path.number_contours(); c < endc; ++c) |
16 | { |
17 | reference_counted_ptr<const PathContour> C(path.contour(c)); |
18 | |
19 | if (C->closed()) |
20 | { |
21 | str << "[ "; |
22 | } |
23 | else |
24 | { |
25 | str << "{"; |
26 | } |
27 | |
28 | for (unsigned int e = 0, end_e = C->number_interpolators(); e < end_e; ++e) |
29 | { |
30 | reference_counted_ptr<const PathContour::interpolator_base> E(C->interpolator(e)); |
31 | const PathContour::arc *a; |
32 | const PathContour::bezier *b; |
33 | |
34 | out_pts->push_back(C->point(e)); |
35 | str << C->point(e) << " "; |
36 | |
37 | a = dynamic_cast<const PathContour::arc*>(E.get()); |
38 | b = dynamic_cast<const PathContour::bezier*>(E.get()); |
39 | if (a) |
40 | { |
41 | range_type<float> angle(a->angle()); |
42 | float delta_angle(angle.m_end - angle.m_begin); |
43 | |
44 | out_arc_center_pts->push_back(a->center()); |
45 | str << "arc "<< delta_angle * 180.0f / FASTUIDRAW_PI; |
46 | } |
47 | else if (b) |
48 | { |
49 | c_array<const vec2> pts; |
50 | |
51 | pts = b->pts().sub_array(1, b->pts().size() - 2); |
52 | str << "[["; |
53 | for (const vec2 &p : pts) |
54 | { |
55 | out_ctl_pts->push_back(p); |
56 | str << p << " "; |
57 | } |
58 | str << "]]"; |
59 | } |
60 | } |
61 | |
62 | if (C->closed()) |
63 | { |
64 | str << "]\n"; |
65 | } |
66 | else |
67 | { |
68 | str << C->point(C->number_points() - 1) << "}\n"; |
69 | } |
70 | } |
71 | *path_text = str.str(); |
72 | } |
73 |