* Character attributes — the TypeScript counterpart of editeng's `Svx*Item`
* family (SvxWeightItem, SvxPostureItem, SvxUnderlineItem, SvxFontItem, …).
*
* Upstream each attribute is a separate pool item keyed by a Which-ID; here a
* plain object plays the role of an `SfxItemSet`. An explicit `false` is
* meaningful: it overrides a value inherited from the paragraph style (e.g.
* un-bolding part of a heading).
*/
export interface SvxCharAttrs {
bold?: boolean;
italic?: boolean;
underline?: boolean;
strikeout?: boolean;
escapement?: "super" | "sub" | "none";
fontName?: string;
fontSize?: number;
color?: string;
highlight?: string;
}
export type SvxCharAttrKey = keyof SvxCharAttrs;
export function normalizeCharAttrs(attrs: SvxCharAttrs): SvxCharAttrs {
const out: Record<string, unknown> = {};
for (const [k, v] of Object.entries(attrs)) if (v !== undefined) out[k] = v;
return out as SvxCharAttrs;
}
export function charAttrsEqual(a: SvxCharAttrs, b: SvxCharAttrs): boolean {
if (a === b) return true;
const ka = Object.keys(a).filter((k) => a[k as SvxCharAttrKey] !== undefined);
const kb = Object.keys(b).filter((k) => b[k as SvxCharAttrKey] !== undefined);
if (ka.length !== kb.length) return false;
return ka.every((k) => a[k as SvxCharAttrKey] === b[k as SvxCharAttrKey]);
}