-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MXF Decoder and MXF font test scene
- Loading branch information
1 parent
5dbfaa6
commit d39018b
Showing
6 changed files
with
446 additions
and
460 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using OpenTS2.Files; | ||
using OpenTS2.Files.Formats.Font; | ||
using OpenTS2.UI.Skia; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UnityEngine; | ||
|
||
namespace OpenTS2.Engine.Tests | ||
{ | ||
public class MXFFontTest : MonoBehaviour | ||
{ | ||
public string BaseGameFontToUse = ""; | ||
public SkiaLabel Label; | ||
|
||
private void Awake() | ||
{ | ||
var baseGamePath = Filesystem.GetDataPathForProduct(Content.ProductFlags.BaseGame); | ||
var fontPath = Path.Combine(baseGamePath, $"Res/UI/Fonts/{BaseGameFontToUse}"); | ||
var mxf = new MXFFile(fontPath); | ||
var font = new SkiaFont(mxf.DecodedData); | ||
Label.Font = font; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using UnityEngine; | ||
|
||
namespace OpenTS2.Files.Formats.Font | ||
{ | ||
/// <summary> | ||
/// Decodes Maxis font files (*.mxf), usually a wrapper for *.ttf or *.pfb fonts. | ||
/// </summary> | ||
public class MXFFile | ||
{ | ||
public byte[] DecodedData { get; private set; } | ||
|
||
public MXFFile(string filename) | ||
{ | ||
var fstream = new FileStream(filename, FileMode.Open); | ||
var reader = new BinaryReader(fstream); | ||
|
||
var magic = reader.ReadBytes(4); | ||
if (magic[0] != 77 || magic[1] != 88 || magic[2] != 70 || magic[3] != 78) | ||
throw new IOException("Not a valid Maxis Font File!"); | ||
|
||
reader.ReadInt32(); | ||
var mask = reader.ReadByte(); | ||
var len = fstream.Length; | ||
var memstream = new MemoryStream(); | ||
var writer = new BinaryWriter(memstream); | ||
while (fstream.Position != len) | ||
{ | ||
writer.Write((byte)(reader.ReadByte() ^ mask)); | ||
} | ||
writer.Flush(); | ||
DecodedData = memstream.ToArray(); | ||
writer.Dispose(); | ||
memstream.Dispose(); | ||
reader.Dispose(); | ||
fstream.Dispose(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.