public BaselineInfo getBaselines(final int c, BaselineInfo info)
{
final boolean cacheable = (c >= 32 && c < 256);
if (cacheable)
{
final BaselineInfo fromCache = cachedBaselines[c - 32];
if (fromCache != null)
{
if (info == null)
{
info = new BaselineInfo();
}
info.update(fromCache);
return info;
}
}
cpBuffer[0] = (char) (c & 0xFFFF);
final LineMetrics lm = font.getLineMetrics(cpBuffer, 0, 1, frc);
final float[] bls = lm.getBaselineOffsets();
final int idx = lm.getBaselineIndex();
if (info == null)
{
info = new BaselineInfo();
}
// The ascent is local - but we need the global baseline, relative to the
// MaxAscent.
final long maxAscent = getMaxAscent();
final long ascent = FontStrictGeomUtility.toInternalValue(lm.getAscent());
final long delta = maxAscent - ascent;
info.setBaseline(BaselineInfo.MATHEMATICAL, delta + maxAscent - getXHeight());
info.setBaseline(BaselineInfo.IDEOGRAPHIC, getMaxHeight());
info.setBaseline(BaselineInfo.MIDDLE, maxAscent / 2);
final long base = delta + ascent;
switch (idx)
{
case Font.CENTER_BASELINE:
{
info.setBaseline(BaselineInfo.CENTRAL, base);
info.setBaseline(BaselineInfo.ALPHABETIC, base + FontStrictGeomUtility.toInternalValue(bls[Font.ROMAN_BASELINE]));
info.setBaseline(BaselineInfo.HANGING, base + FontStrictGeomUtility.toInternalValue(bls[Font.HANGING_BASELINE]));
info.setDominantBaseline(BaselineInfo.CENTRAL);
break;
}
case Font.HANGING_BASELINE:
{
info.setBaseline(BaselineInfo.CENTRAL, base + FontStrictGeomUtility.toInternalValue(bls[Font.CENTER_BASELINE]));
info.setBaseline(BaselineInfo.ALPHABETIC, base + FontStrictGeomUtility.toInternalValue(bls[Font.ROMAN_BASELINE]));
info.setBaseline(BaselineInfo.HANGING, base);
info.setDominantBaseline(BaselineInfo.HANGING);
break;
}
default: // ROMAN Base-line
{
info.setBaseline(BaselineInfo.ALPHABETIC, base);
info.setBaseline(BaselineInfo.CENTRAL, base + FontStrictGeomUtility.toInternalValue(bls[Font.CENTER_BASELINE]));
info.setBaseline(BaselineInfo.HANGING, base + FontStrictGeomUtility.toInternalValue(bls[Font.HANGING_BASELINE]));
info.setDominantBaseline(BaselineInfo.ALPHABETIC);
break;
}
}
if (cacheable)
{
final BaselineInfo cached = new BaselineInfo();
cached.update(info);
cachedBaselines[c - 32] = cached;
}
return info;
}