Skip to content

Commit 798e84e

Browse files
authored
fix: guide lines ignored on loading from old files (synfig#3303)
Due to the awesome changes in b172e37 (synfig#2777)
1 parent 0fa608d commit 798e84e

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

synfig-core/src/synfig/loadcanvas.cpp

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,35 @@ std::set<FileSystem::Identifier> CanvasParser::loading_;
103103

104104
/* === P R O C E D U R E S ================================================= */
105105

106+
// Guide lines storage changed:
107+
// Before:
108+
// guide_x -> list of X positions of vertical guide lines (separated by spaces)
109+
// guide_y -> list of Y positions of horizontal guide lines (separated by spaces)
110+
// Now:
111+
// guide -> list of X*Y*radian-angle coordinates of guide lines (data from same guide is separated by star *) (items separated by spaces)
112+
static void
113+
upgrade_guide_metadata(std::string& content, const std::string& metadata, bool is_x_guide)
114+
{
115+
std::string new_content;
116+
std::istringstream iss(content);
117+
std::string item;
118+
while (std::getline(iss, item, ' ')) {
119+
if (!item.empty()) {
120+
if (is_x_guide) {
121+
// X * 0 * PI/2 radians -> vertical guide line
122+
new_content += item + "*0*1.57079633 ";
123+
} else {
124+
// 0 * Y * 0 radians -> horizontal guide line
125+
new_content += "0*" + item + "*0 ";
126+
}
127+
}
128+
}
129+
// new_content already has a blank space appended
130+
content = new_content + metadata;
131+
if (content.back() == ' ')
132+
content.pop_back();
133+
}
134+
106135
OpenCanvasMap& synfig::get_open_canvas_map()
107136
{
108137
static OpenCanvasMap open_canvas_map_;
@@ -3331,6 +3360,9 @@ CanvasParser::parse_canvas(xmlpp::Element *element,Canvas::Handle parent,bool in
33313360
continue;
33323361
}
33333362

3363+
std::string meta_name = child->get_attribute("name")->get_value();
3364+
std::string content = child->get_attribute("content")->get_value();
3365+
33343366
// In Synfig prior to version 1.0 we have messed decimal separator:
33353367
// some files use ".", but other ones use ","/
33363368
// Let's try to put a workaround for that.
@@ -3341,9 +3373,7 @@ CanvasParser::parse_canvas(xmlpp::Element *element,Canvas::Handle parent,bool in
33413373
replacelist.push_back("grid_color");
33423374
replacelist.push_back("grid_size");
33433375
replacelist.push_back("jack_offset");
3344-
String content;
3345-
content=child->get_attribute("content")->get_value();
3346-
if(std::find(replacelist.begin(), replacelist.end(), child->get_attribute("name")->get_value()) != replacelist.end())
3376+
if(std::find(replacelist.begin(), replacelist.end(), meta_name) != replacelist.end())
33473377
{
33483378
size_t index = 0;
33493379
while (true) {
@@ -3359,7 +3389,19 @@ CanvasParser::parse_canvas(xmlpp::Element *element,Canvas::Handle parent,bool in
33593389
}
33603390

33613391
}
3362-
canvas->set_meta_data(child->get_attribute("name")->get_value(),content);
3392+
3393+
// Commit b172e37 (#2777) changed guide lines storage to give them rotation ability
3394+
if (meta_name == "guide_x") {
3395+
upgrade_guide_metadata(content, canvas->get_meta_data("guide"), true);
3396+
meta_name = "guide";
3397+
}
3398+
3399+
if (meta_name == "guide_y") {
3400+
upgrade_guide_metadata(content, canvas->get_meta_data("guide"), false);
3401+
meta_name = "guide";
3402+
}
3403+
3404+
canvas->set_meta_data(meta_name, content);
33633405
}
33643406
else if(child->get_name()=="name")
33653407
{

0 commit comments

Comments
 (0)