Skip to content

Commit

Permalink
added height scale
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHeitmann committed Nov 7, 2022
1 parent 04ea323 commit abb2f1b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 29 deletions.
13 changes: 8 additions & 5 deletions lib/stateManagement/otherFileTypes/FtbFileData.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,17 @@ class FtbData extends ChangeNotifier {
}

// generate cli json args
var heightScale = fontOverride.heightScale.value.toDouble();
var fontHeight = McdData.availableFonts[fontId]!.fontHeight * heightScale;
var scaleFact = 44 / fontHeight;
CliFontOptions? font = CliFontOptions(
fontOverride.fontPath.value,
chars[0].height,
fontHeight.toInt(),
fontOverride.scale.value.toDouble(),
fontOverride.letXPadding.value.toInt(),
fontOverride.letYPadding.value.toInt(),
fontOverride.xOffset.value.toDouble(),
fontOverride.yOffset.value.toDouble(),
(fontOverride.letXPadding.value * scaleFact).toInt(),
(fontOverride.letYPadding.value * scaleFact).toInt(),
(fontOverride.xOffset.value * scaleFact).toDouble(),
(fontOverride.yOffset.value * scaleFact).toDouble(),
);
const textureBatchesCount = 4;
var charsPerBatch = (chars.length / textureBatchesCount).ceil();
Expand Down
35 changes: 24 additions & 11 deletions lib/stateManagement/otherFileTypes/McdData.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class McdLocalFont extends McdFont {

class McdFontOverride with HasUuid {
final ValueNestedNotifier<int> fontIds;
final NumberProp heightScale;
final StringProp fontPath;
final NumberProp scale;
final NumberProp letXPadding;
Expand All @@ -160,6 +161,7 @@ class McdFontOverride with HasUuid {

McdFontOverride(int firstFontId) :
fontIds = ValueNestedNotifier([firstFontId]),
heightScale = NumberProp(1.0, false),
fontPath = StringProp(""),
scale = NumberProp(1.0, false),
letXPadding = NumberProp(0.0, true),
Expand Down Expand Up @@ -535,11 +537,19 @@ class McdData extends _McdFilePart {
return McdLocalFont.zero();
return usedFonts[id]!;
})
.map((f) => McdFileFont(
f.fontId,
f.fontWidth.toDouble(), f.fontHeight.toDouble(),
f.fontBelow.toDouble(), 0)
)
.map((f) {
var fontOverrideRes = fontOverrides.where((fo) => fo.fontIds.contains(f.fontId));
double heightScale = 1.0;
if (fontOverrideRes.isNotEmpty) {
var fontOverride = fontOverrideRes.first;
heightScale = fontOverride.heightScale.value.toDouble();
}
return McdFileFont(
f.fontId,
f.fontWidth.toDouble(), f.fontHeight * heightScale,
f.fontBelow.toDouble(), 0
);
})
.toList();
var exportFontMap = { for (var f in exportFonts) f.id: f };

Expand Down Expand Up @@ -720,15 +730,16 @@ class McdData extends _McdFilePart {
var symbol = symbols[i];
if (fontOverridesMap.containsKey(symbol.fontId)) {
if (!fonts.containsKey(symbol.fontId)) {
var scaleFact = 44 / availableFonts[symbol.fontId]!.fontHeight;
var fontHeight = (availableFonts[symbol.fontId]!.fontHeight * fontOverridesMap[symbol.fontId]!.heightScale.value).toInt();
var scaleFact = 44 / fontHeight;
fonts[symbol.fontId] = CliFontOptions(
fontOverridesMap[symbol.fontId]!.fontPath.value,
availableFonts[symbol.fontId]!.fontHeight,
fontHeight,
fontOverridesMap[symbol.fontId]!.scale.value.toDouble(),
(fontOverridesMap[symbol.fontId]!.letXPadding.value * scaleFact).toInt(),
(fontOverridesMap[symbol.fontId]!.letYPadding.value * scaleFact).toInt(),
fontOverridesMap[symbol.fontId]!.xOffset.value.toDouble() * scaleFact,
fontOverridesMap[symbol.fontId]!.yOffset.value.toDouble() * scaleFact,
fontOverridesMap[symbol.fontId]!.xOffset.value * scaleFact,
fontOverridesMap[symbol.fontId]!.yOffset.value * scaleFact,
);
}
CliImgOperationDrawFromTexture? fallback;
Expand Down Expand Up @@ -814,6 +825,8 @@ class McdData extends _McdFilePart {
Map<int, McdLocalFont> exportFonts = {};
for (var fontId in generatedSymbols.keys) {
var font = availableFonts[fontId]!;
var heightScale = fontOverridesMap[fontId]?.heightScale.value ?? 1.0;
var fontHeight = (font.fontHeight * heightScale).toInt();
Map<int, McdFontSymbol> exportSymbols = {};
for (var genSym in generatedSymbols[fontId]!) {
var usedSym = genSym.item1;
Expand All @@ -826,11 +839,11 @@ class McdData extends _McdFilePart {
);
}
var fontBelow = atlasInfo.fonts.containsKey(fontId)
? atlasInfo.fonts[fontId]!.baseline - availableFonts[fontId]!.fontHeight
? atlasInfo.fonts[fontId]!.baseline - fontHeight
: font.fontBelow;
fontBelow = min(fontBelow, 0);
exportFonts[fontId] = McdLocalFont(
fontId, font.fontWidth, font.fontHeight,
fontId, font.fontWidth, fontHeight,
fontBelow , exportSymbols
);
}
Expand Down
32 changes: 19 additions & 13 deletions lib/widgets/propEditors/otherFileTypes/FontsManager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class __McdFontsManagerState extends ChangeNotifierState<FontsManager> {

@override
Widget build(BuildContext context) {
const columnNames = ["", "Font IDs", "TTF/OTF Path", "", "Scale", "xPadding", "yPadding", "xOffset", "yOffset", "", ""];
const columnNames = ["", "Font IDs", "absScale", "TTF/OTF Path", "", "locScale", "xPadding", "yPadding", "xOffset", "yOffset", "", ""];

int iStart = 0;
int iEnd = McdData.fontOverrides.length;
Expand All @@ -50,27 +50,29 @@ class __McdFontsManagerState extends ChangeNotifierState<FontsManager> {
// columns:
// X: spacer
// 0: fontIDs
// 1: fontFilePath
// 2: file path selector
// 3: scale
// 4: x letter padding
// 5: y letter padding
// 6: y Offset
// 1: height scale
// 2: fontFilePath
// 3: file path selector
// 4: scale
// 5: x letter padding
// 6: y letter padding
// 7: y Offset
// 8: remove button
// 8: y Offset
// 9: remove button
// X: spacer
columnWidths: const {
0: FixedColumnWidth(16),
1: FixedColumnWidth(100 + 8),
2: FlexColumnWidth(1),
3: FixedColumnWidth(30 + 8),
4: FixedColumnWidth(60 + 8),
2: FixedColumnWidth(60 + 8),
3: FlexColumnWidth(1),
4: FixedColumnWidth(30 + 8),
5: FixedColumnWidth(60 + 8),
6: FixedColumnWidth(60 + 8),
7: FixedColumnWidth(60 + 8),
8: FixedColumnWidth(60 + 8),
9: FixedColumnWidth(30 + 8),
10: FixedColumnWidth(16),
9: FixedColumnWidth(60 + 8),
10: FixedColumnWidth(30 + 8),
11: FixedColumnWidth(16),
},
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
children: [
Expand Down Expand Up @@ -121,6 +123,10 @@ class __McdFontsManagerState extends ChangeNotifierState<FontsManager> {
),
],
),
makePropEditor(
McdData.fontOverrides[i].heightScale,
const PropTFOptions(hintText: "absScale", constraints: BoxConstraints.tightFor(height: 30)),
),
PrimaryPropTextField(
prop: McdData.fontOverrides[i].fontPath,
options: const PropTFOptions(hintText: "Font Path", constraints: BoxConstraints.tightFor(height: 30)),
Expand Down

0 comments on commit abb2f1b

Please sign in to comment.