-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove font-scanner in frontend (#247)
* Remove font-scanner in frontend * Fix eslint * Fix eslint * Remove text to svg
- Loading branch information
1 parent
d44f4d6
commit d1e40bb
Showing
7 changed files
with
108 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* eslint-disable no-param-reassign */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const fontScanner = require('font-scanner'); | ||
const { ipcMain } = require('electron'); | ||
|
||
const events = require('./ipc-events'); | ||
|
||
let fontsListCache = []; | ||
|
||
const findFontsSync = (arg) => { | ||
const availableFonts = fontsListCache || fontScanner.getAvailableFontsSync(); | ||
const matchFamily = availableFonts.filter((font) => font.family === arg.family); | ||
const match = matchFamily.filter((font) => { | ||
let result = true; | ||
Object.getOwnPropertyNames(arg).forEach((a) => { | ||
if (arg[a] !== font[a]) { | ||
result = false; | ||
} | ||
}); | ||
return result; | ||
}); | ||
return match; | ||
}; | ||
|
||
const findFontSync = (arg) => { | ||
if (arg.postscriptName) { | ||
return fontScanner.findFontSync(arg); | ||
} | ||
|
||
arg.style = arg.style || 'Regular'; | ||
const availableFonts = fontsListCache || fontScanner.getAvailableFontsSync(); | ||
let font = availableFonts[0]; | ||
let match = availableFonts.filter((f) => f.family === arg.family); | ||
font = match[0] || font; | ||
if (arg.italic != null) { | ||
match = match.filter((f) => f.italic === arg.italic); | ||
font = match[0] || font; | ||
} | ||
match = match.filter((f) => f.style === arg.style); | ||
font = match[0] || font; | ||
if (arg.weight != null) { | ||
match = match.filter((f) => f.weight === arg.weight); | ||
} | ||
font = match[0] || font; | ||
return font; | ||
}; | ||
|
||
const registerEvents = () => { | ||
ipcMain.on(events.GET_AVAILABLE_FONTS, (event) => { | ||
const fonts = fontScanner.getAvailableFontsSync(); | ||
fontsListCache = fonts; | ||
event.returnValue = fonts; | ||
}); | ||
|
||
ipcMain.on(events.FIND_FONTS, (event, arg) => { | ||
const fonts = findFontsSync(arg); | ||
event.returnValue = fonts; | ||
}); | ||
|
||
ipcMain.on(events.FIND_FONT, (event, arg) => { | ||
const font = findFontSync(arg); | ||
event.returnValue = font; | ||
}); | ||
|
||
ipcMain.on(events.SUBSTITUTE_FONT, (event, postscriptName, text) => { | ||
const font = fontScanner.substituteFontSync(postscriptName, text); | ||
event.returnValue = font; | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
registerEvents, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,36 @@ | ||
module.exports = { | ||
NOTIFY_LANGUAGE : 'NOTIFY_LANGUAGE', | ||
NOTIFY_MACHINE_STATUS : 'NOTIFY_MACHINE_STATUS', | ||
NOTIFY_LANGUAGE: 'NOTIFY_LANGUAGE', | ||
NOTIFY_MACHINE_STATUS: 'NOTIFY_MACHINE_STATUS', | ||
|
||
FRONTEND_READY : 'FRONTEND_READY', | ||
BACKEND_UP : 'BACKEND_UP', | ||
BACKEND_DOWN : 'BACKEND_DOWN', | ||
CHECK_BACKEND_STATUS : 'CHECK_BACKEND_STATUS', | ||
NOTIFY_BACKEND_STATUS : 'NOTIFY_BACKEND_STATUS', | ||
FRONTEND_READY: 'FRONTEND_READY', | ||
BACKEND_UP: 'BACKEND_UP', | ||
BACKEND_DOWN: 'BACKEND_DOWN', | ||
CHECK_BACKEND_STATUS: 'CHECK_BACKEND_STATUS', | ||
NOTIFY_BACKEND_STATUS: 'NOTIFY_BACKEND_STATUS', | ||
|
||
MENU_CLICK : 'MENU_CLICK', | ||
UPDATE_CUSTOM_TITLEBAR : 'UPDATE_CUSTOM_TITLEBAR', | ||
DISABLE_MENU_ITEM : 'DISABLE_MENU_ITEM', | ||
ENABLE_MENU_ITEM : 'ENABLE_MENU_ITEM', | ||
MENU_CLICK: 'MENU_CLICK', | ||
UPDATE_CUSTOM_TITLEBAR: 'UPDATE_CUSTOM_TITLEBAR', | ||
DISABLE_MENU_ITEM: 'DISABLE_MENU_ITEM', | ||
ENABLE_MENU_ITEM: 'ENABLE_MENU_ITEM', | ||
|
||
POPUP_MENU : 'POPUP_MENU_ITEM', | ||
POPUP_MENU: 'POPUP_MENU_ITEM', | ||
|
||
UPDATE_ACCOUNT : 'UPDATE_ACCOUNT', | ||
UPDATE_ACCOUNT: 'UPDATE_ACCOUNT', | ||
|
||
GET_AVAILABLE_FONTS : 'GET_AVAILABLE_FONTS', | ||
FIND_FONTS : 'FIND_FONTS', | ||
FIND_FONT : 'FIND_FONT', | ||
REQUEST_PATH_D_OF_TEXT : 'REQUEST_PATH_D_OF_TEXT', | ||
RESOLVE_PATH_D_OF_TEXT : 'RESOLVE_PATH_D_OF_TEXT', | ||
GET_AVAILABLE_FONTS: 'GET_AVAILABLE_FONTS', | ||
FIND_FONTS: 'FIND_FONTS', | ||
FIND_FONT: 'FIND_FONT', | ||
SUBSTITUTE_FONT: 'SUBSTITUTE_FONT', | ||
|
||
SET_AS_DEFAULT : 'SET_AS_DEFAULT', | ||
SET_AS_DEFAULT: 'SET_AS_DEFAULT', | ||
|
||
CHECK_FOR_UPDATE : 'CHECK_FOR_UPDATE', | ||
UPDATE_AVAILABLE : 'UPDATE_AVAILABLE', | ||
DOWNLOAD_UPDATE : 'DOWNLOAD_UPDATE', | ||
DOWNLOAD_PROGRESS : 'DOWNLOAD_PROGRESS', | ||
UPDATE_DOWNLOADED : 'UPDATE_DOWNLOADED', | ||
QUIT_AND_INSTALL : 'QUIT_AND_INSTALL', | ||
CHECK_FOR_UPDATE: 'CHECK_FOR_UPDATE', | ||
UPDATE_AVAILABLE: 'UPDATE_AVAILABLE', | ||
DOWNLOAD_UPDATE: 'DOWNLOAD_UPDATE', | ||
DOWNLOAD_PROGRESS: 'DOWNLOAD_PROGRESS', | ||
UPDATE_DOWNLOADED: 'UPDATE_DOWNLOADED', | ||
QUIT_AND_INSTALL: 'QUIT_AND_INSTALL', | ||
|
||
SVG_URL_TO_IMG_URL : 'SVG_URL_TO_IMG_URL', | ||
SVG_URL_TO_IMG_URL_DONE : 'SVG_URL_TO_IMG_URL_DONE' | ||
SVG_URL_TO_IMG_URL: 'SVG_URL_TO_IMG_URL', | ||
SVG_URL_TO_IMG_URL_DONE: 'SVG_URL_TO_IMG_URL_DONE', | ||
}; |
Oops, something went wrong.