From b14541e11199e4cb5e1308cfe6f11705a7ac3405 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 20 Jun 2014 21:50:33 +0530 Subject: [PATCH] RTF metadata: Add proper support for unicode characters when reading and writing metadata to RTF files Also fix failure to write metadata to RTF files that do not already have a \info block --- src/calibre/ebooks/metadata/rtf.py | 32 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/calibre/ebooks/metadata/rtf.py b/src/calibre/ebooks/metadata/rtf.py index 0eae93a8d3..770d770909 100644 --- a/src/calibre/ebooks/metadata/rtf.py +++ b/src/calibre/ebooks/metadata/rtf.py @@ -6,6 +6,7 @@ Edit metadata in RTF files. """ import re, cStringIO, codecs +from calibre import force_unicode from calibre.ebooks.metadata import MetaInformation, string_to_authors title_pat = re.compile(r'\{\\info.*?\{\\title(.*?)(? 1: md.append('}') @@ -165,7 +171,7 @@ def set_metadata(stream, options): index = src.rindex('}') return src[:index] + r'{\ '[:-1] + name + ' ' + val + '}}' src, pos = get_document_info(stream) - if src is not None: + if src is None: create_metadata(stream, options) else: olen = len(src) @@ -173,7 +179,7 @@ def set_metadata(stream, options): base_pat = r'\{\\name(.*?)(?