obj.load(text)とsetfontをネイティブエンジンへ対応

このコミットが含まれているのは:
routersys committed 2026-06-29 10:01:06 +09:00
1 親 c186a6b27d
コミット d2b518f611
5ファイル変更
+178 -42

検索条件に一致するファイルはありません

+41 -1
ファイルの表示
@@ -49,6 +49,7 @@ namespace LuaScript.Engine
int timeoutMs,
Func<string, int, SceneObjectInfo?> resolveObject,
Func<string, int, double, double, double, (byte[] buffer, int w, int h)> loadFigure,
Func<string, string, double, bool, bool, int, (byte[] buffer, int w, int h)> loadText,
Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect,
Action<DrawCommand> addDraw,
out bool pixelsDirty,
@@ -104,7 +105,7 @@ namespace LuaScript.Engine
if (status != NativeProtocol.StatusCallback)
break;
DispatchCallback(view, resolveObject, loadFigure, addEffect, addDraw);
DispatchCallback(view, resolveObject, loadFigure, loadText, addEffect, addDraw);
_workEvent.Set();
}
@@ -148,6 +149,7 @@ namespace LuaScript.Engine
MemoryMappedViewAccessor view,
Func<string, int, SceneObjectInfo?> resolveObject,
Func<string, int, double, double, double, (byte[] buffer, int w, int h)> loadFigure,
Func<string, string, double, bool, bool, int, (byte[] buffer, int w, int h)> loadText,
Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect,
Action<DrawCommand> addDraw)
{
@@ -160,6 +162,9 @@ namespace LuaScript.Engine
case NativeProtocol.CbKindLoadFigure:
ResolveLoadFigureCallback(view, loadFigure);
break;
case NativeProtocol.CbKindLoadText:
ResolveLoadTextCallback(view, loadText);
break;
case NativeProtocol.CbKindEffect:
ResolveEffectCallback(view, addEffect);
break;
@@ -262,6 +267,41 @@ namespace LuaScript.Engine
view.Write(NativeProtocol.OffCallbackFound, 1);
}
private void ResolveLoadTextCallback(
MemoryMappedViewAccessor view,
Func<string, string, double, bool, bool, int, (byte[] buffer, int w, int h)> loadText)
{
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
view.ReadArray(NativeProtocol.CallbackTagOffset, _callbackTag, 0, tagLen);
string payload = Encoding.UTF8.GetString(_callbackTag, 0, tagLen);
int separator = payload.IndexOf('\0');
string family = separator >= 0 ? payload[..separator] : string.Empty;
string text = separator >= 0 ? payload[(separator + 1)..] : payload;
long rOff = NativeProtocol.CallbackResultOffset;
double size = view.ReadDouble(rOff + 0 * 8);
bool bold = view.ReadDouble(rOff + 1 * 8) != 0;
bool italic = view.ReadDouble(rOff + 2 * 8) != 0;
int color = (int)view.ReadDouble(rOff + 3 * 8);
(byte[] buffer, int w, int h) result;
try { result = loadText(family, text, size, bold, italic, color); }
catch { result = (new byte[4], 1, 1); }
int pixelSize = result.w * result.h * 4;
long capacity = view.Capacity - NativeProtocol.PixelOffset;
if (pixelSize > capacity)
{
result = (new byte[4], 1, 1);
pixelSize = 4;
}
view.Write(NativeProtocol.OffLoadResultWidth, result.w);
view.Write(NativeProtocol.OffLoadResultHeight, result.h);
view.WriteArray(NativeProtocol.PixelOffset, result.buffer, 0, pixelSize);
view.Write(NativeProtocol.OffCallbackFound, 1);
}
private void ResolveEffectCallback(MemoryMappedViewAccessor view, Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect)
{
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
+1
ファイルの表示
@@ -48,6 +48,7 @@ namespace LuaScript.Engine
public const int CbKindEffect = 2;
public const int CbKindDraw = 3;
public const int CbKindDrawPoly = 4;
public const int CbKindLoadText = 5;
public const int CbExist = 0;
public const int CbX = 1;
+10
ファイルの表示
@@ -89,6 +89,7 @@ namespace LuaScript
private VideoEffectChain? _effectChain;
private DrawCompositor? _drawCompositor;
private TextRenderer? _nativeTextRenderer;
protected override ID2D1Image? CreateEffect(IGraphicsDevicesAndContext devices)
{
@@ -446,6 +447,7 @@ namespace LuaScript
script, _nativeFields, buffer, imgW, imgH, NativeTimeoutMilliseconds,
(tag, frame) => ctx.ResolveObject(tag, frame, out var info) ? info : null,
NativeLoadFigure,
NativeLoadText,
(name, args) => ctx.AddEffect(new AviUtlEffectRequest(name, args)),
ctx.AddDraw,
out bool dirty, out bool bufferReplaced, out byte[]? newPixels,
@@ -498,6 +500,13 @@ namespace LuaScript
return false;
}
private (byte[] buffer, int w, int h) NativeLoadText(string family, string text, double size, bool bold, bool italic, int color)
{
_nativeTextRenderer ??= new TextRenderer();
var buffer = _nativeTextRenderer.Render(text, family, size, bold, italic, color, out int w, out int h);
return (buffer, w, h);
}
private static (byte[] buffer, int w, int h) NativeLoadFigure(string name, int color, double size, double lineWidth, double aspect)
{
aspect = Math.Clamp(aspect, -1d, 1d);
@@ -531,6 +540,7 @@ namespace LuaScript
_nativeWorker?.Dispose();
_effectChain?.Dispose();
_drawCompositor?.Dispose();
_nativeTextRenderer?.Dispose();
_pixelLoaderSemaphore.Dispose();
_pixelManager?.Dispose();
_pixelManager = null;