Browse Source

Improved nvgTextGlyphPositions()

- added glyph min/max x
- fixed first glyph position
shared-context
Mikko Mononen 11 years ago
parent
commit
4cc5fd68d1
2 changed files with 5 additions and 5 deletions
  1. +3
    -4
      src/nanovg.c
  2. +2
    -1
      src/nanovg.h

+ 3
- 4
src/nanovg.c View File

@@ -2116,7 +2116,6 @@ int nvgTextGlyphPositions(struct NVGcontext* ctx, float x, float y, const char*
struct FONStextIter iter;
struct FONSquad q;
int npos = 0;
float px;

if (state->fontId == FONS_INVALID) return 0;

@@ -2132,12 +2131,12 @@ int nvgTextGlyphPositions(struct NVGcontext* ctx, float x, float y, const char*
fonsSetAlign(ctx->fs, state->textAlign);
fonsSetFont(ctx->fs, state->fontId);

px = x*scale;
fonsTextIterInit(ctx->fs, &iter, x*scale, y*scale, string, end);
while (fonsTextIterNext(ctx->fs, &iter, &q)) {
positions[npos].str = iter.str;
positions[npos].x = px * invscale;
px = iter.x;
positions[npos].x = iter.x * invscale;
positions[npos].minx = q.x0 * invscale;
positions[npos].maxx = q.x1 * invscale;
npos++;
if (npos >= maxPositions)
break;


+ 2
- 1
src/nanovg.h View File

@@ -89,7 +89,8 @@ enum NVGalpha {

struct NVGglyphPosition {
const char* str; // Position of the glyph in the input string.
float x; // The x- coordinate of the position of the glyph .
float x; // The x-coordinate of the logical glyph position.
float minx, maxx; // The bounds of the glyph shape.
};

struct NVGtextRow {


Loading…
Cancel
Save