I need to fairly accurately determine the height of the height of the text in my svg elements, unfortunately everything i try to use bounding box and the height i get from this, it's always returns a height that is too big at bigger fonts.
Is there a way to get a more accurate measurement of text height one that is more dependent on the text within my elements.
Related
I'm working on an Illustrator script (javascript) and I need to measure the width of a letter. This letter is a TextFrameItem with only one character:
The object has an attribute .width which gives the width of the bounding box above.
The length I need to know is the one of the blue baseline.
Any idea to measure it?
The only reliable way I have found to get the width of text is to rasterize the textlayer (dup a copy if you need to retain the original textlayer for later) and then work off the bounds of the rasterized layer.
Is this possible to calculate height of the text BEFORE it is inserted into DOM?
Width of the div container is known, but I need a way to calculate its height before it is inserted.
The heights of the one line of text is also known (css), so the height could be calculated by multiplying the height of one line by the amount of lines, but the question is if this is possible to calculated BEFORE it's DOM.
Since your question explicitly requires the text not to be inserted into the dom this precludes the usually used method of simply inserting it outside the viewport and then measuring there.
An alternative approach: The canvas 2D rendering context's measureText function which can be used to determine the width if you know which styling (font width) will apply in advance.
Some advanced CSS rules such as letter-spacing may make those results inaccurate.
I want my nodes to be rectangular, with text content inside the rectangle. That much I can do, however I would like the rectangle to size appropriately to the width of the text. Can that be done?
This is planned for 2.4, but I don't know whether I'll be able to devote the time to it in the near future: https://github.com/cytoscape/cytoscape.js/issues/649
I am trying to learn and make a reference for myself but i can't find correct, enough, and not so confusing information. So tell me how to find the width of these..
Assume there is DOM element with 10px padding all around, border 5px all around, margin 30 px all around, and content that is too long for it so has scroll bars.
Find widths using javascript...
upto Margin.
upto Border.
Inside Border Padding and plus vertical scroll bar if present.
upto padding excluding vertical scrollbar if present.
upto content only that is visible. (no scrollBar, padding, border, margin, extra content)
upto content that's visible and hidden in scrollable area and with padding
upto content that's visible and hidden in scrollable area and with out padding
Javascript as too many unintuitive catches so please make it clear once and for all.
So far I have gotten this:
unknown
element.offsetWidth
unknown
element.clientWidth
unknown ( css width ?)
element.scrollWidth (see below)
unknown
only workarounds that i know are using lots of javascript to get computed values and then calculate all of these manually..but maybe there are builtin functions or better way to find things.
more Problems:
scrollWidth includes only left padding..shouldn't it either include both or none or at least have other options that do. LINK
box Sizing to border box changes the whole world and every question above needs to be answered again for that. For example for 5 css width property won't be true anymore.
There is no one function that will solve what you're asking for.
.outerWidth() will give the the size of an element, padding, borders, contained content and all. It will not however give you the margin of the element. Using the .outerWidth(true) parameter will give you the width of the element including the margin.
.innerWidth() will give you the width of the element. It is the total width of the content in the element plus the padding, but not the border,
If for some reason you want to know the difference between the inner and outer widths. Which is pretty much the border width or the difference between the edge of the border and the margins just subtract them from one another.
$widthDif = outerWidth(."Somethng") - .innerWidth('.something');
The inner and outer width function are mirrored and work the exact same for height.
Generally if you use .innerWidth() on something like the main body element it returns the width of the document minus the scroll bar because the scroll-bar is not part of the content view port.
Inside of an element is another story.
Best thing I could find in a google search was another StackOverflow question. Which outline rendering and element to 100% width inside of the scrollable element, getting its width and then deleting the element since it is unneeded. Getting the height of something minus a horizontal scrollbar could be found the same way. However once you have a vertical and horizontal scrollbar at the same time things could/would get complicated because the 100% height or width element could expand beyond what is in the view-able space depending on how the content is rendered into the element with the scrollbars.
See this example http://jsfiddle.net/37aMB/15/
If you resize the area at some points image will have have space at bottom and some time right side container will have space at bottom.
I want to make everything in proportion and with equality. Red backgeound should never be seen
You may try to set fixed size for this banner, and then manipulate zoom style attribute.
Here is modified example. It's not pixel perfect yet, but I have the impression it scales better.