@@ -11,9 +11,8 @@ function calcFontPoint(linepoint, text, offsetx, offsety, tilt) {
11
11
linepoint [ 0 ] * text . width + offsetx ,
12
12
linepoint [ 1 ] * text . height + offsety
13
13
] ;
14
- // Adding half a line height here is technically a bug
15
- // but pcbnew currently does the same, text is slightly shifted.
16
- point [ 0 ] -= ( point [ 1 ] + text . height * 0.5 ) * tilt ;
14
+ // This approximates pcbnew behavior with how text tilts depending on horizontal justification
15
+ point [ 0 ] -= ( linepoint [ 1 ] + 0.5 * ( 1 + text . horiz_justify ) ) * text . height * tilt ;
17
16
return point ;
18
17
}
19
18
@@ -32,6 +31,7 @@ function drawtext(ctx, text, color, flip) {
32
31
return ;
33
32
}
34
33
ctx . translate ( ...text . pos ) ;
34
+ ctx . translate ( text . thickness * 0.5 , 0 ) ;
35
35
var angle = - text . angle ;
36
36
if ( text . attr . includes ( "mirrored" ) ) {
37
37
ctx . scale ( - 1 , 1 ) ;
@@ -48,13 +48,18 @@ function drawtext(ctx, text, color, flip) {
48
48
ctx . rotate ( deg2rad ( angle ) ) ;
49
49
for ( var i in txt ) {
50
50
var offsety = ( - ( txt . length - 1 ) + i * 2 ) * interline + text . height / 2 ;
51
- var lineWidth = 0 ;
52
- for ( var c of txt [ i ] ) {
53
- if ( c == '\t' ) {
51
+ var lineWidth = text . thickness + interline * tilt ;
52
+ for ( var j = 0 ; j < txt [ i ] . length ; j ++ ) {
53
+ if ( txt [ i ] [ j ] == '\t' ) {
54
54
var fourSpaces = 4 * pcbdata . font_data [ ' ' ] . w * text . width ;
55
55
lineWidth += fourSpaces - lineWidth % fourSpaces ;
56
56
} else {
57
- lineWidth += pcbdata . font_data [ c ] . w * text . width ;
57
+ if ( txt [ i ] [ j ] == '~' ) {
58
+ j ++ ;
59
+ if ( j == txt [ i ] . length )
60
+ break ;
61
+ }
62
+ lineWidth += pcbdata . font_data [ txt [ i ] [ j ] ] . w * text . width ;
58
63
}
59
64
}
60
65
var offsetx = 0 ;
@@ -71,21 +76,45 @@ function drawtext(ctx, text, color, flip) {
71
76
offsetx -= lineWidth ;
72
77
break ;
73
78
}
74
- for ( var c of txt [ i ] ) {
75
- if ( c == '\t' ) {
79
+ var inOverbar = false ;
80
+ for ( var j = 0 ; j < txt [ i ] . length ; j ++ ) {
81
+ if ( txt [ i ] [ j ] == '\t' ) {
76
82
var fourSpaces = 4 * pcbdata . font_data [ ' ' ] . w * text . width ;
77
83
offsetx += fourSpaces - offsetx % fourSpaces ;
78
84
continue ;
85
+ } else if ( txt [ i ] [ j ] == '~' ) {
86
+ j ++ ;
87
+ if ( j == txt [ i ] . length )
88
+ break ;
89
+ if ( txt [ i ] [ j ] != '~' ) {
90
+ inOverbar = ! inOverbar ;
91
+ }
92
+ }
93
+ var glyph = pcbdata . font_data [ txt [ i ] [ j ] ] ;
94
+ if ( inOverbar ) {
95
+ var overbarStart = [ offsetx , - text . height * 1.4 + offsety ] ;
96
+ var overbarEnd = [ offsetx + text . width * glyph . w , overbarStart [ 1 ] ] ;
97
+
98
+ if ( ! lastHadOverbar ) {
99
+ overbarStart [ 0 ] += text . height * 1.4 * tilt ;
100
+ lastHadOverbar = true ;
101
+ }
102
+ ctx . beginPath ( ) ;
103
+ ctx . moveTo ( ...overbarStart ) ;
104
+ ctx . lineTo ( ...overbarEnd ) ;
105
+ ctx . stroke ( ) ;
106
+ } else {
107
+ lastHadOverbar = false ;
79
108
}
80
- for ( var line of pcbdata . font_data [ c ] . l ) {
109
+ for ( var line of glyph . l ) {
81
110
ctx . beginPath ( ) ;
82
111
ctx . moveTo ( ...calcFontPoint ( line [ 0 ] , text , offsetx , offsety , tilt ) ) ;
83
- for ( var i = 1 ; i < line . length ; i ++ ) {
84
- ctx . lineTo ( ...calcFontPoint ( line [ i ] , text , offsetx , offsety , tilt ) ) ;
112
+ for ( var k = 1 ; k < line . length ; k ++ ) {
113
+ ctx . lineTo ( ...calcFontPoint ( line [ k ] , text , offsetx , offsety , tilt ) ) ;
85
114
}
86
115
ctx . stroke ( ) ;
87
116
}
88
- offsetx += pcbdata . font_data [ c ] . w * text . width ;
117
+ offsetx += glyph . w * text . width ;
89
118
}
90
119
}
91
120
ctx . restore ( ) ;
0 commit comments