JUCE 使用内部字库显示中文等字体

1.将字体文件放入项目内

屏幕快照 2019-09-18 上午10.26.38.png

2.在项目的initialise中加入

Typeface::Ptr getTypefaceForFont(const Font &f);
LookAndFeel::setDefaultLookAndFeel(&customLookAndFeel);

EG:

void initialise (const String& commandLine) override
{
    // This method is where you should put your application's initialisation code..
    Typeface::Ptr getTypefaceForFont(const Font &f);
    LookAndFeel::setDefaultLookAndFeel(&customLookAndFeel);
    mainWindow.reset (new MainWindow (getApplicationName()));
}

然后在Main文件中的私有类加入

    class CustomFontLookAndFeel : public LookAndFeel_V4 {
      public:
        CustomFontLookAndFeel() {
            LookAndFeel::setDefaultLookAndFeel(this);
        }

        static const Font getCustomFont() {
            static auto typeface = Typeface::createSystemTypefaceFor(BinaryData::SiHei_otf, BinaryData::SiHei_otfSize);
            return Font(typeface);
        }

        Typeface::Ptr getTypefaceForFont(const Font &f) override {
            return getCustomFont().getTypeface();
        }

      private:
    } customLookAndFeel;

其中SiHei_otf是字体文件文件名称


  • Alipay
  • Wechat
手机上阅读
 最后一次更新于2019-10-12

0 条评论

添加新评论

Markdown is supported.