Skip to content

Commit 12b0400

Browse files
tweak (#326)
* add widget sizes * tidy font*size/name * make sure anything measured in fixed position for stability
1 parent b31329c commit 12b0400

File tree

6 files changed

+101
-23
lines changed

6 files changed

+101
-23
lines changed

css/index.css

+6-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ div.scrollthin {scrollbar-width: thin;}
332332
#tbfp td:first-child {color: var(--test99);}
333333
#tbperf td:first-child {color: var(--test99);}
334334

335-
#lh-fp, #mathml-fp {
335+
#lh-fp, #mathml-fp, #font-fp, #form-fp, #glyph-fp {
336336
position: fixed;
337337
top: 0;
338338
left: 0;
@@ -353,6 +353,11 @@ div.scrollthin {scrollbar-width: thin;}
353353
.measureScale {
354354
transform: scale(1.1234567); /* cause decimals */
355355
}
356+
.unstyled {
357+
-moz-appearance: none;
358+
-webkit-appearance: none;
359+
appearance: none;
360+
}
356361

357362
/* TZP main */
358363
#divrect {position: fixed; padding: 8px; opacity: 0; z-index: -1;}

js/elements.js

+75-2
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,84 @@ function get_mathml(METRIC) {
179179
return
180180
}
181181

182+
function get_widget_sizes(METRIC) {
183+
let t0 = nowFn()
184+
let hash, btn ='', data = {}
185+
const id = 'form-fp'
186+
let oList = {
187+
button: '<input type="button">',
188+
checkbox: '<input type="checkbox">',
189+
checkbox_unstyled: '<input type="checkbox">',
190+
color: '<input type="color">',
191+
date: '<input type="date">',
192+
"datetime-local": '<input type="datetime-local">',
193+
details: '<details></details>',
194+
directory: '<input webkitdirectory directory type="file">',
195+
file: '<input type="file">',
196+
files: '<input multiple="" type="file">',
197+
image: '<input type="image">',
198+
number: '<input type="number">',
199+
radio: '<input type="radio">',
200+
radio_unstyled: '<input type="radio">',
201+
reset: '<input type="reset">',
202+
select: '<select><option id="Y"></option></select>',
203+
select_empty: '<select multiple=""><option></option></select>',
204+
select_empty_option: '<select multiple=""><option></option></select>',
205+
select_spaces: '<select multiple=""><option> &nbsp; &nbsp; &nbsp; </option>"</select>',
206+
select_spaces_option: '<select multiple=""><option> &nbsp; &nbsp; &nbsp; </option>"</select>',
207+
select_string: '<select multiple=""><option>Mōá?-&#xffff;</option></select>',
208+
select_string_option: '<select multiple=""><option>Mōá?-&#xffff;</option></select>',
209+
select_unstyled: '<select><option id="Y"></option></select>',
210+
submit: '<input type="submit">',
211+
time: '<input type="time">',
212+
}
213+
let width, height, x, y, range, method
214+
try {
215+
const doc = document
216+
const div = doc.createElement('div')
217+
div.setAttribute('id', id)
218+
doc.body.appendChild(div)
219+
div.classList.add('measure')
220+
div.classList.add("measureScale")
221+
let parent = dom[id]
222+
for (const k of Object.keys(oList)) {
223+
// important to clear the div so no other elements can affect measurements
224+
parent.innerHTML = ""
225+
try {
226+
parent.innerHTML = oList[k]
227+
let target = parent.firstChild
228+
target.setAttribute("style","display:inline;")
229+
if (k.includes('_unstyled')) {target.classList.add('unstyled')}
230+
if (k.includes('_option')) {target = target.lastElementChild}
231+
// method
232+
if (isDomRect > 1) {range = document.createRange(); range.selectNode(target)}
233+
if (isDomRect < 1) {method = target.getBoundingClientRect() // get a result regardless
234+
} else if (isDomRect == 1) {method = target.getClientRects()[0]
235+
} else if (isDomRect == 2) {method = range.getBoundingClientRect()
236+
} else if (isDomRect > 2) {method = range.getClientRects()[0]
237+
}
238+
data[k] = [method.width, method.height, method.x, method.y]
239+
} catch(e) {
240+
data[k] = zErr
241+
log_error(15, METRIC +'_'+ k, e)
242+
}
243+
}
244+
hash = mini(data), btn = addButton(15, METRIC)
245+
} catch(e) {
246+
hash = e; data = zErrLog
247+
}
248+
removeElementFn(id)
249+
addBoth(15, METRIC, hash, btn,'', data, (isDomRect == -1))
250+
log_perf(15, METRIC, t0)
251+
return
252+
}
253+
182254
const outputElements = () => new Promise(resolve => {
183255
Promise.all([
184256
get_element_keys('htmlelement_keys'),
185-
get_lineheight('line-height'),
186-
get_mathml('mathml'),
257+
get_lineheight('line-height_sizes'),
258+
get_mathml('mathml_sizes'),
259+
get_widget_sizes('widget_sizes'),
187260
]).then(function(){
188261
return resolve()
189262
})

js/fonts.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ function get_document_fonts(METRIC) {
625625
return
626626
}
627627

628-
const get_font_sizes = (isMain = true) => new Promise(resolve => {
628+
const get_font_sizes = (isMain = true, METRIC = 'font_sizes') => new Promise(resolve => {
629629
/* getDimensions code based on https://github.com/abrahamjuliot/creepjs */
630630
const id = 'font-fp'
631631
try {
@@ -703,7 +703,7 @@ const get_font_sizes = (isMain = true) => new Promise(resolve => {
703703
const transform = style.transformOrigin.split(' ')
704704
const perspective = style.perspectiveOrigin.split(' ')
705705
const dimensions = {
706-
// keep in order for fontsizes_base_reported
706+
// keep in order for font_sizes_base_reported
707707
clientHeight: span.clientHeight,
708708
clientWidth: span.clientWidth,
709709
domrectboundingHeight: span.getBoundingClientRect().height,
@@ -868,7 +868,7 @@ const get_font_sizes = (isMain = true) => new Promise(resolve => {
868868
if (error !== undefined) {
869869
item[1].clear()
870870
item[1].add(zErr)
871-
addDisplay(12, name, log_error(12, 'fontsizes_'+ (name.slice(5).toLowerCase()), error))
871+
addDisplay(12, name, log_error(12, METRIC +'_'+ (name.slice(5).toLowerCase()), error))
872872
}
873873
})
874874

@@ -947,7 +947,7 @@ const get_font_sizes = (isMain = true) => new Promise(resolve => {
947947
if (error !== undefined) {
948948
item[1].clear()
949949
item[1].add(zErr)
950-
addDisplay(12, name, log_error(12, 'fontsizes_'+ (name.slice(5).toLowerCase()), error))
950+
addDisplay(12, name, log_error(12, METRIC +'_'+ (name.slice(5).toLowerCase()), error))
951951
delete fntBasesValid[name]
952952
}
953953
})
@@ -986,17 +986,16 @@ const get_font_sizes = (isMain = true) => new Promise(resolve => {
986986
fontsDomRectClientRange,
987987
})
988988
} catch(e) {
989-
if (isMain) {log_error(12, 'fontsizes', e)} else {console.error(e)}
989+
if (isMain) {log_error(12, METRIC, e)} else {console.error(e)}
990990
return resolve(zErr)
991991
}
992992
})
993993

994-
function get_fonts() {
994+
function get_fonts(METRIC) {
995995
let t0 = nowFn()
996-
const METRIC = 'fontsizes'
997996
const METRICG = METRIC +'_groups'
998997
const METRICB = METRIC +'_base'
999-
const METRICN = 'fontnames'
998+
const METRICN = 'font_names'
1000999
let badnotation = isTB ? tb_red : rfp_red
10011000
let goodnotation = isTB ? tb_green : rfp_green
10021001
let oDomList = {
@@ -1078,7 +1077,7 @@ function get_fonts() {
10781077
//console.log(res)
10791078
let firstBaseFont = fntData['control_name'][0]
10801079
let oData = {}, oValid = {}
1081-
// note: do not sort: these are fontnames:size and fntList was already sorted
1080+
// note: do not sort: these are font_names:size and fntList was already sorted
10821081
for (let name in res) {
10831082
let data = res[name]
10841083
if (data.length > 1 && data[0] !== zErr) { // non-errors
@@ -1782,7 +1781,7 @@ const outputFonts = () => new Promise(resolve => {
17821781
Promise.all([
17831782
get_document_fonts('document_fonts'), // sets fntDocEnabled
17841783
get_script_defaults('script_defaults'),
1785-
get_fonts(), // uses fntDocEnabled
1784+
get_fonts('font_sizes'), // uses fntDocEnabled
17861785
get_system_fonts('moz_fonts'),
17871786
get_system_fonts('system_fonts'),
17881787
get_widget_fonts('widget_fonts'),

js/generic.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,6 @@ function get_isDomRect() {
687687
if (runSL) {aDomRect = [false, false, false, false]}
688688
isDomRect = aDomRect.indexOf(true)
689689
//console.log(isDomRect, aDomRect)
690-
691690
log_perf(SECTP, "isDomRect",t0,"", aDomRect.join(", ") +" | "+ isDomRect)
692691
return
693692
}
@@ -1039,8 +1038,8 @@ function lookup_health(sect, metric, scope, isPass) {
10391038
let typeCheck = typeFn(data, true)
10401039
hash = data
10411040
// handle sDetailTemp: copy per run so it doesn't change in gData
1042-
if ('fontnames' == metric) {sDetailTemp = sDetail[scope]['fontnames_health']}
10431041
if (undefined !== sDetail[scope][metric]) {sDetailTemp = sDetail[scope][metric]}
1042+
if ('font_names' == metric) {sDetailTemp = sDetail[scope]['font_names_health']}
10441043
if (undefined !== sDetailTemp) {
10451044
let tmpCheck = typeFn(sDetailTemp)
10461045
if ('object' == tmpCheck) {

js/globals.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ let sectionOrder = [], // numerical order for objects
1414
sectionNos = {} // lookup numbers by name
1515

1616
// ToDo: expand: some info can go into lies but we could create new items such as methods/tampered-data
17-
// some 'methods/entropy' are in the FP: e.g. canvas/domrect or errors e.g. fontsizes
17+
// some 'methods/entropy' are in the FP: e.g. canvas/domrect or errors e.g. font sizes
1818
const btnList = ['alerts', 'errors', 'lies']
1919

2020
const jsFilesExpected = 14,
2121
gSectionsExpected = 16,
22-
expectedMetrics = 150
22+
expectedMetrics = 151
2323
let jsFiles = 0, gCount = 0, gCountTiming = 0
2424

2525
// global

tzp.html

+8-6
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<div class="cssGraphite" style="font-size: 300px;"><span id="testGraphite">+</span><span id="ctrlGraphite">-</span></div>
4848
<div id="elementFS" width=0 height=0></div>
4949
<div id='divDPI' style='height: 1in; width: 1in;'></div>
50-
<div class="normalized">
50+
<div id='glyph-fp' class="normalized">
5151
<div id="ugDiv"><span id="ugSpan"><span id="ugSlot"></span></span></div>
5252
<div><canvas id="ugCanvas"></canvas></div>
5353
<div><span id="dfsize"></span></div>
@@ -709,10 +709,10 @@
709709
</td></tr>
710710
<!--fonts-->
711711
<tr><td></td><td><span class="s12">fonts</span></td></tr>
712-
<tr><td>[groups] fonts <sup>3</sup></td><td class="c mono" id="fontsizes_groups"></td></tr>
712+
<tr><td>[groups] fonts <sup>3</sup></td><td class="c mono" id="font_sizes_groups"></td></tr>
713713
<tr><td><span id="labelF" class="btn btn0" onClick="togglerows('F','btn')">[ show ]</span>
714714
[sizes | names] fonts <sup>3</sup></td>
715-
<td class="mono"><span class="c" id="fontsizes"></span> | <span class="c" id="fontnames"></span></td>
715+
<td class="mono"><span class="c" id="font_sizes"></span> | <span class="c" id="font_names"></span></td>
716716
</tr>
717717
<tr class="togF"><td>client</td><td class="c mono" id="fontsClient"></td></tr>
718718
<tr class="togF"><td>offset</td><td class="c mono" id="fontsOffset"></td></tr>
@@ -730,7 +730,7 @@
730730
<tr class="togF"><td>client</td><td class="c mono" id="fontsDomRectClient"></td></tr>
731731
<tr class="togF"><td>client range</td><td class="c mono border-bottom" id="fontsDomRectClientRange"></td></tr>
732732

733-
<tr><td>[base sizes] fonts <sup>3</sup></td><td class="c mono" id="fontsizes_base"></td></tr>
733+
<tr><td>[base sizes] fonts <sup>3</sup></td><td class="c mono" id="font_sizes_base"></td></tr>
734734
<tr><td>[moz] fonts</td><td class="c mono" id="moz_fonts"></td></tr>
735735
<tr><td>[system] fonts</td><td class="c mono" id="system_fonts"></td></tr>
736736
<tr><td>[widget] fonts</td><td class="c mono" id="widget_fonts"></td></tr>
@@ -859,10 +859,12 @@
859859
&nbsp; DOMRect</td><td class="c mono" id="domrect"></td></tr>
860860
<tr><td>HTMLElement keys <sup>1</sup></td><td class="c mono" id="htmlelement_keys"></td></tr>
861861
<tr><td><a class="blue" href="tests/lineheight.html" target="blank">[PoC]</a>
862-
&nbsp; line-height</td><td class="c mono" id="line-height"></td></tr>
862+
&nbsp; line-height</td><td class="c mono" id="line-height_sizes"></td></tr>
863863
<tr><td><div class="ttip"><span class="icon">[ i ]</span>
864864
<span class="ttxt">mathml.disabled</span></div>
865-
&nbsp; mathml</td><td class="c mono" id="mathml"></td></tr>
865+
&nbsp; mathml</td><td class="c mono" id="mathml_sizes"></td></tr>
866+
<tr><td><a class="blue" href="tests/elementforms.html" target="blank">[PoC]</a>
867+
&nbsp; widgets</td><td class="c mono" id="widget_sizes"></td></tr>
866868
<tr><td colspan="2"><span class="no_color">code by </span><a target="_blank" class="blue"
867869
href="https://github.com/abrahamjuliot/creepjs">CreepJS</a> <sup>1</sup>
868870
</td></tr>

0 commit comments

Comments
 (0)