SVG Fixes to text positioning

This commit is contained in:
Thomas Krijnen
2021-04-29 16:16:41 +02:00
parent fd83564af0
commit 76685d236c
+14 -13
View File
@@ -1685,25 +1685,22 @@ 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;
trsf_view.SetTransformation(gp::XOY(), meta.pln_3d.Position());
v.Transform(trsf_view);
auto svg_name = nameElement(ann); auto svg_name = nameElement(ann);
path_object* po; path_object* po;
if (k.first) { if (k.first) {
po = &start_path(meta.pln_3d, k.first, svg_name); po = &start_path(meta.pln_3d, k.first, svg_name);
} } else {
else {
po = &start_path(meta.pln_3d, k.second, svg_name); po = &start_path(meta.pln_3d, k.second, svg_name);
} }
@@ -1723,23 +1720,28 @@ void SvgSerializer::addTextAnnotations(const drawing_key& k) {
} }
// @todo column or row? // @todo column or row?
double z_rotation = gp_Dir(trsf.HVectorialPart().Column(1)).AngleWithRef(gp_Dir(1., 0., 0.), gp_Dir(0., 0., 1.)); double z_rotation = gp::DX().Transformed(trsf).AngleWithRef(
meta.pln_3d.Position().XDirection(),
meta.pln_3d.Position().Direction()
);
z_rotation *= 180. / M_PI; z_rotation *= 180. / M_PI;
auto y = -v.Y();
util::string_buffer path; util::string_buffer path;
// dominant-baseline="central" is not well supported in IE. // dominant-baseline="central" is not well supported in IE.
// so we add a 0.35 offset to the dy of the tspans // so we add a 0.35 offset to the dy of the tspans
path.add(" <text text-anchor=\"left\" x=\""); path.add(" <text text-anchor=\"left\" x=\"");
xcoords.push_back(path.add(v.X())); xcoords.push_back(path.add(v.X()));
path.add("\" y=\""); path.add("\" y=\"");
ycoords.push_back(path.add(v.Y())); ycoords.push_back(path.add(y));
path.add("\" transform=\"rotate("); path.add("\" transform=\"rotate(");
path.add(z_rotation); path.add(z_rotation);
path.add(" "); path.add(" ");
xcoords.push_back(path.add(v.X())); xcoords.push_back(path.add(v.X()));
path.add(" "); path.add(" ");
ycoords.push_back(path.add(v.Y())); ycoords.push_back(path.add(y));
path.add(")\""); path.add(")\"");
if (font_size) { if (font_size) {
@@ -1775,7 +1777,6 @@ void SvgSerializer::addTextAnnotations(const drawing_key& k) {
} }
} }
} }
}
} }
void SvgSerializer::finalize() { void SvgSerializer::finalize() {