Skip to content
Permalink
Browse files

Push text format setting to layout render context

  • Loading branch information
nyalldawson committed Nov 27, 2018
1 parent 1eaf95a commit 6755cbd6cfbbd82ce76b1a46bb53c8c002782b80
@@ -202,6 +202,24 @@ and customize their rendering based on the layer.
If ``layer`` is -1, all item layers should be rendered.

.. seealso:: :py:func:`setCurrentExportLayer`
%End

QgsRenderContext::TextRenderFormat textRenderFormat() const;
%Docstring
Returns the text render format, which dictates how text is rendered (e.g. as paths or real text objects).

.. seealso:: :py:func:`setTextRenderFormat`

.. versionadded:: 3.4.3
%End

void setTextRenderFormat( QgsRenderContext::TextRenderFormat format );
%Docstring
Sets the text render ``format``, which dictates how text is rendered (e.g. as paths or real text objects).

.. seealso:: :py:func:`textRenderFormat`

.. versionadded:: 3.4.3
%End

signals:
@@ -1118,6 +1118,7 @@ QgsMapSettings QgsLayoutItemMap::mapSettings( const QgsRectangle &extent, QSizeF
jobMapSettings.setPathResolver( mLayout->project()->pathResolver() );

jobMapSettings.setLabelingEngineSettings( mLayout->project()->labelingEngineSettings() );
jobMapSettings.setTextRenderFormat( mLayout->renderContext().textRenderFormat() );

return jobMapSettings;
}
@@ -200,6 +200,28 @@ class CORE_EXPORT QgsLayoutRenderContext : public QObject
*/
int currentExportLayer() const { return mCurrentExportLayer; }

/**
* Returns the text render format, which dictates how text is rendered (e.g. as paths or real text objects).
*
* \see setTextRenderFormat()
* \since QGIS 3.4.3
*/
QgsRenderContext::TextRenderFormat textRenderFormat() const
{
return mTextRenderFormat;
}

/**
* Sets the text render \a format, which dictates how text is rendered (e.g. as paths or real text objects).
*
* \see textRenderFormat()
* \since QGIS 3.4.3
*/
void setTextRenderFormat( QgsRenderContext::TextRenderFormat format )
{
mTextRenderFormat = format;
}

signals:

