Merge pull request #601 from mulle-nat/fxingtabs

Fixed text vanishing when the transform is vertically flipped
This commit is contained in:
Mikko Mononen 2020-12-21 12:07:08 +02:00 • committed by GitHub
commit e906c5bae5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2454,6 +2454,12 @@ static void nvg__renderText(NVGcontext* ctx, NVGvertex* verts, int nverts)
ctx->textTriCount += nverts/3;
}
static int nvg__isTransformFlipped(const float *xform)
{
float det = xform[0] * xform[3] - xform[2] * xform[1];
return( det < 0);
}
float nvgText(NVGcontext* ctx, float x, float y, const char* string, const char* end)
{
NVGstate* state = nvg__getState(ctx);
@ -2464,6 +2470,7 @@ float nvgText(NVGcontext* ctx, float x, float y, const char* string, const char*
float invscale = 1.0f / scale;
int cverts = 0;
int nverts = 0;
int isFlipped = nvg__isTransformFlipped(xform);
if (end == NULL)
end = string + strlen(string);
@ -2497,6 +2504,12 @@ float nvgText(NVGcontext* ctx, float x, float y, const char* string, const char*
break;
}
prevIter = iter;
if(isFlipped) {
float tmp;
tmp = q.y0; q.y0 = q.y1; q.y1 = tmp;
tmp = q.t0; q.t0 = q.t1; q.t1 = tmp;
}
// Transform corners.
nvgTransformPoint(&c[0],&c[1], state->xform, q.x0*invscale, q.y0*invscale);
nvgTransformPoint(&c[2],&c[3], state->xform, q.x1*invscale, q.y0*invscale);