Commit Graph
54 Commits
Author SHA1 Message Date
Martin Lindhe 5b444375f2 fix some typos in comments 2017-10-30 09:25:13 -07:00
Martin Lindhe f646f6c9f8 config_subsitute(): fix typo by renaming to config_substitute() 2017-10-30 09:25:13 -07:00
Joe Wilm e8f5ab89ee Fix memory leak from font resizing
The source of the leak was loading up multiple copies of the FT_face
even when not necessary. Fonts are now appropriately cached for
FreeType when going through the `Rasterize::load_font` API.

Additionally, textures in the glyph cache are now reused.

The result of this is that resizing to already loaded fonts is free
from a memory consumption perspective.
2017-10-14 19:07:43 -07:00
Joe Wilm 6916537858 Update servo-fontconfig-sys fork
Fixes naming collision issue on Fedora 26.
2017-10-08 22:33:01 -07:00
Joe Wilm 2ea20f4823 Scale all fonts based on device-pixel-ratio
Rather than use DPI from config, use device-pixel-ratio from winit. This
is computed using the display DPI anyhow, so it should have the same
effect.
2017-10-08 22:20:58 -07:00
Dan Aloni b03ec0df37 Support bitmap fonts
To allow FontConfig to work with Bitmap font, we shall pass the size
we are interested in, and account for the size returned in the font
matching process. This is, because we cannot scale those fonts.

FontConfig will return the closest match, and we take its returned
pixel size back when we are rendering the glyphs.

There's an oddity when call set_char_size in TrueType - we need to
behave as if the DPI is 72. It is due to the following macro:

    #define FT_REQUEST_HEIGHT( req )                                        \
          ( (req)->vertResolution                                           \
              ? ( (req)->height * (FT_Pos)(req)->vertResolution + 36 ) / 72 \
              : (req)->height )

Further work can allow for integer scaling of the largest bitmap
font variant.

Tested with Terminus PCF-type font under Linux.

This addresses issue #582 .
2017-10-08 22:20:58 -07:00
Joe Wilm 31d1087b86 FreeType rasterizer respects some fontconfig
The FreeType rasterizer now reads settings like antialias, rgba,
lcdfilter, and hintstyle and chooses FreeType settings accordingly. The
result is that Alacritty fonts should look similar to the rest of the
system.
2017-10-08 22:20:58 -07:00
Joe Wilm 46d88ad244 Improve glyph rasterization performance
The hash map of key -> face was previouly cloned every time a glyph was
rasterized. This refactored the rasterization path to be more borrowck
friendly.

Sadly, this implementation is not *that* clean, but once NLLs land, much
of this can be cleaned up.
2017-10-08 22:20:58 -07:00
Joe Wilm cbe484a56b Remove unused macros 2017-10-08 22:20:58 -07:00
Joe Wilm 6c74c51cef Extend and improve FcPattern bindings
The fontconfig `FcPattern` type is wrapped as `fc::Pattern` and
`fc::Pattern` ref. All methods for accessing data on the pattern now
return an `Iterator`. This API turns out to be much more ergonomic than
providing an integer index. We also override the default `nth`
implementation of `Iterator` on these accessors to allow random
(incremental only) access.

For instance, accessing `family` attributes from a pattern:

    let families = pattern.family();
    let second = pattern.nth(1);

Or printing available styles

    for style in pattern.style() {
        println!("style={}", style);
    }
