From 6162ce5c1919af8ed35af5427cded8386b07b704 Mon Sep 17 00:00:00 2001 From: routersys Date: Fri, 3 Jul 2026 08:47:57 +0900 Subject: [PATCH] =?UTF-8?q?setfont=20=E3=81=AE=E5=BC=95=E6=95=B0=E8=A7=A3?= =?UTF-8?q?=E9=87=88=E3=82=92=20AviUtlFontState=20=E3=81=B8=E6=8A=BD?= =?UTF-8?q?=E5=87=BA=E3=81=97=E5=BA=8A=E5=89=B0=E4=BD=99=E3=81=A7=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=AB=E3=82=92=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript/AviUtlFontState.cs | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 LuaScript/AviUtlFontState.cs diff --git a/LuaScript/AviUtlFontState.cs b/LuaScript/AviUtlFontState.cs new file mode 100644 index 0000000..70bf733 --- /dev/null +++ b/LuaScript/AviUtlFontState.cs @@ -0,0 +1,44 @@ +using MoonSharp.Interpreter; + +namespace LuaScript +{ + internal sealed class AviUtlFontState + { + public string Family { get; private set; } = string.Empty; + public double Size { get; private set; } = 34d; + public bool Bold { get; private set; } + public bool Italic { get; private set; } + public int Color { get; private set; } = 0xFFFFFF; + + public void Reset() + { + Family = string.Empty; + Size = 34d; + Bold = false; + Italic = false; + Color = 0xFFFFFF; + } + + public void Apply(DynValue name, DynValue size, DynValue style, DynValue color) + { + if (name.Type == DataType.String) + Family = name.String; + else if (name.Type == DataType.Number) + Family = name.CastToString(); + + Size = size.CastToNumber() ?? Size; + + if (style.CastToNumber() is double styleNumber) + { + double flags = Math.Floor(styleNumber); + Bold = FloorMod(flags, 2d) == 1d; + Italic = FloorMod(Math.Floor(flags / 2d), 2d) == 1d; + } + + Color = (int)(color.CastToNumber() ?? Color); + } + + private static double FloorMod(double value, double divisor) => + value - Math.Floor(value / divisor) * divisor; + } +}