OTS解析错误:无法将Glyphicon的字体文件的WOFF 2.0字体转换为SFNT for Spring-boot

Pra*_*nay 6 maven angularjs glyphicons spring-boot

在通过 maven 创建的 Spring-boot Java 项目中尝试将 Glyphicons 与 Algular 一起使用时,未显示图标,并且在控制台中可以看到以下错误:

Failed to decode downloaded font: <URL> ..
OTS parsing error: Failed to convert WOFF 2.0 font to SFNT
OTS parsing error: incorrect file size in WOFF header
OTS parsing error: incorrect entrySelector for table directory
Run Code Online (Sandbox Code Playgroud)

这里有一些解决方案,但没有一个考虑 Spring-Boot Maven 场景。

Pra*_*nay 14

似乎 Maven 构建资源以某种方式破坏了这些文件,并且 Bootstrap 无法再正确解码它们,从而导致这些错误。我发现的一种解决方法是在 maven-resources-plugin 中添加 nonFilteredFileExtensions:

<configuration>
    <nonFilteredFileExtensions>
    <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
    <nonFilteredFileExtension>woff</nonFilteredFileExtension>
    <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
    <nonFilteredFileExtension>eot</nonFilteredFileExtension>
    <nonFilteredFileExtension>svg</nonFilteredFileExtension>
    </nonFilteredFileExtensions>
 </configuration>
Run Code Online (Sandbox Code Playgroud)

在这里,我们可以添加 maven 损坏的字体/图标文件的所有扩展名,它应该可以解决问题。

插件部分应该是这样的:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <configuration>
        <nonFilteredFileExtensions>
            <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
            <nonFilteredFileExtension>woff</nonFilteredFileExtension>
            <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
            <nonFilteredFileExtension>eot</nonFilteredFileExtension>
            <nonFilteredFileExtension>svg</nonFilteredFileExtension>
        </nonFilteredFileExtensions>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)