From 14243906c8f8ccbb8ac737f6d6ca73fca02b3a54 Mon Sep 17 00:00:00 2001 From: Jonathan Wilkes <jon.w.wilkes@gmail.com> Date: Fri, 28 Aug 2015 19:32:41 -0400 Subject: [PATCH] Make the iemgui font-selection dropdown functional --- pd/nw/dialog_iemgui.html | 13 ++++++++----- pd/nw/pdgui.js | 17 ++++++++++------- pd/src/g_all_guis.c | 18 ++++++++++++------ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/pd/nw/dialog_iemgui.html b/pd/nw/dialog_iemgui.html index b74369134..db3142f92 100644 --- a/pd/nw/dialog_iemgui.html +++ b/pd/nw/dialog_iemgui.html @@ -233,9 +233,9 @@ </td> <td data-i18n="[title]iem.prop.font_tt"> <select name="font-style"> - <option>Font Number 0</option> - <option>Font #1</option> - <option>Font 2</option> + <option>DejaVu Sans Mono</option> + <option>Helvetica</option> + <option>Times</option> </select> </td> <td colspan="4"> @@ -435,8 +435,9 @@ function apply() { slot7 = 0; } - var font_style = document.getElementsByName('font-style')[0].value; - if (font_style !== null) { font_style = 0; } + var font_style = document.getElementsByName('font-style')[0]. + selectedIndex; +// if (font_style !== null) { font_style = 0; } var font_size = document.getElementsByName('font-size')[0].value; if (font_size === '') { font_size = 0; } @@ -545,6 +546,8 @@ function populate_form(attr_array) { // The attr here is a string, so we need to // force it to number, hence the "+" below elem[0].checked = +attr_array[i+1]; + } else if (elem[0].type === 'select-one') { + elem[0].selectedIndex = +attr_array[i+1]; } else { elem[0].value = attr_array[i+1]; } diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js index ce4ed4feb..8a88dc38b 100644 --- a/pd/nw/pdgui.js +++ b/pd/nw/pdgui.js @@ -2767,7 +2767,7 @@ function iemgui_font_height(name, size) { } function iemgui_fontfamily(name) { - var family; + var family = "DejaVu Sans Mono"; if (name === "DejaVu Sans Mono") { family = "DejaVu Sans Mono"; // probably should add some fallbacks here } @@ -2777,6 +2777,7 @@ function iemgui_fontfamily(name) { else if (name === "times") { family = "'Times New Roman', 'DejaVu Serif', 'FreeSerif', serif"; } + return family; } function gui_iemgui_label_new(cid, tag, x, y, color, text, fontname, fontweight, @@ -2842,13 +2843,15 @@ function gui_iemgui_label_select(cid, tag, is_selected) { } } -function gui_iemgui_label_font(cid, tag, font) { +function gui_iemgui_label_font(cid, tag, fontname, fontweight, fontsize) { +gui_post("googoo: fontsize is " + fontsize); var svg_text = get_item(cid, tag + 'label'); - // This has to wait until we remove the tcl formatting - // that Pd uses for font name/size - // configure_item(svg_text, { - // font: font - // }); + configure_item(svg_text, { + 'font-family': iemgui_fontfamily(fontname), + 'font-weight': fontweight, + 'font-size': fontsize + 'px', + transform: 'translate(0,' + iemgui_font_height(fontname, fontsize) / 2 + ')' + }); } function gui_create_mycanvas(cid,tag,color,x1,y1,x2_vis,y2_vis,x2,y2) { diff --git a/pd/src/g_all_guis.c b/pd/src/g_all_guis.c index 712ebdd39..44ec31172 100644 --- a/pd/src/g_all_guis.c +++ b/pd/src/g_all_guis.c @@ -270,10 +270,12 @@ void iemgui_label_font(t_iemgui *x, t_symbol *s, int ac, t_atom *av) { //sys_vgui(".x%lx.c itemconfigure %lxLABEL -font %s\n", // glist_getcanvas(x->x_glist), x, iemgui_font(x)); - gui_vmess("gui_iemgui_label_font", "xxs", + gui_vmess("gui_iemgui_label_font", "xxssi", glist_getcanvas(x->x_glist), x, - iemgui_font(x)); + iemgui_typeface(x), + sys_fontweight, + x->x_fontsize); iemgui_shouldvis(x, IEM_GUI_DRAW_MODE_CONFIG); } } @@ -1013,10 +1015,12 @@ void iemgui_label_draw_config(t_iemgui *x) { // "-fill $pd_colors(selection) -text {%s} \n", // canvas, x, iemgui_font(x), // x->x_lab!=s_empty?x->x_lab->s_name:""); - gui_vmess("gui_iemgui_label_font", "xxs", + gui_vmess("gui_iemgui_label_font", "xxssi", glist_getcanvas(x->x_glist), x, - iemgui_font(x)); + iemgui_typeface(x), + sys_fontweight, + x->x_fontsize); gui_vmess("gui_iemgui_label_set", "xxs", glist_getcanvas(x->x_glist), x, @@ -1033,10 +1037,12 @@ void iemgui_label_draw_config(t_iemgui *x) { // "-fill #%6.6x -text {%s} \n", // canvas, x, iemgui_font(x), // x->x_lcol, x->x_lab!=s_empty?x->x_lab->s_name:""); - gui_vmess("gui_iemgui_label_font", "xxs", + gui_vmess("gui_iemgui_label_font", "xxssi", glist_getcanvas(x->x_glist), x, - iemgui_font(x)); + iemgui_typeface(x), + sys_fontweight, + x->x_fontsize); gui_vmess("gui_iemgui_label_set", "xxs", glist_getcanvas(x->x_glist), x, -- GitLab