Ebooks reader not capturing embedded font for epub file
Asked Answered
T

2

11

I have a problem in my epub reader, it displays all content correctly but it's not capturing the embedded font in the CSS file.

When I run the same file on other readers the embedded font is displayed but when I run the html file on one of the browsers like Firefox it shows the same result as my app and it doesn't display the embedded font.

Here is a sample html content:

<html  dir="rtl"   xml:lang="ar"   lang="ar"  xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=1332,height=794" />
        <title>the-title-3</title>
        <link href="css/idGeneratedStyles.css" rel="stylesheet" type="text/css" />
    </head>
    <body id="the-title-3" lang="en-GB" xml:lang="en-GB" style="width:1332px;height:794px">
        <div id="_idContainer003">
            <img class="_idGenObjectAttribute-1 _idGenObjectAttribute-2" src="image/inner_cover_and_credits_page.jpg" alt="" />
        </div>
        <div id="_idContainer004">
            <div style="width:11599.37px;height:2993.39px;position:absolute;top:0px;left:0px;-webkit-transform-origin: 0% 0%; -webkit-transform: translate(0px,3.93px) rotate(0deg) scale(0.05);transform-origin: 0% 0%; transform: translate(0px,3.93px) rotate(0deg) scale(0.05);">
                <p class="Basic-Paragraph ParaOverride-1"><span id="_idTextSpan000" class="CharOverride-1" style="position:absolute;top:13.65px;left:3168.24px;">الجملة الرئيسية في النص </span></p>
                <p class="Basic-Paragraph ParaOverride-1"><span id="_idTextSpan001" class="CharOverride-1" style="position:absolute;top:733.65px;left:831.71px;">&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;الكاتبة</span></p>
            </div>
        </div>
    </body>
</html>

And this is it's corresponding css file:

@font-face {
    font-family:"Futura Lt BT";
    font-style:normal;
    font-weight:normal;
    src : url("../font/FuturaBT-Light.TTF") format('truetype');
}
@font-face {
    font-family:"GE SS Text Light";
    font-style:normal;
    font-weight:300;
    src : url("../font/GESSTextLight-Light.otf") format('opentype');
}
@font-face {
    font-family:"GE SS Text Medium";
    font-style:normal;
    font-weight:500;
    src : url("../font/GESSTextMedium-Medium.otf") format('opentype');
}
@font-face {
    font-family:"Simplified Arabic";
    font-style:normal;
    font-weight:bold;
    src : url("../font/SimplifiedArabic-Bold.ttf") format('truetype');
}

body, div, dl, dt, dd, h1, h2, h3, h4, h5, h6, p, pre, code, blockquote         {
    margin:0;
    padding:0;
    border-width:0;
    text-rendering:optimizeSpeed;
}
div.Basic-Text-Frame {
    border-style:solid;
}
p.ParaOverride-1 {
    line-height:1;
    white-space:nowrap;
}
span.CharOverride-1 {
    color:#000000;
    font-family:"GE SS Text Medium", sans-serif;
    font-size:420px;
    font-style:normal;
    font-weight:500;
}

Here is a screenshot of the file layout:

enter image description here

To load the content of the html in the UIWebView:

[readingWebView loadHTMLString:contents baseURL:baseURL];

The only difference I can find between the submitted file on the other reader and the one I use in my application is that I submit a file of format .epub to the other reader like iBooks while I use the same file with extension .zip on my application. But I'm not sure if this is related. To display the content of the html files in the epub I use the UIWebView.

