リビジョン | 29 (tree) |
---|---|
日時 | 2020-11-21 13:00:15 |
作者 | hirukawa_ryo |
* pdf-brewer 0.4.6
アプリケーションフォルダーに fonts フォルダーが配置されている場合、fonts フォルダーからフォントをロードするようにしました。
ロード対象のファイルは IPAexフォント(ipaexg.ttf、ipaexm.ttf)、源真ゴシック(GenShinGothic-Regular.ttf、GenShinGothic-Bold.ttf)、源様明朝(GenYoMinJP-R.ttf、GenYoMinJP-B.ttf)です。
fonts フォルダーによって macOS/Linux にも対応できるようになります。
尚、macOS/Linuxのシステムフォントディレクトリーからのフォント検索には対応しません。現時点でpdfboxを使ったフォント埋め込みにOTFは対応しておらずTTFが必要になります。macOS/Linuxのシステムフォントの多くはOTFであるため、システムフォントディレクトリーを検索するべきではないと判断しました。
@@ -26,8 +26,15 @@ | ||
26 | 26 | |
27 | 27 | public static final List<String> FILENAMES_YUGOTHIC; |
28 | 28 | public static final List<String> FILENAMES_YUMINCHO; |
29 | + public static final List<String> FILENAMES_IPA_GOTHIC; | |
30 | + public static final List<String> FILENAMES_IPA_MINCHO; | |
31 | + public static final List<String> FILENAMES_NOTO_GOTHIC; | |
32 | + public static final List<String> FILENAMES_NOTO_MINCHO; | |
29 | 33 | |
30 | 34 | static { |
35 | + // | |
36 | + // for Windows | |
37 | + // | |
31 | 38 | FILENAMES_YUGOTHIC = Arrays.asList( |
32 | 39 | "yugothib.ttf", |
33 | 40 | "yugothic-bold.ttf", |
@@ -43,6 +50,28 @@ | ||
43 | 50 | "yumindb.ttf", |
44 | 51 | "yuminl.ttf" |
45 | 52 | ); |
53 | + | |
54 | + // | |
55 | + // for NOTO | |
56 | + // | |
57 | + FILENAMES_NOTO_GOTHIC = Arrays.asList( | |
58 | + "GenShinGothic-Regular.ttf", | |
59 | + "GenShinGothic-Bold.ttf" | |
60 | + ); | |
61 | + FILENAMES_NOTO_MINCHO = Arrays.asList( | |
62 | + "GenYoMinJP-R.ttf", | |
63 | + "GenYoMinJP-B.ttf" | |
64 | + ); | |
65 | + | |
66 | + // | |
67 | + // for IPA | |
68 | + // | |
69 | + FILENAMES_IPA_GOTHIC = Arrays.asList( | |
70 | + "ipaexg.ttf" | |
71 | + ); | |
72 | + FILENAMES_IPA_MINCHO = Arrays.asList( | |
73 | + "ipaexm.ttf" | |
74 | + ); | |
46 | 75 | } |
47 | 76 | |
48 | 77 | public static File getDefaultFontDir() { |
@@ -67,12 +96,41 @@ | ||
67 | 96 | TrueTypeFont serifBold; |
68 | 97 | TrueTypeFont sansSerif; |
69 | 98 | TrueTypeFont sansSerifBold; |
70 | - | |
99 | + | |
100 | + // for Windows | |
71 | 101 | serif = getFont("YuMincho-Regular"); |
72 | 102 | serifBold = getFont("YuMincho-Demibold"); |
73 | 103 | sansSerif = getFont("YuGothic-Regular"); |
74 | 104 | sansSerifBold = getFont("YuGothic-Bold"); |
75 | 105 | |
106 | + // for Noto (fallback) | |
107 | + if(serif == null) { | |
108 | + serif = getFont("r-源様明朝"); | |
109 | + } | |
110 | + if(serifBold == null) { | |
111 | + serifBold = getFont("b-源様明朝"); | |
112 | + } | |
113 | + if(sansSerif == null) { | |
114 | + sansSerif = getFont("regular-源真ゴシック"); | |
115 | + } | |
116 | + if(sansSerifBold == null) { | |
117 | + sansSerifBold = getFont("bold-源真ゴシック"); | |
118 | + } | |
119 | + | |
120 | + // for IPA (fallback) | |
121 | + if(serif == null) { | |
122 | + serif = getFont("ipaexmincho"); | |
123 | + } | |
124 | + if(serifBold == null) { | |
125 | + serifBold = getFont("ipaexmincho"); | |
126 | + } | |
127 | + if(sansSerif == null) { | |
128 | + sansSerif = getFont("ipaexgothic"); | |
129 | + } | |
130 | + if(sansSerifBold == null) { | |
131 | + sansSerifBold = getFont("ipaexgothic"); | |
132 | + } | |
133 | + | |
76 | 134 | if(serif != null && serifBold != null && sansSerif != null && sansSerifBold != null) { |
77 | 135 | try { |
78 | 136 | register("serif", serif); |
@@ -130,6 +188,10 @@ | ||
130 | 188 | } |
131 | 189 | |
132 | 190 | public void load(File dir, Collection<String> fileNames, Collection<String> fontNames) { |
191 | + if(dir == null) { | |
192 | + return; | |
193 | + } | |
194 | + | |
133 | 195 | Set<String> fileNameSet = null; |
134 | 196 | if(fileNames != null) { |
135 | 197 | fileNameSet = new HashSet<String>(); |