|
Last change
on this file was b8093a0, checked in by imbrsk <boris696boris@…>, 3 days ago |
|
Merge iknow-remaster into frontend/
Bring the Next.js frontend into this repository as a monorepo subdirectory,
preserving its full commit history via a subtree merge.
|
-
Property mode
set to
100644
|
|
File size:
1007 bytes
|
| Line | |
|---|
| 1 | import { jsPDF } from 'jspdf';
|
|---|
| 2 |
|
|---|
| 3 | let fontsLoaded = false;
|
|---|
| 4 | let regularFontBase64: string | null = null;
|
|---|
| 5 | let boldFontBase64: string | null = null;
|
|---|
| 6 |
|
|---|
| 7 | async function fetchFontAsBase64(url: string): Promise<string> {
|
|---|
| 8 | const response = await fetch(url);
|
|---|
| 9 | const buffer = await response.arrayBuffer();
|
|---|
| 10 | const bytes = new Uint8Array(buffer);
|
|---|
| 11 | let binary = '';
|
|---|
| 12 | for (let i = 0; i < bytes.length; i++) {
|
|---|
| 13 | binary += String.fromCharCode(bytes[i]);
|
|---|
| 14 | }
|
|---|
| 15 | return btoa(binary);
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | export async function loadCyrillicFonts(doc: jsPDF): Promise<void> {
|
|---|
| 19 | if (!fontsLoaded) {
|
|---|
| 20 | regularFontBase64 = await fetchFontAsBase64('/fonts/Roboto-Regular.ttf');
|
|---|
| 21 | boldFontBase64 = await fetchFontAsBase64('/fonts/Roboto-Bold.ttf');
|
|---|
| 22 | fontsLoaded = true;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | doc.addFileToVFS('Roboto-Regular.ttf', regularFontBase64!);
|
|---|
| 26 | doc.addFont('Roboto-Regular.ttf', 'Roboto', 'normal');
|
|---|
| 27 |
|
|---|
| 28 | doc.addFileToVFS('Roboto-Bold.ttf', boldFontBase64!);
|
|---|
| 29 | doc.addFont('Roboto-Bold.ttf', 'Roboto', 'bold');
|
|---|
| 30 |
|
|---|
| 31 | doc.setFont('Roboto', 'normal');
|
|---|
| 32 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.