mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Followup 2dc5d95, add unit tests
This commit is contained in:
parent
680b1ced70
commit
51bd0b2bc5
@ -772,6 +772,15 @@ class QgsPalLabeling : QgsLabelingEngineInterface
|
||||
* @note added in QGIS 2.9
|
||||
*/
|
||||
static QStringList splitToLines( const QString& text, const QString& wrapCharacter );
|
||||
|
||||
/** Splits a text string to a list of graphemes, which are the smallest allowable character
|
||||
* divisions in the string. This accounts for scripts were individual characters are not
|
||||
* allowed to be split apart (eg Arabic and Indic based scripts)
|
||||
* @param text string to split
|
||||
* @returns list of graphemes
|
||||
* @note added in QGIS 2.10
|
||||
*/
|
||||
static QStringList splitToGraphemes( const QString& text );
|
||||
|
||||
protected:
|
||||
// update temporary QgsPalLayerSettings with any data defined text style values
|
||||
|
@ -2,9 +2,9 @@
|
||||
#define QGSPALGEOMETRY_H
|
||||
|
||||
#include "qgsgeometry.h"
|
||||
#include "qgspallabeling.h"
|
||||
#include <pal/feature.h>
|
||||
#include <pal/palgeometry.h>
|
||||
#include <QTextBoundaryFinder>
|
||||
|
||||
using namespace pal;
|
||||
|
||||
@ -90,14 +90,7 @@ class QgsPalGeometry : public PalGeometry
|
||||
qreal wordSpaceFix;
|
||||
|
||||
//split string by valid grapheme boundaries - required for certain scripts (see #6883)
|
||||
QTextBoundaryFinder boundaryFinder( QTextBoundaryFinder::Grapheme, mText );
|
||||
int currentBoundary = -1;
|
||||
int previousBoundary = 0;
|
||||
while (( currentBoundary = boundaryFinder.toNextBoundary() ) > 0 )
|
||||
{
|
||||
mClusters << mText.mid( previousBoundary, currentBoundary - previousBoundary );
|
||||
previousBoundary = currentBoundary;
|
||||
}
|
||||
mClusters = QgsPalLabeling::splitToGraphemes( mText );
|
||||
|
||||
mInfo = new pal::LabelInfo( mClusters.count(), labelHeight, maxinangle, maxoutangle );
|
||||
for ( int i = 0; i < mClusters.count(); i++ )
|
||||
|
@ -3412,6 +3412,20 @@ QStringList QgsPalLabeling::splitToLines( const QString &text, const QString &wr
|
||||
return multiLineSplit;
|
||||
}
|
||||
|
||||
QStringList QgsPalLabeling::splitToGraphemes( const QString &text )
|
||||
{
|
||||
QStringList graphemes;
|
||||
QTextBoundaryFinder boundaryFinder( QTextBoundaryFinder::Grapheme, text );
|
||||
int currentBoundary = -1;
|
||||
int previousBoundary = 0;
|
||||
while (( currentBoundary = boundaryFinder.toNextBoundary() ) > 0 )
|
||||
{
|
||||
graphemes << text.mid( previousBoundary, currentBoundary - previousBoundary );
|
||||
previousBoundary = currentBoundary;
|
||||
}
|
||||
return graphemes;
|
||||
}
|
||||
|
||||
QgsGeometry* QgsPalLabeling::prepareGeometry( const QgsGeometry* geometry, const QgsRenderContext& context, const QgsCoordinateTransform* ct, double minSize, QgsGeometry* clipGeometry )
|
||||
{
|
||||
if ( !geometry )
|
||||
|
@ -843,6 +843,15 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
|
||||
*/
|
||||
static QStringList splitToLines( const QString& text, const QString& wrapCharacter );
|
||||
|
||||
/** Splits a text string to a list of graphemes, which are the smallest allowable character
|
||||
* divisions in the string. This accounts for scripts were individual characters are not
|
||||
* allowed to be split apart (eg Arabic and Indic based scripts)
|
||||
* @param text string to split
|
||||
* @returns list of graphemes
|
||||
* @note added in QGIS 2.10
|
||||
*/
|
||||
static QStringList splitToGraphemes( const QString& text );
|
||||
|
||||
protected:
|
||||
// update temporary QgsPalLayerSettings with any data defined text style values
|
||||
void dataDefinedTextStyle( QgsPalLayerSettings& tmpLyr,
|
||||
|
@ -30,6 +30,7 @@ class TestQgsPalLabeling: public QObject
|
||||
void init();// will be called before each testfunction is executed.
|
||||
void cleanup();// will be called after every testfunction.
|
||||
void wrapChar();//test wrapping text lines
|
||||
void graphemes(); //test splitting strings to graphemes
|
||||
|
||||
private:
|
||||
};
|
||||
@ -63,5 +64,19 @@ void TestQgsPalLabeling::wrapChar()
|
||||
QCOMPARE( QgsPalLabeling::splitToLines( "no\nmatching\nchars", QString( "#" ) ), QStringList() << "no" << "matching" << "chars" );
|
||||
}
|
||||
|
||||
void TestQgsPalLabeling::graphemes()
|
||||
{
|
||||
QCOMPARE( QgsPalLabeling::splitToGraphemes( QString() ) , QStringList() );
|
||||
QCOMPARE( QgsPalLabeling::splitToGraphemes( "abcd" ) , QStringList() << "a" << "b" << "c" << "d" );
|
||||
QCOMPARE( QgsPalLabeling::splitToGraphemes( "ab cd" ) , QStringList() << "a" << "b" << " " << "c" << "d" );
|
||||
QCOMPARE( QgsPalLabeling::splitToGraphemes( "ab cd " ) , QStringList() << "a" << "b" << " " << "c" << "d" << " " );
|
||||
QCOMPARE( QgsPalLabeling::splitToGraphemes( QString::fromUtf8( "\u179F\u17D2\u178F\u17D2\u179A\u17B8\u179B\u17D2" ) ) , QStringList() << QString::fromUtf8( "\u179F\u17D2\u178F\u17D2\u179A\u17B8" ) << QString::fromUtf8( "\u179B\u17D2" ) );
|
||||
QCOMPARE( QgsPalLabeling::splitToGraphemes( QString::fromUtf8( "\u1780\u17D2\u179A\u17BB\u1798\u17A2\u1784\u17D2\u1782\u1780\u17B6\u179A\u179F\u17B7\u1791\u17D2\u1792\u17B7\u1798\u1793\u17BB\u179F\u17D2\u179F" ) ) ,
|
||||
QStringList() << QString::fromUtf8( "\u1780\u17D2\u179A\u17BB" ) << QString::fromUtf8( "\u1798" ) << QString::fromUtf8( "\u17A2" )
|
||||
<< QString::fromUtf8( "\u1784\u17D2\u1782" ) << QString::fromUtf8( "\u1780\u17B6" ) << QString::fromUtf8( "\u179A" )
|
||||
<< QString::fromUtf8( "\u179F\u17B7" ) << QString::fromUtf8( "\u1791\u17D2\u1792\u17B7" ) << QString::fromUtf8( "\u1798" )
|
||||
<< QString::fromUtf8( "\u1793\u17BB" ) << QString::fromUtf8( "\u179F\u17D2\u179F" ) );
|
||||
}
|
||||
|
||||
QTEST_MAIN( TestQgsPalLabeling )
|
||||
#include "testqgspallabeling.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user