Skip to content

Commit

Permalink
Merge pull request #33 from aphillips/gh-pages
Browse files Browse the repository at this point in the history
Add font subsetting
  • Loading branch information
aphillips committed Nov 13, 2015
2 parents 0690412 + cd70024 commit 617c4af
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 7 deletions.
57 changes: 57 additions & 0 deletions SubsetFont.user.js
@@ -0,0 +1,57 @@
// ==UserScript==
// @name SubsetFont
// @namespace w3c
// @description Generate subsetted fonts to support charmod
// @version 1
// @include *
// @grant none
// ==/UserScript==

// author = addison@lab126.com

var text = document.body.innerHTML;

var charsToGet = [];
var request = '';

var re = new RegExp("[\u0100-\uffff]", 'g');

var unique = 0;

var m;
while ((m = re.exec(text)) !== null) {
var item = m[0];
if (charsToGet.length === 0 || charsToGet.indexOf(item) < 0) {
charsToGet.push(item);
request = request + item;
unique++;
}
}


//alert(re.test(text) + ' ' + re + ' ' + text.substring(0,100));

var mypanel = document.getElementsByClassName('subsetFont')[0];

if (!mypanel) {
mypanel = document.createElement('div');
}
mypanel.innerHTML = '';

mypanel.setAttribute('id', 'subsetFont');
mypanel.setAttribute('class', "subsetFont");
mypanel.style.position = 'fixed';
mypanel.style.bottom = 0;
mypanel.style.right = 0;
mypanel.style.overflow = 'auto';
mypanel.style.inset = '0 0 0 10px';
mypanel.style.zIndex = '1001'; // make it appear in front of most things

var pre = document.createElement('pre');
pre.appendChild(document.createTextNode('count: ' + unique));
mypanel.appendChild(pre);
pre = document.createElement('pre');
pre.appendChild(document.createTextNode(request));
mypanel.appendChild(pre);

document.body.appendChild(mypanel);
Binary file added font.woff2
Binary file not shown.
20 changes: 13 additions & 7 deletions local.css
@@ -1,3 +1,10 @@
@font-face {
font-family: 'Noto Sans';
font-style: normal;
font-weight: 400;
src: local('Noto Sans'), local('NotoSans'), url('./font.woff2')
}

body {
counter-reset: requirement;
}
Expand Down Expand Up @@ -33,10 +40,9 @@ del {

figure {
margin-bottom: 2em;
text-align: center;
}
}
figcaption {
text-align: center;
text-align: center;
margin: 0.5em 2em;
font-style: italic;
font-size: 90%;
Expand Down Expand Up @@ -72,11 +78,11 @@ a.termref:active {
.quote:after { content: '"'; }
code {
color: #A52A2A;
font-family: Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", monospace;
font-family: Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", NotoSans, monospace;
font-size: 100%;
}
samp, kbd {
font-family: Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", monospace;
font-family: Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", NotoSans, monospace;
font-size: 100%;
}
.uname {
Expand All @@ -95,7 +101,7 @@ div.requirement {

div.requirement p:before {
content: "C" counter(requirement) " \00A0";
font-family:Tahoma, Geneva, sans-serif;
font-family:Tahoma, Geneva, NotoSans, sans-serif;
font-weight: bold;
font-size: smaller;
text-transform: capitalize;
Expand Down Expand Up @@ -155,7 +161,7 @@ div.exampleBox {
}

.markup {
font-family: Lucida Console,monospaced;
font-family: Lucida Console,NotoSans, monospaced;
}

.shakespeare {
Expand Down

0 comments on commit 617c4af

Please sign in to comment.