Cannot load my own font in quasar framework
Asked Answered
F

4

7

Im building an application only for tablet and I want to use my own font in ttf format. How can I load .ttf fonts into quasar?

Another option would be to convert it to woff?

I have tried this in app.scss but it didnt work:

@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;
}
Fluellen answered 3/11, 2020 at 14:57 Comment(1)
No doubt you moved on, but here's a really helpful font setup site google-webfonts-helper Creates the CSS definitions and also provides font download collections with many optionsWarford
D
7

1-Put Your font Files in ./src/css/fonts Folder

2-Delclare the Font Name inside ./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-Define Font in ./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 roboto-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
    ],
Dylane answered 9/8, 2022 at 4:47 Comment(0)
B
6

Remove the ‘roboto-font’ from the quasar.config.js file (unless you intend to still use it as a secondary font). Either select a font from Google Fonts for import, or download a font family .WOFF file to include.

Similar to the documentation ( https://quasar.dev/style/typography#Add-custom-fonts ), you should import the font-family, but it should go into the ‘src/css/quasar.variables.*’ file. Then, change one or more of the default styling variables.

I’m going to assume Sass for examples below:

// 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
Boustrophedon answered 23/12, 2020 at 12:4 Comment(0)
D
4

Hi everyone for people with recent version, my solution was:

Put your custom font, here: enter image description here

and load it like this for example in app.scss: enter image description here

And in the quasar.conf.js, you should comment the line with "roboto-font" like this: enter image description here

Hope it helps, cheers!

Dayak answered 25/4, 2021 at 9:50 Comment(0)
F
1

I use stylus without removing any line for fonts as others suggested but by doing the following steps:

  1. Download font to specific folder i.e 'assets/fonts/plex'
  2. Declare the font name.
  3. Set $typography-font-family in quasar.variables.styl

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'

quasar install config:

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)
Forecast answered 1/8, 2021 at 10:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.