Javascript - Get real letter width and height (without line-height) -


A font-family: Arial font-size: 396.55

Adobe Illustrator (or Photoshop) PT measurement: - Width: 93.8 mm (266 px) - Height: 100.2 mm (284 px)

Measuring in Javascript: - Width: 265px (matches, right) - Height: 456px No, the height of the line is caught, and this is wrong)

How can I get the exact height of the letter?

  // 6pt ----------- ----- 8px // 96px --------------- 25.4 mm Var arial_A_upper_pt = jQuery ("# ​​arial_A_upper_pt") Html (); jQuery ("# ​​arial_A_upper") HTML ('A'). JQuery ("# ​​arial_A_upper"). CSS ("font-size", arial_A_upper_pt + "px"); Var arial_A_upper_width_on_px = jQuery ("# ​​arial_A_upper"). Width (); // px // var arial_A_upper_width_on_mm = ((arial_A_upper_width_on_px * 25.4) / 96); // arial_A_upper_width_on_mm = arial_A_upper_width_on_mm.toFixed (2); JQuery ("# ​​arial_A_upper_width"). Html (arial_A_upper_width_on_px + "px"); Var arial_A_upper_height_on_px = jQuery ("# ​​arial_A_upper") height (); // px // var arial_A_upper_height_on_mm = ((arial_A_upper_height_on_px * 25.4) / 96); // arial_A_upper_height_on_mm = arial_A_upper_height_on_mm.toFixed (2); JQuery ("# ​​arial_A_upper_height"). Html (arial_A_upper_height_on_px + "px"); Example:  

I need it:

This is a question, it has not been answered easily. I can guarantee a lot that there is no such property which you can call to get value.

First of all, the data is embedded into the font file, and probably by JS (please correct me if I am wrong). The second value is just in almost every font file.

However, you can use a small math to get a closer approximation on the shape.

The size of a letter is measured, below the top of the peak, it is also called EM, both of them are horizontally and vertically used. Size of large letters is sometimes called EM Is normalized as being 2/3.

Therefore, because the height of jQuery is false, but the width is correct. (EM-size, not the actual width, if you measure it: D) ​​I will do something like this: var EM_height = jQuery ("# ​​arial_A_upper") width () var uppercase_height = Math.floor (EM_height / 3 * 2)

JS is not my strong side, so someone can probably say, if there is a better way.

You can get better value, if you know that it will be used only on a special font such as ARIL.

For example 72pt Ariel 51.37pt solution on uppercase A on my computer

51,37 / 72 = 0,713472222 so that you need to come up with the ratio. So 7/10 is probably a good suggestion.

Hope that helps a little.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -