From 3e24b6a1152f7fcd4694023d0e95fc81ae802e08 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 4 Sep 2010 17:09:10 -0400 Subject: [PATCH] PDF Input: Fix more characters that the PDF format encodes as two characters that are drawn on top of each other. --- src/calibre/ebooks/conversion/preprocess.py | 73 ++++++++++++++------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/src/calibre/ebooks/conversion/preprocess.py b/src/calibre/ebooks/conversion/preprocess.py index 973e508746..f7b803974f 100644 --- a/src/calibre/ebooks/conversion/preprocess.py +++ b/src/calibre/ebooks/conversion/preprocess.py @@ -142,55 +142,78 @@ class HTMLPreProcessor(object): # Fix pdftohtml markup PDFTOHTML = [ # Fix umlauts - (re.compile(u'¨\s*()*\s*o', re.UNICODE), lambda match: u'ö'), - (re.compile(u'¨\s*()*\s*O', re.UNICODE), lambda match: u'Ö'), - (re.compile(u'¨\s*()*\s*u', re.UNICODE), lambda match: u'ü'), - (re.compile(u'¨\s*()*\s*U', re.UNICODE), lambda match: u'Ü'), + # ¨ + (re.compile(u'¨\s*()*\s*a', re.UNICODE), lambda match: u'ä'), + (re.compile(u'¨\s*()*\s*A', re.UNICODE), lambda match: u'Ä'), (re.compile(u'¨\s*()*\s*e', re.UNICODE), lambda match: u'ë'), (re.compile(u'¨\s*()*\s*E', re.UNICODE), lambda match: u'Ë'), (re.compile(u'¨\s*()*\s*i', re.UNICODE), lambda match: u'ï'), (re.compile(u'¨\s*()*\s*I', re.UNICODE), lambda match: u'Ï'), - (re.compile(u'¨\s*()*\s*a', re.UNICODE), lambda match: u'ä'), - (re.compile(u'¨\s*()*\s*A', re.UNICODE), lambda match: u'Ä'), + (re.compile(u'¨\s*()*\s*o', re.UNICODE), lambda match: u'ö'), + (re.compile(u'¨\s*()*\s*O', re.UNICODE), lambda match: u'Ö'), + (re.compile(u'¨\s*()*\s*u', re.UNICODE), lambda match: u'ü'), + (re.compile(u'¨\s*()*\s*U', re.UNICODE), lambda match: u'Ü'), # Fix accents - (re.compile(u'`\s*()*\s*o', re.UNICODE), lambda match: u'ò'), - (re.compile(u'`\s*()*\s*O', re.UNICODE), lambda match: u'Ò'), - (re.compile(u'`\s*()*\s*u', re.UNICODE), lambda match: u'ù'), - (re.compile(u'`\s*()*\s*U', re.UNICODE), lambda match: u'Ù'), + # ` + (re.compile(u'`\s*()*\s*a', re.UNICODE), lambda match: u'à'), + (re.compile(u'`\s*()*\s*A', re.UNICODE), lambda match: u'À'), (re.compile(u'`\s*()*\s*e', re.UNICODE), lambda match: u'è'), (re.compile(u'`\s*()*\s*E', re.UNICODE), lambda match: u'È'), (re.compile(u'`\s*()*\s*i', re.UNICODE), lambda match: u'ì'), (re.compile(u'`\s*()*\s*I', re.UNICODE), lambda match: u'Ì'), - (re.compile(u'`\s*()*\s*a', re.UNICODE), lambda match: u'à'), - (re.compile(u'`\s*()*\s*A', re.UNICODE), lambda match: u'À'), + (re.compile(u'`\s*()*\s*o', re.UNICODE), lambda match: u'ò'), + (re.compile(u'`\s*()*\s*O', re.UNICODE), lambda match: u'Ò'), + (re.compile(u'`\s*()*\s*u', re.UNICODE), lambda match: u'ù'), + (re.compile(u'`\s*()*\s*U', re.UNICODE), lambda match: u'Ù'), - (re.compile(u'´\s*()*\s*o', re.UNICODE), lambda match: u'ó'), - (re.compile(u'´\s*()*\s*O', re.UNICODE), lambda match: u'Ó'), - (re.compile(u'´\s*()*\s*u', re.UNICODE), lambda match: u'ú'), - (re.compile(u'´\s*()*\s*U', re.UNICODE), lambda match: u'Ú'), + # ´ + (re.compile(u'´\s*()*\s*a', re.UNICODE), lambda match: u'á'), + (re.compile(u'´\s*()*\s*A', re.UNICODE), lambda match: u'Á'), + (re.compile(u'´\s*()*\s*c', re.UNICODE), lambda match: u'ć'), + (re.compile(u'´\s*()*\s*C', re.UNICODE), lambda match: u'Ć'), (re.compile(u'´\s*()*\s*e', re.UNICODE), lambda match: u'é'), (re.compile(u'´\s*()*\s*E', re.UNICODE), lambda match: u'É'), (re.compile(u'´\s*()*\s*i', re.UNICODE), lambda match: u'í'), (re.compile(u'´\s*()*\s*I', re.UNICODE), lambda match: u'Í'), - (re.compile(u'´\s*()*\s*a', re.UNICODE), lambda match: u'á'), - (re.compile(u'´\s*()*\s*A', re.UNICODE), lambda match: u'Á'), + (re.compile(u'´\s*()*\s*o', re.UNICODE), lambda match: u'ó'), + (re.compile(u'´\s*()*\s*O', re.UNICODE), lambda match: u'Ó'), + (re.compile(u'´\s*()*\s*n', re.UNICODE), lambda match: u'ń'), + (re.compile(u'´\s*()*\s*N', re.UNICODE), lambda match: u'Ń'), + (re.compile(u'´\s*()*\s*s', re.UNICODE), lambda match: u'ś'), + (re.compile(u'´\s*()*\s*S', re.UNICODE), lambda match: u'Ś'), + (re.compile(u'´\s*()*\s*u', re.UNICODE), lambda match: u'ú'), + (re.compile(u'´\s*()*\s*U', re.UNICODE), lambda match: u'Ú'), + (re.compile(u'´\s*()*\s*z', re.UNICODE), lambda match: u'ź'), + (re.compile(u'´\s*()*\s*Z', re.UNICODE), lambda match: u'Ź'), - (re.compile(u'ˆ\s*()*\s*o', re.UNICODE), lambda match: u'ô'), - (re.compile(u'ˆ\s*()*\s*O', re.UNICODE), lambda match: u'Ô'), - (re.compile(u'ˆ\s*()*\s*u', re.UNICODE), lambda match: u'û'), - (re.compile(u'ˆ\s*()*\s*U', re.UNICODE), lambda match: u'Û'), + # ˆ + (re.compile(u'ˆ\s*()*\s*a', re.UNICODE), lambda match: u'â'), + (re.compile(u'ˆ\s*()*\s*A', re.UNICODE), lambda match: u'Â'), (re.compile(u'ˆ\s*()*\s*e', re.UNICODE), lambda match: u'ê'), (re.compile(u'ˆ\s*()*\s*E', re.UNICODE), lambda match: u'Ê'), (re.compile(u'ˆ\s*()*\s*i', re.UNICODE), lambda match: u'î'), (re.compile(u'ˆ\s*()*\s*I', re.UNICODE), lambda match: u'Î'), - (re.compile(u'ˆ\s*()*\s*a', re.UNICODE), lambda match: u'â'), - (re.compile(u'ˆ\s*()*\s*A', re.UNICODE), lambda match: u'Â'), + (re.compile(u'ˆ\s*()*\s*o', re.UNICODE), lambda match: u'ô'), + (re.compile(u'ˆ\s*()*\s*O', re.UNICODE), lambda match: u'Ô'), + (re.compile(u'ˆ\s*()*\s*u', re.UNICODE), lambda match: u'û'), + (re.compile(u'ˆ\s*()*\s*U', re.UNICODE), lambda match: u'Û'), - # Fix more special characters + # ¸ (re.compile(u'¸\s*()*\s*c', re.UNICODE), lambda match: u'ç'), (re.compile(u'¸\s*()*\s*C', re.UNICODE), lambda match: u'Ç'), + # ˛ + (re.compile(u'˛\s*()*\s*a', re.UNICODE), lambda match: u'ą'), + (re.compile(u'˛\s*()*\s*A', re.UNICODE), lambda match: u'Ą'), + (re.compile(u'˛\s*()*\s*e', re.UNICODE), lambda match: u'ę'), + (re.compile(u'˛\s*()*\s*E', re.UNICODE), lambda match: u'Ę'), + + # ˙ + (re.compile(u'˙\s*()*\s*z', re.UNICODE), lambda match: u'ż'), + (re.compile(u'˙\s*()*\s*Z', re.UNICODE), lambda match: u'Ż'), + + # Remove page links (re.compile(r'', re.IGNORECASE), lambda match: ''), # Remove
tags