GetQuadInfoForText() публичный Метод

public GetQuadInfoForText ( string text, FTextParams, textParams ) : FLetterQuadLine[],
text string
textParams FTextParams,
Результат FLetterQuadLine[],
Пример #1
0
    public void CreateTextQuads()
    {
        _doesTextNeedUpdate = false;

        int oldFacetsNeeded = _numberOfFacetsNeeded;

        _letterQuadLines = _font.GetQuadInfoForText(_text, _textParams);

        _numberOfFacetsNeeded = 0;

        int lineCount = _letterQuadLines.Length;

        for (int i = 0; i < lineCount; i++)
        {
            _numberOfFacetsNeeded += _letterQuadLines[i].quads.Length;
        }

        if (_isOnStage)
        {
            int delta = _numberOfFacetsNeeded - oldFacetsNeeded;

            if (delta != 0)            //if the number of letter quads has changed, tell the stage
            {
                _stage.HandleFacetsChanged();
            }
        }

        UpdateLocalPosition();         //figures out the bounds and alignment, and sets the mesh dirty
    }
Пример #2
0
        /// <summary>
        /// Checks how long pixels would the text take.
        /// <para>This is very costy in performance, so do not use this too much. See also <see cref="CharMean"/></para>
        /// </summary>
        /// <param name="text">Text you want to test</param>
        /// <param name="bigText">Whether the font is big variant or not</param>
        /// <returns>Text width in pxl</returns>
        public static float GetWidth(string text, bool bigText)
        {
            /*
             * if (!hasChecked) { return CharMean(bigText) * text.Length; }
             * MenuLabel l = !bigText ? tester : testerB;
             * l.text = text;
             * return l.label.textRect.width;*/

            FFont font  = Futile.atlasManager.GetFontWithName(GetFont(bigText, !HasNonASCIIChars(text)));
            float width = 0f;

            foreach (var item in font.GetQuadInfoForText(text, new FTextParams()))
            {
                width = Mathf.Max(width, item.bounds.width);
            }
            return(width);
        }
Пример #3
0
        /// <summary>
        /// Text wrapper by <c>dual curly potato noodles</c>
        /// </summary>
        /// <param name="text">Text you want to wrap</param>
        /// <param name="bigText">Whether the font is big variant or not</param>
        /// <param name="width">Pixel width</param>
        /// <returns></returns>
        public static string WrapText(this string text, bool bigText, float width, bool ascii = false)
        {
            FFont font = Futile.atlasManager.GetFontWithName(GetFont(bigText, ascii));

            string[]      lines = text.Replace("\r\n", "\n").Split('\n');
            StringBuilder ret   = new StringBuilder();

            for (int i = 0; i < lines.Length; i++)
            {
                ret.Append(WrapLine(lines[i]));
                if (i < lines.Length - 1)
                {
                    ret.Append('\n');
                }
            }
            return(ret.ToString());

            string WrapLine(string t)
            {
                StringBuilder r = new StringBuilder(t);

                List <FLetterQuad> quads = new List <FLetterQuad>();

                foreach (var item in font.GetQuadInfoForText(t, new FTextParams()))
                {
                    quads.AddRange(item.quads);
                    quads.Add(new FLetterQuad()
                    {
                        charInfo = new FCharInfo()
                    });                                                          // Placeholders for newlines
                }

                int lastStartLineIndex  = 0;
                int lastWhitespaceIndex = -1;

                for (int i = 0; i < t.Length; i++)
                {
                    void TrimWhitespace()
                    {
                        while (i < t.Length - 1 && t[i] != '\n' && char.IsWhiteSpace(t[i]))
                        {
                            i++;
                        }
                    }

                    var lineWidth = quads[i].rect.x + quads[i].rect.width - (quads[lastStartLineIndex].rect.x + quads[lastStartLineIndex].rect.width);

                    var curChar = r[i];
                    if (curChar == '\n')
                    {
                        TrimWhitespace(); // Trim line-ending whitespace
                        lastWhitespaceIndex = -1;
                        lastStartLineIndex  = i;
                        continue;
                    }

                    if (lineWidth < 0.01f)
                    {
                        TrimWhitespace(); // Trim line-starting whitespace
                    }
                    else if (char.IsWhiteSpace(curChar))
                    {
                        lastWhitespaceIndex = i;
                    }

                    if (lineWidth > width)
                    {
                        if (lastWhitespaceIndex == -1)
                        {
                            r.Insert(i + 1, '\n');
                        }
                        else
                        {
                            r.Insert(lastWhitespaceIndex + 1, '\n');
                            i = lastWhitespaceIndex;
                        }
                        continue;
                    }
                }
                return(r.ToString());
            }
        }