Exemple #1
0
        /// <summary>
        /// Takes a string of text and applies a texture to it.
        /// </summary>
        /// <param name="text">The text to texture.</param>
        /// <param name="font">The font of the text.</param>
        /// <param name="maxWidth">The maximum width of the text.</param>
        /// <param name="background">The background of the text. (default: none/null)</param>
        /// <param name="orientation">The orientation of the text. (default: left)</param>
        /// <returns>The texturized text.</returns>
        public LoadedTexture GenTextTexture(string text, CairoFont font, int maxWidth, TextBackground background = null, EnumTextOrientation orientation = EnumTextOrientation.Left)
        {
            if (background == null)
            {
                background = defaultBackground;
            }


            double fullTextWidth = 0;

            string[] lines = text.Split('\n');
            for (int i = 0; i < lines.Length; i++)
            {
                lines[i] = lines[i].TrimEnd();

                TextExtents textents = ((CairoFont)font).GetTextExtents(lines[i]);
                fullTextWidth = Math.Max(textents.Width, fullTextWidth);
            }

            int width = (int)Math.Min(maxWidth, fullTextWidth) + 2 * background.Padding;

            TextDrawUtil prober = new TextDrawUtil();
            double       height = prober.GetMultilineTextHeight(font as CairoFont, text, width) + 2 * background.Padding;

            return(GenTextTexture(text, font, width, (int)height + 1, background, orientation));
        }
 public double GetMultilineTextHeight()
 {
     return(textUtil.GetMultilineTextHeight(Font, text, Bounds.InnerWidth));
 }