[英]Cannot load my own font in quasar framework
我只为平板电脑构建了一个应用程序,我想使用我自己的 ttf 格式的字体。 如何将.ttf fonts 加载到类星体中?
另一种选择是将其转换为 woff?
我在 app.scss 中试过这个,但没有用:
@font-face {
font-family: 'MyFont';
src: url('css/fonts/MyFont.ttf') format('truetype');
font-weight: 700;
font-style: italic;
}
.my-custom-font {
font-family: 'Cookies', Fallback sans-serif;
}
从 quasar.config.js 文件中删除“roboto-font”(除非您仍打算将其用作辅助字体)。 从 Google Fonts 中选择一种字体进行导入,或下载要包含的字体系列 .WOFF 文件。
类似于文档( https://quasar.dev/style/typography#Add-custom-fonts ),您应该导入字体系列,但它应该进入'src/css/quasar.variables.*'文件. 然后,更改一个或多个默认样式变量。
我将假设 Sass 下面的例子:
// Example: Import Open Sans with multiple weights
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;700;800&display=swap')
// Set the default font-family
$typography-font-family : 'Open Sans', sans-serif !default
// Fix font-weight values to match the imported font family weights
$text-weights: (thin: 300, light: 400, regular: 600, medium: 700, bold: 800, bolder: 800) !default
$button-font-weight: 600 // or 400 if you prefer thinner
我使用手写笔而不像其他人建议的那样删除任何字体行,但执行以下步骤:
assets/fonts/plex
”quasar.variables.styl
设置$typography-font-family
app.styl:
// app global css in Stylus form
@font-face {
font-family: plex;
src: url(../assets/fonts/plex/IBM-Plex-Sans-Arabic/fonts/complete/woff/IBMPlexSansArabic-Regular.woff);
}
quasar.variables.styl:
// Quasar Stylus Variables
// --------------------------------------------------
// To customize the look and feel of this app, you can override
// the Stylus variables found in Quasar's source Stylus files.
// Check documentation for full list of Quasar variables
// Your own variables (that are declared here) and Quasar's own
// ones will be available out of the box in your .vue/.styl files
// It's highly recommended to change the default colors
// to match your app's branding.
// Tip: Use the "Theme Builder" on Quasar's documentation website.
$primary = #1976D2
$secondary = #26A69A
$accent = #9C27B0
$dark = #1D1D1D
$positive = #21BA45
$negative = #C10015
$info = #31CCEC
$warning = #F2C037
$typography-font-family = 'plex'
类星体安装配置:
App dir........... /home/abuabdellah/work/.../quasar
App URL........... http://localhost:8080
Dev mode.......... spa
Pkg quasar........ v1.15.23
Pkg @quasar/app... v2.2.10
Transpiled JS..... yes (Babel)
1-将您的字体文件放入 ./src/css/fonts 文件夹
2-在./src/css/app.css里面声明字体名称
@font-face {
font-family: "vazir";
font-style: normal;
font-weight: 400;
src: url("./fonts/Vazir-Medium.woff2") format("woff2"),
url("./fonts/Vazir-Medium.ttf") format("truetype"),
url("./fonts/Vazir-Medium.woff") format("woff");
font-display: swap;
}
3-在./src/css/quasar.variables.scss中定义字体
$primary: #1976d2;
$secondary: #26a69a;
$accent: #9c27b0;
$dark: #1d1d1d;
$dark-page: #121212;
$positive: #21ba45;
$negative: #c10015;
$info: #31ccec;
$warning: #f2c037;
$typography-font-family: "vazir";
4-Comment robots-font inside./quasar.config.js
extras: [
// 'ionicons-v4',
// 'mdi-v5',
// 'fontawesome-v6',
// 'eva-icons',
// 'themify',
// 'line-awesome',
// 'roboto-font-latin-ext', // this or either 'roboto-font', NEVER both!
//"vazir",
// "roboto-font", // optional, you are not bound to it
"material-icons", // optional, you are not bound to it
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.