Skip to content

Commit

Permalink
Merge pull request #1136 from Framstag/issue_1045_2
Browse files Browse the repository at this point in the history
Further clean ups and preperation for further cleanups.
  • Loading branch information
Framstag authored Oct 14, 2021
2 parents 4cbdf13 + d891afb commit 4049f28
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 130 deletions.
2 changes: 1 addition & 1 deletion libosmscout-map-qt/src/osmscout/MapPainterQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ namespace osmscout {
const MapParameter& parameter,
const MapData& /*data*/)
{
if (delegateLabelLayouter){
if (delegateLabelLayouter !=nullptr){
return;
}

Expand Down
104 changes: 71 additions & 33 deletions libosmscout-map/include/osmscoutmap/LabelLayouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,47 +606,85 @@ namespace osmscout {
}
}

// should be made private
void ProcessLabel(const Projection& projection,
const MapParameter& parameter,
const Vertex2D& point,
LabelInstanceType& instance,
double& offset,
const LabelData& data,
double objectWidth)
{
typename LabelInstance<NativeGlyph, NativeLabel>::Element element;
element.labelData=data;
if (data.type==LabelData::Type::Icon || data.type==LabelData::Type::Symbol){
instance.priority = std::min(data.priority, instance.priority);
element.x = point.GetX() - data.iconWidth / 2;
if (offset<0){
element.y = point.GetY() - data.iconHeight / 2;
offset = point.GetY() + data.iconHeight / 2;
} else {
element.y = offset;
offset += data.iconHeight;
}
}else {
instance.priority = std::min(data.priority, instance.priority);
// TODO: should we take style into account?
// Qt allows to split text layout and style setup
element.label = textLayouter->Layout(projection, parameter,
data.text, data.fontSize,
objectWidth,
/*enable wrapping*/ true,
/*contour label*/ false);
element.x = point.GetX() - element.label->width / 2;
if (offset<0){
element.y = point.GetY() - element.label->height / 2;
offset = point.GetY() + element.label->height / 2;
} else {
element.y = offset;
offset += element.label->height;
}
}
instance.elements.push_back(element);
}

void RegisterLabel(const Projection& projection,
const MapParameter& parameter,
const Vertex2D& point,
const std::vector<LabelData> &data,
const LabelData& data,
double objectWidth = 10.0)
{
LabelInstanceType instance;

double offset=-1;
for (const auto &d:data) {
typename LabelInstance<NativeGlyph, NativeLabel>::Element element;
element.labelData=d;
if (d.type==LabelData::Type::Icon || d.type==LabelData::Type::Symbol){
instance.priority = std::min(d.priority, instance.priority);
element.x = point.GetX() - d.iconWidth / 2;
if (offset<0){
element.y = point.GetY() - d.iconHeight / 2;
offset = point.GetY() + d.iconHeight / 2;
} else {
element.y = offset;
offset += d.iconHeight;
}
}else {
instance.priority = std::min(d.priority, instance.priority);
// TODO: should we take style into account?
// Qt allows to split text layout and style setup
element.label = textLayouter->Layout(projection, parameter,
d.text, d.fontSize,
objectWidth,
/*enable wrapping*/ true,
/*contour label*/ false);
element.x = point.GetX() - element.label->width / 2;
if (offset<0){
element.y = point.GetY() - element.label->height / 2;
offset = point.GetY() + element.label->height / 2;
} else {
element.y = offset;
offset += element.label->height;
}
}
instance.elements.push_back(element);
ProcessLabel(projection,
parameter,
point,
instance,
offset,
data,
objectWidth);

labelInstances.push_back(instance);
}

void RegisterLabel(const Projection& projection,
const MapParameter& parameter,
const Vertex2D& point,
const std::vector<LabelData>& data,
double objectWidth = 10.0)
{
LabelInstanceType instance;

double offset=-1;
for (const auto& d : data) {
ProcessLabel(projection,
parameter,
point,
instance,
offset,
d,
objectWidth);
}

labelInstances.push_back(instance);
Expand Down
6 changes: 0 additions & 6 deletions libosmscout-map/include/osmscoutmap/MapPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,6 @@ namespace osmscout {
const GeoBox& boundingBox,
double pixelOffset) const;

void Transform(const Projection& projection,
const MapParameter& parameter,
const GeoCoord& coord,
double& x,
double& y) const;

double GetProjectedWidth(const Projection& projection,
double minPixel,
double width) const;
Expand Down
12 changes: 12 additions & 0 deletions libosmscout-map/include/osmscoutmap/Styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ namespace osmscout {
sidecar //!< special offset for routes, line are stacked next to way, same colors are "collapsed"
};

extern bool IsLaneOffset(OffsetRel rel);

/**
* \ingroup Stylesheet
*
Expand Down Expand Up @@ -1283,11 +1285,21 @@ namespace osmscout {
return symbolSpace;
}

bool HasDisplayOffset() const
{
return displayOffset!=0.0;
}

double GetDisplayOffset() const
{
return displayOffset;
}

bool HasOffset() const
{
return offset!=0.0;
}

double GetOffset() const
{
return offset;
Expand Down
Loading

0 comments on commit 4049f28

Please sign in to comment.