libosmscout 0.1
Loading...
Searching...
No Matches
osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter > Class Template Reference

#include <LabelLayouter.h>

Classes

struct  LayoutJob
 Layout job initializes separate canvases for icons/symbols, labels and overlay labels. More...
 

Public Types

using ContourLabelType = ContourLabel< NativeGlyph >
 
using LabelInstanceType = LabelInstance< NativeGlyph, NativeLabel >
 
using LabelPtr = std::shared_ptr< LabelType >
 
using LabelType = Label< NativeGlyph, NativeLabel >
 

Public Member Functions

void AssertElementsInsideReach (const Projection &projection, const MapParameter &parameter, const Vertex2D &point, const std::vector< LabelData > &data, const LabelInstanceType &instance) const
 Debug check of the conservative bound the early decision uses: the rectangle of every element a label built has to stay inside the anchor plus the reach of the label.
 
bool CannotReachViewport (const Projection &projection, const MapParameter &parameter, const Vertex2D &point, const LabelData &data) const
 
bool CannotReachViewport (const Projection &projection, const MapParameter &parameter, const Vertex2D &point, const std::vector< LabelData > &data) const
 Returns true when no element of the label can intersect the layout viewport and when the label cannot suppress a label inside it, i.e.
 
const std::vector< ContourLabelType > & ContourLabels () const
 
template<class Painter >
void DrawLabels (const Projection &projection, const MapParameter &parameter, Painter *p)
 
template<class Painter >
void DrawTextLabels (const Projection &, const MapParameter &, Painter *) const
 
size_t GetGlyphCount () const
 Return the number of remembered measurements whose glyph data has been derived.
 
size_t GetMaxMeasurementCount () const
 Return the number of label measurements that are remembered at most.
 
size_t GetMeasurementCount () const
 Return the number of label measurements that are remembered at the moment.
 
 LabelLayouter (TextLayouter *textLayouter, size_t maxMeasurementCount=defaultMeasurementCount)
 
double LabelReach (const Projection &projection, const MapParameter &parameter, const std::vector< LabelData > &data) const
 Upper bound [pixels] of the distance the elements of a label can reach from the anchor position of that label: the measured rectangle of an element stays inside the anchor plus this distance, and the overlap canvases of the layout mark an element with the widest padding of the frame around that rectangle.
 
const std::vector< LabelInstanceType > & Labels () const
 
void Layout (const Projection &projection, const MapParameter &parameter)
 
void ProcessLabel (const Projection &projection, const MapParameter &parameter, const Vertex2D &point, LabelInstanceType &instance, double &offset, const LabelData &data, double objectWidth)
 
void RegisterContourLabel (const Projection &projection, const MapParameter &parameter, bool basemap, const ObjectFileRef &ref, const PathLabelData &labelData, const LabelPath &labelPath)
 
void RegisterLabel (const Projection &projection, const MapParameter &parameter, bool basemap, const ObjectFileRef &ref, const Vertex2D &point, const LabelData &data, double objectWidth=10.0)
 
void RegisterLabel (const Projection &projection, const MapParameter &parameter, bool basemap, const ObjectFileRef &ref, const Vertex2D &point, const std::vector< LabelData > &data, double objectWidth=10.0)
 
void Reset ()
 
void SetLayoutOverlap (uint32_t overlap)
 
void SetMeasurementEnvironment (const std::string &environment)
 Set the measurement environment the measurements of the following frame are made in: the state a backend's measurements depend on that is not an argument of Layout() - the resolved font, the resolution of the drawing target, its font settings.
 
void SetViewport (const ScreenVectorRectangle &v)
 

Static Public Member Functions

static bool IsOverlay (const LabelData &labelData)
 

Static Public Attributes

static constexpr size_t defaultMeasurementCount =4096
 Number of label measurements a layouter remembers by default.
 

Detailed Description

template<class NativeGlyph, class NativeLabel, class TextLayouter>
class osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >
Template Parameters
NativeGlyph
NativeLabel
TextLayouter- class providing low level text layouting required methods:

// glyph bounding box relative to its base point DoubleScreenRectangle GlyphBoundingBox(const NativeGlyph &) const

// layout text for label std::shared_ptr<Label<NativeGlyph, NativeLabel>> Layout( const Projection& projection, const MapParameter& parameter, const std::string& text, double fontSize, double objectWidth, bool enableWrapping = false, bool contourLabel = false);

Member Typedef Documentation

◆ ContourLabelType

