{"id":7502,"date":"2025-12-22T15:39:48","date_gmt":"2025-12-22T07:39:48","guid":{"rendered":"https:\/\/support.fuxinsoft.cn\/?p=7502"},"modified":"2025-12-26T17:20:07","modified_gmt":"2025-12-26T09:20:07","slug":"new-font%e6%97%b6%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%aecharset%e7%b1%bb%e5%9e%8b%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/support.fuxinsoft.cn\/?p=7502","title":{"rendered":"new Font()\u65f6\u600e\u4e48\u8bbe\u7f6eCharset\u7c7b\u578b\uff1f"},"content":{"rendered":"\n<p>1.\u4ec0\u4e48\u662f<strong>charset\uff1f<\/strong><\/p>\n\n\n\n<p><strong>charset<\/strong>&nbsp;\u662f&nbsp;<strong>character set<\/strong>&nbsp;\u7684\u7f29\u5199\uff0c\u4e2d\u6587\u610f\u601d\u662f\u5b57\u7b26\u96c6\uff0c\u5b83\u662f\u8ba1\u7b97\u673a\u4e2d\u7528\u4e8e\u5b9a\u4e49\u5b57\u7b26\u4e0e\u4e8c\u8fdb\u5236\u7f16\u7801\u5bf9\u5e94\u5173\u7cfb\u7684\u96c6\u5408\uff0c\u51b3\u5b9a\u4e86\u6587\u672c\u6570\u636e\u5982\u4f55\u88ab\u5b58\u50a8\u3001\u4f20\u8f93\u548c\u663e\u793a\u3002\u5b57\u7b26\u96c6\u7684\u672c\u8d28\u662f\u5efa\u7acb\u5b57\u7b26\uff08\u5982\u5b57\u6bcd\u3001\u6c49\u5b57\u3001\u7b26\u53f7\uff09&nbsp;\u548c\u4e8c\u8fdb\u5236\u6570\u5b57\uff080 \u548c 1\uff09&nbsp;\u4e4b\u95f4\u7684\u6620\u5c04\u89c4\u5219\uff0c\u89e3\u51b3\u4e0d\u540c\u8bed\u8a00\u3001\u4e0d\u540c\u7b26\u53f7\u5728\u8ba1\u7b97\u673a\u4e2d\u7684\u7edf\u4e00\u8868\u793a\u95ee\u9898\u3002<\/p>\n\n\n\n<p><strong>Foxit PDF  SDK\u4e2d\u7684Charset <\/strong>\u662f\u5728\u4f7f\u7528\u7cfb\u7edf\u5b57\u4f53\u6784\u5efa\u4e00\u4e2a\u5b57\u4f53\u5bf9\u8c61\u65f6\uff0c\u5e38\u4f7f\u7528\u65b9\u6cd5\uff1afoxit.common.Font.Font ( string name,  int styles,  Font.Charset charset,  int weight)\u3002\u5176\u4e2dcharset \u7c7b\u578b\u4e3b\u8981\u662f\u533a\u5206\u5404\u7c7b\u8bed\u8a00\u7684\uff0ccharset\u662f\u4e3a\u4e86\u6620\u5c04\u5b57\u4f53\u540d\u7528\u3002\u5982\u679c\u8bbe\u7f6e\u9519\u8bef\uff0c\u53ef\u80fd\u5bfc\u81f4\u751f\u6210\u7684\u6587\u672c\u5185\u5bb9\u4e71\u7801\u3002<\/p>\n\n\n\n<p>Foxit PDF SDK API\u6587\u6863\u4e2dcharset\u7684\u7c7b\u578b\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"660\" height=\"701\" src=\"https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2025\/12\/image-113.png\" alt=\"\" class=\"wp-image-7504\" style=\"aspect-ratio:0.9415331119185074;width:800px;height:auto\" srcset=\"https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2025\/12\/image-113.png 660w, https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2025\/12\/image-113-282x300.png 282w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/figure>\n\n\n\n<p>2.\u600e\u4e48\u5224\u65ad\u5f53\u524d\u8be5\u4f7f\u7528\u54ea\u4e2acharset?<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u7528\u4e8e\u5e38\u89c1\u7684\u4e2d\u82f1\u6587\u6587\u672c\uff0c\u914d\u5408\u5df2\u77e5\u80fd\u591f\u652f\u6301\u4e2d\u82f1\u6587\u7684\u5b57\u4f53\uff0c\u90a3\u4e48\u7528e_CharsetGB2312\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u6d89\u53ca\u66f4\u591a\u7684\u8bed\u8a00\u79cd\u7c7b\uff0c\u6bd4\u5982\u8981\u7528\u4e00\u4e2a\u6cf0\u6587\u7684\u5b57\u4f53\uff0c\u5728PDF\u4e2d\u6dfb\u52a0\u4e00\u6bb5\u6587\u672c\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<p>a.\u9700\u8981\u5148\u901a\u8fc7\u6807\u51c6\u63a5\u53e3\uff0c\u627e\u5230\u652f\u6301\u8be5\u8bed\u8a00\u7684\u5b57\u4f53\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"782\" height=\"205\" src=\"https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2025\/12\/image-114.png\" alt=\"\" class=\"wp-image-7505\" style=\"aspect-ratio:3.815139502973014;width:800px;height:auto\" srcset=\"https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2025\/12\/image-114.png 782w, https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2025\/12\/image-114-300x79.png 300w, https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2025\/12\/image-114-768x201.png 768w\" sizes=\"(max-width: 782px) 100vw, 782px\" \/><\/figure>\n\n\n\n<p>java \u4e0a\u83b7\u53d6\u7cfb\u7edf\u7684\u5168\u90e8\u5b57\u4f53\uff0c\u4ee5\u53ca\u662f\u5426\u652f\u6301\u6cf0\u6587\u7684\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import java.awt.*;<br>import java.awt.font.FontRenderContext;<br>import java.awt.geom.Rectangle2D;<br>import java.util.*;<br>import  java.util.List;<br><br>public class SystemFontsGet {<br><br>    \/\/ \u5e38\u89c1\u5b57\u4f53\u7684\u5b57\u7b26\u96c6\u6620\u5c04\uff08\u805a\u7126\u5b57\u4f53\u7684\u5b57\u7b26\u96c6\u7c7b\u578b\uff0c\u800c\u975e\u7f16\u7801\uff09<br>    private static final Map&lt;String, String&gt; <em>FONT_CHARSET_MAP <\/em>= new HashMap&lt;&gt;();<br><br><br><br>    \/\/ \u7528\u4e8e\u68c0\u6d4b\u7684\u5b57\u7b26\uff08\u4e2d\u6587\u3001\u65e5\u6587\u3001\u97e9\u6587\u3001\u82f1\u6587\uff09<br>    private static final char <em>CHINESE_CHAR <\/em>= '\u4e2d'; \/\/ \u4e2d\u6587\u6807\u8bc6\u5b57\u7b26<br>    private static final char <em>JAPANESE_CHAR <\/em>= '\u65e5'; \/\/ \u65e5\u6587\u6807\u8bc6\u5b57\u7b26\uff08\u5e73\u5047\u540d\/\u6c49\u5b57\uff09<br>    private static final char <em>KOREAN_CHAR <\/em>= '\ud55c'; \/\/ \u97e9\u6587\u6807\u8bc6\u5b57\u7b26\uff08\u8c1a\u6587\uff09<br>    private static final char <em>ENGLISH_CHAR <\/em>= 'A'; \/\/ \u82f1\u6587\u6807\u8bc6\u5b57\u7b26<br>    private static final char <em>THAI_CHAR <\/em>= '\u0e2a'; \/\/\u6cf0\u6587<br><br>    <em>\/**<br>     * \u68c0\u6d4b\u5b57\u4f53\u662f\u5426\u80fd\u6e32\u67d3\u6307\u5b9a\u5b57\u7b26\uff08\u6838\u5fc3\uff1a\u5224\u65ad\u5b57\u4f53\u662f\u5426\u5305\u542b\u8be5\u5b57\u7b26\u7684\u5b57\u5f62\uff09<br>     * @param font \u5b57\u4f53\u5bf9\u8c61<br>     * @param c \u8981\u68c0\u6d4b\u7684\u5b57\u7b26<br>     * @return true=\u80fd\u6e32\u67d3\uff0cfalse=\u4e0d\u80fd\u6e32\u67d3\uff08\u4f7f\u7528\u9ed8\u8ba4\u5b57\u4f53\u66ff\u4ee3\uff09<br>     *\/<br>    <\/em>private static boolean canRenderChar(Font font, char c) {<br>        \/\/ \u83b7\u53d6\u5b57\u4f53\u7684\u6e32\u67d3\u4e0a\u4e0b\u6587<br>        FontRenderContext frc = new FontRenderContext(null, true, true);<br>        \/\/ \u83b7\u53d6\u5b57\u7b26\u7684\u5b57\u5f62\u8fb9\u754c\uff1a\u5982\u679c\u8fb9\u754c\u4e3a\u7a7a\uff0c\u8bf4\u660e\u5b57\u4f53\u65e0\u6cd5\u6e32\u67d3\u8be5\u5b57\u7b26<br>        Rectangle2D bounds = font.getStringBounds(String.<em>valueOf<\/em>(c), frc);<br>        return font.canDisplay(c) &amp;&amp; bounds.getWidth() &gt; 0 &amp;&amp; bounds.getHeight() &gt; 0;<br>    }<br><br><br>    <em>\/**<br>     * \u83b7\u53d6\u5b57\u4f53\u652f\u6301\u7684\u8bed\u8a00\uff08\u57fa\u4e8e\u5b57\u7b26\u6e32\u67d3\u68c0\u6d4b\uff09<br>     * @param font \u5b57\u4f53\u5bf9\u8c61<br>     * @return \u652f\u6301\u7684\u8bed\u8a00\u63cf\u8ff0<br>     *\/<br>    <\/em>private static String getSupportedLanguages(Font font) {<br>        List&lt;String&gt; supported = new ArrayList&lt;&gt;();<br><br>        \/\/ \u68c0\u6d4b\u82f1\u6587\uff08\u51e0\u4e4e\u6240\u6709\u5b57\u4f53\u90fd\u652f\u6301\uff09<br>        if (<em>canRenderChar<\/em>(font, <em>ENGLISH_CHAR<\/em>)) {<br>            supported.add(\"\u82f1\u6587\");<br>        }<br>        \/\/ \u68c0\u6d4b\u4e2d\u6587<br>        if (<em>canRenderChar<\/em>(font, <em>CHINESE_CHAR<\/em>)) {<br>            supported.add(\"\u4e2d\u6587\uff08\u7b80\/\u7e41\uff09\");<br>        }<br>        \/\/ \u68c0\u6d4b\u65e5\u6587<br>        if (<em>canRenderChar<\/em>(font, <em>JAPANESE_CHAR<\/em>)) {<br>            supported.add(\"\u65e5\u6587\");<br>        }<br>        \/\/ \u68c0\u6d4b\u97e9\u6587<br>        if (<em>canRenderChar<\/em>(font, <em>KOREAN_CHAR<\/em>)) {<br>            supported.add(\"\u97e9\u6587\");<br>        }<br>        if (<em>canRenderChar<\/em>(font, <em>THAI_CHAR<\/em>)) {<br>            supported.add(\"\u6cf0\u6587\");<br>        }<br>        \/\/ \u5982\u679c\u4ec5\u652f\u6301\u82f1\u6587\uff0c\u8865\u5145\u8bf4\u660e\u201c\u897f\u6b27\u8bed\u8a00\u201d<br>        if (supported.size() == 1 &amp;&amp; supported.get(0).equals(\"\u82f1\u6587\")) {<br>            supported.add(\"\u897f\u6b27\u8bed\u8a00\uff08\u5982\u6cd5\u8bed\u3001\u5fb7\u8bed\uff09\");<br>        }<br><br>        return supported.isEmpty() ? \"\u672a\u77e5\" : String.<em>join<\/em>(\"\u3001\", supported);<br>    }<br><br>    <em>\/**<br>     * \u8bfb\u53d6\u7cfb\u7edf\u6240\u6709\u5b57\u4f53\u4fe1\u606f<br>     *\/<br>    <\/em>public static List&lt;Map&lt;String, Object&gt;&gt; readSystemFonts() {<br>        List&lt;Map&lt;String, Object&gt;&gt; fontList = new ArrayList&lt;&gt;();<br><br>        \/\/ \u83b7\u53d6\u672c\u5730\u56fe\u5f62\u73af\u5883\u7684\u6240\u6709\u5b57\u4f53\u5bb6\u65cf\u540d\u79f0\uff08\u53bb\u91cd\uff09<br>        GraphicsEnvironment ge = GraphicsEnvironment.<em>getLocalGraphicsEnvironment<\/em>();<br>        String[] fontFamilyNames = ge.getAvailableFontFamilyNames();<br><br>        \/\/ \u904d\u5386\u6bcf\u4e2a\u5b57\u4f53<br>        for (String fontFamilyName : fontFamilyNames) {<br>            try {<br>                \/\/ \u521b\u5efa\u5b57\u4f53\u5bf9\u8c61\uff08\u5e38\u89c4\u6837\u5f0f\uff0c\u5927\u5c0f12\uff09<br>                Font font = new Font(fontFamilyName, Font.<em>PLAIN<\/em>, 12);<br><br>                \/\/ \u89e3\u6790\u5b57\u4f53\u4fe1\u606f<br>                String supportedLanguages = <em>getSupportedLanguages<\/em>(font);<br>                \/\/ \u5c01\u88c5\u4fe1\u606f<br>                Map&lt;String, Object&gt; fontInfo = new LinkedHashMap&lt;&gt;();<br>                fontInfo.put(\"fontFamilyName\", fontFamilyName); \/\/ \u5b57\u4f53\u5bb6\u65cf\u540d\u79f0<br>                fontInfo.put(\"supportedLanguages\", supportedLanguages); \/\/ \u652f\u6301\u7684\u8bed\u8a00<br><br>                fontList.add(fontInfo);<br>            } catch (Exception e) {<br>                System.<em>err<\/em>.println(\"\u5904\u7406\u5b57\u4f53[\" + fontFamilyName + \"]\u65f6\u51fa\u9519\uff1a\" + e.getMessage());<br>            }<br>        }<br><br>        return fontList;<br>    }<br><br>    public static void main(String[] args) {<br>        \/\/ \u8bfb\u53d6\u5b57\u4f53\u4fe1\u606f<br>        List&lt;Map&lt;String, Object&gt;&gt; fontList = <em>readSystemFonts<\/em>();<br><br>        \/\/ \u683c\u5f0f\u5316\u8f93\u51fa<br>        System.<em>out<\/em>.println(\"\u7cfb\u7edf\u5df2\u5b89\u88c5\u5b57\u4f53\u5217\u8868\uff08\u5171\" + fontList.size() + \"\u4e2a\uff09\uff1a\");<br>        System.<em>out<\/em>.println(\"------------------------------------------------------------------------------------------\");<br>        System.<em>out<\/em>.printf(\"%-30s  %-30s%n\",<br>                \"\u5b57\u4f53\u5bb6\u65cf\u540d\u79f0\", \"\u652f\u6301\u7684\u8bed\u8a00\");<br>        System.<em>out<\/em>.println(\"------------------------------------------------------------------------------------------\");<br><br>        for (Map&lt;String, Object&gt; fontInfo : fontList) {<br>            System.<em>out<\/em>.printf(\"%-30s  %-30s%n\",<br>                    fontInfo.get(\"fontFamilyName\"),<br>                    fontInfo.get(\"supportedLanguages\"));<br>        }<br>    }<br>}<br><\/pre>\n\n\n\n<p>b. \u9009\u53d6\u4e00\u4e2a\u652f\u6301\u6cf0\u6587\u7684\u5b57\u4f53\uff0c\u6bd4\u5982\u201cMicrosoft Sans Serif\u201d\uff0c\u4eceAPI\u6587\u6863\u4e2d\u627e\u5230\u5bf9\u5e94\u6cf0\u6587\u7684\u7684charset\u7c7b\u578b &#8220;e_CharsetThai&#8221;\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Font font=new Font(\"Microsoft Sans Serif\", e_StylesSmallCap, e_CharsetThai, 0);<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u4ec0\u4e48\u662fcharset\uff1f charset&nbsp;\u662f&nbsp;character set&nbsp;\u7684\u7f29 [&hellip;]<\/p>\n","protected":false},"author":31,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77],"tags":[1242,1243,303,334,1244],"class_list":["post-7502","post","type-post","status-publish","format-standard","hentry","category-gsdk","tag-charset","tag-font","tag-303","tag-334","tag-1244"],"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","_links":{"self":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/7502","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7502"}],"version-history":[{"count":2,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/7502\/revisions"}],"predecessor-version":[{"id":7588,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/7502\/revisions\/7588"}],"wp:attachment":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}