これを読んで思ったのは、印刷時に1pxは何cmになるのだろうか、ということだ。対象メディアがプリンタなどの場合、長さの指定にはcm, mm, ptなどの絶対単位が有効であるが、画像のように内包サイズが相対単位のpxで決まるものはその長さが必ず絶対単位に変換されるのだから、絶対単位を使ってさえいれば万事OKとはいかない。印刷時の解像度によっては画像が紙に収まりきらず、はみ出してしまうかもしれない。
印刷時の解像度について、仕様書では次のように述べられている。
Pixel units are relative to the resolution of the viewing device, i.e., most often a computer display. If the pixel density of the output device is very different from that of a typical computer display, the user agent should rescale pixel values. It is recommended that the reference pixel be the visual angle of one pixel on a device with a pixel density of 90dpi and a distance from the reader of an arm's length. For a nominal arm's length of 28 inches, the visual angle is therefore about 0.0227 degrees.
For reading at arm's length, 1px thus corresponds to about 0.28 mm (1/90 inch). When printed on a laser printer, meant for reading at a little less than arm's length (55 cm, 21 inches), 1px is about 0.21 mm. On a 300 dots-per-inch (dpi) printer, that may be rounded up to 3 dots (0.25 mm); on a 600 dpi printer, it can be rounded to 5 dots.
出力メディアの解像度がコンピュータのディスプレイのそれと大きく異なる場合、人間の腕の長さを28inchとし、それに対して解像度が90dpiになるよう値を丸め込むよう推奨している。レーザープリンタで印刷された紙を読む場合、人の腕は折り畳まれて21inchくらいになるから、1px = 1/90inch * (21 / 28) = 0.21mm になる、らしい。推奨しているだけなので、印刷時の解像度がどうなるのかはUA次第だ。
印刷時の解像度についてUAの実装がどうなっているのかを調べてみたが、見つからなかったので自分で測ってみることにした。
次のようなHTML文書を印刷して、1px当たりの長さを計算した。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Language" content="ja">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>1pxは何mm?</title>
</head>
<body style="background: white">
<div style="height: 500px; width: 10px; background-color: green"></div>
</body>
</html>
その結果。
| UA | 500px | 1px | 解像度 |
|---|---|---|---|
| Internet Explorer 7 | 13.25cm | 0.265mm | 95.849dpi |
| Firefox 2 | 13.25cm | 0.265mm | 95.849dpi |
| Opera 9 | 13.25cm | 0.265mm | 95.849dpi |
どのUAでも同じ結果になった。500pxの実際の長さは物差しで測ったので多少の誤差はある。それを考慮すれば、どのUAもウェブ標準(らしい)の解像度、96dpiで印刷していると言ってよさそうだ。腕の長さ云々のくだりは完全に無視されている。(まあ、この方が実装の違いに悩まなくて済むからいいと思う。)
ただ、Windowsでしか試していないので、他のOSでは違ってくるかもしれない。
続きがあります。
2008年5月19日
広告
広告