/** * Horizontal ruler — counterpart of svtools/source/control/ruler.cxx (drawn * by SvxRuler for Writer). Shows the page width, the margins and the current * paragraph's indents. Display-only for now (no dragging of indents/tabs). */ import { CM_TO_PX } from "../../../sw/inc/doc"; export interface RulerProps { pageWidth: number; marginLeft: number; marginRight: number; indentLeft: number; indentRight: number; /** Scale factor (1 = 100%). */ scale: number; } export function Ruler({ pageWidth, marginLeft, marginRight, indentLeft, indentRight, scale }: RulerProps) { const px = (cm: number) => cm * CM_TO_PX * scale; const width = px(pageWidth); const textWidth = pageWidth - marginLeft - marginRight; const ticks = []; // Ticks every 0.25cm, numbered every cm, counted from the left margin. for (let q = -Math.floor(marginLeft * 4); q <= Math.floor((pageWidth - marginLeft) * 4); q++) { const x = px(marginLeft + q / 4); const major = q % 4 === 0; const half = q % 2 === 0; if (major && q !== 0) { ticks.push( {Math.abs(q / 4)} , ); } else if (!major) { ticks.push(); } } const il = px(marginLeft + indentLeft); const ir = px(marginLeft + textWidth - indentRight); return (
{ticks}
); }