Skip to content

Commit

Permalink
fix(css): reference complete woff file, do not reference split woff f…
Browse files Browse the repository at this point in the history
…iles (#160)

* fix(css): reference complete woff file, do not reference split woff files

* chore(scripts): unnecessary default object property

* chore(package): bump version number to v1.0.2
  • Loading branch information
seejamescode committed Apr 16, 2018
1 parent 66de634 commit 376a2e2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ibm/plex",
"description": "The package of IBM’s typeface, IBM Plex",
"version": "1.0.1",
"version": "1.0.2",
"repository": "https://github.com/ibm/plex.git",
"license": "OFL-1.1",
"keywords": [
Expand Down
8 changes: 6 additions & 2 deletions scripts/export-scss.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,28 @@ const filesToWrite = families
Latin2: 4,
Latin1: 5
};
const content = innerFiles
const contentSplit = innerFiles
.sort((a, b) => order[a.unicode.type] - order[b.unicode.type])
.filter(({ unicode }) => family.unicodes.includes(unicode.type))
.map(({ unicode }) => {
const importPath = formatFilename([unicode.type]);
return `@import '${importPath}';`;
})
.join("\n");
const contentWhole = createFontFace(filename, family, weight);

// We spread all the inner files, since they are valid files that we'll
// want to create in the future, and then reduce over the whole
// collection to flatten the array entries.
// String contentWhole (woff) goes before contentSplit (woff2) so modern
// browsers will look for split files.
return [
...innerFiles,
{
filename: `${OUTPUT_DIRECTORY}/${filename.replace(" ", "-")}`,
content: `$font-prefix: '..' !default;
${content}`,
${contentWhole}
${contentSplit}`,
weight
}
];
Expand Down
22 changes: 14 additions & 8 deletions scripts/tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports.formatFilename = formatFilename;
* `createFontFace` is used to generate the actual `@font-face` declarations
* that get written to the appropriate files.
*/
const createFontFace = (filename, family, weight, unicode) => {
const createFontFace = (filename, family, weight, unicode = {}) => {
const fontFileName = [
`IBMPlex${family.type.replace(" ", "")}`,
weight.variant ? weight.type + weight.variant : weight.type,
Expand All @@ -39,20 +39,26 @@ const createFontFace = (filename, family, weight, unicode) => {
.filter(Boolean)
.join("");

const local = `local('${localFileName}'),
local('${localPostscriptName}')`;

const urls = {
woff2: `#{$font-prefix}/IBM-Plex-${family.type.replace(" ", "-")}/fonts/split/woff2/${fontFileName}.woff2`,
woff: `#{$font-prefix}/IBM-Plex-${family.type.replace(" ", "-")}/fonts/split/woff/${fontFileName}.woff`
woff: `#{$font-prefix}/IBM-Plex-${family.type.replace(" ", "-")}/fonts/complete/woff/${fontFileName}.woff`,
woff2: `#{$font-prefix}/IBM-Plex-${family.type.replace(" ", "-")}/fonts/split/woff2/${fontFileName}.woff2`
};

const src = unicode.characters
? `src: ${local},
url('${urls.woff2}') format('woff2');
unicode-range: ${unicode.characters.join(", ")};`
: `src: ${local},
url('${urls.woff}') format('woff');`

return `@font-face {
font-family: '${family.name}';
font-style: ${weight.properties.fontStyle};
font-weight: ${weight.properties.fontWeight};
src: local('${localFileName}'),
local('${localPostscriptName}'),
url('${urls.woff2}') format('woff2'),
url('${urls.woff}') format('woff');
unicode-range: '${unicode.characters.join(", ")}';
${src}
}
`;
};
Expand Down

0 comments on commit 376a2e2

Please sign in to comment.