Spaces:
Running
Running
Download scripts/test_font_offset_correction.cjs from Sarvesh213/getcert-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.9 kB
-
https://huggingface.co/spaces/Sarvesh213/getcert-backend/resolve/main/scripts/test_font_offset_correction.cjs
- Command line
-
hf download hf://spaces/Sarvesh213/getcert-backend/scripts/test_font_offset_correction.cjs
-
curl -L -o test_font_offset_correction.cjs https://huggingface.co/spaces/Sarvesh213/getcert-backend/resolve/main/scripts/test_font_offset_correction.cjs
1.9 kB
| const { chromium } = require('playwright'); | |
| const fs = require('fs'); | |
| const { execSync } = require('child_process'); | |
| (async () => { | |
| const browser = await chromium.launch({ headless: true }); | |
| const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } }); | |
| await page.goto('http://127.0.0.1:5173/preview-certificate'); | |
| await page.waitForTimeout(2000); | |
| // Hook in page with refined baseline correction | |
| await page.evaluate(() => { | |
| const origFillText = CanvasRenderingContext2D.prototype.fillText; | |
| CanvasRenderingContext2D.prototype.fillText = function(text, x, y, maxWidth) { | |
| let correctedY = y; | |
| const match = this.font.match(/([\d.]+)px/); | |
| if (match) { | |
| const fontSize = parseFloat(match[1]); | |
| let shift; | |
| if (fontSize >= 36) { | |
| shift = fontSize * 0.44; | |
| } else if (fontSize >= 24) { | |
| shift = fontSize * 0.46; | |
| } else if (fontSize >= 16) { | |
| shift = fontSize * 0.52; | |
| } else { | |
| shift = fontSize * 0.78; | |
| } | |
| correctedY = y - shift; | |
| } | |
| return origFillText.call(this, text, x, correctedY, maxWidth); | |
| }; | |
| }); | |
| // Trigger PDF export | |
| const [ download ] = await Promise.all([ | |
| page.waitForEvent('download'), | |
| page.click('#btn-download-pdf') | |
| ]); | |
| const pdfPath = '/home/grim/.gemini/antigravity/brain/780fc6f2-0ee4-4d27-a3c9-d81026488398/corrected_test_v3.pdf'; | |
| await download.saveAs(pdfPath); | |
| execSync(`pdftoppm -png -r 150 "${pdfPath}" "/home/grim/.gemini/antigravity/brain/780fc6f2-0ee4-4d27-a3c9-d81026488398/corrected_pdf_v3"`); | |
| fs.renameSync('/home/grim/.gemini/antigravity/brain/780fc6f2-0ee4-4d27-a3c9-d81026488398/corrected_pdf_v3-1.png', '/home/grim/.gemini/antigravity/brain/780fc6f2-0ee4-4d27-a3c9-d81026488398/corrected_pdf_v3.png'); | |
| console.log('Saved corrected_pdf_v3.png'); | |
| await browser.close(); | |
| })(); | |