Skip to content

Commit

Permalink
[labeling] Fix curved labels sometimes placed below line even when
Browse files Browse the repository at this point in the history
set to above line only

(cherry picked from commit 10c4bb9)
  • Loading branch information
nyalldawson committed Jun 3, 2019
1 parent e0b184e commit b52d2ad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/core/pal/feature.cpp
Expand Up @@ -1007,22 +1007,31 @@ LabelPosition *FeaturePart::curvedPlacementAtOffset( PointSet *path_positions, d
double _distance = distance;
int endindex = index;

double startLabelX = 0;
double startLabelY = 0;
double endLabelX = 0;
double endLabelY = 0;
for ( int i = 0; i < li->char_num; i++ )
{
LabelInfo::CharacterInfo &ci = li->char_info[i];
double start_x, start_y, end_x, end_y;
if ( !nextCharPosition( ci.width, path_distances[endindex], path_positions, endindex, _distance, start_x, start_y, end_x, end_y ) )
double start_x, start_y;
if ( !nextCharPosition( ci.width, path_distances[endindex], path_positions, endindex, _distance, start_x, start_y, endLabelX, endLabelY ) )
{
return nullptr;
}
if ( i == 0 )
{
startLabelX = start_x;
startLabelY = start_y;
}
}

// Determine the angle of the path segment under consideration
double dx = path_positions->x[endindex] - path_positions->x[index];
double dy = path_positions->y[endindex] - path_positions->y[index];
double line_angle = std::atan2( -dy, dx );
double dx = endLabelX - startLabelX;
double dy = endLabelY - startLabelY;
const double lineAngle = std::atan2( -dy, dx ) * 180 / M_PI;

bool isRightToLeft = ( line_angle > 0.55 * M_PI || line_angle < -0.45 * M_PI );
bool isRightToLeft = ( lineAngle > 90 || lineAngle < -90 );
reversed = isRightToLeft;
orientation = isRightToLeft ? -1 : 1;
}
Expand Down Expand Up @@ -1175,7 +1184,7 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition * > &lPos
QLinkedList<LabelPosition *> positions;
double delta = std::max( li->label_height, total_distance / mLF->layer()->pal->line_p );

unsigned long flags = mLF->layer()->arrangementFlags();
pal::LineArrangementFlags flags = mLF->layer()->arrangementFlags();
if ( flags == 0 )
flags = FLAG_ON_LINE; // default flag

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 b52d2ad

Please sign in to comment.