Coder Social home page Coder Social logo

node-font-list's Introduction

node-font-list's People

Contributors

alielmajdaoui avatar brettz9 avatar daifkyou avatar jonz94 avatar likaifei avatar moehero avatar nikarh avatar oldj avatar pjheslin avatar qishibo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-font-list's Issues

Angular Compatability

Good afternoon! I was wondering if you knew how compatible this package was in an Angular Application. I love the idea of how "getFonts" works, however it had issues loading in "child_process" and "fs". Once I followed some recommended fixes to get those working, I got "process is undefined" error when trying to run the function. Thanks in advance for any insights you can give me! Here are some details about what I am running locally with the package:
localenviro

Security issue

Hi,

The code at https://github.com/oldj/node-font-list/blob/master/libs/win32/index.js#L69-L71 is being flagged by https://lgtm.com/projects/g/oldj/node-font-list/?mode=list with an explanation for the concern at https://lgtm.com/rules/1510773276307/ . It appears that this concern could be minimized by using:

let cmd = 'cscript'
execFile(cmd, [fn], (err, stdout, stderr) => {

Btw, I find LGTM.com to be a useful site which picks up issues like this which ESLint does not (and across multiple languages), and they have an integration for your site's PRs in case you might be interested: https://lgtm.com/help/lgtm/github-apps-integration

获取字体问题

现在获取的字体无法直接在css里面用
我改了一下 不知道是否可以提交pr

fc-list2 binary is not available on Archlinux

Hi, the linux implementation executes binary fc-list2, but on archlinux fontconfig this binary is called fc-list, without 2. Maybe it would be better to test for existence of one of these two binaries with something like which first?

electron使用font-list的正确方法,支持windows和mac

正常情况下,electron-builder 默认是不会将 font-list 打包的,所以导致无法使用,通过 extraResources 执行处理即可,下面为使用步骤:

  1. package.json 中添加
   "extraResources": [
      "./extraResources/**"
    ],
  1. 在项目根目录创建 extraResources/fontlist 文件夹,将 node_modules/font-list 下的文件源码复制到 extraResources
extraResources
  └─fontlist
      ├─getSystemFonts.js
      ├─index.d.ts
      ├─index.js
      └─libs
          ├─darwin
          ├─linux
          └─win32
  1. getSystemFonts.js 中为
const { getFonts } = require('./index');

function getSystemFonts() {
  return new Promise((resolve, reject) => {
    getFonts({ disableQuoting: true })
      .then((fonts) => {
        fonts = [...new Set(fonts)];
        resolve(fonts || []);
      })
      .catch((err) => {
        resolve([]);
      });
  });
}

(async () => {
  const fonts = await getSystemFonts();
  // process 处理
  process.send(fonts);
  // console.log('fonts', fonts);
})();
  1. 在主进程 main.ts 中添加触发事件 getSystemFonts
import path from 'path';
import cp from 'child_process';

const EXTRARESOURCES_PATH = app.isPackaged
  ? path.join(process.resourcesPath, 'extraResources')
  : path.join(__dirname, '../../extraResources');

const getExtraResourcesPath = (...paths: string[]): string => {
  return path.join(EXTRARESOURCES_PATH, ...paths);
};

// ...
ipcMain.on('getSystemFonts', async () => {
  const systemFontsScriptPath = getExtraResourcesPath('fontlist/getSystemFonts.js')
  let fonts: string[] = [];
  const forked = cp.fork(systemFontsScriptPath);
  forked.on('message', function (message: string[]) {
    fonts = message;
    mainWindow?.webContents.send('getSystemFontsCb', fonts);
  });
});
  1. utils/common.ts 为例子触发事件
import { ipcRenderer } from "electron";

export const systemFonts: string[] = [];

// 获取系统字体列表
ipcRenderer.send('getSystemFonts');
ipcRenderer.on('getSystemFontsCb', (e, fonts: string[] = []) => {
  // console.log('fonts', fonts);
  systemFonts = fonts;
});
  1. 引用即可
import { systemFonts } from "utils/common";

console.log('systemFonts', systemFonts)
// [ 'Arial', 'Bahnschrift', 'Book Antiqua']

具体commit源码 Beats0/bilive-danmaku@0f3f450

中文乱码

当前版本:1.2.11
当前系统:win10
当前nodejs:12.13.0

#13 中提到的强制使用utf8代码页chcp 65001并不是一个万能的解决方案。在我的电脑中这并不能按照预期工作,还是有乱码:

215: ""Yu Gothic UI Semilight""
216: ""Yu Gothic UI""
217: ""Yu Gothic""
218: "΢ܛ�����w"
219: ""΢ܛ�����w Light""
220: "΢���ź�"
221: ""΢���ź� Light""
222: "�¼����w-ExtB"
223: "��Բ"
224: "���IJ���"
225: "���ķ���"

在其他项目中也有类似的情况,例如wmic,但都不清楚问题的原因是什么,这里提到的可能是由于控制台使用的是矢量字体的原因,我尝试过切换字体,但一样不能工作。(也许是因为vs code的原因?因为就算我切换字体vs code里终端的字体也没变化)

目前我发现的一个较为可行的解决方案是使用iconv-lite进行编码转换:

const iconv = require("iconv-lite");
exec(cmd, { maxBuffer: 1024 * 1024 * 10, encoding: "binary" }, (err, stdout, stderr) => {
    let t = iconv.decode(Buffer.from(stdout, "binary"), "utf8");
    // if not include ‘�’
    if (!t.includes("\uFFFD")) stdout = t;
    else stdout = iconv.decode(Buffer.from(stdout, "binary"), "cp936");
    if (err) return reject(err);
    resolve(parse(stdout));
});

只判断是因为Buffer会将无法解析为utf8的字符变成�,参考
由此得出一个通用的解决方案是通过使用chcp来获取当前活动页码,使用binary方式读取结果,最后使用iconv根据活动页码转换编码。

此外,通过vbs获取字体信息时,也存在乱码现象。但在处理返回结果的时候,把objFont.Name的结果给过滤掉了:

// libs/win32/getByVBS.js : line 21
a = a.map(i => {
    i = i
      .split('\t')[0]
      .split(path.sep)
    i = i[i.length - 1]

getByVBS.js这里后续的处理中处理的都是字体路径而非字体名,不知是否符合作者你的预期。

Ps. 通过powershell获取的结果中有空字符串,希望过滤一下。

font-list not work in --asar electron packager

when build my electron project by
electron-packager . test --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/image/logo.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName="test"

font-list not work but when remove --asar worked

show message
error: Command failed: cscript "C:\Users\Your\release-builds\rc-win32-ia32\resources\app.asar\node_modules\font-list\libs\win32\fonts.vbs"
at ChildProcess.exithandler (child_process.js:304)
at ChildProcess.emit (events.js:200)
at maybeClose (internal/child_process.js:1021)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283)

Support Get Font postScriptName

In my using case, I need to get available fonts in AE CEP extension. I using this package to get font name list, but I found that AE using font postScriptName, but not the result return by this package.

image

This package seems to get the name of compatibleFullName.

image

image

electron 打包在windows下无法获取字体

您好,非常感谢。这里报告一个问题,electron 打包在windows下无法获取字体, 报错信息:
EPERM: operation not permitted, copyfile 'C:\Program Files\BlinkMind\resources\app.asar.unpacked\node_modules\font-list\libs\win32\fonts.vbs' -> 'C:\Users\zhou\AppData\Local\Temp\node-font-list-fonts.vbs'

关于fonts.vbs的建议

建议直接在运行时判断文件是否存在,如果不存在则通过fs库将vbs内容写出到这个位置就好了

Support electron-builder in mac

__dirname has different meaning in electron-builder, in font-list/libs/darwin/index.js
const bin = path.join(__dirname, 'fontlist')
can't get the correct path of the fontlist file.
Is there any solution?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.