#include "node.h" using namespace Napi; #define ADD_PROC_FUNCTION(name) obj.Set(#name, Napi::Function::New(env)); #define DEFINE_FUNCTION(name) Napi::Value name(Napi::CallbackInfo const &info) DEFINE_FUNCTION(GetTextSize) { auto text = info[0].As().Utf8Value(); auto fontFace = info[1].As().Int32Value(); auto fontScale = info[2].As().DoubleValue(); auto thickness = info[3].As().Int32Value(); int baseLine; auto size = cv::getTextSize(text, fontFace, fontScale, thickness, &baseLine); auto res = Object::New(info.Env()); res.Set("width", Number::New(info.Env(), size.width)); res.Set("height", Number::New(info.Env(), size.height)); res.Set("baseLine", Number::New(info.Env(), baseLine)); return res; } DEFINE_FUNCTION(GetFontScaleFromHeight) { auto fontFace = info[0].As().Int32Value(); auto pixelHeight = info[1].As().Int32Value(); auto thickness = info[2].As().Int32Value(); return Number::New(info.Env(), cv::getFontScaleFromHeight(fontFace, pixelHeight, thickness)); } void InitProcAPI(Napi::Env env, Napi::Object exports) { auto obj = Object::New(env); ADD_PROC_FUNCTION(GetTextSize); exports.Set("util", obj); }