Skip to content

Commit

Permalink
chore: Update font stack
Browse files Browse the repository at this point in the history
Get fonts from fontsource: Removes requirements to check in fonts while still self-hosting them.
Fonts can also receive updates through npm.
Use Roboto in addition to the standard tailwind font stack: Instead of falling back to only
Helvetica Neue and sans-serif, use the tailwind defaults if other fonts could not be loaded.
Add the bold (700) variation of Roboto: Previously, browsers were approximating the bold version.
This caused some weird font rendering issues on bold text.
Move to Material Symbols: Google's old icon font (Material Icons) is deprecated. Theoretically,
Material Symbols also supports a variable version with customizable fill, weight, etc but as this
version is 3MB, I've decided to go with a static version of it.

Closes #1744
  • Loading branch information
zusorio committed Sep 12, 2024
1 parent f43efb9 commit 9697056
Show file tree
Hide file tree
Showing 22 changed files with 241 additions and 112 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ repos:
- '[email protected]'
- 'prettier-plugin-tailwindcss@^0.6.6'
- '@trivago/prettier-plugin-sort-imports@^4.3.0'
- 'tailwindcss@^3.4.10'
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
hooks:
Expand Down
2 changes: 2 additions & 0 deletions frontend/.storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { Preview } from '@storybook/angular';
import { applicationConfig } from '@storybook/angular';
import { ToastrModule } from 'ngx-toastr';
import docJson from '../documentation.json';
import { IconModule } from '../src/app/icon.module';

setCompodocJson(docJson);

Expand Down Expand Up @@ -41,6 +42,7 @@ const preview: Preview = {
includeTitleDuplicates: true,
}),
RouterModule.forRoot([]),
IconModule,
),
importProvidersFrom(BrowserAnimationsModule),
{ provide: MatDialogRef, useValue: {} },
Expand Down
242 changes: 208 additions & 34 deletions frontend/package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"@angular/platform-browser": "~18.2.3",
"@angular/platform-browser-dynamic": "~18.2.3",
"@angular/router": "~18.2.3",
"@fontsource/material-symbols-outlined": "^5.0.41",
"@fontsource/roboto": "^5.0.15",
"@ngneat/until-destroy": "^10.0.0",
"@panzoom/panzoom": "^4.5.1",
"file-saver": "^2.0.5",
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/app/icon.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { NgModule } from '@angular/core';
import { MatIconRegistry } from '@angular/material/icon';

@NgModule({})
export class IconModule {
constructor(private matIconReg: MatIconRegistry) {
this.matIconReg.setDefaultFontSetClass('material-symbols-outlined');
}
}
Binary file not shown.

This file was deleted.

Binary file removed frontend/src/fonts/roboto-v30-latin-300.woff2
Binary file not shown.
2 changes: 0 additions & 2 deletions frontend/src/fonts/roboto-v30-latin-300.woff2.license

This file was deleted.

Binary file removed frontend/src/fonts/roboto-v30-latin-300italic.woff2
Binary file not shown.
2 changes: 0 additions & 2 deletions frontend/src/fonts/roboto-v30-latin-300italic.woff2.license

This file was deleted.

Binary file removed frontend/src/fonts/roboto-v30-latin-500.woff2
Binary file not shown.
2 changes: 0 additions & 2 deletions frontend/src/fonts/roboto-v30-latin-500.woff2.license

This file was deleted.

Binary file removed frontend/src/fonts/roboto-v30-latin-500italic.woff2
Binary file not shown.
2 changes: 0 additions & 2 deletions frontend/src/fonts/roboto-v30-latin-500italic.woff2.license

This file was deleted.

Binary file removed frontend/src/fonts/roboto-v30-latin-italic.woff2
Binary file not shown.
2 changes: 0 additions & 2 deletions frontend/src/fonts/roboto-v30-latin-italic.woff2.license

This file was deleted.

