{
if (s instanceof BasicStroke == false)
{
return STROKE_SOLID;
}
final BasicStroke bs = (BasicStroke) s;
if (bs.getLineWidth() <= 0)
{
return STROKE_NONE;
}
final float[] dashes = bs.getDashArray();
if (dashes == null)
{
return STROKE_SOLID;
}
if (dashes.length < 2)
{
return STROKE_SOLID;
}
if (dashes.length == 3 || dashes.length == 5)
{
return STROKE_SOLID;
}
if (dashes.length == 2)
{
// maybe dashed or dotted ...
// if (dashes[0] < 2 && dashes[1] < 2) {
// return STROKE_DOTTED;
// }
final float factor = dashes[0] / dashes[1];
if (factor > 0.9 && factor < 1.1)
{
return STROKE_DASHED;
}
else if (factor < 0.1)
{
return STROKE_DOTTED;
}
// else ... not recognized ...
return STROKE_SOLID;
}
else if (dashes.length == 4)
{
// maybe a dot-dashed stroke ...
final float[] copyDashes = (float[]) dashes.clone();
Arrays.sort(copyDashes);
// the first value should be near zero ..
if (Math.abs(copyDashes[0] / bs.getLineWidth()) > 0.5)
{
// not recognized ..
return STROKE_SOLID;
}
// test that the first two values have the same size
final float factor1 = (2 * bs.getLineWidth()) / copyDashes[1];
final float factor2 = (2 * bs.getLineWidth()) / copyDashes[2];
final float factorBig = (2 * bs.getLineWidth()) / copyDashes[3];
if ((factor1 < 0.9 || factor1 > 1.1) ||
(factor2 < 0.9 || factor2 > 1.1))
{
// not recognized ...
return STROKE_SOLID;
}
if (factorBig < 0.4 || factorBig > 2.5)
{
return STROKE_DOT_DASH;
}
if (factorBig < 0.9 || factorBig > 1.1)
{
return STROKE_DOTTED;
}
return STROKE_DASHED;
}
else if (dashes.length == 6)
{
// maybe a dot-dashed stroke ...
final float[] copyDashes = (float[]) dashes.clone();
Arrays.sort(copyDashes);
// test that the first three values have the same size
// the first two values should be near zero ..
if (Math.abs(copyDashes[0] / bs.getLineWidth()) > 0.5)
{
// not recognized ..
return STROKE_SOLID;
}
if (Math.abs(copyDashes[1] / bs.getLineWidth()) > 0.5)
{
// not recognized ..
return STROKE_SOLID;
}
final float factor2 = (2 * bs.getLineWidth()) / copyDashes[2];
final float factor3 = (2 * bs.getLineWidth()) / copyDashes[3];
final float factor4 = (2 * bs.getLineWidth()) / copyDashes[4];
final float factorBig = (2 * bs.getLineWidth()) / copyDashes[5];
if ((factor2 < 0.9 || factor2 > 1.1) ||
(factor3 < 0.9 || factor3 > 1.1) ||
(factor4 < 0.9 || factor4 > 1.1))
{