From ee5db6edaac74913f0b43f0725387779b8fb466e Mon Sep 17 00:00:00 2001 From: czechtech Date: Thu, 17 Apr 2014 20:43:24 -0400 Subject: [PATCH] Make Text drawing stroke-aware. Text can now be outlined in any color/width. --- README.md | 8 +++++--- libshapes.c | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6a034b7..7f73903 100644 --- a/README.md +++ b/README.md @@ -122,17 +122,19 @@ Draw an elliptical arc centered at (x, y), with width and height at (w, h). Sta ### Text and Images void Text(VGfloat x, VGfloat y, char* s, Fontinfo f, int pointsize) -Draw a the text srtring (s) at location (x,y), using pointsize. +Draw the text string (s) at location (x,y), using pointsize. void TextMid(VGfloat x, VGfloat y, char* s, Fontinfo f, int pointsize) -Draw a the text srtring (s) at centered at location (x,y), using pointsize. +Draw the text string (s) centered at location (x,y), using pointsize. void TextEnd(VGfloat x, VGfloat y, char* s, Fontinfo f, int pointsize) -Draw a the text srtring (s) at with its lend aligned to location (x,y), using pointsize +Draw the text string (s) with its left end aligned to location (x,y), using pointsize. VGfloat TextWidth(char *s, Fontinfo f, int pointsize) Return the width of text +Outlined text can be drawn by setting the appropriate Fill, Stroke, and Stroke Width [attributes](#attributes). + void Image(VGfloat x, VGfloat y, int w, int h, char * filename) place a JPEG image with dimensions (w,h) at (x,y). diff --git a/libshapes.c b/libshapes.c index 418f7e5..0111d7b 100644 --- a/libshapes.c +++ b/libshapes.c @@ -386,8 +386,10 @@ void FillRadialGradient(VGfloat cx, VGfloat cy, VGfloat fx, VGfloat fy, VGfloat // derived from http://web.archive.org/web/20070808195131/http://developer.hybrid.fi/font2openvg/renderFont.cpp.txt void Text(VGfloat x, VGfloat y, char *s, Fontinfo f, int pointsize) { VGfloat size = (VGfloat) pointsize, xx = x, mm[9]; + VGfloat strk = vgGetf(VG_STROKE_LINE_WIDTH); int i; - + + vgSetf(VG_STROKE_LINE_WIDTH, strk / size); // scaled size vgGetMatrix(mm); for (i = 0; i < (int)strlen(s); i++) { unsigned int character = (unsigned int)s[i]; @@ -402,10 +404,11 @@ void Text(VGfloat x, VGfloat y, char *s, Fontinfo f, int pointsize) { }; vgLoadMatrix(mm); vgMultMatrix(mat); - vgDrawPath(f.Glyphs[glyph], VG_FILL_PATH); + vgDrawPath(f.Glyphs[glyph], VG_FILL_PATH | VG_STROKE_PATH); xx += size * f.GlyphAdvances[glyph] / 65536.0f; } - vgLoadMatrix(mm); + vgLoadMatrix(mm); + vgSetf(VG_STROKE_LINE_WIDTH, strk); // return to unscaled stroke size } // TextWidth returns the width of a text string at the specified font and size.