0

My question seems too simple but I searched and read many codes without success.
How can I use my font (non-builtin fonts) available to MuPDF in order to render EPUB document using that font?
I tried to load my font as follow without success:

// just after creating fz_context...

// registering my custom system font installation function
fz_install_load_system_font_funcs(m_ctx, [](fz_context *ctx, const char *name, int bold, int italic, int needs_exact_metrics) -> fz_font* {
    reinterpret_cast<const unsigned char*>(ba.constData()), ba.length(), 0, 0);
    fz_font *f = nullptr;
    fz_try(ctx)
    {
        // ignore any argument just for test...
        f = fz_new_font_from_file(ctx, "Ubuntu", "/Users/seyedmahdimousavi/Library/Fonts/Ubuntu-R.ttf", 0, 0);
        //f = fz_new_font_from_file(ctx, nullptr, "/Users/seyedmahdimousavi/Library/Fonts/Ubuntu-R.ttf", 0, 1);
                
    } fz_catch(ctx) {
        return NULL;
    }
    return f;
}, nullptr, nullptr);

// call it
fz_font *ff = fz_load_system_font(m_ctx, "Ubuntu", 0, 0, 0);

and I applied following style for epub doc:

* {font-family: "default", "Ubuntu" ! important; }

by following call:

fz_try(m_ctx)
{
    fz_set_user_css(m_ctx, myCssText);
}
fz_catch(m_ctx)
{
    //...
}

Thanks a lot

S.M.Mousavi
  • 5,013
  • 7
  • 44
  • 59

1 Answers1

1

You can use @font-face declarations in your user CSS to define and load custom fonts for the EPUB engine.

ccxvii
  • 1,873
  • 1
  • 13
  • 11
  • This works as alternate method, but I have internal fonts that I don't want to copy on fs. I'm looking for existing functions to identify fonts such as `fz_new_font_from_memory` and `fz_new_font_from_buffer` but I don't know why these not works – S.M.Mousavi May 06 '23 at 15:35
  • The system font callbacks are only used by the PDF engine. To add fonts to the HTML engine we need more information. You can use the fz_add_html_font_face function on the epub_document.set fz_html_font_set object. – ccxvii May 07 '23 at 19:52
  • but these functions does not included on public api. How can I use these? – S.M.Mousavi May 09 '23 at 07:13