Line data Source code
1 : /* File: pencil_diagram_layouter.c; Copyright and License: see below */
2 :
3 : #include "pencil_diagram_layouter.h"
4 : #include "u8/u8_trace.h"
5 : #include <pango/pangocairo.h>
6 : #include <stdio.h>
7 : #include <stdlib.h>
8 : #include <assert.h>
9 :
10 0 : void pencil_diagram_layouter_init( pencil_diagram_layouter_t *this_ )
11 : {
12 0 : U8_TRACE_BEGIN();
13 :
14 0 : draw_diagram_label_init( &((*this_).draw_diagram_label) );
15 :
16 0 : U8_TRACE_END();
17 0 : }
18 :
19 0 : void pencil_diagram_layouter_destroy( pencil_diagram_layouter_t *this_ )
20 : {
21 0 : U8_TRACE_BEGIN();
22 :
23 0 : draw_diagram_label_init( &((*this_).draw_diagram_label) );
24 :
25 0 : U8_TRACE_END();
26 0 : }
27 :
28 0 : void pencil_diagram_layouter_do_layout ( pencil_diagram_layouter_t *this_,
29 : const data_diagram_t *the_diagram,
30 : const geometry_rectangle_t *diagram_bounds,
31 : const data_profile_part_t *profile,
32 : const pencil_size_t *pencil_size,
33 : PangoLayout *font_layout,
34 : layout_diagram_t *io_layout_diagram )
35 : {
36 0 : U8_TRACE_BEGIN();
37 0 : assert( NULL != the_diagram );
38 0 : assert( NULL != diagram_bounds );
39 0 : assert( NULL != profile );
40 0 : assert( NULL != pencil_size );
41 0 : assert( NULL != font_layout );
42 0 : assert( NULL != io_layout_diagram );
43 :
44 : /* determine diagram bounds */
45 0 : const double left = geometry_rectangle_get_left ( diagram_bounds );
46 0 : const double top = geometry_rectangle_get_top ( diagram_bounds );
47 0 : const double width = geometry_rectangle_get_width ( diagram_bounds );
48 0 : const double height = geometry_rectangle_get_height ( diagram_bounds );
49 0 : const double gap = pencil_size_get_standard_object_border( pencil_size );
50 :
51 : /* calculate label_box */
52 0 : const double text_left = left + 3.0 * gap;
53 0 : const double text_top = top + 2.0 * gap;
54 0 : const geometry_dimensions_t label_dim_proposal
55 0 : = { .width = width, .height = pencil_size_get_standard_font_size( pencil_size ) };
56 : geometry_dimensions_t label_dim;
57 0 : draw_diagram_label_get_type_and_name_dimensions( &((*this_).draw_diagram_label),
58 : the_diagram,
59 : profile,
60 : &label_dim_proposal,
61 : pencil_size,
62 : font_layout,
63 : &label_dim
64 : );
65 0 : const double text_width = geometry_dimensions_get_width( &label_dim );
66 0 : const double text_height = geometry_dimensions_get_height( &label_dim );
67 : geometry_rectangle_t label_box;
68 0 : geometry_rectangle_init( &label_box, text_left, text_top, text_width, text_height );
69 :
70 : /* calculate space */
71 0 : const double space_left = left + 2.0 * gap;
72 0 : const double space_top = top + 4.0 * gap + text_height;
73 0 : const double space_width = width - 4.0 * gap;
74 0 : const double space_height = height - 6.0 * gap - text_height;
75 : geometry_rectangle_t space;
76 0 : if ( ( space_width <= 0.0 ) || ( space_height <= 0.0 ) )
77 : {
78 0 : geometry_rectangle_init_empty( &space );
79 : }
80 : else
81 : {
82 0 : geometry_rectangle_init( &space, space_left, space_top, space_width, space_height );
83 : }
84 :
85 : /* set new metrics */
86 0 : layout_diagram_set_bounds( io_layout_diagram, diagram_bounds );
87 0 : layout_diagram_set_draw_area( io_layout_diagram, &space );
88 0 : layout_diagram_set_label_box( io_layout_diagram, &label_box );
89 :
90 0 : geometry_rectangle_destroy( &space );
91 0 : geometry_rectangle_destroy( &label_box );
92 0 : U8_TRACE_END();
93 0 : }
94 :
95 :
96 : /*
97 : Copyright 2017-2026 Andreas Warnke
98 :
99 : Licensed under the Apache License, Version 2.0 (the "License");
100 : you may not use this file except in compliance with the License.
101 : You may obtain a copy of the License at
102 :
103 : http://www.apache.org/licenses/LICENSE-2.0
104 :
105 : Unless required by applicable law or agreed to in writing, software
106 : distributed under the License is distributed on an "AS IS" BASIS,
107 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
108 : See the License for the specific language governing permissions and
109 : limitations under the License.
110 : */
|