template<class NativeGlyph , class NativeLabel , class TextLayouter >
using osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::ContourLabelType = ContourLabel<NativeGlyph>

◆ LabelInstanceType

template<class NativeGlyph , class NativeLabel , class TextLayouter >
using osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::LabelInstanceType = LabelInstance<NativeGlyph, NativeLabel>

◆ LabelPtr

template<class NativeGlyph , class NativeLabel , class TextLayouter >
using osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::LabelPtr = std::shared_ptr<LabelType>

◆ LabelType

template<class NativeGlyph , class NativeLabel , class TextLayouter >
using osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::LabelType = Label<NativeGlyph, NativeLabel>

Constructor & Destructor Documentation

◆ LabelLayouter()

template<class NativeGlyph , class NativeLabel , class TextLayouter >
osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::LabelLayouter ( TextLayouter *  textLayouter,
size_t  maxMeasurementCount = defaultMeasurementCount 
)
inlineexplicit

Member Function Documentation

◆ AssertElementsInsideReach()

template<class NativeGlyph , class NativeLabel , class TextLayouter >
void osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::AssertElementsInsideReach ( const Projection &  projection,
const MapParameter &  parameter,
const Vertex2D &  point,
const std::vector< LabelData > &  data,
const LabelInstanceType &  instance 
) const
inline

Debug check of the conservative bound the early decision uses: the rectangle of every element a label built has to stay inside the anchor plus the reach of the label.

If an element could leave that box, the early decision could drop a label that the drawing path of the label stage would draw, which would change the rendered output.

References osmscout::Vertex2D::GetX(), osmscout::Vertex2D::GetY(), osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::LabelReach(), and osmscout::LabelData::Text.

Referenced by osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::RegisterLabel(), and osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::RegisterLabel().

◆ CannotReachViewport() [1/2]

template<class NativeGlyph , class NativeLabel , class TextLayouter >
bool osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::CannotReachViewport ( const Projection &  projection,
const MapParameter &  parameter,
const Vertex2D &  point,
const LabelData &  data 
) const
inline

◆ CannotReachViewport() [2/2]

template<class NativeGlyph , class NativeLabel , class TextLayouter >
bool osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::CannotReachViewport ( const Projection &  projection,
const MapParameter &  parameter,
const Vertex2D &  point,
const std::vector< LabelData > &  data 
) const
inline

Returns true when no element of the label can intersect the layout viewport and when the label cannot suppress a label inside it, i.e.

when the label provably has no effect on the frame and does not have to be measured, stored or laid out.

References osmscout::Vertex2D::GetX(), osmscout::Vertex2D::GetY(), osmscout::ScreenVectorRectangle::Intersects(), and osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::LabelReach().

Referenced by osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::CannotReachViewport(), osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::RegisterLabel(), and osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::RegisterLabel().

◆ ContourLabels()

template<class NativeGlyph , class NativeLabel , class TextLayouter >
const std::vector< ContourLabelType > & osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::ContourLabels ( ) const
inline

◆ DrawLabels()

template<class NativeGlyph , class NativeLabel , class TextLayouter >
template<class Painter >
void osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::DrawLabels ( const Projection &  projection,
const MapParameter &  parameter,
Painter *  p 
)
inline
Template Parameters
Painterrequired methods:
void DrawSymbol(const Projection& projection,
                const MapParameter& parameter,
                onst Symbol& symbol,
                double x, double y) override;

void DrawIcon(const IconStyle* style,
              double centerX, double centerY,
              double width, double height) override;

void DrawLabel(const Projection& projection,
               const MapParameter& parameter,
               const DoubleScreenRectangle& labelRectangle,
               const LabelData& label,
               const std::shared_ptr<NativeLabel>& layout);

void DrawGlyphs(const Projection &projection,
                const MapParameter &parameter,
                const osmscout::PathTextStyleRef style,
                const std::vector<Glyph<NativeGlyph>> &glyphs);
Parameters
projection
parameter
p- painter pointer

References osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::ContourLabels(), osmscout::LabelData::Icon, osmscout::ScreenVectorRectangle::Intersects(), osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::IsOverlay(), osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::Labels(), osmscout::ScreenVectorRectangle::Set(), osmscout::LabelData::Symbol, and osmscout::LabelData::Text.

Referenced by osmscout::MapPainterAgg::DrawLabels(), osmscout::MapPainterCairo::DrawLabels(), osmscout::MapPainterQt::DrawLabels(), and osmscout::MapPainterSVG::DrawLabels().

◆ DrawTextLabels()

