Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stroke, and Stroke Width attributes also used when drawing text. #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
9 changes: 6 additions & 3 deletions libshapes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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.
Expand Down