Skip to content

Commit

Permalink
[K8] Added Inter font files for new theme (#102359)
Browse files Browse the repository at this point in the history
Updated the `Fonts` file to accept a `themeVersion` and only use the old Beta files if `v7`.
  • Loading branch information
cchaos committed Jun 17, 2021
1 parent 02c1c61 commit e483351
Show file tree
Hide file tree
Showing 48 changed files with 254 additions and 65 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
94 changes: 94 additions & 0 deletions src/core/server/core_app/assets/fonts/inter/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Copyright (c) 2016-2020 The Inter Project Authors.
"Inter" is trademark of Rasmus Andersson.
https://github.com/rsms/inter

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL

-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION AND CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
3 changes: 2 additions & 1 deletion src/core/server/core_app/assets/fonts/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## Font usage

Kibana packages two fonts:
Kibana packages three fonts:

* [Inter](https://rsms.me/inter/) fonts were pulled from their site and are at v3.18
* [Inter UI](https://rsms.me/inter/) fonts were pulled from their site and are at v3.2
* [Roboto Mono](https://fonts.google.com/specimen/Roboto+Mono) was pulled from the Google Fonts website on January 22, 2019.

Expand Down
1 change: 1 addition & 0 deletions src/core/server/rendering/rendering_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class RenderingService {
locale: i18n.getLocale(),
darkMode,
stylesheetPaths,
themeVersion,
injectedMetadata: {
version: env.packageInfo.version,
buildNumber: env.packageInfo.buildNum,
Expand Down
1 change: 1 addition & 0 deletions src/core/server/rendering/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface RenderingMetadata {
i18n: typeof i18n.translate;
locale: string;
darkMode: boolean;
themeVersion?: string;
stylesheetPaths: string[];
injectedMetadata: {
version: string;
Expand Down
215 changes: 153 additions & 62 deletions src/core/server/rendering/views/fonts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { RenderingMetadata } from '../types';

interface Props {
url: RenderingMetadata['uiPublicUrl'];
themeVersion?: string;
}

interface FontFace {
Expand All @@ -27,8 +28,145 @@ interface FontFace {
}>;
}

export const Fonts: FunctionComponent<Props> = ({ url }) => {
const interUi: FontFace = {
/**
* `Inter` is the latest version of `Inter UI` and used specifically in v8 of Kibana from EUI Amsterdam
*/
const getInter = (url: string): FontFace => {
return {
family: 'Inter',
variants: [
{
style: 'normal',
weight: 100,
sources: [`${url}/fonts/inter/Inter-Thin.woff2`, `${url}/fonts/inter/Inter-Thin.woff`],
},
{
style: 'italic',
weight: 100,
sources: [
`${url}/fonts/inter/Inter-ThinItalic.woff2`,
`${url}/fonts/inter/Inter-ThinItalic.woff`,
],
},
{
style: 'normal',
weight: 200,
sources: [
`${url}/fonts/inter/Inter-ExtraLight.woff2`,
`${url}/fonts/inter/Inter-ExtraLight.woff`,
],
},
{
style: 'italic',
weight: 200,
sources: [
`${url}/fonts/inter/Inter-ExtraLightItalic.woff2`,
`${url}/fonts/inter/Inter-ExtraLightItalic.woff`,
],
},
{
style: 'normal',
weight: 300,
sources: [`${url}/fonts/inter/Inter-Light.woff2`, `${url}/fonts/inter/Inter-Light.woff`],
},
{
style: 'italic',
weight: 300,
sources: [
`${url}/fonts/inter/Inter-LightItalic.woff2`,
`${url}/fonts/inter/Inter-LightItalic.woff`,
],
},
{
style: 'normal',
weight: 400,
sources: [
`${url}/fonts/inter/Inter-Regular.woff2`,
`${url}/fonts/inter/Inter-Regular.woff`,
],
},
{
style: 'italic',
weight: 400,
sources: [`${url}/fonts/inter/Inter-Italic.woff2`, `${url}/fonts/inter/Inter-Italic.woff`],
},
{
style: 'normal',
weight: 500,
sources: [`${url}/fonts/inter/Inter-Medium.woff2`, `${url}/fonts/inter/Inter-Medium.woff`],
},
{
style: 'italic',
weight: 500,
sources: [
`${url}/fonts/inter/Inter-MediumItalic.woff2`,
`${url}/fonts/inter/Inter-MediumItalic.woff`,
],
},
{
style: 'normal',
weight: 600,
sources: [
`${url}/fonts/inter/Inter-SemiBold.woff2`,
`${url}/fonts/inter/Inter-SemiBold.woff`,
],
},
{
style: 'italic',
weight: 600,
sources: [
`${url}/fonts/inter/Inter-SemiBoldItalic.woff2`,
`${url}/fonts/inter/Inter-SemiBoldItalic.woff`,
],
},
{
style: 'normal',
weight: 700,
sources: [`${url}/fonts/inter/Inter-Bold.woff2`, `${url}/fonts/inter/Inter-Bold.woff`],
},
{
style: 'italic',
weight: 700,
sources: [
`${url}/fonts/inter/Inter-BoldItalic.woff2`,
`${url}/fonts/inter/Inter-BoldItalic.woff`,
],
},
{
style: 'normal',
weight: 800,
sources: [
`${url}/fonts/inter/Inter-ExtraBold.woff2`,
`${url}/fonts/inter/Inter-ExtraBold.woff`,
],
},
{
style: 'italic',
weight: 800,
sources: [
`${url}/fonts/inter/Inter-ExtraBoldItalic.woff2`,
`${url}/fonts/inter/Inter-ExtraBoldItalic.woff`,
],
},
{
style: 'normal',
weight: 900,
sources: [`${url}/fonts/inter/Inter-Black.woff2`, `${url}/fonts/inter/Inter-Black.woff`],
},
{
style: 'italic',
weight: 900,
sources: [
`${url}/fonts/inter/Inter-BlackItalic.woff2`,
`${url}/fonts/inter/Inter-BlackItalic.woff`,
],
},
],
};
};

const getInterUi = (url: string): FontFace => {
return {
family: 'Inter UI',
variants: [
{
Expand Down Expand Up @@ -177,7 +315,10 @@ export const Fonts: FunctionComponent<Props> = ({ url }) => {
},
],
};
const roboto: FontFace = {
};

const getRoboto = (url: string): FontFace => {
return {
family: 'Roboto Mono',
variants: [
{
Expand Down Expand Up @@ -229,12 +370,20 @@ export const Fonts: FunctionComponent<Props> = ({ url }) => {
},
],
};
};

export const Fonts: FunctionComponent<Props> = ({ url, themeVersion }) => {
/**
* If `themeVersion` is not provided, we want to fallback to the newest font family `Inter`
*/
const sansFont = themeVersion === 'v7' ? getInterUi(url) : getInter(url);
const codeFont = getRoboto(url);

return (
<style
dangerouslySetInnerHTML={{
__html: `
${[interUi, roboto]
${[sansFont, codeFont]
.flatMap(({ family, variants }) =>
variants.map(({ style, weight, format, sources, unicodeRange }) => {
const src = sources
Expand All @@ -260,64 +409,6 @@ export const Fonts: FunctionComponent<Props> = ({ url }) => {
})
)
.join('\n')}
/*
Single variable font.
Note that you may want to do something like this to make sure you're serving
constant fonts to older browsers:
html {
font-family: 'Inter UI', sans-serif;
}
@supports (font-variation-settings: normal) {
html {
font-family: 'Inter UI var', sans-serif;
}
}
BUGS:
- Safari 12.0 will default to italic instead of regular when font-weight
is provided in a @font-face declaration.
Workaround: Use 'Inter UI var alt' for Safari, or explicitly set
\`font-variation-settings: 'slnt' DEGREE\`.
@font-face {
font-family: 'Inter UI var';
font-weight: 100 900;
font-style: oblique 0deg 10deg;
src:
url('${url}/fonts/inter_ui/Inter-UI.var.woff2') format('woff2-variations'),
url('${url}/fonts/inter_ui/Inter-UI.var.woff2') format('woff2');
}
'Inter UI var alt' is recommended for Safari and Edge, for reliable italics.
@supports (font-variation-settings: normal) {
html {
font-family: 'Inter UI var alt', sans-serif;
}
}
@font-face {
font-family: 'Inter UI var alt';
font-weight: 100 900;
font-style: normal;
font-named-instance: 'Regular';
src:
url('${url}/fonts/inter_ui/Inter-UI-upright.var.woff2') format('woff2 supports variations(gvar)'),
url('${url}/fonts/inter_ui/Inter-UI-upright.var.woff2') format('woff2-variations'),
url('${url}/fonts/inter_ui/Inter-UI-upright.var.woff2') format('woff2');
}
@font-face {
font-family: 'Inter UI var alt';
font-weight: 100 900;
font-style: italic;
font-named-instance: 'Italic';
src:
url('${url}/fonts/inter_ui/Inter-UI-italic.var.woff2') format('woff2 supports variations(gvar)'),
url('${url}/fonts/inter_ui/Inter-UI-italic.var.woff2') format('woff2-variations'),
url('${url}/fonts/inter_ui/Inter-UI-italic.var.woff2') format('woff2');
}
*/
`,
}}
/>
Expand Down
3 changes: 2 additions & 1 deletion src/core/server/rendering/views/template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const Template: FunctionComponent<Props> = ({
uiPublicUrl,
locale,
darkMode,
themeVersion,
stylesheetPaths,
injectedMetadata,
i18n,
Expand All @@ -36,7 +37,7 @@ export const Template: FunctionComponent<Props> = ({
<meta httpEquiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width" />
<title>Elastic</title>
<Fonts url={uiPublicUrl} />
<Fonts themeVersion={themeVersion} url={uiPublicUrl} />
{/* The alternate icon is a fallback for Safari which does not yet support SVG favicons */}
<link rel="alternate icon" type="image/png" href={`${uiPublicUrl}/favicons/favicon.png`} />
<link rel="icon" type="image/svg+xml" href={`${uiPublicUrl}/favicons/favicon.svg`} />
Expand Down
Loading

0 comments on commit e483351

Please sign in to comment.