From b7d724dcab4c3cbe0cf6817265c27e62cfbfa490 Mon Sep 17 00:00:00 2001 From: Stefan Schippers Date: Wed, 23 Sep 2020 22:13:39 +0200 Subject: [PATCH] apply visible layers (View->Symbol visible layers) to any object (lines. arcs, text etc),better bounding box calculation for slant text --- src/actions.c | 72 +++++++++++----------- src/draw.c | 13 ++-- src/xschem.tcl | 2 +- xschem_library/examples/0_examples_top.sch | 5 +- 4 files changed, 48 insertions(+), 44 deletions(-) diff --git a/src/actions.c b/src/actions.c index 0da73598..d5e0af35 100644 --- a/src/actions.c +++ b/src/actions.c @@ -2057,7 +2057,7 @@ int text_bbox(const char *str, double xscale, double yscale, double size; cairo_text_extents_t ext; cairo_font_extents_t fext; - double ww, hh; + double ww, hh, maxw; if(!has_x) return 0; size = xscale*52.*cairo_font_scale; @@ -2080,7 +2080,8 @@ int text_bbox(const char *str, double xscale, double yscale, cairo_lines++; if(str_ptr[0]!='\0') { cairo_text_extents(ctx, str_ptr, &ext); - if(ext.x_advance > ww) ww= ext.x_advance; + maxw = ext.x_advance > ext.width ? ext.x_advance : ext.width; + if(maxw > ww) ww= maxw; } s[c]='\n'; str_ptr = s+c+1; @@ -2090,7 +2091,8 @@ int text_bbox(const char *str, double xscale, double yscale, } if(str_ptr && str_ptr[0]!='\0') { cairo_text_extents(ctx, str_ptr, &ext); - if(ext.x_advance > ww) ww= ext.x_advance; + maxw = ext.x_advance > ext.width ? ext.x_advance : ext.width; + if(maxw > ww) ww= maxw; } my_free(1159, &s); hh = hh*fext.height*cairo_font_line_spacing; @@ -2098,25 +2100,25 @@ int text_bbox(const char *str, double xscale, double yscale, *rx1=x1;*ry1=y1; if(hcenter) { - if(rot==0 && flip == 0) { *rx1-= ww*zoom/2;} - if(rot==1 && flip == 0) { *ry1-= ww*zoom/2;} - if(rot==2 && flip == 0) { *rx1+= ww*zoom/2;} - if(rot==3 && flip == 0) { *ry1+= ww*zoom/2;} - if(rot==0 && flip == 1) { *rx1+= ww*zoom/2;} - if(rot==1 && flip == 1) { *ry1+= ww*zoom/2;} - if(rot==2 && flip == 1) { *rx1-= ww*zoom/2;} - if(rot==3 && flip == 1) { *ry1-= ww*zoom/2;} + if (rot==0 && flip == 0) { *rx1-= ww*zoom/2;} + else if(rot==1 && flip == 0) { *ry1-= ww*zoom/2;} + else if(rot==2 && flip == 0) { *rx1+= ww*zoom/2;} + else if(rot==3 && flip == 0) { *ry1+= ww*zoom/2;} + else if(rot==0 && flip == 1) { *rx1+= ww*zoom/2;} + else if(rot==1 && flip == 1) { *ry1+= ww*zoom/2;} + else if(rot==2 && flip == 1) { *rx1-= ww*zoom/2;} + else if(rot==3 && flip == 1) { *ry1-= ww*zoom/2;} } if(vcenter) { - if(rot==0 && flip == 0) { *ry1-= hh*zoom/2;} - if(rot==1 && flip == 0) { *rx1+= hh*zoom/2;} - if(rot==2 && flip == 0) { *ry1+= hh*zoom/2;} - if(rot==3 && flip == 0) { *rx1-= hh*zoom/2;} - if(rot==0 && flip == 1) { *ry1-= hh*zoom/2;} - if(rot==1 && flip == 1) { *rx1+= hh*zoom/2;} - if(rot==2 && flip == 1) { *ry1+= hh*zoom/2;} - if(rot==3 && flip == 1) { *rx1-= hh*zoom/2;} + if (rot==0 && flip == 0) { *ry1-= hh*zoom/2;} + else if(rot==1 && flip == 0) { *rx1+= hh*zoom/2;} + else if(rot==2 && flip == 0) { *ry1+= hh*zoom/2;} + else if(rot==3 && flip == 0) { *rx1-= hh*zoom/2;} + else if(rot==0 && flip == 1) { *ry1-= hh*zoom/2;} + else if(rot==1 && flip == 1) { *rx1+= hh*zoom/2;} + else if(rot==2 && flip == 1) { *ry1+= hh*zoom/2;} + else if(rot==3 && flip == 1) { *rx1-= hh*zoom/2;} } @@ -2158,25 +2160,25 @@ int text_bbox(const char * str,double xscale, double yscale, else *rx1-=nocairo_vert_correct; if(hcenter) { - if(rot==0 && flip == 0) { *rx1-= w/2;} - if(rot==1 && flip == 0) { *ry1-= w/2;} - if(rot==2 && flip == 0) { *rx1+= w/2;} - if(rot==3 && flip == 0) { *ry1+= w/2;} - if(rot==0 && flip == 1) { *rx1+= w/2;} - if(rot==1 && flip == 1) { *ry1+= w/2;} - if(rot==2 && flip == 1) { *rx1-= w/2;} - if(rot==3 && flip == 1) { *ry1-= w/2;} + if (rot==0 && flip == 0) { *rx1-= w/2;} + else if(rot==1 && flip == 0) { *ry1-= w/2;} + else if(rot==2 && flip == 0) { *rx1+= w/2;} + else if(rot==3 && flip == 0) { *ry1+= w/2;} + else if(rot==0 && flip == 1) { *rx1+= w/2;} + else if(rot==1 && flip == 1) { *ry1+= w/2;} + else if(rot==2 && flip == 1) { *rx1-= w/2;} + else if(rot==3 && flip == 1) { *ry1-= w/2;} } if(vcenter) { - if(rot==0 && flip == 0) { *ry1-= h/2;} - if(rot==1 && flip == 0) { *rx1+= h/2;} - if(rot==2 && flip == 0) { *ry1+= h/2;} - if(rot==3 && flip == 0) { *rx1-= h/2;} - if(rot==0 && flip == 1) { *ry1-= h/2;} - if(rot==1 && flip == 1) { *rx1+= h/2;} - if(rot==2 && flip == 1) { *ry1+= h/2;} - if(rot==3 && flip == 1) { *rx1-= h/2;} + if (rot==0 && flip == 0) { *ry1-= h/2;} + else if(rot==1 && flip == 0) { *rx1+= h/2;} + else if(rot==2 && flip == 0) { *ry1+= h/2;} + else if(rot==3 && flip == 0) { *rx1-= h/2;} + else if(rot==0 && flip == 1) { *ry1-= h/2;} + else if(rot==1 && flip == 1) { *rx1+= h/2;} + else if(rot==2 && flip == 1) { *ry1+= h/2;} + else if(rot==3 && flip == 1) { *rx1-= h/2;} } ROTATION(0.0,0.0,w,h,(*rx2),(*ry2)); diff --git a/src/draw.c b/src/draw.c index 321adb9a..651d6728 100644 --- a/src/draw.c +++ b/src/draw.c @@ -267,7 +267,7 @@ void cairo_draw_string_line(cairo_t *ctx, char *s, if(s==NULL) return; if(llength==0) return; cairo_text_extents(ctx, s, &ext); - xadvance = ext.x_advance; + xadvance = ext.x_advance > ext.width? ext.x_advance : ext.width; line_delta = lineno*fontheight*cairo_font_line_spacing; lines = (cairo_lines-1)*fontheight*cairo_font_line_spacing; @@ -320,7 +320,7 @@ void draw_string(int layer, int what, const char *s, int rot, int flip, int hcen size = xscale*52.*cairo_font_scale; /*fprintf(errfp, "size=%.16g\n", size*mooz); */ if(size*mooz<3.0) return; /* too small */ - if(size*mooz>800) return; /* too big */ + if(size*mooz>1600) return; /* too big */ text_bbox(s, xscale, yscale, rot, flip, hcenter, vcenter, x,y, &textx1,&texty1,&textx2,&texty2); if(!textclip(areax1,areay1,areax2,areay2,textx1,texty1,textx2,texty2)) { @@ -1585,22 +1585,22 @@ void draw(void) { if(draw_single_layer!=-1 && c != draw_single_layer) continue; /* 20151117 */ - for(i=0;i= cadlayers) textlayer = TEXTLAYER; dbg(1, "draw(): drawing string %d = %s\n",i, textelement[i].txt_ptr); #ifdef HAS_CAIRO + if(!enable_layer[textlayer]) continue; textfont = textelement[i].font; /* 20171206 */ if( (textfont && textfont[0]) || textelement[i].flags) { cairo_font_slant_t slant; diff --git a/src/xschem.tcl b/src/xschem.tcl index 6aaf3bd9..18c01fde 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -3610,7 +3610,7 @@ font configure Underline-Font -underline true -size 24 color_dim xschem color_dim } - .menubar.zoom.menu add command -label "Symbol visible layers" -accelerator {} -command { + .menubar.zoom.menu add command -label "Visible layers" -accelerator {} -command { select_layers xschem redraw } diff --git a/xschem_library/examples/0_examples_top.sch b/xschem_library/examples/0_examples_top.sch index e5fe6729..95a2ab9f 100644 --- a/xschem_library/examples/0_examples_top.sch +++ b/xschem_library/examples/0_examples_top.sch @@ -1,5 +1,6 @@ v {xschem version=2.9.7 file_version=1.2} G {} +K {} V {} S {} E {} @@ -36,13 +37,13 @@ T {Components} 1010 -210 0 0 0.6 0.6 {layer=4} T {TEXT} 890 -620 0 0 0.5 0.5 {layer=8} T {TEXT} 890 -670 1 0 0.7 0.7 {layer=6 font=FreeMono} T {Text} 900 -660 0 0 0.5 0.5 {layer=7 font="Times"} -T {TEXT} 990 -660 1 0 0.5 0.5 {} +T {TEXT} 990 -660 1 0 0.5 0.5 {weight=bold} T {Text} 1010 -650 0 0 0.6 0.6 {layer=4} T {Arcs/Circles} 1010 -120 0 0 0.6 0.6 {layer=4} T {Select the components here under and press'-h' or -click them to visit xschem websites -or local docs} 400 -360 0 0 0.3 0.3 {} +or local docs} 400 -360 0 0 0.3 0.3 {slant=oblique } N 870 -300 990 -300 {lab=#net1} N 910 -340 910 -250 {lab=#net2} N 910 -270 970 -270 {lab=#net2}