Commit ce7fa7b9 authored by Abdel-Rahman Abdel-Rahman's avatar Abdel-Rahman Abdel-Rahman Committed by Albert Astals Cid

Fictionbook: Add support for code, superscript, & subscript tags

Summary: BUG: 387426

Test Plan: Open a book with the code, superscript, & subscript tags. Verify that the code is visible in a mono-space font, & superscripts & subscripts are formatted appropriately.

Reviewers: #okular, aacid

Reviewed By: #okular, aacid

Subscribers: aacid, cfeck, ngraham

Tags: #okular

Differential Revision: https://phabricator.kde.org/D10566
parent 7014e86f
......@@ -422,6 +422,9 @@ bool Converter::convertSection( const QDomElement &element )
} else if ( child.tagName() == QLatin1String( "empty-line" ) ) {
if ( !convertEmptyLine( child ) )
return false;
} else if ( child.tagName() == QLatin1String( "code" ) ) {
if( !convertCode( child ) )
return false;
}
child = child.nextSiblingElement();
......@@ -505,6 +508,15 @@ bool Converter::convertParagraph( const QDomElement &element )
} else if ( childElement.tagName() == QLatin1String( "strikethrough" ) ) {
if ( !convertStrikethrough( childElement ) )
return false;
} else if ( childElement.tagName() == QLatin1String( "code" ) ) {
if( !convertCode( childElement ) )
return false;
} else if ( childElement.tagName() == QLatin1String( "sup" ) ) {
if( !convertSuperScript( childElement ) )
return false;
} else if ( childElement.tagName() == QLatin1String( "sub" ) ) {
if( !convertSubScript( childElement ) )
return false;
}
} else if ( child.isText() ) {
const QDomText childText = child.toText();
......@@ -791,3 +803,51 @@ bool Converter::convertStanza( const QDomElement &element )
return true;
}
bool Converter::convertCode( const QDomElement &element )
{
QTextCharFormat origFormat = mCursor->charFormat();
QTextCharFormat codeFormat( origFormat );
codeFormat.setFontFamily( QStringLiteral( "monospace" ) );
mCursor->setCharFormat( codeFormat );
if ( !convertParagraph( element ) )
return false;
mCursor->setCharFormat( origFormat );
return true;
}
bool Converter::convertSuperScript( const QDomElement &element )
{
QTextCharFormat origFormat = mCursor->charFormat();
QTextCharFormat superScriptFormat( origFormat );
superScriptFormat.setVerticalAlignment( QTextCharFormat::AlignSuperScript );
mCursor->setCharFormat( superScriptFormat );
if ( !convertParagraph( element ) )
return false;
mCursor->setCharFormat( origFormat );
return true;
}
bool Converter::convertSubScript( const QDomElement &element )
{
QTextCharFormat origFormat = mCursor->charFormat();
QTextCharFormat subScriptFormat( origFormat );
subScriptFormat.setVerticalAlignment( QTextCharFormat::AlignSubScript );
mCursor->setCharFormat( subScriptFormat );
if ( !convertParagraph( element ) )
return false;
mCursor->setCharFormat( origFormat );
return true;
}
......@@ -47,6 +47,9 @@ class Converter : public Okular::TextDocumentConverter
bool convertStrikethrough( const QDomElement &element );
bool convertStyle( const QDomElement &element );
bool convertStanza( const QDomElement &element );
bool convertCode( const QDomElement &element );
bool convertSuperScript( const QDomElement &element );
bool convertSubScript( const QDomElement &element );
bool convertTitleInfo( const QDomElement &element );
......
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