Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickcontext2d.cpp File Reference
#include "qquickcontext2d_p.h"
#include "qquickcontext2dcommandbuffer_p.h"
#include "qquickcanvasitem_p.h"
#include <private/qtquickglobal_p.h>
#include <private/qquickcontext2dtexture_p.h>
#include <private/qquickitem_p.h>
#include <qsgrendererinterface.h>
#include <QtQuick/private/qsgcontext_p.h>
#include <private/qquicksvgparser_p.h>
#include <private/qquickimage_p_p.h>
#include <qqmlinfo.h>
#include <qqmlengine.h>
#include <private/qv4domerrors_p.h>
#include <private/qv4engine_p.h>
#include <private/qv4object_p.h>
#include <private/qv4qobjectwrapper_p.h>
#include <private/qquickwindow_p.h>
#include <private/qv4value_p.h>
#include <private/qv4functionobject_p.h>
#include <private/qv4objectproto_p.h>
#include <private/qv4scopedvalue_p.h>
#include <private/qlocale_tools_p.h>
#include <QtCore/qmath.h>
#include <QtCore/qvector.h>
#include <QtCore/private/qnumeric_p.h>
#include <QtCore/QRunnable>
#include <QtGui/qguiapplication.h>
#include <private/qguiapplication_p.h>
#include <qpa/qplatformintegration.h>
#include <private/qsgdefaultrendercontext_p.h>
#include <cmath>
#include "moc_qquickcontext2d_p.cpp"
+ Include dependency graph for qquickcontext2d.cpp:

Go to the source code of this file.

Classes

class  QQuickContext2DEngineData
 
struct  QV4::Heap::QQuickJSContext2D
 
struct  QV4::Heap::QQuickJSContext2DPrototype
 
struct  QV4::Heap::QQuickContext2DStyle
 
struct  QV4::Heap::QQuickJSContext2DPixelData
 
struct  QV4::Heap::QQuickJSContext2DImageData
 
struct  QQuickJSContext2D
 
struct  QQuickJSContext2DPrototype
 
struct  QQuickContext2DStyle
 
struct  QQuickJSContext2DPixelData
 
struct  QQuickJSContext2DImageData
 

Namespaces

namespace  QV4
 \qmltype Particle \inqmlmodule QtQuick.Particles
 
namespace  QV4::Heap
 

Macros

#define CHECK_CONTEXT(r)
 \qmltype Context2D \instantiates QQuickContext2D \inqmlmodule QtQuick
 
#define CHECK_CONTEXT_SETTER(r)
 
#define qClamp(val, min, max)   qMin(qMax(val, min), max)
 
#define CHECK_RGBA(c)   (c == '-' || c == '.' || (c >=0 && c <= 9))
 
#define Q_TRY_SET_TOKEN(token, value, setStatement)
 

Enumerations

enum  FontToken { NoTokens = 0x00 , FontStyle = 0x01 , FontVariant = 0x02 , FontWeight = 0x04 }
 

Functions

Q_QUICK_PRIVATE_EXPORT QColor qt_color_from_string (const QV4::Value &name)
 
static int qParseFontSizeFromToken (QStringView fontSizeToken, bool &ok)
 
static bool qSetFontSizeFromToken (QFont &font, QStringView fontSizeToken)
 
static QStringList qExtractFontFamiliesFromString (QStringView fontFamiliesString)
 
static bool qSetFontFamilyFromTokens (QFont &font, const QStringList &fontFamilyTokens)
 
static QFont qt_font_from_string (const QString &fontString, const QFont &currentFont)
 
 DEFINE_OBJECT_VTABLE (QQuickJSContext2D)
 
 DEFINE_OBJECT_VTABLE (QQuickJSContext2DPrototype)
 
 DEFINE_OBJECT_VTABLE (QQuickContext2DStyle)
 
QImage qt_image_convolute_filter (const QImage &src, const QVector< qreal > &weights, int radius=0)
 
void qt_image_boxblur (QImage &image, int radius, bool quality)
 
static QPainter::CompositionMode qt_composite_mode_from_string (const QString &compositeOperator)
 
static QString qt_composite_mode_to_string (QPainter::CompositionMode op)
 
 DEFINE_OBJECT_VTABLE (QQuickJSContext2DPixelData)
 
 DEFINE_OBJECT_VTABLE (QQuickJSContext2DImageData)
 
static QV4::ReturnedValue qt_create_image_data (qreal w, qreal h, QV4::ExecutionEngine *v4, const QImage &image)
 
int baseLineOffset (QQuickContext2D::TextBaseLineType value, const QFontMetrics &metrics)
 
static int textAlignOffset (QQuickContext2D::TextAlignType value, const QFontMetrics &metrics, const QString &text)
 
static bool areCollinear (const QPointF &a, const QPointF &b, const QPointF &c)
 
static bool withinRange (qreal p, qreal a, qreal b)
 

Macro Definition Documentation

