Skip to content

Commit

Permalink
Fix widths of time columns for fonts with proportional figures
Browse files Browse the repository at this point in the history
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 #111 .
  • Loading branch information
arch1t3cht committed Feb 19, 2024
1 parent eaf09b2 commit 1515c77
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/grid_column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand All @@ -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);
}
};

Expand Down

0 comments on commit 1515c77

Please sign in to comment.