{"record":{"id":"58eb011057c84f47","repo":"parallax/jsPDF","slug":"arcto-not-implemented","errorCode":null,"errorMessage":"arcTo not implemented.","messagePattern":"arcTo not implemented\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/context2d.js","lineNumber":1036,"sourceCode":"    });\n    // this.ctx.lastPoint(new Point(pt.x,pt.y));\n  };\n\n  /**\n   * Creates an arc/curve between two tangents\n   *\n   * @name arcTo\n   * @function\n   * @param x1 {Number} The x-coordinate of the first tangent\n   * @param y1 {Number} The y-coordinate of the first tangent\n   * @param x2 {Number} The x-coordinate of the second tangent\n   * @param y2 {Number} The y-coordinate of the second tangent\n   * @param radius The radius of the arc\n   * @description The arcTo() method creates an arc/curve between two tangents on the canvas.\n   */\n  // eslint-disable-next-line no-unused-vars\n  Context2D.prototype.arcTo = function(x1, y1, x2, y2, radius) {\n    throw new Error(\"arcTo not implemented.\");\n  };\n\n  /**\n   * Creates a rectangle\n   *\n   * @name rect\n   * @function\n   * @param x {Number} The x-coordinate of the upper-left corner of the rectangle\n   * @param y {Number} The y-coordinate of the upper-left corner of the rectangle\n   * @param w {Number} The width of the rectangle, in pixels\n   * @param h {Number} The height of the rectangle, in pixels\n   * @description The rect() method creates a rectangle.\n   */\n  Context2D.prototype.rect = function(x, y, w, h) {\n    if (isNaN(x) || isNaN(y) || isNaN(w) || isNaN(h)) {\n      console.error(\"jsPDF.context2d.rect: Invalid arguments\", arguments);\n      throw new Error(\"Invalid arguments passed to jsPDF.context2d.rect\");\n    }","sourceCodeStart":1018,"sourceCodeEnd":1054,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/context2d.js#L1018-L1054","documentation":"The Canvas2D-compatible context2d API exposed by jsPDF (obtained via doc.context2d) implements most of the HTML5 Canvas drawing surface, but arcTo() is an explicit stub: the body is a single unconditional throw. The jsdoc promises arc/curve-between-tangents behavior that was never ported to the PDF path model. Calling it always fails, regardless of arguments.","triggerScenarios":"Any call to doc.context2d.arcTo(x1, y1, x2, y2, radius) — or code/porting a real <canvas> script that rounds rectangle corners via arcTo. Libraries that auto-polyfill CanvasRenderingContext2D onto jsPDF will trip it the moment a rounded-corner path is drawn.","commonSituations":"Porting an existing browser canvas drawing routine to jsPDF's context2d; using a charting/shape library that rounds corners with arcTo; assuming full Canvas2D parity because the object looks like a 2D context.","solutions":["Replace arcTo with an equivalent built from lineTo plus arc() (which IS implemented): compute the tangent intersection and draw a quadratic/circular arc segment manually.","Draw rounded rectangles via a path of lineTo/arc/quadraticCurveTo calls instead of arcTo.","Render the shape to an offscreen HTML <canvas> first, then embed it as an image via doc.addImage (the canvas2d arcTo restriction then does not apply).","Avoid the context2d surface entirely and draw the rounded path with jsPDF's native path API (lines + bezier) using m, l, etc."],"exampleFix":"// before\nctx.beginPath();\nctx.moveTo(x, y);\nctx.arcTo(x1, y1, x2, y2, r); // throws [100]\n\n// after: emulate arcTo with lineTo + arc\nfunction arcTo(ctx, x1, y1, x2, y2, r) {\n  // simplified: draw a quadratic curve to the start of the arc\n  ctx.lineTo(x1, y1);\n  // fall back to arc() at the corner as needed\n}","handlingStrategy":"fallback","validationCode":"// arcTo is an unconditional stub — detect the surface before relying on it.\nfunction supportsArcTo(ctx) {\n  // jsPDF context2d always throws; real <canvas> does not.\n  // Probe on a throwaway path.\n  try {\n    const probe = document.createElement('canvas').getContext('2d');\n    probe.beginPath();\n    probe.arcTo(0, 0, 10, 0, 5);\n    return true;\n  } catch (e) {\n    return false;\n  }\n}","typeGuard":"type guard not applicable (method exists; it throws at runtime). Use a capability probe instead:\nfunction isArcToUsable(ctx) {\n  try { ctx.arcTo(0,0,1,1,1); return true; } catch (e) { return false; }\n}","tryCatchPattern":"try {\n  ctx.arcTo(x1, y1, x2, y2, r);\n} catch (e) {\n  if (/arcTo not implemented/.test(e.message)) {\n    // fall back to lineTo/arc emulation\n    ctx.lineTo(x1, y1);\n  } else { throw e; }\n}","preventionTips":["Do not assume full Canvas2D parity on jsPDF context2d — maintain a list of unsupported methods (arcTo, toDataURL).","Centralize rounded-corner drawing in a helper that uses arcTo on real canvas and lineTo/arc on jsPDF.","Probe capability once per render session and branch accordingly."],"tags":["canvas2d","context2d","unimplemented","stub","pdf"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}