◆ CHECK_CONTEXT

#define CHECK_CONTEXT (   r)
Value:
if (!r || !r->d()->context() || !r->d()->context()->bufferValid()) \
THROW_GENERIC_ERROR("Not a Context2D object");
GLboolean r
[2]

\qmltype Context2D \instantiates QQuickContext2D \inqmlmodule QtQuick

Since
5.0

Provides 2D context for shapes on a Canvas item.

The Context2D object can be created by Canvas item's getContext() method:

Canvas {
id:canvas
onPaint:{
var ctx = canvas.getContext('2d');
//...
}
}
EGLContext ctx
GLenum GLuint id
[7]

The Context2D API implements the same \l {http://www.w3.org/TR/2dcontext}{W3C Canvas 2D Context API standard} with some enhanced features.

The Context2D API provides the rendering {context} which defines the methods and attributes needed to draw on the Canvas item. The following assigns the canvas rendering context to a {context} variable:

var context = mycanvas.getContext("2d")
static void * context

The Context2D API renders the canvas as a coordinate system whose origin (0,0) is at the top left corner, as shown in the figure below. Coordinates increase along the {x} axis from left to right and along the {y} axis from top to bottom of the canvas.

Definition at line 92 of file qquickcontext2d.cpp.

◆ CHECK_CONTEXT_SETTER

#define CHECK_CONTEXT_SETTER (   r)
Value:
if (!r || !r->d()->context() || !r->d()->context()->bufferValid()) \
THROW_GENERIC_ERROR("Not a Context2D object");

Definition at line 95 of file qquickcontext2d.cpp.

◆ CHECK_RGBA

#define CHECK_RGBA (   c)    (c == '-' || c == '.' || (c >=0 && c <= 9))

Definition at line 98 of file qquickcontext2d.cpp.

◆ Q_TRY_SET_TOKEN

#define Q_TRY_SET_TOKEN (   token,
  value,
  setStatement 
)
Value:
if (!(usedTokens & token)) { \
usedTokens |= token; \
setStatement; \
} else { \
qWarning().nospace() << "Context2D: Duplicate token " << QLatin1String(value) << " found in font string."; \
return currentFont; \
}
Token token
Definition keywords.cpp:444
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
QLatin1StringView QLatin1String
Definition qstringfwd.h:31

Definition at line 316 of file qquickcontext2d.cpp.

◆ qClamp

#define qClamp (   val,
  min,
  max 
)    qMin(qMax(val, min), max)

Definition at line 97 of file qquickcontext2d.cpp.

Enumeration Type Documentation

◆ FontToken

enum FontToken
Enumerator
NoTokens 
FontStyle 
FontVariant 
FontWeight 

Definition at line 308 of file qquickcontext2d.cpp.

Function Documentation

◆ areCollinear()

static bool areCollinear ( const QPointF a,
const QPointF b,
const QPointF c 
)
inlinestatic

Definition at line 4173 of file qquickcontext2d.cpp.

References qFuzzyCompare().

Referenced by QQuickContext2D::isPointInPath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ baseLineOffset()

int baseLineOffset ( QQuickContext2D::TextBaseLineType  value,
const QFontMetrics metrics 
)

Definition at line 4109 of file qquickcontext2d.cpp.

References QQuickContext2D::Alphabetic, QQuickContext2D::Bottom, QQuickContext2D::Hanging, QQuickContext2D::Middle, and QQuickContext2D::Top.

Referenced by QQuickContext2D::createTextGlyphs().

+ Here is the caller graph for this function:

◆ DEFINE_OBJECT_VTABLE() [1/5]

DEFINE_OBJECT_VTABLE ( QQuickContext2DStyle  )

◆ DEFINE_OBJECT_VTABLE() [2/5]

DEFINE_OBJECT_VTABLE ( QQuickJSContext2D  )

◆ DEFINE_OBJECT_VTABLE() [3/5]

DEFINE_OBJECT_VTABLE ( QQuickJSContext2DImageData  )

◆ DEFINE_OBJECT_VTABLE() [4/5]

DEFINE_OBJECT_VTABLE ( QQuickJSContext2DPixelData  )

◆ DEFINE_OBJECT_VTABLE() [5/5]

DEFINE_OBJECT_VTABLE ( QQuickJSContext2DPrototype  )

◆ qExtractFontFamiliesFromString()

static QStringList qExtractFontFamiliesFromString ( QStringView  fontFamiliesString)
static

Definition at line 217 of file qquickcontext2d.cpp.

References QStringView::at(), ch, QString::clear(), QString::isEmpty(), QStringView::mid(), QString::push_back(), qWarning, QStringView::size(), and QStringView::toString().

Referenced by qt_font_from_string().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qParseFontSizeFromToken()

static int qParseFontSizeFromToken ( QStringView  fontSizeToken,
bool &  ok 
)
static

Definition at line 171 of file qquickcontext2d.cpp.

References ok, qWarning, QStringView::toFloat(), and QStringView::trimmed().

