Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Push text format setting to layout render context
(cherry picked from commit 6a131bb)
  • Loading branch information
nyalldawson committed Dec 11, 2018
1 parent 7c5a74d commit 8053198
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
18 changes: 18 additions & 0 deletions python/core/auto_generated/layout/qgslayoutrendercontext.sip.in
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutitemmap.cpp
Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions src/core/layout/qgslayoutrendercontext.h
Expand Up @@ -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:

/**
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgslayoututils.cpp
Expand Up @@ -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;
}
}
Expand All @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/src/core/testqgslayoutcontext.cpp
Expand Up @@ -43,6 +43,7 @@ class TestQgsLayoutContext: public QObject
void layer();
void dpi();
void renderContextFlags();
void textFormat();
void boundingBoxes();
void exportLayer();
void geometry();
Expand Down Expand Up @@ -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 );
Expand Down
22 changes: 19 additions & 3 deletions tests/src/core/testqgslayoututils.cpp
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 8053198

Please sign in to comment.