mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-06 00:03:16 -05:00
Add a QgsStringUtils function to substitute characters with vertical representation counterparts
This commit is contained in:
parent
08c1df18de
commit
bdf18ee0fd
@ -275,6 +275,17 @@ the string will be wrapped so that each line will ideally exceed ``length`` of c
|
|||||||
A custom delimiter can be specified to use instead of space characters.
|
A custom delimiter can be specified to use instead of space characters.
|
||||||
|
|
||||||
.. versionadded:: 3.4
|
.. versionadded:: 3.4
|
||||||
|
%End
|
||||||
|
|
||||||
|
static QString substituteVerticalCharacters( QString string );
|
||||||
|
%Docstring
|
||||||
|
Returns a string with characters having vertical representation form substituted.
|
||||||
|
|
||||||
|
:param string: input string
|
||||||
|
|
||||||
|
:return: string with substition applied
|
||||||
|
|
||||||
|
.. versionadded:: 3.10
|
||||||
%End
|
%End
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -518,6 +518,28 @@ QString QgsStringUtils::wordWrap( const QString &string, const int length, const
|
|||||||
return newstr;
|
return newstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QgsStringUtils::substituteVerticalCharacters( QString string )
|
||||||
|
{
|
||||||
|
string = string.replace( ',', QChar( 65040 ) ).replace( QChar( 8229 ), QChar( 65072 ) ); // comma & two-dot leader
|
||||||
|
string = string.replace( QChar( 12289 ), QChar( 65041 ) ).replace( QChar( 12290 ), QChar( 65042 ) ); // ideographic comma & full stop
|
||||||
|
string = string.replace( ':', QChar( 65043 ) ).replace( ';', QChar( 65044 ) );
|
||||||
|
string = string.replace( '!', QChar( 65045 ) ).replace( '?', QChar( 65046 ) );
|
||||||
|
string = string.replace( QChar( 12310 ), QChar( 65047 ) ).replace( QChar( 12311 ), QChar( 65048 ) ); // white lenticular brackets
|
||||||
|
string = string.replace( QChar( 8230 ), QChar( 65049 ) ); // three-dot ellipse
|
||||||
|
string = string.replace( QChar( 8212 ), QChar( 65073 ) ).replace( QChar( 8211 ), QChar( 65074 ) ); // em & en dash
|
||||||
|
string = string.replace( '_', QChar( 65075 ) ).replace( QChar( 65103 ), QChar( 65076 ) ); // low line & wavy low line
|
||||||
|
string = string.replace( '(', QChar( 65077 ) ).replace( ')', QChar( 65078 ) );
|
||||||
|
string = string.replace( '{', QChar( 65079 ) ).replace( '}', QChar( 65080 ) );
|
||||||
|
string = string.replace( '<', QChar( 65087 ) ).replace( '>', QChar( 65088 ) );
|
||||||
|
string = string.replace( '[', QChar( 65095 ) ).replace( ']', QChar( 65096 ) );
|
||||||
|
string = string.replace( QChar( 12308 ), QChar( 65081 ) ).replace( QChar( 12309 ), QChar( 65082 ) ); // tortoise shell brackets
|
||||||
|
string = string.replace( QChar( 12304 ), QChar( 65083 ) ).replace( QChar( 12305 ), QChar( 65084 ) ); // black lenticular brackets
|
||||||
|
string = string.replace( QChar( 12298 ), QChar( 65085 ) ).replace( QChar( 12299 ), QChar( 65086 ) ); // double angle brackets
|
||||||
|
string = string.replace( QChar( 12300 ), QChar( 65089 ) ).replace( QChar( 12301 ), QChar( 65090 ) ); // corner brackets
|
||||||
|
string = string.replace( QChar( 12302 ), QChar( 65091 ) ).replace( QChar( 12303 ), QChar( 65092 ) ); // white corner brackets
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
QgsStringReplacement::QgsStringReplacement( const QString &match, const QString &replacement, bool caseSensitive, bool wholeWordOnly )
|
QgsStringReplacement::QgsStringReplacement( const QString &match, const QString &replacement, bool caseSensitive, bool wholeWordOnly )
|
||||||
: mMatch( match )
|
: mMatch( match )
|
||||||
, mReplacement( replacement )
|
, mReplacement( replacement )
|
||||||
|
|||||||
@ -275,6 +275,14 @@ class CORE_EXPORT QgsStringUtils
|
|||||||
* \since QGIS 3.4
|
* \since QGIS 3.4
|
||||||
*/
|
*/
|
||||||
static QString wordWrap( const QString &string, int length, bool useMaxLineLength = true, const QString &customDelimiter = QString() );
|
static QString wordWrap( const QString &string, int length, bool useMaxLineLength = true, const QString &customDelimiter = QString() );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string with characters having vertical representation form substituted.
|
||||||
|
* \param string input string
|
||||||
|
* \returns string with substition applied
|
||||||
|
* \since QGIS 3.10
|
||||||
|
*/
|
||||||
|
static QString substituteVerticalCharacters( QString string );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //QGSSTRINGUTILS_H
|
#endif //QGSSTRINGUTILS_H
|
||||||
|
|||||||
@ -3552,25 +3552,7 @@ void QgsTextRenderer::drawTextInternal( TextPart drawType,
|
|||||||
|
|
||||||
// apply some character replacement to draw symbols in vertical presentation
|
// apply some character replacement to draw symbols in vertical presentation
|
||||||
QString lines = textLines.join( '\n' );
|
QString lines = textLines.join( '\n' );
|
||||||
lines = lines.replace( ',', QChar( 65040 ) ).replace( QChar( 8229 ), QChar( 65072 ) ); // comma & two-dot leader
|
const auto constTextLines = QgsStringUtils::substituteVerticalCharacters( lines ).split( '\n' );
|
||||||
lines = lines.replace( QChar( 12289 ), QChar( 65041 ) ).replace( QChar( 12290 ), QChar( 65042 ) ); // ideographic comma & full stop
|
|
||||||
lines = lines.replace( ':', QChar( 65043 ) ).replace( ';', QChar( 65044 ) );
|
|
||||||
lines = lines.replace( '!', QChar( 65045 ) ).replace( '?', QChar( 65046 ) );
|
|
||||||
lines = lines.replace( QChar( 12310 ), QChar( 65047 ) ).replace( QChar( 12311 ), QChar( 65048 ) ); // white lenticular brackets
|
|
||||||
lines = lines.replace( QChar( 8230 ), QChar( 65049 ) ); // three-dot ellipse
|
|
||||||
lines = lines.replace( QChar( 8212 ), QChar( 65073 ) ).replace( QChar( 8211 ), QChar( 65074 ) ); // em & en dash
|
|
||||||
lines = lines.replace( '_', QChar( 65075 ) ).replace( QChar( 65103 ), QChar( 65076 ) ); // low line & wavy low line
|
|
||||||
lines = lines.replace( '(', QChar( 65077 ) ).replace( ')', QChar( 65078 ) );
|
|
||||||
lines = lines.replace( '{', QChar( 65079 ) ).replace( '}', QChar( 65080 ) );
|
|
||||||
lines = lines.replace( '<', QChar( 65087 ) ).replace( '>', QChar( 65088 ) );
|
|
||||||
lines = lines.replace( '[', QChar( 65095 ) ).replace( ']', QChar( 65096 ) );
|
|
||||||
lines = lines.replace( QChar( 12308 ), QChar( 65081 ) ).replace( QChar( 12309 ), QChar( 65082 ) ); // tortoise shell brackets
|
|
||||||
lines = lines.replace( QChar( 12304 ), QChar( 65083 ) ).replace( QChar( 12305 ), QChar( 65084 ) ); // black lenticular brackets
|
|
||||||
lines = lines.replace( QChar( 12298 ), QChar( 65085 ) ).replace( QChar( 12299 ), QChar( 65086 ) ); // double angle brackets
|
|
||||||
lines = lines.replace( QChar( 12300 ), QChar( 65089 ) ).replace( QChar( 12301 ), QChar( 65090 ) ); // corner brackets
|
|
||||||
lines = lines.replace( QChar( 12302 ), QChar( 65091 ) ).replace( QChar( 12303 ), QChar( 65092 ) ); // white corner brackets
|
|
||||||
|
|
||||||
const auto constTextLines = lines.split( '\n' );
|
|
||||||
for ( QString line : constTextLines )
|
for ( QString line : constTextLines )
|
||||||
{
|
{
|
||||||
context.painter()->save();
|
context.painter()->save();
|
||||||
|
|||||||
@ -175,6 +175,10 @@ class PyQgsStringUtils(unittest.TestCase):
|
|||||||
self.assertEqual(QgsStringUtils.capitalize(' testing abc', QgsStringUtils.ForceFirstLetterToCapital),
|
self.assertEqual(QgsStringUtils.capitalize(' testing abc', QgsStringUtils.ForceFirstLetterToCapital),
|
||||||
' Testing Abc')
|
' Testing Abc')
|
||||||
|
|
||||||
|
def testSubstituteVerticalCharacters(self):
|
||||||
|
""" test subsitute vertical characters """
|
||||||
|
self.assertEqual(QgsStringUtils.substituteVerticalCharacters('123{[(45654)]}321'), '123︷﹇︵45654︶﹈︸321')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user