Пример #1
0
        /// <summary>
        /// 字符布局
        /// </summary>
        static void LayoutText(StringEx str, ref TextGenerationSettings setting)
        {
            int[] eles = str.noEmojiInfo.lens;
            if (eles == null)
            {
                return;
            }
            lineInfo = new TextLineInfo();
            var    font = setting.font;
            string full = str.FullString;
            string no   = str.noEmoji;

            font.RequestCharactersInTexture(no, setting.fontSize, setting.fontStyle);

            CharacterInfoEx info = new CharacterInfoEx();

            info.color = setting.color;
            CharUV uV = new CharUV();
            int    s  = 0;
            float  w  = setting.generationExtents.x;
            float  lw = 0;

            lineInfo.fontSize = setting.fontSize;
            for (int i = 0; i < eles.Length; i++)
            {
                int len = eles[i];
                if (no[i] == '\n')//行结束
                {
                    font.GetCharacterInfo(no[i], out info.info, setting.fontSize, setting.fontStyle);
                    info.type            = -3;
                    info.info.glyphWidth = 0;
                    info.info.advance    = 0;
                    lineInfo.CharEnd     = i - 1;
                    lineInfos[MaxLine]   = lineInfo;
                    MaxLine++;
                    lineInfo.CharStart = i;
                    lineInfo.minY      = 0;
                    lineInfo.maxY      = 0;
                    lw = 0;
                    s++;
                }
                else
                {
                    if (len == 1)
                    {
                        if (no[i] == ' ')
                        {
                            info.type = -2;
                        }
                        else
                        {
                            info.type = 0;
                        }
                        if (customFont != null)
                        {
                            if (customFont.GetCharacterInfo(no[i], ref info.info, setting.fontSize))
                            {
                                info.type = 1;
                            }
                            else
                            {
                                font.GetCharacterInfo(no[i], out info.info, setting.fontSize, setting.fontStyle);
                            }
                        }
                        else
                        {
                            font.GetCharacterInfo(no[i], out info.info, setting.fontSize, setting.fontStyle);
                        }
                    }
                    else
                    {
                        font.GetCharacterInfo('@', out info.info, setting.fontSize, setting.fontStyle);
                        int index = EmojiMap.FindEmojiInfo(full, s, len, ref uV);
                        if (index >= 0)
                        {
                            info.type = -1;
                            info.info.uvBottomLeft  = uV.uv3;
                            info.info.uvTopLeft     = uV.uv0;
                            info.info.uvTopRight    = uV.uv1;
                            info.info.uvBottomRight = uV.uv2;
                        }
                        else
                        {
                            info.type = 0;
                        }
                    }
                    if (setting.horizontalOverflow == HorizontalWrapMode.Wrap)
                    {
                        if (lw + info.info.advance > w)
                        {
                            lineInfo.CharEnd   = i - 1;
                            lineInfos[MaxLine] = lineInfo;
                            MaxLine++;
                            lineInfo.CharStart = i;
                            lineInfo.minY      = 0;
                            lineInfo.maxY      = 0;
                            lw = info.info.advance;
                        }
                        else
                        {
                            lw += info.info.advance;
                        }
                    }
                    else
                    {
                        lw += info.info.advance;
                    }
                    if (info.info.maxY > lineInfo.maxY)
                    {
                        lineInfo.maxY = info.info.maxY;
                    }
                    if (info.info.minY < lineInfo.minY)
                    {
                        lineInfo.minY = info.info.minY;
                    }
                    lineInfo.Width = lw;
                    s += len;
                }
                characters[MaxChar]          = info;
                characters[MaxChar].fontSize = setting.fontSize;
                characters[MaxChar].ch       = no[i];
                MaxChar++;
            }
            int end = eles.Length - 1;

            if (MaxLine > 0)
            {
                if (lineInfos[MaxLine - 1].CharEnd < end)
                {
                    lineInfo.CharEnd   = end;
                    lineInfos[MaxLine] = lineInfo;
                    MaxLine++;
                }
            }
            else
            {
                lineInfo.CharEnd   = end;
                lineInfos[MaxLine] = lineInfo;
                MaxLine++;
            }
        }
