From 5a319b4eb5e8221ca1f8d4a238550cbc9a8d8565 Mon Sep 17 00:00:00 2001 From: Fabien Bodard Date: Fri, 1 Jan 2010 22:19:11 +0000 Subject: [PATCH] [GB.GTK] * NEW: implement Paint.TextExtents [GB.QT4] * NEW: implement Paint.TextExtents git-svn-id: svn://localhost/gambas/trunk@2585 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- .../gb.chart/.src/{ => Styles}/_CSerie.class | 0 .../.src/{ => Styles}/_CStyleAreas.class | 0 .../.src/{ => Styles}/_CStyleBar.class | 0 .../.src/{ => Styles}/_CStyleColumns.class | 0 .../.src/{ => Styles}/_CStyleLine.class | 0 .../.src/{ => Styles}/_CStylePie.class | 0 .../.src/{ => Styles}/_CStylePlot.class | 0 gb.gtk/src/cpaint_impl.cpp | 23 +++++++++++++++++-- gb.qt4/src/cpaint_impl.cpp | 5 ++-- main/lib/draw/cpaint.c | 6 ++--- main/lib/draw/gb.paint.h | 2 +- 11 files changed, 28 insertions(+), 8 deletions(-) rename comp/src/gb.chart/.src/{ => Styles}/_CSerie.class (100%) rename comp/src/gb.chart/.src/{ => Styles}/_CStyleAreas.class (100%) rename comp/src/gb.chart/.src/{ => Styles}/_CStyleBar.class (100%) rename comp/src/gb.chart/.src/{ => Styles}/_CStyleColumns.class (100%) rename comp/src/gb.chart/.src/{ => Styles}/_CStyleLine.class (100%) rename comp/src/gb.chart/.src/{ => Styles}/_CStylePie.class (100%) rename comp/src/gb.chart/.src/{ => Styles}/_CStylePlot.class (100%) diff --git a/comp/src/gb.chart/.src/_CSerie.class b/comp/src/gb.chart/.src/Styles/_CSerie.class similarity index 100% rename from comp/src/gb.chart/.src/_CSerie.class rename to comp/src/gb.chart/.src/Styles/_CSerie.class diff --git a/comp/src/gb.chart/.src/_CStyleAreas.class b/comp/src/gb.chart/.src/Styles/_CStyleAreas.class similarity index 100% rename from comp/src/gb.chart/.src/_CStyleAreas.class rename to comp/src/gb.chart/.src/Styles/_CStyleAreas.class diff --git a/comp/src/gb.chart/.src/_CStyleBar.class b/comp/src/gb.chart/.src/Styles/_CStyleBar.class similarity index 100% rename from comp/src/gb.chart/.src/_CStyleBar.class rename to comp/src/gb.chart/.src/Styles/_CStyleBar.class diff --git a/comp/src/gb.chart/.src/_CStyleColumns.class b/comp/src/gb.chart/.src/Styles/_CStyleColumns.class similarity index 100% rename from comp/src/gb.chart/.src/_CStyleColumns.class rename to comp/src/gb.chart/.src/Styles/_CStyleColumns.class diff --git a/comp/src/gb.chart/.src/_CStyleLine.class b/comp/src/gb.chart/.src/Styles/_CStyleLine.class similarity index 100% rename from comp/src/gb.chart/.src/_CStyleLine.class rename to comp/src/gb.chart/.src/Styles/_CStyleLine.class diff --git a/comp/src/gb.chart/.src/_CStylePie.class b/comp/src/gb.chart/.src/Styles/_CStylePie.class similarity index 100% rename from comp/src/gb.chart/.src/_CStylePie.class rename to comp/src/gb.chart/.src/Styles/_CStylePie.class diff --git a/comp/src/gb.chart/.src/_CStylePlot.class b/comp/src/gb.chart/.src/Styles/_CStylePlot.class similarity index 100% rename from comp/src/gb.chart/.src/_CStylePlot.class rename to comp/src/gb.chart/.src/Styles/_CStylePlot.class diff --git a/gb.gtk/src/cpaint_impl.cpp b/gb.gtk/src/cpaint_impl.cpp index d773eef15..cc97d48f7 100644 --- a/gb.gtk/src/cpaint_impl.cpp +++ b/gb.gtk/src/cpaint_impl.cpp @@ -647,11 +647,29 @@ static void Text(GB_PAINT *d, const char *text, int len, float w, float h, int a /*static void RichText(GB_PAINT *d, const char *text, int len, float w, float h, int align) { draw_text(d, TRUE, text, len, w, h, align); -} +}*/ + static void TextExtents(GB_PAINT *d, const char *text, int len, GB_EXTENTS *ext) { -}*/ + PangoLayout *layout; + CFONT *font; + PangoRectangle *rect; + PangoRectangle *logrect; + + layout = pango_cairo_create_layout(CONTEXT(d)); + Paint_Font(d, FALSE, (GB_FONT *)&font); + gt_add_layout_from_font(layout, font->font); + pango_layout_set_text(layout, text, len); + pango_layout_get_extents(layout, rect, logrect); + + ext->x2 = (float)rect->width; + ext->y2 = (float)rect->height; + g_object_unref(layout); + g_object_unref(rect); + g_object_unref(logrect); +} + static void Matrix(GB_PAINT *d, int set, GB_TRANSFORM matrix) @@ -945,6 +963,7 @@ GB_PAINT_DESC PAINT_Interface = { LineTo, CurveTo, Text, + TextExtents, Matrix, SetBrush, { diff --git a/gb.qt4/src/cpaint_impl.cpp b/gb.qt4/src/cpaint_impl.cpp index 2334ee527..1470e50d8 100644 --- a/gb.qt4/src/cpaint_impl.cpp +++ b/gb.qt4/src/cpaint_impl.cpp @@ -623,7 +623,7 @@ static void Text(GB_PAINT *d, const char *text, int len, float w, float h, int a DRAW_text_with(PAINTER(d), text, len, pos.x(), pos.y(), w, h, align, draw_text_cb); } -/*static void TextExtents(GB_PAINT *d, const char *text, int len, GB_EXTENTS *ext) +static void TextExtents(GB_PAINT *d, const char *text, int len, GB_EXTENTS *ext) { QRectF rect = PAINTER(d)->boundingRect(QRectF(0, 0, d->width, d->height), Qt::AlignLeft | Qt::AlignTop | Qt::TextSingleLine | Qt::TextIncludeTrailingSpaces, QString::fromUtf8(text, len)); @@ -631,7 +631,7 @@ static void Text(GB_PAINT *d, const char *text, int len, float w, float h, int a ext->y1 = 0; ext->x2 = (float)rect.width(); ext->y2 = (float)rect.height(); -}*/ +} static void Matrix(GB_PAINT *d, int set, GB_TRANSFORM matrix) @@ -842,6 +842,7 @@ GB_PAINT_DESC PAINT_Interface = { LineTo, CurveTo, Text, + TextExtents, Matrix, SetBrush, { diff --git a/main/lib/draw/cpaint.c b/main/lib/draw/cpaint.c index 8cd87f8b4..6d19e8e7f 100644 --- a/main/lib/draw/cpaint.c +++ b/main/lib/draw/cpaint.c @@ -643,7 +643,7 @@ BEGIN_METHOD(Paint_RichText, GB_STRING text; GB_FLOAT x; GB_FLOAT y; GB_FLOAT w; END_METHOD */ -/*BEGIN_METHOD(Paint_TextExtents, GB_STRING text) +BEGIN_METHOD(Paint_TextExtents, GB_STRING text) PAINT_EXTENTS *extents; @@ -654,7 +654,7 @@ END_METHOD GB.ReturnObject(extents); -END_METHOD*/ +END_METHOD static PAINT_BRUSH *make_brush(GB_PAINT *d, GB_BRUSH brush) { @@ -913,7 +913,7 @@ GB_DESC PaintDesc[] = GB_STATIC_PROPERTY("Font", "Font", Paint_Font), GB_STATIC_METHOD("Text", NULL, Paint_Text, "(Text)s[(X)f(Y)f(Width)f(Height)f(Alignment)i)]"), //GB_STATIC_METHOD("RichText", NULL, Paint_RichText, "(Text)s[(X)f(Y)f(Width)f(Height)f(Alignment)i)]"), - //GB_STATIC_METHOD("TextExtents", "TextExtents", Paint_TextExtents, "(Text)s"), + GB_STATIC_METHOD("TextExtents", "PaintExtents", Paint_TextExtents, "(Text)s"), GB_STATIC_METHOD("Color", "PaintBrush", Paint_Color, "(Color)i"), GB_STATIC_METHOD("Image", "PaintBrush", Paint_Image, "(Image)Image;[(X)f(Y)f]"), diff --git a/main/lib/draw/gb.paint.h b/main/lib/draw/gb.paint.h index 1aa8f7e7c..dad9c8a15 100644 --- a/main/lib/draw/gb.paint.h +++ b/main/lib/draw/gb.paint.h @@ -164,7 +164,7 @@ typedef void (*Text)(GB_PAINT *d, const char *text, int len, float w, float h, int align); //void (*RichText)(GB_PAINT *d, const char *text, int len, float w, float h, int align); - //void (*TextExtents)(GB_PAINT *d, const char *text, int len, GB_EXTENTS *ext); + void (*TextExtents)(GB_PAINT *d, const char *text, int len, GB_EXTENTS *ext); void (*Matrix)(GB_PAINT *d, int set, GB_TRANSFORM matrix);