Files
request-portal/src/webparts/requestPortal/shared/letterheadLogo.ts
T
gorbenko.pavel 637e51d7f9
Tests / frontend-test (push) Successful in 1m24s
Feature/vacation edo signing (#23)
Co-authored-by: gorbenko.pavel <gorbenko.pavel@tansu.kz>
Reviewed-on: http://git.tnsu.kz/timur.gorodetskiy/request-portal/pulls/23
2026-10-05 08:53:18 +00:00

34 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { ORG_LOGOS } from './orgLogos';
/** Логотип для шапки документа: PNG в base64 и его размеры в пикселях (по ним считается пропорция). */
export interface ILetterheadLogo {
base64: string;
width: number;
height: number;
}
/** Ширина и высота PNG из заголовка IHDR (байты 16–23). */
export function pngSize(base64: string): { width: number; height: number } {
const head = atob(base64.slice(0, 44));
const read = (offset: number): number =>
((head.charCodeAt(offset) << 24) |
(head.charCodeAt(offset + 1) << 16) |
(head.charCodeAt(offset + 2) << 8) |
head.charCodeAt(offset + 3)) >>>
0;
return { width: read(16), height: read(20) };
}
/**
* Логотип компании — тот же, что в печатной шапке (shared/ui/OrgLetterhead). Логотипы вшиты в бандл,
* поэтому у компании, для которой он есть, шапка в документе будет всегда. Нет логотипа у компании
* вовсе — undefined, документ уходит без шапки, как и печатается.
*/
export function letterheadLogoFor(company: string, logos: Record<string, string> = ORG_LOGOS): ILetterheadLogo | undefined {
const dataUri = logos[company];
const prefix = 'data:image/png;base64,';
if (!dataUri?.startsWith(prefix)) return undefined;
const base64 = dataUri.slice(prefix.length);
return { base64, ...pngSize(base64) };
}