Commit ec709958 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

QString as key is evil, add a nice enum

parent e72d2f53
......@@ -1884,66 +1884,68 @@ void DocumentPrivate::doContinueGooglesDocumentSearch(void *pagesToNotifySet, vo
}
}
QVariant DocumentPrivate::documentMetaData( const QString &key, const QVariant &option ) const
QVariant DocumentPrivate::documentMetaData( const Generator::DocumentMetaDataKey &key, const QVariant &option ) const
{
if ( key == QLatin1String( "PaperColor" ) )
switch ( key )
{
bool giveDefault = option.toBool();
// load paper color from Settings, or use the default color (white)
// if we were told to do so
QColor color;
if ( ( SettingsCore::renderMode() == SettingsCore::EnumRenderMode::Paper )
&& SettingsCore::changeColors() )
case Generator::PaperColorMetaData:
{
color = SettingsCore::paperColor();
}
else if ( giveDefault )
{
color = Qt::white;
bool giveDefault = option.toBool();
QColor color;
if ( ( SettingsCore::renderMode() == SettingsCore::EnumRenderMode::Paper )
&& SettingsCore::changeColors() )
{
color = SettingsCore::paperColor();
}
else if ( giveDefault )
{
color = Qt::white;
}
return color;
}
return color;
}
else if ( key == QLatin1String( "TextAntialias" ) )
{
switch ( SettingsCore::textAntialias() )
{
case SettingsCore::EnumTextAntialias::Enabled:
return true;
break;
break;
case Generator::TextAntialiasMetaData:
switch ( SettingsCore::textAntialias() )
{
case SettingsCore::EnumTextAntialias::Enabled:
return true;
break;
#if 0
case Settings::EnumTextAntialias::UseKDESettings:
// TODO: read the KDE configuration
return true;
break;
case Settings::EnumTextAntialias::UseKDESettings:
// TODO: read the KDE configuration
return true;
break;
#endif
case SettingsCore::EnumTextAntialias::Disabled:
return false;
break;
}
}
else if ( key == QLatin1String( "GraphicsAntialias" ) )
{
switch ( SettingsCore::graphicsAntialias() )
{
case SettingsCore::EnumGraphicsAntialias::Enabled:
return true;
break;
case SettingsCore::EnumGraphicsAntialias::Disabled:
return false;
break;
}
}
else if ( key == QLatin1String( "TextHinting" ) )
{
switch ( SettingsCore::textHinting() )
{
case SettingsCore::EnumTextHinting::Enabled:
return true;
break;
case SettingsCore::EnumTextHinting::Disabled:
return false;
break;
}
case SettingsCore::EnumTextAntialias::Disabled:
return false;
break;
}
break;
case Generator::GraphicsAntialiasMetaData:
switch ( SettingsCore::graphicsAntialias() )
{
case SettingsCore::EnumGraphicsAntialias::Enabled:
return true;
break;
case SettingsCore::EnumGraphicsAntialias::Disabled:
return false;
break;
}
break;
case Generator::TextHintingMetaData:
switch ( SettingsCore::textHinting() )
{
case SettingsCore::EnumTextHinting::Enabled:
return true;
break;
case SettingsCore::EnumTextHinting::Disabled:
return false;
break;
}
break;
}
return QVariant();
}
......
......@@ -172,11 +172,12 @@ class DocumentPrivate
* Sets the bounding box of the given @p page (in terms of upright orientation, i.e., Rotation0).
*/
void setPageBoundingBox( int page, const NormalizedRect& boundingBox );
/**
* Request a particular metadata of the Document itself (ie, not something
* depending on the document type/backend).
*/
QVariant documentMetaData( const QString &key, const QVariant &option ) const;
QVariant documentMetaData( const Generator::DocumentMetaDataKey &key, const QVariant &option ) const;
/**
* Return whether the normalized rectangle @p rectOfInterest on page number @p rectPage
......
......@@ -420,6 +420,24 @@ void Generator::setFeature( GeneratorFeature feature, bool on )
}
QVariant Generator::documentMetaData( const QString &key, const QVariant &option ) const
{
Q_D( const Generator );
if ( !d->m_document )
return QVariant();
if (key == QLatin1String("PaperColor"))
return documentMetaData(PaperColorMetaData, option);
if (key == QLatin1String("GraphicsAntialias"))
return documentMetaData(GraphicsAntialiasMetaData, option);
if (key == QLatin1String("TextAntialias"))
return documentMetaData(TextAntialiasMetaData, option);
if (key == QLatin1String("TextHinting"))
return documentMetaData(TextHintingMetaData, option);
return QVariant();
}
QVariant Generator::documentMetaData( const DocumentMetaDataKey &key, const QVariant &option ) const
{
Q_D( const Generator );
if ( !d->m_document )
......
......@@ -518,11 +518,29 @@ class OKULARCORE_EXPORT Generator : public QObject
*/
void setFeature( GeneratorFeature feature, bool on = true );
/**
* Internal document setting
*/
enum DocumentMetaDataKey {
PaperColorMetaData, ///< Returns the paper color if set in Settings or the default color (white) if option is true (otherwise returns a non initialized QColor)
TextAntialiasMetaData, ///< Returns text antialias from Settings (option is not used)
GraphicsAntialiasMetaData, ///< Returns graphic antialias from Settings (option is not used)
TextHintingMetaData ///< Returns text hinting from Settings (option is not used)
};
/**
* Request a meta data of the Document, if available, like an internal
* setting.
*
* @since 1.1
*/
QVariant documentMetaData( const DocumentMetaDataKey &key, const QVariant &option = QVariant() ) const;
/**
* Request a meta data of the Document, if available, like an internal
* setting.
*/
QVariant documentMetaData( const QString &key, const QVariant &option = QVariant() ) const;
OKULARCORE_DEPRECATED QVariant documentMetaData( const QString &key, const QVariant &option = QVariant() ) const;
/**
* Return the pointer to a mutex the generator can use freely.
......
......@@ -60,7 +60,7 @@ bool DviGenerator::loadDocument( const QString & fileName, QVector< Okular::Page
(void)userMutex();
m_dviRenderer = new dviRenderer(documentMetaData(QStringLiteral("TextHinting"), QVariant()).toBool());
m_dviRenderer = new dviRenderer(documentMetaData(TextHintingMetaData, QVariant()).toBool());
connect(m_dviRenderer, &dviRenderer::error, this, &DviGenerator::error);
connect(m_dviRenderer, &dviRenderer::warning, this, &DviGenerator::warning);
connect(m_dviRenderer, &dviRenderer::notice, this, &DviGenerator::notice);
......
......@@ -1249,7 +1249,7 @@ bool PDFGenerator::reparseConfig()
bool somethingchanged = false;
// load paper color
QColor color = documentMetaData( QStringLiteral("PaperColor"), true ).value< QColor >();
QColor color = documentMetaData( PaperColorMetaData, true ).value< QColor >();
// if paper color is changed we have to rebuild every visible pixmap in addition
// to the outputDevice. it's the 'heaviest' case, other effect are just recoloring
// over the page rendered on 'standard' white background.
......@@ -1281,16 +1281,16 @@ bool PDFGenerator::setDocumentRenderHints()
const Poppler::Document::RenderHints oldhints = pdfdoc->renderHints();
#define SET_HINT(hintname, hintdefvalue, hintflag) \
{ \
bool newhint = documentMetaData(QStringLiteral(hintname), hintdefvalue).toBool(); \
bool newhint = documentMetaData(hintname, hintdefvalue).toBool(); \
if (newhint != oldhints.testFlag(hintflag)) \
{ \
pdfdoc->setRenderHint(hintflag, newhint); \
changed = true; \
} \
}
SET_HINT("GraphicsAntialias", true, Poppler::Document::Antialiasing)
SET_HINT("TextAntialias", true, Poppler::Document::TextAntialiasing)
SET_HINT("TextHinting", false, Poppler::Document::TextHinting)
SET_HINT(GraphicsAntialiasMetaData, true, Poppler::Document::Antialiasing)
SET_HINT(TextAntialiasMetaData, true, Poppler::Document::TextAntialiasing)
SET_HINT(TextHintingMetaData, false, Poppler::Document::TextHinting)
#undef SET_HINT
#ifdef HAVE_POPPLER_0_24
// load thin line mode
......
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