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

Serve fonts locally #848

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions src/book/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ impl BookBuilder {
let mut general_css = File::create(cssdir.join("general.css"))?;
general_css.write_all(theme::GENERAL_CSS)?;

let mut fonts_css = File::create(cssdir.join("fonts.css"))?;
fonts_css.write_all(theme::FONTS_CSS)?;

let mut chrome_css = File::create(cssdir.join("chrome.css"))?;
chrome_css.write_all(theme::CHROME_CSS)?;

Expand Down
101 changes: 101 additions & 0 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl HtmlHandlebars {

write_file(destination, "book.js", &theme.js)?;
write_file(destination, "css/general.css", &theme.general_css)?;
write_file(destination, "css/fonts.css", &theme.fonts_css)?;
write_file(destination, "css/chrome.css", &theme.chrome_css)?;
write_file(destination, "css/print.css", &theme.print_css)?;
write_file(destination, "css/variables.css", &theme.variables_css)?;
Expand Down Expand Up @@ -159,6 +160,106 @@ impl HtmlHandlebars {
"FontAwesome/fonts/FontAwesome.ttf",
theme::FONT_AWESOME_TTF,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-300.woff",
theme::FONT_OPEN_SANS_V15_LATIN_300_WOFF,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-300.woff2",
theme::FONT_OPEN_SANS_V15_LATIN_300_WOFF2,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-300italic.woff",
theme::FONT_OPEN_SANS_V15_LATIN_300_ITALIC_WOFF,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-300italic.woff2",
theme::FONT_OPEN_SANS_V15_LATIN_300_ITALIC_WOFF2,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-regular.woff",
theme::FONT_OPEN_SANS_V15_LATIN_REGULAR_WOFF,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-regular.woff2",
theme::FONT_OPEN_SANS_V15_LATIN_REGULAR_WOFF2,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-italic.woff",
theme::FONT_OPEN_SANS_V15_LATIN_ITALIC_WOFF,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-italic.woff2",
theme::FONT_OPEN_SANS_V15_LATIN_ITALIC_WOFF2,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-600.woff",
theme::FONT_OPEN_SANS_V15_LATIN_600_WOFF,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-600.woff2",
theme::FONT_OPEN_SANS_V15_LATIN_600_WOFF2,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-600italic.woff",
theme::FONT_OPEN_SANS_V15_LATIN_600_ITALIC_WOFF,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-600italic.woff2",
theme::FONT_OPEN_SANS_V15_LATIN_600_ITALIC_WOFF2,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-700.woff",
theme::FONT_OPEN_SANS_V15_LATIN_700_WOFF,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-700.woff2",
theme::FONT_OPEN_SANS_V15_LATIN_700_WOFF2,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-700italic.woff",
theme::FONT_OPEN_SANS_V15_LATIN_700_ITALIC_WOFF,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-700italic.woff2",
theme::FONT_OPEN_SANS_V15_LATIN_700_ITALIC_WOFF2,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-800.woff",
theme::FONT_OPEN_SANS_V15_LATIN_800_WOFF,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-800.woff2",
theme::FONT_OPEN_SANS_V15_LATIN_800_WOFF2,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-800italic.woff",
theme::FONT_OPEN_SANS_V15_LATIN_800_ITALIC_WOFF,
)?;
write_file(
destination,
"fonts/open-sans-v15-latin-800italic.woff2",
theme::FONT_OPEN_SANS_V15_LATIN_800_ITALIC_WOFF2,
)?;

let playpen_config = &html_config.playpen;

Expand Down
100 changes: 100 additions & 0 deletions src/theme/css/fonts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* open-sans-300 - latin */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 300;
src: local('Open Sans Light'), local('OpenSans-Light'),
url('../fonts/open-sans-v15-latin-300.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
url('../fonts/open-sans-v15-latin-300.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}
/* open-sans-300italic - latin */
@font-face {
font-family: 'Open Sans';
font-style: italic;
font-weight: 300;
src: local('Open Sans Light Italic'), local('OpenSans-LightItalic'),
url('../fonts/open-sans-v15-latin-300italic.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
url('../fonts/open-sans-v15-latin-300italic.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}
/* open-sans-regular - latin */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans Regular'), local('OpenSans-Regular'),
url('../fonts/open-sans-v15-latin-regular.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
url('../fonts/open-sans-v15-latin-regular.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}
/* open-sans-italic - latin */
@font-face {
font-family: 'Open Sans';
font-style: italic;
font-weight: 400;
src: local('Open Sans Italic'), local('OpenSans-Italic'),
url('../fonts/open-sans-v15-latin-italic.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
url('../fonts/open-sans-v15-latin-italic.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}
/* open-sans-600 - latin */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 600;
src: local('Open Sans SemiBold'), local('OpenSans-SemiBold'),
url('../fonts/open-sans-v15-latin-600.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
url('../fonts/open-sans-v15-latin-600.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}
/* open-sans-600italic - latin */
@font-face {
font-family: 'Open Sans';
font-style: italic;
font-weight: 600;
src: local('Open Sans SemiBold Italic'), local('OpenSans-SemiBoldItalic'),
url('../fonts/open-sans-v15-latin-600italic.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
url('../fonts/open-sans-v15-latin-600italic.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}
/* open-sans-700italic - latin */
@font-face {
font-family: 'Open Sans';
font-style: italic;
font-weight: 700;
src: local('Open Sans Bold Italic'), local('OpenSans-BoldItalic'),
url('../fonts/open-sans-v15-latin-700italic.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
url('../fonts/open-sans-v15-latin-700italic.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}
/* open-sans-700 - latin */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 700;
src: local('Open Sans Bold'), local('OpenSans-Bold'),
url('../fonts/open-sans-v15-latin-700.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
url('../fonts/open-sans-v15-latin-700.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}
/* open-sans-800 - latin */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 800;
src: local('Open Sans ExtraBold'), local('OpenSans-ExtraBold'),
url('../fonts/open-sans-v15-latin-800.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
url('../fonts/open-sans-v15-latin-800.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}
/* open-sans-800italic - latin */
@font-face {
font-family: 'Open Sans';
font-style: italic;
font-weight: 800;
src: local('Open Sans ExtraBold Italic'), local('OpenSans-ExtraBoldItalic'),
url('../fonts/open-sans-v15-latin-800italic.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
url('../fonts/open-sans-v15-latin-800italic.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}

/* source-code-pro-500 - latin */
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 500;
src: local('Source Code Pro Medium'), local('SourceCodePro-Medium'),
url('../fonts/source-code-pro-v8-latin-500.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
url('../fonts/source-code-pro-v8-latin-500.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}
Binary file added src/theme/fonts/open-sans-v15-latin-300.woff
Binary file not shown.
Binary file added src/theme/fonts/open-sans-v15-latin-300.woff2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/theme/fonts/open-sans-v15-latin-600.woff
Binary file not shown.
Binary file added src/theme/fonts/open-sans-v15-latin-600.woff2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/theme/fonts/open-sans-v15-latin-700.woff
Binary file not shown.
Binary file added src/theme/fonts/open-sans-v15-latin-700.woff2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/theme/fonts/open-sans-v15-latin-800.woff
Binary file not shown.
Binary file added src/theme/fonts/open-sans-v15-latin-800.woff2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/theme/fonts/open-sans-v15-latin-italic.woff
Binary file not shown.
Binary file added src/theme/fonts/open-sans-v15-latin-italic.woff2
Binary file not shown.
Binary file added src/theme/fonts/open-sans-v15-latin-regular.woff
Binary file not shown.
Binary file added src/theme/fonts/open-sans-v15-latin-regular.woff2
Binary file not shown.
Binary file added src/theme/fonts/source-code-pro-v8-latin-500.woff
Binary file not shown.
Binary file not shown.
3 changes: 1 addition & 2 deletions src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

<!-- Fonts -->
<link rel="stylesheet" href="{{ path_to_root }}FontAwesome/css/font-awesome.css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="{{ path_to_root }}css/fonts.css">

<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" href="{{ path_to_root }}highlight.css">
Expand Down
36 changes: 36 additions & 0 deletions src/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub static INDEX: &'static [u8] = include_bytes!("index.hbs");
pub static HEADER: &'static [u8] = include_bytes!("header.hbs");
pub static CHROME_CSS: &'static [u8] = include_bytes!("css/chrome.css");
pub static GENERAL_CSS: &'static [u8] = include_bytes!("css/general.css");
pub static FONTS_CSS: &'static [u8] = include_bytes!("css/fonts.css");
pub static PRINT_CSS: &'static [u8] = include_bytes!("css/print.css");
pub static VARIABLES_CSS: &'static [u8] = include_bytes!("css/variables.css");
pub static FAVICON: &'static [u8] = include_bytes!("favicon.png");
Expand All @@ -37,6 +38,36 @@ pub static FONT_AWESOME_WOFF2: &'static [u8] =
include_bytes!("FontAwesome/fonts/fontawesome-webfont.woff2");
pub static FONT_AWESOME_OTF: &'static [u8] = include_bytes!("FontAwesome/fonts/FontAwesome.otf");

pub static FONT_OPEN_SANS_V15_LATIN_300_WOFF: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-300.woff");
pub static FONT_OPEN_SANS_V15_LATIN_300_WOFF2: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-300.woff2");
pub static FONT_OPEN_SANS_V15_LATIN_300_ITALIC_WOFF: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-300italic.woff");
pub static FONT_OPEN_SANS_V15_LATIN_300_ITALIC_WOFF2: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-300italic.woff2");

// Regular is 400
pub static FONT_OPEN_SANS_V15_LATIN_REGULAR_WOFF: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-regular.woff");
pub static FONT_OPEN_SANS_V15_LATIN_REGULAR_WOFF2: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-regular.woff2");
pub static FONT_OPEN_SANS_V15_LATIN_ITALIC_WOFF: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-italic.woff");
pub static FONT_OPEN_SANS_V15_LATIN_ITALIC_WOFF2: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-italic.woff2");

pub static FONT_OPEN_SANS_V15_LATIN_600_WOFF: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-600.woff");
pub static FONT_OPEN_SANS_V15_LATIN_600_WOFF2: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-600.woff2");
pub static FONT_OPEN_SANS_V15_LATIN_600_ITALIC_WOFF: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-600italic.woff");
pub static FONT_OPEN_SANS_V15_LATIN_600_ITALIC_WOFF2: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-600italic.woff2");

pub static FONT_OPEN_SANS_V15_LATIN_700_WOFF: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-700.woff");
pub static FONT_OPEN_SANS_V15_LATIN_700_WOFF2: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-700.woff2");
pub static FONT_OPEN_SANS_V15_LATIN_700_ITALIC_WOFF: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-700italic.woff");
pub static FONT_OPEN_SANS_V15_LATIN_700_ITALIC_WOFF2: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-700italic.woff2");

pub static FONT_OPEN_SANS_V15_LATIN_800_WOFF: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-800.woff");
pub static FONT_OPEN_SANS_V15_LATIN_800_WOFF2: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-800.woff2");
pub static FONT_OPEN_SANS_V15_LATIN_800_ITALIC_WOFF: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-800italic.woff");
pub static FONT_OPEN_SANS_V15_LATIN_800_ITALIC_WOFF2: &'static [u8] = include_bytes!("fonts/open-sans-v15-latin-800italic.woff2");

pub static FONT_SOURCE_CODE_PRO_V8_LATIN_500_WOFF: &'static [u8] = include_bytes!("fonts/source-code-pro-v8-latin-500.woff");
pub static FONT_SOURCE_CODE_PRO_V8_LATIN_500_WOFF2: &'static [u8] = include_bytes!("fonts/source-code-pro-v8-latin-500.woff2");


/// The `Theme` struct should be used instead of the static variables because
/// the `new()` method will look if the user has a theme directory in their
/// source folder and use the users theme instead of the default.
Expand All @@ -48,6 +79,7 @@ pub struct Theme {
pub index: Vec<u8>,
pub header: Vec<u8>,
pub chrome_css: Vec<u8>,
pub fonts_css: Vec<u8>,
pub general_css: Vec<u8>,
pub print_css: Vec<u8>,
pub variables_css: Vec<u8>,
Expand Down Expand Up @@ -79,6 +111,7 @@ impl Theme {
(theme_dir.join("header.hbs"), &mut theme.header),
(theme_dir.join("book.js"), &mut theme.js),
(theme_dir.join("css/chrome.css"), &mut theme.chrome_css),
(theme_dir.join("css/fonts.css"), &mut theme.fonts_css),
(theme_dir.join("css/general.css"), &mut theme.general_css),
(theme_dir.join("css/print.css"), &mut theme.print_css),
(
Expand Down Expand Up @@ -120,6 +153,7 @@ impl Default for Theme {
index: INDEX.to_owned(),
header: HEADER.to_owned(),
chrome_css: CHROME_CSS.to_owned(),
fonts_css: FONTS_CSS.to_owned(),
general_css: GENERAL_CSS.to_owned(),
print_css: PRINT_CSS.to_owned(),
variables_css: VARIABLES_CSS.to_owned(),
Expand Down Expand Up @@ -175,6 +209,7 @@ mod tests {
"header.hbs",
"favicon.png",
"css/chrome.css",
"css/fonts.css",
"css/general.css",
"css/print.css",
"css/variables.css",
Expand All @@ -200,6 +235,7 @@ mod tests {
index: Vec::new(),
header: Vec::new(),
chrome_css: Vec::new(),
fonts_css: Vec::new(),
general_css: Vec::new(),
print_css: Vec::new(),
variables_css: Vec::new(),
Expand Down