Commit a771f7ecd774e218a5b5d3af74e5d52ef5c01940

Authored by Perry Werneck
1 parent 92a95c77
Exists in master and in 1 other branch develop

Adding property for font-family allowing change it from debug console.

src/terminal/font.c
... ... @@ -34,7 +34,7 @@
34 34  
35 35  
36 36 #define VIEW_HEIGTH_FROM_FONT(font_height) (( ((unsigned int) font_height) * (rows+1)) + OIA_TOP_MARGIN + 2)
37   - #define VIEW_WIDTH_FROM_FONT(max_x_advance) (((unsigned int) max_x_advance) * cols)
  37 + #define VIEW_WIDTH_FROM_FONT(max_x_advance) ( ((unsigned int) max_x_advance) * cols)
38 38  
39 39 /*--[ Globals ]--------------------------------------------------------------------------------------*/
40 40  
... ... @@ -68,19 +68,26 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, unsigned int width,
68 68 cairo_font_extents_t extents;
69 69  
70 70 lib3270_get_screen_size(terminal->host,&rows,&cols);
71   - debug("Screen_size: %ux%u Scalled=%s view_rows=%d view_cols=%d",rows,cols,terminal->font.scaled ? "Yes" : "No", (rows+OIA_TOP_MARGIN+3));
  71 +
  72 + debug(
  73 + "Screen_size: %ux%u Scalled=%s view_rows=%d",
  74 + rows,
  75 + cols,
  76 + terminal->font.scaled ? "Yes" : "No",
  77 + (rows+OIA_TOP_MARGIN+3)
  78 + );
72 79  
73 80 terminal->font.weight = lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL;
74 81  
75 82 cairo_select_font_face(cr,terminal->font.family, CAIRO_FONT_SLANT_NORMAL,terminal->font.weight);
76 83  
  84 + /*
77 85 if(terminal->font.scaled)
78 86 {
79   - /*
80   - double w = ((double) width) / ((double)cols);
81   - double h = ((double) height) / ((double) ((rows + OIA_TOP_MARGIN + 3)));
82   - double s = (w < h) ? w : h;
83   - */
  87 +
  88 + // double w = ((double) width) / ((double)cols);
  89 + // double h = ((double) height) / ((double) ((rows + OIA_TOP_MARGIN + 3)));
  90 + // double s = (w < h) ? w : h;
84 91  
85 92 double s = 0.1;
86 93  
... ... @@ -100,7 +107,7 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, unsigned int width,
100 107 cairo_font_extents(cr,&extents);
101 108  
102 109 }
103   - else
  110 + else */
104 111 {
105 112 static const unsigned int font_size[] = { 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 26, 28, 32, 36, 40, 48, 56, 64, 72 };
106 113 size_t f;
... ... @@ -118,12 +125,14 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, unsigned int width,
118 125 terminal->minimum_height = ((rows+1) * (extents.height + extents.descent)) + (OIA_TOP_MARGIN+2);
119 126 }
120 127  
121   - debug("font_size=%d y_advance=%u font_extents=%u+%u font_height=%u view_height=%u",
  128 + debug("font_size=%d x_advance=%lf y_advance=%lf font_extents=%u+%u font_height=%u view_height=%u view_width=%u",
122 129 font_size[f],
123   - (unsigned int) extents.max_y_advance,
  130 + extents.max_x_advance,
  131 + extents.max_y_advance,
124 132 (unsigned int) extents.height, (unsigned int) extents.descent,
125 133 VIEW_HEIGTH_FROM_FONT( (unsigned int) (extents.height + extents.descent) ),
126   - height
  134 + height,
  135 + VIEW_WIDTH_FROM_FONT(extents.max_x_advance)
127 136 );
128 137  
129 138 if( VIEW_HEIGTH_FROM_FONT((extents.height + extents.descent)) < height && VIEW_WIDTH_FROM_FONT(extents.max_x_advance) < width)
... ... @@ -228,6 +237,7 @@ LIB3270_EXPORT void v3270_set_font_family(GtkWidget *widget, const gchar *name)
228 237 terminal->font.weight = lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL;
229 238  
230 239 g_signal_emit(widget,v3270_widget_signal[SIGNAL_UPDATE_CONFIG], 0, "font-family", name);
  240 + g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties.font_family);
231 241  
232 242 v3270_reload(widget);
233 243 gtk_widget_queue_draw(widget);
... ...
src/terminal/private.h
... ... @@ -246,6 +246,10 @@ G_BEGIN_DECLS
246 246 guint str;
247 247 } type;
248 248  
  249 + // V3270 Internal properties.
  250 + GParamSpec * font_family;
  251 +
  252 + // Properties who launch signals.
