| 1 |
/* File: pencil_floating_label_layouter.h; Copyright and License: see below */ |
| 2 |
|
| 3 |
#ifndef PENCIL_FLOATING_LABEL_LAYOUTER_H |
| 4 |
#define PENCIL_FLOATING_LABEL_LAYOUTER_H |
| 5 |
|
| 6 |
/* public file for the doxygen documentation: */ |
| 7 |
/*! |
| 8 |
* \file |
| 9 |
* \brief Evaluates proposed label positions in a diagram |
| 10 |
*/ |
| 11 |
|
| 12 |
#include "draw/draw_relationship_label.h" |
| 13 |
#include "draw/draw_feature_label.h" |
| 14 |
#include "pencil_size.h" |
| 15 |
#include "layout/layout_visible_set.h" |
| 16 |
#include "geometry/geometry_rectangle.h" |
| 17 |
#include "geometry/geometry_dimensions.h" |
| 18 |
#include "geometry/geometry_anchor.h" |
| 19 |
|
| 20 |
/*! |
| 21 |
* \brief attributes of the floating label layout helper |
| 22 |
* |
| 23 |
* \note This class is not stateless. |
| 24 |
* This object is valid to layout one or more objects of layout_data onto a canvas for which font_layout is valid. |
| 25 |
* For other layout_data or other canvas, the object needs to be re-initialized. |
| 26 |
*/ |
| 27 |
struct pencil_floating_label_layouter_struct { |
| 28 |
layout_visible_set_t *layout_data; /*!< layout data of objects that are already (partly) layouted */ |
| 29 |
const data_profile_part_t *profile; /*!< profile-part that provides the stereotype definition of the element to be layouted */ |
| 30 |
const pencil_size_t *pencil_size; /*!< the pencil size proposes preferred distances */ |
| 31 |
PangoLayout *font_layout; /*!< pango layout object to determine the font metrics in the current cairo drawing context */ |
| 32 |
}; |
| 33 |
|
| 34 |
typedef struct pencil_floating_label_layouter_struct pencil_floating_label_layouter_t; |
| 35 |
|
| 36 |
/*! |
| 37 |
* \brief initializes the floating label layouter to void |
| 38 |
* |
| 39 |
* \param this_ pointer to own object attributes |
| 40 |
*/ |
| 41 |
void pencil_floating_label_layouter_init_void ( pencil_floating_label_layouter_t *this_ ); |
| 42 |
|
| 43 |
/*! |
| 44 |
* \brief re-initializes the floating label layouter to void |
| 45 |
* |
| 46 |
* \param this_ pointer to own object attributes |
| 47 |
*/ |
| 48 |
void pencil_floating_label_layouter_reinit_void ( pencil_floating_label_layouter_t *this_ ); |
| 49 |
|
| 50 |
/*! |
| 51 |
* \brief initializes the floating label layouter |
| 52 |
* |
| 53 |
* This object is valid to layout one or more objects of layout_data onto a canvas for which font_layout is valid. |
| 54 |
* For other layout_data or canvas, the object needs to be re-initialized. |
| 55 |
* |
| 56 |
* \param this_ pointer to own object attributes |
| 57 |
* \param layout_data data that is already (partly) layouted - by which to determine a suitable space |
| 58 |
* \param profile profile-part that provides the stereotype definition of the element to be layouted |
| 59 |
* \param pencil_size proposal for preferred distances |
| 60 |
* \param font_layout pango layout object to determine the font metrics in the current cairo drawing context |
| 61 |
*/ |
| 62 |
void pencil_floating_label_layouter_reinit ( pencil_floating_label_layouter_t *this_, |
| 63 |
layout_visible_set_t *layout_data, |
| 64 |
const data_profile_part_t *profile, |
| 65 |
const pencil_size_t *pencil_size, |
| 66 |
PangoLayout *font_layout |
| 67 |
); |
| 68 |
|
| 69 |
/*! |
| 70 |
* \brief destroys the floating label layouter |
| 71 |
* |
| 72 |
* \param this_ pointer to own object attributes |
| 73 |
*/ |
| 74 |
void pencil_floating_label_layouter_destroy ( pencil_floating_label_layouter_t *this_ ); |
| 75 |
|
| 76 |
/*! |
| 77 |
* \brief proposes one solution to layout a label rectangle for a layout_feature_t |
| 78 |
* |
| 79 |
* \param this_ pointer to own object attributes |
| 80 |
* \param anchor point where the object is located to which the label belongs |
| 81 |
* \param preferred_dim preferred dimension of the label in case there is enough space |
| 82 |
* \param draw_estimator drawing estimator that can estimate the drawing bounds given the available width |
| 83 |
* \param feature data that is already (partly) layouted - by which to select a solution |
| 84 |
* \param[out] out_solution a solution |
| 85 |
*/ |
| 86 |
void pencil_floating_label_layouter_propose_solution_feat ( const pencil_floating_label_layouter_t *this_, |
| 87 |
const geometry_anchor_t *anchor, |
| 88 |
const geometry_dimensions_t *preferred_dim, |
| 89 |
draw_feature_label_t *draw_estimator, |
| 90 |
const data_feature_t *feature, |
| 91 |
geometry_rectangle_t *out_solution |
| 92 |
); |
| 93 |
|
| 94 |
/*! |
| 95 |
* \brief proposes one solution to layout a label rectangle for a layout_relationship_t |
| 96 |
* |
| 97 |
* \param this_ pointer to own object attributes |
| 98 |
* \param anchor point where the object is located to which the label belongs |
| 99 |
* \param preferred_dim preferred dimension of the label in case there is enough space |
| 100 |
* \param draw_estimator drawing estimator that can estimate the drawing bounds given the available width |
| 101 |
* \param relation data that is already (partly) layouted - by which to select a solution |
| 102 |
* \param[out] out_solution a solution |
| 103 |
*/ |
| 104 |
void pencil_floating_label_layouter_propose_solution_rel ( const pencil_floating_label_layouter_t *this_, |
| 105 |
const geometry_anchor_t *anchor, |
| 106 |
const geometry_dimensions_t *preferred_dim, |
| 107 |
draw_relationship_label_t *draw_estimator, |
| 108 |
const data_relationship_t *relation, |
| 109 |
geometry_rectangle_t *out_solution |
| 110 |
); |
| 111 |
|
| 112 |
/*! |
| 113 |
* \brief proposes one solution to layout a label rectangle for a layout_feature_t or a layout_relationship_t |
| 114 |
* |
| 115 |
* \param this_ pointer to own object attributes |
| 116 |
* \param anchor point where the object is located to which the label belongs |
| 117 |
* \param preferred_dim preferred dimension of the label in case there is enough space |
| 118 |
* \param draw_estimator_feat drawing estimator that can estimate the drawing bounds given the available width or NULL |
| 119 |
* \param feature data that is already (partly) layouted - by which to select a solution or NULL |
| 120 |
* \param draw_estimator_rel drawing estimator that can estimate the drawing bounds given the available width or NULL |
| 121 |
* \param relation data that is already (partly) layouted - by which to select a solution or NULL |
| 122 |
* \param[out] out_solution a solution |
| 123 |
*/ |
| 124 |
static inline void pencil_floating_label_layouter_private_propose_solution ( const pencil_floating_label_layouter_t *this_, |
| 125 |
const geometry_anchor_t *anchor, |
| 126 |
const geometry_dimensions_t *preferred_dim, |
| 127 |
draw_feature_label_t *draw_estimator_feat, |
| 128 |
const data_feature_t *feature, |
| 129 |
draw_relationship_label_t *draw_estimator_rel, |
| 130 |
const data_relationship_t *relation, |
| 131 |
geometry_rectangle_t *out_solution |
| 132 |
); |
| 133 |
|
| 134 |
/*! |
| 135 |
* \brief selects one solution to layout a label rectangle |
| 136 |
* |
| 137 |
* \param this_ pointer to own object attributes |
| 138 |
* \param target_point point where the object is located to which the label belongs |
| 139 |
* \param solutions_count number of proposed solutions; at least 1 shall be provided |
| 140 |
* \param solutions array of solutions |
| 141 |
* \param out_index_of_best index of the best solution; must not be NULL. |
| 142 |
*/ |
| 143 |
void pencil_floating_label_layouter_select_solution ( pencil_floating_label_layouter_t *this_, |
| 144 |
geometry_point_t target_point, |
| 145 |
uint32_t solutions_count, |
| 146 |
const geometry_rectangle_t solutions[], |
| 147 |
uint32_t *out_index_of_best |
| 148 |
); |
| 149 |
|
| 150 |
#include "pencil_floating_label_layouter.inl" |
| 151 |
|
| 152 |
#endif /* PENCIL_FLOATING_LABEL_LAYOUTER_H */ |
| 153 |
|
| 154 |
|
| 155 |
/* |
| 156 |
Copyright 2019-2026 Andreas Warnke |
| 157 |
|
| 158 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 159 |
you may not use this file except in compliance with the License. |
| 160 |
You may obtain a copy of the License at |
| 161 |
|
| 162 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 163 |
|
| 164 |
Unless required by applicable law or agreed to in writing, software |
| 165 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 166 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 167 |
See the License for the specific language governing permissions and |
| 168 |
limitations under the License. |
| 169 |
*/ |