From 4d97838ed9954ae7f8d7bb53edc6ac0bc97e499c Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 19 May 2015 04:56:16 -0400
Subject: [PATCH] Fix font artifacts in text2html conversion (#1490353)
---
program/lib/Roundcube/rcube_text2html.php | 28 ++++++++++++----------------
1 files changed, 12 insertions(+), 16 deletions(-)
diff --git a/program/lib/Roundcube/rcube_text2html.php b/program/lib/Roundcube/rcube_text2html.php
index 2ffe530..5c240d5 100644
--- a/program/lib/Roundcube/rcube_text2html.php
+++ b/program/lib/Roundcube/rcube_text2html.php
@@ -46,10 +46,6 @@
protected $config = array(
// non-breaking space
'space' => "\xC2\xA0",
- // word-joiner (zero-width no-break space)
- // 'wordjoiner' => "\xEF\xBB\xBF", // U+2060
- // use deprecated U+FEFF character because of webkit issue with displaying U+2060 (#1490353)
- 'wordjoiner' => "\xEF\xBB\xBF", // U+FEFF
// enables format=flowed parser
'flowed' => false,
// enables wrapping for non-flowed text
@@ -63,6 +59,9 @@
'links' => true,
// string replacer class
'replacer' => 'rcube_string_replacer',
+ // prefix and suffix of unwrappable line
+ 'nobr_start' => '<span style="white-space:nowrap">',
+ 'nobr_end' => '</span>',
);
@@ -281,11 +280,10 @@
// replace HTML special characters
$text = strtr($text, $table);
- $nbsp = $this->config['space'];
- $nobr = $this->config['wordjoiner'];
-
// replace some whitespace characters
$text = str_replace(array("\r", "\t"), array('', ' '), $text);
+
+ $nbsp = $this->config['space'];
// replace spaces with non-breaking spaces
if ($is_flowed) {
@@ -304,15 +302,13 @@
$text = $copy;
}
- // make the whole line non-breakable
- else {
- $repl = array(
- ' ' => $nbsp,
- '-' => $nobr . '-' . $nobr,
- '/' => $nobr . '/',
- );
-
- $text = str_replace(array_keys($repl), array_values($repl), $text);
+ // make the whole line non-breakable if needed
+ else if ($text !== '' && preg_match('/[^a-zA-Z0-9_]/', $text)) {
+ // use non-breakable spaces to correctly display
+ // trailing/leading spaces and multi-space inside
+ $text = str_replace(' ', $nbsp, $text);
+ // wrap in nobr element, so it's not wrapped on e.g. - or /
+ $text = $this->config['nobr_start'] . $text . $this->config['nobr_end'];
}
return $text;
--
Gitblit v1.9.1