Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fonts: Roboto #614

Merged
merged 1 commit into from Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/fonts.yml
Expand Up @@ -21,6 +21,7 @@ jobs:
font:
- inter
- jetbrains-mono
- roboto

runs-on: ubuntu-latest
if: |
Expand Down
Expand Up @@ -190,6 +190,8 @@ public static float computeTextYCorrection( Graphics2D g ) {
case "Inter Light":
case "Inter Semi Bold":
case "Roboto":
case "Roboto Light":
case "Roboto Medium":
return correctionForScaleY( g, CORRECTION_INTER );

case "Noto Sans":
Expand Down
2 changes: 2 additions & 0 deletions flatlaf-demo/build.gradle.kts
Expand Up @@ -23,6 +23,7 @@ dependencies {
implementation( project( ":flatlaf-core" ) )
implementation( project( ":flatlaf-extras" ) )
implementation( project( ":flatlaf-fonts-inter" ) )
implementation( project( ":flatlaf-fonts-roboto" ) )
implementation( project( ":flatlaf-intellij-themes" ) )
implementation( "com.miglayout:miglayout-swing:5.3" )
implementation( "com.jgoodies:jgoodies-forms:1.9.0" )
Expand All @@ -34,6 +35,7 @@ tasks {
dependsOn( ":flatlaf-core:jar" )
dependsOn( ":flatlaf-extras:jar" )
dependsOn( ":flatlaf-fonts-inter:jar" )
dependsOn( ":flatlaf-fonts-roboto:jar" )
dependsOn( ":flatlaf-intellij-themes:jar" )
// dependsOn( ":flatlaf-natives-jna:jar" )

Expand Down
Expand Up @@ -44,6 +44,7 @@
import com.formdev.flatlaf.extras.components.FlatButton;
import com.formdev.flatlaf.extras.components.FlatButton.ButtonType;
import com.formdev.flatlaf.fonts.inter.FlatInterFont;
import com.formdev.flatlaf.fonts.roboto.FlatRobotoFont;
import com.formdev.flatlaf.icons.FlatAbstractIcon;
import com.formdev.flatlaf.themes.FlatMacDarkLaf;
import com.formdev.flatlaf.themes.FlatMacLightLaf;
Expand All @@ -66,6 +67,7 @@ class DemoFrame
{
private final String[] availableFontFamilyNames;
private boolean interFontInstalled;
private boolean robotoFontInstalled;
private int initialFontMenuItemCount = -1;

DemoFrame() {
Expand Down Expand Up @@ -288,6 +290,12 @@ private void fontFamilyChanged( ActionEvent e ) {
interFontInstalled = true;
}

// install Roboto font on demand
if( fontFamily.equals( FlatRobotoFont.FAMILY ) && !robotoFontInstalled ) {
FlatRobotoFont.install();
robotoFontInstalled = true;
}

FlatAnimatedLafChange.showSnapshot();

Font font = UIManager.getFont( "defaultFont" );
Expand Down Expand Up @@ -361,7 +369,8 @@ void updateFontMenuItems() {
ButtonGroup familiesGroup = new ButtonGroup();
for( String family : families ) {
if( Arrays.binarySearch( availableFontFamilyNames, family ) < 0 &&
!family.equals( FlatInterFont.FAMILY ) )
!family.equals( FlatInterFont.FAMILY ) &&
!family.equals( FlatRobotoFont.FAMILY ) )
continue; // not available

JCheckBoxMenuItem item = new JCheckBoxMenuItem( family );
Expand Down
1 change: 1 addition & 0 deletions flatlaf-fonts/README.md
Expand Up @@ -6,3 +6,4 @@ easy-to-use and redistributable JARs.

- [Inter](flatlaf-fonts-inter) font
- [JetBrains Mono](flatlaf-fonts-jetbrains-mono) font
- [Roboto](flatlaf-fonts-roboto) font
76 changes: 76 additions & 0 deletions flatlaf-fonts/flatlaf-fonts-roboto/README.md
@@ -0,0 +1,76 @@
Roboto font
===========

This sub-project contains fonts from the Roboto font family and bundles them
into an easy-to-use and redistributable JAR.

Font home page: https://fonts.google.com/specimen/Roboto

GitHub project: https://github.com/googlefonts/roboto

License:
[Apache License, Version 2.0](src/main/resources/com/formdev/flatlaf/fonts/roboto/LICENSE.txt)


How to install?
---------------

Invoke the `install()` method once (e.g. in your `main()` method; on AWT
thread):

~~~java
FlatRobotoFont.install();
~~~


How to use?
-----------

Use as default font:

~~~java
FlatLaf.setPreferredFontFamily( FlatRobotoFont.FAMILY );
FlatLaf.setPreferredLightFontFamily( FlatRobotoFont.FAMILY_LIGHT );
FlatLaf.setPreferredSemiboldFontFamily( FlatRobotoFont.FAMILY_SEMIBOLD );
~~~

Create fonts:

~~~java
// basic styles
new Font( FlatRobotoFont.FAMILY, Font.PLAIN, 12 );
new Font( FlatRobotoFont.FAMILY, Font.ITALIC, 12 );
new Font( FlatRobotoFont.FAMILY, Font.BOLD, 12 );
new Font( FlatRobotoFont.FAMILY, Font.BOLD | Font.ITALIC, 12 );

// light
new Font( FlatRobotoFont.FAMILY_LIGHT, Font.PLAIN, 12 );
new Font( FlatRobotoFont.FAMILY_LIGHT, Font.ITALIC, 12 );

// semibold
new Font( FlatRobotoFont.FAMILY_SEMIBOLD, Font.PLAIN, 12 );
new Font( FlatRobotoFont.FAMILY_SEMIBOLD, Font.ITALIC, 12 );
~~~


Download
--------

Not yet available.

<!--

FlatLaf Fonts binaries are available on **Maven Central**.

If you use Maven or Gradle, add a dependency with following coordinates to your
build script:

groupId: com.formdev
artifactId: flatlaf-fonts-roboto
version: (see button below)

Otherwise download `flatlaf-fonts-roboto-<version>.jar` here:

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.formdev/flatlaf-fonts-roboto/badge.svg?style=flat-square&color=007ec6)](https://maven-badges.herokuapp.com/maven-central/com.formdev/flatlaf-fonts-roboto)

-->
62 changes: 62 additions & 0 deletions flatlaf-fonts/flatlaf-fonts-roboto/build.gradle.kts
@@ -0,0 +1,62 @@
/*
* Copyright 2022 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Version format: <font-version>[-<build-number>]
// For maven compatibility, <font-version> should be in format <major>.<minor>[.<micro>].
// <build-number> is optional and should be incremented only if a new release is
// necessary, but the <font-version> has not changed.
version = "2.137"

if( !rootProject.hasProperty( "release" ) )
version = version.toString() + "-SNAPSHOT"


plugins {
`java-library`
`flatlaf-module-info`
`flatlaf-publish`
}

dependencies {
testImplementation( "org.junit.jupiter:junit-jupiter-api:5.7.2" )
testImplementation( "org.junit.jupiter:junit-jupiter-params" )
testRuntimeOnly( "org.junit.jupiter:junit-jupiter-engine" )
}

java {
withSourcesJar()
withJavadocJar()
}

tasks {
named<Jar>( "sourcesJar" ) {
exclude( "**/*.ttf", "**/*.otf" )
}

test {
useJUnitPlatform()
testLogging.exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}

withType<PublishToMavenRepository>().configureEach {
onlyIf { !rootProject.hasProperty( "skipFonts" ) }
}
}

flatlafPublish {
artifactId = "flatlaf-fonts-roboto"
name = "FlatLaf Roboto Fonts Pack"
}
@@ -0,0 +1,150 @@
/*
* Copyright 2022 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.formdev.flatlaf.fonts.roboto;

import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.io.IOException;
import java.io.InputStream;

/**
* The Roboto font family.
* <p>
* Font home page: <a href="https://fonts.google.com/specimen/Roboto">https://fonts.google.com/specimen/Roboto</a><br>
* GitHub project: <a href="https://github.com/googlefonts/roboto">https://github.com/googlefonts/roboto</a>
* <p>
* To install the font, invoke following once (e.g. in your {@code main()} method; on AWT thread):
* <pre>{@code
* FlatRobotoFont.install();
* }</pre>
* <p>
* Use as default font:
* <pre>{@code
* FlatLaf.setPreferredFontFamily( FlatRobotoFont.FAMILY );
* FlatLaf.setPreferredLightFontFamily( FlatRobotoFont.FAMILY_LIGHT );
* FlatLaf.setPreferredSemiboldFontFamily( FlatRobotoFont.FAMILY_SEMIBOLD );
* }</pre>
* <p>
* Create fonts:
* <pre>{@code
* new Font( FlatRobotoFont.FAMILY, Font.PLAIN, 12 );
* new Font( FlatRobotoFont.FAMILY, Font.ITALIC, 12 );
* new Font( FlatRobotoFont.FAMILY, Font.BOLD, 12 );
* new Font( FlatRobotoFont.FAMILY, Font.BOLD | Font.ITALIC, 12 );
* new Font( FlatRobotoFont.FAMILY_LIGHT, Font.PLAIN, 12 );
* new Font( FlatRobotoFont.FAMILY_LIGHT, Font.ITALIC, 12 );
* new Font( FlatRobotoFont.FAMILY_SEMIBOLD, Font.PLAIN, 12 );
* new Font( FlatRobotoFont.FAMILY_SEMIBOLD, Font.ITALIC, 12 );
* }</pre>
*
* @author Karl Tauber
*/
public class FlatRobotoFont
{
/**
* Family name for basic styles (regular, italic and bold).
* <p>
* Usage:
* <pre>{@code
* new Font( FlatRobotoFont.FAMILY, Font.PLAIN, 12 );
* new Font( FlatRobotoFont.FAMILY, Font.ITALIC, 12 );
* new Font( FlatRobotoFont.FAMILY, Font.BOLD, 12 );
* new Font( FlatRobotoFont.FAMILY, Font.BOLD | Font.ITALIC, 12 );
* }</pre>
*/
public static final String FAMILY = "Roboto";

/**
* Family name for light styles.
* <p>
* Usage:
* <pre>{@code
* new Font( FlatRobotoFont.FAMILY_LIGHT, Font.PLAIN, 12 );
* new Font( FlatRobotoFont.FAMILY_LIGHT, Font.ITALIC, 12 );
* }</pre>
*/
public static final String FAMILY_LIGHT = "Roboto Light";

/**
* Family name for semibold styles.
* <p>
* Usage:
* <pre>{@code
* new Font( FlatRobotoFont.FAMILY_SEMIBOLD, Font.PLAIN, 12 );
* new Font( FlatRobotoFont.FAMILY_SEMIBOLD, Font.ITALIC, 12 );
* }</pre>
*/
public static final String FAMILY_SEMIBOLD = "Roboto Medium";

/**
* Use for {@link #installStyle(String)} to install single font style.
*/
public static final String
// basic styles
STYLE_REGULAR = "Roboto-Regular.ttf",
STYLE_ITALIC = "Roboto-Italic.ttf",
STYLE_BOLD = "Roboto-Bold.ttf",
STYLE_BOLD_ITALIC = "Roboto-BoldItalic.ttf",

// light
STYLE_LIGHT = "Roboto-Light.ttf",
STYLE_LIGHT_ITALIC = "Roboto-LightItalic.ttf",

// semibold
STYLE_SEMIBOLD = "Roboto-Medium.ttf",
STYLE_SEMIBOLD_ITALIC = "Roboto-MediumItalic.ttf";


private FlatRobotoFont() {}

/**
* Creates and registers the fonts for all styles.
*/
public static void install() {
// basic styles
installStyle( STYLE_REGULAR );
installStyle( STYLE_ITALIC );
installStyle( STYLE_BOLD );
installStyle( STYLE_BOLD_ITALIC );

// light
installStyle( STYLE_LIGHT );
installStyle( STYLE_LIGHT_ITALIC );

// semibold
installStyle( STYLE_SEMIBOLD );
installStyle( STYLE_SEMIBOLD_ITALIC );
}

/**
* Creates and registers the font for the given style.
* See {@code STYLE_} constants.
*/
public static boolean installStyle( String name ) {
try( InputStream in = FlatRobotoFont.class.getResourceAsStream( name ) ) {
Font font = Font.createFont( Font.TRUETYPE_FONT, in );
return GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont( font );
} catch( FontFormatException ex ) {
ex.printStackTrace();
return false;
} catch( IOException ex ) {
ex.printStackTrace();
return false;
}
}
}
@@ -0,0 +1,26 @@
/*
* Copyright 2022 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @author Karl Tauber
*/
module com.formdev.flatlaf.fonts.roboto {
requires java.desktop;

exports com.formdev.flatlaf.fonts.roboto;

opens com.formdev.flatlaf.fonts.roboto;
}