Esempio n. 1
0
        // lineX下一行的偏移量
        public virtual void fill(ref Vector2 currentpos, List <Line> lines, float maxWidth, float pixelsPerUnit)
        {
            NextLineX = d_nextLineX * pixelsPerUnit;
            List <Element> TempList;

            UpdateWidthList(out TempList, pixelsPerUnit);
            float height = getHeight();

            AlterX(ref currentpos.x, maxWidth);
            if (TempList.Count == 0)
            {
                return;
            }

            Around around    = owner.around;
            bool   isContain = false; // 当前行是否包含此元素

            for (int i = 0; i < TempList.Count;)
            {
                float totalwidth = TempList[i].totalwidth;
                float newx       = 0f;
                if (((currentpos.x + totalwidth) > maxWidth))
                {
                    currentpos = TempList[i].Next(this, currentpos, lines, maxWidth, NextLineX, height, around, totalwidth, ref isContain);
                    ++i;
                }
                else if (around != null && !around.isContain(currentpos.x, currentpos.y, totalwidth, height, out newx))
                {
                    // 放置不下了
                    currentpos.x = newx;
                }
                else
                {
                    currentpos.x += totalwidth;
                    isContain     = true;
                    ++i;
                }
            }

            Line bl = lines.back();

            bl.x = currentpos.x;
            bl.y = Mathf.Max(height, bl.y);

            if (d_bNewLine)
            {
                lines.Add(new Line(Vector2.zero));
                currentpos.y += height;
                currentpos.x  = NextLineX;
            }
        }
Esempio n. 2
0
            void DrawCurrent(bool isnewLine, Around around, float lineX)
            {
                if (sb.Length != 0)
                {
                    var  line      = lines[(int)yline];
                    Rect area_rect = new Rect(pt.x + alignedX, pt.y, x - pt.x + offsetX, node.getHeight());

                    cache.cacheText(line, node, sb.ToString(), area_rect);

                    sb.Remove(0, sb.Length);
                }

                if (isnewLine)
                {
                    // 再换行
                    yline++;
                    x = lineX;

                    pt.x = offsetX;
                    pt.y = offsetY;
                    for (int n = 0; n < yline; ++n)
                    {
                        pt.y += lines[n].y;
                    }

                    if (yline >= lines.Count)
                    {
                        --yline;
                        //Debug.LogError("yline >= vLineSize.Count!yline:" + yline + " vLineSize:" + lines.Count);
                    }

                    alignedX = AlignedFormatting(node.owner, xFormatting, maxWidth, lines[(int)(yline)].x, lineX);

                    float newx;
                    if (!around.isContain(pt.x + alignedX, pt.y, 1, node.getHeight(), out newx))
                    {
                        pt.x = newx - alignedX;
                        x    = pt.x;
                    }
                }
            }
Esempio n. 3
0
            public Vector2 Next(NodeBase n, Vector2 currentPos, List <Line> lines, float maxWidth, float lineX, float height, Around round, float tw, ref bool currentLineContain)
            {
                if (currentPos.x != 0f)
                {
                    Line bl = lines.back();
                    bl.x = currentPos.x;
                    if (currentLineContain)
                    {
                        bl.y = Mathf.Max(bl.y, height);
                    }

                    // 当前行有数据,在新行里处理
                    currentPos.x       = lineX;
                    currentPos.y      += bl.y;
                    currentLineContain = false;
                    lines.Add(new Line(new Vector2(lineX, 0)));
                }
                else
                {
                    // 当前行没有数据,直接在此行处理
                }

                if (round != null)
                {
                    float newx = 0f;
                    while (!round.isContain(currentPos.x, currentPos.y, tw, height, out newx))
                    {
                        currentPos.x = newx;
                        if (currentPos.x + tw > maxWidth)
                        {
                            currentPos.x = lineX;
                            lines.Add(new Line(new Vector2(lineX, height)));
                            currentPos.y += height;
                        }
                    }
                }

                if (widthList != null)
                {
                    for (int i = 0; i < widthList.Count; ++i)
                    {
                        currentPos = Add(n, currentPos, widthList[i], maxWidth, lineX, lines, height, ref currentLineContain);
                    }
                }
                else
                {
                    currentPos = Add(n, currentPos, totalWidth, maxWidth, lineX, lines, height, ref currentLineContain);
                }

                lines.back().x = currentPos.x;

                return(currentPos);
            }
Esempio n. 4
0
            void DrawCurrent(bool isnewLine, Around around)
            {
                if (node.owner.isArabic)
                {
                    if (sb.Length != 0)
                    {
                        float width     = pt.x - x - offsetX;
                        Rect  area_rect = new Rect(x - alignedX, pt.y, width, node.getHeight());

                        cache.cacheText(lines[(int)yline], node, sb.ToString(), area_rect);

                        sb.Remove(0, sb.Length);
                    }

                    if (isnewLine)
                    {
                        // 再换行
                        yline++;
                        x = maxWidth;

                        pt.x = x - offsetX;
                        pt.y = offsetY;
                        for (int n = 0; n < yline; ++n)
                        {
                            pt.y += lines[n].y;
                        }

                        if (yline >= lines.Count)
                        {
                            --yline;
                            //Debug.LogError("yline >= vLineSize.Count!yline:" + yline + " vLineSize:" + lines.Count);
                        }

                        float curentWidth = lines[(int)(yline)].x;
                        alignedX = AlignedFormatting(node.owner, xFormatting, maxWidth, curentWidth);
                        alignedX = maxWidth - (alignedX + curentWidth);

                        float newx;
                        if (!around.isContain(pt.x + alignedX, pt.y, 1, node.getHeight(), out newx, true))
                        {
                            pt.x = newx - alignedX;
                            x    = pt.x;
                        }
                    }
                }
                else
                {
                    if (sb.Length != 0)
                    {
                        Rect area_rect = new Rect(pt.x + alignedX, pt.y, x - pt.x + offsetX, node.getHeight());

                        cache.cacheText(lines[(int)yline], node, sb.ToString(), area_rect);

                        sb.Remove(0, sb.Length);
                    }

                    if (isnewLine)
                    {
                        // 再换行
                        yline++;
                        x = 0.0f;

                        pt.x = offsetX;
                        pt.y = offsetY;
                        for (int n = 0; n < yline; ++n)
                        {
                            pt.y += lines[n].y;
                        }

                        if (yline >= lines.Count)
                        {
                            --yline;
                            //Debug.LogError("yline >= vLineSize.Count!yline:" + yline + " vLineSize:" + lines.Count);
                        }

                        alignedX = AlignedFormatting(node.owner, xFormatting, maxWidth, lines[(int)(yline)].x);

                        float newx;
                        if (!around.isContain(pt.x + alignedX, pt.y, 1, node.getHeight(), out newx))
                        {
                            pt.x = newx - alignedX;
                            x    = pt.x;
                        }
                    }
                }
            }