2017-10-08 22:20:58 -07:00
Joe Wilm 65065e06d1 Organize fontconfig wrappers
Each Fc type is split into a separate file. This organization will help
as features are added to the bindings.
2017-10-08 22:20:58 -07:00
Aaron Hill 5f7885749c Use clippy = "*", update, and fix some warnings (#796)
Because there are so many clippy warnings in the current codebase,
this commit removes '#![cfg_attr(feature = "clippy", deny(clippy))]',
to make it easier to fix warnings incrementally.
2017-09-27 17:29:44 -07:00
Jack O'Connor 11af896734 remove unused macros
This silences a couple of compiler warnings in the build.
2017-08-08 08:55:04 -05:00
Martin Lindhe f3e0c8609f font: update macOS core-text dependency to 6.1.0, fixes #685 (#692) 2017-07-28 09:00:55 -07:00
Joe Wilm 63787d0bf0 Use foreign-types from crates.io
We had previously vendored a very early version of this package before
it was ever published.
2017-06-27 09:29:09 -07:00
James A Keene 9825adf695 changes osx fallback symbol font style
Previously, the fallback symbol font copied the style of the font from
the config. However, the only available style for the fallback symbol
font is Normal slant, Normal weight.
2017-06-06 20:59:21 -07:00
Martin Algesten 40de8402a7 macOS use system font fallback 2017-06-06 09:47:32 -07:00
Martin Algesten 1fb2c843be final core-graphics extensions moved upstream 2017-06-01 09:47:58 -07:00
Martin Algesten d5ab4183c6 remove code that has been upstreamed 2017-05-31 09:30:54 -07:00
Martin Algesten dafa4ccde9 updated some font deps 2017-05-31 09:30:54 -07:00
Martin Algesten c1ab0042d4 avoid unused warning 2017-05-31 09:30:54 -07:00
Joe Wilm 13eac6b673 Fixes font raster for mono, gray bitmaps (#590)
As it turns out, FreeType does not always provide glyph data in LCD mode
as we requested. We now correctly handle several common modes returned
from FreeType including Lcd, Mono, and Gray.

Note that we don't check number of grays at this time since it's

1. Almost always 256, according to FreeType docs
2. Not available in the Rust FreeType bindings being used

Resolves #515
Resolves #185
Resolves #482
2017-05-28 17:36:55 -07:00
Joe Wilm f051e686da Update dependencies 2017-05-25 10:57:42 -07:00
Joe Wilm 573c5035ef Fix sign error in CoreText font rasterizer
Descent was being reported as a positive value instead of negative. This
caused the background and text alignment to be off dramatically.

Resolves #545
2017-05-06 23:09:07 -07:00
Joe Wilm 149fbaef09 Fix glyph offsets in cell
We previously had a hard-coded value for aligning glyphs within cells.
The font descent is now used, and the offset should be correct by
default.
2017-05-06 12:53:54 -07:00
Aaron Williamson 1277e07671 Remove unnecessary size argument to metrics function
The changes to metric consumption rendered the size argument
unnecessary, remove it.
2017-05-01 08:52:22 -07:00
Aaron Williamson 7fc50f6690 Improve freetype metric usage
The font metrics function was using freetype metrics in an ineffective
way, improve the use of those metrics and remove the now unnecessary
separate default values for font offset in linux.
2017-05-01 08:52:22 -07:00
Harlan Lieberman-Berg 55876522a2 font::fc: Remove unneeded clone 2017-03-01 22:07:14 -08:00
Harlan Lieberman-Berg 7bb89e50df font::ft: misc style cleanup. 2017-03-01 22:07:14 -08:00
Harlan Lieberman-Berg d5342a78cd Drop unnecessary unsafe on add_charset 2017-03-01 22:07:14 -08:00
Harlan Lieberman-Berg 6ed7d99453 Switch over to using font_match everywhere. 2017-03-01 22:07:14 -08:00
Harlan Lieberman-Berg 50f27af643 Rework font cache to cache on paths
This is done in order to help prevent us from loading the same
font face over and over again under separate keys.  We still incur
the performance hit of doing the fontconfig search each new glyph,
but that's unavoidable without more extensive refactoring.
2017-03-01 22:07:14 -08:00
Harlan Lieberman-Berg 3ad6869967 First pass of font fallback rendering 2017-03-01 22:07:14 -08:00
Joe Wilm 4b4a187fbd Fix fc::Pattern::add_charset
The lifetime constraints didn't do what I thought, and such constraints
turn out to be unnecessary anyhow.
2017-03-01 22:07:14 -08:00
Joe Wilm 28700ed3dc PoC find font with glyph 2017-03-01 22:07:14 -08:00
Joe Wilm f2f750f9f3 Alacritty now compiles on stable Rust 🎉 2017-02-03 08:11:19 -08:00
Joe Wilm 08f348ecea Optimize glyph cache access
Loading a glyph from the cache is a very hot operation in the renderer.
The original implementation would first check if a glyph was loaded and
then call `get()` which would have to search a second time. This showed
up as a very slow point in profiles.

This patch addresses glyph cache access in two ways: by using a faster
hasher optimized for small keys (fnv), and by using the entry API for
fetching a cached glyph. The `fnv` hasher is faster than the default and
is very efficient for small keys. Using the entry API on the HashMap
means only 1 lookup instead of two. The entry API has a downside where
the key needs to get cloned on fetches.

Reducing the GlyphKey width to 64-bits helps in both areas. Copying an
8-byte wide type is very cheap and thus limits downside of the entry
API. The small width also helps with the hasher performance.

Over all, this patch reduced typical render times by several hundred
microseconds on a 2013 MacBook Pro with a full screen terminal full of
text.
2017-01-26 08:43:53 -08:00
Lukas Lueg 64b42cd2f3 Use the log-crate instead of printing to stdout 2017-01-23 09:14:01 -08:00
Tom Crayford 67aba7f4e4 add suggestive fallback messages on unavailable fonts
as per https://github.com/jwilm/alacritty/issues/39
2017-01-12 21:21:14 -08:00
Tom Crayford f85cc353a6 make thin stroke rendering configurable
Makes thin stroke rendering for darwin configurable by a new toplevel
key under `font:` in the config file. Defaults to false, has no impact
on non macos.
2017-01-12 21:19:40 -08:00
Joe Wilm 8630185639 Rework font loading
This work started because we wanted to be able to simply say "monospace"
on Linux and have it give us some sort of font. The config format for
fonts changed to accomodate this new paradigm. As a result, italic and
bold can have different families from the normal (roman) face.

The fontconfig based font resolution probably works a lot better than
the CoreText version at this point. With CoreText, we simply iterate
over fonts and check it they match the requested properties. What's
worse is that the CoreText version requires a valid family. With
fontconfig, it will just provide the closest matching thing and use it
(unless a specific style is requested).
2017-01-02 19:49:38 -08:00
Joe Wilm 2738969f29 Propagate font rasterizer errors
This allows consumers of the font crate to handle errors instead of the
library panicking.
2016-12-31 20:47:02 -08:00
Joe Wilm a00970c9a8 Add ffi-util crate and use in fontconfig wrapper
This cleans up and fixes the C-type wrapping for fontconfig.
2016-12-30 18:55:10 -08:00
Joe Wilm 44c6171bc0 Refactor FontConfig wrappers
There's now a proper wrapper in place for working with the FontConfig
library. This should help significantly with error handling with font
loading; at least, the FontConfig code shouldn't panic. The FreeType
rasterizer still needs to be updated to handle missing fonts, and a more
sensible default font should be specified.
2016-12-30 00:34:57 -05:00
Joe Wilm bde4dacc79 Misc formatting fixes 2016-12-16 22:48:04 -08:00
Joe Wilm 0421012c2d Replace remaining use of try! with ? 2016-12-16 22:29:35 -08:00
Joe Wilm 66dbd29cd1 Add support for recording/running ref tests
Ref tests use a recording of the terminal protocol and a serialization
of the grid state to check that the parsing and action handling systems
produce the correct result. Ref tests may be recorded by running
alacritty with `--ref-test` and closing the terminal by using the window
"X" button. At that point, the recording is fully written to disk, and a
serialization of important state is recorded. Those files should be
moved to an appropriate folder in the `tests/ref/` tree, and the
`ref_test!` macro invocation should be updated accordingly.

A couple of changes were necessary to make this work:

* Ref tests shouldn't create a pty; the pty was refactored out of the
  `Term` type.
* Repeatable lines/cols were needed; on startup, the terminal is resized
* by default to 80x24 though that may be changed by passing
  `--dimensions w h`.
* Calculating window size based on desired rows/columns and font metrics
  required making load_font callable multiple times.
* Refactor types into library crate so they may be imported in an
  integration test.
* A whole bunch of types needed symmetric serialization and
  deserialization. Mostly this was just adding derives, but the custom
  deserialization of Rgb had to change to a deserialize_with function.

This initially adds one ref test as a sanity check, and more will be
added in subsequent commits. This initial ref tests just starts the
terminal and runs `ll`.
2016-11-19 21:34:11 -08:00
Joe Wilm a62f9aee65 Support bold/italic font rendering on Linux
The FreeType font Rasterizer API is updated to match the CoreText
Rasterizer. This enabled bold/italic fonts since the rest of the
codebase has already been updated.
2016-08-14 20:08:56 -07:00
Joe Wilm b70394170c Support bold/italic font rendering on macOS
This patch adds support for rendering italic fonts and bold fonts.

The `font` crate has a couple of new paradigms to support this: font
keys and glyph keys. `FontKey` is a lightweight (4 byte) identifier for
a font loaded out of the rasterizer. This replaces `FontDesc` for
rasterizing glyphs from a loaded font. `FontDesc` had the problem that
it contained two strings, and the glyph cache needs to store a copy of
the font key for every loaded glyph. `GlyphKey` is now passed to the
glyph rasterization method instead of a simple `char`. `GlyphKey`
contains information including font, size, and the character.

The rasterizer APIs do not define what happens when loading the same
font from a `FontDesc` more than once. It is assumed that the
application will track the resulting `FontKey` instead of asking the
font to be loaded multiple times.
2016-08-12 19:30:14 -05:00
Joe Wilm 874719580c Add support for CGContextSetFontSmoothingStyle
This enables narrower rendering of glyphs and it tends to look a bit
better. iTerm2 and Terminal both do this.
2016-08-03 19:53:48 -07:00