Skip to content

Commit 0437934

Browse files
committed
- 修复TypesettingTools#173: \fn0字体重置,在libass/VSFilter中等同于\fn,重置为样式默认字体 - 修复TypesettingTools#45: 分辨率设置UB,'设为视频分辨率'不再调用ResampleResolution - 修复TypesettingTools#118: SRT时间精度,厘秒转换从四舍五入改为截断,匹配VSFilter/libass - 修复TypesettingTools#28: 字体收集器性能,PrintUsage行号批量拼接输出
1 parent a623fdf commit 0437934

5 files changed

Lines changed: 29 additions & 11 deletions

File tree

libaegisub/ass/time.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include <algorithm>
2525

2626
// classic VSFilter internally uses a signed 32-bit int to denote milliseconds.
27-
// To avoid this limit to < 596h (-6 to avoid rounding up to 596h in centisecond precision)
28-
static const int MAX_TIME = 596 * 60 * 60 * 1000 - 6;
27+
// 限制在 596 小时以内
28+
static const int MAX_TIME = 596 * 60 * 60 * 1000;
2929

3030
static void decompose_time(int ms_time, int& h, int& m, int& s, int& ms) {
3131
h = ms_time / 3600000;

libaegisub/include/libaegisub/ass/time.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ class Time {
2828
Time(int ms = 0);
2929
Time(std::string_view text);
3030

31-
/// Get millisecond, rounded to centisecond precision
32-
// Always round up for 5ms because the range is [start, stop)
33-
operator int() const { return (time + 5) - (time + 5) % 10; }
31+
/// 获取截断至厘秒精度的毫秒值,与 VSFilter/libass 行为一致
32+
operator int() const { return time - time % 10; }
3433

3534
/// Return the time as a string
3635
/// @param ms Use milliseconds precision, for non-ASS formats

src/dialog_video_properties.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ bool update_video_properties(AssFile *file, const AsyncVideoProvider *new_provid
158158
if (res == FIX_IGNORE) return commit_subs;
159159
OPT_SET("Video/Last Script Resolution Mismatch Choice")->SetInt(res);
160160

161+
// "设置为视频分辨率"仅更新脚本属性,不执行 resample
162+
if (res == FIX_SET) {
163+
file->SetScriptInfo("PlayResX", std::to_string(vx));
164+
file->SetScriptInfo("PlayResY", std::to_string(vy));
165+
return true;
166+
}
167+
161168
ResampleResolution(file, {
162169
{0, 0, 0, 0},
163170
sx, sy, vx, vy,

src/font_file_lister.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
9191
overriden = true;
9292
}
9393
else if (tag.Name == "\\fn") {
94-
style.facename = tag.Params[0].Get(initial.facename);
94+
auto name = tag.Params[0].Get(initial.facename);
95+
// \fn0 在 libass/VSFilter 中等同于 \fn,重置为样式默认字体
96+
style.facename = (name == "0") ? initial.facename : name;
9597
overriden = true;
9698
}
9799
}
@@ -196,10 +198,12 @@ void FontCollector::PrintUsage(UsageData const& data) {
196198
}
197199

198200
if (data.lines.size()) {
199-
status_callback(_("Used on lines:"), 2);
201+
// 批量拼接行号,避免逐行号调用 status_callback 导致 GUI 事件风暴
202+
wxString lines_str = _("Used on lines:");
200203
for (int line : data.lines)
201-
status_callback(fmt_wx(" %d", line), 2);
202-
status_callback("\n", 2);
204+
lines_str += fmt_wx(" %d", line);
205+
lines_str += "\n";
206+
status_callback(lines_str, 2);
203207
}
204208
status_callback("\n", 2);
205209
}

tests/tests/time.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@ using agi::Time;
2323

2424
TEST(lagi_time, out_of_range_times) {
2525
EXPECT_EQ(0, (int)Time(-1));
26-
EXPECT_EQ(596 * 60 * 60 * 1000 - 10, (int)Time(596 * 60 * 60 * 1000));
26+
EXPECT_EQ(596 * 60 * 60 * 1000, (int)Time(596 * 60 * 60 * 1000));
2727
}
2828

29-
TEST(lagi_time, rounds_to_cs) {
29+
TEST(lagi_time, truncates_to_cs) {
3030
EXPECT_EQ(10, (int)Time(14));
31+
EXPECT_EQ(10, (int)Time(15));
32+
EXPECT_EQ(10, (int)Time(19));
33+
EXPECT_EQ(0, (int)Time(5));
34+
}
35+
36+
TEST(lagi_time, srt_to_ass_truncates) {
37+
EXPECT_STREQ("0:00:49.46", Time("0:00:49,466").GetAssFormatted().c_str());
38+
EXPECT_STREQ("1:23:45.67", Time("1:23:45,678").GetAssFormatted().c_str());
3139
}
3240

3341
TEST(lagi_time, cs_formatting) {

0 commit comments

Comments
 (0)