LCOV - code coverage report
Current view: top level - pencil/include/draw - draw_stereotype_image.inl (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.57.0_covts Lines: 23 41 56.1 %
Date: 2024-04-07 11:14:42 Functions: 4 7 57.1 %

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

Generated by: LCOV version 1.16