LCOV - code coverage report
Current view: top level - pencil/source/draw - draw_diagram_label.c (source / functions) Coverage Total Hit
Test: crystal-facet-uml_v1.63.2_covts Lines: 0.0 % 68 0
Test Date: 2025-05-01 10:10:14 Functions: 0.0 % 4 0

            Line data    Source code
       1              :   /* File: draw_diagram_label.c; Copyright and License: see below */
       2              : 
       3              : #include "draw/draw_diagram_label.h"
       4              : #include "u8/u8_trace.h"
       5              : #include "entity/data_classifier.h"
       6              : #include "entity/data_diagramelement.h"
       7              : #include "u8/u8_f64.h"
       8              : #include "utf8stringbuf/utf8stringbuf.h"
       9              : #include "utf8stringbuf/utf8string.h"
      10              : #include <pango/pangocairo.h>
      11              : #include <stdio.h>
      12              : #include <stdlib.h>
      13              : #include <assert.h>
      14              : 
      15              : static const int DRAW_DIAGRAM_PANGO_AUTO_DETECT_LENGTH = -1;
      16              : 
      17            0 : void draw_diagram_label_init( draw_diagram_label_t *this_ )
      18              : {
      19            0 :     draw_stereotype_icon_init( &((*this_).image_renderer) );
      20            0 : }
      21              : 
      22            0 : void draw_diagram_label_destroy( draw_diagram_label_t *this_ )
      23              : {
      24            0 :     draw_stereotype_icon_destroy( &((*this_).image_renderer) );
      25            0 : }
      26              : 
      27            0 : void draw_diagram_label_get_type_and_name_dimensions ( const draw_diagram_label_t *this_,
      28              :                                                        const data_diagram_t *diagram,
      29              :                                                        const data_profile_part_t *profile,
      30              :                                                        const geometry_dimensions_t *proposed_bounds,
      31              :                                                        const pencil_size_t *pencil_size,
      32              :                                                        PangoLayout *font_layout,
      33              :                                                        geometry_dimensions_t *out_label_dim )
      34              : {
      35            0 :     U8_TRACE_BEGIN();
      36            0 :     assert( NULL != diagram );
      37            0 :     assert( NULL != profile );
      38            0 :     assert( NULL != proposed_bounds );
      39            0 :     assert( NULL != pencil_size );
      40            0 :     assert( NULL != font_layout );
      41            0 :     assert( NULL != out_label_dim );
      42              : 
      43            0 :     if ( data_diagram_is_valid( diagram ) )
      44              :     {
      45              :         /* calc stereotype image bounds */
      46            0 :         const char *const diagram_stereotype = data_diagram_get_stereotype_const( diagram );
      47              :         const bool has_stereotype_image
      48            0 :             = draw_stereotype_icon_exists( &((*this_).image_renderer), diagram_stereotype, profile );
      49            0 :         const geometry_dimensions_t icon_dim
      50              :             = has_stereotype_image
      51            0 :             ? draw_stereotype_icon_get_dimensions( &((*this_).image_renderer), pencil_size )
      52            0 :             : (geometry_dimensions_t){ .width = 0.0, .height = 0.0 };
      53            0 :         const double icon_gap = has_stereotype_image ? pencil_size_get_standard_object_border( pencil_size ) : 0.0;
      54              : 
      55              :         /* calc name text dimensions */
      56              :         /* int proposed_pango_width = geometry_dimensions_get_width( proposed_bounds ); */
      57            0 :         int text2_height = 0;
      58            0 :         int text2_width = 0;
      59            0 :         if ( 0 != utf8string_get_length( data_diagram_get_name_const( diagram ) ))
      60              :         {
      61            0 :             pango_layout_set_font_description( font_layout, pencil_size_get_standard_font_description( pencil_size ) );
      62            0 :             pango_layout_set_text( font_layout,
      63              :                                    data_diagram_get_name_const( diagram ),
      64              :                                    DRAW_DIAGRAM_PANGO_AUTO_DETECT_LENGTH
      65              :                                  );
      66            0 :             pango_layout_get_pixel_size (font_layout, &text2_width, &text2_height);
      67            0 :             text2_height += PENCIL_SIZE_FONT_ALIGN_MARGIN;  /* allow to align font with pixel border */
      68            0 :             text2_width += PENCIL_SIZE_FONT_ALIGN_MARGIN;
      69              :         }
      70              : 
      71            0 :         *out_label_dim = (geometry_dimensions_t) {
      72            0 :             .width = geometry_dimensions_get_width( &icon_dim ) + icon_gap + text2_width,
      73            0 :             .height = u8_f64_max2( geometry_dimensions_get_height( &icon_dim ), text2_height )
      74              :         };
      75              :     }
      76              :     else
      77              :     {
      78            0 :         U8_LOG_ERROR("invalid diagram in draw_diagram_label_get_type_and_name_dimensions()");
      79            0 :         *out_label_dim = (geometry_dimensions_t) { .width = 0.0, .height = 0.0 };
      80              :     }
      81            0 :     U8_TRACE_END();
      82            0 : }
      83              : 
      84            0 : void draw_diagram_label_draw_type_and_name ( const draw_diagram_label_t *this_,
      85              :                                              const data_diagram_t *diagram,
      86              :                                              const data_profile_part_t *profile,
      87              :                                              const GdkRGBA *color,
      88              :                                              const geometry_rectangle_t *label_box,
      89              :                                              const pencil_size_t *pencil_size,
      90              :                                              PangoLayout *font_layout,
      91              :                                              cairo_t *cr )
      92              : {
      93            0 :     U8_TRACE_BEGIN();
      94            0 :     assert( NULL != diagram );
      95            0 :     assert( NULL != profile );
      96            0 :     assert( NULL != color );
      97            0 :     assert( NULL != label_box );
      98            0 :     assert( NULL != pencil_size );
      99            0 :     assert( NULL != font_layout );
     100            0 :     assert( NULL != cr );
     101              : 
     102              :     /* calc bounds of stereotype icon */
     103            0 :     const char *const diagram_stereotype = data_diagram_get_stereotype_const( diagram );
     104              :     const bool has_stereotype_image
     105            0 :         = draw_stereotype_icon_exists( &((*this_).image_renderer), diagram_stereotype, profile );
     106            0 :     const geometry_rectangle_t stereotype_box
     107              :         = has_stereotype_image
     108            0 :         ? draw_stereotype_icon_get_bounds( &((*this_).image_renderer),
     109              :                                             geometry_rectangle_get_left( label_box ),
     110              :                                             geometry_rectangle_get_top( label_box ),
     111              :                                             GEOMETRY_H_ALIGN_LEFT,
     112              :                                             GEOMETRY_V_ALIGN_TOP,
     113              :                                             pencil_size
     114              :                                           )
     115            0 :         : (geometry_rectangle_t){ .left = 0.0, .top = 0.0, .width = 0.0, .height = 0.0 };
     116            0 :     const double icon_gap = has_stereotype_image ? pencil_size_get_standard_object_border( pencil_size ) : 0.0;
     117              : 
     118              :     /* draw stereotype icon */
     119            0 :     if ( has_stereotype_image )
     120              :     {
     121              :         u8_error_info_t err_info;
     122              :         const u8_error_t stereotype_err
     123            0 :             = draw_stereotype_icon_draw( &((*this_).image_renderer),
     124              :                                           diagram_stereotype,
     125              :                                           profile,
     126              :                                           color,
     127              :                                           &err_info,
     128              :                                           &stereotype_box,
     129              :                                           cr
     130              :                                         );
     131            0 :         if ( u8_error_info_is_error( &err_info ) )
     132              :         {
     133            0 :             U8_LOG_WARNING_INT( "stereotype image: unxpected token in svg path in line",
     134              :                                 u8_error_info_get_line( &err_info )
     135              :                               );
     136              :         }
     137            0 :         else if ( stereotype_err != U8_ERROR_NONE )
     138              :         {
     139            0 :             U8_LOG_WARNING_HEX( "error at drawing stereotype image", stereotype_err );
     140              :         }
     141              :     }
     142              : 
     143              :     /* define names for input data */
     144            0 :     const double text_left
     145            0 :         = geometry_rectangle_get_left( label_box ) + geometry_rectangle_get_width( &stereotype_box ) + icon_gap;
     146            0 :     const double text_top = geometry_rectangle_get_top( label_box );
     147              : 
     148              :     /* draw name text */
     149            0 :     if ( 0 != utf8string_get_length( data_diagram_get_name_const( diagram ) ))
     150              :     {
     151            0 :         cairo_set_source_rgba( cr, color->red, color->green, color->blue, color->alpha );
     152            0 :         pango_layout_set_font_description (font_layout, pencil_size_get_standard_font_description(pencil_size) );
     153            0 :         pango_layout_set_text( font_layout,
     154              :                                data_diagram_get_name_const( diagram ),
     155              :                                DRAW_DIAGRAM_PANGO_AUTO_DETECT_LENGTH
     156              :                              );
     157              : 
     158              :         /* draw text */
     159            0 :         cairo_move_to ( cr, ceil( text_left ), ceil( text_top ) );  /* align font with pixel border */
     160            0 :         pango_cairo_show_layout (cr, font_layout);
     161              :     }
     162              : 
     163            0 :     U8_TRACE_END();
     164            0 : }
     165              : 
     166              : 
     167              : /*
     168              : Copyright 2017-2025 Andreas Warnke
     169              :     http://www.apache.org/licenses/LICENSE-2.0
     170              : 
     171              : Licensed under the Apache License, Version 2.0 (the "License");
     172              : you may not use this file except in compliance with the License.
     173              : You may obtain a copy of the License at
     174              : 
     175              : 
     176              : Unless required by applicable law or agreed to in writing, software
     177              : distributed under the License is distributed on an "AS IS" BASIS,
     178              : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     179              : See the License for the specific language governing permissions and
     180              : limitations under the License.
     181              : */
        

Generated by: LCOV version 2.0-1