mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 05:50:53 +03:00
@@ -18,18 +18,29 @@ License:
|
||||
How to install?
|
||||
---------------
|
||||
|
||||
Invoke the `install()` method once (e.g. in your `main()` method; on AWT
|
||||
thread):
|
||||
Invoke following once (e.g. in your `main()` method; on AWT thread).
|
||||
|
||||
For lazy loading use:
|
||||
|
||||
~~~java
|
||||
FlatInterFont.installLazy();
|
||||
~~~
|
||||
|
||||
Or load immediately with:
|
||||
|
||||
~~~java
|
||||
FlatInterFont.install();
|
||||
// or
|
||||
FlatInterFont.installBasic();
|
||||
FlatInterFont.installLight();
|
||||
FlatInterFont.installSemiBold();
|
||||
~~~
|
||||
|
||||
|
||||
How to use?
|
||||
-----------
|
||||
|
||||
Use as default font:
|
||||
Use as application font (invoke before setting up FlatLaf):
|
||||
|
||||
~~~java
|
||||
FlatLaf.setPreferredFontFamily( FlatInterFont.FAMILY );
|
||||
@@ -37,7 +48,7 @@ FlatLaf.setPreferredLightFontFamily( FlatInterFont.FAMILY_LIGHT );
|
||||
FlatLaf.setPreferredSemiboldFontFamily( FlatInterFont.FAMILY_SEMIBOLD );
|
||||
~~~
|
||||
|
||||
Create fonts:
|
||||
Create single fonts:
|
||||
|
||||
~~~java
|
||||
// basic styles
|
||||
@@ -55,6 +66,27 @@ new Font( FlatInterFont.FAMILY_SEMIBOLD, Font.PLAIN, 12 );
|
||||
new Font( FlatInterFont.FAMILY_SEMIBOLD, Font.ITALIC, 12 );
|
||||
~~~
|
||||
|
||||
If using lazy loading, invoke one of following before creating the font:
|
||||
|
||||
~~~java
|
||||
FontUtils.loadFontFamily( FlatInterFont.FAMILY );
|
||||
FontUtils.loadFontFamily( FlatInterFont.FAMILY_LIGHT );
|
||||
FontUtils.loadFontFamily( FlatInterFont.FAMILY_SEMIBOLD );
|
||||
~~~
|
||||
|
||||
E.g.:
|
||||
|
||||
~~~java
|
||||
FontUtils.loadFontFamily( FlatInterFont.FAMILY );
|
||||
Font font = new Font( FlatInterFont.FAMILY, Font.PLAIN, 12 );
|
||||
~~~
|
||||
|
||||
Or use following:
|
||||
|
||||
~~~java
|
||||
Font font = FontUtils.getCompositeFont( FlatInterFont.FAMILY, Font.PLAIN, 12 );
|
||||
~~~
|
||||
|
||||
|
||||
Download
|
||||
--------
|
||||
|
||||
@@ -31,6 +31,8 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation( project( ":flatlaf-core" ) )
|
||||
|
||||
testImplementation( "org.junit.jupiter:junit-jupiter-api:5.7.2" )
|
||||
testImplementation( "org.junit.jupiter:junit-jupiter-params" )
|
||||
testRuntimeOnly( "org.junit.jupiter:junit-jupiter-engine" )
|
||||
|
||||
@@ -16,11 +16,7 @@
|
||||
|
||||
package com.formdev.flatlaf.fonts.inter;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontFormatException;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import com.formdev.flatlaf.util.FontUtils;
|
||||
|
||||
/**
|
||||
* The Inter font family.
|
||||
@@ -31,19 +27,30 @@ import java.io.InputStream;
|
||||
* Font home page: <a href="https://rsms.me/inter/">https://rsms.me/inter/</a><br>
|
||||
* GitHub project: <a href="https://github.com/rsms/inter">https://github.com/rsms/inter</a>
|
||||
* <p>
|
||||
* To install the font, invoke following once (e.g. in your {@code main()} method; on AWT thread):
|
||||
* To install the font, invoke following once (e.g. in your {@code main()} method; on AWT thread).
|
||||
* <p>
|
||||
* For lazy loading use:
|
||||
* <pre>{@code
|
||||
* FlatInterFont.install();
|
||||
* FlatInterFont.installLazy();
|
||||
* }</pre>
|
||||
* <p>
|
||||
* Use as default font:
|
||||
* Or load immediately with:
|
||||
* <pre>{@code
|
||||
* FlatInterFont.install();
|
||||
* // or
|
||||
* FlatInterFont.installBasic();
|
||||
* FlatInterFont.installLight();
|
||||
* FlatInterFont.installSemiBold();
|
||||
* }</pre>
|
||||
* <p>
|
||||
* Use as application font (invoke before setting up FlatLaf):
|
||||
* <pre>{@code
|
||||
* FlatLaf.setPreferredFontFamily( FlatInterFont.FAMILY );
|
||||
* FlatLaf.setPreferredLightFontFamily( FlatInterFont.FAMILY_LIGHT );
|
||||
* FlatLaf.setPreferredSemiboldFontFamily( FlatInterFont.FAMILY_SEMIBOLD );
|
||||
* }</pre>
|
||||
* <p>
|
||||
* Create fonts:
|
||||
* Create single fonts:
|
||||
* <pre>{@code
|
||||
* new Font( FlatInterFont.FAMILY, Font.PLAIN, 12 );
|
||||
* new Font( FlatInterFont.FAMILY, Font.ITALIC, 12 );
|
||||
@@ -54,6 +61,24 @@ import java.io.InputStream;
|
||||
* new Font( FlatInterFont.FAMILY_SEMIBOLD, Font.PLAIN, 12 );
|
||||
* new Font( FlatInterFont.FAMILY_SEMIBOLD, Font.ITALIC, 12 );
|
||||
* }</pre>
|
||||
* <p>
|
||||
* If using lazy loading, invoke one of following before creating the font:
|
||||
* <pre>{@code
|
||||
* FontUtils.loadFontFamily( FlatInterFont.FAMILY );
|
||||
* FontUtils.loadFontFamily( FlatInterFont.FAMILY_LIGHT );
|
||||
* FontUtils.loadFontFamily( FlatInterFont.FAMILY_SEMIBOLD );
|
||||
* }</pre>
|
||||
* <p>
|
||||
* E.g.:
|
||||
* <pre>{@code
|
||||
* FontUtils.loadFontFamily( FlatInterFont.FAMILY );
|
||||
* Font font = new Font( FlatInterFont.FAMILY, Font.PLAIN, 12 );
|
||||
* }</pre>
|
||||
* <p>
|
||||
* Or use following:
|
||||
* <pre>{@code
|
||||
* Font font = FontUtils.getCompositeFont( FlatInterFont.FAMILY, Font.PLAIN, 12 );
|
||||
* }</pre>
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
@@ -115,21 +140,61 @@ public class FlatInterFont
|
||||
|
||||
private FlatInterFont() {}
|
||||
|
||||
/**
|
||||
* Registers the fonts for lazy loading via {@link FontUtils#registerFontFamilyLoader(String, Runnable)}.
|
||||
* <p>
|
||||
* This is the preferred method (when using FlatLaf) to avoid unnecessary loading of maybe unused fonts.
|
||||
* <p>
|
||||
* <strong>Note</strong>: When using '{@code new Font(...)}', you need to first invoke
|
||||
* {@link FontUtils#loadFontFamily(family)} to ensure that the font family is loaded.
|
||||
* When FlatLaf loads a font, or when using {@link FontUtils#getCompositeFont(family, style, size)},
|
||||
* this is done automatically.
|
||||
*/
|
||||
public static void installLazy() {
|
||||
FontUtils.registerFontFamilyLoader( FAMILY, FlatInterFont::installBasic );
|
||||
FontUtils.registerFontFamilyLoader( FAMILY_LIGHT, FlatInterFont::installLight );
|
||||
FontUtils.registerFontFamilyLoader( FAMILY_SEMIBOLD, FlatInterFont::installSemiBold );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and registers the fonts for all styles.
|
||||
* <p>
|
||||
* When using FlatLaf, consider using {@link #installLazy()}.
|
||||
*/
|
||||
public static void install() {
|
||||
// basic styles
|
||||
installBasic();
|
||||
installLight();
|
||||
installSemiBold();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and registers the fonts for basic styles (regular, italic and bold).
|
||||
* <p>
|
||||
* When using FlatLaf, consider using {@link #installLazy()}.
|
||||
*/
|
||||
public static void installBasic() {
|
||||
installStyle( STYLE_REGULAR );
|
||||
installStyle( STYLE_ITALIC );
|
||||
installStyle( STYLE_BOLD );
|
||||
installStyle( STYLE_BOLD_ITALIC );
|
||||
}
|
||||
|
||||
// light
|
||||
/**
|
||||
* Creates and registers the fonts for light styles.
|
||||
* <p>
|
||||
* When using FlatLaf, consider using {@link #installLazy()}.
|
||||
*/
|
||||
public static void installLight() {
|
||||
installStyle( STYLE_LIGHT );
|
||||
installStyle( STYLE_LIGHT_ITALIC );
|
||||
}
|
||||
|
||||
// semibold
|
||||
/**
|
||||
* Creates and registers the fonts for semibold styles.
|
||||
* <p>
|
||||
* When using FlatLaf, consider using {@link #installLazy()}.
|
||||
*/
|
||||
public static void installSemiBold() {
|
||||
installStyle( STYLE_SEMIBOLD );
|
||||
installStyle( STYLE_SEMIBOLD_ITALIC );
|
||||
}
|
||||
@@ -139,15 +204,6 @@ public class FlatInterFont
|
||||
* See {@code STYLE_} constants.
|
||||
*/
|
||||
public static boolean installStyle( String name ) {
|
||||
try( InputStream in = FlatInterFont.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;
|
||||
}
|
||||
return FontUtils.installFont( FlatInterFont.class.getResource( name ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
module com.formdev.flatlaf.fonts.inter {
|
||||
requires java.desktop;
|
||||
requires com.formdev.flatlaf;
|
||||
|
||||
exports com.formdev.flatlaf.fonts.inter;
|
||||
|
||||
|
||||
@@ -15,8 +15,15 @@ License:
|
||||
How to install?
|
||||
---------------
|
||||
|
||||
Invoke the `install()` method once (e.g. in your `main()` method; on AWT
|
||||
thread):
|
||||
Invoke following once (e.g. in your `main()` method; on AWT thread).
|
||||
|
||||
For lazy loading use:
|
||||
|
||||
~~~java
|
||||
FlatJetBrainsMonoFont.installLazy();
|
||||
~~~
|
||||
|
||||
Or load immediately with:
|
||||
|
||||
~~~java
|
||||
FlatJetBrainsMonoFont.install();
|
||||
@@ -26,13 +33,13 @@ FlatJetBrainsMonoFont.install();
|
||||
How to use?
|
||||
-----------
|
||||
|
||||
Use as default monospaced font:
|
||||
Use as application monospaced font (invoke before setting up FlatLaf):
|
||||
|
||||
~~~java
|
||||
FlatLaf.setPreferredMonospacedFontFamily( FlatJetBrainsMonoFont.FAMILY );
|
||||
~~~
|
||||
|
||||
Create fonts:
|
||||
Create single fonts:
|
||||
|
||||
~~~java
|
||||
// basic styles
|
||||
@@ -42,6 +49,25 @@ new Font( FlatJetBrainsMonoFont.FAMILY, Font.BOLD, 12 );
|
||||
new Font( FlatJetBrainsMonoFont.FAMILY, Font.BOLD | Font.ITALIC, 12 );
|
||||
~~~
|
||||
|
||||
If using lazy loading, invoke one of following before creating the font:
|
||||
|
||||
~~~java
|
||||
FontUtils.loadFontFamily( FlatJetBrainsMonoFont.FAMILY );
|
||||
~~~
|
||||
|
||||
E.g.:
|
||||
|
||||
~~~java
|
||||
FontUtils.loadFontFamily( FlatJetBrainsMonoFont.FAMILY );
|
||||
Font font = new Font( FlatJetBrainsMonoFont.FAMILY, Font.PLAIN, 12 );
|
||||
~~~
|
||||
|
||||
Or use following:
|
||||
|
||||
~~~java
|
||||
Font font = FontUtils.getCompositeFont( FlatJetBrainsMonoFont.FAMILY, Font.PLAIN, 12 );
|
||||
~~~
|
||||
|
||||
|
||||
Download
|
||||
--------
|
||||
|
||||
@@ -31,6 +31,8 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation( project( ":flatlaf-core" ) )
|
||||
|
||||
testImplementation( "org.junit.jupiter:junit-jupiter-api:5.7.2" )
|
||||
testImplementation( "org.junit.jupiter:junit-jupiter-params" )
|
||||
testRuntimeOnly( "org.junit.jupiter:junit-jupiter-engine" )
|
||||
|
||||
@@ -16,11 +16,7 @@
|
||||
|
||||
package com.formdev.flatlaf.fonts.jetbrains_mono;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontFormatException;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import com.formdev.flatlaf.util.FontUtils;
|
||||
|
||||
/**
|
||||
* The JetBrains Mono font family.
|
||||
@@ -28,23 +24,46 @@ import java.io.InputStream;
|
||||
* Font home page: <a href="https://www.jetbrains.com/mono">https://www.jetbrains.com/mono</a><br>
|
||||
* GitHub project: <a href="https://github.com/JetBrains/JetBrainsMono">https://github.com/JetBrains/JetBrainsMono</a>
|
||||
* <p>
|
||||
* To install the font, invoke following once (e.g. in your {@code main()} method; on AWT thread):
|
||||
* To install the font, invoke following once (e.g. in your {@code main()} method; on AWT thread).
|
||||
* <p>
|
||||
* For lazy loading use:
|
||||
* <pre>{@code
|
||||
* FlatJetBrainsMonoFont.installLazy();
|
||||
* }</pre>
|
||||
* <p>
|
||||
* Or load immediately with:
|
||||
* <pre>{@code
|
||||
* FlatJetBrainsMonoFont.install();
|
||||
* }</pre>
|
||||
* <p>
|
||||
* Use as default monospaced font:
|
||||
* Use as application monospaced font (invoke before setting up FlatLaf):
|
||||
* <pre>{@code
|
||||
* FlatLaf.setPreferredMonospacedFontFamily( FlatJetBrainsMonoFont.FAMILY );
|
||||
* }</pre>
|
||||
* <p>
|
||||
* Create fonts:
|
||||
* Create single fonts:
|
||||
* <pre>{@code
|
||||
* new Font( FlatJetBrainsMonoFont.FAMILY, Font.PLAIN, 12 );
|
||||
* new Font( FlatJetBrainsMonoFont.FAMILY, Font.ITALIC, 12 );
|
||||
* new Font( FlatJetBrainsMonoFont.FAMILY, Font.BOLD, 12 );
|
||||
* new Font( FlatJetBrainsMonoFont.FAMILY, Font.BOLD | Font.ITALIC, 12 );
|
||||
* }</pre>
|
||||
* <p>
|
||||
* If using lazy loading, invoke following before creating the font:
|
||||
* <pre>{@code
|
||||
* FontUtils.loadFontFamily( FlatJetBrainsMonoFont.FAMILY );
|
||||
* }</pre>
|
||||
* <p>
|
||||
* E.g.:
|
||||
* <pre>{@code
|
||||
* FontUtils.loadFontFamily( FlatJetBrainsMonoFont.FAMILY );
|
||||
* Font font = new Font( FlatJetBrainsMonoFont.FAMILY, Font.PLAIN, 12 );
|
||||
* }</pre>
|
||||
* <p>
|
||||
* Or use following:
|
||||
* <pre>{@code
|
||||
* Font font = FontUtils.getCompositeFont( FlatJetBrainsMonoFont.FAMILY, Font.PLAIN, 12 );
|
||||
* }</pre>
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
@@ -76,8 +95,24 @@ public class FlatJetBrainsMonoFont
|
||||
|
||||
private FlatJetBrainsMonoFont() {}
|
||||
|
||||
/**
|
||||
* Registers the fonts for lazy loading via {@link FontUtils#registerFontFamilyLoader(String, Runnable)}.
|
||||
* <p>
|
||||
* This is the preferred method (when using FlatLaf) to avoid unnecessary loading of maybe unused fonts.
|
||||
* <p>
|
||||
* <strong>Note</strong>: When using '{@code new Font(...)}', you need to first invoke
|
||||
* {@link FontUtils#loadFontFamily(family)} to ensure that the font family is loaded.
|
||||
* When FlatLaf loads a font, or when using {@link FontUtils#getCompositeFont(family, style, size)},
|
||||
* this is done automatically.
|
||||
*/
|
||||
public static void installLazy() {
|
||||
FontUtils.registerFontFamilyLoader( FAMILY, FlatJetBrainsMonoFont::install );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and registers the fonts for all styles.
|
||||
* <p>
|
||||
* When using FlatLaf, consider using {@link #installLazy()}.
|
||||
*/
|
||||
public static void install() {
|
||||
installStyle( STYLE_REGULAR );
|
||||
@@ -91,15 +126,6 @@ public class FlatJetBrainsMonoFont
|
||||
* See {@code STYLE_} constants.
|
||||
*/
|
||||
public static boolean installStyle( String name ) {
|
||||
try( InputStream in = FlatJetBrainsMonoFont.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;
|
||||
}
|
||||
return FontUtils.installFont( FlatJetBrainsMonoFont.class.getResource( name ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
module com.formdev.flatlaf.fonts.jetbrains_mono {
|
||||
requires java.desktop;
|
||||
requires com.formdev.flatlaf;
|
||||
|
||||
exports com.formdev.flatlaf.fonts.jetbrains_mono;
|
||||
|
||||
|
||||
@@ -15,18 +15,29 @@ License:
|
||||
How to install?
|
||||
---------------
|
||||
|
||||
Invoke the `install()` method once (e.g. in your `main()` method; on AWT
|
||||
thread):
|
||||
Invoke following once (e.g. in your `main()` method; on AWT thread).
|
||||
|
||||
For lazy loading use:
|
||||
|
||||
~~~java
|
||||
FlatRobotoFont.installLazy();
|
||||
~~~
|
||||
|
||||
Or load immediately with:
|
||||
|
||||
~~~java
|
||||
FlatRobotoFont.install();
|
||||
// or
|
||||
FlatRobotoFont.installBasic();
|
||||
FlatRobotoFont.installLight();
|
||||
FlatRobotoFont.installSemiBold();
|
||||
~~~
|
||||
|
||||
|
||||
How to use?
|
||||
-----------
|
||||
|
||||
Use as default font:
|
||||
Use as application font (invoke before setting up FlatLaf):
|
||||
|
||||
~~~java
|
||||
FlatLaf.setPreferredFontFamily( FlatRobotoFont.FAMILY );
|
||||
@@ -34,7 +45,7 @@ FlatLaf.setPreferredLightFontFamily( FlatRobotoFont.FAMILY_LIGHT );
|
||||
FlatLaf.setPreferredSemiboldFontFamily( FlatRobotoFont.FAMILY_SEMIBOLD );
|
||||
~~~
|
||||
|
||||
Create fonts:
|
||||
Create single fonts:
|
||||
|
||||
~~~java
|
||||
// basic styles
|
||||
@@ -52,6 +63,27 @@ new Font( FlatRobotoFont.FAMILY_SEMIBOLD, Font.PLAIN, 12 );
|
||||
new Font( FlatRobotoFont.FAMILY_SEMIBOLD, Font.ITALIC, 12 );
|
||||
~~~
|
||||
|
||||
If using lazy loading, invoke one of following before creating the font:
|
||||
|
||||
~~~java
|
||||
FontUtils.loadFontFamily( FlatRobotoFont.FAMILY );
|
||||
FontUtils.loadFontFamily( FlatRobotoFont.FAMILY_LIGHT );
|
||||
FontUtils.loadFontFamily( FlatRobotoFont.FAMILY_SEMIBOLD );
|
||||
~~~
|
||||
|
||||
E.g.:
|
||||
|
||||
~~~java
|
||||
FontUtils.loadFontFamily( FlatRobotoFont.FAMILY );
|
||||
Font font = new Font( FlatRobotoFont.FAMILY, Font.PLAIN, 12 );
|
||||
~~~
|
||||
|
||||
Or use following:
|
||||
|
||||
~~~java
|
||||
Font font = FontUtils.getCompositeFont( FlatRobotoFont.FAMILY, Font.PLAIN, 12 );
|
||||
~~~
|
||||
|
||||
|
||||
Download
|
||||
--------
|
||||
|
||||
@@ -31,6 +31,8 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation( project( ":flatlaf-core" ) )
|
||||
|
||||
testImplementation( "org.junit.jupiter:junit-jupiter-api:5.7.2" )
|
||||
testImplementation( "org.junit.jupiter:junit-jupiter-params" )
|
||||
testRuntimeOnly( "org.junit.jupiter:junit-jupiter-engine" )
|
||||
|
||||
@@ -16,11 +16,7 @@
|
||||
|
||||
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;
|
||||
import com.formdev.flatlaf.util.FontUtils;
|
||||
|
||||
/**
|
||||
* The Roboto font family.
|
||||
@@ -28,19 +24,30 @@ import java.io.InputStream;
|
||||
* 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):
|
||||
* To install the font, invoke following once (e.g. in your {@code main()} method; on AWT thread).
|
||||
* <p>
|
||||
* For lazy loading use:
|
||||
* <pre>{@code
|
||||
* FlatRobotoFont.install();
|
||||
* FlatRobotoFont.installLazy();
|
||||
* }</pre>
|
||||
* <p>
|
||||
* Use as default font:
|
||||
* Or load immediately with:
|
||||
* <pre>{@code
|
||||
* FlatRobotoFont.install();
|
||||
* // or
|
||||
* FlatRobotoFont.installBasic();
|
||||
* FlatRobotoFont.installLight();
|
||||
* FlatRobotoFont.installSemiBold();
|
||||
* }</pre>
|
||||
* <p>
|
||||
* Use as application font (invoke before setting up FlatLaf):
|
||||
* <pre>{@code
|
||||
* FlatLaf.setPreferredFontFamily( FlatRobotoFont.FAMILY );
|
||||
* FlatLaf.setPreferredLightFontFamily( FlatRobotoFont.FAMILY_LIGHT );
|
||||
* FlatLaf.setPreferredSemiboldFontFamily( FlatRobotoFont.FAMILY_SEMIBOLD );
|
||||
* }</pre>
|
||||
* <p>
|
||||
* Create fonts:
|
||||
* Create single fonts:
|
||||
* <pre>{@code
|
||||
* new Font( FlatRobotoFont.FAMILY, Font.PLAIN, 12 );
|
||||
* new Font( FlatRobotoFont.FAMILY, Font.ITALIC, 12 );
|
||||
@@ -51,6 +58,24 @@ import java.io.InputStream;
|
||||
* new Font( FlatRobotoFont.FAMILY_SEMIBOLD, Font.PLAIN, 12 );
|
||||
* new Font( FlatRobotoFont.FAMILY_SEMIBOLD, Font.ITALIC, 12 );
|
||||
* }</pre>
|
||||
* <p>
|
||||
* If using lazy loading, invoke one of following before creating the font:
|
||||
* <pre>{@code
|
||||
* FontUtils.loadFontFamily( FlatRobotoFont.FAMILY );
|
||||
* FontUtils.loadFontFamily( FlatRobotoFont.FAMILY_LIGHT );
|
||||
* FontUtils.loadFontFamily( FlatRobotoFont.FAMILY_SEMIBOLD );
|
||||
* }</pre>
|
||||
* <p>
|
||||
* E.g.:
|
||||
* <pre>{@code
|
||||
* FontUtils.loadFontFamily( FlatRobotoFont.FAMILY );
|
||||
* Font font = new Font( FlatRobotoFont.FAMILY, Font.PLAIN, 12 );
|
||||
* }</pre>
|
||||
* <p>
|
||||
* Or use following:
|
||||
* <pre>{@code
|
||||
* Font font = FontUtils.getCompositeFont( FlatRobotoFont.FAMILY, Font.PLAIN, 12 );
|
||||
* }</pre>
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
@@ -81,7 +106,7 @@ public class FlatRobotoFont
|
||||
public static final String FAMILY_LIGHT = "Roboto Light";
|
||||
|
||||
/**
|
||||
* Family name for semibold styles.
|
||||
* Family name for semibold (medium) styles.
|
||||
* <p>
|
||||
* Usage:
|
||||
* <pre>{@code
|
||||
@@ -112,21 +137,61 @@ public class FlatRobotoFont
|
||||
|
||||
private FlatRobotoFont() {}
|
||||
|
||||
/**
|
||||
* Registers the fonts for lazy loading via {@link FontUtils#registerFontFamilyLoader(String, Runnable)}.
|
||||
* <p>
|
||||
* This is the preferred method (when using FlatLaf) to avoid unnecessary loading of maybe unused fonts.
|
||||
* <p>
|
||||
* <strong>Note</strong>: When using '{@code new Font(...)}', you need to first invoke
|
||||
* {@link FontUtils#loadFontFamily(family)} to ensure that the font family is loaded.
|
||||
* When FlatLaf loads a font, or when using {@link FontUtils#getCompositeFont(family, style, size)},
|
||||
* this is done automatically.
|
||||
*/
|
||||
public static void installLazy() {
|
||||
FontUtils.registerFontFamilyLoader( FAMILY, FlatRobotoFont::installBasic );
|
||||
FontUtils.registerFontFamilyLoader( FAMILY_LIGHT, FlatRobotoFont::installLight );
|
||||
FontUtils.registerFontFamilyLoader( FAMILY_SEMIBOLD, FlatRobotoFont::installSemiBold );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and registers the fonts for all styles.
|
||||
* <p>
|
||||
* When using FlatLaf, consider using {@link #installLazy()}.
|
||||
*/
|
||||
public static void install() {
|
||||
// basic styles
|
||||
installBasic();
|
||||
installLight();
|
||||
installSemiBold();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and registers the fonts for basic styles (regular, italic and bold).
|
||||
* <p>
|
||||
* When using FlatLaf, consider using {@link #installLazy()}.
|
||||
*/
|
||||
public static void installBasic() {
|
||||
installStyle( STYLE_REGULAR );
|
||||
installStyle( STYLE_ITALIC );
|
||||
installStyle( STYLE_BOLD );
|
||||
installStyle( STYLE_BOLD_ITALIC );
|
||||
}
|
||||
|
||||
// light
|
||||
/**
|
||||
* Creates and registers the fonts for light styles.
|
||||
* <p>
|
||||
* When using FlatLaf, consider using {@link #installLazy()}.
|
||||
*/
|
||||
public static void installLight() {
|
||||
installStyle( STYLE_LIGHT );
|
||||
installStyle( STYLE_LIGHT_ITALIC );
|
||||
}
|
||||
|
||||
// semibold
|
||||
/**
|
||||
* Creates and registers the fonts for semibold (medium) styles.
|
||||
* <p>
|
||||
* When using FlatLaf, consider using {@link #installLazy()}.
|
||||
*/
|
||||
public static void installSemiBold() {
|
||||
installStyle( STYLE_SEMIBOLD );
|
||||
installStyle( STYLE_SEMIBOLD_ITALIC );
|
||||
}
|
||||
@@ -136,15 +201,6 @@ public class FlatRobotoFont
|
||||
* 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;
|
||||
}
|
||||
return FontUtils.installFont( FlatRobotoFont.class.getResource( name ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
module com.formdev.flatlaf.fonts.roboto {
|
||||
requires java.desktop;
|
||||
requires com.formdev.flatlaf;
|
||||
|
||||
exports com.formdev.flatlaf.fonts.roboto;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user