找不到名称' fontface'在角度使用vexflow

发布于 2025-02-12 14:21:35 字数 1638 浏览 2 评论 0原文

我在尝试将Vexflow集成到我的Angular 12项目中时遇到了麻烦。

首先,我使用以下方式安装了库:

npm install vexflow

然后我创建了一个简单的组件,然后简单地使用本地API示例试用库的文档。这是一个组件:

import {AfterViewInit, Component, ElementRef, OnInit} from '@angular/core';
import {Renderer, Stave} from "vexflow";

@Component({
  selector: 'app-note-display',
  templateUrl: './note-display.component.html',
  styleUrls: ['./note-display.component.scss']
})
export class NoteDisplayComponent implements OnInit, AfterViewInit {

  constructor(private elRef: ElementRef) { }

  ngOnInit(): void {
  }

  ngAfterViewInit() {
    const renderer = new Renderer(this.elRef.nativeElement.querySelector('#note-display'), Renderer.Backends.SVG);

// Configure the rendering context.
    renderer.resize(500, 500);
    const context = renderer.getContext();

// Create a stave of width 400 at position 10, 40.
    const stave = new Stave(10, 40, 400);

// Add a clef and time signature.
    stave.addClef('treble').addTimeSignature('4/4');

// Connect it to the rendering context and draw!
    stave.setContext(context).draw();
  }

}

但是,在服务我的应用程序时,我会遇到以下错误:

Error: node_modules/vexflow/build/types/src/font.d.ts:132:92 - error TS2304: Cannot find name 'FontFace'.

132     static loadWebFont(fontName: string, woffURL: string, includeWoff2?: boolean): Promise<FontFace>;

我尝试了此解决方案>解决方案在我的情况下没有帮助。

Im having trouble when trying to integrate VexFlow in my Angular 12 project.

First I installed the library using:

npm install vexflow

Then I created a simple component and simply used the native api example from the documentation to try out the library. Here is the component:

import {AfterViewInit, Component, ElementRef, OnInit} from '@angular/core';
import {Renderer, Stave} from "vexflow";

@Component({
  selector: 'app-note-display',
  templateUrl: './note-display.component.html',
  styleUrls: ['./note-display.component.scss']
})
export class NoteDisplayComponent implements OnInit, AfterViewInit {

  constructor(private elRef: ElementRef) { }

  ngOnInit(): void {
  }

  ngAfterViewInit() {
    const renderer = new Renderer(this.elRef.nativeElement.querySelector('#note-display'), Renderer.Backends.SVG);

// Configure the rendering context.
    renderer.resize(500, 500);
    const context = renderer.getContext();

// Create a stave of width 400 at position 10, 40.
    const stave = new Stave(10, 40, 400);

// Add a clef and time signature.
    stave.addClef('treble').addTimeSignature('4/4');

// Connect it to the rendering context and draw!
    stave.setContext(context).draw();
  }

}

But Im getting the following error when serving my application:

Error: node_modules/vexflow/build/types/src/font.d.ts:132:92 - error TS2304: Cannot find name 'FontFace'.

132     static loadWebFont(fontName: string, woffURL: string, includeWoff2?: boolean): Promise<FontFace>;

I tried this solution from another question, but it was not helpful in my case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放血 2025-02-19 14:21:35

正如其他解决方案所建议的那样,@types/css-font-loading-module可能是您需要的。
使用NPM I -D @types/css-font-loading-module确保它包含在您的tsconfig.json 中。
必须将其添加到类型字段中,它应该喜欢与此类似:

{
  "compilerOptions": {
    /* other compiler options... */
    "types": ["css-font-loading-module"]
  }
}

As the other solution suggest, @types/css-font-loading-module is probably what you need.
Install it with npm i -D @types/css-font-loading-module and make sure that it is included in your tsconfig.json.
It must be added to the types field, it should like similar to this:

{
  "compilerOptions": {
    /* other compiler options... */
    "types": ["css-font-loading-module"]
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文