Example #1
0
        protected override void UpdateWidthList(out List <Element> widths, float pixelsPerUnit)
        {
            widths = d_widthList;
            d_widthList.Clear();
            if (d_text.Length == 0)
            {
                return;
            }

            float unitsPerPixel = 1f / pixelsPerUnit;
            int   fontsize      = (int)(d_fontSize * pixelsPerUnit);

            size.x = 0;
            size.y = FontCache.GetLineHeight(d_font, fontsize, d_fontStyle) * unitsPerPixel;

            float wordSpacing            = owner.GetWordSpacing(d_font);
            Func <char, float> fontwidth = (char code) => { return((FontCache.GetAdvance(d_font, fontsize, d_fontStyle, code) + wordSpacing) * unitsPerPixel); };
            ElementSegment     es        = owner.elementSegment;

            if (es == null)
            {
                for (int i = 0; i < d_text.Length; ++i)
                {
                    var e = new Element(fontwidth(d_text[i]));
#if UNITY_EDITOR
                    e.text = "" + d_text[i];
#endif
                    widths.Add(e);
                }
            }
            else
            {
                es.Segment(d_text, widths, fontwidth);
            }

            for (int i = 0; i < d_widthList.Count; ++i)
            {
                size.x += d_widthList[i].totalwidth;
            }

            //size.x *= pixelsPerUnit;
            //size.y *= pixelsPerUnit;
        }
Example #2
0
 public override void fill(ref Vector2 currentpos, List <Line> lines, float maxWidth, float pixelsPerUnit)
 {
     height = FontCache.GetLineHeight(font, (int)(fontSize * pixelsPerUnit), fs) / pixelsPerUnit;
     lines.Add(new Line(new Vector2(NextLineX, height)));
 }