Failed to decode downloaded font ,OTS parsing error: Failed to convert WOFF 2.0等问题

该博客讨论了在Maven配置中如何设置资源过滤,同时避免对特定文件类型(如.woff、.woff2和.ttf)的破坏。通过排除和包含规则确保字体文件不被过滤过程影响,以保持项目正常运行。如果遇到文件损坏问题,建议从官方网站重新下载,并在问题仍未解决时尝试清除浏览器缓存。

第一个是配置maven过滤器。

<resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>**/*.woff</exclude>
                    <exclude>**/*.woff2</exclude>
                    <exclude>**/*.ttf</exclude>
                 </excludes>
            </resource>
            <resource>
            <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <includes>
                    <include>**/*.woff</include>
                    <include>**/*.woff2</include>
                    <include>**/*.ttf</include>
                </includes>
            </resource>
 </resources>

有可能是你写的filter破坏了文件,所以过滤器排除掉这些文件。

第二个文件已被破坏,就去官网重新下载一份 。

第三 如果重启项目还没成功 。清除浏览器缓存,再访问页面

解决 CSS 引用字体时出现 `Failed to decode downloaded font` 和 `OTS parsing error: invalid sfntVersion` 错误,可采用以下方法: ### 检查字体文件路径 确保 CSS 中引用字体文件的路径无误。若字体文件存于项目的 `fonts` 目录下,可如下引用: ```css @font-face { font-family: 'CustomFont'; src: url('/fonts/2cf05d918cb3560363ef.ttf') format('truetype'); font-weight: normal; font-style: normal; } ``` ### 检查字体文件完整性 保证字体文件未损坏,可尝试在其他项目或工具中打开该字体文件,若文件损坏,需重新下载或获取正确的字体文件。 ### 检查服务器配置 若使用服务器提供字体文件,要确保服务器配置正确,能够正确提供字体文件。部分服务器可能需要特定配置才能正确提供字体文件。例如,在 Spring Boot 项目中,需配置静态资源路径,避免被拦截: ```java import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class WebMvcConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**/*").addResourceLocations("classpath:/static/"); } } ``` ### 排除资源过滤问题(针对 Maven 项目) 在 `pom.xml` 中的 `build` 节点的 `resources` 部分排除字体文件过滤,示例如下: ```xml <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>**/*.woff</exclude> <exclude>**/*.woff2</exclude> <exclude>**/*.ttf</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <includes> <include>**/*.woff</include> <include>**/*.woff2</include> <include>**/*.ttf</include> </includes> </resource> </resources> </build> ``` ### 检查跨域问题字体文件来自不同域名或端口,可能会出现跨域问题。可在服务器端配置允许跨域访问,例如在 Node.js 的 Express 服务器中,可使用 `cors` 中间件: ```javascript const express = require('express'); const cors = require('cors'); const app = express(); app.use(cors()); // 其他路由和配置 app.listen(8080, () => { console.log('Server is running on port 8080'); }); ``` ### 缓存问题 清除浏览器缓存,有时候缓存的字体文件可能已损坏,清除缓存后重新加载页面,查看问题是否解决。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值