mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
SVG Fixes to text positioning
This commit is contained in:
@@ -1685,91 +1685,92 @@ void SvgSerializer::addTextAnnotations(const drawing_key& k) {
|
|||||||
gp_Trsf trsf;
|
gp_Trsf trsf;
|
||||||
if (kernel.convert_placement(*pl, trsf)) {
|
if (kernel.convert_placement(*pl, trsf)) {
|
||||||
|
|
||||||
auto v = trsf.TranslationPart();
|
auto v = gp_Pnt(trsf.TranslationPart());
|
||||||
if (k.first) {
|
|
||||||
v.ChangeCoord(1) *= -1.;
|
|
||||||
trsf.SetTranslationPart(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @todo Inverted?
|
|
||||||
auto z_local = gp::DZ().Transformed(trsf);
|
auto z_local = gp::DZ().Transformed(trsf);
|
||||||
auto view_dir = z_local.Dot(meta.pln_3d.Axis().Direction());
|
auto view_dir = z_local.Dot(meta.pln_3d.Axis().Direction());
|
||||||
|
|
||||||
if ((!range || (v.Z() >= range->first && v.Z() < range->second)) && view_dir > 0.99) {
|
if ((!range || (v.Z() >= range->first && v.Z() < range->second)) && view_dir > 0.99) {
|
||||||
|
|
||||||
if (meta.pln_3d.Position().Direction().Dot(gp_Dir(trsf.HVectorialPart().Column(3))) > 0.99) {
|
gp_Trsf trsf_view;
|
||||||
auto svg_name = nameElement(ann);
|
trsf_view.SetTransformation(gp::XOY(), meta.pln_3d.Position());
|
||||||
path_object* po;
|
v.Transform(trsf_view);
|
||||||
if (k.first) {
|
|
||||||
po = &start_path(meta.pln_3d, k.first, svg_name);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
po = &start_path(meta.pln_3d, k.second, svg_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (object_type.size()) {
|
auto svg_name = nameElement(ann);
|
||||||
// postfix the object_type for CSS matching
|
path_object* po;
|
||||||
boost::replace_all(svg_name, "class=\"IfcAnnotation\"", "class=\"IfcAnnotation " + object_type + "\"");
|
if (k.first) {
|
||||||
}
|
po = &start_path(meta.pln_3d, k.first, svg_name);
|
||||||
|
} else {
|
||||||
boost::optional<double> font_size;
|
po = &start_path(meta.pln_3d, k.second, svg_name);
|
||||||
std::vector<std::string> tokens;
|
|
||||||
boost::split(tokens, name, boost::is_any_of("_"));
|
|
||||||
if (tokens.size() == 2) {
|
|
||||||
try {
|
|
||||||
font_size = boost::lexical_cast<double>(tokens.back());
|
|
||||||
}
|
|
||||||
catch (...) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// @todo column or row?
|
|
||||||
double z_rotation = gp_Dir(trsf.HVectorialPart().Column(1)).AngleWithRef(gp_Dir(1., 0., 0.), gp_Dir(0., 0., 1.));
|
|
||||||
z_rotation *= 180. / M_PI;
|
|
||||||
|
|
||||||
util::string_buffer path;
|
|
||||||
// dominant-baseline="central" is not well supported in IE.
|
|
||||||
// so we add a 0.35 offset to the dy of the tspans
|
|
||||||
path.add(" <text text-anchor=\"left\" x=\"");
|
|
||||||
xcoords.push_back(path.add(v.X()));
|
|
||||||
path.add("\" y=\"");
|
|
||||||
ycoords.push_back(path.add(v.Y()));
|
|
||||||
|
|
||||||
path.add("\" transform=\"rotate(");
|
|
||||||
path.add(z_rotation);
|
|
||||||
path.add(" ");
|
|
||||||
xcoords.push_back(path.add(v.X()));
|
|
||||||
path.add(" ");
|
|
||||||
ycoords.push_back(path.add(v.Y()));
|
|
||||||
path.add(")\"");
|
|
||||||
|
|
||||||
if (font_size) {
|
|
||||||
path.add(" font-size=\"");
|
|
||||||
path.add(*font_size);
|
|
||||||
path.add("\"");
|
|
||||||
}
|
|
||||||
path.add(">");
|
|
||||||
|
|
||||||
std::vector<std::string> labels{ desc };
|
|
||||||
|
|
||||||
for (auto lit = labels.begin(); lit != labels.end(); ++lit) {
|
|
||||||
const auto& l = *lit;
|
|
||||||
double dy = labels.begin() == lit
|
|
||||||
? 0.0 // align bottom
|
|
||||||
: 1.0; // <- dy is relative to the previous text element, so
|
|
||||||
// always 1 for successive spans.
|
|
||||||
path.add("<tspan x=\"");
|
|
||||||
xcoords.push_back(path.add(v.X()));
|
|
||||||
path.add("\" dy=\"");
|
|
||||||
path.add(boost::lexical_cast<std::string>(dy));
|
|
||||||
path.add("em\">");
|
|
||||||
path.add(l);
|
|
||||||
path.add("</tspan>");
|
|
||||||
}
|
|
||||||
|
|
||||||
path.add("</text>");
|
|
||||||
|
|
||||||
po->second.push_back(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (object_type.size()) {
|
||||||
|
// postfix the object_type for CSS matching
|
||||||
|
boost::replace_all(svg_name, "class=\"IfcAnnotation\"", "class=\"IfcAnnotation " + object_type + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::optional<double> font_size;
|
||||||
|
std::vector<std::string> tokens;
|
||||||
|
boost::split(tokens, name, boost::is_any_of("_"));
|
||||||
|
if (tokens.size() == 2) {
|
||||||
|
try {
|
||||||
|
font_size = boost::lexical_cast<double>(tokens.back());
|
||||||
|
}
|
||||||
|
catch (...) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @todo column or row?
|
||||||
|
double z_rotation = gp::DX().Transformed(trsf).AngleWithRef(
|
||||||
|
meta.pln_3d.Position().XDirection(),
|
||||||
|
meta.pln_3d.Position().Direction()
|
||||||
|
);
|
||||||
|
z_rotation *= 180. / M_PI;
|
||||||
|
|
||||||
|
auto y = -v.Y();
|
||||||
|
|
||||||
|
util::string_buffer path;
|
||||||
|
// dominant-baseline="central" is not well supported in IE.
|
||||||
|
// so we add a 0.35 offset to the dy of the tspans
|
||||||
|
path.add(" <text text-anchor=\"left\" x=\"");
|
||||||
|
xcoords.push_back(path.add(v.X()));
|
||||||
|
path.add("\" y=\"");
|
||||||
|
ycoords.push_back(path.add(y));
|
||||||
|
|
||||||
|
path.add("\" transform=\"rotate(");
|
||||||
|
path.add(z_rotation);
|
||||||
|
path.add(" ");
|
||||||
|
xcoords.push_back(path.add(v.X()));
|
||||||
|
path.add(" ");
|
||||||
|
ycoords.push_back(path.add(y));
|
||||||
|
path.add(")\"");
|
||||||
|
|
||||||
|
if (font_size) {
|
||||||
|
path.add(" font-size=\"");
|
||||||
|
path.add(*font_size);
|
||||||
|
path.add("\"");
|
||||||
|
}
|
||||||
|
path.add(">");
|
||||||
|
|
||||||
|
std::vector<std::string> labels{ desc };
|
||||||
|
|
||||||
|
for (auto lit = labels.begin(); lit != labels.end(); ++lit) {
|
||||||
|
const auto& l = *lit;
|
||||||
|
double dy = labels.begin() == lit
|
||||||
|
? 0.0 // align bottom
|
||||||
|
: 1.0; // <- dy is relative to the previous text element, so
|
||||||
|
// always 1 for successive spans.
|
||||||
|
path.add("<tspan x=\"");
|
||||||
|
xcoords.push_back(path.add(v.X()));
|
||||||
|
path.add("\" dy=\"");
|
||||||
|
path.add(boost::lexical_cast<std::string>(dy));
|
||||||
|
path.add("em\">");
|
||||||
|
path.add(l);
|
||||||
|
path.add("</tspan>");
|
||||||
|
}
|
||||||
|
|
||||||
|
path.add("</text>");
|
||||||
|
|
||||||
|
po->second.push_back(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user