Skip to content

Commit

Permalink
Add new chars to FTB
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHeitmann committed Jun 30, 2024
1 parent ee89585 commit 99195a5
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 94 deletions.
2 changes: 1 addition & 1 deletion assets/FontAtlasGenerator
14 changes: 10 additions & 4 deletions lib/fileTypeUtils/ftb/ftbIO.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import '../utils/ByteDataWrapper.dart';

class FtbFileHeader {
List<int> magic;
List<int> start;
int globalKerning;
int null0;
int texturesCount;
int unknown;
int charsCount;
int texturesOffset;
int charsOffset;
int charsOffset2;

FtbFileHeader(this.magic, this.texturesCount, this.unknown, this.charsCount, this.texturesOffset, this.charsOffset, this.charsOffset2);
FtbFileHeader(this.start, this.globalKerning, this.null0, this.texturesCount, this.unknown, this.charsCount, this.texturesOffset, this.charsOffset, this.charsOffset2);

FtbFileHeader.read(ByteDataWrapper bytes) :
magic = bytes.readUint8List(118),
start = bytes.readUint8List(114),
globalKerning = bytes.readInt16(),
null0 = bytes.readUint16(),
texturesCount = bytes.readUint16(),
unknown = bytes.readUint16(),
charsCount = bytes.readUint16(),
Expand All @@ -21,8 +25,10 @@ class FtbFileHeader {
charsOffset2 = bytes.readUint32();

void write(ByteDataWrapper bytes) {
for (var b in magic)
for (var b in start)
bytes.writeUint8(b);
bytes.writeInt16(globalKerning);
bytes.writeUint16(null0);
bytes.writeUint16(texturesCount);
bytes.writeUint16(unknown);
bytes.writeUint16(charsCount);
Expand Down
2 changes: 2 additions & 0 deletions lib/fileTypeUtils/textures/ddsConverter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Future<void> pngToDds(String ddsPath, String pngPath) async {
[pngPath, "-define", "dds:mipmaps=0", ddsPath]
);
if (result.exitCode != 0) {
messageLog.add("stdout: ${result.stdout}");
messageLog.add("stderr: ${result.stderr}");
messageLog.add("Failed to convert texture to DDS: ${result.stderr}");
throw Exception("Failed to convert texture to DDS: ${result.stderr}");
}
Expand Down
53 changes: 53 additions & 0 deletions lib/fileTypeUtils/ttf/ttf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ class Cmap {
numTables = bytes.readUint16();
encodingRecords = List.generate(numTables, (i) => EncodingRecord.read(bytes, cmapOffset));
}

Iterable<String> allChars() {
return encodingRecords
.map((r) => r.allChars())
.expand((c) => c)
.toSet();
}
}

class EncodingRecord {
Expand All @@ -140,6 +147,10 @@ class EncodingRecord {
format = CmapFormat.read(bytes);
bytes.position = previous;
}

Iterable<String> allChars() {
return format?.allChars() ?? [];
}
}
abstract class CmapFormat {
late final int format;
Expand All @@ -163,6 +174,8 @@ abstract class CmapFormat {
}

int? getGlyphIndex(String char);

Iterable<String> allChars();
}
class CmapFormat0 implements CmapFormat {
late final int format;
Expand All @@ -186,6 +199,15 @@ class CmapFormat0 implements CmapFormat {
return null;
return glyphIndexArray[code];
}

@override
Iterable<String> allChars() {
return glyphIndexArray
.asMap()
.entries
.where((e) => e.value != 0)
.map((e) => String.fromCharCode(e.key));
}
}
class CmapFormat4 implements CmapFormat {
late final int format;
Expand Down Expand Up @@ -245,6 +267,11 @@ class CmapFormat4 implements CmapFormat {
int code = char.codeUnitAt(0);
return glyphToIndexMap[code];
}

@override
Iterable<String> allChars() {
return glyphToIndexMap.keys.map((c) => String.fromCharCode(c));
}
}
class CmapFormat6 implements CmapFormat {
late final int format;
Expand Down Expand Up @@ -272,6 +299,15 @@ class CmapFormat6 implements CmapFormat {
return null;
return glyphIndexArray[code - firstCode];
}

@override
Iterable<String> allChars() {
return glyphIndexArray
.asMap()
.entries
.where((e) => e.value != 0)
.map((e) => String.fromCharCode(e.key + firstCode));
}
}
class CmapFormat1213 implements CmapFormat {
late final int format;
Expand Down Expand Up @@ -301,6 +337,14 @@ class CmapFormat1213 implements CmapFormat {
else
return group.id;
}

@override
Iterable<String> allChars() {
return groupRecords
.map((group) => Iterable.generate(group.endCharCode - group.startCharCode + 1, (i) => group.startCharCode + i))
.expand((c) => c)
.map((c) => String.fromCharCode(c));
}
}
class GroupRecord extends Range {
late final int id;
Expand All @@ -325,6 +369,11 @@ class CmapFormatUnknown implements CmapFormat {
int? getGlyphIndex(String char) {
return null;
}

@override
Iterable<String> allChars() {
return [];
}
}


Expand Down Expand Up @@ -1025,4 +1074,8 @@ class TtfFile {
double getKerningScaled(String left, String right, int fontSize) {
return getKerning(left, right) * fontSize / head.unitsPerEm;
}

Iterable<String> allChars() {
return cmap.allChars();
}
}
Loading

0 comments on commit 99195a5

Please sign in to comment.