Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ttf format #6

Merged
merged 7 commits into from
Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion mixin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ $fonts-path: '../fonts' !default;
$src: (local('☺'));
$family-folder: str-replace($font-family, ' ', '-');
@each $type in $font-types {
$src: append($src, url('#{$fonts-path}/#{$font-family}/#{nth($font-file, 1)}.#{$type}') format('#{$type}'), 'comma');
$format-type: $type;
@if $type == 'ttf' {
//Allows ttf fonts to be correctly included in CSS
$format-type: 'truetype';
}
$src: append($src, url('#{$fonts-path}/#{$font-family}/#{nth($font-file, 1)}.#{$type}') format('#{$format-type}'), 'comma');
}
@return $src;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "font-face-generator",
"version": "1.1.1",
"version": "1.1.2",
"description": "An @font-face code generator for SCSS",
"main": "mixin.scss",
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions tests/generator/generator.test.css
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
@charset "UTF-8";
@font-face {
font-family: "Open Sans";
src: local("☺"), url("/path/to/fonts/Open Sans/open-sans-light.woff2") format("woff2"), url("/path/to/fonts/Open Sans/open-sans-light.woff") format("woff");
src: local("☺"), url("/path/to/fonts/Open Sans/open-sans-light.woff2") format("woff2"), url("/path/to/fonts/Open Sans/open-sans-light.woff") format("woff"), url("/path/to/fonts/Open Sans/open-sans-light.ttf") format("truetype");
font-weight: 300;
font-style: normal; }

@font-face {
font-family: "Open Sans";
src: local("☺"), url("/path/to/fonts/Open Sans/open-sans-normal.woff2") format("woff2"), url("/path/to/fonts/Open Sans/open-sans-normal.woff") format("woff");
src: local("☺"), url("/path/to/fonts/Open Sans/open-sans-normal.woff2") format("woff2"), url("/path/to/fonts/Open Sans/open-sans-normal.woff") format("woff"), url("/path/to/fonts/Open Sans/open-sans-normal.ttf") format("truetype");
font-weight: 400;
font-style: normal; }

@font-face {
font-family: "Open Sans";
src: local("☺"), url("/path/to/fonts/Open Sans/open-sans-normal-italic.woff2") format("woff2"), url("/path/to/fonts/Open Sans/open-sans-normal-italic.woff") format("woff");
src: local("☺"), url("/path/to/fonts/Open Sans/open-sans-normal-italic.woff2") format("woff2"), url("/path/to/fonts/Open Sans/open-sans-normal-italic.woff") format("woff"), url("/path/to/fonts/Open Sans/open-sans-normal-italic.ttf") format("truetype");
font-weight: 400;
font-style: italic; }

@font-face {
font-family: "Open Sans";
src: local("☺"), url("/path/to/fonts/Open Sans/open-sans-semibold.woff2") format("woff2"), url("/path/to/fonts/Open Sans/open-sans-semibold.woff") format("woff");
src: local("☺"), url("/path/to/fonts/Open Sans/open-sans-semibold.woff2") format("woff2"), url("/path/to/fonts/Open Sans/open-sans-semibold.woff") format("woff"), url("/path/to/fonts/Open Sans/open-sans-semibold.ttf") format("truetype");
font-weight: 600;
font-style: normal; }

@font-face {
font-family: "Open Sans";
src: local("☺"), url("/path/to/fonts/Open Sans/open-sans-bold.woff2") format("woff2"), url("/path/to/fonts/Open Sans/open-sans-bold.woff") format("woff");
src: local("☺"), url("/path/to/fonts/Open Sans/open-sans-bold.woff2") format("woff2"), url("/path/to/fonts/Open Sans/open-sans-bold.woff") format("woff"), url("/path/to/fonts/Open Sans/open-sans-bold.ttf") format("truetype");
font-weight: 700;
font-style: normal; }

@font-face {
font-family: "Font Two";
src: local("☺"), url("/path/to/fonts/Font Two/font-two.woff2") format("woff2"), url("/path/to/fonts/Font Two/font-two.woff") format("woff");
src: local("☺"), url("/path/to/fonts/Font Two/font-two.woff2") format("woff2"), url("/path/to/fonts/Font Two/font-two.woff") format("woff"), url("/path/to/fonts/Font Two/font-two.ttf") format("truetype");
font-weight: 400;
font-style: normal; }
2 changes: 1 addition & 1 deletion tests/generator/generator.test.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $fonts: (
)
);

$font-file-types: 'woff2' 'woff';
$font-file-types: 'woff2' 'woff' 'ttf';

$fonts-path: '/path/to/fonts';

Expand Down
12 changes: 12 additions & 0 deletions tests/mixin/mixin.test.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@
font-weight: 400;
font-style: normal; }

@font-face {
font-family: "TTF Font";
src: local("☺"), url("/global/path/to/fonts/TTF Font/ttf-normal.ttf") format("truetype");
font-weight: 400;
font-style: normal; }

@font-face {
font-family: "TTF with backup Font";
src: local("☺"), url("/global/path/to/fonts/TTF with backup Font/ttf-normal.ttf") format("truetype"), url("/global/path/to/fonts/TTF with backup Font/ttf-normal.woff") format("woff");
font-weight: 400;
font-style: normal; }

@font-face {
font-family: "Open Sans";
src: local("☺"), url("/path/to/fonts/Open Sans/open-sans-light.woff2") format("woff2"), url("/path/to/fonts/Open Sans/open-sans-light.woff") format("woff");
Expand Down
20 changes: 20 additions & 0 deletions tests/mixin/mixin.test.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ $fonts-path: '/global/path/to/fonts';
$types: 'woff'
);

@include font-face(
$fonts: (
'TTF Font' : (
400 : 'ttf-normal'
)
),
// overide the default file types setting
$types: 'ttf'
);

@include font-face(
$fonts: (
'TTF with backup Font' : (
400 : 'ttf-normal'
)
),
// overide the default file types setting
$types: 'ttf' 'woff'
);

@include font-face(
$fonts: (
'Open Sans' : (
Expand Down