新增3.4版本支持
This commit is contained in:
1 parent
4c5033d2f9
commit
9635428f78
21 files changed
+5425
-51
No files matched your search
+17
-1
@@ -11,4 +11,20 @@ function dataUrl() {
|
||||
return cachedDataUrl;
|
||||
}
|
||||
|
||||
module.exports = { path: badgePath, dataUrl };
|
||||
function drawVersion(ctx, width, height, version) {
|
||||
if (!/^\d+\.\d+(?:\.\d+)?$/.test(String(version || ''))) return;
|
||||
const fontSize = Math.max(12, Math.round(Math.min(width, height) * 0.055));
|
||||
const margin = Math.max(10, Math.round(Math.min(width, height) * 0.03));
|
||||
ctx.save();
|
||||
try {
|
||||
ctx.font = '600 ' + fontSize + 'px sans-serif';
|
||||
ctx.textAlign = 'left'; ctx.textBaseline = 'middle';
|
||||
const boxHeight = fontSize + 12;
|
||||
const y = height - margin - boxHeight;
|
||||
ctx.fillStyle = 'rgba(0,0,0,0.65)';
|
||||
ctx.fillRect(margin, y, ctx.measureText(version).width + 16, boxHeight);
|
||||
ctx.fillStyle = '#ffffff'; ctx.fillText(version, margin + 8, y + boxHeight / 2);
|
||||
} finally { ctx.restore(); }
|
||||
}
|
||||
|
||||
module.exports = { path: badgePath, dataUrl, drawVersion };
|
||||
Reference in new issue
Block a user