template<class NativeGlyph , class NativeLabel , class TextLayouter >
template<class Painter >
void osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::DrawTextLabels ( const Projection &  ,
const MapParameter &  ,
Painter *   
) const
inline

◆ GetGlyphCount()

template<class NativeGlyph , class NativeLabel , class TextLayouter >
size_t osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::GetGlyphCount ( ) const
inline

Return the number of remembered measurements whose glyph data has been derived.

◆ GetMaxMeasurementCount()

template<class NativeGlyph , class NativeLabel , class TextLayouter >
size_t osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::GetMaxMeasurementCount ( ) const
inline

Return the number of label measurements that are remembered at most.

◆ GetMeasurementCount()

template<class NativeGlyph , class NativeLabel , class TextLayouter >
size_t osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::GetMeasurementCount ( ) const
inline

Return the number of label measurements that are remembered at the moment.

◆ IsOverlay()

◆ LabelReach()

template<class NativeGlyph , class NativeLabel , class TextLayouter >
double osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::LabelReach ( const Projection &  projection,
const MapParameter &  parameter,
const std::vector< LabelData > &  data 
) const
inline

Upper bound [pixels] of the distance the elements of a label can reach from the anchor position of that label: the measured rectangle of an element stays inside the anchor plus this distance, and the overlap canvases of the layout mark an element with the widest padding of the frame around that rectangle.

A label that is farther away from the layout viewport than this bound can therefore be dropped before it is measured, without changing which labels the drawing path draws and which labels the layout suppresses.

The bound is summed over the elements, because the elements of a label are stacked at its anchor, and it uses the conservative label extent bound of the label helper for text elements.

References osmscout::Projection::ConvertWidthToPixel(), osmscout::CountLabelWords(), osmscout::MapParameter::GetFontSize(), osmscout::GetLabelExtentBound(), osmscout::GetMaxLabelPaddingPixel(), and osmscout::LabelData::Text.

Referenced by osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::AssertElementsInsideReach(), and osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::CannotReachViewport().

◆ Labels()

template<class NativeGlyph , class NativeLabel , class TextLayouter >
const std::vector< LabelInstanceType > & osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::Labels ( ) const
inline

◆ Layout()

◆ ProcessLabel()

◆ RegisterContourLabel()

template<class NativeGlyph , class NativeLabel , class TextLayouter >
void osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::RegisterContourLabel ( const Projection &  projection,
const MapParameter &  parameter,
bool  basemap,
const ObjectFileRef &  ref,
const PathLabelData &  labelData,
const LabelPath &  labelPath 
)
inline

◆ RegisterLabel() [1/2]

◆ RegisterLabel() [2/2]

template<class NativeGlyph , class NativeLabel , class TextLayouter >
void osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::RegisterLabel ( const Projection &  projection,
const MapParameter &  parameter,
bool  basemap,
const ObjectFileRef &  ref,
const Vertex2D &  point,
const std::vector< LabelData > &  data,
double  objectWidth = 10.0 
)
inline

◆ Reset()

template<class NativeGlyph , class NativeLabel , class TextLayouter >
void osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::Reset ( )
inline

◆ SetLayoutOverlap()

◆ SetMeasurementEnvironment()

template<class NativeGlyph , class NativeLabel , class TextLayouter >
void osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::SetMeasurementEnvironment ( const std::string &  environment)
inline

Set the measurement environment the measurements of the following frame are made in: the state a backend's measurements depend on that is not an argument of Layout() - the resolved font, the resolution of the drawing target, its font settings.

A backend calls this once per frame, before it registers labels. While the environment is unchanged the measurements of earlier frames stay valid; when it changes they are dropped, because the backend would measure them differently now.

A backend that never sets an environment has an empty one, which means that its measurements depend on the arguments of Layout() alone.

Referenced by osmscout::MapPainterAgg::DrawMap(), osmscout::MapPainterCairo::DrawMap(), osmscout::MapPainterQt::DrawMap(), and osmscout::MapPainterSVG::DrawMap().

◆ SetViewport()

Member Data Documentation

◆ defaultMeasurementCount

template<class NativeGlyph , class NativeLabel , class TextLayouter >
constexpr size_t osmscout::LabelLayouter< NativeGlyph, NativeLabel, TextLayouter >::defaultMeasurementCount =4096
staticconstexpr

Number of label measurements a layouter remembers by default.

The bound exists so that a long pan session does not accumulate the measurements of every label ever seen; it is far above the label count of a typical view.


The documentation for this class was generated from the following file: