Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 05-13-2015, 01:01 PM   #16
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
Sigil is doing that correct. But there are a lot of converters or other programs doing it not correct.

Doitso: thx but this is only working for octet-stream, there are some other media-types out there.

@Diap: yes, thats what i'm looking for. But to achieve this i need to know how Sigil is doinf that to do it the same way. Now i need to have a look in the Sigil-Python-API to find out what is available to achieve this. Getting the fonts is easy, i've done that creating the Stylesheet. But now i need the way back

Edit: just read the API documentation and as far as i can see there is no method to write something to the manifest.

Last edited by rubeus; 05-13-2015 at 01:23 PM.
rubeus is offline   Reply With Quote
Old 05-13-2015, 02:06 PM   #17
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,644
Karma: 5433388
Join Date: Nov 2009
Device: many
Hi,

Quote:
Edit: just read the API documentation and as far as i can see there is no method to write something to the manifest.
I am not sure what you are trying to do. Where did the incorrect media type come from? Upon import if you load an epub, it will use the media-type from the incoming content.opf otherwise it will use the file extension to look up the media-type per the map I posted a link to.

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.

So, yes this is easily doable via a plugin. If you want more information about how to understand the plugin api, just ask in the Sigil plugin developers thread so that any answers can be kept in one place to help future plugin developers.

KevinH
KevinH is online now   Reply With Quote
Advert
Old 05-14-2015, 03:46 AM   #18
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by KevinH View Post
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."
Doitsu is offline   Reply With Quote
Old 05-14-2015, 05:14 AM   #19
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
Hi doitso

thats exactly what i'm currently testing, i'm only using the font iterator. Is there a way to get the sigil version in a plugin?

But maybe we should really move this to plugin develop forum.
rubeus is offline   Reply With Quote
Old 05-14-2015, 05:34 AM   #20
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by rubeus View Post
thats exactly what i'm currently testing, i'm only using the font iterator.
My code uses parts of the font iterator code and should behave exactly the same.

Quote:
Originally Posted by rubeus View Post
Is there a way to get the sigil version in a plugin?
For all intents and purposes my code pretty much mimics what Sigil does when fonts are added.

Quote:
Originally Posted by rubeus View Post
But maybe we should really move this to plugin develop forum.
I agree. Can a moderator please move this thread to the Plugin section?
Doitsu is offline   Reply With Quote
Advert
Old 05-14-2015, 09:31 AM   #21
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,549
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by Doitsu View Post
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())
Not that it matters a lot in this instance/example, but you may just want to use the manifest_iter method of the bookcontainer (bk) class instead of calling the underlying wrapper methods and properties directly.

Code:
for id, href, mime in bk.manifest_iter()

Last edited by DiapDealer; 05-14-2015 at 09:58 AM.
DiapDealer is offline   Reply With Quote
Old 05-14-2015, 09:54 AM   #22
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,644
Karma: 5433388
Join Date: Nov 2009
Device: many
Hi,

Yes, DiapDealer is correct. Calling the wrapper routines directly in your plugin is NOT supported. The wrapper routines are subject to change at any time. You should be using the iterators in the bookcontainer class. The bookcontainer class is the public API for the edit plugins.

Given the design uses the content.opf to derive the interface itself and tries to protect the content.opf from being incorrectly changed, directly changing the media-types will not be supported. It should not be needed if font files are added in Sigil as Sigil will assign the correct media-type.

Hope this explains things.

KevinH
KevinH is online now   Reply With Quote
Old 05-14-2015, 10:09 AM   #23
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
There are books created outside Sigil and often they do have an incorrect media type. Sigil itself does not offer any help here, it only flags the error and i need to manipulate the content.opf manually. I guess i was telling this more than three times, why is there always the hint that Sigil is inserting fonts correctly? I never said that Sigil is inserting fonts incorrectly. But others do. At least one person out of 8 billion would like to have something helpful here. thats why i created this plugin.
rubeus is offline   Reply With Quote
Old 05-14-2015, 10:39 AM   #24
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,644
Karma: 5433388
Join Date: Nov 2009
Device: many
No, you are incorrect ...

If you load an epub into Sigil that has bad media types it may end up storing the file in the incorrect location for an epub in Sigil. Or it may place it in the correct place but with an incorrect media- type. If either of these happen, the user can do one of two things depending on their skill level.

1) Delete the font files in Sigil and re-add them and Sigil will automatically put them in the right place (as I repeatedly have pointed out).

OR

2) Use CodeView to directly edit the content.opf and change just the media-types.


If you want to accomplish something similar in the plugin, simply use the correct bookcontainer API calls as directed earler.

No one is saying the problem does not exist. We are simply pointing out that if you add fonts using Sigil, they will be assigned the correct media-types which in turn leads directly to approach 1) above and the API approach we pointed out in the plugin.

Hope this makes things clearer.

KevinH

Quote:
Originally Posted by rubeus View Post
There are books created outside Sigil and often they do have an incorrect media type. Sigil itself does not offer any help here, it only flags the error and i need to manipulate the content.opf manually. I guess i was telling this more than three times, why is there always the hint that Sigil is inserting fonts correctly? I never said that Sigil is inserting fonts incorrectly. But others do. At least one person out of 8 billion would like to have something helpful here. thats why i created this plugin.
KevinH is online now   Reply With Quote
Old 05-14-2015, 12:16 PM   #25
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
*sigh* nuff said
rubeus is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Q: media-type for TrueType fonts? phossler Editor 19 09-08-2023 11:06 PM
Problem with detection/correction of media-type error jackie_w Editor 2 01-04-2014 08:06 AM
Buy vs licence in another media type murraypaul General Discussions 15 06-11-2013 11:11 PM
media-type me too ePub 5 08-07-2012 05:32 PM
Permissable Spine Media Type Error mimosawind ePub 5 10-07-2011 03:55 AM


All times are GMT -4. The time now is 10:28 AM.


MobileRead.com is a privately owned, operated and funded community.