Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2026-05-24 10:57:07 -07:00
parent 5c792db8f3
commit 8f12ac15fa

View File

@@ -87,9 +87,7 @@ class AnnotationHandler extends CodeContentHandler {
*/ */
private function buildSvg($metadata) { private function buildSvg($metadata) {
//Set SVG UID-ish for element IDs //Set SVG UID-ish for element IDs
$svgID = bin2hex(random_bytes(6)); $svgID = wfRandomString(12);
self::console_log($svgID, true);
self::console_log(wfRandomString(12), true);
//Check if the image to annotate has been set //Check if the image to annotate has been set
if (isset($metadata['baseImage'])) { if (isset($metadata['baseImage'])) {
@@ -101,17 +99,12 @@ class AnnotationHandler extends CodeContentHandler {
//Gather basic data //Gather basic data
$elBaseImg = ''; $elBaseImg = '';
$vbHeight = 100;
$vbWidth = 100;
if ($baseImage) { if ($baseImage) {
$imageStr = 'data:image/png;base64,' . base64_encode(file_get_contents($baseImage->getLocalRefPath())); $imageStr = 'data:image/png;base64,' . base64_encode(file_get_contents($baseImage->getLocalRefPath()));
$baseHeight = $baseImage->getHeight(); $baseHeight = $baseImage->getHeight();
$baseWidth = $baseImage->getWidth(); $baseWidth = $baseImage->getWidth();
$baseAspect = $baseHeight / $baseWidth; $baseAspect = $baseHeight / $baseWidth;
$vbWidth = 100 / sqrt($baseAspect);
$fixScale = $baseWidth / 100 * sqrt($baseAspect); $fixScale = $baseWidth / 100 * sqrt($baseAspect);
self::console_log($fixScale, true);
//$vbHeight = $baseAspect * $vbWidth;
$attrBase = array( $attrBase = array(
'class' => 'annot-base', 'class' => 'annot-base',
'preserveAspectRatio' => 'none', 'preserveAspectRatio' => 'none',
@@ -213,8 +206,8 @@ class AnnotationHandler extends CodeContentHandler {
} }
} }
$attrMaskRect = array( $attrMaskRect = array(
'width' => $vbWidth, 'width' => $baseWidth / $fixScale,
'height' => $vbHeight, 'height' => $baseHeight / $fixScale,
'fill' => 'white' 'fill' => 'white'
); );
$maskRect = Html::rawElement('rect',$attrMaskRect); $maskRect = Html::rawElement('rect',$attrMaskRect);
@@ -242,7 +235,6 @@ class AnnotationHandler extends CodeContentHandler {
$tmpFileFactory = MediaWikiServices::getInstance()->getTempFSFileFactory(); $tmpFileFactory = MediaWikiServices::getInstance()->getTempFSFileFactory();
$tmpFile = $tmpFileFactory->newTempFSFile( 'annotSvg_', 'svg' ); $tmpFile = $tmpFileFactory->newTempFSFile( 'annotSvg_', 'svg' );
//$tmpFile = TempFSFile::factory( $pageTitle, 'svg' );
if ( !$tmpFile ) { if ( !$tmpFile ) {
$status->fatal( 'svg-error-create-temp', 'Failed to create temp SVG' ); $status->fatal( 'svg-error-create-temp', 'Failed to create temp SVG' );
return; return;