Beispiel #1
0
		void SetMathVariant(XElement mathVariant)
		{
			string name = mathVariant.Attribute("name").Value;
			string weight = mathVariant.Attributes("weight").FirstOrDefault() != null ? mathVariant.Attribute("weight").Value : "normal";
			string style = mathVariant.Attributes("style").FirstOrDefault() != null ? mathVariant.Attribute("style").Value : "normal";
			MathVariant mv = new MathVariant(name, weight, style);
			mathVariant.Attribute("family").Value.Split(',').Select(x => x.Trim()).ToList().ForEach(x=> mv.AddFamily(x));
			Variants.Add(name, mv);
		}
Beispiel #2
0
        private void SetMathVariant(XElement mathVariant)
        {
            string name   = mathVariant.Attribute("name").Value;
            string weight = mathVariant.Attributes("weight").FirstOrDefault() != null?mathVariant.Attribute("weight").Value : "normal";

            string style = mathVariant.Attributes("style").FirstOrDefault() != null?mathVariant.Attribute("style").Value : "normal";

            MathVariant mv = new MathVariant(name, weight, style);

            mathVariant.Attribute("family").Value.Split(',').Select(x => x.Trim()).ToList().ForEach(mv.AddFamily);
            Variants.Add(name, mv);
        }
Beispiel #3
0
        public static void DefaultContext(MathNode node)
        {
            if (node.Parent != null)
            {
                node.MathSize     = node.Parent.MathSize;
                node.FontSize     = node.Parent.FontSize;
                node.MetricList   = node.Parent.MetricList;
                node.ScriptLevel  = node.Parent.ScriptLevel;
                node.TightSpaces  = node.Parent.TightSpaces;
                node.DisplayStyle = node.Parent.DisplayStyle;
                node.Color        = node.Parent.Color;
                node.FontFamilies = node.Parent.FontFamilies;
                node.FontWeight   = node.Parent.FontWeight;
                node.FontStyle    = node.Parent.FontStyle;
                node.NodeDefaults = node.Parent.NodeDefaults;
                node.Parent.MakeChildContext(node);
            }
            else
            {
                node.MathSize     = node.ParseLength(node.NodeDefaults["mathsize"]);
                node.FontSize     = node.MathSize;
                node.MetricList   = null;
                node.ScriptLevel  = int.Parse(node.NodeDefaults["scriptlevel"]);
                node.TightSpaces  = false;
                node.DisplayStyle = (node.NodeDefaults["displaystyle"] == "true");
                node.Color        = node.NodeDefaults["mathcolor"];

                if (!node.Config.Variants.ContainsKey(node.NodeDefaults["mathvariant"]))
                {
                    throw new InvalidOperationException("Default mathvariant not defined in configuration file: configuration is unusable");
                }

                MathVariant defaultVariant = node.Config.Variants[node.NodeDefaults["mathvariant"]];
                node.FontWeight   = defaultVariant.Weight;
                node.FontStyle    = defaultVariant.Style;
                node.FontFamilies = defaultVariant.Families;
            }

            node.ProcessFontAttributes();
            node.Width        = 0;
            node.Height       = 0;
            node.Depth        = 0;
            node.Ascender     = 0;
            node.Descender    = 0;
            node.LeftSpace    = 0;
            node.RightSpace   = 0;
            node.AlignToAxis  = false;
            node.Base         = node;
            node.Core         = node;
            node.Stretchy     = false;
            node.Accent       = false;
            node.MoveLimits   = false;
            node.TextShift    = 0;
            node.TextStretch  = 1;
            node.LeftBearing  = 0;
            node.RightBearing = 0;
            node.IsSpace      = false;
            //Reset metrics list to None(so far, we used metrics from the parent)
            node.MetricList    = null;
            node.NominalMetric = null;
        }
