1 | // Aseprite |
---|---|
2 | // Copyright (C) 2016 David Capello |
3 | // |
4 | // This program is distributed under the terms of |
5 | // the End-User License Agreement for Aseprite. |
6 | |
7 | #ifdef HAVE_CONFIG_H |
8 | #include "config.h" |
9 | #endif |
10 | |
11 | #include "app/util/pixel_ratio.h" |
12 | |
13 | #include "base/split_string.h" |
14 | |
15 | #include <string> |
16 | #include <vector> |
17 | |
18 | namespace base { |
19 | |
20 | template<> |
21 | doc::PixelRatio convert_to(const std::string& from) |
22 | { |
23 | std::vector<std::string> parts; |
24 | split_string(from, parts, ":"); |
25 | doc::PixelRatio pixelRatio(1, 1); |
26 | |
27 | if (parts.size() == 2) { |
28 | pixelRatio.w = convert_to<int>(parts[0]); |
29 | pixelRatio.h = convert_to<int>(parts[1]); |
30 | pixelRatio.w = std::max(1, pixelRatio.w); |
31 | pixelRatio.h = std::max(1, pixelRatio.h); |
32 | } |
33 | |
34 | return pixelRatio; |
35 | } |
36 | |
37 | template<> |
38 | std::string convert_to(const doc::PixelRatio& from) |
39 | { |
40 | return (convert_to<std::string>(from.w) + ":"+ |
41 | convert_to<std::string>(from.h)); |
42 | } |
43 | |
44 | } // namespace base |
45 |