Binary file removed frontend/src/fonts/roboto-v30-latin-regular.woff2
Binary file not shown.
2 changes: 0 additions & 2 deletions frontend/src/fonts/roboto-v30-latin-regular.woff2.license

This file was deleted.

2 changes: 2 additions & 0 deletions frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { AppRoutingModule } from './app/app-routing.module';
import { AppComponent } from './app/app.component';
import { AuthInterceptor } from './app/general/auth/http-interceptor/auth.interceptor';
import { ErrorHandlingInterceptor } from './app/general/error-handling/error-handling.interceptor';
import { IconModule } from './app/icon.module';
import { environment } from './environments/environment';

if (environment.production) {
Expand All @@ -38,6 +39,7 @@ bootstrapApplication(AppComponent, {
resetTimeoutOnDuplicate: true,
includeTitleDuplicates: true,
}),
IconModule,
),
{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
{
Expand Down
73 changes: 9 additions & 64 deletions frontend/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,25 @@

/* You can add global styles to this file, and also import other style files */

@import "@fontsource/roboto/300.css";
@import "@fontsource/roboto/400.css";
@import "@fontsource/roboto/500.css";
@import "@fontsource/roboto/700.css";
@import "@fontsource/material-symbols-outlined/400.css";

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
@font-face {
font-display: swap;
font-family: "Roboto";
font-style: normal;
font-weight: 300;
src: url("fonts/roboto-v30-latin-300.woff2") format("woff2");
}
@font-face {
font-display: swap;
font-family: "Roboto";
font-style: italic;
font-weight: 300;
src: url("fonts/roboto-v30-latin-300italic.woff2") format("woff2");
}
@font-face {
font-display: swap;
font-family: "Roboto";
font-style: normal;
font-weight: 400;
src: url("fonts/roboto-v30-latin-regular.woff2") format("woff2");
}
@font-face {
font-display: swap;
font-family: "Roboto";
font-style: italic;
font-weight: 400;
src: url("fonts/roboto-v30-latin-italic.woff2") format("woff2");
}
@font-face {
font-display: swap;
font-family: "Roboto";
font-style: normal;
font-weight: 500;
src: url("fonts/roboto-v30-latin-500.woff2") format("woff2");
}
@font-face {
font-display: swap;
font-family: "Roboto";
font-style: italic;
font-weight: 500;
src: url("fonts/roboto-v30-latin-500italic.woff2") format("woff2");
}
@font-face {
font-display: swap;
font-family: "Material Icons";
font-style: normal;
font-weight: 400;
src: url("fonts/material-icons-v142-latin-regular.woff2") format("woff2");
}
}

html,
body {
height: 100%;
font-size: 100%;
}

/* Copied from https://developers.google.com/fonts/docs/material_icons#setup_method_2_self_hosting */
.material-icons {
font-family: "Material Icons";
/* Copied from https://fontsource.org/docs/getting-started/material-symbols */
.material-symbols-outlined {
font-family: "Material Symbols Outlined";
font-weight: normal;
font-style: normal;
font-size: 24px; /* Preferred icon size */
Expand All @@ -80,14 +34,6 @@ body {
word-wrap: normal;
white-space: nowrap;
direction: ltr;

/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;

/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;
}

html {
Expand All @@ -97,7 +43,6 @@ html {

body {
@apply m-0;
font-family: Roboto, "Helvetica Neue", sans-serif;
}

a {
Expand Down
4 changes: 4 additions & 0 deletions frontend/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
* SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
* SPDX-License-Identifier: Apache-2.0
*/
const defaultTheme = require("tailwindcss/defaultTheme");

/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{html,ts}"],
theme: {
extend: {
fontFamily: {
sans: ["Roboto", ...defaultTheme.fontFamily.sans],
},
colors: {
primary: "var(--primary-color)",
error: "var(--error-color)",
Expand Down

0 comments on commit 9697056

Please sign in to comment.