- // Pixel values are scaled so that the ratio
- // between lengths and font sizes on the screen
- // is the same as on paper.
-
- // we don't care about sign of value, we
- // can't display negative anyway
- result = 0.0;
- value = len.value();
- short val_sign = value < 0.0 ? -1 : 1;
-
- switch (len.unit()) {
- case LyXLength::SP:
- // Scaled point: sp = 1/65536 pt
- result = zoom * dpi * value
- / (72.27 * 65536); // 4736286.7
- break;
- case LyXLength::PT:
- // Point: 1 pt = 1/72.27 inch
- result = zoom * dpi * value
- / 72.27; // 72.27
- break;
- case LyXLength::BP:
- // Big point: 1 bp = 1/72 inch
- result = zoom * dpi * value
- / 72; // 72
- break;
- case LyXLength::DD:
- // Didot: 1157dd = 1238 pt?
- result = zoom * dpi * value
- / (72.27 / (0.376 * 2.845)); // 67.559735
- break;
- case LyXLength::MM:
- // Millimeter: 1 mm = 1/25.4 inch
- result = zoom * dpi * value
- / 25.4; // 25.4
- break;
- case LyXLength::PC:
- // Pica: 1 pc = 12 pt
- result = zoom * dpi * value
- / (72.27 / 12); // 6.0225
- break;
- case LyXLength::CC:
- // Cicero: 1 cc = 12 dd
- result = zoom * dpi * value
- / (72.27 / (12 * 0.376 * 2.845)); // 5.6299779
- break;
- case LyXLength::CM:
- // Centimeter: 1 cm = 1/2.54 inch
- result = zoom * dpi * value
- / 2.54; // 2.54
- break;
- case LyXLength::IN:
- // Inch
- result = zoom * dpi * value;
- break;
- case LyXLength::EX:
- // Ex: The height of an "x"
- result = zoom * value * height / 2; // what to / width?
- break;
- case LyXLength::EM: // what to / width?
- // Em: The width of an "m"
- result = zoom * value * height / 2; // Why 2?
- break;
- case LyXLength::MU: // This is probably only allowed in
- // math mode
- result = zoom * value * height;
- break;
- case LyXLength::UNIT_NONE:
- result = 0; // this cannot happen
- break;
- }
- return int (result * val_sign + 0.5);