diff --git a/profiles/cc/font-lb.lua b/profiles/cc/font-lb.lua index 37926180..29e77418 100644 --- a/profiles/cc/font-lb.lua +++ b/profiles/cc/font-lb.lua @@ -5,8 +5,8 @@ root.Fonts = { OutlineSheet = "FontLBOutline", Columns = 64, Rows = 125, - Widths = "games/cc/font-lb/widths.bin", - DesignColWidth = 48, + AdvanceWidths = "games/cc/font-lb/widths.bin", + AdvanceWidthsEmWidth = 48, OutlineOffset = { X = -4, Y = -4 }, LineSpacing = 14, } diff --git a/profiles/cc/font.lua b/profiles/cc/font.lua index 395285cb..58f57b50 100644 --- a/profiles/cc/font.lua +++ b/profiles/cc/font.lua @@ -4,13 +4,13 @@ root.Fonts = { Sheet = "Font", Columns = 64, Rows = 117, - Widths = {}, - DesignColWidth = 32, + AdvanceWidths = {}, + AdvanceWidthsEmWidth = 32, LineSpacing = 22, } }; -local westernWidths = { +local westernAdvanceWidths = { [0]=0x20, 0x18, 0x0D, 0x18, 0x17, 0x1A, 0x16, 0x17, 0x17, 0x18, 0x17, 0x1C, 0x19, 0x1A, 0x1A, 0x16, 0x15, 0x1A, 0x1A, 0x08, 0x13, 0x1A, 0x17, 0x1E, 0x1A, 0x1C, 0x18, 0x1C, 0x1A, 0x18, 0x1C, 0x1A, 0x1C, 0x20, 0x1C, 0x1A, @@ -46,9 +46,9 @@ local westernWidths = { }; for i = 0, (64 * 117) - 1 do - if i <= #westernWidths then - root.Fonts["Default"].Widths[i] = westernWidths[i]; + if i <= #westernAdvanceWidths then + root.Fonts["Default"].AdvanceWidths[i] = westernAdvanceWidths[i]; else - root.Fonts["Default"].Widths[i] = root.Fonts["Default"].DesignColWidth; + root.Fonts["Default"].AdvanceWidths[i] = root.Fonts["Default"].AdvanceWidthsEmWidth; end end \ No newline at end of file diff --git a/profiles/cclcc/font-lb.lua b/profiles/cclcc/font-lb.lua index 37926180..29e77418 100644 --- a/profiles/cclcc/font-lb.lua +++ b/profiles/cclcc/font-lb.lua @@ -5,8 +5,8 @@ root.Fonts = { OutlineSheet = "FontLBOutline", Columns = 64, Rows = 125, - Widths = "games/cc/font-lb/widths.bin", - DesignColWidth = 48, + AdvanceWidths = "games/cc/font-lb/widths.bin", + AdvanceWidthsEmWidth = 48, OutlineOffset = { X = -4, Y = -4 }, LineSpacing = 14, } diff --git a/profiles/cclcc/font.lua b/profiles/cclcc/font.lua index f514273d..db287e3f 100644 --- a/profiles/cclcc/font.lua +++ b/profiles/cclcc/font.lua @@ -4,13 +4,13 @@ root.Fonts = { Sheet = "Font", Columns = 64, Rows = 117, - Widths = {}, - DesignColWidth = 48, + AdvanceWidths = {}, + AdvanceWidthsEmWidth = 48, LineSpacing = 22, } }; -local westernWidths = { +local westernAdvanceWidths = { [0]=0x20, 0x18, 0x0D, 0x18, 0x17, 0x1A, 0x16, 0x17, 0x17, 0x18, 0x17, 0x1C, 0x19, 0x1A, 0x1A, 0x16, 0x15, 0x1A, 0x1A, 0x08, 0x13, 0x1A, 0x17, 0x1E, 0x1A, 0x1C, 0x18, 0x1C, 0x1A, 0x18, 0x1C, 0x1A, 0x1C, 0x20, 0x1C, 0x1A, @@ -46,9 +46,9 @@ local westernWidths = { }; for i = 0, (64 * 117) - 1 do - if i <= #westernWidths then - root.Fonts["Default"].Widths[i] = westernWidths[i] * 1.5; + if i <= #westernAdvanceWidths then + root.Fonts["Default"].AdvanceWidths[i] = westernAdvanceWidths[i] * 1.5; else - root.Fonts["Default"].Widths[i] = root.Fonts["Default"].DesignColWidth; + root.Fonts["Default"].AdvanceWidths[i] = root.Fonts["Default"].AdvanceWidthsEmWidth; end end \ No newline at end of file diff --git a/profiles/chlcc/font-lb.lua b/profiles/chlcc/font-lb.lua index 0e4badf6..866058e4 100644 --- a/profiles/chlcc/font-lb.lua +++ b/profiles/chlcc/font-lb.lua @@ -5,8 +5,8 @@ root.Fonts = { OutlineSheet = "FontLBOutline", Columns = 64, Rows = 37, - Widths = "games/chlcc/font-lb/widths.bin", - DesignColWidth = 48, + AdvanceWidths = "games/chlcc/font-lb/widths.bin", + AdvanceWidthsEmWidth = 48, OutlineOffset = { X = -4, Y = -4 }, LineSpacing = 14, } diff --git a/profiles/chlcc/font.lua b/profiles/chlcc/font.lua index 6f82ad94..62daa0a3 100644 --- a/profiles/chlcc/font.lua +++ b/profiles/chlcc/font.lua @@ -6,13 +6,13 @@ root.Fonts = { Sheet = "Font", Columns = 64, Rows = 37, - Widths = {}, - DesignColWidth = 32, + AdvanceWidths = {}, + AdvanceWidthsEmWidth = 32, LineSpacing = 22, } }; -local westernWidths = { +local westernAdvanceWidths = { [0]=0x20, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, @@ -38,9 +38,9 @@ local westernWidths = { }; for i = 0, (64 * 37) - 1 do - if i <= #westernWidths then - root.Fonts["Default"].Widths[i] = westernWidths[i]; + if i <= #westernAdvanceWidths then + root.Fonts["Default"].AdvanceWidths[i] = westernAdvanceWidths[i]; else - root.Fonts["Default"].Widths[i] = root.Fonts["Default"].DesignColWidth; + root.Fonts["Default"].AdvanceWidths[i] = root.Fonts["Default"].AdvanceWidthsEmWidth; end end \ No newline at end of file diff --git a/profiles/chn/font-lb.lua b/profiles/chn/font-lb.lua index f4a801f6..14f9512b 100644 --- a/profiles/chn/font-lb.lua +++ b/profiles/chn/font-lb.lua @@ -5,8 +5,8 @@ root.Fonts = { OutlineSheet = "FontLBOutline", Columns = 64, Rows = 50, - Widths = "games/rne/font-lb/widths.bin", - DesignColWidth = 48, + AdvanceWidths = "games/rne/font-lb/widths.bin", + AdvanceWidthsEmWidth = 48, OutlineOffset = { X = -4, Y = -4 }, LineSpacing = 14, } diff --git a/profiles/chn/font.lua b/profiles/chn/font.lua index 395285cb..58f57b50 100644 --- a/profiles/chn/font.lua +++ b/profiles/chn/font.lua @@ -4,13 +4,13 @@ root.Fonts = { Sheet = "Font", Columns = 64, Rows = 117, - Widths = {}, - DesignColWidth = 32, + AdvanceWidths = {}, + AdvanceWidthsEmWidth = 32, LineSpacing = 22, } }; -local westernWidths = { +local westernAdvanceWidths = { [0]=0x20, 0x18, 0x0D, 0x18, 0x17, 0x1A, 0x16, 0x17, 0x17, 0x18, 0x17, 0x1C, 0x19, 0x1A, 0x1A, 0x16, 0x15, 0x1A, 0x1A, 0x08, 0x13, 0x1A, 0x17, 0x1E, 0x1A, 0x1C, 0x18, 0x1C, 0x1A, 0x18, 0x1C, 0x1A, 0x1C, 0x20, 0x1C, 0x1A, @@ -46,9 +46,9 @@ local westernWidths = { }; for i = 0, (64 * 117) - 1 do - if i <= #westernWidths then - root.Fonts["Default"].Widths[i] = westernWidths[i]; + if i <= #westernAdvanceWidths then + root.Fonts["Default"].AdvanceWidths[i] = westernAdvanceWidths[i]; else - root.Fonts["Default"].Widths[i] = root.Fonts["Default"].DesignColWidth; + root.Fonts["Default"].AdvanceWidths[i] = root.Fonts["Default"].AdvanceWidthsEmWidth; end end \ No newline at end of file diff --git a/profiles/darling/font.lua b/profiles/darling/font.lua index 7d5b94dc..53392b30 100644 --- a/profiles/darling/font.lua +++ b/profiles/darling/font.lua @@ -6,13 +6,13 @@ root.Fonts = { Sheet = "Font", Columns = 64, Rows = 43, - Widths = {}, - DesignColWidth = 32, + AdvanceWidths = {}, + AdvanceWidthsEmWidth = 32, LineSpacing = 22, } }; -local westernWidths = { +local westernAdvanceWidths = { [0]=0x20, 0x16, 0x0E, 0x14, 0x15, 0x16, 0x16, 0x16, 0x15, 0x16, 0x16, 0x18, 0x16, 0x17, 0x17, 0x15, 0x14, 0x18, 0x16, 0x08, 0x0E, 0x17, 0x13, 0x1A, 0x16, 0x19, 0x15, 0x19, 0x16, 0x15, 0x15, 0x16, 0x17, 0x1E, 0x16, 0x15, @@ -48,9 +48,9 @@ local westernWidths = { }; for i = 0, (64 * 43) - 1 do - if i <= #westernWidths then - root.Fonts["Default"].Widths[i] = westernWidths[i]; + if i <= #westernAdvanceWidths then + root.Fonts["Default"].AdvanceWidths[i] = westernAdvanceWidths[i]; else - root.Fonts["Default"].Widths[i] = root.Fonts["Default"].DesignColWidth; + root.Fonts["Default"].AdvanceWidths[i] = root.Fonts["Default"].AdvanceWidthsEmWidth; end end \ No newline at end of file diff --git a/profiles/dash/font-lb.lua b/profiles/dash/font-lb.lua index f4a801f6..14f9512b 100644 --- a/profiles/dash/font-lb.lua +++ b/profiles/dash/font-lb.lua @@ -5,8 +5,8 @@ root.Fonts = { OutlineSheet = "FontLBOutline", Columns = 64, Rows = 50, - Widths = "games/rne/font-lb/widths.bin", - DesignColWidth = 48, + AdvanceWidths = "games/rne/font-lb/widths.bin", + AdvanceWidthsEmWidth = 48, OutlineOffset = { X = -4, Y = -4 }, LineSpacing = 14, } diff --git a/profiles/dash/font.lua b/profiles/dash/font.lua index e1c89f25..4bf05562 100644 --- a/profiles/dash/font.lua +++ b/profiles/dash/font.lua @@ -6,13 +6,13 @@ root.Fonts = { Sheet = "Font", Columns = 64, Rows = 50, - Widths = {}, - DesignColWidth = 32, + AdvanceWidths = {}, + AdvanceWidthsEmWidth = 32, LineSpacing = 22, } }; -local westernWidths = { +local westernAdvanceWidths = { [0]=0x20, 0x16, 0x0E, 0x14, 0x15, 0x16, 0x16, 0x16, 0x15, 0x16, 0x16, 0x18, 0x16, 0x17, 0x17, 0x15, 0x14, 0x18, 0x16, 0x08, 0x0E, 0x17, 0x13, 0x1A, 0x16, 0x19, 0x15, 0x19, 0x16, 0x15, 0x15, 0x16, 0x17, 0x1E, 0x16, 0x15, @@ -48,9 +48,9 @@ local westernWidths = { }; for i = 0, (64 * 50) - 1 do - if i <= #westernWidths then - root.Fonts["Default"].Widths[i] = westernWidths[i]; + if i <= #westernAdvanceWidths then + root.Fonts["Default"].AdvanceWidths[i] = westernAdvanceWidths[i]; else - root.Fonts["Default"].Widths[i] = root.Fonts["Default"].DesignColWidth; + root.Fonts["Default"].AdvanceWidths[i] = root.Fonts["Default"].AdvanceWidthsEmWidth; end end \ No newline at end of file diff --git a/profiles/mo6tw/font.lua b/profiles/mo6tw/font.lua index 47c1a3e1..434358e0 100644 --- a/profiles/mo6tw/font.lua +++ b/profiles/mo6tw/font.lua @@ -6,13 +6,13 @@ root.Fonts = { Sheet = "Font", Columns = 64, Rows = 39, - Widths = {}, - DesignColWidth = 32, + AdvanceWidths = {}, + AdvanceWidthsEmWidth = 32, LineSpacing = 22, } }; -local westernWidths = { +local westernAdvanceWidths = { [0]=0x20, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, @@ -48,9 +48,9 @@ local westernWidths = { }; for i = 0, (64 * 39) - 1 do - if i <= #westernWidths then - root.Fonts["Default"].Widths[i] = westernWidths[i]; + if i <= #westernAdvanceWidths then + root.Fonts["Default"].AdvanceWidths[i] = westernAdvanceWidths[i]; else - root.Fonts["Default"].Widths[i] = root.Fonts["Default"].DesignColWidth; + root.Fonts["Default"].AdvanceWidths[i] = root.Fonts["Default"].AdvanceWidthsEmWidth; end end \ No newline at end of file diff --git a/profiles/mo7/font.lua b/profiles/mo7/font.lua index eff76d8c..022d6537 100644 --- a/profiles/mo7/font.lua +++ b/profiles/mo7/font.lua @@ -6,13 +6,13 @@ root.Fonts = { Sheet = "Font", Columns = 64, Rows = 43, - Widths = {}, - DesignColWidth = 32, + AdvanceWidths = {}, + AdvanceWidthsEmWidth = 32, LineSpacing = 22, } }; -local westernWidths = { +local westernAdvanceWidths = { [0]=0x20, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, @@ -48,9 +48,9 @@ local westernWidths = { }; for i = 0, (64 * 43) - 1 do - if i <= #westernWidths then - root.Fonts["Default"].Widths[i] = westernWidths[i]; + if i <= #westernAdvanceWidths then + root.Fonts["Default"].AdvanceWidths[i] = westernAdvanceWidths[i]; else - root.Fonts["Default"].Widths[i] = root.Fonts["Default"].DesignColWidth; + root.Fonts["Default"].AdvanceWidths[i] = root.Fonts["Default"].AdvanceWidthsEmWidth; end end \ No newline at end of file diff --git a/profiles/mo8/font-lb.lua b/profiles/mo8/font-lb.lua index f4a801f6..14f9512b 100644 --- a/profiles/mo8/font-lb.lua +++ b/profiles/mo8/font-lb.lua @@ -5,8 +5,8 @@ root.Fonts = { OutlineSheet = "FontLBOutline", Columns = 64, Rows = 50, - Widths = "games/rne/font-lb/widths.bin", - DesignColWidth = 48, + AdvanceWidths = "games/rne/font-lb/widths.bin", + AdvanceWidthsEmWidth = 48, OutlineOffset = { X = -4, Y = -4 }, LineSpacing = 14, } diff --git a/profiles/mo8/font.lua b/profiles/mo8/font.lua index a6ccebfe..c6795b1f 100644 --- a/profiles/mo8/font.lua +++ b/profiles/mo8/font.lua @@ -4,13 +4,13 @@ root.Fonts = { Sheet = "Font", Columns = 64, Rows = 116, - Widths = {}, - DesignColWidth = 48, + AdvanceWidths = {}, + AdvanceWidthsEmWidth = 48, LineSpacing = 22, } }; -local westernWidths = { +local westernAdvanceWidths = { [0]=0x20, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, @@ -39,9 +39,9 @@ local westernWidths = { }; for i = 0, (64 * 116) - 1 do - if i <= #westernWidths then - root.Fonts["Default"].Widths[i] = westernWidths[i] * 1.5; + if i <= #westernAdvanceWidths then + root.Fonts["Default"].AdvanceWidths[i] = westernAdvanceWidths[i] * 1.5; else - root.Fonts["Default"].Widths[i] = root.Fonts["Default"].DesignColWidth; + root.Fonts["Default"].AdvanceWidths[i] = root.Fonts["Default"].AdvanceWidthsEmWidth; end end \ No newline at end of file diff --git a/profiles/rne/font-lb.lua b/profiles/rne/font-lb.lua index f4a801f6..14f9512b 100644 --- a/profiles/rne/font-lb.lua +++ b/profiles/rne/font-lb.lua @@ -5,8 +5,8 @@ root.Fonts = { OutlineSheet = "FontLBOutline", Columns = 64, Rows = 50, - Widths = "games/rne/font-lb/widths.bin", - DesignColWidth = 48, + AdvanceWidths = "games/rne/font-lb/widths.bin", + AdvanceWidthsEmWidth = 48, OutlineOffset = { X = -4, Y = -4 }, LineSpacing = 14, } diff --git a/profiles/rne/font.lua b/profiles/rne/font.lua index e1c89f25..4bf05562 100644 --- a/profiles/rne/font.lua +++ b/profiles/rne/font.lua @@ -6,13 +6,13 @@ root.Fonts = { Sheet = "Font", Columns = 64, Rows = 50, - Widths = {}, - DesignColWidth = 32, + AdvanceWidths = {}, + AdvanceWidthsEmWidth = 32, LineSpacing = 22, } }; -local westernWidths = { +local westernAdvanceWidths = { [0]=0x20, 0x16, 0x0E, 0x14, 0x15, 0x16, 0x16, 0x16, 0x15, 0x16, 0x16, 0x18, 0x16, 0x17, 0x17, 0x15, 0x14, 0x18, 0x16, 0x08, 0x0E, 0x17, 0x13, 0x1A, 0x16, 0x19, 0x15, 0x19, 0x16, 0x15, 0x15, 0x16, 0x17, 0x1E, 0x16, 0x15, @@ -48,9 +48,9 @@ local westernWidths = { }; for i = 0, (64 * 50) - 1 do - if i <= #westernWidths then - root.Fonts["Default"].Widths[i] = westernWidths[i]; + if i <= #westernAdvanceWidths then + root.Fonts["Default"].AdvanceWidths[i] = westernAdvanceWidths[i]; else - root.Fonts["Default"].Widths[i] = root.Fonts["Default"].DesignColWidth; + root.Fonts["Default"].AdvanceWidths[i] = root.Fonts["Default"].AdvanceWidthsEmWidth; end end \ No newline at end of file diff --git a/profiles/sgps3/font.lua b/profiles/sgps3/font.lua index 8164ebb4..7cca2c4c 100644 --- a/profiles/sgps3/font.lua +++ b/profiles/sgps3/font.lua @@ -6,13 +6,13 @@ root.Fonts = { Sheet = "Font", Columns = 64, Rows = 14, - Widths = {}, - DesignColWidth = 32, + AdvanceWidths = {}, + AdvanceWidthsEmWidth = 32, LineSpacing = 22, } }; -local westernWidths = { +local westernAdvanceWidths = { [0]=0x20, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, @@ -48,9 +48,9 @@ local westernWidths = { }; for i = 0, (64 * 14) - 1 do - if i <= #westernWidths then - root.Fonts["Default"].Widths[i] = westernWidths[i]; + if i <= #westernAdvanceWidths then + root.Fonts["Default"].AdvanceWidths[i] = westernAdvanceWidths[i]; else - root.Fonts["Default"].Widths[i] = root.Fonts["Default"].DesignColWidth; + root.Fonts["Default"].AdvanceWidths[i] = root.Fonts["Default"].AdvanceWidthsEmWidth; end end \ No newline at end of file diff --git a/src/font.h b/src/font.h index ec406791..6411a272 100644 --- a/src/font.h +++ b/src/font.h @@ -15,11 +15,14 @@ class Font { uint8_t Columns; uint8_t Rows; - float* Widths; + float* AdvanceWidths; float CellHeight; float CellWidth; + float BitmapEmWidth; + float BitmapEmHeight; + float LineSpacing; virtual void CalculateDefaultSizes() = 0; @@ -41,9 +44,9 @@ class BasicFont : public Font { Sprite Glyph(uint16_t id) { uint8_t row = id / Columns; uint8_t col = id % Columns; - float width = Widths[id]; + float width = AdvanceWidths[id]; return Sprite(Sheet, col * CellWidth + 1, row * CellHeight + 1, width - 2, - CellHeight - 2); + BitmapEmHeight - 2); } }; @@ -57,6 +60,7 @@ class LBFont : public Font { float OutlineCellHeight; float OutlineCellWidth; + glm::vec2 ForegroundOffset; glm::vec2 OutlineOffset; void CalculateDefaultSizes() override { @@ -72,8 +76,7 @@ class LBFont : public Font { Sprite Glyph(uint16_t id) { uint8_t row = id / Columns; uint8_t col = id % Columns; - float width = Widths[id]; - return Sprite(ForegroundSheet, col * CellWidth, row * CellHeight, width, + return Sprite(ForegroundSheet, col * CellWidth, row * CellHeight, CellWidth, CellHeight); } diff --git a/src/profile/fonts.cpp b/src/profile/fonts.cpp index 4fc07515..d260e9c4 100644 --- a/src/profile/fonts.cpp +++ b/src/profile/fonts.cpp @@ -36,6 +36,9 @@ void LoadFonts() { font->ForegroundSheet = EnsureGetMemberSpriteSheet("ForegroundSheet"); font->OutlineSheet = EnsureGetMemberSpriteSheet("OutlineSheet"); + if (!TryGetMemberVec2("ForegroundOffset", font->ForegroundOffset)) { + font->ForegroundOffset = glm::vec2(0.0f); + } font->OutlineOffset = EnsureGetMemberVec2("OutlineOffset"); break; @@ -47,12 +50,20 @@ void LoadFonts() { baseFont->CalculateDefaultSizes(); + if (!TryGetMemberFloat("BitmapEmWidth", baseFont->BitmapEmWidth)) { + baseFont->BitmapEmWidth = baseFont->CellWidth; + } + + if (!TryGetMemberFloat("BitmapEmHeight", baseFont->BitmapEmHeight)) { + baseFont->BitmapEmHeight = baseFont->CellHeight; + } + baseFont->LineSpacing = EnsureGetMemberFloat("LineSpacing"); - float designColWidth = EnsureGetMemberFloat("DesignColWidth"); - float actualColWidth = baseFont->CellWidth; + float advanceWidthsEmWidth = EnsureGetMemberFloat("AdvanceWidthsEmWidth"); + float bitmapEmWidth = baseFont->BitmapEmWidth; - baseFont->Widths = + baseFont->AdvanceWidths = (float*)malloc(baseFont->Columns * baseFont->Rows * sizeof(float)); float extraLetterSpacing; @@ -61,7 +72,7 @@ void LoadFonts() { } { - EnsurePushMember("Widths"); + EnsurePushMember("AdvanceWidths"); Io::AssetPath widthTablePath; if (TryGetAssetPath(widthTablePath)) { @@ -74,8 +85,8 @@ void LoadFonts() { } assert(widthSz == baseFont->Columns * baseFont->Rows); for (uint16_t i = 0; i < widthSz; i++) { - baseFont->Widths[i] = ((float)widthBin[i] + extraLetterSpacing) * - actualColWidth / designColWidth; + baseFont->AdvanceWidths[i] = ((float)widthBin[i] + extraLetterSpacing) * + bitmapEmWidth / advanceWidthsEmWidth; } } else { AssertIs(LUA_TTABLE); @@ -83,9 +94,9 @@ void LoadFonts() { PushInitialIndex(); while (PushNextTableElement() != 0) { int i = EnsureGetKeyInt(); - baseFont->Widths[i] = + baseFont->AdvanceWidths[i] = (EnsureGetArrayElementFloat() + extraLetterSpacing) * - actualColWidth / designColWidth; + bitmapEmWidth / advanceWidthsEmWidth; Pop(); } } diff --git a/src/renderer/renderer.cpp b/src/renderer/renderer.cpp index a7491d6c..677d7c18 100644 --- a/src/renderer/renderer.cpp +++ b/src/renderer/renderer.cpp @@ -159,12 +159,13 @@ void BaseRenderer::DrawProcessedText_LBFont( color.a *= text[i].Opacity; } - float scale = text[i].DestRect.Height / font->CellHeight; + float scaleX = text[i].DestRect.Width / font->BitmapEmWidth; + float scaleY = text[i].DestRect.Height / font->BitmapEmHeight; RectF outlineDest = RectF( - text[i].DestRect.X + scale * font->OutlineOffset.x, - text[i].DestRect.Y + scale * font->OutlineOffset.y, - scale * font->OutlineCellWidth, scale * font->OutlineCellHeight); + text[i].DestRect.X + scaleX * font->OutlineOffset.x, + text[i].DestRect.Y + scaleY * font->OutlineOffset.y, + scaleX * font->OutlineCellWidth, scaleY * font->OutlineCellHeight); if (maskedSheet) { Sprite mask; mask.Sheet = *maskedSheet; @@ -186,15 +187,23 @@ void BaseRenderer::DrawProcessedText_LBFont( } else { color.a *= text[i].Opacity; } + + float scaleX = text[i].DestRect.Width / font->BitmapEmWidth; + float scaleY = text[i].DestRect.Height / font->BitmapEmHeight; + + RectF foregroundDest = RectF( + text[i].DestRect.X + scaleX * font->ForegroundOffset.x, + text[i].DestRect.Y + scaleY * font->ForegroundOffset.y, + scaleX * font->CellWidth, scaleY * font->CellHeight); if (maskedSheet) { Sprite mask; mask.Sheet = *maskedSheet; - mask.Bounds = text[i].DestRect; + mask.Bounds = foregroundDest; DrawMaskedSpriteOverlay(font->Glyph(text[i].CharId), mask, - text[i].DestRect, color, color.a * 255, 256, + foregroundDest, color, color.a * 255, 256, false, 0, false); } else { - DrawSprite(font->Glyph(text[i].CharId), text[i].DestRect, color); + DrawSprite(font->Glyph(text[i].CharId), foregroundDest, color); } } } diff --git a/src/text.cpp b/src/text.cpp index eed85fef..4ebd46a7 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -549,8 +549,8 @@ void DialoguePage::AddString(Vm::Sc3VmThread* ctx, Audio::AudioStream* voice, } ptg.DestRect.X = BoxBounds.X + CurrentX; - ptg.DestRect.Width = (FontSize / DialogueFont->CellHeight) * - DialogueFont->Widths[ptg.CharId]; + ptg.DestRect.Width = (FontSize / DialogueFont->BitmapEmWidth) * + DialogueFont->AdvanceWidths[ptg.CharId]; ptg.DestRect.Height = FontSize; CurrentX += ptg.DestRect.Width; @@ -788,7 +788,7 @@ int TextLayoutPlainLine(Vm::Sc3VmThread* ctx, int stringLength, ptg.DestRect.X = currentX; ptg.DestRect.Y = pos.y; ptg.DestRect.Width = - std::floor((fontSize / font->CellHeight) * font->Widths[ptg.CharId]); + std::floor((fontSize / font->BitmapEmWidth) * font->AdvanceWidths[ptg.CharId]); ptg.DestRect.Height = fontSize; currentX += ptg.DestRect.Width; @@ -825,7 +825,7 @@ std::vector TextLayoutPlainLine( ptg.DestRect.X = currentX; ptg.DestRect.Y = pos.y; ptg.DestRect.Width = - std::floor((fontSize / font->CellHeight) * font->Widths[ptg.CharId]); + std::floor((fontSize / font->CellHeight) * font->AdvanceWidths[ptg.CharId]); ptg.DestRect.Height = fontSize; currentX += ptg.DestRect.Width; @@ -902,8 +902,8 @@ float TextGetPlainLineWidth(Vm::Sc3VmThread* ctx, Font* font, float fontSize) { if (token.Type == STT_EndOfString) break; if (token.Type != STT_Character) continue; - width += std::floor((fontSize / font->CellHeight) * - font->Widths[token.Val_Uint16]); + width += std::floor((fontSize / font->BitmapEmWidth) * + font->AdvanceWidths[token.Val_Uint16]); } return width;