Esempio n. 1
0
        public int GetStringWidth(string text)
        {
            if (text == null || text.Length <= 0)
            {
                return(0);
            }
            char[] charArray = text.ToCharArray();
            int    num1      = 0;
            int    num2      = 0;

            for (int index = 0; index < charArray.Length; ++index)
            {
                char ch = charArray[index];
                if ((int)ch >= 32 && (int)ch < 256)
                {
                    FontImage fontImage = this.m_Images[(int)ch - 32];
                    num1 += fontImage.xWidth;
                    if (num1 > num2)
                    {
                        num2 = num1;
                    }
                }
                else if ((int)ch == 10)
                {
                    num1 = 0;
                }
            }
            return(num2);
        }
Esempio n. 2
0
        unsafe Texture IFontFactory.CreateInstance(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(Texture.Empty);
            }
            int num1  = 0;
            int num2  = 0;
            int Width = 0;
            int num3  = 1;

            char[] charArray = text.ToCharArray();
            for (int index = 0; index < charArray.Length; ++index)
            {
                char ch = charArray[index];
                if ((int)ch >= 32 && (int)ch < 256)
                {
                    FontImage fontImage = this.m_Images[(int)ch - 32];
                    num2 += fontImage.xWidth;
                    if (num2 > Width)
                    {
                        Width = num2;
                    }
                    if (fontImage.yHeight > num1)
                    {
                        num1 = fontImage.yHeight;
                    }
                }
                else if ((int)ch == 10)
                {
                    num2 = 0;
                    ++num3;
                }
            }
            int Height = num3 * num1;

            if (Width <= 0 || Height <= 0)
                return(Texture.Empty); }
Esempio n. 3
0
        public unsafe Font(int fid)
        {
            this.m_FontID = fid;
            this.m_Cache  = new FontCache((IFontFactory)this);
            this.m_Images = new FontImage[224];
            string cachePath = Font.GetCachePath();

            if (!File.Exists(cachePath))
            {
                string str = Engine.FileManager.BasePath("data/ultima/cache/fonts.uoi");
                if (File.Exists(str))
                {
                    try
                    {
                        File.Move(str, cachePath);
                    }
                    catch
                    {
                        File.Copy(str, cachePath, false);
                    }
                }
                else
                {
                    Font.Reformat();
                }
            }
            FileStream   file         = new FileStream(cachePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryReader binaryReader = new BinaryReader((Stream)file);

            if (DateTime.FromFileTime(binaryReader.ReadInt64()) != new FileInfo(Engine.FileManager.ResolveMUL(Files.Fonts)).LastWriteTime)
            {
                binaryReader.Close();
                Font.Reformat();
                file         = new FileStream(cachePath, FileMode.Open, FileAccess.Read, FileShare.None);
                binaryReader = new BinaryReader((Stream)file);
            }
            file.Seek((long)(12 + fid * 8), SeekOrigin.Begin);
            int num1 = binaryReader.ReadInt32();
            int size = binaryReader.ReadInt32();

            file.Seek((long)num1, SeekOrigin.Begin);
            if (Font.m_Buffer == null || size > Font.m_Buffer.Length)
            {
                Font.m_Buffer = new byte[size];
                fixed(byte *numPtr1 = Font.m_Buffer)
                {
                    UnsafeMethods.ReadFile(file, (void *)numPtr1, size);
                    byte *numPtr2 = numPtr1;

                    for (int index = 0; index < 224; ++index)
                    {
                        int xWidth  = (int)*numPtr2;
                        int yHeight = (int)numPtr2[1];
                        numPtr2 += 3;
                        FontImage fontImage = new FontImage(xWidth, yHeight);
                        int       num2      = fontImage.xDelta;
                        fixed(byte *numPtr3 = fontImage.xyPixels)
                        {
                            IntPtr localPtr = (IntPtr)numPtr3;
                            int    num3     = 0;

                            while (num3 < yHeight)
                            {
                                int   num4    = 0;
                                byte *numPtr4 = (byte *)localPtr;
                                for (; num4 < xWidth; ++num4)
                                {
                                    *numPtr4++ = *numPtr2++;
                                }
                                ++num3;
                                localPtr += num2;
                            }
                        }

                        this.m_Images[index] = fontImage;
                    }
                    int    length  = *(int *)numPtr2;
                    short *numPtr5 = (short *)(numPtr2 + 4);

                    this.m_Palette = new short[length];
                    for (int index = 0; index < length; ++index)
                    {
                        this.m_Palette[index] = *numPtr5++;
                    }
                }

                binaryReader.Close();
        }