Quote:
Originally Posted by KevinH
In a plugin, you can walk all of the fonts (or even all of the files in the manifest) using the api and then add new files for any with the wrong media-type and then remove the incorrect ones.
|
If I understand you correctly, there's no way to directly manipulate manifest entries or rewrite the manifest section only. The following code seems to work, but, IMHO, it'd be much easier if the Plugin Runner code allowed for direct manifest entry value changes.
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
def run(bk):
# read manifest items
for id in sorted(bk._w.id_to_mime):
mime = bk._w.id_to_mime[id]
href = bk._w.id_to_href[id]
# check for invalid MIME types
if href.endswith('tf') and mime not in ('application/x-font-ttf', 'application/vnd.ms-opentype') :
data = bk.readfile(id)
bk.deletefile(id)
if href.endswith('ttf'):
bk.addfile(id, os.path.basename(href), data, 'application/x-font-ttf')
else:
bk.addfile(id, os.path.basename(href), data, 'application/vnd.ms-opentype')
print 'MIME type updated: ' + os.path.basename(href)
def main():
print 'I reached main when I should not have\n'
return -1
if __name__ == "__main__":
sys.exit(main())
BTW, for Sigil 0.9.0 you could theoretically use
application/font-sfnt for both .ttf and .otf files, since both epubcheck 3.0.1 and epubcheck 4.x accept all font mimetypes that start with "font" or "x-font."