@@ -53,9 +53,123 @@ const loader = acode.require("loader");
5353const DialogBox = acode . require ( "dialogBox" ) ;
5454const pageComponent = acode . require ( "page" ) ;
5555const actionStack = acode . require ( "actionStack" ) ;
56+ const acodeFonts = acode . require ( "fonts" ) ;
5657
5758const { clipboard } = cordova . plugins ;
5859
60+ const FONT_CDN_BASE =
61+ "https://cdn.jsdelivr.net/gh/bajrangCoder/acode-plugin-acodex@main/fonts/" ;
62+
63+ const TERMINAL_FONTS = [
64+ {
65+ name : "Fira Code Bold Nerd Font" ,
66+ url : `${ FONT_CDN_BASE } Fira Code Bold Nerd Font.ttf` ,
67+ format : "truetype" ,
68+ weight : "bold" ,
69+ style : "normal" ,
70+ } ,
71+ {
72+ name : "Fira Code Medium Nerd Font" ,
73+ url : `${ FONT_CDN_BASE } Fira Code Medium Nerd Font Complete Mono.ttf` ,
74+ format : "truetype" ,
75+ weight : "normal" ,
76+ style : "normal" ,
77+ } ,
78+ {
79+ name : "JetBrains Mono Bold Nerd Font" ,
80+ url : `${ FONT_CDN_BASE } JetBrains Mono Bold Nerd Font Complete.ttf` ,
81+ format : "truetype" ,
82+ weight : "bold" ,
83+ style : "normal" ,
84+ } ,
85+ {
86+ name : "JetBrains Mono Medium Nerd Font" ,
87+ url : `${ FONT_CDN_BASE } JetBrains Mono Medium Nerd Font Complete.ttf` ,
88+ format : "truetype" ,
89+ weight : "normal" ,
90+ style : "normal" ,
91+ } ,
92+ {
93+ name : "VictorMonoNerdFont Bold" ,
94+ url : `${ FONT_CDN_BASE } VictorMonoNerdFont-Bold.ttf` ,
95+ format : "truetype" ,
96+ weight : "bold" ,
97+ style : "normal" ,
98+ } ,
99+ {
100+ name : "VictorMonoNerdFont BoldItalic" ,
101+ url : `${ FONT_CDN_BASE } VictorMonoNerdFont-BoldItalic.ttf` ,
102+ format : "truetype" ,
103+ weight : "bold" ,
104+ style : "italic" ,
105+ } ,
106+ {
107+ name : "VictorMonoNerdFont Medium" ,
108+ url : `${ FONT_CDN_BASE } VictorMonoNerdFont-Medium.ttf` ,
109+ format : "truetype" ,
110+ weight : "normal" ,
111+ style : "normal" ,
112+ } ,
113+ {
114+ name : "VictorMonoNerdFont Italic" ,
115+ url : `${ FONT_CDN_BASE } VictorMonoNerdFont-Italic.ttf` ,
116+ format : "truetype" ,
117+ weight : "normal" ,
118+ style : "italic" ,
119+ } ,
120+ {
121+ name : "SauceCodeProNerdFont Bold" ,
122+ url : `${ FONT_CDN_BASE } SauceCodeProNerdFont-Bold.ttf` ,
123+ format : "truetype" ,
124+ weight : "bold" ,
125+ style : "normal" ,
126+ } ,
127+ {
128+ name : "SauceCodeProNerdFont Medium" ,
129+ url : `${ FONT_CDN_BASE } SauceCodeProNerdFont-Medium.ttf` ,
130+ format : "truetype" ,
131+ weight : "normal" ,
132+ style : "normal" ,
133+ } ,
134+ {
135+ name : "MesloLGS NF Bold Italic" ,
136+ url : `${ FONT_CDN_BASE } MesloLGS NF Bold Italic.ttf` ,
137+ format : "truetype" ,
138+ weight : "bold" ,
139+ style : "italic" ,
140+ } ,
141+ {
142+ name : "MesloLGS NF Bold" ,
143+ url : `${ FONT_CDN_BASE } MesloLGS NF Bold.ttf` ,
144+ format : "truetype" ,
145+ weight : "bold" ,
146+ style : "normal" ,
147+ } ,
148+ {
149+ name : "MesloLGS NF Italic" ,
150+ url : `${ FONT_CDN_BASE } MesloLGS NF Italic.ttf` ,
151+ format : "truetype" ,
152+ weight : "normal" ,
153+ style : "italic" ,
154+ } ,
155+ ] ;
156+
157+ function registerTerminalFonts ( ) {
158+ if ( typeof acodeFonts ?. add !== "function" ) return ;
159+
160+ TERMINAL_FONTS . forEach ( ( { name, url, format, weight, style } ) => {
161+ if ( acodeFonts ?. has ?. ( name ) ) return ;
162+ const fontUrl = encodeURI ( url ) ;
163+ const fontFace = `@font-face {
164+ font-family: '${ name } ';
165+ src: url('${ fontUrl } ') format('${ format } ');
166+ font-weight: ${ weight } ;
167+ font-style: ${ style } ;
168+ }` ;
169+ acodeFonts . add ( name , fontFace ) ;
170+ } ) ;
171+ }
172+
59173export default class AcodeX {
60174 // constants for draggable Terminal panel
61175 isDragging = false ;
@@ -92,12 +206,7 @@ export default class AcodeX {
92206
93207 async init ( $page , cacheFile , cacheFileUrl ) {
94208 try {
95- if ( ! ( await fsOperation ( `${ window . DATA_STORAGE } acodex_fonts` ) . exists ( ) ) ) {
96- helpers . downloadFont ( fsOperation , loader ) ;
97- }
98- const baseFontUrl = window . IS_FREE_VERSION
99- ? "https://localhost/__cdvfile_sdcard__/Android/data/com.foxdebug.acodefree/files/acodex_fonts/"
100- : "https://localhost/__cdvfile_sdcard__/Android/data/com.foxdebug.acode/files/acodex_fonts/" ;
209+ registerTerminalFonts ( ) ;
101210 this . xtermCss = tag ( "link" , {
102211 rel : "stylesheet" ,
103212 href : `${ this . baseUrl } xterm.css` ,
@@ -106,11 +215,8 @@ export default class AcodeX {
106215 rel : "stylesheet" ,
107216 href : `${ this . baseUrl } main.css` ,
108217 } ) ;
109- this . $fontStyleSheet = tag ( "style" , {
110- textContent : helpers . fontsStyleSheetStr ( baseFontUrl ) ,
111- } ) ;
112218 this . _loadCustomFontStyleSheet ( ) ;
113- document . head . append ( this . xtermCss , this . $style , this . $fontStyleSheet ) ;
219+ document . head . append ( this . xtermCss , this . $style ) ;
114220 // add command in command Palette for opening and closing terminal
115221 editorManager . editor . commands . addCommand ( {
116222 name : "acodex:open_terminal" ,
@@ -969,6 +1075,7 @@ export default class AcodeX {
9691075 this . $terminalContainer . style . height = `${ termContainerHeight } px` ;
9701076 this . $terminalContent . style . width = "100%" ;
9711077 this . $terminalContent . style . height = `calc(100% - ${ this . $terminalContainer . offsetHeight } px)` ;
1078+ await acodeFonts . loadFont ( this . settings . fontFamily ) ;
9721079
9731080 if ( this . settings . transparency ) {
9741081 this . $terminalContainer . style . background = "transparent" ;
@@ -2330,7 +2437,9 @@ export default class AcodeX {
23302437 text : "Font Family" ,
23312438 value : this . settings . fontFamily ,
23322439 info : "The font family used to render text." ,
2333- select : FONTS_LIST ,
2440+ get select ( ) {
2441+ return acodeFonts . getNames ( ) ;
2442+ } ,
23342443 } ,
23352444 {
23362445 index : 4 ,
@@ -2525,7 +2634,7 @@ export default class AcodeX {
25252634 ] ;
25262635 }
25272636
2528- settingsSaveCallback ( key , value ) {
2637+ async settingsSaveCallback ( key , value ) {
25292638 switch ( key ) {
25302639 case "customFontStyleSheet" :
25312640 this . setCustomFontFile ( ) ;
@@ -2557,6 +2666,11 @@ export default class AcodeX {
25572666 appSettings . update ( ) ;
25582667 break ;
25592668 case "fontFamily" :
2669+ try {
2670+ await acodeFonts . loadFont ( value ) ;
2671+ } catch ( error ) {
2672+ console . warn ( `Failed to load font ${ value } :` , error ) ;
2673+ }
25602674 if ( this . $terminal ) {
25612675 this . $terminal . options . fontFamily = value ;
25622676 this . $terminal . refresh ( 0 , this . $terminal . rows - 1 ) ;
0 commit comments