diff options
author | Vincent Sanders <vince@kyllikki.org> | 2024-02-25 10:00:31 +0000 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2024-02-25 10:00:56 +0000 |
commit | edcece91624e87427709f96bf923fd5bc54636e4 (patch) | |
tree | 8d4bbe55d96d65bee1ed4dc8f9de9eb20e207ad0 | |
parent | bfb8ef933a42053c53d0f368eb4baa93903afbfb (diff) | |
download | netsurf-vince/qt6.tar.gz netsurf-vince/qt6.tar.bz2 |
call text ploting in layoutvince/qt6
-rw-r--r-- | frontends/qt/layout.cpp | 22 | ||||
-rw-r--r-- | frontends/qt/layout.h | 14 | ||||
-rw-r--r-- | frontends/qt/plotters.cpp | 22 |
3 files changed, 43 insertions, 15 deletions
diff --git a/frontends/qt/layout.cpp b/frontends/qt/layout.cpp index 3aab3ca80..110ab5f60 100644 --- a/frontends/qt/layout.cpp +++ b/frontends/qt/layout.cpp @@ -22,6 +22,7 @@ */ #include <stddef.h> +#include <QPainter> extern "C" { @@ -132,6 +133,27 @@ nsqt_layout_split(const struct plot_font_style *fstyle, return NSERROR_OK; } +/* exported interface documented in qt/layout.h */ +nserror +nsqt_layout_plot(QPainter* painter, + const struct plot_font_style *fstyle, + int x, + int y, + const char *text, + size_t length) +{ + QColor strokecolour(fstyle->foreground & 0xFF, + (fstyle->foreground & 0xFF00) >>8, + (fstyle->foreground & 0xFF0000) >>16); + QPen pen(strokecolour); + painter->setPen(pen); + + painter->drawText(x,y, QString::fromUtf8(text,length)); + + return NSERROR_OK; + +} + static struct gui_layout_table layout_table = { .width = nsqt_layout_width, .position = nsqt_layout_position, diff --git a/frontends/qt/layout.h b/frontends/qt/layout.h index 62173d69a..effae7f18 100644 --- a/frontends/qt/layout.h +++ b/frontends/qt/layout.h @@ -24,4 +24,18 @@ */ extern struct gui_layout_table *nsqt_layout_table; + +/** + * Text plotting. + * + * \param painter The QT painter to use + * \param fstyle plot style for this text + * \param x x coordinate + * \param y y coordinate + * \param text UTF-8 string to plot + * \param length length of string, in bytes + * \return NSERROR_OK on success else error code. + */ +nserror nsqt_layout_plot(QPainter* painter, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length); + #endif diff --git a/frontends/qt/plotters.cpp b/frontends/qt/plotters.cpp index 4d56a8522..9dda469ac 100644 --- a/frontends/qt/plotters.cpp +++ b/frontends/qt/plotters.cpp @@ -36,6 +36,7 @@ extern "C" { } #include "qt/window.h" +#include "qt/layout.h" #include "qt/plotters.h" @@ -296,22 +297,13 @@ nsqt_plot_bitmap(const struct redraw_context *ctx, */ static nserror nsqt_plot_text(const struct redraw_context *ctx, - const struct plot_font_style *fstyle, - int x, - int y, - const char *text, - size_t length) + const struct plot_font_style *fstyle, + int x, + int y, + const char *text, + size_t length) { - QPainter* painter = (QPainter*)ctx->priv; - QColor strokecolour(fstyle->foreground & 0xFF, - (fstyle->foreground & 0xFF00) >>8, - (fstyle->foreground & 0xFF0000) >>16); - QPen pen(strokecolour); - painter->setPen(pen); - - painter->drawText(x,y, QString::fromUtf8(text,length)); - - return NSERROR_OK; + return nsqt_layout_plot((QPainter*)ctx->priv, fstyle, x, y, text, length); } |