Пример #1
0
        /// <summary>
        /// Renders the theme command out.
        /// </summary>
        public void Render(ThemeContext context)
        {
            // Get the values
            float rx = x.GetValue(context);
            float ry = y.GetValue(context);

            // Get the font
            font = context.Theme.Fonts[fontName];

            // Figure out the string
            string output = text;
            string fmt = format;

            if (!String.IsNullOrEmpty(format) && variables != null)
            {
                // Create a format string instead
                object [] parms = new object [variables.Length];

                for (int i = 0; i < variables.Length; i++)
                {
                    // We need to do a bit of formatting to make these
                    // numbers as appropriate.
                    if (fmt.IndexOf("{" + i + ":N") >= 0)
                    {
                        // Convert to a double to make it a number
                        parms[i] = Convert.ToDouble(context[variables[i]]);
                    }
                    else if (fmt.IndexOf("{" + i + ":z") >= 0)
                    {
                        // This uses the zero fill rules
                        FormatZeroFill(i, ref fmt, context[variables[i]]);
                        parms[i] = 0;
                    }
                    else
                    {
                        // Just use it as a string
                        parms[i] = context[variables[i]].ToString();
                    }
                }

                // Format the string
                output = String.Format(fmt, parms);
            }

            // Render out the string
            font.Font.Print(output,
                color.GetColor(context),
                rx, ry,
                font.Alignment);
        }
Пример #2
0
        /// <summary>
        /// Reads font information into the system and prepares its
        /// use.
        /// </summary>
        private void ReadFont(XmlReader xml)
        {
            // Sanity checking
            if (String.IsNullOrEmpty(xml["id"]))
                throw new Exception("Cannot read font: id");
            if (String.IsNullOrEmpty(xml["size"]))
                throw new Exception("Cannot read font: size");
            if (String.IsNullOrEmpty(xml["align"]))
                throw new Exception("Cannot read font: align");
            if (String.IsNullOrEmpty(xml["file"]))
                throw new Exception("Cannot read font: file");

            // Pull out the parts
            string id = xml["id"];
            float size = Single.Parse(xml["size"]);
            ContentAlignment alignment = (ContentAlignment)
                Enum.Parse(typeof(ContentAlignment), xml["align"]);
            FileInfo file = new FileInfo(xml["file"]);

            // Create the font
            ThemeFont tf = new ThemeFont(id, size, alignment, file);
            fonts[id] = tf;
            Log.Info("Loaded theme font: {0}", id);
        }