概要
- AWS Lambda + Java で日本語が使えるフォントがあるか Java のプログラムを書いて調べる
- Font#canDisplay で各種文字が使えるかどうか調べる
- 現時点では日本語 (ひらがな・カタカナ・漢字) を使えるフォントはシステム内に用意されていなかった
ソースコード
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.List;
import java.util.Map;
import java.util.stream.Collectors;
public class FontList implements RequestHandler<Map<String, Object>, Map<String, Object>> {
/**
* スタンドアローンの Java アプリケーションとして実行した場合のエントリポイントです。
*
* @param args 使用しない
*/
public static void main(String[] args) {
Map<String, Object> output = new FontList().invoke();
// フォント情報を出力
for (Map font : (List<Map>) output.get("fonts")) {
System.out.println(font);
}
// システム情報
System.out.println(output.get("system"));
}
/**
* AWS Labmda 関数を実行した場合のエントリポイント (ハンドラーメソッド) です。
*
* @param input 入力データ
* @param context AWS Lambda Context オブジェクト
* @return 出力データ
*/
@Override
public Map<String, Object> handleRequest(Map<String, Object> input, Context context) {
return invoke();
}
/**
* 使用できるフォントの情報を返します。
*
* @return 使用できるフォントの情報
*/
private static Map<String, Object> invoke() {
// 使用できるフォントの一覧を取得
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] allFonts = ge.getAllFonts();
// 各種文字が使えるか調べる
List<Map> fonts = Arrays.stream(allFonts)
.sorted(Comparator.comparing(Font::getNumGlyphs)) // グリフ数でソート
.map(f -> {
Map m = new HashMap<String, Object>();
m.put("name", f.getName());
m.put("number_of_glyphs", f.getNumGlyphs());
m.put("display_number", f.canDisplay('0'));
m.put("display_alphabet", f.canDisplay('A'));
m.put("display_hiragana", f.canDisplay('あ'));
m.put("display_katakana", f.canDisplay('ア'));
m.put("display_kanji", f.canDisplay('亜'));
return m;
})
.collect(Collectors.toList());
// システム情報を取得
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"));
// 出力データを構築
Map output = new HashMap<String, Object>();
output.put("fonts", fonts);
output.put("system", system);
return output;
}
/**
* 指定されたキーによって示されるシステム・プロパティを取得します。
*
* @param key システム・プロパティの名前
* @return システム・プロパティの文字列値 (そのキーを持つプロパティが存在しない場合は null)
*/
private static String getSystemProperty(String key) {
try {
return System.getProperty(key);
} catch (SecurityException e) {
return e.toString();
}
}
}
AWS Lambda + Java 8 での実行結果
残念ながら、現時点では日本語 (ひらがな・カタカナ・漢字) を使えるフォントはシステム内に用意されていなかった。
{
"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"
},
"fonts": [
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 155,
"name": "Cursor",
"display_number": false,
"display_alphabet": false
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 190,
"name": "Standard Symbols L",
"display_number": true,
"display_alphabet": false
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 203,
"name": "Dingbats ",
"display_number": false,
"display_alphabet": false
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 224,
"name": "Hershey Plain- Duplex",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 224,
"name": "Hershey Plain- Duplex- Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 224,
"name": "Hershey Plain- Triplex",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 224,
"name": "Hershey Plain- Triplex- Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 224,
"name": "Hershey Script- Complex",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 224,
"name": "Hershey Script- Simplex",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 228,
"name": "Hershey Gothic- English",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 228,
"name": "Hershey Gothic- German",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 228,
"name": "Hershey Gothic- Italian",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 229,
"name": "Bitstream Charter",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 229,
"name": "Bitstream Charter Bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 229,
"name": "Bitstream Charter Bold Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 229,
"name": "Bitstream Charter Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 229,
"name": "Courier 10 Pitch",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 229,
"name": "Courier 10 Pitch Bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 229,
"name": "Courier 10 Pitch Bold Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 229,
"name": "Courier 10 Pitch Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 229,
"name": "Utopia Bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 229,
"name": "Utopia Bold Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 229,
"name": "Utopia Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 229,
"name": "Utopia Regular",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 503,
"name": "URW Chancery L Medium Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 512,
"name": "URW Bookman L Demi Bold Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 519,
"name": "URW Bookman L Demi Bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 519,
"name": "URW Bookman L Light Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 522,
"name": "DialogInput.bolditalic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 522,
"name": "Monospaced.bolditalic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 522,
"name": "Nimbus Mono L Bold Oblique",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 522,
"name": "URW Palladio L Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 523,
"name": "URW Palladio L Bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 523,
"name": "URW Palladio L Bold Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 525,
"name": "URW Palladio L Roman",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 533,
"name": "DialogInput.italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 533,
"name": "Monospaced.italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 533,
"name": "Nimbus Mono L Regular Oblique",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 535,
"name": "Nimbus Roman No9 L Medium Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 535,
"name": "Nimbus Roman No9 L Regular Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 540,
"name": "DialogInput.bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 540,
"name": "Monospaced.bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 540,
"name": "Nimbus Mono L Bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 545,
"name": "URW Bookman L Light",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 561,
"name": "Nimbus Sans L Bold Condensed",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Century Schoolbook L Bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Century Schoolbook L Bold Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Century Schoolbook L Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Century Schoolbook L Roman",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "DialogInput.plain",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Monospaced.plain",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Nimbus Mono L Regular",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Nimbus Roman No9 L Medium",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Nimbus Roman No9 L Regular",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Nimbus Sans L Bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Nimbus Sans L Bold Condensed Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Nimbus Sans L Bold Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Nimbus Sans L Regular",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Nimbus Sans L Regular Condensed",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Nimbus Sans L Regular Condensed Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "Nimbus Sans L Regular Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "URW Gothic L Book",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "URW Gothic L Book Oblique",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "URW Gothic L Demi",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 563,
"name": "URW Gothic L Demi Oblique",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 1915,
"name": "DejaVu Sans ExtraLight",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 3320,
"name": "DejaVu Serif Bold Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 3320,
"name": "DejaVu Serif Condensed Bold Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 3320,
"name": "Serif.bolditalic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 3321,
"name": "DejaVu Serif Bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 3321,
"name": "DejaVu Serif Condensed Bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 3321,
"name": "Serif.bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 3399,
"name": "DejaVu Serif",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 3399,
"name": "DejaVu Serif Condensed",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 3399,
"name": "Serif.plain",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 3449,
"name": "DejaVu Serif Condensed Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 3449,
"name": "DejaVu Serif Italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 3449,
"name": "Serif.italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5085,
"name": "DejaVu Sans Bold Oblique",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5085,
"name": "DejaVu Sans Condensed Bold Oblique",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5085,
"name": "Dialog.bolditalic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5085,
"name": "SansSerif.bolditalic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5155,
"name": "DejaVu Sans Condensed Oblique",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5155,
"name": "DejaVu Sans Oblique",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5155,
"name": "Dialog.italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5155,
"name": "SansSerif.italic",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5854,
"name": "DejaVu Sans Bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5854,
"name": "DejaVu Sans Condensed Bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5854,
"name": "Dialog.bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5854,
"name": "SansSerif.bold",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5928,
"name": "DejaVu Sans",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5928,
"name": "DejaVu Sans Condensed",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5928,
"name": "Dialog.plain",
"display_number": true,
"display_alphabet": true
},
{
"display_hiragana": false,
"display_katakana": false,
"display_kanji": false,
"number_of_glyphs": 5928,
"name": "SansSerif.plain",
"display_number": true,
"display_alphabet": true
}
]
}