6.7.0 - Alpha13 - 修复 Canvas 构造函数可接受的参数类型错误 (issue #402)
This commit is contained in:
@@ -42,6 +42,7 @@ import org.autojs.autojs.runtime.api.augment.automator.RootAutomator
|
||||
import org.autojs.autojs.runtime.api.augment.barcode.Barcode
|
||||
import org.autojs.autojs.runtime.api.augment.barcode.QrCode
|
||||
import org.autojs.autojs.runtime.api.augment.base64.Base64
|
||||
import org.autojs.autojs.runtime.api.augment.canvas.Canvas
|
||||
import org.autojs.autojs.runtime.api.augment.colors.Color
|
||||
import org.autojs.autojs.runtime.api.augment.colors.Colors
|
||||
import org.autojs.autojs.runtime.api.augment.console.Console
|
||||
@@ -755,6 +756,7 @@ class ScriptRuntime private constructor(builder: Builder) {
|
||||
Selector(this).augment(target, true, READONLY)
|
||||
Events(this).augment(target, events, true)
|
||||
Keys.augmentWithRuntime(target, this, true)
|
||||
Canvas(this).augment(target, false)
|
||||
Images(this).augment(target, true)
|
||||
Ocr(this).augment(target, true).also { ocr ->
|
||||
OcrMLKit(this).augment(ocr, false).also { augmentedOcrMLKit = it }
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.autojs.autojs.runtime.api.augment.canvas
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import org.autojs.autojs.core.graphics.ScriptCanvas
|
||||
import org.autojs.autojs.core.image.ImageWrapper
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsBrief
|
||||
import org.autojs.autojs.extension.FlexibleArray.Companion.component1
|
||||
import org.autojs.autojs.extension.FlexibleArray.Companion.component2
|
||||
import org.autojs.autojs.runtime.ScriptRuntime
|
||||
import org.autojs.autojs.runtime.api.augment.Augmentable
|
||||
import org.autojs.autojs.runtime.api.augment.Constructable
|
||||
import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException
|
||||
import org.autojs.autojs.util.RhinoUtils.coerceIntNumber
|
||||
import org.mozilla.javascript.Context
|
||||
import org.mozilla.javascript.Scriptable
|
||||
|
||||
@Suppress("unused")
|
||||
class Canvas(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime), Constructable {
|
||||
|
||||
init {
|
||||
originateKeyName()
|
||||
}
|
||||
|
||||
override fun construct(vararg args: Any?): Scriptable = ensureArgumentsAtMost(args, 2) { argList ->
|
||||
when (argList.size) {
|
||||
0 -> ScriptCanvas(scriptRuntime)
|
||||
1 -> when (val o = argList[0]) {
|
||||
is Bitmap -> ScriptCanvas(scriptRuntime, o)
|
||||
is ImageWrapper -> ScriptCanvas(scriptRuntime, o)
|
||||
else -> throw WrappedIllegalArgumentException("Invalid argument ${o.jsBrief()} for $key constructor")
|
||||
}
|
||||
2 -> {
|
||||
val (width, height) = argList
|
||||
require(width is Number) {
|
||||
"Argument \"width\" ${width.jsBrief()} for $key constructor must be a number"
|
||||
}
|
||||
require(height is Number) {
|
||||
"Argument \"height\" ${height.jsBrief()} for $key constructor must be a number"
|
||||
}
|
||||
ScriptCanvas(scriptRuntime, coerceIntNumber(width), coerceIntNumber(height))
|
||||
}
|
||||
else -> throw WrappedIllegalArgumentException("Invalid arguments length ${argList.size} for $key constructor")
|
||||
}.let { javaCanvas ->
|
||||
Context.javaToJS(javaCanvas, scriptRuntime.topLevelScope) as Scriptable
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -461,8 +461,9 @@ class Classes {
|
||||
@JvmField
|
||||
val JsWebView = org.autojs.autojs.core.ui.widget.JsWebView::class
|
||||
|
||||
@JvmField
|
||||
val Canvas = org.autojs.autojs.core.graphics.ScriptCanvas::class
|
||||
// @Comment by SuperMonster003 on Jan 3, 2026.
|
||||
// # @JvmField
|
||||
// # val Canvas = org.autojs.autojs.core.graphics.ScriptCanvas::class
|
||||
|
||||
@JvmField
|
||||
val EvaluatorException = org.mozilla.javascript.EvaluatorException::class
|
||||
|
||||
Reference in New Issue
Block a user