最新公告
  • 欢迎您光临起源地模板网,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!立即加入钻石VIP
  • Electron+Vue3 MAC 版日历开发记录(31)——Icons Font 制作

    正文概述 掘金(叶梅树)   2021-07-18   685

    在之前,我们的 设置 按钮因为 FullCalendar 没有提供对应的图标,所以独立于 FullCalendar 在 Main 界面添加,但这导致页面的不统一和协调。

    今天就想着如何自己手动创建一个只带图标 icons 的字体 CSS,把需要的 icons 打包进去。

    参考模仿

    先看看我们引用的 FullCalendar 提供的 font-face

    // icons.css
    
    @font-face {
      font-family: 'fcicons';
      src: url("data:application/x-font-ttf;charset=utf-8;base64,AAEAAAALAIAAAwAwT1MvMg8SBfAAAAC8AAAAYGNtYXAXVtKNAAABHAAAAFRnYXNwAAAAEAAAAXAAAAAIZ2x5ZgYydxIAAAF4AAAFNGhlYWQUJ7cIAAAGrAAAADZoaGVhB20DzAAABuQAAAAkaG10eCIABhQAAAcIAAAALGxvY2ED4AU6AAAHNAAAABhtYXhwAA8AjAAAB0wAAAAgbmFtZXsr690AAAdsAAABhnBvc3QAAwAAAAAI9AAAACAAAwPAAZAABQAAApkCzAAAAI8CmQLMAAAB6wAzAQkAAAAAAAAAAAAAAAAAAAABEAAAAAAAAAAAAAAAAAAAAABAAADpBgPA/8AAQAPAAEAAAAABAAAAAAAAAAAAAAAgAAAAAAADAAAAAwAAABwAAQADAAAAHAADAAEAAAAcAAQAOAAAAAoACAACAAIAAQAg6Qb//f//AAAAAAAg6QD//f//AAH/4xcEAAMAAQAAAAAAAAAAAAAAAQAB//8ADwABAAAAAAAAAAAAAgAANzkBAAAAAAEAAAAAAAAAAAACAAA3OQEAAAAAAQAAAAAAAAAAAAIAADc5AQAAAAABAWIAjQKeAskAEwAAJSc3NjQnJiIHAQYUFwEWMjc2NCcCnuLiDQ0MJAz/AA0NAQAMJAwNDcni4gwjDQwM/wANIwz/AA0NDCMNAAAAAQFiAI0CngLJABMAACUBNjQnASYiBwYUHwEHBhQXF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AGkAYwBvAG4Ac2ZjaWNvbnMAZgBjAGkAYwBvAG4Ac1JlZ3VsYXIAUgBlAGcAdQBsAGEAcmZjaWNvbnMAZgBjAGkAYwBvAG4Ac0ZvbnQgZ2VuZXJhdGVkIGJ5IEljb01vb24uAEYAbwBuAHQAIABnAGUAbgBlAHIAYQB0AGUAZAAgAGIAeQAgAEkAYwBvAE0AbwBvAG4ALgAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") format('truetype');
      font-weight: normal;
      font-style: normal;
    }
    
    .fc-icon {
      /* added for fc */
      display: inline-block;
      width: 1em;
      height: 1em;
      text-align: center;
      user-select: none;
    
      /* use !important to prevent issues with browser extensions that change fonts */
      font-family: 'fcicons' !important;
      speak: none;
      font-style: normal;
      font-weight: normal;
      font-variant: normal;
      text-transform: none;
      line-height: 1;
    
      /* Better Font Rendering =========== */
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
    }
    
    .fc-icon-chevron-left:before {
      content: "\e900";
    }
    .fc-icon-chevron-right:before {
      content: "\e901";
    }
    .fc-icon-chevrons-left:before {
      content: "\e902";
    }
    .fc-icon-chevrons-right:before {
      content: "\e903";
    }
    .fc-icon-minus-square:before {
      content: "\e904";
    }
    .fc-icon-plus-square:before {
      content: "\e905";
    }
    .fc-icon-x:before {
      content: "\e906";
    }
    

    这里我们看到两个关注点:

    1. 字体可以导出成 base64;所以如何将我们的图标转成 base64 需要看看;
    2. 每个图标都需要增加一个 before 伪类,具体看看还是有规律的,所以我们自己生成的尽可能和他们保持一致,前缀:.fc-icon-

    制作 Font

    搜索一圈网站,大部分人推荐使用 icomoon icomoon.io/app/#/selec…

    Electron+Vue3 MAC 版日历开发记录(31)——Icons Font 制作

    官网提供了一些免费的和专题图标,但这不是我们需要的,这里,我先从 Naive UI 推荐的 xicons www.xicons.org/#/zh-CN 里挑选出需要的 icons 的 SVG。

    Electron+Vue3 MAC 版日历开发记录(31)——Icons Font 制作

    再导入到 icomoon.io。

    Electron+Vue3 MAC 版日历开发记录(31)——Icons Font 制作

    然后,再为他们设定一些属性:

    Electron+Vue3 MAC 版日历开发记录(31)——Icons Font 制作

    下葬后的文件夹里,除了字体文件,还有一个 css 文件,内容和上面的 css 居然高度相似 (难道 FullCalendar 也是这个网站制作他们的 Font 的?):

    @font-face {
      font-family: 'fcicons';
      src:
        url('fonts/fcicons.ttf?c33sp3') format('truetype'),
        url('fonts/fcicons.woff?c33sp3') format('woff'),
        url('fonts/fcicons.svg?c33sp3#fcicons') format('svg');
      font-weight: normal;
      font-style: normal;
      font-display: block;
    }
    
    [class^="fc-icon-"], [class*=" fc-icon-"] {
      /* use !important to prevent issues with browser extensions that change fonts */
      font-family: 'fcicons' !important;
      speak: never;
      font-style: normal;
      font-weight: normal;
      font-variant: normal;
      text-transform: none;
      line-height: 1;
    
      /* Better Font Rendering =========== */
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
    }
    
    .fc-icon-chevron-left:before {
      content: "\e900";
    }
    .fc-icon-chevron-right:before {
      content: "\e901";
    }
    .fc-icon-chevrons-left:before {
      content: "\e902";
    }
    .fc-icon-chevrons-right:before {
      content: "\e903";
    }
    .fc-icon-minus-square:before {
      content: "\e904";
    }
    .fc-icon-plus-square:before {
      content: "\e905";
    }
    .fc-icon-setting:before {
      content: "\e907";
    }
    .fc-icon-x:before {
      content: "\e906";
    }
    

    下面就是需要将字体文件转为 base64 格式的。

    借助 transfonter 工具transfonter.org/

    @font-face {
        font-family: 'fcicons';
        src: url('data:font/ttf;charset=utf-8;base64,AAEAAAANAIAAAwBQRkZUTY/XMFEAAAqkAAAAHEdERUYAJwATAAAKhAAAAB5PUy8yDxMFXgAAAVgAAABgY21hcBdX2ecAAAHsAAABXmdhc3AAAAAQAAAKfAAAAAhnbHlmYPjVtwAAA2gAAATsaGVhZB0uTcUAAADcAAAANmhoZWEHngPOAAABFAAAACRobXR4IRUA9QAAAbgAAAA0bG9jYQRCBa4AAANMAA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gEDAAMBBAEFAQYBBwEIAQkBCgELBmdseXBoMQd1bmkwMDAxB3VuaUU5MDAHdW5pRTkwMQd1bmlFOTAyB3VuaUU5MDMHdW5pRTkwNAd1bmlFOTA1B3VuaUU5MDYHdW5pRTkwNwAAAQAB//8ADwABAAAADAAAABYAAAACAAEAAQAMAAEABAAAAAIAAAAAAAAAAQAAAADVpCcIAAAAAN0ZhKQAAAAA3RmEpA==') format('truetype');
        font-weight: normal;
        font-style: normal;
        font-display: swap;
    }
    

    所以,我们可以直接重写 css 了。

    Electron+Vue3 MAC 版日历开发记录(31)——Icons Font 制作

    这样,我们就比 FullCalendar 多了一个设置 按钮:

    ::v-deep(.fc-icon-setting:before) {
      content: "\e907";
    }
    

    好了,验证下,按钮图标的可用性,创建一个 Custorm Button:

      calendarOptions: {
        plugins: [dayGridPlugin, interactionPlugin],
        customButtons: {
          settingButton: {
            icon: 'setting',
            click: this.settingClick,
          } as CustomButtonInput,
        } as unknown,
        headerToolbar: {
          left: 'settingButton',
          center: 'title',
          right: 'prev,next',
        },
        
        ...
    

    看看效果:

    Electron+Vue3 MAC 版日历开发记录(31)——Icons Font 制作

    总结

    只要稍微调整下,以后可以根据需要,增加一些需要的图标,然后制作成 base64 格式,直接修改 @font-face 即可。

    今天只是简单的介绍如何自制 Font 图标字体样式。之后可能可以做一些复杂的。


    起源地下载网 » Electron+Vue3 MAC 版日历开发记录(31)——Icons Font 制作

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
    提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。若排除这种情况,可在对应资源底部留言,或 联络我们.。
    找不到素材资源介绍文章里的示例图片?
    对于PPT,KEY,Mockups,APP,网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。
    模板不会安装或需要功能定制以及二次开发?
    请QQ联系我们

    发表评论

    还没有评论,快来抢沙发吧!

    如需帝国cms功能定制以及二次开发请联系我们

    联系作者

    请选择支付方式

    ×
    迅虎支付宝
    迅虎微信
    支付宝当面付
    余额支付
    ×
    微信扫码支付 0 元