Commit Graph
72 Commits
Author SHA1 Message Date
Christian Duerr 228400a6c2 Prevent font_size_modifier from sinking too low (#994)
This replaces the `font_size_modifier` stored on the `Term` struct with a `font_size` field.

With this change it is not necessary anymore to calculate the new font size from a delta but the current font size is always stored directly on the `Term` struct.

As a result of this it is now possible to increase the font size by more than 127 steps at runtime. It also limits the minimum font size to 1, so issues with the `font_size_modifier` dropping far below font size 1 are resolved with this change.

This fixes #955.
2018-01-05 03:22:58 +00:00
Christian Dürr 793b5cc3a9 Move custom cursor block on ft
Moved the custom cursor block on ft to the top, so no unnecessary
operations are executed when trying to draw a custom cursor glyph.
2017-12-24 09:46:54 -08:00
Christian Dürr 62d9174509 Use font_key provided with cursor glyphs
Previously it was assumed that the font_key for the normal font is
always 0, because this assumption was a bit of a stretch, now the
font_key provided with the glyph is used. This is always the bold,
italics or normal font associated with the cell.
2017-12-24 09:46:54 -08:00
Christian Duerr 645100cf5f Fix linux symbol size
With linux every box, line or underline should now have the
pixel-perfect size with any font at any size.

This uses the default font to get the size of the monospace box. It
assumes that the face 0 is always the primary font, if this is not the
case, this will probably break.
2017-12-24 09:46:54 -08:00
Christian Duerr 6eb634a2b8 Add box cursor to unfocused underline and beam
Because some people have requested this change, the beam and underline
cursors now also transform into an empty box when the terminal loses
focus. Like this there is one unique symbol to indicate that a terminal
is not currently focused.
2017-12-24 09:46:54 -08:00
Christian Duerr 44251d9dbb Refactor darwin code
The ascent calculation on darwin was more complicated than it needed to
be. By running a `.ceil()` instead of adding one, checking if it's 0,
substracting if it is, and then flooring it, a few instructions could be
shaved off.
2017-12-24 09:46:54 -08:00
Christian Duerr fe29b8c687 Add custom box cursor for unfocused window 2017-12-24 09:46:54 -08:00
Christian Duerr 8195d71034 Format cursor code and add documentation
As requested a few comments have been added to the darwin code. There
also was an off by one error in the ascent calculation which has been
corrected.

The beam cursor width has also been tweaked to be slightly slimmer in
general.

All code added in this PR has also been run through the default rustfmt
to make sure the formatting is okay.
2017-12-24 09:46:54 -08:00
Christian Duerr ce8bd1aaf2 Add custom cursors for macos
The macos target now also supports the custom beam and underline
cursors. The only thing left for this is now is testing and making sure
it works with tiny fonts.
2017-12-24 09:46:54 -08:00
Christian Duerr d82c4f02b6 Add custom beam cursor
In issue jwilm/asacritty#31 a few people complained about Beam cursor
being weird with their fonts, so to make all cursors uniform in
alacritty, a custom cursor has been added for the Beam too.

The beam cursor's height is always the full height of the monospace font
glyph bounding box. The width depends on the font size. It is calculated
using the width of the cell and dividing it by two. The block is always
aligned at the far-left of the cell.

The implementation is identical to the one of the underline cursor, but
it has been refactored so the glyphs are created in `lib.rs`, which can
be used by darwin/macos to implement these features too.

A small bug in the underline cursor has also been fixed, until now the
width was just using the width of the unicode character. Now it should
be using the full width of the monospace glyph bounding box with every
font.

Here are some screenshots for the Beam cursor:
![Small](https://u.teknik.io/v1QH3.png)
![Normal](https://u.teknik.io/RTlp2.png)
![Big](https://u.teknik.io/DLu2M.png)
![Huge](https://u.teknik.io/pSAFX.png)
2017-12-24 09:46:54 -08:00
Christian Duerr 9f708146d9 Specify unicode code point explicitly 2017-12-24 09:46:54 -08:00
Christian Duerr 5177e42bca Update comment to reference proper character
The unicode character comment has been updated to correctly reference
the character instead of commenting on the variable that might be that
character.
2017-12-24 09:46:54 -08:00
Christian Duerr 5149dcffbf Revert to old system for macos
Because rendering with macos works differently, the old underline cursor
is used for that. The cursor symbol has also been setup as a constant in
the font project.
2017-12-24 09:46:54 -08:00
Christian Duerr bf72b5a326 Add custom underline cursor
As mentioned in jwilm/alacritty#931, it can be troublesome if a font has
an underline symbol outside of the glyph's bounding box. This can lead
to the underline disappearing at the bottom of the terminal.

As a solution a symbol from the private use area was used as the
character code for the underline symbol. Whenever this symbol is
encountered, instead of rendering it, a custom block is rendered.

In this implementation the block has the full character as width and
sits flush with the bottom of the glyph's bounding box. The height is
half the distance between the baseline and the bottom of the bounding
box.
2017-12-24 09:46:54 -08:00
Chet Gurevitch b10390ede8 Update euclid to v16 2017-12-23 21:39:09 -08:00
Chet Gurevitch 1117bb5fda Update deps 2017-12-23 21:39:09 -08:00
Joe Wilm 7f7ec0682c Remove debug print 2017-12-22 21:01:23 -08:00
Joe Wilm 79e0ced15d Fix macOS fallbacks (#956)
The cascade list is now generated from Menlo for all fonts. This doesn't
feel correct to me, but it seems to give the expected behavior on macOS.
One of the problems cited was that certain glyphs like ❯ would not be
rendered with default cascade lists for some fonts.
2017-12-22 17:36:52 -08:00
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