]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #65665 - tspiteri:italic-and-update-SourceCodePro, r=GuillaumeGomez
authorMazdak Farrokhzad <twingoow@gmail.com>
Wed, 20 Nov 2019 11:58:26 +0000 (12:58 +0100)
committerGitHub <noreply@github.com>
Wed, 20 Nov 2019 11:58:26 +0000 (12:58 +0100)
Update Source Code Pro and include italics

Fixes #65502.

A few notes:
  * As stated in #65502, this does increase the download size.
  * Since this PR changes the font set, I think docs.rs would have to be updated if this PR is merged.
  * The fonts have a double extension (.ttf.woff); this is to keep the names consistent with the upstream font release which does that to distinguish these from the .otf.woff files ([Source Code Pro otf renders poorly on older Windows system apps](https://github.com/adobe-fonts/source-code-pro/issues/25#issuecomment-9019600)).

1  2 
src/librustdoc/html/render.rs
src/librustdoc/html/static_files.rs

index 1207c5e3bc58dfae106fc5fd859c90d18302521e,25c2f08c77a48f4027cc46feba6010a9c528430d..2fa56f5851220c6a5533ac7459f109304387123a
@@@ -49,7 -49,7 +49,7 @@@ use syntax::feature_gate::UnstableFeatu
  use syntax::print::pprust;
  use syntax::source_map::FileName;
  use syntax::symbol::{Symbol, sym};
 -use syntax_expand::base::MacroKind;
 +use syntax_pos::hygiene::MacroKind;
  use rustc::hir::def_id::DefId;
  use rustc::middle::privacy::AccessLevels;
  use rustc::middle::stability;
@@@ -633,16 -633,19 +633,16 @@@ function handleThemeButtonsBlur(e) {
  
  themePicker.onclick = switchThemeButtonState;
  themePicker.onblur = handleThemeButtonsBlur;
 -[{}].forEach(function(item) {{
 +{}.forEach(function(item) {{
      var but = document.createElement('button');
 -    but.innerHTML = item;
 +    but.textContent = item;
      but.onclick = function(el) {{
          switchTheme(currentTheme, mainTheme, item, true);
      }};
      but.onblur = handleThemeButtonsBlur;
      themes.appendChild(but);
  }});"#,
 -                 themes.iter()
 -                       .map(|s| format!("\"{}\"", s))
 -                       .collect::<Vec<String>>()
 -                       .join(","));
 +                 as_json(&themes));
      write(cx.dst.join(&format!("theme{}.js", cx.shared.resource_suffix)),
            theme_js.as_bytes()
      )?;
            static_files::source_serif_pro::ITALIC)?;
      write(cx.dst.join("SourceSerifPro-LICENSE.md"),
            static_files::source_serif_pro::LICENSE)?;
-     write(cx.dst.join("SourceCodePro-Regular.woff"),
+     write(cx.dst.join("SourceCodePro-Regular.ttf.woff"),
            static_files::source_code_pro::REGULAR)?;
-     write(cx.dst.join("SourceCodePro-Semibold.woff"),
+     write(cx.dst.join("SourceCodePro-Semibold.ttf.woff"),
            static_files::source_code_pro::SEMIBOLD)?;
+     write(cx.dst.join("SourceCodePro-It.ttf.woff"),
+           static_files::source_code_pro::ITALIC)?;
      write(cx.dst.join("SourceCodePro-LICENSE.txt"),
            static_files::source_code_pro::LICENSE)?;
      write(cx.dst.join("LICENSE-MIT.txt"),
@@@ -1227,87 -1232,17 +1229,87 @@@ impl AllTypes 
      }
  }
  
 +#[derive(Debug)]
 +enum Setting {
 +    Section {
 +        description: &'static str,
 +        sub_settings: Vec<Setting>,
 +    },
 +    Entry {
 +        js_data_name: &'static str,
 +        description: &'static str,
 +        default_value: bool,
 +    }
 +}
 +
 +impl Setting {
 +    fn display(&self) -> String {
 +        match *self {
 +            Setting::Section { ref description, ref sub_settings } => {
 +                format!(
 +                    "<div class='setting-line'>\
 +                        <div class='title'>{}</div>\
 +                        <div class='sub-settings'>{}</div>
 +                    </div>",
 +                    description,
 +                    sub_settings.iter().map(|s| s.display()).collect::<String>()
 +                )
 +            }
 +            Setting::Entry { ref js_data_name, ref description, ref default_value } => {
 +                format!(
 +                    "<div class='setting-line'>\
 +                        <label class='toggle'>\
 +                        <input type='checkbox' id='{}' {}>\
 +                        <span class='slider'></span>\
 +                        </label>\
 +                        <div>{}</div>\
 +                    </div>",
 +                    js_data_name,
 +                    if *default_value { " checked" } else { "" },
 +                    description,
 +                )
 +            }
 +        }
 +    }
 +}
 +
 +impl From<(&'static str, &'static str, bool)> for Setting {
 +    fn from(values: (&'static str, &'static str, bool)) -> Setting {
 +        Setting::Entry {
 +            js_data_name: values.0,
 +            description: values.1,
 +            default_value: values.2,
 +        }
 +    }
 +}
 +
 +impl<T: Into<Setting>> From<(&'static str, Vec<T>)> for Setting {
 +    fn from(values: (&'static str, Vec<T>)) -> Setting {
 +        Setting::Section {
 +            description: values.0,
 +            sub_settings: values.1.into_iter().map(|v| v.into()).collect::<Vec<_>>(),
 +        }
 +    }
 +}
 +
  fn settings(root_path: &str, suffix: &str) -> String {
      // (id, explanation, default value)
 -    let settings = [
 -        ("item-declarations", "Auto-hide item declarations.", true),
 -        ("item-attributes", "Auto-hide item attributes.", true),
 -        ("trait-implementations", "Auto-hide trait implementations documentation",
 -            true),
 -        ("method-docs", "Auto-hide item methods' documentation", false),
 +    let settings: &[Setting] = &[
 +        ("Auto-hide item declarations", vec![
 +            ("auto-hide-struct", "Auto-hide structs declaration", true),
 +            ("auto-hide-enum", "Auto-hide enums declaration", false),
 +            ("auto-hide-union", "Auto-hide unions declaration", true),
 +            ("auto-hide-trait", "Auto-hide traits declaration", true),
 +            ("auto-hide-macro", "Auto-hide macros declaration", false),
 +        ]).into(),
 +        ("auto-hide-attributes", "Auto-hide item attributes.", true).into(),
 +        ("auto-hide-method-docs", "Auto-hide item methods' documentation", false).into(),
 +        ("auto-hide-trait-implementations", "Auto-hide trait implementations documentation",
 +            true).into(),
          ("go-to-only-result", "Directly go to item in search if there is only one result",
 -            false),
 -        ("line-numbers", "Show line numbers on code examples", false),
 +            false).into(),
 +        ("line-numbers", "Show line numbers on code examples", false).into(),
 +        ("disable-shortcuts", "Disable keyboard shortcuts", false).into(),
      ];
      format!(
  "<h1 class='fqn'>\
  </h1>\
  <div class='settings'>{}</div>\
  <script src='{}settings{}.js'></script>",
 -            settings.iter()
 -                        .map(|(id, text, enabled)| {
 -                            format!("<div class='setting-line'>\
 -                                            <label class='toggle'>\
 -                                            <input type='checkbox' id='{}' {}>\
 -                                            <span class='slider'></span>\
 -                                            </label>\
 -                                            <div>{}</div>\
 -                                        </div>", id, if *enabled { " checked" } else { "" }, text)
 -                        })
 -                        .collect::<String>(),
 +            settings.iter().map(|s| s.display()).collect::<String>(),
              root_path,
              suffix)
  }
@@@ -3020,7 -2965,7 +3022,7 @@@ fn render_attribute(attr: &ast::MetaIte
      if attr.is_word() {
          Some(path)
      } else if let Some(v) = attr.value_str() {
 -        Some(format!("{} = {:?}", path, v.as_str()))
 +        Some(format!("{} = {:?}", path, v))
      } else if let Some(values) = attr.meta_item_list() {
          let display: Vec<_> = values.iter().filter_map(|attr| {
              attr.meta_item().and_then(|mi| render_attribute(mi))
index 9fc1d76185fb7bf6aa12c41efe419c648f9bfe0c,080b786eea2cb7b723381951bf3647685bc4607f..34055f386fbc048c91d6a539f3467d588f40252a
@@@ -59,7 -59,7 +59,7 @@@ pub static RUST_FAVICON: &'static [u8] 
  /// The built-in themes given to every documentation site.
  pub mod themes {
      /// The "light" theme, selected by default when no setting is available. Used as the basis for
 -    /// the `--theme-checker` functionality.
 +    /// the `--check-theme` functionality.
      pub static LIGHT: &'static str = include_str!("static/themes/light.css");
  
      /// The "dark" theme.
@@@ -96,11 -96,15 +96,15 @@@ pub mod source_serif_pro 
  
  /// Files related to the Source Code Pro font.
  pub mod source_code_pro {
-     /// The file `SourceCodePro-Regular.woff`, the Regular variant of the Source Code Pro font.
-     pub static REGULAR: &'static [u8] = include_bytes!("static/SourceCodePro-Regular.woff");
+     /// The file `SourceCodePro-Regular.ttf.woff`, the Regular variant of the Source Code Pro font.
+     pub static REGULAR: &'static [u8] = include_bytes!("static/SourceCodePro-Regular.ttf.woff");
  
-     /// The file `SourceCodePro-Semibold.woff`, the Semibold variant of the Source Code Pro font.
-     pub static SEMIBOLD: &'static [u8] = include_bytes!("static/SourceCodePro-Semibold.woff");
+     /// The file `SourceCodePro-Semibold.ttf.woff`, the Semibold variant of the Source Code Pro
+     /// font.
+     pub static SEMIBOLD: &'static [u8] = include_bytes!("static/SourceCodePro-Semibold.ttf.woff");
+     /// The file `SourceCodePro-It.ttf.woff`, the Italic variant of the Source Code Pro font.
+     pub static ITALIC: &'static [u8] = include_bytes!("static/SourceCodePro-It.ttf.woff");
  
      /// The file `SourceCodePro-LICENSE.txt`, the license text of the Source Code Pro font.
      pub static LICENSE: &'static [u8] = include_bytes!("static/SourceCodePro-LICENSE.txt");