FolioReader / FolioReader-Android

A Java ePub reader and parser framework for Android.
BSD 3-Clause "New" or "Revised" License
2.25k stars 718 forks source link

Fonts are not working #317

Open iLeafSolutionsPvtLtd opened 5 years ago

iLeafSolutionsPvtLtd commented 5 years ago

Hi, The default fonts available in Folio Reader seem like not having much effect. Andada, Lato, Lora all look same. I tried your sample app, everyting is fine in it. Any help would be appreciated

hrishikesh-kadam commented 5 years ago

@iLeafSolutionsPvtLtd Do you mean to say choosing a different font doesn't change the font of book?

iLeafSolutionsPvtLtd commented 5 years ago

Yes. Change is not getting reflected

iLeafSolutionsPvtLtd commented 5 years ago

It actually redraws the page. But change is not visible font looks similar as it was

hrishikesh-kadam commented 5 years ago

It would be helpful if you could please fill the Issue Template, like Issue_Template_Examples.md

iLeafSolutionsPvtLtd commented 5 years ago

ok

iLeafSolutionsPvtLtd commented 5 years ago

Issue / Feature - Default fonts are not having any effect FolioReader version - 0.5.1 FolioReader Stock / Modified - Modified, But not much Android SDK - 27 Mobile / Tablet / Emulator Info - Mobile Crash / Error -

Steps to reproduce / Describe in detail - When we applied a font listed in Folio Reader has no effect at all. It looks similar as it was. Please find the implementation below: Config config = new Config() .setFont(1) .setShowTts(false) .setAllowedDirection(Config.AllowedDirection.VERTICAL_AND_HORIZONTAL) .setThemeColorRes(R.color.app_secondary_color);

    ReadPosition readPosition = DbUtility.getReadPositionFromDb(LOG_TAG,
            activity.getApplicationContext(), book.bookId);

    FolioReader folioReader = FolioReader.get();
    folioReader.setReadPositionListener(this)
            .setReadPosition(readPosition)
            .setConfig(config, true)
            .openBook(bookPath, String.valueOf(book.bookId));
hrishikesh-kadam commented 5 years ago

Thanks for filling the issue template. So do you mean to say setFont() is not showing any effect or by changing font from UI doesn't change font?

iLeafSolutionsPvtLtd commented 5 years ago

from UI

hrishikesh-kadam commented 5 years ago

Can you please share EPUB file with us for further investigation?

iLeafSolutionsPvtLtd commented 5 years ago

Sure. will give you now

iLeafSolutionsPvtLtd commented 5 years ago

Please use this link: save this file in directory :

hrishikesh-kadam commented 5 years ago

Issue is in OPS/styles/stylesheet.css of the above EPUB, body overrides the font-family.

iLeafSolutionsPvtLtd commented 5 years ago

Ok any workaround for it. Its better to hide that feature in such scenarios rite.

egidijusk commented 5 years ago

To override fonts in any epub file I did something like this. Just put this code in HtmlUtil#getHtmlContent. Feel free to offer a better solution.

String fontFamily = null;
String fontStyle = null;

switch (config.getFont()) {
    case Constants.FONT_ANDADA:
        fontFamily = "andada";
        fontStyle = "sans-serif";
        break;
    case Constants.FONT_LATO:
        fontFamily = "lato";
        fontStyle = "serif";
        break;
    case Constants.FONT_LORA:
        fontFamily = "lora";
        fontStyle = "serif";
        break;
    case Constants.FONT_RALEWAY:
        fontFamily = "raleway";
        fontStyle = "sans-serif";
        break;
    default:
        // default or internal epub fonts will be used
        break;
}

if (fontFamily != null) {
    String[] textElements = {"p", "span", "h1", "h2", "h3", "h4", "h5", "h6"};
    String fontFamilyStyle = "{font-family:\"{font family}\", {font style} !important;}"
            .replace("{font family}", fontFamily)
            .replace("{font style}", fontStyle);

    cssPath = cssPath + "\n<style>\n";
    for (String e : textElements) {
        cssPath = cssPath + "    " + e + " " + fontFamilyStyle + "\n";
    }
    cssPath = cssPath + "</style>";
}
slmolloy commented 5 years ago

@hrishikesh-kadam The solution @egidijusk posted worked for me as well. Could this solution be merged in?