| 1 |
/* File: draw_stereotype_icon.inl; Copyright and License: see below */ |
| 2 |
|
| 3 |
#include "u8/u8_log.h" |
| 4 |
#include <math.h> |
| 5 |
#include <assert.h> |
| 6 |
|
| 7 |
static inline void draw_stereotype_icon_init( draw_stereotype_icon_t *this_ ) |
| 8 |
{ |
| 9 |
(*this_).dummy = 0; /* prevent warnings on uninitialized usage */ |
| 10 |
} |
| 11 |
|
| 12 |
static inline void draw_stereotype_icon_destroy( draw_stereotype_icon_t *this_ ) |
| 13 |
{ |
| 14 |
|
| 15 |
} |
| 16 |
|
| 17 |
static const double DRAW_STEREOTYPE_ICON_REL_SIZE = 1.5; |
| 18 |
|
| 19 |
static inline geometry_dimensions_t draw_stereotype_icon_get_dimensions( const draw_stereotype_icon_t *this_, |
| 20 |
const pencil_size_t *pencil_size ) |
| 21 |
{ |
| 22 |
assert( pencil_size != NULL ); |
| 23 |
geometry_dimensions_t result; |
| 24 |
|
| 25 |
const double image_height = DRAW_STEREOTYPE_ICON_REL_SIZE * pencil_size_get_title_font_size( pencil_size ); |
| 26 |
geometry_dimensions_init ( &result, DRAW_STEREOTYPE_ICON_WIDTH_TO_HEIGHT * image_height, image_height ); |
| 27 |
|
| 28 |
return result; |
| 29 |
} |
| 30 |
|
| 31 |
static inline geometry_rectangle_t draw_stereotype_icon_get_bounds ( const draw_stereotype_icon_t *this_, |
| 32 |
double x, |
| 33 |
double y, |
| 34 |
geometry_h_align_t h_align, |
| 35 |
geometry_v_align_t v_align, |
| 36 |
const pencil_size_t *pencil_size ) |
| 37 |
{ |
| 38 |
geometry_rectangle_t result; |
| 39 |
|
| 40 |
const double image_height = DRAW_STEREOTYPE_ICON_REL_SIZE * pencil_size_get_title_font_size( pencil_size ); |
| 41 |
const double image_width = DRAW_STEREOTYPE_ICON_WIDTH_TO_HEIGHT * image_height; |
| 42 |
geometry_rectangle_init( &result, |
| 43 |
geometry_h_align_get_left( &h_align, image_width, x, 0.0 ), |
| 44 |
geometry_v_align_get_top( &v_align, image_height, y, 0.0 ), |
| 45 |
image_width, |
| 46 |
image_height |
| 47 |
); |
| 48 |
|
| 49 |
return result; |
| 50 |
} |
| 51 |
|
| 52 |
static inline bool draw_stereotype_icon_exists( const draw_stereotype_icon_t *this_, |
| 53 |
const char *stereotype, |
| 54 |
const data_profile_part_t *profile ) |
| 55 |
{ |
| 56 |
assert( stereotype != NULL ); |
| 57 |
assert( profile != NULL ); |
| 58 |
bool result = false; |
| 59 |
|
| 60 |
const utf8stringview_t stereotype_view = UTF8STRINGVIEW_STR(stereotype); |
| 61 |
const data_classifier_t *const optional_stereotype |
| 62 |
= data_profile_part_get_stereotype_by_name_const( profile, &stereotype_view ); |
| 63 |
if ( optional_stereotype != NULL ) |
| 64 |
{ |
| 65 |
U8_TRACE_INFO_STR( "stereotype", stereotype ); |
| 66 |
const char *const drawing_directives = data_classifier_get_description_const( optional_stereotype ); |
| 67 |
result = draw_stereotype_icon_private_exists( this_, drawing_directives ); |
| 68 |
} |
| 69 |
|
| 70 |
return result; |
| 71 |
} |
| 72 |
|
| 73 |
static inline bool draw_stereotype_icon_private_exists( const draw_stereotype_icon_t *this_, |
| 74 |
const char *drawing_directives ) |
| 75 |
{ |
| 76 |
assert( drawing_directives != NULL ); |
| 77 |
/* TODO allow namespaces, e.g. <ns:path; check for end of nmtoken to prevent finding <pathfinder */ |
| 78 |
const char *pattern = "<path"; |
| 79 |
const bool exists = utf8string_contains_str( drawing_directives, pattern ); |
| 80 |
return exists; |
| 81 |
} |
| 82 |
|
| 83 |
static inline u8_error_t draw_stereotype_icon_parse_svg_xml( const draw_stereotype_icon_t *this_, |
| 84 |
const char *drawing_directives, |
| 85 |
geometry_rectangle_t *out_view_rect, |
| 86 |
u8_error_info_t *out_err_info ) |
| 87 |
{ |
| 88 |
assert( drawing_directives != NULL ); |
| 89 |
assert( out_view_rect != NULL ); |
| 90 |
assert( out_err_info != NULL ); |
| 91 |
|
| 92 |
geometry_rectangle_t target_bounds; |
| 93 |
geometry_rectangle_init_empty( &target_bounds ); |
| 94 |
geometry_rectangle_init_empty( out_view_rect ); |
| 95 |
const GdkRGBA default_color = { .red = 0.0, .green = 0.0, .blue = 0.0, .alpha = 0.0 }; |
| 96 |
u8_error_info_init_void( out_err_info ); |
| 97 |
|
| 98 |
const u8_error_t result |
| 99 |
= draw_stereotype_icon_private_parse_svg_xml( this_, |
| 100 |
false, /* draw */ |
| 101 |
drawing_directives, |
| 102 |
out_view_rect, |
| 103 |
&default_color, |
| 104 |
out_err_info, |
| 105 |
&target_bounds, |
| 106 |
NULL /* cr */ |
| 107 |
); |
| 108 |
return result; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
/* |
| 113 |
Copyright 2023-2026 Andreas Warnke |
| 114 |
|
| 115 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 116 |
you may not use this file except in compliance with the License. |
| 117 |
You may obtain a copy of the License at |
| 118 |
|
| 119 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 120 |
|
| 121 |
Unless required by applicable law or agreed to in writing, software |
| 122 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 123 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 124 |
See the License for the specific language governing permissions and |
| 125 |
limitations under the License. |
| 126 |
*/ |