Ejemplo n.º 1
0
 static void Layout(StringEx str, ref TextGenerationSettings setting)
 {
     MaxChar = 0;
     MaxLine = 0;
     if (setting.richText)
     {
         if (str.HaveLabel)
         {
             lineInfo = new TextLineInfo();
             str.SplitLableString(setting.fontSize, setting.color, setting.fontStyle);
             var info = str.lableInfos;
             var cur  = setting;
             int s    = 0;
             for (int i = 0; i < info.Count; i++)
             {
                 cur.fontSize  = info[i].fontSize;
                 cur.color     = info[i].color;
                 cur.fontStyle = info[i].style;
                 var son = new StringEx(info[i].Text, false);
                 LayoutRichText(son, ref cur, s);
                 s += son.Length;
             }
             int end = str.meshInfo.lens.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++;
             }
         }
         else
         {
             LayoutText(str, ref setting);
         }
     }
     else
     {
         LayoutText(str, ref setting);
     }
 }
Ejemplo n.º 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++;
            }
        }
Ejemplo n.º 3
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++;
            }
        }