Skip to content

Commit

Permalink
add font faces health + lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorin-Oakenpants authored Dec 11, 2024
1 parent 0cc2178 commit aadc947
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 16 deletions.
60 changes: 56 additions & 4 deletions js/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,12 +633,27 @@ function set_fntList() {
if ('android' == isOS) {
fntBtn = fntBtnAll
} else if (isTB) {
fntBtn = fntBtnSystem +' + '+ fntBtnBundled +' = '+ fntBtnBase +' + '+ fntBtnUnexpected +' = '+ fntBtnAll
fntBtn = fntBtnSystem +' + '+ fntBtnBundled +' = '+ fntBtnBase +' + '+ fntBtnUnexpected +' = '+ fntBtnAll
} else if ('windows' == isOS) {
fntBtn = fntBtnBase +' + '+ fntBtnBaseLang +' = '+ fntBtnFPP +' + '+ fntBtnUnexpected +' = '+ fntBtnAll
} else {
fntBtn = (isOS !== 'linux' ? fntBtnBase : '') + fntBtnAll
}
// fntBtnFaces
let fntBtnFaces = '', strface = 'font_faces_'+ isOS
if (fntFaceData.full.length) {
fntBtnUnexpected = addButton(12, strface +'_unexpected', fntFaceData.unexpected.length, 'btnc', 'lists')
fntBtnBase = addButton(12, strface +'_'+ fntListBaseName, fntFaceData.base.length, 'btnc', 'lists')
fntBtnBaseLang = addButton(12, strface +'_kLangPackFonts', fntFaceData.baselang.length, 'btnc', 'lists')
fntBtnFPP = addButton(12, strface +'_FPP', fntFaceData.fpp.length, 'btnc', 'lists')
fntBtnAll = addButton(12, strface, fntFaceData.full.length, 'btnc', 'lists')
if (isTB) {
fntBtnFaces = fntBtnBase +' + '+ fntBtnUnexpected +' = '+ fntBtnAll
} else {
fntBtnFaces = fntBtnBase +' + '+ fntBtnBaseLang +' = '+ fntBtnFPP +' + '+ fntBtnUnexpected +' = '+ fntBtnAll
}
fntBtn = fntBtnFaces +' | '+ fntBtn
}
}
}
// bail
Expand All @@ -647,13 +662,21 @@ function set_fntList() {
// fnt*Btn data
if (gRun || build) {
let str = 'fonts_'+ isOS
let strface = 'font_faces_'+ isOS
addDetail(str +'_system', fntData.system, 'lists')
addDetail(str +'_bundled', fntData.bundled, 'lists')
addDetail(str +'_'+ fntListBaseName, fntData.base, 'lists')
addDetail(str +'_kLangPackFonts', fntData.baselang, 'lists')
addDetail(str +'_FPP', fntData.fpp, 'lists')
addDetail(str +'_unexpected', fntData.unexpected, 'lists')
addDetail(str, fntData.full, 'lists')
if (fntFaceData.full.length) {
addDetail(strface +'_'+ fntListBaseName, fntFaceData.base, 'lists')
addDetail(strface +'_kLangPackFonts', fntFaceData.baselang, 'lists')
addDetail(strface +'_FPP', fntFaceData.fpp, 'lists')
addDetail(strface +'_unexpected', fntFaceData.unexpected, 'lists')
addDetail(strface, fntFaceData.full, 'lists')
}
}
}

