Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
make HTML5 Canvas text fontSize based on text size in the page instead of Canvas resolution

In the project i have the following Textarea:

<textarea ref={textAreaRef} className='relative z-30 w-11/12 h-full font-sans text-xs bg-transparent outline-none resize-none ' />

and canvas:

 <canvas
                    id={'canvas'}
                    ref={boardRef}
                    })}
                    onMouseDown={onMouseDown}
                    onMouseUp={onMouseUp}
                    onMouseMove={throttle(onMouseMove, 15)}
                    onTouchStart={onMouseDown}
                    onTouchEnd={onMouseUp}
                    onMouseLeave={onPaletteLeave}
                    onTouchCancel={onMouseUp}
                    onTouchMove={throttle(onMouseMove, 15)}
                    width={1600}
                    height={900}
                    style={isLayer ? canvasStyle : null}
                  />

The textarea can contain text with a specific font size in pixels that changes based on user input.

The problem is that if we compare the same text with the same properties in the text area and canvas, the text imprinted in the canvas is clearly smaller than those found in the textarea.

I tried to use the page dimension ratio to try to scale up the resulting text of the canvas, but it did not give good results:

 function ratioSize(size) {
      const canvasRatio = currentCanvas.current.clientWidth / currentCanvas.current.clientHeight;
      const pageRatio = window.screen.width / window.screen.height;
      return (pageRatio * size) / canvasRatio;
    }
  }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!