HGustavs / LenaSYS

Code Viewer and Course Organization System used in some courses at University of Skövde
57 stars 31 forks source link

Diagram text measuring functionality #9846

Open HGustavs opened 3 years ago

HGustavs commented 3 years ago

If no other smarter text measuring functionality (making a canvas and using text measuring from html5 canvas (which is used in previous diagram version) is considered too cumbersome) is found, I suggest making similar relative measuring functionality for the capital letters also... and as a stretch goal, also supporting some other font as a parameter to the measuring function.

https://github.com/HGustavs/DiagramEngine/commit/a5022cf

a19hammi commented 3 years ago

@a18nadma IIRC you were looking at this an hour ago or so.

HGustavs commented 3 years ago

The way that this type of stuff has been achieved since the 1980-s if no native measuring is available, is to go over the letters and figure out roughly how much narrower / broader each letter is compared to the standard width.

In most fonts, only a few letters differ from standard and in a rather predictable way, e.g. W is a certain proportion bigger than normal letters and M is nearly the same.

For most fonts a good-enough guess is possible without cumbersome stuff... we want something that takes up as few lines of code as possible and does not use any costly functionality.