diff --git a/fonts/NotoSans-Regular.ttf b/fonts/NotoSans-Regular.ttf new file mode 100644 index 000000000..a1b8994ed Binary files /dev/null and b/fonts/NotoSans-Regular.ttf differ diff --git a/lib/libraries b/lib/libraries index 2a80a5dad..776d3b4de 100644 --- a/lib/libraries +++ b/lib/libraries @@ -44,4 +44,5 @@ requests: https://github.com/kennethreitz/requests **** Fonts **** fonts/LiberationMono-Regular.ttf: https://github.com/thewca/tnoodle/pull/223 +fonts/NotoSans-Regular.ttf: https://github.com/googlei18n/noto-fonts fonts/wqy-microhei.ttf: https://github.com/thewca/tnoodle/pull/246#issuecomment-349533724 diff --git a/webscrambles/src/net/gnehzr/tnoodle/server/webscrambles/ScrambleRequest.java b/webscrambles/src/net/gnehzr/tnoodle/server/webscrambles/ScrambleRequest.java index b6f1058a6..29b300d4f 100644 --- a/webscrambles/src/net/gnehzr/tnoodle/server/webscrambles/ScrambleRequest.java +++ b/webscrambles/src/net/gnehzr/tnoodle/server/webscrambles/ScrambleRequest.java @@ -99,11 +99,19 @@ class ScrambleRequest { private static final char NON_BREAKING_SPACE = '\u00A0'; - private static BaseFont monoFont, sansSerifFont; + private static BaseFont monoFont, notoSans; + private static HashMap FONT_BY_LOCALE = new HashMap(); static { try { monoFont = BaseFont.createFont("fonts/LiberationMono-Regular.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); - sansSerifFont = BaseFont.createFont("fonts/wqy-microhei.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); + + BaseFont cjk = BaseFont.createFont("fonts/wqy-microhei.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); + FONT_BY_LOCALE.put(Locale.forLanguageTag("zh-CN"), cjk); + FONT_BY_LOCALE.put(Locale.forLanguageTag("zh-TW"), cjk); + FONT_BY_LOCALE.put(Locale.forLanguageTag("ko"), cjk); + FONT_BY_LOCALE.put(Locale.forLanguageTag("ja"), cjk); + + notoSans = BaseFont.createFont("fonts/NotoSans-Regular.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } catch (DocumentException e) { l.log(Level.INFO, "", e); } catch (IOException e) { @@ -111,6 +119,10 @@ class ScrambleRequest { } } + private static BaseFont getFontForLocale(Locale locale) { + return FONT_BY_LOCALE.getOrDefault(locale, notoSans); + } + private static HashMap scrambleCachers = new HashMap(); private static SortedMap> puzzles; static { @@ -442,7 +454,7 @@ private static void addFmcSolutionSheet(PdfWriter docWriter, Document doc, Scram } PdfContentByte cb = docWriter.getDirectContent(); float LINE_THICKNESS = 0.5f; - BaseFont bf = sansSerifFont; + BaseFont bf = getFontForLocale(locale); int bottom = 30; int left = 35; @@ -715,7 +727,7 @@ private static void addFmcScrambleCutoutSheet(PdfWriter docWriter, Document doc, String scramble = scrambleRequest.scrambles[index]; PdfContentByte cb = docWriter.getDirectContent(); - BaseFont bf = sansSerifFont; + BaseFont bf = getFontForLocale(Translate.DEFAULT_LOCALE); int bottom = 30; int left = 35;