Merge pull request #184 from thedeemon/master

Fix bugs in Win32ColorDrawBuf, ColorDrawBuf and SimpleTextFormatter
This commit is contained in:
Vadim Lopatin 2016-03-04 08:41:22 +03:00
commit d47825e6aa
3 changed files with 17 additions and 11 deletions

View File

@ -475,13 +475,16 @@ class ColorDrawBufBase : DrawBuf {
} }
} }
import std.container.array;
/// Create mapping of source coordinates to destination coordinates, for resize. /// Create mapping of source coordinates to destination coordinates, for resize.
private int[] createMap(int dst0, int dst1, int src0, int src1) { private Array!int createMap(int dst0, int dst1, int src0, int src1, double k) {
int dd = dst1 - dst0; int dd = dst1 - dst0;
int sd = src1 - src0; //int sd = src1 - src0;
int[] res = new int[dd]; Array!int res;
res.length = dd;
foreach(int i; 0 .. dd) foreach(int i; 0 .. dd)
res[i] = src0 + i * sd / dd; res[i] = src0 + cast(int)(i * k);//sd / dd;
return res; return res;
} }
@ -490,11 +493,14 @@ class ColorDrawBufBase : DrawBuf {
//Log.d("drawRescaled ", dstrect, " <- ", srcrect); //Log.d("drawRescaled ", dstrect, " <- ", srcrect);
if (_alpha >= 254) if (_alpha >= 254)
return; // fully transparent - don't draw return; // fully transparent - don't draw
double kx = cast(double)srcrect.width / dstrect.width;
double ky = cast(double)srcrect.height / dstrect.height;
if (applyClipping(dstrect, srcrect)) { if (applyClipping(dstrect, srcrect)) {
int[] xmapArray = createMap(dstrect.left, dstrect.right, srcrect.left, srcrect.right); auto xmapArray = createMap(dstrect.left, dstrect.right, srcrect.left, srcrect.right, kx);
int[] ymapArray = createMap(dstrect.top, dstrect.bottom, srcrect.top, srcrect.bottom); auto ymapArray = createMap(dstrect.top, dstrect.bottom, srcrect.top, srcrect.bottom, ky);
int * xmap = xmapArray.ptr;
int * ymap = ymapArray.ptr; int * xmap = &xmapArray[0];
int * ymap = &ymapArray[0];
int dx = dstrect.width; int dx = dstrect.width;
int dy = dstrect.height; int dy = dstrect.height;
ColorDrawBufBase colorDrawBuf = cast(ColorDrawBufBase) src; ColorDrawBufBase colorDrawBuf = cast(ColorDrawBufBase) src;

View File

@ -502,8 +502,8 @@ struct SimpleTextFormatter {
if (ch == '\t' || ch == ' ') { if (ch == '\t' || ch == ' ') {
// track last word end // track last word end
if (prevChar != '\t' && prevChar != ' ' && prevChar != 0) { if (prevChar != '\t' && prevChar != ' ' && prevChar != 0) {
lastWordEnd = i - 1; lastWordEnd = i;
lastWordEndX = widths[i - 1]; lastWordEndX = widths[i];
} }
prevChar = ch; prevChar = ch;
continue; continue;

View File

@ -157,7 +157,7 @@ class Win32ColorDrawBuf : ColorDrawBufBase {
int len = _dx * _dy; int len = _dx * _dy;
//for (int i = 0; i < len; i++) //for (int i = 0; i < len; i++)
// _pixels[i] = color; // _pixels[i] = color;
_pixels[0 .. len - 1] = color; _pixels[0 .. len] = color;
} }
/// draw to win32 device context /// draw to win32 device context
void drawTo(HDC dc, int x, int y) { void drawTo(HDC dc, int x, int y) {