Add QSizeF and QFontMetricsF
This commit is contained in:
parent
481062423e
commit
bd6b127358
@ -55,6 +55,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QEvent/QDragLeaveEvent/qdragleaveevent_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QFontDatabase/qfontdatabase_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QFontMetrics/qfontmetrics_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QFontMetricsF/qfontmetricsf_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QPicture/qpicture_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QPixmap/qpixmap_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QIcon/qicon_wrap.cpp"
|
||||
@ -73,6 +74,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QObject/qobject_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QVariant/qvariant_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QSize/qsize_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QSizeF/qsizef_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QSettings/qsettings_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QRect/qrect_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QRectF/qrectf_wrap.cpp"
|
||||
|
||||
30
src/cpp/include/nodegui/QtCore/QSizeF/qsizef_wrap.h
Normal file
30
src/cpp/include/nodegui/QtCore/QSizeF/qsizef_wrap.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
#include <QSizeF>
|
||||
|
||||
#include "Extras/Export/export.h"
|
||||
#include "core/Component/component_macro.h"
|
||||
|
||||
class DLL_EXPORT QSizeFWrap : public Napi::ObjectWrap<QSizeFWrap> {
|
||||
COMPONENT_WRAPPED_METHODS_DECLARATION
|
||||
private:
|
||||
std::unique_ptr<QSizeF> instance;
|
||||
|
||||
public:
|
||||
static Napi::FunctionReference constructor;
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QSizeFWrap(const Napi::CallbackInfo& info);
|
||||
~QSizeFWrap();
|
||||
QSizeF* getInternalInstance();
|
||||
// Wrapped methods
|
||||
Napi::Value setHeight(const Napi::CallbackInfo& info);
|
||||
Napi::Value setWidth(const Napi::CallbackInfo& info);
|
||||
Napi::Value height(const Napi::CallbackInfo& info);
|
||||
Napi::Value width(const Napi::CallbackInfo& info);
|
||||
};
|
||||
|
||||
namespace StaticQSizeFWrapMethods {
|
||||
DLL_EXPORT Napi::Value fromQVariant(const Napi::CallbackInfo& info);
|
||||
} // namespace StaticQSizeFWrapMethods
|
||||
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
#include <QFontMetricsF>
|
||||
|
||||
#include "Extras/Export/export.h"
|
||||
#include "core/Component/component_macro.h"
|
||||
|
||||
class DLL_EXPORT QFontMetricsFWrap
|
||||
: public Napi::ObjectWrap<QFontMetricsFWrap> {
|
||||
COMPONENT_WRAPPED_METHODS_DECLARATION
|
||||
|
||||
private:
|
||||
std::unique_ptr<QFontMetricsF> instance;
|
||||
|
||||
public:
|
||||
static Napi::FunctionReference constructor;
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QFontMetricsFWrap(const Napi::CallbackInfo& info);
|
||||
QFontMetricsF* getInternalInstance();
|
||||
// Wrapped methods
|
||||
Napi::Value ascent(const Napi::CallbackInfo& info);
|
||||
Napi::Value averageCharWidth(const Napi::CallbackInfo& info);
|
||||
Napi::Value capHeight(const Napi::CallbackInfo& info);
|
||||
Napi::Value descent(const Napi::CallbackInfo& info);
|
||||
Napi::Value fontDpi(const Napi::CallbackInfo& info);
|
||||
Napi::Value height(const Napi::CallbackInfo& info);
|
||||
Napi::Value horizontalAdvance(const Napi::CallbackInfo& info);
|
||||
Napi::Value inFont(const Napi::CallbackInfo& info);
|
||||
Napi::Value leading(const Napi::CallbackInfo& info);
|
||||
Napi::Value leftBearing(const Napi::CallbackInfo& info);
|
||||
Napi::Value lineSpacing(const Napi::CallbackInfo& info);
|
||||
Napi::Value lineWidth(const Napi::CallbackInfo& info);
|
||||
Napi::Value overlinePos(const Napi::CallbackInfo& info);
|
||||
Napi::Value rightBearing(const Napi::CallbackInfo& info);
|
||||
Napi::Value size(const Napi::CallbackInfo& info);
|
||||
Napi::Value strikeOutPos(const Napi::CallbackInfo& info);
|
||||
Napi::Value swap(const Napi::CallbackInfo& info);
|
||||
Napi::Value underlinePos(const Napi::CallbackInfo& info);
|
||||
Napi::Value xHeight(const Napi::CallbackInfo& info);
|
||||
Napi::Value maxWidth(const Napi::CallbackInfo& info);
|
||||
Napi::Value minLeftBearing(const Napi::CallbackInfo& info);
|
||||
Napi::Value minRightBearing(const Napi::CallbackInfo& info);
|
||||
Napi::Value inFontUcs4(const Napi::CallbackInfo& info);
|
||||
Napi::Value boundingRect(const Napi::CallbackInfo& info);
|
||||
Napi::Value tightBoundingRect(const Napi::CallbackInfo& info);
|
||||
Napi::Value elidedText(const Napi::CallbackInfo& info);
|
||||
};
|
||||
86
src/cpp/lib/QtCore/QSizeF/qsizef_wrap.cpp
Normal file
86
src/cpp/lib/QtCore/QSizeF/qsizef_wrap.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
#include "QtCore/QSizeF/qsizef_wrap.h"
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtCore/QVariant/qvariant_wrap.h"
|
||||
|
||||
Napi::FunctionReference QSizeFWrap::constructor;
|
||||
|
||||
Napi::Object QSizeFWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QSizeF";
|
||||
Napi::Function func = DefineClass(
|
||||
env, CLASSNAME,
|
||||
{InstanceMethod("setHeight", &QSizeFWrap::setHeight),
|
||||
InstanceMethod("setWidth", &QSizeFWrap::setWidth),
|
||||
InstanceMethod("height", &QSizeFWrap::height),
|
||||
InstanceMethod("width", &QSizeFWrap::width),
|
||||
StaticMethod("fromQVariant", &StaticQSizeFWrapMethods::fromQVariant),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QSizeFWrap)});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
QSizeFWrap::QSizeFWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QSizeFWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if (info.Length() == 2) {
|
||||
int width = info[0].As<Napi::Number>().Int32Value();
|
||||
int height = info[1].As<Napi::Number>().Int32Value();
|
||||
this->instance = std::make_unique<QSizeF>(width, height);
|
||||
} else if (info.Length() == 1) {
|
||||
this->instance =
|
||||
std::unique_ptr<QSizeF>(info[0].As<Napi::External<QSizeF>>().Data());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<QSizeF>();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
this->rawData = extrautils::configureComponent(this->getInternalInstance());
|
||||
}
|
||||
|
||||
QSizeFWrap::~QSizeFWrap() { this->instance.reset(); }
|
||||
|
||||
QSizeF* QSizeFWrap::getInternalInstance() { return this->instance.get(); }
|
||||
|
||||
Napi::Value QSizeFWrap::setHeight(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
qreal height = info[0].As<Napi::Number>().FloatValue();
|
||||
this->instance->setHeight(height);
|
||||
return env.Null();
|
||||
}
|
||||
Napi::Value QSizeFWrap::setWidth(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
qreal width = info[0].As<Napi::Number>().FloatValue();
|
||||
this->instance->setWidth(width);
|
||||
return env.Null();
|
||||
}
|
||||
Napi::Value QSizeFWrap::height(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
return Napi::Value::From(env, this->instance->height());
|
||||
}
|
||||
Napi::Value QSizeFWrap::width(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
return Napi::Value::From(env, this->instance->width());
|
||||
}
|
||||
|
||||
Napi::Value StaticQSizeFWrapMethods::fromQVariant(
|
||||
const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
Napi::Object variantObject = info[0].As<Napi::Object>();
|
||||
QVariantWrap* variantWrap =
|
||||
Napi::ObjectWrap<QVariantWrap>::Unwrap(variantObject);
|
||||
QVariant* variant = variantWrap->getInternalInstance();
|
||||
QSizeF size = variant->value<QSizeF>();
|
||||
auto instance = QSizeFWrap::constructor.New({Napi::External<QSizeF>::New(
|
||||
env, new QSizeF(size.width(), size.height()))});
|
||||
return instance;
|
||||
}
|
||||
304
src/cpp/lib/QtGui/QFontMetricsF/qfontmetricsf_wrap.cpp
Normal file
304
src/cpp/lib/QtGui/QFontMetricsF/qfontmetricsf_wrap.cpp
Normal file
@ -0,0 +1,304 @@
|
||||
#include "QtGui/QFontMetricsF/qfontmetricsf_wrap.h"
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtCore/QRectF/qrectf_wrap.h"
|
||||
#include "QtCore/QSizeF/qsizef_wrap.h"
|
||||
#include "QtGui/QFont/qfont_wrap.h"
|
||||
|
||||
Napi::FunctionReference QFontMetricsFWrap::constructor;
|
||||
|
||||
Napi::Object QFontMetricsFWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QFontMetricsF";
|
||||
Napi::Function func = DefineClass(
|
||||
env, CLASSNAME,
|
||||
{InstanceMethod("ascent", &QFontMetricsFWrap::ascent),
|
||||
InstanceMethod("averageCharWidth", &QFontMetricsFWrap::averageCharWidth),
|
||||
InstanceMethod("capHeight", &QFontMetricsFWrap::capHeight),
|
||||
InstanceMethod("descent", &QFontMetricsFWrap::descent),
|
||||
InstanceMethod("fontDpi", &QFontMetricsFWrap::fontDpi),
|
||||
InstanceMethod("height", &QFontMetricsFWrap::height),
|
||||
InstanceMethod("horizontalAdvance",
|
||||
&QFontMetricsFWrap::horizontalAdvance),
|
||||
InstanceMethod("inFont", &QFontMetricsFWrap::inFont),
|
||||
InstanceMethod("leading", &QFontMetricsFWrap::leading),
|
||||
InstanceMethod("leftBearing", &QFontMetricsFWrap::leftBearing),
|
||||
InstanceMethod("lineSpacing", &QFontMetricsFWrap::lineSpacing),
|
||||
InstanceMethod("lineWidth", &QFontMetricsFWrap::lineWidth),
|
||||
InstanceMethod("overlinePos", &QFontMetricsFWrap::overlinePos),
|
||||
InstanceMethod("rightBearing", &QFontMetricsFWrap::rightBearing),
|
||||
InstanceMethod("size", &QFontMetricsFWrap::size),
|
||||
InstanceMethod("strikeOutPos", &QFontMetricsFWrap::strikeOutPos),
|
||||
InstanceMethod("swap", &QFontMetricsFWrap::swap),
|
||||
InstanceMethod("underlinePos", &QFontMetricsFWrap::underlinePos),
|
||||
InstanceMethod("xHeight", &QFontMetricsFWrap::xHeight),
|
||||
InstanceMethod("maxWidth", &QFontMetricsFWrap::maxWidth),
|
||||
InstanceMethod("minLeftBearing", &QFontMetricsFWrap::minLeftBearing),
|
||||
InstanceMethod("minRightBearing", &QFontMetricsFWrap::minRightBearing),
|
||||
InstanceMethod("inFontUcs4", &QFontMetricsFWrap::inFontUcs4),
|
||||
InstanceMethod("boundingRect", &QFontMetricsFWrap::boundingRect),
|
||||
InstanceMethod("tightBoundingRect",
|
||||
&QFontMetricsFWrap::tightBoundingRect),
|
||||
InstanceMethod("elidedText", &QFontMetricsFWrap::elidedText),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QFontMetricsFWrap)});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
QFontMetricsFWrap::QFontMetricsFWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QFontMetricsFWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if (info.Length() == 1) {
|
||||
if (info[0].IsExternal()) {
|
||||
this->instance = std::unique_ptr<QFontMetricsF>(
|
||||
info[0].As<Napi::External<QFontMetricsF>>().Data());
|
||||
} else {
|
||||
Napi::Object wrap0_0 = info[0].As<Napi::Object>();
|
||||
QFontWrap* wrap0_1 = Napi::ObjectWrap<QFontWrap>::Unwrap(wrap0_0);
|
||||
this->instance =
|
||||
std::make_unique<QFontMetricsF>(*wrap0_1->getInternalInstance());
|
||||
}
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
this->rawData = extrautils::configureComponent(this->getInternalInstance());
|
||||
}
|
||||
|
||||
QFontMetricsF* QFontMetricsFWrap::getInternalInstance() {
|
||||
return this->instance.get();
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::ascent(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
return Napi::Value::From(env, this->instance->ascent());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::averageCharWidth(
|
||||
const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
return Napi::Value::From(env, this->instance->averageCharWidth());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::capHeight(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
return Napi::Value::From(env, this->instance->capHeight());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::descent(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
return Napi::Value::From(env, this->instance->descent());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::fontDpi(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
return Napi::Value::From(env, this->instance->fontDpi());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::height(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
return Napi::Value::From(env, this->instance->height());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::horizontalAdvance(
|
||||
const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
std::string format = info[0].As<Napi::String>().Utf8Value();
|
||||
QString text = QString::fromUtf8(format.c_str());
|
||||
if (info.Length() <= 2 && text.length() == 1) {
|
||||
return Napi::Value::From(env, this->instance->horizontalAdvance(text[0]));
|
||||
} else if (info.Length() == 2) {
|
||||
int len = info[1].As<Napi::Number>().Int32Value();
|
||||
return Napi::Value::From(env, this->instance->horizontalAdvance(text, len));
|
||||
} else {
|
||||
Napi::TypeError::New(env,
|
||||
"Invalid number of arguments to horizontalAdvance")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::inFont(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
char ch = info[0].As<Napi::String>().Utf8Value()[0];
|
||||
return Napi::Boolean::New(env, this->instance->inFont(ch));
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::leading(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
return Napi::Value::From(env, this->instance->leading());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::leftBearing(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
char ch = info[0].As<Napi::String>().Utf8Value()[0];
|
||||
return Napi::Boolean::New(env, this->instance->leftBearing(ch));
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::lineSpacing(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
return Napi::Value::From(env, this->instance->lineSpacing());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::lineWidth(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
return Napi::Value::From(env, this->instance->lineWidth());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::overlinePos(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
return Napi::Value::From(env, this->instance->overlinePos());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::rightBearing(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
char ch = info[0].As<Napi::String>().Utf8Value()[0];
|
||||
return Napi::Boolean::New(env, this->instance->rightBearing(ch));
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::size(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if (info.Length() != 2 && info.Length() != 3) {
|
||||
Napi::TypeError::New(env, "Invalid number of arguments to size")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
int flags = info[0].As<Napi::Number>().Int32Value();
|
||||
std::string format = info[1].As<Napi::String>().Utf8Value();
|
||||
QString text = QString::fromUtf8(format.c_str());
|
||||
int tabStops = info[2].As<Napi::Number>().Int32Value();
|
||||
QSizeF size = this->instance->size(flags, text, tabStops);
|
||||
auto instance = QSizeFWrap::constructor.New(
|
||||
{Napi::External<QSizeF>::New(env, new QSizeF(size))});
|
||||
return instance;
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::strikeOutPos(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
return Napi::Value::From(env, this->instance->strikeOutPos());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::swap(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object wrap0_0 = info[0].As<Napi::Object>();
|
||||
QFontMetricsFWrap* wrap0_1 =
|
||||
Napi::ObjectWrap<QFontMetricsFWrap>::Unwrap(wrap0_0);
|
||||
this->instance->swap(*wrap0_1->getInternalInstance());
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::underlinePos(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
return Napi::Value::From(env, this->instance->underlinePos());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::xHeight(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
return Napi::Value::From(env, this->instance->xHeight());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::maxWidth(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
int result = this->instance->maxWidth();
|
||||
return Napi::Number::New(env, result);
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::minLeftBearing(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
int result = this->instance->minLeftBearing();
|
||||
return Napi::Number::New(env, result);
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::minRightBearing(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
int result = this->instance->minRightBearing();
|
||||
return Napi::Number::New(env, result);
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::inFontUcs4(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
uint ucs4 = info[0].As<Napi::Number>().Uint32Value();
|
||||
bool result = this->instance->inFontUcs4(ucs4);
|
||||
return Napi::Boolean::New(env, result);
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::boundingRect(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
std::string textNapiText = info[0].As<Napi::String>().Utf8Value();
|
||||
QString text = QString::fromUtf8(textNapiText.c_str());
|
||||
QRectF result = this->instance->boundingRect(text);
|
||||
auto resultInstance = QRectFWrap::constructor.New(
|
||||
{Napi::External<QRectF>::New(env, new QRectF(result))});
|
||||
return resultInstance;
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::tightBoundingRect(
|
||||
const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
std::string textNapiText = info[0].As<Napi::String>().Utf8Value();
|
||||
QString text = QString::fromUtf8(textNapiText.c_str());
|
||||
QRectF result = this->instance->tightBoundingRect(text);
|
||||
auto resultInstance = QRectFWrap::constructor.New(
|
||||
{Napi::External<QRectF>::New(env, new QRectF(result))});
|
||||
return resultInstance;
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsFWrap::elidedText(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
std::string textNapiText = info[0].As<Napi::String>().Utf8Value();
|
||||
QString text = QString::fromUtf8(textNapiText.c_str());
|
||||
Qt::TextElideMode mode =
|
||||
static_cast<Qt::TextElideMode>(info[1].As<Napi::Number>().Int32Value());
|
||||
int width = info[2].As<Napi::Number>().Int32Value();
|
||||
int flags = info[3].As<Napi::Number>().Int32Value();
|
||||
QString result = this->instance->elidedText(text, mode, width, flags);
|
||||
return Napi::String::New(env, result.toStdString());
|
||||
}
|
||||
@ -14,6 +14,7 @@
|
||||
#include "QtCore/QRectF/qrectf_wrap.h"
|
||||
#include "QtCore/QSettings/qsettings_wrap.h"
|
||||
#include "QtCore/QSize/qsize_wrap.h"
|
||||
#include "QtCore/QSizeF/qsizef_wrap.h"
|
||||
#include "QtCore/QTime/qtime_wrap.h"
|
||||
#include "QtCore/QUrl/qurl_wrap.h"
|
||||
#include "QtCore/QVariant/qvariant_wrap.h"
|
||||
@ -35,6 +36,7 @@
|
||||
#include "QtGui/QFont/qfont_wrap.h"
|
||||
#include "QtGui/QFontDatabase/qfontdatabase_wrap.h"
|
||||
#include "QtGui/QFontMetrics/qfontmetrics_wrap.h"
|
||||
#include "QtGui/QFontMetricsF/qfontmetricsf_wrap.h"
|
||||
#include "QtGui/QIcon/qicon_wrap.h"
|
||||
#include "QtGui/QImage/qimage_wrap.h"
|
||||
#include "QtGui/QKeySequence/qkeysequence_wrap.h"
|
||||
@ -131,6 +133,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
|
||||
QRectWrap::init(env, exports);
|
||||
QRectFWrap::init(env, exports);
|
||||
QSizeWrap::init(env, exports);
|
||||
QSizeFWrap::init(env, exports);
|
||||
QTimeWrap::init(env, exports);
|
||||
QUrlWrap::init(env, exports);
|
||||
QVariantWrap::init(env, exports);
|
||||
@ -145,6 +148,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
|
||||
QKeySequenceWrap::init(env, exports);
|
||||
QFontDatabaseWrap::init(env, exports);
|
||||
QFontMetricsWrap::init(env, exports);
|
||||
QFontMetricsFWrap::init(env, exports);
|
||||
QIconWrap::init(env, exports);
|
||||
QImageWrap::init(env, exports);
|
||||
QFontWrap::init(env, exports);
|
||||
|
||||
@ -20,6 +20,7 @@ export { QClipboard, QClipboardMode } from './lib/QtGui/QClipboard';
|
||||
export { QStyle, QStylePixelMetric } from './lib/QtGui/QStyle';
|
||||
export { QFontDatabase, SystemFont, WritingSystem } from './lib/QtGui/QFontDatabase';
|
||||
export { QFontMetrics } from './lib/QtGui/QFontMetrics';
|
||||
export { QFontMetricsF } from './lib/QtGui/QFontMetricsF';
|
||||
// Events: Maybe a separate module ?
|
||||
export { QKeyEvent } from './lib/QtGui/QEvent/QKeyEvent';
|
||||
export { QMouseEvent } from './lib/QtGui/QEvent/QMouseEvent';
|
||||
@ -150,6 +151,7 @@ export { QMimeData } from './lib/QtCore/QMimeData';
|
||||
export { QObject, QObjectSignals, NodeObject } from './lib/QtCore/QObject';
|
||||
export { QVariant } from './lib/QtCore/QVariant';
|
||||
export { QSize } from './lib/QtCore/QSize';
|
||||
export { QSizeF } from './lib/QtCore/QSizeF';
|
||||
export { QRect } from './lib/QtCore/QRect';
|
||||
export { QRectF } from './lib/QtCore/QRectF';
|
||||
export { QPoint } from './lib/QtCore/QPoint';
|
||||
|
||||
36
src/lib/QtCore/QSizeF.ts
Normal file
36
src/lib/QtCore/QSizeF.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { NativeElement, Component } from '../core/Component';
|
||||
import addon from '../utils/addon';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
import { QVariant } from './QVariant';
|
||||
|
||||
export class QSizeF extends Component {
|
||||
native: NativeElement;
|
||||
constructor();
|
||||
constructor(nativeElement: NativeElement);
|
||||
constructor(width?: number, height?: number);
|
||||
constructor(arg?: number | NativeElement, height?: number) {
|
||||
super();
|
||||
if (!arg) {
|
||||
this.native = new addon.QSizeF();
|
||||
} else if (checkIfNativeElement(arg)) {
|
||||
this.native = arg as NativeElement;
|
||||
} else {
|
||||
this.native = new addon.QSizeF(arg, height);
|
||||
}
|
||||
}
|
||||
setWidth(width: number): void {
|
||||
return this.native.setWidth(width);
|
||||
}
|
||||
width(): number {
|
||||
return this.native.width();
|
||||
}
|
||||
setHeight(height: number): void {
|
||||
return this.native.setHeight(height);
|
||||
}
|
||||
height(): number {
|
||||
return this.native.height();
|
||||
}
|
||||
static fromQVariant(variant: QVariant): QSizeF {
|
||||
return new QSizeF(addon.QSizeF.fromQVariant(variant.native));
|
||||
}
|
||||
}
|
||||
181
src/lib/QtGui/QFontMetricsF.ts
Normal file
181
src/lib/QtGui/QFontMetricsF.ts
Normal file
@ -0,0 +1,181 @@
|
||||
import addon from '../utils/addon';
|
||||
import { Component, NativeElement } from '../core/Component';
|
||||
import { QFont } from './QFont';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
import { QSize } from '../QtCore/QSize';
|
||||
import { TextElideMode, TextFlag } from '../QtEnums';
|
||||
import { QRect } from '../..';
|
||||
|
||||
export class QFontMetricsF extends Component {
|
||||
native: NativeElement;
|
||||
constructor(native: NativeElement);
|
||||
constructor(qfont: QFont);
|
||||
constructor(qfontmetricsf: QFontMetricsF);
|
||||
constructor(arg: QFont | QFontMetricsF | NativeElement) {
|
||||
super();
|
||||
if (checkIfNativeElement(arg)) {
|
||||
this.native = arg as NativeElement;
|
||||
} else if (arg instanceof QFontMetricsF) {
|
||||
this.native = arg.native;
|
||||
} else {
|
||||
this.native = new addon.QFontMetricsF(arg.native);
|
||||
}
|
||||
}
|
||||
// *** Public Functions ***
|
||||
|
||||
/** Returns the ascent of the font */
|
||||
ascent(): number {
|
||||
return this.native.ascent();
|
||||
}
|
||||
|
||||
/** Returns the average width of glyphs in the font */
|
||||
averageCharWidth(): number {
|
||||
return this.native.averageCharWidth();
|
||||
}
|
||||
|
||||
boundingRect(text: string): QRect {
|
||||
return new QRect(this.native.boundingRect(text));
|
||||
}
|
||||
|
||||
/** Returns the cap height of the font */
|
||||
capHeight(): number {
|
||||
return this.native.capHeight();
|
||||
}
|
||||
|
||||
/** Returns the descent of the font */
|
||||
descent(): number {
|
||||
return this.native.descent();
|
||||
}
|
||||
|
||||
elidedText(text: string, mode: TextElideMode, width: number, flags = 0): string {
|
||||
return this.native.elidedText(text, mode, width, flags);
|
||||
}
|
||||
|
||||
/** Returns the font DPI */
|
||||
fontDpi(): number {
|
||||
return this.native.fontDpi();
|
||||
}
|
||||
|
||||
/** Returns the height of the font */
|
||||
height(): number {
|
||||
return this.native.height();
|
||||
}
|
||||
|
||||
/** Returns the horizontal advance in pixels of the first len characters of text. If len is negative (the default), the entire string is used */
|
||||
horizontalAdvance(text: string, len = -1): number {
|
||||
return this.native.horizontalAdvance(text, len);
|
||||
}
|
||||
|
||||
/** Returns true if character ch is a valid character in the font; otherwise returns false */
|
||||
inFont(text: string): number {
|
||||
return this.native.inFont(text);
|
||||
}
|
||||
|
||||
inFontUcs4(ucs4: number): boolean {
|
||||
return this.native.inFontUcs4(ucs4);
|
||||
}
|
||||
|
||||
/** Returns the leading of the font */
|
||||
leading(): number {
|
||||
return this.native.leading();
|
||||
}
|
||||
|
||||
/** Returns the left bearing of character ch in the font */
|
||||
leftBearing(text: string): number {
|
||||
return this.native.leftBearing(text);
|
||||
}
|
||||
|
||||
/** Returns the distance from one base line to the next */
|
||||
lineSpacing(): number {
|
||||
return this.native.lineSpacing();
|
||||
}
|
||||
|
||||
/** Returns the width of the underline and strikeout lines, adjusted for the point size of the font */
|
||||
lineWidth(): number {
|
||||
return this.native.lineWidth();
|
||||
}
|
||||
maxWidth(): number {
|
||||
return this.native.maxWidth();
|
||||
}
|
||||
minLeftBearing(): number {
|
||||
return this.native.minLeftBearing();
|
||||
}
|
||||
minRightBearing(): number {
|
||||
return this.native.minRightBearing();
|
||||
}
|
||||
|
||||
/** Returns the distance from the base line to where an overline should be drawn */
|
||||
overlinePos(): number {
|
||||
return this.native.overlinePos();
|
||||
}
|
||||
|
||||
/** Returns the right bearing of character ch in the font */
|
||||
rightBearing(text: string): number {
|
||||
return this.native.rightBearing(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size in pixels of text
|
||||
*
|
||||
* See QtEnums::TextFlag for flags
|
||||
*/
|
||||
size(flags: TextFlag, text: string, tabStops = 0): QSize {
|
||||
const native = this.native.size(flags, text, tabStops);
|
||||
return new QSize(native);
|
||||
}
|
||||
|
||||
/** Returns the distance from the base line to where the strikeout line should be drawn */
|
||||
strikeOutPos(): number {
|
||||
return this.native.strikeOutPos();
|
||||
}
|
||||
|
||||
/** Swaps metrics other with this metrics. This operation is very fast and never fails */
|
||||
swap(other: QFontMetricsF): void {
|
||||
return this.native.swap(other.native);
|
||||
}
|
||||
|
||||
tightBoundingRect(text: string): QRect {
|
||||
return new QRect(this.native.tightBoundingRect(text));
|
||||
}
|
||||
|
||||
/** Returns the distance from the base line to where an underscore should be drawn */
|
||||
underlinePos(): number {
|
||||
return this.native.underlinePos();
|
||||
}
|
||||
|
||||
/** Returns the 'x' height of the font. This is often but not always the same as the height of the character 'x'. */
|
||||
xHeight(): number {
|
||||
return this.native.xHeight();
|
||||
}
|
||||
// TODO: qreal ascent() const
|
||||
// TODO: qreal averageCharWidth() const
|
||||
// TODO: QRectF boundingRect(const QString &text) const
|
||||
// TODO: QRectF boundingRect(QChar ch) const
|
||||
// TODO: QRectF boundingRect(const QRectF &rect, int flags, const QString &text, int tabStops = 0, int *tabArray = nullptr) const
|
||||
// TODO: qreal capHeight() const
|
||||
// TODO: qreal descent() const
|
||||
// TODO: QString elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags = 0) const
|
||||
// TODO: qreal fontDpi() const
|
||||
// TODO: qreal height() const
|
||||
// TODO: qreal horizontalAdvance(const QString &text, int length = -1) const
|
||||
// TODO: qreal horizontalAdvance(QChar ch) const
|
||||
// TODO: bool inFont(QChar ch) const
|
||||
// TODO: bool inFontUcs4(uint ch) const
|
||||
// TODO: qreal leading() const
|
||||
// TODO: qreal leftBearing(QChar ch) const
|
||||
// TODO: qreal lineSpacing() const
|
||||
// TODO: qreal lineWidth() const
|
||||
// TODO: qreal maxWidth() const
|
||||
// TODO: qreal minLeftBearing() const
|
||||
// TODO: qreal minRightBearing() const
|
||||
// TODO: qreal overlinePos() const
|
||||
// TODO: qreal rightBearing(QChar ch) const
|
||||
// TODO: QSizeF size(int flags, const QString &text, int tabStops = 0, int *tabArray = nullptr) const
|
||||
// TODO: qreal strikeOutPos() const
|
||||
// TODO: void swap(QFontMetricsF &other)
|
||||
// TODO: QRectF tightBoundingRect(const QString &text) const
|
||||
// TODO: qreal underlinePos() const
|
||||
// TODO: qreal xHeight() const
|
||||
// TODO: bool operator!=(const QFontMetricsF &other) const
|
||||
// TODO: bool operator==(const QFontMetricsF &other) const
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user