MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   bk.font_iter() is listing no fonts (https://www.mobileread.com/forums/showthread.php?t=326009)

Vroni 12-28-2019 05:41 AM

bk.font_iter() is listing no fonts
 
Hi,

what am i doing wrong?

Code:

def run(bk):
    print('xxx-|Start|-xxx')
    for (id, href, mime) in bk.font_iter():
        print('xxx-|',id , '|-xxx')
        print('xxx-|',href , '|-xxx')
        print('xxx-|',mime , '|-xxx')
 
    print('xxx-|End|-xxx')

    return 0

i am getting no fonts listet :(

mac os mojave, sigil 1.0.0

The fonts i have in the book are valid as they do show up in preview, in ADE and on my devices.

Regardless of what fonts i'm adding the list is always empty :(

Doitsu 12-28-2019 08:10 AM

Quote:

Originally Posted by Vroni (Post 3933686)
what am i doing wrong?

bk.font_iter() might fail, if the fonts don't have the proper mime type.

Please post the font manifest section of your test epub. For example,

Code:

<item id="LinLibertineG30-Regular.ttf" href="LinLibertineG30-Regular.ttf" media-type="application/vnd.ms-opentype"/>
The following quick & dirty version will also work with fonts that have the wrong mime type:

Code:

def run(bk):
    print('xxx-|Start|-xxx')
    for id, href, mime in bk.manifest_iter():
        if href.endswith('tf'):
            print('xxx-|',id , '|-xxx')
            print('xxx-|',href , '|-xxx')
            print('xxx-|',mime , '|-xxx')
    print('xxx-|End|-xxx')


Vroni 12-28-2019 08:42 AM

1 Attachment(s)
Hi,

i added the file with sigil and the original item looks like this

Code:

<item id="SourceCodePro-Regular.otf" href="Fonts/SourceCodePro-Regular.otf" media-type="font/otf"/>
Flightcrew is complaining that the mimetype isnt correct, changing it to the suggest value

Code:

<item id="SourceCodePro-Regular.otf" href="Fonts/SourceCodePro-Regular.otf" media-type="application/vnd.ms-opentype"/>
is fixing my "problem" with bk.font_iter()

So is this a bug in sigil not choosing the right mimetype? As i said, i added the fontfile with sigil.

Doitsu 12-28-2019 10:27 AM

Quote:

Originally Posted by Vroni (Post 3933724)
So is this a bug in sigil not choosing the right mimetype?

According to the IANA, the following font mime types can be used:

otf font/otf
sfnt font/sfnt
ttf font/ttf
woff font/woff
woff2 font/woff2

According to the epub3 specs, the following mime types are also acceptable:

ttf application/font-sfnt
otf application/vnd.ms-opentype
woff application/font-woff

I.e., font/otf is definitely a valid mime type. Maybe bk.font_iter() needs to be updated.

KevinH 12-28-2019 10:47 AM

Yes, this is a bug as I updated the media-types based on the latest iana spec which icludes the new font/* style recommended media types:

Here is the updated list of recognized font media types:

Code:

    'font/woff2'                              : 'Fonts',
    'font/woff'                              : 'Fonts',
    'font/ttf'                                : 'Fonts',
    'font/otf'                                : 'Fonts',
    'font/sfnt'                              : 'Fonts',
    'font/collection'                        : 'Fonts',
    'application/vnd.ms-opentype'            : 'Fonts',
    'application/font-sfnt'                  : 'Fonts',  # deprecated
    'application/font-ttf'                    : 'Fonts',  # deprecated
    'application/font-otf'                    : 'Fonts',  # deprecated
    'application/font-woff'                  : 'Fonts',  # deprecated
    'application/font-woff2'                  : 'Fonts',  # deprecated
    'application/x-font-ttf'                  : 'Fonts',  # deprecated
    'application/x-truetype-font'            : 'Fonts',  # deprecated
    'application/x-opentype-font'            : 'Fonts',  # deprecated
    'application/x-font-ttf'                  : 'Fonts',  # deprecated
    'application/x-font-otf'                  : 'Fonts',  # deprecated
    'application/x-font-opentype'            : 'Fonts',  # deprecated
    'application/x-font-truetype'            : 'Fonts',  # deprecated
    'application/x-font-truetype-collection'  : 'Fonts',  # deprecated

But I forgot to fix the code in the bk.font_iter() to match that expanded list:

Code:

    def font_iter(self):
        # yields manifest id, href, and mimetype
        for id in sorted(self._w.id_to_mime):
            mime = self._w.id_to_mime[id]
            if mime.find('font-') > -1 or mime.endswith('-ttf') or mime.endswith('truetype') or mime.endswith('opentype'):
                href = self._w.id_to_href[id]
                yield id, href, mime

So this code needs to be updated to include the new font/* media types.

Kevin

I will push a fix for this to master today.

Kevin

KevinH 12-28-2019 04:42 PM

This should now be fixed in master.
Thanks for your bug report.


All times are GMT -4. The time now is 08:44 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.