{"id":170,"date":"2025-06-13T10:38:30","date_gmt":"2025-06-13T02:38:30","guid":{"rendered":"https:\/\/itcat.me\/?p=170"},"modified":"2025-06-13T10:38:31","modified_gmt":"2025-06-13T02:38:31","slug":"go%e7%bc%96%e7%a8%8b%e6%97%b6fyne%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"https:\/\/itcat.me\/?p=170","title":{"rendered":"GO\u7f16\u7a0b\u65f6fyne\u4e2d\u6587\u4e71\u7801\u89e3\u51b3"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\u4fbf\u53ef\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#24292e;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 0 16px;font-size:0.8em;width:100%;text-align:left;background-color:#fff;font-style:italic;color:#24292e\"><span style=\"border-bottom:1px solid rgba(16, 41, 67, 0.2)\">Go<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"func init() {\n\t\/\/ \u8bbe\u7f6e\u4e2d\u6587\u5b57\u4f53\uff1a\u89e3\u51b3\u4e2d\u6587\u4e71\u7801\u95ee\u9898\n\tfontPaths := findfont.List()\n\tfor _, path := range fontPaths {\n\t\tif strings.Contains(path, &quot;msyh.ttf&quot;) || strings.Contains(path, &quot;simhei.ttf&quot;) || strings.Contains(path, &quot;simsun.ttc&quot;) || strings.Contains(path, &quot;simkai.ttf&quot;) {\n\t\t\tos.Setenv(&quot;FYNE_FONT&quot;, path)\n\t\t\tbreak\n\t\t}\n\t}\n}\" style=\"color:#fff;display:none;background-color:#24292e\" aria-label=\"\u590d\u5236\" data-copied-text=\"\u5df2\u590d\u5236\uff01\" data-has-text-button=\"textSimple\" data-inside-header-type=\"stringSmall\" aria-live=\"polite\" class=\"code-block-pro-copy-button\"><span class=\"cbp-btn-text\">\u590d\u5236<\/span><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">func<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #6F42C1\">init<\/span><span style=\"color: #24292E\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">\t<\/span><span style=\"color: #6A737D\">\/\/ \u8bbe\u7f6e\u4e2d\u6587\u5b57\u4f53\uff1a\u89e3\u51b3\u4e2d\u6587\u4e71\u7801\u95ee\u9898<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">\tfontPaths <\/span><span style=\"color: #D73A49\">:=<\/span><span style=\"color: #24292E\"> findfont.<\/span><span style=\"color: #005CC5\">List<\/span><span style=\"color: #24292E\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">\t<\/span><span style=\"color: #D73A49\">for<\/span><span style=\"color: #24292E\"> _, path <\/span><span style=\"color: #D73A49\">:=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">range<\/span><span style=\"color: #24292E\"> fontPaths {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">\t\t<\/span><span style=\"color: #D73A49\">if<\/span><span style=\"color: #24292E\"> strings.<\/span><span style=\"color: #005CC5\">Contains<\/span><span style=\"color: #24292E\">(path, <\/span><span style=\"color: #032F62\">&quot;msyh.ttf&quot;<\/span><span style=\"color: #24292E\">) <\/span><span style=\"color: #D73A49\">||<\/span><span style=\"color: #24292E\"> strings.<\/span><span style=\"color: #005CC5\">Contains<\/span><span style=\"color: #24292E\">(path, <\/span><span style=\"color: #032F62\">&quot;simhei.ttf&quot;<\/span><span style=\"color: #24292E\">) <\/span><span style=\"color: #D73A49\">||<\/span><span style=\"color: #24292E\"> strings.<\/span><span style=\"color: #005CC5\">Contains<\/span><span style=\"color: #24292E\">(path, <\/span><span style=\"color: #032F62\">&quot;simsun.ttc&quot;<\/span><span style=\"color: #24292E\">) <\/span><span style=\"color: #D73A49\">||<\/span><span style=\"color: #24292E\"> strings.<\/span><span style=\"color: #005CC5\">Contains<\/span><span style=\"color: #24292E\">(path, <\/span><span style=\"color: #032F62\">&quot;simkai.ttf&quot;<\/span><span style=\"color: #24292E\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">\t\t\tos.<\/span><span style=\"color: #005CC5\">Setenv<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;FYNE_FONT&quot;<\/span><span style=\"color: #24292E\">, path)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">\t\t\t<\/span><span style=\"color: #D73A49\">break<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">}<\/span><\/span><\/code><\/pre><\/div>\n<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_170\" class=\"pvc_stats all  \" data-element-id=\"170\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/itcat.me\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\u4fbf\u53ef\uff1a<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_170\" class=\"pvc_stats all  \" data-element-id=\"170\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/itcat.me\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-170","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/itcat.me\/index.php?rest_route=\/wp\/v2\/posts\/170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itcat.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itcat.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itcat.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itcat.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=170"}],"version-history":[{"count":1,"href":"https:\/\/itcat.me\/index.php?rest_route=\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":171,"href":"https:\/\/itcat.me\/index.php?rest_route=\/wp\/v2\/posts\/170\/revisions\/171"}],"wp:attachment":[{"href":"https:\/\/itcat.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itcat.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itcat.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}