public static void DrawSVGText(MathNode node, XElement output) { DrawBox(node, output); List <string> fontFamilies = node.FontPool().Where(x => x.Used == true).Select(x => x.Family).ToList(); if (fontFamilies.Count == 0) { fontFamilies = node.FontFamilies; } Dictionary <string, string> attrs = new Dictionary <string, string>() { { "fill", node.Color }, { "font-family", string.Join(", ", fontFamilies) }, { "font-size", string.Format(CultureInfo.InvariantCulture, "{0}", node.FontSize) }, { "text-anchor", "middle" }, { "x", string.Format(CultureInfo.InvariantCulture, "{0}", (node.Width + node.LeftBearing - node.RightBearing) / 2 / node.TextStretch) }, { "y", string.Format(CultureInfo.InvariantCulture, "{0}", -node.TextShift) } }; if (node.FontWeight != "normal") { attrs["font-weight"] = node.FontWeight; } if (node.FontStyle != "normal") { attrs["font-style"] = node.FontStyle; } if (node.TextStretch != 1) { attrs["transform"] = string.Format(CultureInfo.InvariantCulture, "scale({0}, 1)", node.TextStretch); } foreach (KeyValuePair <int, char> ch in MathDefaults.SpecialChars) { node.Text = node.Text.Replace((char)ch.Key, ch.Value); //ToDo: validate } XElement nxe = creatElement("text", attrs); XText chars = new XText(node.Text); nxe.Add(chars); output.Add(nxe); }
public static void DrawSVGText(MathNode node, XElement output) { DrawBox(node, output); List<string> fontFamilies = node.FontPool().Where(x => x.Used == true).Select(x => x.Family).ToList(); if (fontFamilies.Count == 0) fontFamilies = node.FontFamilies; Dictionary<string, string> attrs = new Dictionary<string, string>() { { "fill", node.Color }, { "font-family", string.Join(", ",fontFamilies) }, { "font-size", node.FontSize.ToString() }, { "text-anchor", "middle" }, { "x", string.Format("{0}",(node.Width + node.LeftBearing - node.RightBearing) / 2 / node.TextStretch)}, { "y", (-node.TextShift).ToString()} }; if (node.FontWeight != "normal") attrs["font-weight"] = node.FontWeight; if (node.FontStyle != "normal") attrs["font-style"] = node.FontStyle; if (node.TextStretch != 1) attrs["transform"] = string.Format("scale({0}, 1)", node.TextStretch); foreach (KeyValuePair<int, char> ch in MathDefaults.SpecialChars) { node.Text = node.Text.Replace((char)ch.Key, ch.Value); //ToDo: validate } XElement nxe = creatElement("text", attrs); XText chars = new XText(node.Text); nxe.Add(chars); output.Add(nxe); }