Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/layout/reftests/svg/sizing/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 2 kB image not shown  

Quelle  svg-image-util.js   Sprache: JAVA

 
/**
 * Reusable SVG data uri prefix for generated SVGs.
 */

const SVG_DATA_URI_PREFIX = 'data:image/svg+xml,
/**
 * Reusable SVG data uri suffix for generated SVGs.
 */

const SVG_DATA_URI_SUFFIX = '>';

/**
 * Generates full data URI for an SVG document, with the given parameters
 * on the SVG element.
 *
 * @param aWidth    The width attribute, or null for no width.
 * @param aHeight   The height attribute, or null for no height.
 * @param aViewbox  The viewBox attribute, or null for no viewBox.
 */

function generateSVGDataURI(aWidth, aHeight, aViewBox) {
  let datauri = SVG_DATA_URI_PREFIX;

  if (aWidth) {
    datauri += " width=\"" + aWidth + "\""
  }

  if (aHeight) {
    datauri += " height=\"" + aHeight + "\"";
  }

  if (aViewBox) {
    datauri += " viewBox=\"" + aViewBox + "\"";
  }

  datauri += SVG_DATA_URI_SUFFIX;

  return datauri;
}

/**
 * Generates a canvas, with the given width and height parameters, and uses
 * CanvasRenderingContext2D.drawImage() to draw a SVG image with the given
 * width and height attributes.
 *
 * @param aCanvasWidth      The width attribute of the canvas.
 * @param aCanvasHeight     The height attribute of the canvas.
 * @param aSVGWidth         The width attribute of the svg, or null for no width.
 * @param aSVGHeight        The height attribute of the svg, or null for no height.
 * @param aSVGViewBox       The viewBox attribute sf the svg, or null for no viewBox.
 *
 * @returns A promise that resolves when the SVG image has been drawn to the
 *          created canvas
 */

async function generateCanvasDrawImageSVG(aCanvasWidth, aCanvasHeight, aSVGWidth,
                                          aSVGHeight, aSVGViewBox) {
    let canvas = document.createElement("canvas");
    let ctx = canvas.getContext("2d");
    document.body.appendChild(canvas);

    canvas.setAttribute("width", aCanvasWidth);
    canvas.setAttribute("height", aCanvasHeight);

    let img = document.createElement("img");

    let promise = new Promise(resolve => {
      img.onload = () => {
        ctx.drawImage(img, 0, 0);
        resolve();
      };
    });

    let uri = generateSVGDataURI(aSVGWidth, aSVGHeight, aSVGViewBox);
    img.src = uri;

    return promise;
}

Messung V0.5
C=95 H=89 G=91

¤ Dauer der Verarbeitung: 0.2 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.