Thymelaeaceous answered 21/5, 2018 at 8:29 Comment(13)
Please post the layout of your resource files (css and fonts) on disk before you are loading the web view, and also some code of how you are doing that.Liaoyang
That and the resource file layout on disk. By file layout I mean where exactly do you have files like "idGeneratedStyles.css" and "FuturaBT-Light.TTF". Because obviously those files need to exist in order to be loaded, and they need to be in specific directories.Liaoyang
I have added a screenshot to show it.Thymelaeaceous
I also added the line where I load the content of the HTML on the UIWebViewThymelaeaceous
Kindly if you need any other details let me know.Thymelaeaceous
This looks good. Do you see images rendered? Like "images/inner_cover_and_credits_page.jpg". What's the value of baseURL ? If it's not a layout issue, then it might be a HTML/CSS or a font issue. I see that you apply the font "GE SS Text Medium" to span tags with class "CharOverride-1". In HTML you have some arabic text there. It should work as long as your font (GE SS) contains glyphs for arabic characters. Is that true? I would try to simplify your HTML and CSS to a minimal example , and make it work in a standalone Safari on desktop to find out what the problem is.Liaoyang
Yes the images are rendered correctly, all the features of the file are showing correctly, the only problem faced is with the embedded font, instead of using the embedded font it changes to a default one, although the same file in epub format renders the embedded fonts correctly on iBooks.Thymelaeaceous
On browsers like safari and firefox the html renders similarly to my app, it doesn't show the embedded fonts. so I think there should be smg extra to be done from the app side to render the font correctly like iBooksThymelaeaceous
Could you make a small test with just 3 files: html, css and 1 font. Test it with Safari and make sure that it doesn't work. Then set some other font, and test again. If it works with another font, then it is the font problem. In this case you need to investigate what's wrong with the font itself. If it doesn't work with another font, then it's a mistake in HTML/CSS, which should be trivial to fix. In the latter case share the simplified files in a zip, and people can help. I feel that it's a font problem.Liaoyang
As I have mentioned earlier the same file works properly on iBooks and may other e-readers. and the embedded font is showing perfectly without any issue, the problem is only showing on my application and on the browsers. I have tested the files with Safari and firefox and the embedded font doesn't work and I think that's because these browsers would not show a font that is not already among their default fonts. Other well known fonts would definitely work well.Thymelaeaceous
The Safari browser is definitely capable of loading a custom OTF font via @font-face. I believe it is either you files have a mistake (that iBooks can identify and fix), or your font has some peculiarities (that iBooks can identify and fix). I can't try it myself unless you share all the files and the font, so I'm asking you to try it.Liaoyang
Actually since iBooks can read it, I doubt that it's a font issue. What is the baseURL that you pass in?Liaoyang
This is not specific to one epub file this applies to all files I have, which are many hunderds which have many different embedded fonts (ttf and otf), and even other apps like play Books and Lithium also identify the fonts correctly.Thymelaeaceous
L
2

I can confirm the issue. I have tried your HTML and CSS (adapted it) with 2 different Arabic fonts ("Arabic Magic" and "Mcs Book Title 3"). Those are TTF fonts, but didn't work either.

When applied, there are no errors in the Web Inspector console, the fonts are loaded well. Also when applied I actually see the default font changes a bit: it increases spacing between letters a bit, and that's it. Same situation when I tried on Firefox and Chrome on macOS.

My guess is that most likely those fonts we try don't contain all the glyphs for the required characters to display, or that the font needs to be processed in some way before browser engines (including UIWebView) can successfully detect and render them.

I know it's not a definitive answer, but I'm just sharing my research here. Hope that it helps to continue digging into the problem.

Related issues:

Update: also tried windows-1256 Arabic encoding (reencoded HTML, and applied meta charset), because I thought that utf-8 might be too complicated for these fonts, but got the same result: the text is rendered with some default font.

Liaoyang answered 23/5, 2018 at 13:31 Comment(1)
Thank you for sharing your trials, any idea how I can fix that, cause it's showing perfectly on other applications.Thymelaeaceous
C
2

Not all the fonts are suitable for web display. You can check your font here. Notice, that some fonts have active icons of web, screen or mobile, and some don't. Use those fonts which are designed for web and screen simultaneously. https://www.fontsquirrel.com/fonts/list/recent

Christiechristin answered 17/11, 2018 at 10:8 Comment(1)
Thank you for your contribution, I truly appreciate your input, as I mentioned earlier, the font was being captured on iBooks reader, but in my reader it was not, therefore, it was not a font issue.Thymelaeaceous

© 2022 - 2024 — McMap. All rights reserved.