Beispiel #4
0
        public void ProcessFontAttributes()
        {
            if (Attributes != null && Attributes.ContainsKey("displaystyle"))
            {
                DisplayStyle = (Attributes["displaystyle"] == "true");
            }

            string scriptlevelattr = null;

            if (Attributes != null && Attributes.ContainsKey("scriptlevel"))
            {
                scriptlevelattr = Attributes["scriptlevel"].Trim();
                if (scriptlevelattr.StartsWith("+"))
                {
                    ScriptLevel += int.Parse(scriptlevelattr.Substring(1));
                }
                else if (scriptlevelattr.StartsWith("-"))
                {
                    ScriptLevel -= int.Parse(scriptlevelattr.Substring(1));;
                }
                else
                {
                    ScriptLevel = int.Parse(scriptlevelattr);
                }
                ScriptLevel = Math.Max(ScriptLevel, 0);
            }

            if (Attributes != null && Attributes.ContainsKey("mathcolor"))
            {
                Color = Attributes["mathcolor"];
            }
            else if (Attributes != null && Attributes.ContainsKey("color"))
            {
                Color = Attributes["color"];
            }

            // Calculate font attributes
            if (Attributes != null && Attributes.ContainsKey("mathvariant"))
            {
                string mathvariantattr = Attributes["mathvariant"];
                if (!Config.Variants.ContainsKey(mathvariantattr))
                {
                    throw new InvalidOperationException(string.Format("Ignored mathvariant attribute: value '{0}' not defined in the font configuration file", mathvariantattr));
                }
                MathVariant mathvariant = Config.Variants[mathvariantattr];
                FontFamilies = mathvariant.Families;
                FontStyle    = mathvariant.Style;
                FontWeight   = mathvariant.Weight;
            }
            else
            {
                if (Attributes != null && Attributes.ContainsKey("fontfamily"))
                {
                    FontFamilies = Attributes["fontfamily"].Split(',').Select(x => x.Trim()).ToList();
                }
                if (Attributes != null && Attributes.ContainsKey("fontstyle"))
                {
                    FontStyle = Attributes["fontstyle"];
                }
                if (Attributes != null && Attributes.ContainsKey("fontweight"))
                {
                    FontWeight = Attributes["fontweight"];
                }
            }

            // Calculate font size
            string mathsizeattr = null;

            if (Attributes != null && Attributes.ContainsKey("mathsize"))
            {
                mathsizeattr = Attributes["mathsize"];
                double pLength = ParseLength(NodeDefaults["mathsize"]);
                switch (mathsizeattr)
                {
                case "normal":
                    MathSize = pLength;
                    break;

                case "big":
                    MathSize = pLength * 1.41;
                    break;

                case "small":
                    MathSize = pLength / 1.41;
                    break;

                default:
                    double mathsize = ParseLengthOrPercent(mathsizeattr, MathSize);
                    if (mathsize > 0)
                    {
                        MathSize = mathsize;
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format("Value of attribute 'mathsize' ignored - not a positive length: {0}", mathsizeattr));
                    }
                    break;
                }
            }

            FontSize = MathSize;

            if (ScriptLevel > 0)
            {
                double scriptsizemultiplier = double.Parse(NodeDefaults["scriptsizemultiplier"]);
                if (scriptsizemultiplier <= 0)
                {
                    throw new InvalidOperationException(string.Format("Bad inherited value of 'scriptsizemultiplier' attribute: {0}; using default value", mathsizeattr));
                }
                scriptsizemultiplier = double.Parse(MathDefaults.globalDefaults["scriptsizemultiplier"]);
                FontSize            *= Math.Pow(scriptsizemultiplier, ScriptLevel);
            }

            if (Attributes != null && Attributes.ContainsKey("fontsize") && mathsizeattr == null)
            {
                string fontsizeattr     = Attributes["fontsize"];
                double fontSizeOverride = ParseLengthOrPercent(fontsizeattr, FontSize);
                if (fontSizeOverride > 0)
                {
                    MathSize *= fontSizeOverride / FontSize;
                    FontSize  = fontSizeOverride;
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Value of attribute 'fontsize' ignored - not a positive length: {0}", fontsizeattr));
                }
            }

            double scriptminsize = ParseLength(NodeDefaults["scriptminsize"]);

            FontSize         = Math.Max(FontSize, scriptminsize);
            OriginalFontSize = FontSize;
        }