This project is read-only.

Chinese Characters

Jun 28, 2010 at 10:11 AM

Hi, Tom, It's really a great work!!

Sorry for my poor English.

The only way to display Chinese is to set the charMap of FontSprite, but if there are a lot of characters to show, There is something wrong of calculating the Heights of charMap  in the file FontSprite.cs :

private int CalculateIdealBitmapHeight(int width)
        {
            int charHeight = CharHeight;
            int x = 0;
            int y = 0;

            int trail = LeadingSpace + TrailingSpace;
            width -= trail;
            for (int i = StartCharIndex; i <= EndCharIndex; i++)
            {
                int charWidth = CharacterWidth((char)i);
                if ((x + charWidth) >= width)
                {
                    x = 0;
                    y += charHeight;
                }

                x += charWidth + trail;
            }
            return y;
            // return TextureUtil.ConvertToValidTextureDimension(y);
        }

should be changed to :

private int CalculateIdealBitmapHeight(int width)
        {
            int charHeight = CharHeight;
            int x = 0;
            int y = 0;

            int trail = LeadingSpace + TrailingSpace;
            width -= trail;
            //for (int i = StartCharIndex; i <= EndCharIndex; i++)
            //{
            //    int charWidth = CharacterWidth((char)i);
            //    if ((x + charWidth) >= width)
            //    {
            //        x = 0;
            //        y += charHeight;
            //    }

            //    x += charWidth + trail;
            //}
            foreach (char c in charWidths.Keys)
            {
                int charWidth = charWidths[c];
                if (x + charWidth >= width)
                {
                    x = 0;
                    y += charHeight;
                }
                x += charWidth + trail;
            }
            return y;
        }

Because the MaxTextureSize of device is limited, the Max count of Chinese characters which can be displayed is less than 1,000.

this solution is not efficient and practical. Can you give some hints to solve this problem?

Jun 28, 2010 at 6:06 PM

you can use images to display text. Create a texture and use texture.CreateGraphics to render the text with gdi.

just create a ChineseStringShape that does so and replace the Shape operator to convert a string to use that class instead of StringShape and most all conrols (except label) will use this shape by default.

 

 
Jun 30, 2010 at 7:36 AM

Thanks Tom, I tried it ,But nothing to display. Could you give me some example code when you have time? Thanks again.