From 6648652ae5f5e5860512f62520a7b87bb3da3b03 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Sun, 3 Dec 2023 12:26:18 +0100 Subject: [PATCH] allow instance attribute `text_n_size=s` (where s is a double and n is an integer) to set symbol text item `n` to size `s` --- doc/xschem_man/component_property_syntax.html | 3 ++ src/draw.c | 40 +++++++++++++++++-- src/psprint.c | 9 +++-- src/scheduler.c | 9 +++-- src/select.c | 6 ++- src/svgdraw.c | 9 +++-- src/xschem.h | 1 + 7 files changed, 63 insertions(+), 14 deletions(-) diff --git a/doc/xschem_man/component_property_syntax.html b/doc/xschem_man/component_property_syntax.html index 4a5eebf0..bbef4ed8 100644 --- a/doc/xschem_man/component_property_syntax.html +++ b/doc/xschem_man/component_property_syntax.html @@ -127,6 +127,9 @@ name="mchanged_name" model=\"nmos\" w="20u" l="3u" m="10"

A hide=true attribute will only display the symbol bounding box.

  • hide_texts
  • A hide_texts=true attribute will hide all symbol texts.

    +
  • text_<n>_size
  • +

    This attribute sets the size of symbol text item number n. This allows + instance based symbol text sizing.

  • highlight
  • If set to true the symbol will be highlighted when one of the nets attached to its pins are highlighted.

  • net_name
  • diff --git a/src/draw.c b/src/draw.c index be211cf0..c1dc925d 100644 --- a/src/draw.c +++ b/src/draw.c @@ -414,6 +414,32 @@ void draw_temp_string(GC gctext, int what, const char *str, short rot, short fli } +void get_sym_text_size(int inst, int text_n, double *xscale, double *yscale) +{ + char attr[50]; + const char *ts; + double size; + int sym_n = xctx->inst[inst].ptr; + xText *txtptr; + + if(sym_n >= 0 && xctx->sym[sym_n].texts > text_n) { + txtptr = &(xctx->sym[sym_n].text[text_n]); + my_snprintf(attr, S(attr), "text_%d_size", text_n); + ts = get_tok_value(xctx->inst[inst].prop_ptr, attr, 0); + if(xctx->tok_size) { + size = atof(ts); + *xscale = size; + *yscale = size; + } else { + *xscale = txtptr->xscale; + *yscale = txtptr->yscale; + } + } else { + *xscale = *yscale = 0.0; + } +} + + /* * layer: the set of symbol objects on xschem layer 'layer' to draw * c : the layer 'c' to draw those objects on (if != layer it is the hilight color) @@ -644,8 +670,11 @@ void draw_symbol(int what,int c, int n,int layer,short tmp_flip, short rot, { for(j=0;j< symptr->texts; ++j) { + double xscale, yscale; + + get_sym_text_size(n, j, &xscale, &yscale); text = symptr->text[j]; - if(!text.txt_ptr || !text.txt_ptr[0] || text.xscale*FONTWIDTH*xctx->mooz<1) continue; + if(!text.txt_ptr || !text.txt_ptr[0] || xscale*FONTWIDTH*xctx->mooz<1) continue; if(!xctx->show_hidden_texts && (text.flags & HIDE_TEXT)) continue; if( hide && text.txt_ptr && strcmp(text.txt_ptr, "@symname") && strcmp(text.txt_ptr, "@name") ) continue; ROTATION(rot, flip, 0.0,0.0,text.x0,text.y0,x1,y1); @@ -686,7 +715,7 @@ void draw_symbol(int what,int c, int n,int layer,short tmp_flip, short rot, draw_string(textlayer, what, txtptr, (text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3, flip^text.flip, text.hcenter, text.vcenter, - x0+x1, y0+y1, text.xscale, text.yscale); + x0+x1, y0+y1, xscale, yscale); my_free(_ALLOC_ID_, &txtptr); #if HAS_CAIRO!=1 drawrect(textlayer, END, 0.0, 0.0, 0.0, 0.0, 0); @@ -837,8 +866,11 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,short tmp_flip, short rot char *txtptr = NULL; for(j=0;j< symptr->texts; ++j) { + double xscale, yscale; + + get_sym_text_size(n, j, &xscale, &yscale); text = symptr->text[j]; - if(!text.txt_ptr || !text.txt_ptr[0] || text.xscale*FONTWIDTH*xctx->mooz<1) continue; + if(!text.txt_ptr || !text.txt_ptr[0] || xscale*FONTWIDTH*xctx->mooz<1) continue; if(!xctx->show_hidden_texts && (text.flags & HIDE_TEXT)) continue; ROTATION(rot, flip, 0.0,0.0,text.x0,text.y0,x1,y1); #if HAS_CAIRO==1 @@ -847,7 +879,7 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,short tmp_flip, short rot my_strdup2(_ALLOC_ID_, &txtptr, translate(n, text.txt_ptr)); if(txtptr[0]) draw_temp_string(gc, what, txtptr, (text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3, - flip^text.flip, text.hcenter, text.vcenter, x0+x1, y0+y1, text.xscale, text.yscale); + flip^text.flip, text.hcenter, text.vcenter, x0+x1, y0+y1, xscale, yscale); my_free(_ALLOC_ID_, &txtptr); #if HAS_CAIRO==1 if(customfont) { diff --git a/src/psprint.c b/src/psprint.c index 4218f083..244bcc66 100644 --- a/src/psprint.c +++ b/src/psprint.c @@ -893,8 +893,11 @@ static void ps_draw_symbol(int n,int layer, int what, short tmp_flip, short rot, const char *txtptr; for(j=0;j< (xctx->inst[n].ptr+ xctx->sym)->texts; ++j) { + double xscale, yscale; + + get_sym_text_size(n, j, &xscale, &yscale); text = (xctx->inst[n].ptr+ xctx->sym)->text[j]; - /* if(text.xscale*FONTWIDTH* xctx->mooz<1) continue; */ + /* if(xscale*FONTWIDTH* xctx->mooz<1) continue; */ if(!xctx->show_hidden_texts && (text.flags & HIDE_TEXT)) continue; if( hide && text.txt_ptr && strcmp(text.txt_ptr, "@symname") && strcmp(text.txt_ptr, "@name") ) continue; txtptr= translate(n, text.txt_ptr); @@ -929,12 +932,12 @@ static void ps_draw_symbol(int n,int layer, int what, short tmp_flip, short rot, ps_draw_string(textlayer, txtptr, (text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3, flip^text.flip, text.hcenter, text.vcenter, - x0+x1, y0+y1, text.xscale, text.yscale); + x0+x1, y0+y1, xscale, yscale); } else { old_ps_draw_string(textlayer, txtptr, (text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3, flip^text.flip, text.hcenter, text.vcenter, - x0+x1, y0+y1, text.xscale, text.yscale); + x0+x1, y0+y1, xscale, yscale); } } } diff --git a/src/scheduler.c b/src/scheduler.c index fe8fdccd..17f7393b 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -4760,7 +4760,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg /* test * Testmode ... */ - else if(0 && !strcmp(argv[1], "test") ) + else if(1 && !strcmp(argv[1], "test") ) { Iterator_ctx ctx; Objectentry *objectptr; @@ -4806,8 +4806,11 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg del_object_table(); Tcl_ResetResult(interp); } - else if(argc > 2 && atoi(argv[2]) == 2) { - dbg(0, "cur=%d, tail=%d, head=%d\n", xctx->cur_undo_ptr, xctx->tail_undo_ptr, xctx->head_undo_ptr); + /* test 2 inst text_n */ + else if(argc > 5 && atoi(argv[2]) == 2) { + double sx, sy; + get_sym_text_size(atoi(argv[3]), atoi(argv[4]), &sx, &sy); + dbg(0, "size=%g, %g\n", sx, sy); Tcl_ResetResult(interp); } } diff --git a/src/select.c b/src/select.c index 0bc12d26..f8529326 100644 --- a/src/select.c +++ b/src/select.c @@ -352,6 +352,10 @@ void symbol_bbox(int i, double *x1,double *y1, double *x2, double *y2) /* strings bbox */ for(j=0;j< (xctx->inst[i].ptr+ xctx->sym)->texts; ++j) { + double xscale, yscale; + + get_sym_text_size(i, j, &xscale, &yscale); + text = (xctx->inst[i].ptr+ xctx->sym)->text[j]; if(!xctx->show_hidden_texts && (text.flags & HIDE_TEXT)) continue; sym_flip = flip; @@ -363,7 +367,7 @@ void symbol_bbox(int i, double *x1,double *y1, double *x2, double *y2) #if HAS_CAIRO==1 customfont=set_text_custom_font(&text); #endif - text_bbox(tmp_txt, text.xscale, text.yscale, + text_bbox(tmp_txt, xscale, yscale, (text.rot + ( (sym_flip && (text.rot & 1) ) ? sym_rot+2 : sym_rot)) &0x3, sym_flip ^ text.flip, text.hcenter, text.vcenter, x0+text_x0,y0+text_y0, &xx1,&yy1,&xx2,&yy2, &tmp, &dtmp); diff --git a/src/svgdraw.c b/src/svgdraw.c index ce903102..863bffa2 100644 --- a/src/svgdraw.c +++ b/src/svgdraw.c @@ -542,8 +542,11 @@ static void svg_draw_symbol(int c, int n,int layer,short tmp_flip, short rot, { const char *txtptr; for(j=0;j< symptr->texts; ++j) { + double xscale, yscale; + + get_sym_text_size(n, j, &xscale, &yscale); text = symptr->text[j]; - /* if(text.xscale*FONTWIDTH* xctx->mooz<1) continue; */ + /* if(xscale*FONTWIDTH* xctx->mooz<1) continue; */ if(!xctx->show_hidden_texts && (symptr->text[j].flags & HIDE_TEXT)) continue; if( hide && text.txt_ptr && strcmp(text.txt_ptr, "@symname") && strcmp(text.txt_ptr, "@name") ) continue; txtptr= translate(n, text.txt_ptr); @@ -573,12 +576,12 @@ static void svg_draw_symbol(int c, int n,int layer,short tmp_flip, short rot, svg_draw_string(textlayer, txtptr, (text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3, flip^text.flip, text.hcenter, text.vcenter, - x0+x1, y0+y1, text.xscale, text.yscale); + x0+x1, y0+y1, xscale, yscale); else old_svg_draw_string(textlayer, txtptr, (text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3, flip^text.flip, text.hcenter, text.vcenter, - x0+x1, y0+y1, text.xscale, text.yscale); + x0+x1, y0+y1, xscale, yscale); } } } diff --git a/src/xschem.h b/src/xschem.h index c8065cbb..26acc903 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1356,6 +1356,7 @@ extern void find_closest_net_or_symbol_pin(double mx,double my, double *x, doubl extern void drawline(int c, int what, double x1,double y1,double x2,double y2, int dash, void *ct); extern void draw_string(int layer,int what, const char *str, short rot, short flip, int hcenter, int vcenter, double x1, double y1, double xscale, double yscale); +extern void get_sym_text_size(int inst, int text_n, double *xscale, double *yscale); extern void draw_symbol(int what,int c, int n,int layer, short tmp_flip, short tmp_rot, double xoffset, double yoffset); extern void drawrect(int c, int what, double rectx1,double recty1,