Skip to content

Commit

Permalink
Bundle and use Inconsolata v2.012
Browse files Browse the repository at this point in the history
There's a newer version of the font available but ligatures seem
broken googlefonts/Inconsolata#58 and googlefonts/Inconsolata#52.

As part of this commit I also upgraded rust-embed to use the new
exclusion feature, which allows us to skip embedding OS files like
`.DS_Store`.
  • Loading branch information
as-cii committed Sep 4, 2021
1 parent 0e4f777 commit 00f6bdc
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 26 deletions.
14 changes: 8 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions gpui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ impl App {
}))
}

pub fn platform(&self) -> Arc<dyn Platform> {
self.0.borrow().platform()
}

pub fn font_cache(&self) -> Arc<FontCache> {
self.0.borrow().cx.font_cache.clone()
}
Expand Down
1 change: 1 addition & 0 deletions gpui/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub enum CursorStyle {
}

pub trait FontSystem: Send + Sync {
fn add_fonts(&self, fonts: Vec<Arc<Vec<u8>>>) -> anyhow::Result<()>;
fn load_family(&self, name: &str) -> anyhow::Result<Vec<FontId>>;
fn select_font(
&self,
Expand Down
30 changes: 25 additions & 5 deletions gpui/src/platform/mac/fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,39 @@ use core_graphics::{
base::CGGlyph, color_space::CGColorSpace, context::CGContext, geometry::CGAffineTransform,
};
use core_text::{line::CTLine, string_attributes::kCTFontAttributeName};
use font_kit::{canvas::RasterizationOptions, hinting::HintingOptions, source::SystemSource};
use font_kit::{
canvas::RasterizationOptions, handle::Handle, hinting::HintingOptions, source::SystemSource,
sources::mem::MemSource,
};
use parking_lot::RwLock;
use std::{cell::RefCell, char, cmp, convert::TryFrom, ffi::c_void};
use std::{cell::RefCell, char, cmp, convert::TryFrom, ffi::c_void, sync::Arc};

#[allow(non_upper_case_globals)]
const kCGImageAlphaOnly: u32 = 7;

pub struct FontSystem(RwLock<FontSystemState>);

struct FontSystemState {
source: SystemSource,
memory_source: MemSource,
system_source: SystemSource,
fonts: Vec<font_kit::font::Font>,
}

impl FontSystem {
pub fn new() -> Self {
Self(RwLock::new(FontSystemState {
source: SystemSource::new(),
memory_source: MemSource::empty(),
system_source: SystemSource::new(),
fonts: Vec::new(),
}))
}
}

impl platform::FontSystem for FontSystem {
fn add_fonts(&self, fonts: Vec<Arc<Vec<u8>>>) -> anyhow::Result<()> {
self.0.write().add_fonts(fonts)
}

fn load_family(&self, name: &str) -> anyhow::Result<Vec<FontId>> {
self.0.write().load_family(name)
}
Expand Down Expand Up @@ -93,9 +102,20 @@ impl platform::FontSystem for FontSystem {
}

impl FontSystemState {
fn add_fonts(&mut self, fonts: Vec<Arc<Vec<u8>>>) -> anyhow::Result<()> {
self.memory_source
.add_fonts(fonts.into_iter().map(|bytes| Handle::from_memory(bytes, 0)))?;
Ok(())
}

fn load_family(&mut self, name: &str) -> anyhow::Result<Vec<FontId>> {
let mut font_ids = Vec::new();
for font in self.source.select_family_by_name(name)?.fonts() {

let family = self
.memory_source
.select_family_by_name(name)
.or_else(|_| self.system_source.select_family_by_name(name))?;
for font in family.fonts() {
let font = font.load()?;
font_ids.push(FontId(self.fonts.len()));
self.fonts.push(font);
Expand Down
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ oauth2-surf = "0.1.1"
parking_lot = "0.11.1"
postage = { version = "0.4.1", features = ["futures-traits"] }
rand = "0.8"
rust-embed = "5.9.0"
rust-embed = { version = "6.2", features = ["include-exclude"] }
scrypt = "0.7"
serde = { version = "1.0", features = ["derive"] }
sha-1 = "0.9"
Expand Down
2 changes: 1 addition & 1 deletion server/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ async fn get_static_asset(request: Request) -> tide::Result {

Ok(tide::Response::builder(200)
.content_type(content_type)
.body(content.as_ref())
.body(content.data.as_ref())
.build())
}
4 changes: 2 additions & 2 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl AppState {
let partial = Templates::get(path.as_ref()).unwrap();
self.handlebars
.write()
.register_partial(partial_name, std::str::from_utf8(partial.as_ref()).unwrap())
.register_partial(partial_name, std::str::from_utf8(&partial.data).unwrap())
.unwrap()
}
}
Expand All @@ -98,7 +98,7 @@ impl AppState {
self.register_partials();

self.handlebars.read().render_template(
std::str::from_utf8(Templates::get(path).unwrap().as_ref()).unwrap(),
std::str::from_utf8(&Templates::get(path).unwrap().data).unwrap(),
data,
)
}
Expand Down
2 changes: 1 addition & 1 deletion zed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ parking_lot = "0.11.1"
postage = { version = "0.4.1", features = ["futures-traits"] }
rand = "0.8.3"
rsa = "0.4"
rust-embed = "5.9.0"
rust-embed = { version = "6.2", features = ["include-exclude"] }
seahash = "4.1"
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1.0.64", features = ["preserve_order"] }
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion zed/assets/themes/dark.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extends = "_base"
2 = "#131415"

[text]
base = { family = "Helvetica", size = 14.0 }
base = { family = "Inconsolata", size = 14 }
0 = { extends = "$text.base", color = "#ffffff" }
1 = { extends = "$text.base", color = "#b3b3b3" }
2 = { extends = "$text.base", color = "#7b7d80" }
Expand Down
2 changes: 1 addition & 1 deletion zed/assets/themes/light.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extends = "_base"
3 = "#3a3b3c"

[text]
base = { family = "Helvetica", size = 14.0 }
base = { family = "Inconsolata", size = 14 }
0 = { extends = "$text.base", color = "#acacac" }
1 = { extends = "$text.base", color = "#111111" }
2 = { extends = "$text.base", color = "#333333" }
Expand Down
5 changes: 4 additions & 1 deletion zed/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ use rust_embed::RustEmbed;

#[derive(RustEmbed)]
#[folder = "assets"]
#[exclude = "*.DS_Store"]
pub struct Assets;

impl AssetSource for Assets {
fn load(&self, path: &str) -> Result<std::borrow::Cow<[u8]>> {
Self::get(path).ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
Self::get(path)
.map(|f| f.data)
.ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
}

fn list(&self, path: &str) -> Vec<std::borrow::Cow<'static, str>> {
Expand Down
5 changes: 3 additions & 2 deletions zed/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ impl Language {
impl LanguageRegistry {
pub fn new() -> Self {
let grammar = tree_sitter_rust::language();
let rust_config = toml::from_slice(&LanguageDir::get("rust/config.toml").unwrap()).unwrap();
let rust_config =
toml::from_slice(&LanguageDir::get("rust/config.toml").unwrap().data).unwrap();
let rust_language = Language {
config: rust_config,
grammar,
Expand Down Expand Up @@ -84,7 +85,7 @@ impl LanguageRegistry {
fn load_query(grammar: tree_sitter::Language, path: &str) -> Query {
Query::new(
grammar,
str::from_utf8(LanguageDir::get(path).unwrap().as_ref()).unwrap(),
str::from_utf8(&LanguageDir::get(path).unwrap().data).unwrap(),
)
.unwrap()
}
Expand Down
14 changes: 11 additions & 3 deletions zed/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#![allow(non_snake_case)]

use fs::OpenOptions;
use gpui::AssetSource;
use log::LevelFilter;
use parking_lot::Mutex;
use simplelog::SimpleLogger;
use std::{fs, path::PathBuf, sync::Arc};
use zed::{
self, assets,
self,
assets::Assets,
channel::ChannelList,
chat_panel, editor, file_finder,
fs::RealFs,
Expand All @@ -20,9 +22,15 @@ use zed::{
fn main() {
init_logger();

let app = gpui::App::new(assets::Assets).unwrap();
let app = gpui::App::new(Assets).unwrap();
let embedded_fonts = Assets
.list("fonts")
.into_iter()
.map(|f| Arc::new(Assets.load(&f).unwrap().to_vec()))
.collect();
app.platform().fonts().add_fonts(embedded_fonts).unwrap();

let themes = settings::ThemeRegistry::new(assets::Assets, app.font_cache());
let themes = settings::ThemeRegistry::new(Assets, app.font_cache());
let (settings_tx, settings) = settings::channel(&app.font_cache(), &themes).unwrap();
let languages = Arc::new(language::LanguageRegistry::new());
languages.set_theme(&settings.borrow().theme.syntax);
Expand Down
4 changes: 2 additions & 2 deletions zed/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ impl Settings {

pub fn new(font_cache: &FontCache, theme: Arc<Theme>) -> Result<Self> {
Ok(Self {
buffer_font_family: font_cache.load_family(&["Fira Code", "Monaco"])?,
buffer_font_size: 14.0,
buffer_font_family: font_cache.load_family(&["Inconsolata"])?,
buffer_font_size: 16.,
tab_size: 4,
theme,
})
Expand Down

0 comments on commit 00f6bdc

Please sign in to comment.