MCPcopy Index your code
hub / github.com/pythongosssss/ComfyUI-Custom-Scripts / init

Function init

web/js/workflowImage.js:502–587  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

500app.registerExtension({
501 name: "pysssss.WorkflowImage",
502 init() {
503 // https://codepen.io/peterhry/pen/nbMaYg
504 function wrapText(context, text, x, y, maxWidth, lineHeight) {
505 var words = text.split(" "),
506 line = "",
507 i,
508 test,
509 metrics;
510
511 for (i = 0; i < words.length; i++) {
512 test = words[i];
513 metrics = context.measureText(test);
514 while (metrics.width > maxWidth) {
515 // Determine how much of the word will fit
516 test = test.substring(0, test.length - 1);
517 metrics = context.measureText(test);
518 }
519 if (words[i] != test) {
520 words.splice(i + 1, 0, words[i].substr(test.length));
521 words[i] = test;
522 }
523
524 test = line + words[i] + " ";
525 metrics = context.measureText(test);
526
527 if (metrics.width > maxWidth && i > 0) {
528 context.fillText(line, x, y);
529 line = words[i] + " ";
530 y += lineHeight;
531 } else {
532 line = test;
533 }
534 }
535
536 context.fillText(line, x, y);
537 }
538
539 const stringWidget = ComfyWidgets.STRING;
540 // Override multiline string widgets to draw text using canvas while saving as svg
541 ComfyWidgets.STRING = function () {
542 const w = stringWidget.apply(this, arguments);
543 if (w.widget && w.widget.type === "customtext") {
544 const draw = w.widget.draw;
545 w.widget.draw = function (ctx) {
546 draw.apply(this, arguments);
547 const inputEl = this.inputEl ?? this.element;
548 if (!inputEl || inputEl.hidden) return;
549
550 if (getDrawTextConfig) {
551 const config = getDrawTextConfig(ctx, this);
552 const t = ctx.getTransform();
553 ctx.save();
554 if (config.resetTransform) {
555 ctx.resetTransform();
556 }
557
558 const style = document.defaultView.getComputedStyle(inputEl, null);
559 const x = config.x;

Callers

nothing calls this directly

Calls 2

wrapTextFunction · 0.85
saveMethod · 0.80

Tested by

no test coverage detected