Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #3712 from nirvn/pal_zero_width_char_fix
[pal] fix curved labels failure with zero-width characters
  • Loading branch information
nyalldawson committed Nov 3, 2016
2 parents 9cd29f3 + 769c82b commit 777fc86
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/core/pal/feature.cpp
Expand Up @@ -1059,6 +1059,10 @@ LabelPosition* FeaturePart::curvedPlacementAtOffset( PointSet* path_positions, d

// grab the next character according to the orientation
LabelInfo::CharacterInfo& ci = ( orientation > 0 ? li->char_info[i] : li->char_info[li->char_num-i-1] );
if ( qgsDoubleNear( ci.width, 0.0 ) )
// Certain scripts rely on zero-width character, skip those to prevent failure (see #15801)
continue;

double start_x, start_y, end_x, end_y;
if ( nextCharPosition( ci.width, path_distances[index], path_positions, index, distance, start_x, start_y, end_x, end_y ) == false )
{
Expand Down
12 changes: 12 additions & 0 deletions tests/src/python/test_qgspallabeling_placement.py
Expand Up @@ -433,6 +433,18 @@ def test_label_line_avoid_jaggy(self):
self.removeMapLayer(self.layer)
self.layer = None

def test_label_curved_zero_width_char(self):
# Test that curved label work with zero-width characters
self.layer = TestQgsPalLabeling.loadFeatureLayer('line')
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
self.lyr.placement = QgsPalLayerSettings.Curved
self.lyr.placementFlags = QgsPalLayerSettings.OnLine
self.lyr.fieldName = "'invisible​space'"
self.lyr.isExpression = True
self.checkTest()
self.removeMapLayer(self.layer)
self.layer = None

if __name__ == '__main__':
# NOTE: unless PAL_SUITE env var is set all test class methods will be run
# SEE: test_qgspallabeling_tests.suiteTests() to define suite
Expand Down
3 changes: 2 additions & 1 deletion tests/src/python/test_qgspallabeling_tests.py
Expand Up @@ -308,8 +308,9 @@ def test_curved_placement_below(self):
self.lyr.placementFlags = QgsPalLayerSettings.BelowLine | QgsPalLayerSettings.MapOrientation
self.checkTest()


# noinspection PyPep8Naming


def suiteTests():
"""
Use to define which tests are run when PAL_SUITE is set.
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 777fc86

Please sign in to comment.