skishore / makemeahanzi

Free, open-source Chinese character data
https://www.skishore.me/makemeahanzi/
Other
1.87k stars 466 forks source link

Bounding box for characters on canvas #82

Closed dhowe closed 3 years ago

dhowe commented 4 years ago

Greetings. I'm drawing characters, stroke-by-stroke on canvas2d in the browser. How do I get the bounding box for the character?

skishore commented 3 years ago

From the README:

strokes: List of SVG path data for each stroke of this character, ordered by proper stroke order. Each stroke is laid out on a 1024x1024 size coordinate system where:

Note that the y-axes DECREASES as you move downwards, which is strage! To display these paths properly, you should hide render them as follows:

<svg viewBox="0 0 1024 1024">
  <g transform="scale(1, -1) translate(0, -900)">
    <path d="STROKE[0] DATA GOES HERE"></path>
    <path d="STROKE[1] DATA GOES HERE"></path>
    ...
  </g>
</svg>