apply visible layers (View->Symbol visible layers) to any object (lines. arcs, text etc),better bounding box calculation for slant text

This commit is contained in:
Stefan Schippers 2020-09-23 22:13:39 +02:00
parent 5bab41e28b
commit b7d724dcab
4 changed files with 48 additions and 44 deletions

View File

@ -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));

View File

@ -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<lastline[c];i++) {
if(enable_layer[c]) for(i=0;i<lastline[c];i++) {
if(line[c][i].bus)
drawline(c, THICK, line[c][i].x1, line[c][i].y1, line[c][i].x2, line[c][i].y2, line[c][i].dash);
else
drawline(c, ADD, line[c][i].x1, line[c][i].y1, line[c][i].x2, line[c][i].y2, line[c][i].dash);
}
for(i=0;i<lastrect[c];i++)
if(enable_layer[c]) for(i=0;i<lastrect[c];i++)
{
drawrect(c, ADD, rect[c][i].x1, rect[c][i].y1, rect[c][i].x2, rect[c][i].y2, rect[c][i].dash);
filledrect(c, ADD, rect[c][i].x1, rect[c][i].y1, rect[c][i].x2, rect[c][i].y2);
}
for(i=0;i<lastarc[c];i++)
if(enable_layer[c]) for(i=0;i<lastarc[c];i++)
{
drawarc(c, ADD, arc[c][i].x, arc[c][i].y, arc[c][i].r, arc[c][i].a, arc[c][i].b, arc[c][i].fill, arc[c][i].dash);
}
for(i=0;i<lastpolygon[c];i++) {
if(enable_layer[c]) for(i=0;i<lastpolygon[c];i++) {
/* 20180914 added fill */
drawpolygon(c, NOW, polygon[c][i].x, polygon[c][i].y, polygon[c][i].points, polygon[c][i].fill, polygon[c][i].dash);
}
@ -1717,6 +1717,7 @@ void draw(void)
if(textlayer < 0 || textlayer >= 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;

View File

@ -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
}

View File

@ -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'<Ctrl>-h' or <Ctrl>-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}