|
46604 | 46604 | 8: $eefa2b8b831d14eeeb495d913889d53$exports.FC_WIDTH_EXTRAEXPANDED, |
46605 | 46605 | 9: $eefa2b8b831d14eeeb495d913889d53$exports.FC_WIDTH_ULTRAEXPANDED |
46606 | 46606 | }; |
| 46607 | + const $c8c163c85a2fe4122f49de2a1cd9c12c$var$Css3StretchToFcWidth = { |
| 46608 | + 'ultra-condensed': $eefa2b8b831d14eeeb495d913889d53$exports.FC_WIDTH_ULTRACONDENSED, |
| 46609 | + 'extra-condensed': $eefa2b8b831d14eeeb495d913889d53$exports.FC_WIDTH_EXTRACONDENSED, |
| 46610 | + 'condensed': $eefa2b8b831d14eeeb495d913889d53$exports.FC_WIDTH_CONDENSED, |
| 46611 | + 'semi-condensed': $eefa2b8b831d14eeeb495d913889d53$exports.FC_WIDTH_SEMICONDENSED, |
| 46612 | + 'normal': $eefa2b8b831d14eeeb495d913889d53$exports.FC_WIDTH_NORMAL, |
| 46613 | + 'semi-expanded': $eefa2b8b831d14eeeb495d913889d53$exports.FC_WIDTH_SEMIEXPANDED, |
| 46614 | + 'expanded': $eefa2b8b831d14eeeb495d913889d53$exports.FC_WIDTH_EXPANDED, |
| 46615 | + 'extra-expanded': $eefa2b8b831d14eeeb495d913889d53$exports.FC_WIDTH_EXTRAEXPANDED, |
| 46616 | + 'ultra-expanded': $eefa2b8b831d14eeeb495d913889d53$exports.FC_WIDTH_ULTRAEXPANDED |
| 46617 | + }; |
46607 | 46618 |
|
46608 | 46619 | if (typeof TextEncoder === 'undefined') { |
| 46620 | + //nodejs |
46609 | 46621 | const { |
46610 | 46622 | TextEncoder, |
46611 | 46623 | TextDecoder |
|
46640 | 46652 | if ($c8c163c85a2fe4122f49de2a1cd9c12c$var$strContainsIgnoreCase(s, 'bold')) return $eefa2b8b831d14eeeb495d913889d53$exports.FC_WEIGHT_BOLD; |
46641 | 46653 | if ($c8c163c85a2fe4122f49de2a1cd9c12c$var$strContainsIgnoreCase(s, 'ultrablack')) return $eefa2b8b831d14eeeb495d913889d53$exports.FC_WEIGHT_EXTRABLACK; |
46642 | 46654 | if ($c8c163c85a2fe4122f49de2a1cd9c12c$var$strContainsIgnoreCase(s, 'superblack')) return $eefa2b8b831d14eeeb495d913889d53$exports.FC_WEIGHT_EXTRABLACK; |
46643 | | - if ($c8c163c85a2fe4122f49de2a1cd9c12c$var$strContainsIgnoreCase(s, 'extrablack')) return $eefa2b8b831d14eeeb495d913889d53$exports.FC_WEIGHT_EXTRABLACK; // TODO ultra? |
46644 | | - |
| 46655 | + if ($c8c163c85a2fe4122f49de2a1cd9c12c$var$strContainsIgnoreCase(s, 'extrablack')) return $eefa2b8b831d14eeeb495d913889d53$exports.FC_WEIGHT_EXTRABLACK; |
46645 | 46656 | if ($c8c163c85a2fe4122f49de2a1cd9c12c$var$strContainsIgnoreCase(s, 'black')) return $eefa2b8b831d14eeeb495d913889d53$exports.FC_WEIGHT_BLACK; |
46646 | 46657 | if ($c8c163c85a2fe4122f49de2a1cd9c12c$var$strContainsIgnoreCase(s, 'heavy')) return $eefa2b8b831d14eeeb495d913889d53$exports.FC_WEIGHT_HEAVY; |
46647 | 46658 | return -1; |
|
46658 | 46669 | if ($c8c163c85a2fe4122f49de2a1cd9c12c$var$strContainsIgnoreCase(s, 'ultraexpanded')) return $eefa2b8b831d14eeeb495d913889d53$exports.FC_WIDTH_ULTRAEXPANDED; |
46659 | 46670 | if ($c8c163c85a2fe4122f49de2a1cd9c12c$var$strContainsIgnoreCase(s, 'expanded')) return $eefa2b8b831d14eeeb495d913889d53$exports.FC_WIDTH_EXPANDED; |
46660 | 46671 | return -1; |
46661 | | - } // See FcContainsSlant in fcfreetype.c |
46662 | | - |
| 46672 | + } |
46663 | 46673 |
|
46664 | 46674 | function $c8c163c85a2fe4122f49de2a1cd9c12c$var$containsSlant(s) { |
46665 | 46675 | if ($c8c163c85a2fe4122f49de2a1cd9c12c$var$strContainsIgnoreCase(s, 'italic')) return $eefa2b8b831d14eeeb495d913889d53$exports.FC_SLANT_ITALIC; |
|
46687 | 46697 | if (codePageRange1 & 1 << 18 === bits17to20) return 'zh-cn'; |
46688 | 46698 | if (codePageRange1 & 1 << 19 === bits17to20) return 'ko'; |
46689 | 46699 | if (codePageRange1 & 1 << 20 === bits17to20) return 'zh-tw'; |
| 46700 | + } // https://stackoverflow.com/a/7616484 |
| 46701 | + |
| 46702 | + |
| 46703 | + function $c8c163c85a2fe4122f49de2a1cd9c12c$var$hash(s) { |
| 46704 | + let hash = 0, |
| 46705 | + i, |
| 46706 | + chr; |
| 46707 | + |
| 46708 | + for (i = 0; i < s.length; i++) { |
| 46709 | + chr = s.charCodeAt(i); |
| 46710 | + hash = (hash << 5) - hash + chr; |
| 46711 | + hash |= 0; // Convert to 32bit integer |
| 46712 | + } |
| 46713 | + |
| 46714 | + return hash; |
46690 | 46715 | } |
46691 | 46716 |
|
46692 | 46717 | $c8c163c85a2fe4122f49de2a1cd9c12c$exports = function (wasm) { |
|
46761 | 46786 | constructor(matches, coverage) { |
46762 | 46787 | this.matches = matches; |
46763 | 46788 | this.coverage = coverage; |
| 46789 | + this.key = $c8c163c85a2fe4122f49de2a1cd9c12c$var$hash(JSON.stringify(matches)); |
46764 | 46790 | } |
46765 | 46791 |
|
46766 | 46792 | } |
|
46809 | 46835 | const jsfonts = raw.fonts ? raw.fonts : [raw]; |
46810 | 46836 |
|
46811 | 46837 | for (const [index, jsfont] of jsfonts.entries()) { |
46812 | | - const fnt = FcPatternCreate(); // Family |
| 46838 | + const fnt = FcPatternCreate(); // Preferred |
| 46839 | + |
| 46840 | + if ('preferredFamily' in jsfont.name.records) { |
| 46841 | + for (const [lang, text] of Object.entries(jsfont.name.records.preferredFamily)) { |
| 46842 | + const pt = smalloc(text.toString()); |
| 46843 | + const pl = smalloc(lang.toString()); |
| 46844 | + FcPatternObjectAddString(fnt, $c8c163c85a2fe4122f49de2a1cd9c12c$var$FC_FAMILY_OBJECT, pt); |
| 46845 | + FcPatternObjectAddString(fnt, $c8c163c85a2fe4122f49de2a1cd9c12c$var$FC_FAMILYLANG_OBJECT, pl); |
| 46846 | + free(pt); |
| 46847 | + free(pl); |
| 46848 | + } |
| 46849 | + } // Family |
| 46850 | + |
46813 | 46851 |
|
46814 | 46852 | if ('fontFamily' in jsfont.name.records) { |
46815 | 46853 | for (const [lang, text] of Object.entries(jsfont.name.records.fontFamily)) { |
|
46832 | 46870 | free(pt); |
46833 | 46871 | free(pl); |
46834 | 46872 | } |
46835 | | - } // Style |
| 46873 | + } // Preferred style |
46836 | 46874 |
|
46837 | 46875 |
|
| 46876 | + if ('preferredSubFamily' in jsfont.name.records) { |
| 46877 | + for (const [lang, text] of Object.entries(jsfont.name.records.preferredSubFamily)) { |
| 46878 | + const pt = smalloc(text.toString()); |
| 46879 | + const pl = smalloc(lang.toString()); |
| 46880 | + FcPatternObjectAddString(fnt, $c8c163c85a2fe4122f49de2a1cd9c12c$var$FC_STYLE_OBJECT, pt); |
| 46881 | + FcPatternObjectAddString(fnt, $c8c163c85a2fe4122f49de2a1cd9c12c$var$FC_STYLELANG_OBJECT, pl); |
| 46882 | + free(pt); |
| 46883 | + free(pl); |
| 46884 | + } |
| 46885 | + } |
| 46886 | + |
46838 | 46887 | if ('fontSubfamily' in jsfont.name.records) { |
46839 | 46888 | for (const [lang, text] of Object.entries(jsfont.name.records.fontSubfamily)) { |
46840 | 46889 | const pt = smalloc(text.toString()); |
|
46883 | 46932 | if (width < 0) width = $c8c163c85a2fe4122f49de2a1cd9c12c$var$containsWidth(style); |
46884 | 46933 | if (slant < 0) slant = $c8c163c85a2fe4122f49de2a1cd9c12c$var$containsSlant(style); |
46885 | 46934 | if (!decorative) decorative = $c8c163c85a2fe4122f49de2a1cd9c12c$var$containsDecorative(style); |
46886 | | - } // Guarantee slant, final lowest priority values |
| 46935 | + } // TODO check the style name for slant, weight, width, if < 0 |
| 46936 | + // https://gitlab.freedesktop.org/fontconfig/fontconfig/-/blob/93c93689f5da4ceaa675e006df63283e25b91d49/src/fcfreetype.c#L1926 |
| 46937 | + // Guarantee slant, final lowest priority values |
46887 | 46938 |
|
46888 | 46939 |
|
46889 | 46940 | if (slant < 0) { |
@@ -46929,24 +46980,46 @@ |
46929 | 46980 | const pat = FcPatternCreate(); |
46930 | 46981 | const matches = []; |
46931 | 46982 |
|
46932 | | - if (typeof fontspec !== 'object' || typeof fontspec.family !== 'string') { |
| 46983 | + if (typeof fontspec !== 'object' || typeof fontspec.family !== 'string' && !Array.isArray(fontspec.family)) { |
46933 | 46984 | throw new Error('Pass an object with at least {family: string}'); |
46934 | 46985 | } |
46935 | 46986 |
|
46936 | | - const familyPtr = smalloc(fontspec.family); |
46937 | | - FcPatternObjectAddString(pat, $c8c163c85a2fe4122f49de2a1cd9c12c$var$FC_FAMILY_OBJECT, familyPtr); |
46938 | | - free(familyPtr); |
| 46987 | + const familyNormalized = Array.isArray(fontspec.family) ? fontspec.family : [fontspec.family]; |
| 46988 | + |
| 46989 | + for (const family of familyNormalized) { |
| 46990 | + const familyPtr = smalloc(family); |
| 46991 | + FcPatternObjectAddString(pat, $c8c163c85a2fe4122f49de2a1cd9c12c$var$FC_FAMILY_OBJECT, familyPtr); |
| 46992 | + free(familyPtr); |
| 46993 | + } |
46939 | 46994 |
|
46940 | 46995 | if ('weight' in fontspec) { |
46941 | | - FcPatternObjectAddDouble(pat, $c8c163c85a2fe4122f49de2a1cd9c12c$var$FC_WEIGHT_OBJECT, fontspec.weight); |
| 46996 | + let weight = fontspec.weight; |
| 46997 | + |
| 46998 | + if (typeof weight === 'string') { |
| 46999 | + const otweight = parseInt(weight, 10); |
| 47000 | + if (!Number.isNaN(otweight)) weight = FcWeightFromOpenTypeDouble(otweight); |
| 47001 | + } |
| 47002 | + |
| 47003 | + if (Number.isFinite(weight)) { |
| 47004 | + FcPatternObjectAddDouble(pat, $c8c163c85a2fe4122f49de2a1cd9c12c$var$FC_WEIGHT_OBJECT, weight); |
| 47005 | + } |
46942 | 47006 | } |
46943 | 47007 |
|
46944 | 47008 | if ('width' in fontspec) { |
46945 | | - FcPatternObjectAddInteger(pat, $c8c163c85a2fe4122f49de2a1cd9c12c$var$FC_WIDTH_OBJECT, fontspec.width); |
| 47009 | + let width = fontspec.width; |
| 47010 | + |
| 47011 | + if (typeof width === 'string' && width in $c8c163c85a2fe4122f49de2a1cd9c12c$var$Css3StretchToFcWidth) { |
| 47012 | + width = $c8c163c85a2fe4122f49de2a1cd9c12c$var$Css3StretchToFcWidth[width]; |
| 47013 | + } |
| 47014 | + |
| 47015 | + FcPatternObjectAddInteger(pat, $c8c163c85a2fe4122f49de2a1cd9c12c$var$FC_WIDTH_OBJECT, width); |
46946 | 47016 | } |
46947 | 47017 |
|
46948 | 47018 | if ('slant' in fontspec) { |
46949 | | - FcPatternObjectAddInteger(pat, $c8c163c85a2fe4122f49de2a1cd9c12c$var$FC_SLANT_OBJECT, fontspec.slant); |
| 47019 | + let slant = fontspec.slant; |
| 47020 | + if (slant === 'oblique') slant = $eefa2b8b831d14eeeb495d913889d53$exports.FC_SLANT_OBLIQUE; |
| 47021 | + if (slant === 'italic') slant = $eefa2b8b831d14eeeb495d913889d53$exports.FC_SLANT_ITALIC; |
| 47022 | + FcPatternObjectAddInteger(pat, $c8c163c85a2fe4122f49de2a1cd9c12c$var$FC_SLANT_OBJECT, slant); |
46950 | 47023 | } |
46951 | 47024 |
|
46952 | 47025 | if ('coverage' in fontspec) { |
|
47269 | 47342 | }); |
47270 | 47343 | }); |
47271 | 47344 | })(); |
47272 | | -//# sourceMappingURL=demo.e800fe03.js.map |
| 47345 | +//# sourceMappingURL=demo.dcf871bd.js.map |
0 commit comments