/**
@@ -230,6 +252,8 @@ class CORE_EXPORT QgsLayoutRenderContext : public QObject
bool mBoundingBoxesVisible = true;
bool mPagesVisible = true;

QgsRenderContext::TextRenderFormat mTextRenderFormat = QgsRenderContext::TextFormatAlwaysOutlines;

friend class QgsLayoutExporter;
friend class TestQgsLayout;
friend class LayoutContextPreviewSettingRestorer;
@@ -130,6 +130,7 @@ QgsRenderContext QgsLayoutUtils::createRenderContextForMap( QgsLayoutItemMap *ma
context.setPainter( painter );

context.setFlags( map->layout()->renderContext().renderContextFlags() );
context.setTextRenderFormat( map->layout()->renderContext().textRenderFormat() );
return context;
}
}
@@ -139,7 +140,11 @@ QgsRenderContext QgsLayoutUtils::createRenderContextForLayout( QgsLayout *layout
QgsLayoutItemMap *referenceMap = layout ? layout->referenceMap() : nullptr;
QgsRenderContext context = createRenderContextForMap( referenceMap, painter, dpi );
if ( layout )
{
context.setFlags( layout->renderContext().renderContextFlags() );
context.setTextRenderFormat( layout->renderContext().textRenderFormat() );
}

return context;
}

@@ -43,6 +43,7 @@ class TestQgsLayoutContext: public QObject
void layer();
void dpi();
void renderContextFlags();
void textFormat();
void boundingBoxes();
void exportLayer();
void geometry();
@@ -193,6 +194,15 @@ void TestQgsLayoutContext::renderContextFlags()
QVERIFY( ( flags & QgsRenderContext::ForceVectorOutput ) );
}

void TestQgsLayoutContext::textFormat()
{
QgsLayoutRenderContext context( nullptr );
context.setTextRenderFormat( QgsRenderContext::TextFormatAlwaysOutlines );
QCOMPARE( context.textRenderFormat(), QgsRenderContext::TextFormatAlwaysOutlines );
context.setTextRenderFormat( QgsRenderContext::TextFormatAlwaysText );
QCOMPARE( context.textRenderFormat(), QgsRenderContext::TextFormatAlwaysText );
}

void TestQgsLayoutContext::boundingBoxes()
{
QgsLayoutRenderContext context( nullptr );
@@ -285,6 +285,14 @@ void TestQgsLayoutUtils::createRenderContextFromLayout()
QVERIFY( ( rc.flags() & QgsRenderContext::UseAdvancedEffects ) );
QVERIFY( ( rc.flags() & QgsRenderContext::ForceVectorOutput ) );

// check text format is correctly set
l.renderContext().setTextRenderFormat( QgsRenderContext::TextFormatAlwaysOutlines );
rc = QgsLayoutUtils::createRenderContextForLayout( &l, nullptr );
QCOMPARE( rc.textRenderFormat(), QgsRenderContext::TextFormatAlwaysOutlines );
l.renderContext().setTextRenderFormat( QgsRenderContext::TextFormatAlwaysText );
rc = QgsLayoutUtils::createRenderContextForLayout( &l, nullptr );
QCOMPARE( rc.textRenderFormat(), QgsRenderContext::TextFormatAlwaysText );

p.end();
}

@@ -340,23 +348,31 @@ void TestQgsLayoutUtils::createRenderContextFromMap()

// check render context flags are correctly set
l.renderContext().setFlags( nullptr );
rc = QgsLayoutUtils::createRenderContextForLayout( &l, nullptr );
rc = QgsLayoutUtils::createRenderContextForMap( map2, &p );
QVERIFY( !( rc.flags() & QgsRenderContext::Antialiasing ) );
QVERIFY( !( rc.flags() & QgsRenderContext::UseAdvancedEffects ) );
QVERIFY( ( rc.flags() & QgsRenderContext::ForceVectorOutput ) );

l.renderContext().setFlag( QgsLayoutRenderContext::FlagAntialiasing );
rc = QgsLayoutUtils::createRenderContextForLayout( &l, nullptr );
rc = QgsLayoutUtils::createRenderContextForMap( map2, &p );
QVERIFY( ( rc.flags() & QgsRenderContext::Antialiasing ) );
QVERIFY( !( rc.flags() & QgsRenderContext::UseAdvancedEffects ) );
QVERIFY( ( rc.flags() & QgsRenderContext::ForceVectorOutput ) );

l.renderContext().setFlag( QgsLayoutRenderContext::FlagUseAdvancedEffects );
rc = QgsLayoutUtils::createRenderContextForLayout( &l, nullptr );
rc = QgsLayoutUtils::createRenderContextForMap( map2, &p );
QVERIFY( ( rc.flags() & QgsRenderContext::Antialiasing ) );
QVERIFY( ( rc.flags() & QgsRenderContext::UseAdvancedEffects ) );
QVERIFY( ( rc.flags() & QgsRenderContext::ForceVectorOutput ) );

// check text format is correctly set
l.renderContext().setTextRenderFormat( QgsRenderContext::TextFormatAlwaysOutlines );
rc = QgsLayoutUtils::createRenderContextForMap( map2, &p );
QCOMPARE( rc.textRenderFormat(), QgsRenderContext::TextFormatAlwaysOutlines );
l.renderContext().setTextRenderFormat( QgsRenderContext::TextFormatAlwaysText );
rc = QgsLayoutUtils::createRenderContextForMap( map2, &p );
QCOMPARE( rc.textRenderFormat(), QgsRenderContext::TextFormatAlwaysText );

p.end();
}

0 comments on commit 6755cbd

Please sign in to comment.
You can’t perform that action at this time.