Referenced by qSetFontSizeFromToken().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qSetFontFamilyFromTokens()

static bool qSetFontFamilyFromTokens ( QFont font,
const QStringList fontFamilyTokens 
)
static

Definition at line 275 of file qquickcontext2d.cpp.

References QFont::Cursive, QFont::defaultFamily(), QFont::Fantasy, font, QFontDatabase::hasFamily(), QFont::Monospace, qPrintable, qWarning, QFont::SansSerif, QFont::Serif, QFont::setFamily(), and QFont::setStyleHint().

Referenced by qt_font_from_string().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qSetFontSizeFromToken()

static bool qSetFontSizeFromToken ( QFont font,
QStringView  fontSizeToken 
)
static

Definition at line 187 of file qquickcontext2d.cpp.

References font, QStringView::left(), ok, qParseFontSizeFromToken(), qWarning, QStringView::right(), QFont::setPixelSize(), QFont::setPointSize(), QStringView::size(), and QStringView::trimmed().

Referenced by qt_font_from_string().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qt_color_from_string()

Q_QUICK_PRIVATE_EXPORT QColor qt_color_from_string ( const QV4::Value name)

Definition at line 99 of file qquickcontext2d.cpp.

References QString::data(), QColor::fromHsl(), QColor::fromRgba(), QColor::fromString(), hasAlpha(), ok, Q_UNUSED, qClamp, qRgba(), qRound(), qstrtod(), QString::size(), str, and QString::toUtf8().

Referenced by QQuickContext2DStyle::gradient_proto_addColorStop(), QQuickJSContext2D::method_set_fillStyle(), QQuickJSContext2D::method_set_shadowColor(), and QQuickJSContext2D::method_set_strokeStyle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qt_composite_mode_from_string()

◆ qt_composite_mode_to_string()

◆ qt_create_image_data()

static QV4::ReturnedValue qt_create_image_data ( qreal  w,
qreal  h,
QV4::ExecutionEngine v4,
const QImage image 
)
static

Definition at line 935 of file qquickcontext2d.cpp.

References QV4::MemoryManager::allocate(), QV4::Scoped< T >::asReturnedValue(), QV4::Scope::engine, QImage::Format_ARGB32, imageData, QV4::EngineBase::memoryManager, QQuickContext2DEngineData::pixelArrayProto, Q_ASSERT, qAbs(), qRound(), and QV4::PersistentValue::value().

Referenced by QQuickJSContext2DPrototype::method_createImageData(), and QQuickJSContext2DPrototype::method_getImageData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qt_font_from_string()

static QFont qt_font_from_string ( const QString fontString,
const QFont currentFont 
)
static

Definition at line 330 of file qquickcontext2d.cpp.

References FontStyle, FontVariant, FontWeight, QString::indexOf(), QString::isEmpty(), QStringView::isEmpty(), QString::lastIndexOf(), QStringView::mid(), QString::mid(), NoTokens, Q_TRY_SET_TOKEN, qExtractFontFamiliesFromString(), qSetFontFamilyFromTokens(), qSetFontSizeFromToken(), qWarning, QString::remove(), QFont::setBold(), QFont::setCapitalization(), QFont::setStyle(), QFont::setWeight(), QFont::SmallCaps, QStringView::split(), QFont::StyleItalic, QFont::StyleOblique, token, QStringView::trimmed(), and QStringView::truncate().

Referenced by QQuickJSContext2D::method_set_font().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qt_image_boxblur()

void qt_image_boxblur ( QImage image,
int  radius,
bool  quality 
)

Definition at line 769 of file qquickcontext2d.cpp.

References i, and qt_image_convolute_filter().

+ Here is the call graph for this function:

◆ qt_image_convolute_filter()

QImage qt_image_convolute_filter ( const QImage src,
const QVector< qreal > &  weights,
int  radius = 0 
)

Definition at line 693 of file qquickcontext2d.cpp.

References qAlpha(), qBlue(), qFloor(), qGreen(), qRed(), QRgb, qRgba(), qRound(), qSqrt(), and red.

Referenced by qt_image_boxblur().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ textAlignOffset()

static int textAlignOffset ( QQuickContext2D::TextAlignType  value,
const QFontMetrics metrics,
const QString text 
)
static

Definition at line 4129 of file qquickcontext2d.cpp.

References QQuickContext2D::Center, QQuickContext2D::End, QGuiApplication::layoutDirection, QQuickContext2D::Left, Qt::LeftToRight, QQuickContext2D::Right, QQuickContext2D::Start, and text.

Referenced by QQuickContext2D::createTextGlyphs().

+ Here is the caller graph for this function:

◆ withinRange()

static bool withinRange ( qreal  p,
qreal  a,
qreal  b 
)
inlinestatic

Definition at line 4179 of file qquickcontext2d.cpp.

Referenced by QQuickContext2D::isPointInPath().

+ Here is the caller graph for this function: