public int GetStringWidth(string text) { if ((text == null) || (text.Length <= 0)) { return(0); } char[] chArray = text.ToCharArray(); int num = 0; int num2 = 0; for (int i = 0; i < chArray.Length; i++) { char ch = chArray[i]; if ((ch >= ' ') && (ch < 'Ā')) { FontImage image = this.m_Images[ch - ' ']; num += image.xWidth; if (num > num2) { num2 = num; } } else if (ch == '\n') { num = 0; } } return(num2); }
public unsafe Font(int fid) { this.m_FontID = fid; this.m_Cache = new FontCache(this); this.m_Images = new FontImage[0xe0]; string path = Engine.FileManager.BasePath("Data/QuickLoad/Fonts.mul"); if (!File.Exists(path)) { Reformat(); } FileStream input = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryReader reader = new BinaryReader(input); if (DateTime.FromFileTime(reader.ReadInt64()) != new FileInfo(Engine.FileManager.ResolveMUL(Files.Fonts)).LastWriteTime) { reader.Close(); Reformat(); input = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None); reader = new BinaryReader(input); } input.Seek((long)(12 + (fid * 8)), SeekOrigin.Begin); int num = reader.ReadInt32(); int bytes = reader.ReadInt32(); input.Seek((long)num, SeekOrigin.Begin); if ((m_Buffer == null) || (bytes > m_Buffer.Length)) { m_Buffer = new byte[bytes]; } fixed(byte *numRef = m_Buffer) { Engine.NativeRead(input, (void *)numRef, bytes); byte *numPtr = numRef; for (int i = 0; i < 0xe0; i++) { int xWidth = numPtr[0]; int yHeight = numPtr[1]; numPtr += 3; FontImage image = new FontImage(xWidth, yHeight); int xDelta = image.xDelta; fixed(byte *numRef2 = image.xyPixels) { byte *numPtr2 = numRef2; int num7 = 0; while (num7 < yHeight) { int num6 = 0; byte *numPtr3 = numPtr2; while (num6 < xWidth) { *(numPtr3++) = *(numPtr++); num6++; } num7++; numPtr2 += xDelta; } } this.m_Images[i] = image; } int num9 = *((int *)numPtr); numPtr += 4; short *numPtr4 = (short *)numPtr; this.m_Palette = new short[num9]; for (int j = 0; j < num9; j++) { numPtr4++; this.m_Palette[j] = numPtr4[0]; } numPtr = (byte *)numPtr4; } reader.Close(); }
public unsafe Font(int fid) { this.m_FontID = fid; this.m_Cache = new FontCache(this); this.m_Images = new FontImage[0xe0]; string path = Engine.FileManager.BasePath("Data/QuickLoad/Fonts.mul"); if (!File.Exists(path)) { Reformat(); } FileStream input = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryReader reader = new BinaryReader(input); if (DateTime.FromFileTime(reader.ReadInt64()) != new FileInfo(Engine.FileManager.ResolveMUL(Files.Fonts)).LastWriteTime) { reader.Close(); Reformat(); input = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None); reader = new BinaryReader(input); } input.Seek((long) (12 + (fid * 8)), SeekOrigin.Begin); int num = reader.ReadInt32(); int bytes = reader.ReadInt32(); input.Seek((long) num, SeekOrigin.Begin); if ((m_Buffer == null) || (bytes > m_Buffer.Length)) { m_Buffer = new byte[bytes]; } fixed (byte* numRef = m_Buffer) { Engine.NativeRead(input, (void*) numRef, bytes); byte* numPtr = numRef; for (int i = 0; i < 0xe0; i++) { int xWidth = numPtr[0]; int yHeight = numPtr[1]; numPtr += 3; FontImage image = new FontImage(xWidth, yHeight); int xDelta = image.xDelta; fixed (byte* numRef2 = image.xyPixels) { byte* numPtr2 = numRef2; int num7 = 0; while (num7 < yHeight) { int num6 = 0; byte* numPtr3 = numPtr2; while (num6 < xWidth) { *(numPtr3++) = *(numPtr++); num6++; } num7++; numPtr2 += xDelta; } } this.m_Images[i] = image; } int num9 = *((int*) numPtr); numPtr += 4; short* numPtr4 = (short*) numPtr; this.m_Palette = new short[num9]; for (int j = 0; j < num9; j++) { numPtr4++; this.m_Palette[j] = numPtr4[0]; } numPtr = (byte*) numPtr4; } reader.Close(); }