Skip to content

Commit 6d2ab9e

Browse files
authoredOct 10, 2016
Merge pull request #3582 from fritsvanveen/fix_illegible_labels
Fix illegible labels
2 parents 6fd5815 + 12a8891 commit 6d2ab9e

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed
 

‎src/core/pal/feature.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,19 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition* >& lPos,
11701170
return 0;
11711171
}
11721172

1173+
//calculate overall angle of line
1174+
double lineAngle;
1175+
double bx = mapShape->x[0];
1176+
double by = mapShape->y[0];
1177+
double ex = mapShape->x[ mapShape->nbPoints - 1 ];
1178+
double ey = mapShape->y[ mapShape->nbPoints - 1 ];
1179+
if ( qgsDoubleNear( ey, by ) && qgsDoubleNear( ex, bx ) )
1180+
{
1181+
lineAngle = 0.0;
1182+
}
1183+
else
1184+
lineAngle = atan2( ey - by, ex - bx );
1185+
11731186
QLinkedList<LabelPosition*> positions;
11741187
double delta = qMax( li->label_height, total_distance / mLF->layer()->pal->line_p );
11751188

@@ -1178,7 +1191,7 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition* >& lPos,
11781191
flags = FLAG_ON_LINE; // default flag
11791192

11801193
// generate curved labels
1181-
for ( int i = 0; i * delta < total_distance; i++ )
1194+
for ( double i = 0; i < total_distance; i += delta )
11821195
{
11831196
bool flip = false;
11841197
// placements may need to be reversed if using map orientation and the line has right-to-left direction
@@ -1193,7 +1206,7 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition* >& lPos,
11931206
orientation = 1;
11941207
}
11951208

1196-
LabelPosition* slp = curvedPlacementAtOffset( mapShape, path_distances, orientation, 1, i * delta, reversed, flip );
1209+
LabelPosition* slp = curvedPlacementAtOffset( mapShape, path_distances, orientation, 1, i, reversed, flip );
11971210
if ( slp == nullptr )
11981211
continue;
11991212

@@ -1205,7 +1218,7 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition* >& lPos,
12051218
{
12061219
delete slp;
12071220
orientation = -orientation;
1208-
slp = curvedPlacementAtOffset( mapShape, path_distances, orientation, 1, i * delta, reversed, flip );
1221+
slp = curvedPlacementAtOffset( mapShape, path_distances, orientation, 1, i, reversed, flip );
12091222
}
12101223
}
12111224
if ( slp == nullptr )
@@ -1236,7 +1249,7 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition* >& lPos,
12361249
if ( cost < 0.0001 ) cost = 0.0001;
12371250

12381251
// penalize positions which are further from the line's midpoint
1239-
double labelCenter = ( i * delta ) + getLabelWidth() / 2;
1252+
double labelCenter = i + getLabelWidth() / 2;
12401253
double costCenter = qAbs( total_distance / 2 - labelCenter ) / total_distance; // <0, 0.5>
12411254
cost += costCenter / 1000; // < 0, 0.0005 >
12421255
slp->setCost( cost );
@@ -1753,7 +1766,7 @@ bool FeaturePart::showUprightLabels() const
17531766
return uprightLabel;
17541767
}
17551768

1756-
bool FeaturePart::nextCharPosition( int charWidth, double segment_length, PointSet* path_positions, int& index, double& distance,
1769+
bool FeaturePart::nextCharPosition( double charWidth, double segment_length, PointSet* path_positions, int& index, double& distance,
17571770
double& start_x, double& start_y, double& end_x, double& end_y ) const
17581771
{
17591772
// Coordinates this character will start at

‎src/core/pal/feature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ namespace pal
271271
bool showUprightLabels() const;
272272

273273
//! Returns true if the next char position is found. The referenced parameters are updated.
274-
bool nextCharPosition( int charWidth, double segment_length, PointSet* path_positions, int& index, double& distance,
274+
bool nextCharPosition( double charWidth, double segment_length, PointSet* path_positions, int& index, double& distance,
275275
double& start_x, double& start_y, double& end_x, double& end_y ) const;
276276

277277
protected:

0 commit comments

Comments
 (0)
Please sign in to comment.