Esempio n. 5
0
            public void Draw(TextNode n)
            {
                node = n;
                if (n.owner.isArabic)
                {
                    pt = new Vector2(x - offsetX, offsetY);
                    for (int i = 0; i < yline; ++i)
                    {
                        pt.y += lines[i].y;
                    }

                    if (maxWidth == 0)
                    {
                        return;
                    }

                    float curentWidth = lines[(int)(yline)].x;
                    alignedX = AlignedFormatting(n.owner, xFormatting, maxWidth, curentWidth);
                    alignedX = maxWidth - (alignedX + curentWidth);
                    fHeight  = node.getHeight();

                    sb.Remove(0, sb.Length);

                    Around around = n.owner.around;

                    int   textindex = node.d_text.Length - 1;
                    float newx      = maxWidth;
                    for (int k = node.d_widthList.Count - 1; k >= 0; --k)
                    {
                        Element e          = node.d_widthList[k];
                        float   totalwidth = e.totalwidth;
                        if ((x - totalwidth) < 0)
                        {
                            if (x != maxWidth)
                            {
                                DrawCurrent(true, around);
                            }

                            if (e.widths == null)
                            {
                                if ((x - e.totalwidth < 0))
                                {
                                    DrawCurrent(true, around);
                                }
                                else
                                {
                                    x -= e.totalwidth;
                                    sb.Insert(0, node.d_text[textindex--]);
                                }
                            }
                            else
                            {
                                for (int m = 0; m < e.widths.Count;)
                                {
                                    if (x != maxWidth && x - e.widths[m] < 0)
                                    {
                                        DrawCurrent(true, around);
                                    }
                                    else
                                    {
                                        x -= e.widths[m];
                                        sb.Insert(0, node.d_text[textindex--]);
                                        ++m;
                                    }
                                }
                            }
                        }
                        else if (!around.isContain(x, pt.y, totalwidth, fHeight, out newx, true))
                        {
                            DrawCurrent(false, around);

                            x    = newx;
                            pt.x = newx;
                            ++k;
                        }
                        else
                        {
                            int ec = e.count;
                            sb.Insert(0, node.d_text.Substring(textindex + 1 - ec, ec));
                            textindex -= ec;
                            x         -= totalwidth;
                        }
                    }

                    if (sb.Length != 0)
                    {
                        DrawCurrent(false, around);
                    }

                    if (node.d_bNewLine == true)
                    {
                        yline++;
                        x = maxWidth;
                    }
                }
                else
                {
                    pt = new Vector2(x + offsetX, offsetY);
                    for (int i = 0; i < yline; ++i)
                    {
                        pt.y += lines[i].y;
                    }

                    if (maxWidth == 0)
                    {
                        return;
                    }

                    alignedX = AlignedFormatting(n.owner, xFormatting, maxWidth, lines[(int)(yline)].x);
                    fHeight  = node.getHeight();

                    sb.Remove(0, sb.Length);

                    Around around = n.owner.around;

                    int   textindex = 0;
                    float newx      = 0f;
                    for (int k = 0; k < node.d_widthList.Count; ++k)
                    {
                        Element e          = node.d_widthList[k];
                        float   totalwidth = e.totalwidth;
                        if ((x + totalwidth) > maxWidth)
                        {
                            if (x != 0f)
                            {
                                DrawCurrent(true, around);
                            }

                            if (e.widths == null)
                            {
                                if ((x + e.totalwidth > maxWidth))
                                {
                                    DrawCurrent(true, around);
                                }
                                else
                                {
                                    x += e.totalwidth;
                                    sb.Append(node.d_text[textindex++]);
                                }
                            }
                            else
                            {
                                for (int m = 0; m < e.widths.Count;)
                                {
                                    if (x != 0 && x + e.widths[m] > maxWidth)
                                    {
                                        DrawCurrent(true, around);
                                    }
                                    else
                                    {
                                        x += e.widths[m];
                                        sb.Append(node.d_text[textindex++]);
                                        ++m;
                                    }
                                }
                            }
                        }
                        else if (!around.isContain(x, pt.y, totalwidth, fHeight, out newx))
                        {
                            DrawCurrent(false, around);

                            x    = newx;
                            pt.x = newx;
                            --k;
                        }
                        else
                        {
                            int ec = e.count;
                            sb.Append(node.d_text.Substring(textindex, ec));
                            textindex += ec;
                            x         += totalwidth;
                        }
                    }

                    if (sb.Length != 0)
                    {
                        DrawCurrent(false, around);
                    }

                    if (node.d_bNewLine == true)
                    {
                        yline++;
                        x = 0;
                    }
                }
            }