1- import { ChangeDetectionStrategy , Component , signal , computed , inject , viewChild , OnInit } from '@angular/core' ;
1+ import { ChangeDetectionStrategy , Component , signal , computed , inject , viewChild } from '@angular/core' ;
22import { IgxColumnComponent , IgxPdfExporterService , IgxPdfExporterOptions } from 'igniteui-angular/grids/core' ;
33import { IgxGridComponent } from 'igniteui-angular/grids/grid' ;
4+ import notoSansFontData from './fonts/noto-sans.json' ;
45
56/**
67 * Demonstrates PDF export with a custom Unicode font.
78 *
89 * The sample ships with Noto Sans (Latin/Cyrillic/Greek) loaded from
9- * assets/ fonts/noto-sans.json. Users can also upload their own .ttf font —
10+ * fonts/noto-sans.json. Users can also upload their own .ttf font —
1011 * for example Noto Sans CJK for Japanese/Chinese/Korean support.
1112 *
1213 * All Noto fonts are licensed under the SIL Open Font License 1.1
13- * (see assets/ fonts/OFL.txt).
14+ * (see fonts/OFL.txt).
1415 */
1516@Component ( {
1617 selector : 'app-export-pdf-custom-font' ,
@@ -19,7 +20,7 @@ import { IgxGridComponent } from 'igniteui-angular/grids/grid';
1920 changeDetection : ChangeDetectionStrategy . OnPush ,
2021 imports : [ IgxGridComponent , IgxColumnComponent ]
2122} )
22- export class ExportPdfCustomFontComponent implements OnInit {
23+ export class ExportPdfCustomFontComponent {
2324 private pdfExporter = inject ( IgxPdfExporterService ) ;
2425
2526 protected readonly grid = viewChild . required < IgxGridComponent > ( 'grid' ) ;
@@ -48,32 +49,12 @@ export class ExportPdfCustomFontComponent implements OnInit {
4849 { Name : 'Ирина Петрова' , City : 'Санкт-Петербург' , Product : '製品 F' , Amount : 2890 }
4950 ] ) ;
5051
51- public ngOnInit ( ) : void {
52- this . loadBuiltInFont ( ) ;
53- }
54-
55- /** Loads the built-in Noto Sans font from application assets. */
56- private async loadBuiltInFont ( ) : Promise < void > {
57- this . builtInFontLoading . set ( true ) ;
58- this . exportStatus . set ( 'Loading built-in Noto Sans font…' ) ;
59-
60- try {
61- const response = await fetch ( 'assets/fonts/noto-sans.json' ) ;
62- if ( ! response . ok ) {
63- throw new Error ( `HTTP ${ response . status } ` ) ;
64- }
65- const fontJson : { normal : string ; bold : string } = await response . json ( ) ;
66-
67- this . builtInFontData = fontJson . normal ;
68- this . builtInBoldFontData = fontJson . bold ;
69- this . builtInFontLoaded . set ( true ) ;
70- this . exportStatus . set ( 'Noto Sans loaded — ready to export. Upload a CJK font for Japanese/Chinese/Korean support.' ) ;
71- } catch ( error ) {
72- console . error ( 'Failed to load built-in font:' , error ) ;
73- this . exportStatus . set ( 'Failed to load built-in Noto Sans font.' ) ;
74- } finally {
75- this . builtInFontLoading . set ( false ) ;
76- }
52+ constructor ( ) {
53+ const fontJson = notoSansFontData as unknown as { normal : string ; bold : string } ;
54+ this . builtInFontData = fontJson . normal ;
55+ this . builtInBoldFontData = fontJson . bold ;
56+ this . builtInFontLoaded . set ( true ) ;
57+ this . exportStatus . set ( 'Noto Sans loaded — ready to export. Upload a CJK font for Japanese/Chinese/Korean support.' ) ;
7758 }
7859
7960 /** Handles the user uploading a custom .ttf font file. */
0 commit comments