This project is read-only.

how to use chinese character?

Mar 27, 2011 at 11:04 AM
Edited Mar 27, 2011 at 11:07 AM

 how to use chinese character?please give a sample!Thanks!

Please help me!

 

----------------------------------------------------

请问哪位兄弟能够用Silvermoon显示中文字符啊?给个例子吧。

Jul 19, 2011 at 9:07 AM

一个笨办法,能显示中文,但效率不是太好,每次有新中文加入时都要重画,待以后慢慢解决。

我的QQ:64563177

FontSprite类中增加

  
       public void CheckCharData(string str, int pos, int end) //hqm
        {
            StringBuilder addStr = new StringBuilder();
            for (int i = pos; i < end; i++)
            {
                char c = str[i];
                if (!Characters.ContainsKey(c))
                {
                    addStr.Append(c);
                }
            }
            if (addStr.Length >0)
            {
                using (Font renderFont = new Font(Name, Size, Style))
                {
                    GetFontMetrics(renderFont, addStr.ToString());
                    texture = new Texture();
                    RenderBitmapAndFillCharArray(texture, renderFont);
                }
            }
        }

在TextSprite类中修改函数LayoutCharacters,标注hqm部份
        protected virtual void LayoutCharacters()
        {
            visibleChars = 0;
            Size size = GetScaledSize();

            bool measure = (lineMode & LineMode.EndEllipsis) != 0;
            int clipWidth = measure ? size.Width : int.MaxValue;
            int clipHeight = measure ? size.Height : int.MaxValue;

            textureSize = Font.TextureSize;

            int n = text.Length;
            if (rebuild == false) rebuild = textureMap == null || textureMap.Length != n || visibleChars != n;

            if (indexes == null || indexes.Length / 6 < (n + ellipsisCharacters)) BuildIndexes(n + ellipsisCharacters);
            if (rebuild)
            {
                textureMap = new VectorQuad2i[n];
                vertexMap = new VectorQuads[n];
            }

            FontSprite font = Font;
            int h = font.CharHeight;
            int y = 0;
            int wMax = 0;

            int pos = 0;
            bool multiLine = (lineMode & LineMode.MultiLine) != 0;
            while (pos < n)
            {
                int end = multiLine ? GetLineEnd(pos, clipWidth) : n;
                if (end == pos) end++;
                int x = alignment != Alignment.Near ? GetStartXFromAlignment(size.Width, pos, end) : 0;
                if (rebuild)
                {
                    font.CheckCharData(text, pos, end); //hqm
                }
                for (int i = pos; i < end; i++)
                {
                    char c = text[i];
                    var cd = font.GetCharData(c);
                    vertexMap[i].SetChar(x, y, cd.Width, h, skew);

                    if (rebuild)
                    {
                        SetTexture(i, cd, h);
                    }
                    if (!(i == end - 1 && IsSpace(c)))
                    {
                        x += cd.Width + charSpace;
                    }
                    if (!multiLine)
                    {
                        if ((x - charSpace) <= size.Width) visibleChars = i + 1;
                    }
                }
                wMax = Math.Max(x, wMax);
                pos = end;
                if (multiLine)
                {
                    if ((y + h) <= clipHeight) visibleChars = pos;
                    y += h;
                }
            }
            if (multiLine && pos > 0 && text[pos - 1] == '\n') y += h;
            if (lineMode == LineMode.EndEllipsis && wMax > clipWidth)
            {
                wMax = AddEllipsis(visibleChars, clipWidth, h);
            }

            wMax += 1;
            textSize = Unscale(new Size(wMax, Math.Max(y + 1, h)));
            rebuild = false;
        }