Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickcontext2d.cpp File Reference

(f373e6407424bc23f0327b82a0b500d120339632)

#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 <QtCore/qpointer.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
 
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_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, 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 94 of file qquickcontext2d.cpp.

Referenced by QQuickJSContext2DPrototype::method_arc(), QQuickJSContext2DPrototype::method_arcTo(), QQuickJSContext2DPrototype::method_beginPath(), QQuickJSContext2DPrototype::method_bezierCurveTo(), QQuickJSContext2DPrototype::method_clearRect(), QQuickJSContext2DPrototype::method_clip(), QQuickJSContext2DPrototype::method_closePath(), QQuickJSContext2DPrototype::method_createConicalGradient(), QQuickJSContext2DPrototype::method_createImageData(), QQuickJSContext2DPrototype::method_createLinearGradient(), QQuickJSContext2DPrototype::method_createPattern(), QQuickJSContext2DPrototype::method_createRadialGradient(), QQuickJSContext2DPrototype::method_drawImage(), QQuickJSContext2DPrototype::method_ellipse(), QQuickJSContext2DPrototype::method_fill(), QQuickJSContext2DPrototype::method_fillRect(), QQuickJSContext2DPrototype::method_fillText(), QQuickJSContext2DPrototype::method_get_canvas(), QQuickJSContext2D::method_get_fillRule(), QQuickJSContext2D::method_get_fillStyle(), QQuickJSContext2D::method_get_font(), QQuickJSContext2D::method_get_globalAlpha(), QQuickJSContext2D::method_get_globalCompositeOperation(), QQuickJSContext2D::method_get_lineCap(), QQuickJSContext2D::method_get_lineDashOffset(), QQuickJSContext2D::method_get_lineJoin(), QQuickJSContext2D::method_get_lineWidth(), QQuickJSContext2D::method_get_miterLimit(), QQuickJSContext2D::method_get_shadowBlur(), QQuickJSContext2D::method_get_shadowColor(), QQuickJSContext2D::method_get_shadowOffsetX(), QQuickJSContext2D::method_get_shadowOffsetY(), QQuickJSContext2D::method_get_strokeStyle(), QQuickJSContext2D::method_get_textAlign(), QQuickJSContext2D::method_get_textBaseline(), QQuickJSContext2DPrototype::method_getImageData(), QQuickJSContext2DPrototype::method_getLineDash(), QQuickJSContext2DPrototype::method_isPointInPath(), QQuickJSContext2DPrototype::method_lineTo(), QQuickJSContext2DPrototype::method_measureText(), QQuickJSContext2DPrototype::method_moveTo(), QQuickJSContext2DPrototype::method_putImageData(), QQuickJSContext2DPrototype::method_quadraticCurveTo(), QQuickJSContext2DPrototype::method_rect(), QQuickJSContext2DPrototype::method_reset(), QQuickJSContext2DPrototype::method_resetTransform(), QQuickJSContext2DPrototype::method_restore(), QQuickJSContext2DPrototype::method_rotate(), QQuickJSContext2DPrototype::method_roundedRect(), QQuickJSContext2DPrototype::method_save(), QQuickJSContext2DPrototype::method_scale(), QQuickJSContext2DPrototype::method_setTransform(), QQuickJSContext2DPrototype::method_shear(), QQuickJSContext2DPrototype::method_stroke(), QQuickJSContext2DPrototype::method_strokeRect(), QQuickJSContext2DPrototype::method_strokeText(), QQuickJSContext2DPrototype::method_text(), QQuickJSContext2DPrototype::method_transform(), and QQuickJSContext2DPrototype::method_translate().

◆ CHECK_CONTEXT_SETTER

◆ CHECK_RGBA

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

Definition at line 100 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 318 of file qquickcontext2d.cpp.

Referenced by qt_font_from_string().

◆ qClamp

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

Definition at line 99 of file qquickcontext2d.cpp.

Referenced by qt_color_from_string().

Enumeration Type Documentation

◆ FontToken

enum FontToken
Enumerator
NoTokens 
FontStyle 
FontVariant 
FontWeight 

Definition at line 310 of file qquickcontext2d.cpp.

Function Documentation

◆ areCollinear()

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

Definition at line 4176 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 4111 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 219 of file qquickcontext2d.cpp.

References ch, QString::mid(), QString::push_back(), and qWarning.

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 173 of file qquickcontext2d.cpp.

References ok, and qWarning.

Referenced by qSetFontSizeFromToken().

+ Here is the caller graph for this function:

◆ qSetFontFamilyFromTokens()

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

Definition at line 277 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 189 of file qquickcontext2d.cpp.

References font, QStringView::left(), ok, qParseFontSizeFromToken(), qWarning, QStringView::right(), QFont::setPixelSize(), QFont::setPointSize(), 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_EXPORT QColor qt_color_from_string ( const QV4::Value & name)

Definition at line 101 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,
QImage && image )
static

Definition at line 937 of file qquickcontext2d.cpp.

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

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 332 of file qquickcontext2d.cpp.

References FontStyle, FontVariant, FontWeight, QStringView::mid(), NoTokens, Q_TRY_SET_TOKEN, qExtractFontFamiliesFromString(), qSetFontFamilyFromTokens(), qSetFontSizeFromToken(), qWarning, QString::remove(), QFont::SmallCaps, QStringView::split(), QFont::StyleItalic, QFont::StyleOblique, token, and QStringView::trimmed().

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 771 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 695 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 4131 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 4182 of file qquickcontext2d.cpp.

Referenced by QQuickContext2D::isPointInPath().

+ Here is the caller graph for this function: