@@ -48,6 +48,7 @@ async function fetchContributors() {
48
48
49
49
// Generate Certificate Button
50
50
const button = document . createElement ( "button" ) ;
51
+ button . className = "certificate-button" ;
51
52
button . textContent = "Certificate" ;
52
53
button . addEventListener ( "click" , ( ) => {
53
54
generateCertificate ( contributor . login , contributor . avatar_url ) ;
@@ -76,8 +77,11 @@ async function fetchContributors() {
76
77
ctx . fillStyle = gradient ;
77
78
ctx . fillRect ( 0 , 0 , canvas . width , canvas . height ) ;
78
79
80
+ // Get the value of the CSS variable
81
+ const primaryColor = getComputedStyle ( document . documentElement ) . getPropertyValue ( '--primary-color' ) . trim ( ) ;
82
+
79
83
// Decorative border
80
- ctx . strokeStyle = "#1da1f2" ;
84
+ ctx . strokeStyle = primaryColor ;
81
85
ctx . lineWidth = 20 ;
82
86
ctx . strokeRect ( 50 , 50 , canvas . width - 100 , canvas . height - 100 ) ;
83
87
@@ -113,12 +117,39 @@ async function fetchContributors() {
113
117
ctx . fillStyle = "white" ;
114
118
ctx . fillText ( username , canvas . width / 2 , 500 ) ;
115
119
120
+ // Function to wrap text
121
+ function wrapText ( ctx , text , x , y , maxWidth , lineHeight ) {
122
+ const words = text . split ( " " ) ;
123
+ let line = "" ;
124
+ for ( let i = 0 ; i < words . length ; i ++ ) {
125
+ const testLine = line + words [ i ] + " " ;
126
+ const metrics = ctx . measureText ( testLine ) ;
127
+ const testWidth = metrics . width ;
128
+
129
+ if ( testWidth > maxWidth && i > 0 ) {
130
+ ctx . fillText ( line , x , y ) ;
131
+ line = words [ i ] + " " ;
132
+ y += lineHeight ;
133
+ } else {
134
+ line = testLine ;
135
+ }
136
+ }
137
+ ctx . fillText ( line , x , y ) ;
138
+ }
139
+
116
140
// Certificate content
117
141
ctx . font = "35px Arial" ;
118
142
const content = `This certificate is proudly presented to ${ username } for their valuable contribution to planetoid. Keep contributing. Best wishes for their future endeavors.` ;
119
- content . split ( "\n" ) . forEach ( ( line , index ) => {
120
- ctx . fillText ( line . trim ( ) , canvas . width / 2 , 600 + index * 40 ) ;
121
- } ) ;
143
+
144
+ // Call the wrapText function to render wrapped text
145
+ const contentX = canvas . width / 2 ;
146
+ const contentY = 600 ;
147
+ const maxWidth = canvas . width - 500 ;
148
+ const lineHeight = 40 ;
149
+
150
+ ctx . textAlign = "center" ;
151
+ wrapText ( ctx , content , contentX , contentY , maxWidth , lineHeight ) ;
152
+
122
153
123
154
// Signature with decorative underline
124
155
ctx . font = "italic 30px Georgia" ;
0 commit comments