├── pom.xml
└── src
└── main
└── java
└── com
└── example
└── FontList.java
FontList.java
Ein Java-Programm, das verfügbare Schriftinformationen abruft.
package com.example;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
public class FontList implements RequestHandler<Map<String, Object>, Map<String, Object>> {
/**
*Dies ist der Einstiegspunkt, wenn Sie als eigenständige Java-Anwendung ausgeführt werden.
*
* @param args nicht verwendet
*/
public static void main(String[] args) {
Map<String, Object> output = new FontList().invoke();
//Schriftartenname
for (String name : (String[]) output.get("names")) {
System.out.println(name);
}
//Schriftname und Anzahl der Glyphen
for (String info : (String[]) output.get("numGlyphs")) {
System.out.println(info);
}
//System Information
System.out.println(output.get("system"));
}
/**
*Einstiegspunkt bei der Ausführung der AWS Lambda-Funktion(Handler-Methode)ist.
*
* @param input Eingabedaten
* @param context AWS Lambda Context-Objekt
* @Ausgabedaten zurückgeben
*/
@Override
public Map<String, Object> handleRequest(Map<String, Object> input, Context context) {
return invoke();
}
/**
*Gibt Informationen zu verfügbaren Schriftarten zurück.
*
* @Informationen zu verfügbaren Schriftarten zurückgeben
*/
private static Map<String, Object> invoke() {
//Holen Sie sich eine Liste der verfügbaren Schriftarten
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] allFonts = ge.getAllFonts();
//Fassen Sie die Schriftinformationen zusammen, die Sie ausgeben möchten
String[] names = Arrays.stream(allFonts)
.map(Font::getName) //Schriftartenname
.toArray(String[]::new);
//In aufsteigender Reihenfolge der Glyphennummer anordnen
String[] numGlyphs = Arrays.stream(allFonts)
.sorted(Comparator.comparing(Font::getNumGlyphs)) //Nach Glyphennummer sortieren
.map(f -> f.getName() + ": " + f.getNumGlyphs()) //Schriftname und Anzahl der Glyphen
.toArray(String[]::new);
//Systeminformationen abrufen
Map system = new HashMap<String, String>();
system.put("os.name", getSystemProperty("os.name"));
system.put("os.arch", getSystemProperty("os.arch"));
system.put("os.version", getSystemProperty("os.version"));
system.put("java.version", getSystemProperty("java.version"));
system.put("java.specification.version", getSystemProperty("java.specification.version"));
system.put("java.runtime.name", getSystemProperty("java.runtime.name"));
system.put("java.runtime.version", getSystemProperty("java.runtime.version"));
system.put("java.vm.name", getSystemProperty("java.vm.name"));
system.put("java.vm.version", getSystemProperty("java.vm.version"));
//Erstellen Sie Ausgabedaten
Map output = new HashMap<String, Object>();
output.put("names", names);
output.put("numGlyphs", numGlyphs);
output.put("system", system);
return output;
}
/**
*Ruft die durch den angegebenen Schlüssel angegebenen Systemeigenschaften ab.
*
* @param key Der Name der Systemeigenschaft
* @Rückgabewert der Systemeigenschaftszeichenfolge(Null, wenn keine Eigenschaft mit diesem Schlüssel vorhanden ist)
*/
private static String getSystemProperty(String key) {
try {
return System.getProperty(key);
} catch (SecurityException e) {
return e.toString();
}
}
}
pom.xml
Konfigurationsdatei zum Erstellen mit Maven.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>fontlist</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>fontlist</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-core -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- https://maven.apache.org/plugins/maven-shade-plugin/ -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
{
"names": [
"Bitstream Charter",
"Bitstream Charter Bold",
"Bitstream Charter Bold Italic",
"Bitstream Charter Italic",
"Century Schoolbook L Bold",
"Century Schoolbook L Bold Italic",
"Century Schoolbook L Italic",
"Century Schoolbook L Roman",
"Courier 10 Pitch",
"Courier 10 Pitch Bold",
"Courier 10 Pitch Bold Italic",
"Courier 10 Pitch Italic",
"Cursor",
"DejaVu Sans",
"DejaVu Sans Bold",
"DejaVu Sans Bold Oblique",
"DejaVu Sans Condensed",
"DejaVu Sans Condensed Bold",
"DejaVu Sans Condensed Bold Oblique",
"DejaVu Sans Condensed Oblique",
"DejaVu Sans ExtraLight",
"DejaVu Sans Oblique",
"DejaVu Serif",
"DejaVu Serif Bold",
"DejaVu Serif Bold Italic",
"DejaVu Serif Condensed",
"DejaVu Serif Condensed Bold",
"DejaVu Serif Condensed Bold Italic",
"DejaVu Serif Condensed Italic",
"DejaVu Serif Italic",
"Dialog.bold",
"Dialog.bolditalic",
"Dialog.italic",
"Dialog.plain",
"DialogInput.bold",
"DialogInput.bolditalic",
"DialogInput.italic",
"DialogInput.plain",
"Dingbats ",
"Hershey Gothic- English",
"Hershey Gothic- German",
"Hershey Gothic- Italian",
"Hershey Plain- Duplex",
"Hershey Plain- Duplex- Italic",
"Hershey Plain- Triplex",
"Hershey Plain- Triplex- Italic",
"Hershey Script- Complex",
"Hershey Script- Simplex",
"Monospaced.bold",
"Monospaced.bolditalic",
"Monospaced.italic",
"Monospaced.plain",
"Nimbus Mono L Bold",
"Nimbus Mono L Bold Oblique",
"Nimbus Mono L Regular",
"Nimbus Mono L Regular Oblique",
"Nimbus Roman No9 L Medium",
"Nimbus Roman No9 L Medium Italic",
"Nimbus Roman No9 L Regular",
"Nimbus Roman No9 L Regular Italic",
"Nimbus Sans L Bold",
"Nimbus Sans L Bold Condensed",
"Nimbus Sans L Bold Condensed Italic",
"Nimbus Sans L Bold Italic",
"Nimbus Sans L Regular",
"Nimbus Sans L Regular Condensed",
"Nimbus Sans L Regular Condensed Italic",
"Nimbus Sans L Regular Italic",
"SansSerif.bold",
"SansSerif.bolditalic",
"SansSerif.italic",
"SansSerif.plain",
"Serif.bold",
"Serif.bolditalic",
"Serif.italic",
"Serif.plain",
"Standard Symbols L",
"URW Bookman L Demi Bold",
"URW Bookman L Demi Bold Italic",
"URW Bookman L Light",
"URW Bookman L Light Italic",
"URW Chancery L Medium Italic",
"URW Gothic L Book",
"URW Gothic L Book Oblique",
"URW Gothic L Demi",
"URW Gothic L Demi Oblique",
"URW Palladio L Bold",
"URW Palladio L Bold Italic",
"URW Palladio L Italic",
"URW Palladio L Roman",
"Utopia Bold",
"Utopia Bold Italic",
"Utopia Italic",
"Utopia Regular"
],
"system": {
"java.runtime.name": "OpenJDK Runtime Environment",
"java.specification.version": "1.8",
"java.version": "1.8.0_201",
"java.vm.version": "25.201-b09",
"os.arch": "amd64",
"java.runtime.version": "1.8.0_201-b09",
"os.name": "Linux",
"java.vm.name": "OpenJDK 64-Bit Server VM",
"os.version": "4.14.133-97.112.amzn2.x86_64"
},
"numGlyphs": [
"Cursor: 155",
"Standard Symbols L: 190",
"Dingbats : 203",
"Hershey Plain- Duplex: 224",
"Hershey Plain- Duplex- Italic: 224",
"Hershey Plain- Triplex: 224",
"Hershey Plain- Triplex- Italic: 224",
"Hershey Script- Complex: 224",
"Hershey Script- Simplex: 224",
"Hershey Gothic- English: 228",
"Hershey Gothic- German: 228",
"Hershey Gothic- Italian: 228",
"Bitstream Charter: 229",
"Bitstream Charter Bold: 229",
"Bitstream Charter Bold Italic: 229",
"Bitstream Charter Italic: 229",
"Courier 10 Pitch: 229",
"Courier 10 Pitch Bold: 229",
"Courier 10 Pitch Bold Italic: 229",
"Courier 10 Pitch Italic: 229",
"Utopia Bold: 229",
"Utopia Bold Italic: 229",
"Utopia Italic: 229",
"Utopia Regular: 229",
"URW Chancery L Medium Italic: 503",
"URW Bookman L Demi Bold Italic: 512",
"URW Bookman L Demi Bold: 519",
"URW Bookman L Light Italic: 519",
"DialogInput.bolditalic: 522",
"Monospaced.bolditalic: 522",
"Nimbus Mono L Bold Oblique: 522",
"URW Palladio L Italic: 522",
"URW Palladio L Bold: 523",
"URW Palladio L Bold Italic: 523",
"URW Palladio L Roman: 525",
"DialogInput.italic: 533",
"Monospaced.italic: 533",
"Nimbus Mono L Regular Oblique: 533",
"Nimbus Roman No9 L Medium Italic: 535",
"Nimbus Roman No9 L Regular Italic: 535",
"DialogInput.bold: 540",
"Monospaced.bold: 540",
"Nimbus Mono L Bold: 540",
"URW Bookman L Light: 545",
"Nimbus Sans L Bold Condensed: 561",
"Century Schoolbook L Bold: 563",
"Century Schoolbook L Bold Italic: 563",
"Century Schoolbook L Italic: 563",
"Century Schoolbook L Roman: 563",
"DialogInput.plain: 563",
"Monospaced.plain: 563",
"Nimbus Mono L Regular: 563",
"Nimbus Roman No9 L Medium: 563",
"Nimbus Roman No9 L Regular: 563",
"Nimbus Sans L Bold: 563",
"Nimbus Sans L Bold Condensed Italic: 563",
"Nimbus Sans L Bold Italic: 563",
"Nimbus Sans L Regular: 563",
"Nimbus Sans L Regular Condensed: 563",
"Nimbus Sans L Regular Condensed Italic: 563",
"Nimbus Sans L Regular Italic: 563",
"URW Gothic L Book: 563",
"URW Gothic L Book Oblique: 563",
"URW Gothic L Demi: 563",
"URW Gothic L Demi Oblique: 563",
"DejaVu Sans ExtraLight: 1915",
"DejaVu Serif Bold Italic: 3320",
"DejaVu Serif Condensed Bold Italic: 3320",
"Serif.bolditalic: 3320",
"DejaVu Serif Bold: 3321",
"DejaVu Serif Condensed Bold: 3321",
"Serif.bold: 3321",
"DejaVu Serif: 3399",
"DejaVu Serif Condensed: 3399",
"Serif.plain: 3399",
"DejaVu Serif Condensed Italic: 3449",
"DejaVu Serif Italic: 3449",
"Serif.italic: 3449",
"DejaVu Sans Bold Oblique: 5085",
"DejaVu Sans Condensed Bold Oblique: 5085",
"Dialog.bolditalic: 5085",
"SansSerif.bolditalic: 5085",
"DejaVu Sans Condensed Oblique: 5155",
"DejaVu Sans Oblique: 5155",
"Dialog.italic: 5155",
"SansSerif.italic: 5155",
"DejaVu Sans Bold: 5854",
"DejaVu Sans Condensed Bold: 5854",
"Dialog.bold: 5854",
"SansSerif.bold: 5854",
"DejaVu Sans: 5928",
"DejaVu Sans Condensed: 5928",
"Dialog.plain: 5928",
"SansSerif.plain: 5928"
]
}
Recommended Posts