From 1515c774387da09cf4505ad303a62a272116cc59 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Mon, 19 Feb 2024 14:22:27 +0100 Subject: [PATCH] Fix widths of time columns for fonts with proportional figures This still breaks when the 0 digit is narrower than some other digit, but that's unlikely and the current behavior now matches the original behavior when all times are < 10h. Fixes arch1t3cht/Aegisub#111 . --- src/grid_column.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/grid_column.cpp b/src/grid_column.cpp index aff198513..c28b460dc 100644 --- a/src/grid_column.cpp +++ b/src/grid_column.cpp @@ -159,9 +159,14 @@ struct GridColumnStartTime final : GridColumnTime { int Width(const agi::Context *c, WidthHelper &helper) const override { agi::Time max_time = max_value(&AssDialogue::Start, c->ass->Events); - if (!by_frame) - return helper(max_time.GetAssFormatted()); - return helper(std::to_wstring(c->videoController->FrameAtTime(max_time, agi::vfr::START))); + std::string value = by_frame ? std::to_string(c->videoController->FrameAtTime(max_time, agi::vfr::START)) : max_time.GetAssFormatted(); + + for (char &c : value) { + if (c >= '0' && c <= '9') + c = '0'; + } + + return helper(value); } }; @@ -177,9 +182,14 @@ struct GridColumnEndTime final : GridColumnTime { int Width(const agi::Context *c, WidthHelper &helper) const override { agi::Time max_time = max_value(&AssDialogue::End, c->ass->Events); - if (!by_frame) - return helper(max_time.GetAssFormatted()); - return helper(std::to_wstring(c->videoController->FrameAtTime(max_time, agi::vfr::END))); + std::string value = by_frame ? std::to_string(c->videoController->FrameAtTime(max_time, agi::vfr::END)) : max_time.GetAssFormatted(); + + for (char &c : value) { + if (c >= '0' && c <= '9') + c = '0'; + } + + return helper(value); } };