Expand Down Expand Up @@ -712,20 +735,50 @@ const get_fontfaces = (METRIC) => new Promise(resolve => {
testLocalFontFamily(fntFaceFake),
]).then(function(res){
let value ='', data = '', btn='', notation = '', isLies = false
let fntList = fntFaceData.full
let isNotate = fntList.length > 0
// only notate if we're testing it
let badnotation = !isNotate ? '' : isTB ? tb_red : rfp_red
let goodnotation = !isNotate ? '' : isTB ? tb_green : rfp_green

try {
let test = res[0]
let fntList = fntFaceData.full
if (fntFaceFake == test) {throw zErrInvalid +'fake font detected'
} else if ('NetworkError: A network error occurred.' !== test) {throw test
} else if (0 == fntList.length) {
exit(zNA, btn, notation, data, isLies)
exit(zNA, btn, badnotation, data, isLies)
} else {
loadFonts(fntFaceData.full).then(function(results){
if (results.length) {
if (results.includes(fntFaceFake)) {isLies = true}
data = results, value = mini(results)
btn = addButton(12, METRIC, results.length)
if (fntFaceData.base.length) {
notation = goodnotation
let aNotInBase = results, aMissing = []
aNotInBase = aNotInBase.filter(x => !fntFaceData.base.includes(x))
if (isTB) {
aMissing = fntFaceData.base
aMissing = aMissing.filter(x => !results.includes(x))
}
let count = aNotInBase.length + aMissing.length
if (count > 0) {
let tmpName = METRIC +'_health', tmpobj = {}
if (aMissing.length) {tmpobj['missing'] = aMissing}
if (aNotInBase.length) {tmpobj['unexpected'] = aNotInBase}
addDetail(tmpName, tmpobj)
let brand = isTB ? (isMullvad ? 'MB' : 'TB') : 'RFP'
notation = addButton('bad', tmpName, "<span class='health'>"+ cross + '</span> '+ count +' '+ brand)
// FFP if all unexpected are in baselang then we're fpp_green
if (fntFaceData.baselang.length) {
let aNotInBaseLang = aNotInBase.filter(x => !fntFaceData.baselang.includes(x))
if (aNotInBaseLang.length == 0) {notation = fpp_green}
}
}
}
} else {
// ToDo: once we allow fontFace in TB this will always be badnotation
notation = isTB ? goodnotation : badnotation
value = 'none'
}
exit(value, btn, notation, data, isLies)
Expand Down Expand Up @@ -1269,7 +1322,6 @@ function get_fonts(METRIC) {
let notation =''
if (fntData.base.length) {
notation = goodnotation
// names: not needed in FP but include for upstream
let aNotInBase = oData[k].datafonts, aMissing = [], aMissingSystem = []
aNotInBase = aNotInBase.filter(x => !fntData.base.includes(x))
if (isTB) {
Expand Down
15 changes: 8 additions & 7 deletions js/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,22 +957,23 @@ function lookup_health(sect, metric, scope, isPass) {
data = gData[zFP][scope][sect]['metrics'][nested]['metrics'][metric]
} else if (sDetail[scope].lookup[metric] !== undefined) {
data = sDetail[scope].lookup[metric]
} else if ('font_names' == metric) {
// special case font names: not in FP / hash = full enumeration
data = sDetail[scope][metric]
hash = mini(data)
} else {
data = gData[zFP][scope][sect]['metrics'][metric]
if ('font_names' == metric) {data =''} // force font_names for next if statement
}
if (undefined !== data) {
let typeCheck = typeFn(data, true)
hash = data
hash = '' == hash ? data : hash
// handle sDetailTemp: copy per run so it doesn't change in gData
if (undefined !== sDetail[scope][metric]) {
sDetailTemp = sDetail[scope][metric]
if ('font_names' == metric && '' == data) {
// hash is always the FP: i.e full enumeration: for consistency + all/pass/fail + compares
// but detail needs to reflect isPass: can't just check for !== undefined
if (!isPass) {
// special case font names/faces: detail should reflect isPass: can't just check for !== undefined
// e.g. windows FPP will still have unexpected data (for RFP)
hash = mini(sDetailTemp)
if (!isPass) {sDetailTemp = sDetail[scope]['font_names_health']}
if ('font_faces' == metric || 'font_names' == metric) {sDetailTemp = sDetail[scope][metric +'_health']}
}
let tmpCheck = typeFn(sDetailTemp)
if ('object' == tmpCheck) {
Expand Down
8 changes: 3 additions & 5 deletions tzp.html
Original file line number Diff line number Diff line change
Expand Up @@ -714,21 +714,19 @@
<span class="c" id="fontshash"></span>
<div class="btn-right"><span class="c" id="fntBtn"></span></div>
</td></tr>
<tr><td>[test] graphite <sup>1</sup></td><td class="c mono" id="graphite"></td></tr>
<tr><td>[css | test] woff2 <sup>2</sup></td><td class="mono">
<span id="cssWoff2"></span> | <span class="c" id="woff2"></span></td></tr>
<tr><td><div class="ttip"><span class="icon">[ i ]</span>
<span class="ttxtx">browser.display.use_document_fonts</span></div>
&nbsp; document fonts</td><td class="c mono" id="document_fonts"></td></tr>
<tr><td><div class="ttip"><span class="icon">[ i ]</span>
<span class="ttxtb">layout.css.font-tech.enabled</span></div>
&nbsp; font-format | font-tech</td><td class="mono"><span class="c" id="font-format"></span> | <span class="c" id="font-tech"></span>
</td></tr>
<tr><td>[test] graphite <sup>1</sup></td><td class="c mono" id="graphite"></td></tr>
<tr><td><div class="ttip"><span class="icon">[ i ]</span>
<span class="ttxt">proportional font<br>monospace size<br>sans-serif size<br>serif size</span></div>
&nbsp; script defaults</td><td class="c mono" id="script_defaults"></td></tr>
<tr><td>[css | test] woff2 <sup>2</sup></td><td class="mono">
<span id="cssWoff2"></span> | <span class="c" id="woff2">
</span>
</td></tr>
<!--fonts-->
<tr><td>[faces] fonts</td><td class="mono" id="font_faces"></td></tr>
<tr><td>[methods] fonts <sup>3</sup></td>
Expand Down

0 comments on commit aadc947

Please sign in to comment.