Handling division-by-zero situation in LineStroker, added MIN_CAPS_JOINS_WEIGHT constant in PGL

This commit is contained in:
codeanticode
2012-05-16 15:49:00 +00:00
parent 1cd006af19
commit 9cf0e725dd
4 changed files with 39 additions and 21 deletions

View File

@@ -111,6 +111,11 @@ public class PGL {
/** Maximum dimension of a texture used to hold font data. **/
public static final int MAX_FONT_TEX_SIZE = 256;
/** Minimum stroke weight needed to apply the full path stroking
* algorithm that properly generates caps and joing.
*/
public static final float MIN_CAPS_JOINS_WEIGHT = 2.1f;
/** Minimum array size to use arrayCopy method(). **/
static protected final int MIN_ARRAYCOPY_SIZE = 2;

View File

@@ -653,13 +653,15 @@ public class LineStroker extends LineSink {
long ldx = (long) (px0 - x0);
long ldy = (long) (py0 - y0);
long llen = lineLength(ldx, ldy);
long s = (long) lineWidth2 * 65536 / llen;
if (0 < llen) {
long s = (long) lineWidth2 * 65536 / llen;
int capx = x0 - (int) (ldx * s >> 16);
int capy = y0 - (int) (ldy * s >> 16);
int capx = x0 - (int) (ldx * s >> 16);
int capy = y0 - (int) (ldy * s >> 16);
emitLineTo(capx + omx, capy + omy);
emitLineTo(capx - omx, capy - omy);
emitLineTo(capx + omx, capy + omy);
emitLineTo(capx - omx, capy - omy);
}
}
for (int i = rindex - 2; i >= 0; i -= 2) {
@@ -674,13 +676,15 @@ public class LineStroker extends LineSink {
long ldx = (long) (sx1 - sx0);
long ldy = (long) (sy1 - sy0);
long llen = lineLength(ldx, ldy);
long s = (long) lineWidth2 * 65536 / llen;
if (0 < llen) {
long s = (long) lineWidth2 * 65536 / llen;
int capx = sx0 - (int) (ldx * s >> 16);
int capy = sy0 - (int) (ldy * s >> 16);
int capx = sx0 - (int) (ldx * s >> 16);
int capy = sy0 - (int) (ldy * s >> 16);
emitLineTo(capx - mx0, capy - my0);
emitLineTo(capx + mx0, capy + my0);
emitLineTo(capx - mx0, capy - my0);
emitLineTo(capx + mx0, capy + my0);
}
}
emitClose();