From e911f6e83f58eb0ffbf893ff53bb64a12b2081f2 Mon Sep 17 00:00:00 2001 From: routersys Date: Fri, 3 Jul 2026 08:48:05 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=B3=E3=83=88=E7=8A=B6?= =?UTF-8?q?=E6=85=8B=E3=82=92=20AviUtlFontState=20=E3=81=B8=E3=81=AE?= =?UTF-8?q?=E5=A7=94=E8=AD=B2=E3=81=B8=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript/LuaScriptEngine.cs | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/LuaScript/LuaScriptEngine.cs b/LuaScript/LuaScriptEngine.cs index 910dea9..f69ccb2 100644 --- a/LuaScript/LuaScriptEngine.cs +++ b/LuaScript/LuaScriptEngine.cs @@ -60,11 +60,7 @@ namespace LuaScript private TextRenderer? _textRenderer; private ImageDecoder? _imageDecoder; private MovieDecoder? _movieDecoder; - private string _fontFamily = string.Empty; - private double _fontSize = 34d; - private bool _fontBold; - private bool _fontItalic; - private int _fontColor = 0xFFFFFF; + private readonly AviUtlFontState _fontState = new(); private Script? _script; private DynValue? _compiledChunk; @@ -219,11 +215,7 @@ namespace LuaScript _options.Clear(); _pixelOptions.Clear(); - _fontFamily = string.Empty; - _fontSize = 34d; - _fontBold = false; - _fontItalic = false; - _fontColor = 0xFFFFFF; + _fontState.Reset(); if (isFirstSetup) { @@ -552,20 +544,11 @@ namespace LuaScript obj["setfont"] = DynValue.NewCallback((_, args) => { _activeCancellation.ThrowIfCancellationRequested(); - if (args.Count == 0) - return DynValue.Void; - if (args[0].Type == DataType.String) - _fontFamily = args[0].String; - if (args.Count > 1) - _fontSize = args[1].CastToNumber() ?? _fontSize; - if (args.Count > 2) - { - int type = (int)(args[2].CastToNumber() ?? 0d); - _fontBold = (type & 1) != 0; - _fontItalic = (type & 2) != 0; - } - if (args.Count > 3) - _fontColor = (int)(args[3].CastToNumber() ?? _fontColor); + _fontState.Apply( + args.Count > 0 ? args[0] : DynValue.Nil, + args.Count > 1 ? args[1] : DynValue.Nil, + args.Count > 2 ? args[2] : DynValue.Nil, + args.Count > 3 ? args[3] : DynValue.Nil); return DynValue.Void; }); @@ -781,7 +764,7 @@ namespace LuaScript { _textRenderer ??= new TextRenderer(); var buffer = _textRenderer.Render( - text, _fontFamily, _fontSize, _fontBold, _fontItalic, _fontColor, + text, _fontState.Family, _fontState.Size, _fontState.Bold, _fontState.Italic, _fontState.Color, out int w, out int h); _activeContext!.ReplaceBuffer(buffer, w, h); RefreshObjDimensions();