function addSquare(PDF, square, left, maxwidth) {
  const SQUARE_SIZE = parseInt(
      document.querySelector("[name=size]:checked").value
  );
  const PAPER_SEL = document.querySelector("#paper option:checked");
  const PAGE_WIDTH = parseFloat(PAPER_SEL.dataset.pagewidth);

  const WIDTH = Math.min(SQUARE_SIZE, maxwidth);
  const TOP_MARGIN = 1.25;
  const LEFT_MARGIN = (PAGE_WIDTH - WIDTH) / 2;
  const OUTLINE_WIDTH = 0.02;

  const LEFT_PX = (left / SQUARE_SIZE) * square.naturalWidth;
  const WIDTH_PX = (WIDTH / SQUARE_SIZE) * square.naturalWidth;

  PDF.setFillColor(204, 204, 204);
  PDF.rect(
    LEFT_MARGIN - OUTLINE_WIDTH,
    TOP_MARGIN - OUTLINE_WIDTH,
    WIDTH + (2 * OUTLINE_WIDTH),
    SQUARE_SIZE + (2 * OUTLINE_WIDTH),
    "F"
  );

  PDF.addImage(
    slice(square, LEFT_PX, WIDTH_PX),
    "JPEG",
    LEFT_MARGIN,
    TOP_MARGIN,
    WIDTH,
    SQUARE_SIZE,
    "",
    "NONE"
  );
}
/**
  * @desc adds square or slice of a square to the PDF.
  * @param PDF jsPDF - jsPDF Object
  * @param square image - input image square
  * @param left int- start of left edge of slice in CM
  * @param maxWidth int- max width in CM
*/
@desc adds square or slice of a square to the PDF.
@param PDF jsPDF - jsPDF Object
@param square image - input image square
@param left int- start of left edge of slice in CM
@param maxWidth int- max width in CM
@desc adds square or slice of a square to the PDF . @param PDF jsPDF - jsPDF Object @param square image - input image square @param left int - start of left edge of slice in CM @param maxWidth int - max width in CM
function addSquare(PDF, square, left, maxwidth) {
  const SQUARE_SIZE = parseInt(
      document.querySelector("[name=size]:checked").value
  );
  const PAPER_SEL = document.querySelector("#paper option:checked");
  const PAGE_WIDTH = parseFloat(PAPER_SEL.dataset.pagewidth);
  const WIDTH = Math.min(SQUARE_SIZE, maxwidth);
  const TOP_MARGIN = 1.25;
  const LEFT_MARGIN = (PAGE_WIDTH - WIDTH) / 2;
  const OUTLINE_WIDTH = 0.02;
  const LEFT_PX = (left / SQUARE_SIZE) * square.naturalWidth;
  const WIDTH_PX = (WIDTH / SQUARE_SIZE) * square.naturalWidth;
  PDF.setFillColor(204, 204, 204);
  PDF.rect(
    LEFT_MARGIN - OUTLINE_WIDTH,
    TOP_MARGIN - OUTLINE_WIDTH,
    WIDTH + (2 * OUTLINE_WIDTH),
    SQUARE_SIZE + (2 * OUTLINE_WIDTH),
    "F"
  );
  PDF.addImage(
    slice(square, LEFT_PX, WIDTH_PX),
    "JPEG",
    LEFT_MARGIN,
    TOP_MARGIN,
    WIDTH,
    SQUARE_SIZE,
    "",
    "NONE"
  );
}
function addSquare ( PDF , square , left , maxwidth ) { const SQUARE_SIZE = parseInt ( document . querySelector ( "[name=size]:checked" ) . value ) ; const PAPER_SEL = document . querySelector ( "#paper option:checked" ) ; const PAGE_WIDTH = parseFloat ( PAPER_SEL . dataset . pagewidth ) ; const WIDTH = Math . min ( SQUARE_SIZE , maxwidth ) ; const TOP_MARGIN = 1.25 ; const LEFT_MARGIN = ( PAGE_WIDTH - WIDTH ) / 2 ; const OUTLINE_WIDTH = 0.02 ; const LEFT_PX = ( left / SQUARE_SIZE ) * square . naturalWidth ; const WIDTH_PX = ( WIDTH / SQUARE_SIZE ) * square . naturalWidth ; PDF . setFillColor ( 204 , 204 , 204 ) ; PDF . rect ( LEFT_MARGIN - OUTLINE_WIDTH , TOP_MARGIN - OUTLINE_WIDTH , WIDTH + ( 2 * OUTLINE_WIDTH ) , SQUARE_SIZE + ( 2 * OUTLINE_WIDTH ) , "F" ) ; PDF . addImage ( slice ( square , LEFT_PX , WIDTH_PX ) , "JPEG" , LEFT_MARGIN , TOP_MARGIN , WIDTH , SQUARE_SIZE , "" , "NONE" ) ; }
@desc adds square or slice of a square to the PDF.
@desc adds square or slice of a square to the PDF .