Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 4410d6a8 authored by Laurent Montel's avatar Laurent Montel 😁

Fix Bug 316707 - Use em font size rather than absolute px values in HTML messages

FIXED-IN: 14.12.2
BUG: 316707
parent 71c2a621
......@@ -770,7 +770,7 @@ bool KMeditor::replaceSignature( const KPIMIdentities::Signature &oldSig,
return found;
}
void KMeditor::fillComposerTextPart ( MessageComposer::TextPart* textPart ) const
void KMeditor::fillComposerTextPart ( MessageComposer::TextPart* textPart )
{
if( isFormattingUsed() && MessageComposer::MessageComposerSettings::self()->improvePlainTextOfHtmlMessage() ) {
Grantlee::PlainTextMarkupBuilder *pb = new Grantlee::PlainTextMarkupBuilder();
......@@ -792,11 +792,38 @@ void KMeditor::fillComposerTextPart ( MessageComposer::TextPart* textPart ) cons
}
textPart->setWordWrappingEnabled( lineWrapMode() == QTextEdit::FixedColumnWidth );
if( isFormattingUsed() ) {
textPart->setCleanHtml( toCleanHtml() );
QString cleanHtml = toCleanHtml();
fixHtmlFontSize(cleanHtml);
textPart->setCleanHtml( cleanHtml );
textPart->setEmbeddedImages( embeddedImages() );
}
}
void KMeditor::fixHtmlFontSize(QString &cleanHtml)
{
static const QString FONTSTYLEREGEX = QLatin1String("<span style=\".*font-size:(.*)pt;.*</span>" );
QRegExp styleRegex( FONTSTYLEREGEX );
styleRegex.setMinimal( true );
int offset = styleRegex.indexIn( cleanHtml, 0 );
while (offset != -1) {
// replace all the matching text with the new line text
bool ok = false;
const QString fontSizeStr = styleRegex.cap(1);
const int ptValue = fontSizeStr.toInt(&ok);
if (ok) {
double emValue = (double)ptValue/12;
const QString emValueStr = QString::number(emValue, 'g', 2);
cleanHtml.replace(styleRegex.pos(1), QString(fontSizeStr + QLatin1String("px")).length(), emValueStr + QLatin1String("em"));
}
// advance the search offset to just beyond the last replace
offset += styleRegex.matchedLength();
// find the next occurance
offset = styleRegex.indexIn( cleanHtml, offset );
}
}
PimCommon::AutoCorrection* KMeditor::autocorrection() const
{
return d->mAutoCorrection;
......
......@@ -175,7 +175,7 @@ public:
* Fill the given composer MessageComposer::TextPart with what's in the editor currently.
* @param textPart The MessageComposer::TextPart to fill.
*/
void fillComposerTextPart( MessageComposer::TextPart* textPart ) const;
void fillComposerTextPart( MessageComposer::TextPart* textPart );
PimCommon::AutoCorrection *autocorrection() const;
......@@ -224,6 +224,8 @@ protected:
virtual void keyPressEvent ( QKeyEvent * e );
private:
void fixHtmlFontSize(QString &cleanHtml);
KMeditorPrivate *const d;
friend class KMeditorPrivate;
Q_PRIVATE_SLOT( d, void ensureCursorVisibleDelayed() )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment