mirror of
https://github.com/alibaba/GCanvas.git
synced 2025-12-08 17:36:42 +00:00
48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#include "CanvasPattern.h"
|
|
#include "NodeBindingUtil.h"
|
|
namespace NodeBinding
|
|
{
|
|
Napi::FunctionReference Pattern::constructor;
|
|
|
|
Pattern::Pattern(const Napi::CallbackInfo &info)
|
|
: Napi::ObjectWrap<Pattern>(info) {
|
|
if (info[0].IsNull())
|
|
{
|
|
this->repetition = "repeat";
|
|
return;
|
|
}
|
|
this->repetition = info[0].As<Napi::String>().Utf8Value();
|
|
if (this->repetition != "" &&
|
|
this->repetition != "repeat" &&
|
|
this->repetition != "repeat-x" && this->repetition != "repeat-y" &&
|
|
this->repetition != "no-repeat")
|
|
{
|
|
throwError(info, "repetition value wrong");
|
|
}
|
|
if (this->repetition == "")
|
|
{
|
|
this->repetition = "repeat";
|
|
}
|
|
}
|
|
|
|
Napi::Object Pattern::NewInstance(Napi::Env env, const Napi::Value arg) {
|
|
Napi::Object obj = constructor.New({arg});
|
|
obj.Set("name", Napi::String::New(env, "pattern"));
|
|
return obj;
|
|
}
|
|
|
|
void Pattern::Init(Napi::Env env) {
|
|
Napi::HandleScope scope(env);
|
|
|
|
Napi::Function func =
|
|
DefineClass(env,
|
|
"CanvasPattern",
|
|
{
|
|
|
|
});
|
|
constructor = Napi::Persistent(func);
|
|
constructor.SuppressDestruct();
|
|
}
|
|
|
|
const std::string &Pattern::getRepetition() { return this->repetition; }
|
|
} // namespace NodeBinding
|