249 253 GParamSpec * online;
250 254 GParamSpec * luname;
251 255 GParamSpec * model;
... ...
src/terminal/properties.c
... ... @@ -88,10 +88,17 @@
88 88 lib3270_set_toggle(window->host,prop_id - v3270_properties.type.toggle, (int) g_value_get_boolean (value));
89 89  
90 90 }
91   - else
92   - {
  91 +
  92 + // Check for internal properties.
  93 + switch(prop_id) {
  94 + case PROP_BEGIN: // Font-family
  95 + v3270_set_font_family(GTK_WIDGET(object), g_value_get_string(value));
  96 + break;
  97 +
  98 + default:
93 99 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
94   - }
  100 +
  101 + }
95 102  
96 103 }
97 104  
... ... @@ -134,10 +141,19 @@
134 141 g_value_set_boolean(value,lib3270_get_toggle(window->host,prop_id - v3270_properties.type.toggle) ? TRUE : FALSE );
135 142  
136 143 }
137   - else
138   - {
  144 +
  145 + // Check for internal properties.
  146 + switch(prop_id) {
  147 + case PROP_BEGIN: // Font-family
  148 + g_value_set_string(value,v3270_get_font_family(GTK_WIDGET(object)));
  149 + break;
  150 +
  151 + default:
139 152 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
140   - }
  153 +
  154 + }
  155 +
  156 +
141 157  
142 158 }
143 159  
... ... @@ -148,10 +164,10 @@
148 164 const char *name;
149 165 GParamSpec **prop;
150 166 } properties[] = {
151   - { "connected", &v3270_properties.online },
152   - { "luname", &v3270_properties.luname },
153   - { "model", &v3270_properties.model },
154   - { "has-selection", &v3270_properties.selection }
  167 + { "connected", &v3270_properties.online },
  168 + { "luname", &v3270_properties.luname },
  169 + { "model", &v3270_properties.model },
  170 + { "has-selection", &v3270_properties.selection },
155 171 };
156 172  
157 173 size_t ix;
... ... @@ -179,59 +195,75 @@
179 195 debug("%s",__FUNCTION__);
180 196  
181 197 memset(&v3270_properties,0,sizeof(v3270_properties));
182   - v3270_properties.count = LIB3270_TOGGLE_COUNT;
183   - v3270_properties.type.toggle = PROP_BEGIN;
184   -
185 198 gobject_class->set_property = v3270_set_property;
186 199 gobject_class->get_property = v3270_get_property;
187 200  
188   - // Get property tables
189   - const LIB3270_INT_PROPERTY * bool_props = lib3270_get_boolean_properties_list();
190   - const LIB3270_INT_PROPERTY * int_props = lib3270_get_int_properties_list();
191   - const LIB3270_STRING_PROPERTY * str_props = lib3270_get_string_properties_list();
192   -
193   - v3270_properties.type.boolean = v3270_properties.count + PROP_BEGIN;
194   - for(ix = 0; bool_props[ix].name; ix++)
195   - {
196   - v3270_properties.count++;
197   - }
198   -
199   - v3270_properties.type.integer = v3270_properties.count + PROP_BEGIN;
200   - for(ix = 0; int_props[ix].name; ix++)
201   - {
202   - v3270_properties.count++;
203   - }
204   -
205   - v3270_properties.type.str = v3270_properties.count + PROP_BEGIN;
206   - for(ix = 0; str_props[ix].name; ix++)
  201 + v3270_properties.count = PROP_BEGIN;
  202 +
  203 + // Setup internal properties.
  204 + v3270_properties.font_family = g_param_spec_string(
  205 + "font_family",
  206 + "font_family",
  207 + _("Font family for terminal contents"),
  208 + FALSE,
  209 + G_PARAM_READABLE|G_PARAM_WRITABLE
  210 + );
  211 +
  212 + g_object_class_install_property(
  213 + gobject_class,
  214 + v3270_properties.count++,
  215 + v3270_properties.font_family
  216 + );
  217 +
  218 + //
  219 + // Extract properties from LIB3270 control tables
  220 + //
  221 +
  222 + // Extract toggle class.
  223 + v3270_properties.type.toggle = v3270_properties.count;
  224 + for(ix = 0; ix < LIB3270_TOGGLE_COUNT; ix++)
207 225 {
208   - v3270_properties.count++;
209   - }
  226 + debug("Property %u=%s (Toggle)",(unsigned int) v3270_properties.type.toggle + ix, lib3270_get_toggle_name(ix));
  227 +
  228 + v3270_properties.toggle[ix] =
  229 + g_param_spec_boolean(
  230 + lib3270_get_toggle_name(ix),
  231 + lib3270_get_toggle_name(ix),
  232 + lib3270_get_toggle_description(ix),
  233 + FALSE,
  234 + G_PARAM_WRITABLE|G_PARAM_READABLE
  235 + );
210 236  
211   - debug("Creating %u properties", (unsigned int) v3270_properties.count);
  237 + v3270_install_property(gobject_class, v3270_properties.count++, v3270_properties.toggle[ix]);
