#include <msp/strings/format.h>
#include <msp/strings/utils.h>
#include "libr2c2/catalogue.h"
+#include "libr2c2/trackappearance.h"
#include "libr2c2/track.h"
#include "libr2c2/tracktype.h"
#include "svgexporter.h"
using namespace R2C2;
SvgExporter::SvgExporter(const Layout &l):
- layout(l),
- gauge(0)
+ layout(l)
{ }
void SvgExporter::save(const string &fn)
{
- gauge = layout.get_catalogue().get_gauge();
-
xmlpp::Document *doc = new xmlpp::Document;
root = doc->create_root_node("svg", "http://www.w3.org/2000/svg");
style->set_attribute("type", "text/css");
styles.push_back(".rail { fill: none; stroke: #000000; }");
styles.push_back(".border { fill: none; stroke: #808080; }");
- styles.push_back(format(".artnr { text-anchor: middle; font-family: sans; font-size: %.3f; }", gauge*750));
+ styles.push_back(".artnr { text-anchor: middle; font-family: sans; }");
defs = root->add_child("defs");
{
save_track(**i);
+ float gauge = (*i)->get_type().get_gauge();
unsigned n_endpoints = (*i)->get_type().get_endpoints().size();
for(unsigned j=0; j<n_endpoints; ++j)
{
minp = maxp = pos;
else
{
- minp.x = min(minp.x, pos.x);
- minp.y = min(minp.y, pos.y);
- maxp.x = max(maxp.x, pos.x);
- maxp.y = max(maxp.y, pos.y);
+ minp.x = min(minp.x, pos.x-gauge*3);
+ minp.y = min(minp.y, pos.y-gauge*3);
+ maxp.x = max(maxp.x, pos.x+gauge*3);
+ maxp.y = max(maxp.y, pos.y+gauge*3);
}
}
}
style->set_child_text(join(styles.begin(), styles.end(), "\n"));
root->set_attribute("viewBox", format("%.3f %.3f %.3f %.3f",
- minp.x*1000-gauge*3, -maxp.y*1000-gauge*3, (maxp.x-minp.x)*1000+gauge*6, (maxp.y-minp.y)*1000+gauge*6));
+ minp.x*1000, -maxp.y*1000, (maxp.x-minp.x)*1000, (maxp.y-minp.y)*1000));
doc->write_to_file_formatted(fn);
}
string SvgExporter::create_appearance(const TrackAppearance &appearance)
{
- string key = format("a%p", &appearance);
+ float gauge = appearance.get_gauge();
+ string key = format("a%.0f", gauge*1000);
if(!appearances_created.count(&appearance))
{
styles.push_back(format(".%s .rail { stroke-width: %.3f }", key, rail_width*1000));
styles.push_back(format(".%s .border { stroke-width: %.3f }", key, rail_width*500));
+ styles.push_back(format(".%s .artnr { font-size: %.3f }", key, gauge*750));
appearances_created.insert(&appearance);
}
group->set_attribute("id", key);
group->set_attribute("class", appearance_key);
+ float gauge = appearance.get_gauge();
float rail_width = appearance.get_rail_profile().get_width();
const vector<TrackType::Endpoint> &endpoints = type.get_endpoints();