Skip to content

Commit

Permalink
Add MXF Decoder and MXF font test scene
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyDuchess committed Jun 20, 2024
1 parent 5dbfaa6 commit d39018b
Show file tree
Hide file tree
Showing 6 changed files with 446 additions and 460 deletions.
806 changes: 346 additions & 460 deletions Assets/Scenes/Tests/SkiaUITest.unity

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions Assets/Scripts/OpenTS2/Engine/Tests/MXFFontTest.cs
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;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/OpenTS2/Engine/Tests/MXFFontTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Scripts/OpenTS2/Files/Formats/Font.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions Assets/Scripts/OpenTS2/Files/Formats/Font/MXFFile.cs
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();
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/OpenTS2/Files/Formats/Font/MXFFile.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d39018b

Please sign in to comment.