212 238  
213   - // Creating toggle properties.
214   - for(ix = 0; ix < LIB3270_TOGGLE_COUNT; ix++)
215   - {
216   -// debug("Property %u=%s (Toggle)",(unsigned int) v3270_properties.type.toggle + ix, lib3270_get_toggle_name(ix));
217   - v3270_properties.toggle[ix] = g_param_spec_boolean(lib3270_get_toggle_name(ix),lib3270_get_toggle_name(ix),lib3270_get_toggle_description(ix),FALSE,G_PARAM_WRITABLE|G_PARAM_READABLE);
218   - v3270_install_property(gobject_class, v3270_properties.type.toggle + ix, v3270_properties.toggle[ix]);
219 239 }
220 240  
221   -
222 241 // Creating boolean properties.
  242 + v3270_properties.type.boolean = v3270_properties.count;
  243 + const LIB3270_INT_PROPERTY * bool_props = lib3270_get_boolean_properties_list();
  244 +
223 245 for(ix = 0; bool_props[ix].name; ix++)
224 246 {
225   -// debug("Property %u=%s (Boolean)",(unsigned int) v3270_properties.type.boolean + ix, bool_props[ix].name);
226   - spec = g_param_spec_boolean(bool_props[ix].name, bool_props[ix].name, bool_props[ix].description, FALSE,(bool_props[ix].set == NULL ? G_PARAM_READABLE : (G_PARAM_READABLE|G_PARAM_WRITABLE)));
227   - v3270_install_property(gobject_class, v3270_properties.type.boolean + ix, spec);
  247 + debug("Property %u=%s (Boolean)",(unsigned int) v3270_properties.type.boolean + ix, bool_props[ix].name);
  248 + spec = g_param_spec_boolean(
  249 + bool_props[ix].name,
  250 + bool_props[ix].name,
  251 + bool_props[ix].description,
  252 + FALSE,
  253 + (bool_props[ix].set == NULL ? G_PARAM_READABLE : (G_PARAM_READABLE|G_PARAM_WRITABLE))
  254 + );
  255 +
  256 + v3270_install_property(gobject_class, v3270_properties.count++, spec);
228 257  
229 258 }
230 259  
231 260 // Creating integer properties.
  261 + const LIB3270_INT_PROPERTY * int_props = lib3270_get_int_properties_list();
  262 + v3270_properties.type.integer = v3270_properties.count;
  263 +
232 264 for(ix = 0; int_props[ix].name; ix++)
233 265 {
234   -// debug("Property %u=%s (Integer)",(unsigned int) v3270_properties.type.integer + ix, int_props[ix].name);
  266 + debug("Property %u=%s (Integer)",(unsigned int) v3270_properties.type.integer + ix, int_props[ix].name);
235 267  
236 268 spec = g_param_spec_int(
237 269 int_props[ix].name,
... ... @@ -242,17 +274,34 @@
242 274 0, // Default
243 275 (int_props[ix].set == NULL ? G_PARAM_READABLE : (G_PARAM_READABLE|G_PARAM_WRITABLE))
244 276 );
  277 + debug("Creating %u properties", (unsigned int) v3270_properties.count);
  278 +
  279 +
  280 +
  281 +
245 282  
246   - v3270_install_property(gobject_class, v3270_properties.type.integer + ix, spec);
  283 + v3270_install_property(gobject_class, v3270_properties.count++, spec);
247 284  
248 285 }
249 286  
250 287 // Creating string properties.
  288 + const LIB3270_STRING_PROPERTY * str_props = lib3270_get_string_properties_list();
  289 + v3270_properties.type.str = v3270_properties.count;
  290 +
251 291 for(ix = 0; str_props[ix].name; ix++)
252 292 {
253   -// debug("Property %u=%s (String)",(unsigned int) v3270_properties.type.str + ix, str_props[ix].name);
254   - spec = g_param_spec_string(str_props[ix].name, str_props[ix].name, str_props[ix].description, FALSE,(str_props[ix].set == NULL ? G_PARAM_READABLE : (G_PARAM_READABLE|G_PARAM_WRITABLE)));
255   - v3270_install_property(gobject_class, v3270_properties.type.str + ix, spec);
  293 +
  294 + debug("Property %u=%s (String)",(unsigned int) v3270_properties.type.str + ix, str_props[ix].name);
  295 +
  296 + spec = g_param_spec_string(
  297 + str_props[ix].name,
  298 + str_props[ix].name,
  299 + str_props[ix].description,
  300 + FALSE,
  301 + (str_props[ix].set == NULL ? G_PARAM_READABLE : (G_PARAM_READABLE|G_PARAM_WRITABLE))
  302 + );
  303 +
  304 + v3270_install_property(gobject_class, v3270_properties.count++, spec);
256 305  
257 306 }
258 307  
... ...