void compute() {
float lt1;
float ln1;
float lt2;
float ln2;
FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, true);
gv = font.createGlyphVector(frc, str);
Rectangle2D r = gv.getLogicalBounds();
w = r.getWidth();
angle = 0;
int nseg = llpoints.length / 2 - 1;
lt1 = llpoints[0];
ln1 = llpoints[1];
llp1.setLatLon(lt1, ln1, true);
lt2 = llpoints[2 * nseg];
ln2 = llpoints[2 * nseg + 1];
llp2.setLatLon(lt2, ln2, true);
distance = GreatCircle.spherical_distance(lt1, ln1, lt2, ln2)
* Planet.wgs84_earthEquatorialRadiusMeters;
//System.out.println(nseg+" "+llp1+" "+llp2);
setNeedToRegenerate(true);
visible = false;
float[] ds = new float[nseg];
float[] az = new float[nseg];
float[] cs = new float[nseg];
int j = 2;
float s = 0;
float corr = 0;
float dz;
float az0 = 0;
for (int i = 0; i < nseg; i++) {
//if(j>llpoints.length-2){System.out.println(j+" "+i+"
// "+nseg);nseg=1;break;}
lt2 = (float) llpoints[j++];
ln2 = (float) llpoints[j++];
if (lt2 == lt1 && ln2 == ln1) {
// suppress null segments
i--;
nseg--;
} else {
s += GreatCircle.spherical_distance(lt1, ln1, lt2, ln2);
ds[i] = s;
az[i] = GreatCircle.spherical_azimuth(lt1, ln1, lt2, ln2);
if (i > 0) {
dz = (float) Math.tan((az[i] - az0) / 2);
if (dz < 0) {
cs[i - 1] = -dz;
corr -= 2 * dz;
}
}
az0 = az[i];
lt1 = lt2;
ln1 = ln2;
}
}
if (nseg <= 1)
return;
// now try to play with little boxes
// rotate them either on upper left corner or lower lef corner
// probably can be simplified ...
visible = true;
LineMetrics lm = font.getLineMetrics("MM", frc);
if (lm == null) {
System.out.println("null metrics");
return;
}
float h = (float) lm.getAscent();
//System.out.println("ascent:" + h + " w:" + w + " s:" + s +
// " corr:" + corr + " wc:" + (w - corr * h) + " " + str);
corr = 0f;
w -= corr * h;
float sc = (float) (w / s);
for (int i = 0; i < nseg; i++)
ds[i] *= sc;
int m = gv.getNumGlyphs();
float[] gp = gv.getGlyphPositions(0, m, null);
if (gp == null)
System.out.println("gp null");
//path = new GeneralPath();
AffineTransform at;
double dx;
double dy;
double x = 0;
double y = 0;
double xa;
double ya;
double s0 = 0;
double ps;
double s1;
double s2;
double theta;
double theta2;
double thetai;
double dtheta;
double ch0 = 0;
double cos1;
double sin1;
double cos2;
double sin2;
j = 0;
for (int i = 0; i < m; i++) {
s = (i == m - 1) ? (float) w : gp[2 * i + 2];
ps = s - s0;
theta = az[j];
cos1 = Math.cos(theta);
sin1 = Math.sin(theta);
float ch = (float) (cs[j] * h);
if (s + ch0 < ds[j] - ch || j == nseg - 1) {
xa = x;
ya = y;
x += ps * cos1;
y += ps * sin1;
} else {
theta2 = az[j + 1];
cos2 = Math.cos(theta2);
sin2 = Math.sin(theta2);
dtheta = theta2 - theta;
s1 = ds[j] - ch - ch0 - s0;
s2 = s1 * Math.sin(dtheta);
s2 = ps * ps - s2 * s2;
s2 = Math.sqrt(s2) - s1 * Math.cos(dtheta);
dx = s1 * cos1 + s2 * cos2;
dy = s1 * sin1 + s2 * sin2;
thetai = Math.atan2(dy, dx);
if (ch == 0) {
xa = x;
ya = y;
} else {
dx += ch * cos1 + ch * cos2;
dy += ch * sin1 + ch * sin2;
xa = x + h * sin1 - h * Math.sin(thetai);
ya = y - h * cos1 + h * Math.cos(thetai);
}
x += dx;
y += dy;
j++;
ch0 = ch;
theta = thetai;
}
gv.setGlyphPosition(i, new Point2D.Double(xa, ya));
if (theta != 0) {
at = new AffineTransform();
at.rotate(theta);
gv.setGlyphTransform(i, at);
}
s0 = s;
/*
* path.moveTo((float) xa, (float) ya); xa += ps *