View Single Post
Old 11-23-2014, 12:50 PM   #13
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,738
Karma: 24031403
Join Date: Dec 2010
Device: Kindle PW2
@KevinH: Does bk.addfile() support bytearrays?

I did a quick test and came up with the following proof-of-concept code, which will add a blackletter ttf font located in the plugin's directory to the epub:

Code:
#!/usr/bin/env python
import os, inspect, uuid

def run(bk):
    basename = 'WallauRundgotisch-Heavy.ttf'
    binary_path = os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), basename)
    file_handle = open(binary_path, 'rb')
    uniqueid = 'id' + str(uuid.uuid4())[24:82]
    data = bytearray(file_handle.read())
    file_handle.close()
    mime = 'application/x-font-ttf'
    bk.addfile(uniqueid, basename, data, mime)
    
    return 0

def main():
    print('I reached main when I should not have\n')
    return -1

if __name__ == "__main__":
    sys.exit(main())
This code appears to be working, but I'm wondering if there is a better and/or more desirable method to add binary files?

Last edited by Doitsu; 11-24-2014 at 02:18 PM. Reason: Fixed invalid code.
Doitsu is offline   Reply With Quote