Fill in QFontMetrics methods
This commit is contained in:
parent
7af718b834
commit
a4a961666a
@ -38,4 +38,11 @@ class DLL_EXPORT QFontMetricsWrap : public Napi::ObjectWrap<QFontMetricsWrap> {
|
||||
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);
|
||||
};
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include "QtGui/QFontMetrics/qfontmetrics_wrap.h"
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtCore/QRect/qrect_wrap.h"
|
||||
#include "QtCore/QSize/qsize_wrap.h"
|
||||
#include "QtGui/QFont/qfont_wrap.h"
|
||||
|
||||
@ -31,6 +32,14 @@ Napi::Object QFontMetricsWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
InstanceMethod("swap", &QFontMetricsWrap::swap),
|
||||
InstanceMethod("underlinePos", &QFontMetricsWrap::underlinePos),
|
||||
InstanceMethod("xHeight", &QFontMetricsWrap::xHeight),
|
||||
InstanceMethod("maxWidth", &QFontMetricsWrap::maxWidth),
|
||||
InstanceMethod("minLeftBearing", &QFontMetricsWrap::minLeftBearing),
|
||||
InstanceMethod("minRightBearing", &QFontMetricsWrap::minRightBearing),
|
||||
InstanceMethod("inFontUcs4", &QFontMetricsWrap::inFontUcs4),
|
||||
InstanceMethod("boundingRect", &QFontMetricsWrap::boundingRect),
|
||||
InstanceMethod("tightBoundingRect",
|
||||
&QFontMetricsWrap::tightBoundingRect),
|
||||
InstanceMethod("elidedText", &QFontMetricsWrap::elidedText),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QFontMetricsWrap)});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
@ -227,3 +236,68 @@ Napi::Value QFontMetricsWrap::xHeight(const Napi::CallbackInfo& info) {
|
||||
|
||||
return Napi::Value::From(env, this->instance->xHeight());
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsWrap::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 QFontMetricsWrap::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 QFontMetricsWrap::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 QFontMetricsWrap::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 QFontMetricsWrap::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());
|
||||
QRect result = this->instance->boundingRect(text);
|
||||
auto resultInstance = QRectWrap::constructor.New(
|
||||
{Napi::External<QRect>::New(env, new QRect(result))});
|
||||
return resultInstance;
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsWrap::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());
|
||||
QRect result = this->instance->tightBoundingRect(text);
|
||||
auto resultInstance = QRectWrap::constructor.New(
|
||||
{Napi::External<QRect>::New(env, new QRect(result))});
|
||||
return resultInstance;
|
||||
}
|
||||
|
||||
Napi::Value QFontMetricsWrap::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());
|
||||
}
|
||||
|
||||
@ -3,7 +3,8 @@ import { Component, NativeElement } from '../core/Component';
|
||||
import { QFont } from './QFont';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
import { QSize } from '../QtCore/QSize';
|
||||
import { TextFlag } from '../QtEnums';
|
||||
import { TextElideMode, TextFlag } from '../QtEnums';
|
||||
import { QRect } from '../..';
|
||||
|
||||
export class QFontMetrics extends Component {
|
||||
native: NativeElement;
|
||||
@ -20,6 +21,7 @@ export class QFontMetrics extends Component {
|
||||
this.native = new addon.QFontMetrics(arg.native);
|
||||
}
|
||||
}
|
||||
// *** Public Functions ***
|
||||
|
||||
/** Returns the ascent of the font */
|
||||
ascent(): number {
|
||||
@ -31,6 +33,10 @@ export class QFontMetrics extends Component {
|
||||
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();
|
||||
@ -41,6 +47,10 @@ export class QFontMetrics extends Component {
|
||||
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();
|
||||
@ -61,6 +71,10 @@ export class QFontMetrics extends Component {
|
||||
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();
|
||||
@ -80,6 +94,15 @@ export class QFontMetrics extends Component {
|
||||
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 {
|
||||
@ -111,6 +134,10 @@ export class QFontMetrics extends Component {
|
||||
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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user