obj.load(text)とsetfontをネイティブエンジンへ対応
このコミットが含まれているのは:
5ファイル変更
+178
-42
検索条件に一致するファイルはありません
@@ -10,6 +10,7 @@ namespace LuaScript.Tests
|
||||
|
||||
private static readonly Func<string, int, SceneObjectInfo?> NoResolver = (_, _) => null;
|
||||
private static readonly Func<string, int, double, double, double, (byte[] buffer, int w, int h)> NoLoadFigure = (_, _, _, _, _) => ([], 1, 1);
|
||||
private static readonly Func<string, string, double, bool, bool, int, (byte[] buffer, int w, int h)> NoLoadText = (_, _, _, _, _, _) => ([], 1, 1);
|
||||
private static readonly Action<string, System.Collections.Generic.IReadOnlyList<System.Collections.Generic.KeyValuePair<string, object>>> NoAddEffect = (_, _) => { };
|
||||
private static readonly Action<DrawCommand> NoAddDraw = _ => { };
|
||||
|
||||
@@ -37,7 +38,7 @@ namespace LuaScript.Tests
|
||||
|
||||
bool ok = _worker.Execute(
|
||||
"obj.rz = obj.time * 90\nobj.alpha = 128",
|
||||
fields, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||
fields, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.False(dirty);
|
||||
@@ -72,7 +73,7 @@ namespace LuaScript.Tests
|
||||
"local gray = r*0.299 + g*0.587 + b*0.114 " +
|
||||
"obj.setpixel(x,y,gray,gray,gray,a) end end";
|
||||
|
||||
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.True(dirty);
|
||||
@@ -107,7 +108,7 @@ namespace LuaScript.Tests
|
||||
"local gray=r*0.299+g*0.587+b*0.114 " +
|
||||
"pd:set(base+1,gray) pd:set(base+2,gray) pd:set(base+3,gray) end end";
|
||||
|
||||
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.True(dirty);
|
||||
@@ -143,7 +144,7 @@ namespace LuaScript.Tests
|
||||
for (int k = 1; k <= 5; k++)
|
||||
{
|
||||
var fields = Fields(2, 2, k);
|
||||
bool ok = _worker.Execute("obj.x = obj.time * 10", fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
bool ok = _worker.Execute("obj.x = obj.time * 10", fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(k * 10d, fields[NativeProtocol.X]);
|
||||
}
|
||||
@@ -158,12 +159,12 @@ namespace LuaScript.Tests
|
||||
var fields = Fields(2, 2, 0d);
|
||||
|
||||
bool timedOut = _worker.Execute(
|
||||
"local x=0 while true do x=x+1 end", fields, pixels, 2, 2, 1500, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
"local x=0 while true do x=x+1 end", fields, pixels, 2, 2, 1500, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
Assert.False(timedOut);
|
||||
Assert.Contains("timed out", error);
|
||||
|
||||
var fields2 = Fields(2, 2, 3d);
|
||||
bool ok = _worker.Execute("obj.x = obj.time", fields2, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out error);
|
||||
bool ok = _worker.Execute("obj.x = obj.time", fields2, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out error);
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(3d, fields2[NativeProtocol.X]);
|
||||
}
|
||||
@@ -185,7 +186,7 @@ namespace LuaScript.Tests
|
||||
"obj.zoom = o.zoom obj.rz = o.rz obj.alpha = o.alpha " +
|
||||
"obj.sx = o.sy obj.rzr = o.rzr";
|
||||
|
||||
bool ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, resolver, NoLoadFigure, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
bool ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, resolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(12d, fields[NativeProtocol.X]);
|
||||
@@ -217,13 +218,13 @@ namespace LuaScript.Tests
|
||||
"local b = obj.getobject(\"a\") " +
|
||||
"obj.x = a.x + b.x";
|
||||
|
||||
bool ok = _worker.Execute(script, Fields(2, 2, 0d), pixels, 2, 2, 5000, resolver, NoLoadFigure, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
bool ok = _worker.Execute(script, Fields(2, 2, 0d), pixels, 2, 2, 5000, resolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(1, calls);
|
||||
var fields = Fields(2, 2, 0d);
|
||||
|
||||
x = 20d;
|
||||
ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, resolver, NoLoadFigure, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out error);
|
||||
ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, resolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out error);
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(2, calls);
|
||||
Assert.Equal(40d, fields[NativeProtocol.X]);
|
||||
@@ -240,7 +241,7 @@ namespace LuaScript.Tests
|
||||
const string script =
|
||||
"local o = obj.getobject(\"missing\") obj.x = o == nil and 1 or 0";
|
||||
|
||||
bool ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
bool ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(1d, fields[NativeProtocol.X]);
|
||||
@@ -258,7 +259,7 @@ namespace LuaScript.Tests
|
||||
|
||||
bool ok = _worker.Execute(
|
||||
"obj.draw() obj.draw(10, 20, 30, 2, 0.5, 0.25)",
|
||||
fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, addDraw,
|
||||
fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, addDraw,
|
||||
out _, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
@@ -279,7 +280,7 @@ namespace LuaScript.Tests
|
||||
|
||||
bool ok = _worker.Execute(
|
||||
"obj.drawpoly(0,0,0, 10,0,0, 10,10,0, 0,10,0)",
|
||||
fields, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoAddEffect, addDraw,
|
||||
fields, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, addDraw,
|
||||
out _, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
@@ -301,7 +302,7 @@ namespace LuaScript.Tests
|
||||
|
||||
bool ok = _worker.Execute(
|
||||
"obj.drawpoly(0,0,0, 8,0,0, 8,8,0, 0,8,0, 1,1, 3,1, 3,3, 1,3, 0.5)",
|
||||
fields, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoAddEffect, addDraw,
|
||||
fields, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, addDraw,
|
||||
out _, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
@@ -322,7 +323,7 @@ namespace LuaScript.Tests
|
||||
|
||||
bool ok = _worker.Execute(
|
||||
"obj.setoption('antialias', 0) obj.x = obj.getoption('antialias') obj.y = obj.getoption('unset')",
|
||||
fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw,
|
||||
fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw,
|
||||
out _, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
@@ -341,7 +342,7 @@ namespace LuaScript.Tests
|
||||
|
||||
bool ok = _worker.Execute(
|
||||
"obj.draw() obj.setoption('antialias', 0) obj.draw()",
|
||||
Fields(2, 2, 0d), pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, addDraw,
|
||||
Fields(2, 2, 0d), pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, addDraw,
|
||||
out _, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
@@ -350,6 +351,52 @@ namespace LuaScript.Tests
|
||||
Assert.Equal(0d, commands[1].Antialias);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadText_RoundTripsThroughCallback()
|
||||
{
|
||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
||||
|
||||
const int tw = 3, th = 2;
|
||||
var rendered = new byte[tw * th * 4];
|
||||
for (int i = 0; i < rendered.Length; i++)
|
||||
rendered[i] = (byte)((i * 17 + 5) & 0xFF);
|
||||
|
||||
string? capturedFamily = null;
|
||||
string? capturedText = null;
|
||||
double capturedSize = 0;
|
||||
bool capturedBold = false, capturedItalic = false;
|
||||
int capturedColor = 0;
|
||||
Func<string, string, double, bool, bool, int, (byte[], int, int)> loadText =
|
||||
(family, text, size, bold, italic, color) =>
|
||||
{
|
||||
capturedFamily = family; capturedText = text; capturedSize = size;
|
||||
capturedBold = bold; capturedItalic = italic; capturedColor = color;
|
||||
return (rendered, tw, th);
|
||||
};
|
||||
|
||||
var pixels = new byte[4 * 4 * 4];
|
||||
var fields = Fields(4, 4, 0d);
|
||||
|
||||
bool ok = _worker.Execute(
|
||||
"obj.setfont('Meiryo', 40, 3, 0x112233) obj.load('text', 'Hi')",
|
||||
fields, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, loadText, NoAddEffect, NoAddDraw,
|
||||
out bool dirty, out bool bufferReplaced, out byte[]? newPixels, out int rw, out int rh, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal("Meiryo", capturedFamily);
|
||||
Assert.Equal("Hi", capturedText);
|
||||
Assert.Equal(40d, capturedSize);
|
||||
Assert.True(capturedBold);
|
||||
Assert.True(capturedItalic);
|
||||
Assert.Equal(0x112233, capturedColor);
|
||||
Assert.True(dirty);
|
||||
Assert.True(bufferReplaced);
|
||||
Assert.Equal(tw, rw);
|
||||
Assert.Equal(th, rh);
|
||||
Assert.NotNull(newPixels);
|
||||
Assert.Equal(rendered, newPixels!.AsSpan(0, rendered.Length).ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetValue_ReturnsObjFields()
|
||||
{
|
||||
@@ -361,7 +408,7 @@ namespace LuaScript.Tests
|
||||
|
||||
bool ok = _worker.Execute(
|
||||
"obj.x = obj.getvalue('track0') obj.y = obj.getvalue('alpha') obj.z = obj.getvalue('unknown')",
|
||||
fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw,
|
||||
fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw,
|
||||
out _, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
@@ -388,7 +435,7 @@ namespace LuaScript.Tests
|
||||
"for y=0,obj.h-1 do for x=0,obj.w-1 do obj.setpixel(x,y,0,0,0,0) end end " +
|
||||
"obj.copybuffer('obj','tmp')";
|
||||
|
||||
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.True(dirty);
|
||||
@@ -407,11 +454,11 @@ namespace LuaScript.Tests
|
||||
stored[3] = 255; stored[7] = 255; stored[11] = 255; stored[15] = 255;
|
||||
|
||||
var save = (byte[])stored.Clone();
|
||||
bool ok = _worker.Execute("obj.copybuffer('cache:foo','obj')", Fields(w, h, 0d), save, w, h, 5000, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
bool ok = _worker.Execute("obj.copybuffer('cache:foo','obj')", Fields(w, h, 0d), save, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
Assert.True(ok, error);
|
||||
|
||||
var blank = new byte[w * h * 4];
|
||||
ok = _worker.Execute("obj.copybuffer('obj','cache:foo')", Fields(w, h, 0d), blank, w, h, 5000, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out error);
|
||||
ok = _worker.Execute("obj.copybuffer('obj','cache:foo')", Fields(w, h, 0d), blank, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out bool dirty, out _, out _, out _, out _, out error);
|
||||
Assert.True(ok, error);
|
||||
Assert.True(dirty);
|
||||
Assert.Equal(stored, blank);
|
||||
@@ -425,12 +472,12 @@ namespace LuaScript.Tests
|
||||
var pixels = new byte[16];
|
||||
var fields = Fields(2, 2, 0d);
|
||||
|
||||
bool ok = _worker.Execute("obj.x = missing.value", fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
bool ok = _worker.Execute("obj.x = missing.value", fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out string? error);
|
||||
Assert.False(ok);
|
||||
Assert.False(string.IsNullOrEmpty(error));
|
||||
|
||||
var fields2 = Fields(2, 2, 7d);
|
||||
bool ok2 = _worker.Execute("obj.x = obj.time", fields2, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out error);
|
||||
bool ok2 = _worker.Execute("obj.x = obj.time", fields2, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoAddEffect, NoAddDraw, out _, out _, out _, out _, out _, out error);
|
||||
Assert.True(ok2, error);
|
||||
Assert.Equal(7d, fields2[NativeProtocol.X]);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
+58
-20
@@ -63,6 +63,7 @@ local CB_KIND_LOADFIGURE = 1
|
||||
local CB_KIND_EFFECT = 2
|
||||
local CB_KIND_DRAW = 3
|
||||
local CB_KIND_DRAWPOLY = 4
|
||||
local CB_KIND_LOADTEXT = 5
|
||||
|
||||
assert(loadfile(shimPath))()
|
||||
|
||||
@@ -174,26 +175,20 @@ function obj.rand(a, b, seed, frame)
|
||||
return aviutl_rand(a or 0, b or 0, seed or 0, frame or obj.frame or 0)
|
||||
end
|
||||
|
||||
function obj.load(kind, name, color, size, lineWidth, aspect)
|
||||
if kind ~= "figure" then return end
|
||||
name = name or ""
|
||||
color = color or 0
|
||||
size = size or 100
|
||||
lineWidth = lineWidth or 0
|
||||
aspect = aspect or 0
|
||||
local nameBytes = tostring(name)
|
||||
local len = #nameBytes
|
||||
if len > CB_TAG_MAX then len = CB_TAG_MAX end
|
||||
ffi.copy(base + CB_TAG_OFFSET, nameBytes, len)
|
||||
i32[OFF_CB_TAGLEN] = len
|
||||
i32[OFF_CB_KIND] = CB_KIND_LOADFIGURE
|
||||
cbResult[0] = color
|
||||
cbResult[1] = size
|
||||
cbResult[2] = lineWidth
|
||||
cbResult[3] = aspect
|
||||
i32[OFF_STATUS] = STATUS_CALLBACK
|
||||
k32.SetEvent(doneEvent)
|
||||
k32.WaitForSingleObject(workEvent, INFINITE)
|
||||
local font = { family = "", size = 34, bold = false, italic = false, color = 0xFFFFFF }
|
||||
|
||||
function obj.setfont(name, size, style, col1)
|
||||
if name ~= nil then font.family = tostring(name) end
|
||||
if size ~= nil then font.size = size end
|
||||
if style ~= nil then
|
||||
local s = math.floor(style)
|
||||
font.bold = (s % 2) == 1
|
||||
font.italic = (math.floor(s / 2) % 2) == 1
|
||||
end
|
||||
if col1 ~= nil then font.color = col1 end
|
||||
end
|
||||
|
||||
local function applyLoadResult()
|
||||
local newW = i32[OFF_LOAD_RESULT_W]
|
||||
local newH = i32[OFF_LOAD_RESULT_H]
|
||||
if newW > 0 and newH > 0 then
|
||||
@@ -210,6 +205,48 @@ function obj.load(kind, name, color, size, lineWidth, aspect)
|
||||
end
|
||||
end
|
||||
|
||||
local function loadFigure(name, color, size, lineWidth, aspect)
|
||||
local nameBytes = tostring(name or "")
|
||||
local len = #nameBytes
|
||||
if len > CB_TAG_MAX then len = CB_TAG_MAX end
|
||||
ffi.copy(base + CB_TAG_OFFSET, nameBytes, len)
|
||||
i32[OFF_CB_TAGLEN] = len
|
||||
i32[OFF_CB_KIND] = CB_KIND_LOADFIGURE
|
||||
cbResult[0] = color or 0
|
||||
cbResult[1] = size or 100
|
||||
cbResult[2] = lineWidth or 0
|
||||
cbResult[3] = aspect or 0
|
||||
i32[OFF_STATUS] = STATUS_CALLBACK
|
||||
k32.SetEvent(doneEvent)
|
||||
k32.WaitForSingleObject(workEvent, INFINITE)
|
||||
applyLoadResult()
|
||||
end
|
||||
|
||||
local function loadText(str)
|
||||
local payload = font.family .. "\0" .. tostring(str or "")
|
||||
local len = #payload
|
||||
if len > CB_TAG_MAX then len = CB_TAG_MAX end
|
||||
ffi.copy(base + CB_TAG_OFFSET, payload, len)
|
||||
i32[OFF_CB_TAGLEN] = len
|
||||
i32[OFF_CB_KIND] = CB_KIND_LOADTEXT
|
||||
cbResult[0] = font.size
|
||||
cbResult[1] = font.bold and 1 or 0
|
||||
cbResult[2] = font.italic and 1 or 0
|
||||
cbResult[3] = font.color
|
||||
i32[OFF_STATUS] = STATUS_CALLBACK
|
||||
k32.SetEvent(doneEvent)
|
||||
k32.WaitForSingleObject(workEvent, INFINITE)
|
||||
applyLoadResult()
|
||||
end
|
||||
|
||||
function obj.load(kind, ...)
|
||||
if kind == "figure" then
|
||||
loadFigure(...)
|
||||
elseif kind == "text" then
|
||||
loadText(...)
|
||||
end
|
||||
end
|
||||
|
||||
function obj.effect(name, ...)
|
||||
if type(name) ~= "string" then return end
|
||||
local args = { ... }
|
||||
@@ -467,6 +504,7 @@ while true do
|
||||
cacheTag = nil
|
||||
for k in pairs(options) do options[k] = nil end
|
||||
for k in pairs(pixeloptions) do pixeloptions[k] = nil end
|
||||
font.family = ""; font.size = 34; font.bold = false; font.italic = false; font.color = 0xFFFFFF
|
||||
math.randomseed(f64[31])
|
||||
setfenv(compiledChunk, sandbox)
|
||||
local ok, err = pcall(compiledChunk)
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする