| 1 |
/* File: draw_stereotype_icon.h; Copyright and License: see below */ |
| 2 |
|
| 3 |
#ifndef DRAW_STEREOTYPE_ICON_H |
| 4 |
#define DRAW_STEREOTYPE_ICON_H |
| 5 |
|
| 6 |
/* public file for the doxygen documentation: */ |
| 7 |
/*! |
| 8 |
* \file |
| 9 |
* \brief Renders a stereotype icon into a cairo drawing context |
| 10 |
*/ |
| 11 |
|
| 12 |
#include "pencil_size.h" |
| 13 |
#include "geometry/geometry_h_align.h" |
| 14 |
#include "geometry/geometry_v_align.h" |
| 15 |
#include "geometry/geometry_rectangle.h" |
| 16 |
#include "geometry/geometry_dimensions.h" |
| 17 |
#include "entity/data_classifier_type.h" |
| 18 |
#include "set/data_profile_part.h" |
| 19 |
#include "utf8stringbuf/utf8stringviewtokenizer.h" |
| 20 |
#include "u8/u8_error.h" |
| 21 |
#include "u8/u8_error_info.h" |
| 22 |
#include <cairo.h> |
| 23 |
#include <stdint.h> |
| 24 |
|
| 25 |
/*! \brief aspect ratio of the stereotype icon */ |
| 26 |
extern const double DRAW_STEREOTYPE_ICON_WIDTH_TO_HEIGHT; |
| 27 |
|
| 28 |
/*! |
| 29 |
* \brief attributes of the draw stereotype icon functions |
| 30 |
* |
| 31 |
* \note This class is stateless. |
| 32 |
* It may either be instantiated once and used many times or be instantiated per use. |
| 33 |
*/ |
| 34 |
struct draw_stereotype_icon_struct { |
| 35 |
int dummy; /*!< This object is a collection of stateless drawing functions */ |
| 36 |
}; |
| 37 |
|
| 38 |
typedef struct draw_stereotype_icon_struct draw_stereotype_icon_t; |
| 39 |
|
| 40 |
/*! |
| 41 |
* \brief initializes the draw_stereotype_icon_t |
| 42 |
* |
| 43 |
* \param this_ pointer to own object attributes |
| 44 |
*/ |
| 45 |
static inline void draw_stereotype_icon_init( draw_stereotype_icon_t *this_ ); |
| 46 |
|
| 47 |
/*! |
| 48 |
* \brief destroys the draw_stereotype_icon_t |
| 49 |
* |
| 50 |
* \param this_ pointer to own object attributes |
| 51 |
*/ |
| 52 |
static inline void draw_stereotype_icon_destroy( draw_stereotype_icon_t *this_ ); |
| 53 |
|
| 54 |
/*! |
| 55 |
* \brief determines the dimensions of the stereotype icon. |
| 56 |
* |
| 57 |
* Type icons are e.g. artifact-icon or component-icon. |
| 58 |
* |
| 59 |
* \param this_ pointer to own object attributes |
| 60 |
* \param pencil_size set of sizes and colors for drawing lines and text |
| 61 |
* \return dimension of the stereotype icon. |
| 62 |
*/ |
| 63 |
static inline geometry_dimensions_t draw_stereotype_icon_get_dimensions ( const draw_stereotype_icon_t *this_, |
| 64 |
const pencil_size_t *pencil_size |
| 65 |
); |
| 66 |
|
| 67 |
/*! |
| 68 |
* \brief calculates the bounding rectangle for the stereotype icon |
| 69 |
* |
| 70 |
* \param this_ pointer to own object attributes |
| 71 |
* \param x x location where to draw the stereotype icon |
| 72 |
* \param y y location where to draw the stereotype icon |
| 73 |
* \param h_align alignment of the stereotype icon versus the given x coordinate |
| 74 |
* \param v_align alignment of the stereotype icon versus the given y coordinate |
| 75 |
* \param pencil_size set of sizes and colors for drawing lines and text |
| 76 |
* \return bounding box rectangle of the stereotype icon |
| 77 |
*/ |
| 78 |
static inline geometry_rectangle_t draw_stereotype_icon_get_bounds ( const draw_stereotype_icon_t *this_, |
| 79 |
double x, |
| 80 |
double y, |
| 81 |
geometry_h_align_t h_align, |
| 82 |
geometry_v_align_t v_align, |
| 83 |
const pencil_size_t *pencil_size |
| 84 |
); |
| 85 |
|
| 86 |
/*! |
| 87 |
* \brief a quick check if the description field of the stereotype contains an svg path tag. |
| 88 |
* No check if the svg-path is valid. |
| 89 |
* |
| 90 |
* use draw_stereotype_icon_parse_svg_xml if valid parser structure of the svg-path shall also be checked. |
| 91 |
* |
| 92 |
* \param this_ pointer to own object attributes |
| 93 |
* \param stereotype name of the stereotype(s) to be drawn |
| 94 |
* \param profile profile-part that provides the stereotype definition of the element to be drawn |
| 95 |
* \return true if description field of the stereotype contains an svg path tag |
| 96 |
*/ |
| 97 |
static inline bool draw_stereotype_icon_exists ( const draw_stereotype_icon_t *this_, |
| 98 |
const char *stereotype, |
| 99 |
const data_profile_part_t *profile |
| 100 |
); |
| 101 |
|
| 102 |
/*! |
| 103 |
* \brief a quick check if drawing_directives contain an svg path tag. No check if the path is valid. |
| 104 |
* |
| 105 |
* use draw_stereotype_icon_parse_svg_xml if valid parser structure shall also be checked. |
| 106 |
* |
| 107 |
* \param this_ pointer to own object attributes |
| 108 |
* \param drawing_directives sequence of drawing directives |
| 109 |
* \return true if drawing_directives contain an svg path tag |
| 110 |
*/ |
| 111 |
static inline bool draw_stereotype_icon_private_exists ( const draw_stereotype_icon_t *this_, |
| 112 |
const char *drawing_directives |
| 113 |
); |
| 114 |
|
| 115 |
/*! |
| 116 |
* \brief draws the stereotype icon into the bounds rect |
| 117 |
* |
| 118 |
* \param this_ pointer to own object attributes |
| 119 |
* \param stereotype name of the stereotype(s) to be drawn |
| 120 |
* \param profile profile-part that provides the stereotype definition of the element to be drawn |
| 121 |
* \param default_color color to stroke paths if no stroke color is stated in the svg path of the stereotype |
| 122 |
* \param[out] out_err_info pointer to an error_info_t data struct; |
| 123 |
* in case of U8_ERROR_PARSER_STRUCTURE, it provides an error description when returning |
| 124 |
* \param bounds bounding rectangle of the stereotype icon |
| 125 |
* \param cr a cairo drawing context |
| 126 |
* \return U8_ERROR_NONE if one (or more) icons were drawn, |
| 127 |
* U8_ERROR_NOT_FOUND if no icon was found, |
| 128 |
* U8_ERROR_PARSER_STRUCTURE if expected tokens in the input icon were missing or in wrong order |
| 129 |
*/ |
| 130 |
u8_error_t draw_stereotype_icon_draw ( const draw_stereotype_icon_t *this_, |
| 131 |
const char *stereotype, |
| 132 |
const data_profile_part_t *profile, |
| 133 |
const GdkRGBA *default_color, |
| 134 |
u8_error_info_t *out_err_info, |
| 135 |
const geometry_rectangle_t *bounds, |
| 136 |
cairo_t *cr |
| 137 |
); |
| 138 |
|
| 139 |
/*! |
| 140 |
* \brief parses the stereotype icon (svg xml) and returns an error line number if invalid. |
| 141 |
* |
| 142 |
* \param this_ pointer to own object attributes |
| 143 |
* \param drawing_directives sequence of drawing directives |
| 144 |
* \param[out] out_view_rect bounding rectangle of the drawing_directives |
| 145 |
* \param[out] out_err_info pointer to an error_info_t data struct; |
| 146 |
* in case of U8_ERROR_PARSER_STRUCTURE, it provides an error description when returning |
| 147 |
* \return U8_ERROR_NONE if the icon was drawn, |
| 148 |
* U8_ERROR_NOT_FOUND if no icon was found, |
| 149 |
* U8_ERROR_PARSER_STRUCTURE if expected tokens in the input icon were missing or in wrong order |
| 150 |
*/ |
| 151 |
static inline u8_error_t draw_stereotype_icon_parse_svg_xml ( const draw_stereotype_icon_t *this_, |
| 152 |
const char *drawing_directives, |
| 153 |
geometry_rectangle_t *out_view_rect, |
| 154 |
u8_error_info_t *out_err_info |
| 155 |
); |
| 156 |
|
| 157 |
/*! |
| 158 |
* \brief draws the stereotype icon (svg xml) into the bounds rect |
| 159 |
* |
| 160 |
* \param this_ pointer to own object attributes |
| 161 |
* \param draw false if only the view_rect shall be determined, true if the drawing_directives shall be drawn |
| 162 |
* \param drawing_directives sequence of drawing directives |
| 163 |
* \param[in,out] io_view_rect bounding rectangle of the drawing_directives; |
| 164 |
* in all cases this is provided as output, |
| 165 |
* in case of draw==true this is needed as input, |
| 166 |
* in case of draw==false this is required to be initialized as empty, |
| 167 |
* eventually pre-filled by previous calls to preceding svg xml fragments. |
| 168 |
* \param default_color color to stroke paths if no stroke color is stated in the svg path of the stereotype |
| 169 |
* \param[out] out_err_info pointer to an error_info_t data struct; |
| 170 |
* in case of U8_ERROR_PARSER_STRUCTURE, it provides an error description when returning |
| 171 |
* \param target_bounds bounding rectangle of the drawing directives |
| 172 |
* \param cr a cairo drawing context |
| 173 |
* \return U8_ERROR_NONE if the icon was drawn, |
| 174 |
* U8_ERROR_NOT_FOUND if no icon was found, |
| 175 |
* U8_ERROR_PARSER_STRUCTURE if expected tokens in the input icon were missing or in wrong order |
| 176 |
*/ |
| 177 |
u8_error_t draw_stereotype_icon_private_parse_svg_xml ( const draw_stereotype_icon_t *this_, |
| 178 |
bool draw, |
| 179 |
const char *drawing_directives, |
| 180 |
geometry_rectangle_t *io_view_rect, |
| 181 |
const GdkRGBA *default_color, |
| 182 |
u8_error_info_t *out_err_info, |
| 183 |
const geometry_rectangle_t *target_bounds, |
| 184 |
cairo_t *cr |
| 185 |
); |
| 186 |
|
| 187 |
#include "draw_stereotype_icon.inl" |
| 188 |
|
| 189 |
#endif /* DRAW_STEREOTYPE_ICON_H */ |
| 190 |
|
| 191 |
|
| 192 |
/* |
| 193 |
Copyright 2023-2026 Andreas Warnke |
| 194 |
|
| 195 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 196 |
you may not use this file except in compliance with the License. |
| 197 |
You may obtain a copy of the License at |
| 198 |
|
| 199 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 200 |
|
| 201 |
Unless required by applicable law or agreed to in writing, software |
| 202 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 203 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 204 |
See the License for the specific language governing permissions and |
| 205 |
limitations under the License. |
| 206 |
*/ |