-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
currently, the most popular fontSize/fontColor/fontStyle/font is determined by the amount of text characters that were styled with the measured font property. This favours long texts in tiny fonts (e.g. footer texts) that a reader wouldn't consider the most "dominant" texts on the page.
if we measure the pixel area consumed by a certain text node (width x height of its bounding box), we would get a more accurate measurement. furthermore we can calculate the total text area on a page and compare that to the area covered by images.
The bounding box of a text node can be calculated using range selections:
function getTextNodeBBox(textNode) {
var dims = {};
var range = document.createRange();
range.selectNode(textNode);
var rect = range.getBoundingClientRect();
if (rect.left && rect.right && rect.top && rect.bottom && rect.width && rect.height){
dims.bottom = rect.bottom;
dims.left = rect.left;
dims.right = rect.right;
dims.top = rect.top;
dims.width = rect.width;
dims.height = rect.height;
}
range.detach();
return rect;
}