Skip to content

Commit

Permalink
Use Japanese font in non-Japanese Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgqy committed Jan 27, 2024
1 parent 9aa2157 commit 6f8a368
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/AozoraEpub3Applet.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Point;
Expand Down Expand Up @@ -43,7 +44,9 @@
import java.net.URLDecoder;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -2217,7 +2220,7 @@ public void actionPerformed(ActionEvent evt)
jTextArea.append(" )\n対応ファイル: 青空文庫txt(txt,zip,rar), 画像(zip,rar,cbz), URLショートカット(url)\n");
jTextArea.append("ファイルまたはURL文字列をここにドラッグ&ドロップ/ペーストで変換します。\n");
jTextArea.setEditable(false);
jTextArea.setFont(new Font("Default", Font.PLAIN, 12));
jTextArea.setFont(getDefaultFont());
jTextArea.setBorder(new LineBorder(Color.white, 3));
//new DropTarget(jTextArea, DnDConstants.ACTION_COPY_OR_MOVE, new DropListener(), true);
jTextArea.setTransferHandler(new TextAreaTransferHandler("text"));
Expand Down Expand Up @@ -4684,6 +4687,32 @@ private void setProperties(Properties props)
props.setProperty("OverWrite", this.jCheckOverWrite.isSelected()?"1":"");
}

/** 候補リストからフォントの選択 */
private static FontUIResource getDefaultFont() {
final String[] sysFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
final String[] fontList = {"Yu Gothic UI", "Meiryo UI", "MS PGothic"};
final int FONT_SIZE = 12;
FontUIResource fr = new FontUIResource("SansSerif", Font.PLAIN, FONT_SIZE);
for (int i = 0; i < fontList.length; ++i) {
if (Arrays.asList(sysFonts).contains(fontList[i])) {
fr = new FontUIResource(fontList[i], Font.PLAIN, FONT_SIZE);
break;
}
}
return fr;
}

/** UI フォントの設定 */
private static void setUIFont(FontUIResource fr) {
Enumeration<Object> keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof FontUIResource) {
UIManager.put(key, fr);
}
}
}
////////////////////////////////////////////////////////////////
// JFrame
////////////////////////////////////////////////////////////////
Expand All @@ -4696,6 +4725,8 @@ public static void main(String args[])
//lafName = "";
if (lafName.startsWith("com.sun.java.swing.plaf.windows.")) {
UIManager.setLookAndFeel(lafName);
// 他言語の Windows でも日本語のフォントを使う
setUIFont(getDefaultFont());
} else {
//Windows以外はMetalのままでFontはPLAIN
UIDefaults defaultTable = UIManager.getLookAndFeelDefaults();
Expand Down

0 comments on commit 6f8a368

Please sign in to comment.