我需要在我的React材质UI主题中使用诺托Sans阿拉伯字体。主题工作得很好,覆盖也很好。
我尝试过React Material UI docs来导入我的字体,就像在react-material文档中一样,但它不工作:
import notoArabic from '../static/fonts/NotoSansArabic-Regular.ttf'
....
const arabic = {
fontFamily: 'Noto Sans Arabic',
fontStyle: 'regular',
fontDisplay: 'swap',
fontWeight: 400,
src: `
local('Noto Sans Arabic'),
local('Noto Sans Arabic-Regular'),
url(${notoArabic}) format('ttf')
`,
unicodeRange:
'U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF',
};
...
overrides: {
MuiCssBaseline: {
'@global': {
'@font-face': [arabic],
},
},
...
我希望字体将被导入并工作。
我有任何错误,可以看到font-family:诺托Sans Arabic;在我的浏览器里但它不起作用
3条答案
按热度按时间2skhul331#
我是波斯人,我们的语言字体非常非常像阿拉伯字体。对于我的项目,我创建了一个单独的文件,并将其命名为
globalStyles.js
:在我的组件的顶层,我注入了项目根组件:
另外,在Webpack配置文件中,我编写了字体加载器,如下所示:
现在一切都很好。我希望我的配置对你有帮助。
6ojccjat2#
你可以尝试下面提到的一些事情来检查你是否正确地编译了代码。
1.从您提到的导入字体的相关URL推断
static
文件夹和above file
目录是同级。确保相关路径与每个root
文件夹相同。1.此外,如果您使用
webpack
捆绑代码,请确保包含ttf
文件扩展名,并在compiling期间添加file-loader
模块来处理它。例如
zf9nrax13#
有几种可能性,但我建议尝试加载相同的字体通过您的index.css文件并检查结果,可能是您引用的位置不正确或字体不存在.
此外,可能需要一个文件加载器或插件来渲染与webpack read字体:https://chriscourses.com/blog/loading-fonts-webpack