< prev index next >

src/java.desktop/share/classes/sun/java2d/marlin/Dasher.java

Print this page

        

*** 136,191 **** * @param dashLen length of the given dash array * @param phase a <code>float</code> containing the dash phase * @param recycleDashes true to indicate to recycle the given dash array * @return this instance */ ! Dasher init(final PathConsumer2D out, float[] dash, int dashLen, ! float phase, boolean recycleDashes) { this.out = out; // Normalize so 0 <= phase < dash[0] int sidx = 0; dashOn = true; float sum = 0.0f; ! for (float d : dash) { ! sum += d; } this.cycleLen = sum; float cycles = phase / sum; if (phase < 0.0f) { if (-cycles >= MAX_CYCLES) { phase = 0.0f; } else { int fullcycles = FloatMath.floor_int(-cycles); ! if ((fullcycles & dash.length & 1) != 0) { dashOn = !dashOn; } phase += fullcycles * sum; while (phase < 0.0f) { if (--sidx < 0) { ! sidx = dash.length - 1; } phase += dash[sidx]; dashOn = !dashOn; } } } else if (phase > 0.0f) { if (cycles >= MAX_CYCLES) { phase = 0.0f; } else { int fullcycles = FloatMath.floor_int(cycles); ! if ((fullcycles & dash.length & 1) != 0) { dashOn = !dashOn; } phase -= fullcycles * sum; float d; while (phase >= (d = dash[sidx])) { phase -= d; ! sidx = (sidx + 1) % dash.length; dashOn = !dashOn; } } } --- 136,192 ---- * @param dashLen length of the given dash array * @param phase a <code>float</code> containing the dash phase * @param recycleDashes true to indicate to recycle the given dash array * @return this instance */ ! Dasher init(final PathConsumer2D out, final float[] dash, final int dashLen, ! float phase, final boolean recycleDashes) { this.out = out; // Normalize so 0 <= phase < dash[0] int sidx = 0; dashOn = true; + // note: BasicStroke constructor checks dash elements and sum > 0 float sum = 0.0f; ! for (int i = 0; i < dashLen; i++) { ! sum += dash[i]; } this.cycleLen = sum; float cycles = phase / sum; if (phase < 0.0f) { if (-cycles >= MAX_CYCLES) { phase = 0.0f; } else { int fullcycles = FloatMath.floor_int(-cycles); ! if ((fullcycles & dashLen & 1) != 0) { dashOn = !dashOn; } phase += fullcycles * sum; while (phase < 0.0f) { if (--sidx < 0) { ! sidx = dashLen - 1; } phase += dash[sidx]; dashOn = !dashOn; } } } else if (phase > 0.0f) { if (cycles >= MAX_CYCLES) { phase = 0.0f; } else { int fullcycles = FloatMath.floor_int(cycles); ! if ((fullcycles & dashLen & 1) != 0) { dashOn = !dashOn; } phase -= fullcycles * sum; float d; while (phase >= (d = dash[sidx])) { phase -= d; ! sidx = (sidx + 1) % dashLen; dashOn = !dashOn; } } }
< prev index next >