Re: Pre-Fontal lobotomy (was Re: True font sizes)
Roedy Green wrote:
On Thu, 01 Oct 2009 15:57:18 +0100, RedGrittyBrick
<RedGrittyBrick@spamweary.invalid> wrote, quoted or indirectly quoted
someone who said :
I have not yet figured out how to pull this off in CSS.
Phew!
This font size varying so widely cause big problems with CSS. You
specify a list of possible fonts for a style. Which one gets picked
depends on what the user has installed.
The answer seems to be
??? Avoid using decorative fonts for body text.
??? List only the small subset of commonly installed book fonts.
??? Avoid using for European languages, fonts designed for Asian languages.
Suddenly type grows or
shrinks for that style to double the size you intended! This is NOT a
good thing.
In your FontShower, on my PC, Gautami and Biondi are near the extremes.
Gautami needs the extra interline spacing to allow room for Telugu vowel
signs above and below the glyphs. If you force the interline spacing to
be halved you may render the text unreadable in some languages.
If you write English text in a font intended for Telugu you should be
prepared for it to look odd. It's the choice of font for purpose that is
wrong, not it's interline spacing.
The following may surprise you (it did me).
------------------------------8<---------------------------------
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.font.FontRenderContext;
import java.awt.font.LineMetrics;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class AboutFonts {
public static void main(String[] args) {
System.out.println(getFontHeightLessLeading("Gautami"));
System.out.println(getFontHeight("Gautami"));
}
static float getFontHeight(String FontName) {
Font font = new Font(FontName, Font.PLAIN, 10);
JFrame frame = new JFrame();
FontMetrics fm = frame.getFontMetrics(font);
return fm.getHeight();
}
static float getFontHeightLessLeading(String FontName) {
final Font f = new Font(FontName, Font.PLAIN, 10);
final BufferedImage dummybi = new BufferedImage(200 /* dummy */,
200 /* dummy */, BufferedImage.TYPE_4BYTE_ABGR_PRE);
final Graphics2D dummyg2d = dummybi.createGraphics();
final FontRenderContext fr = dummyg2d.getFontRenderContext();
final LineMetrics lm = f.getLineMetrics("", fr);
//^^ SURPRISE!
return lm.getDescent() + lm.getAscent();
}
}
------------------------------8<---------------------------------
16.796875 // SURPRISED?
18.0 // Includes leading.
I'm still unsure what real-world problem you are trying to avoid.
--
RGB