Пример #2
0
        static void LayoutText(String no, ref TextGenerationSettings setting)
        {
            MaxChar  = 0;
            MaxLine  = 0;
            lineInfo = new TextLineInfo();
            var font = setting.font;

            font.RequestCharactersInTexture(no, setting.fontSize, setting.fontStyle);
            CharacterInfoEx info = new CharacterInfoEx();

            info.color = setting.color;
            float w  = setting.generationExtents.x;
            float lw = 0;

            lineInfo.fontSize = setting.fontSize;
            for (int i = 0; i < no.Length; i++)
            {
                if (no[i] == '\n')//行结束
                {
                    font.GetCharacterInfo(no[i], out info.info, setting.fontSize, setting.fontStyle);
                    info.type          = 0;
                    lineInfo.CharEnd   = i - 1;
                    lineInfos[MaxLine] = lineInfo;
                    MaxLine++;
                    lineInfo.CharStart = i;
                    lineInfo.minY      = 0;
                    lineInfo.maxY      = 0;
                    lw = 0;
                }
                else
                {
                    if (no[i] == ' ')
                    {
                        info.type = -2;
                    }
                    else
                    {
                        info.type = 0;
                    }
                    if (customFont != null)
                    {
                        if (customFont.GetCharacterInfo(no[i], ref info.info, setting.fontSize))
                        {
                            info.type = 1;
                        }
                        else
                        {
                            font.GetCharacterInfo(no[i], out info.info, setting.fontSize, setting.fontStyle);
                        }
                    }
                    else
                    {
                        font.GetCharacterInfo(no[i], out info.info, setting.fontSize, setting.fontStyle);
                    }
                    if (setting.horizontalOverflow == HorizontalWrapMode.Wrap)
                    {
                        if (lw + info.info.advance > w)
                        {
                            lineInfo.CharEnd   = i - 1;
                            lineInfos[MaxLine] = lineInfo;
                            MaxLine++;
                            lw = info.info.advance;
                            lineInfo.CharStart = i;
                            lineInfo.minY      = 0;
                            lineInfo.minY      = 0;
                        }
                        else
                        {
                            lw += info.info.advance;
                        }
                    }
                    else
                    {
                        lw += info.info.advance;
                    }
                    if (info.info.maxY > lineInfo.maxY)
                    {
                        lineInfo.maxY = info.info.maxY;
                    }
                    if (info.info.minY < lineInfo.minY)
                    {
                        lineInfo.minY = info.info.minY;
                    }
                    lineInfo.Width = lw;
                }
                characters[MaxChar]          = info;
                characters[MaxChar].fontSize = setting.fontSize;
                characters[MaxChar].ch       = no[i];
                MaxChar++;
            }
            int end = no.Length - 1;

            if (MaxLine > 0)
            {
                if (lineInfos[MaxLine - 1].CharEnd < end)
                {
                    lineInfo.CharEnd   = end;
                    lineInfos[MaxLine] = lineInfo;
                    MaxLine++;
                }
            }
            else
            {
                lineInfo.CharEnd   = end;
                lineInfos[MaxLine] = lineInfo;
                MaxLine++;
            }
        }
Пример #3
0
        static void AddVertex(float lx, float rx, float dy, float ty, ref HVertex vertex, ref CharacterInfoEx info)
        {
            vertex.position.x = lx;
            vertex.position.y = dy;
            vertex.uv         = info.info.uvBottomLeft;
            vertices.Add(vertex);

            vertex.position.x = lx;
            vertex.position.y = ty;
            vertex.uv         = info.info.uvTopLeft;
            vertices.Add(vertex);

            vertex.position.x = rx;
            vertex.position.y = ty;
            vertex.uv         = info.info.uvTopRight;
            vertices.Add(vertex);

            vertex.position.x = rx;
            vertex.position.y = dy;
            vertex.uv         = info.info.uvBottomRight;
            vertices.Add(vertex);
        }