source-foundry / font-line Goto Github PK
View Code? Open in Web Editor NEWOpenType vertical metrics reporting and font line spacing adjustment tool
OpenType vertical metrics reporting and font line spacing adjustment tool
First of all thanks for the great tool. Very handy.
I am just asking/suggesting a feature improvement. In the next update if it is possible please add an option to write back the modified fontreport.txt data to the fontfile. That would be very fancy feature to have!
Thank You.
Active bug identified in v0.5.3
From @Phantom-code in Hack repository source-foundry/Hack#188 (comment):
I've run font-line percent 20 ./Hack-Regular.ttf and got the following error:
[font-line] ERROR: Unable to modify the line spacing in the font file './Hack-Regular.ttf'. [Errno 2] No such file or directory: '-linegap20./Hack-Regular'
This will allow decreasing the font line on "already big font-line fonts".
Need to explore the fontTools library support.
Will need to take into account that line spacing may be handled differently in the browser setting, perhaps modify the approach with these file types. From Tim Brown in TypeKit blog comment:
Happy to share this info, although it’s not super interesting for most people. We’re constantly learning, but here’s what we know right now: Windows browsers use Win metrics, Mac browsers use hhea metrics, and Firefox on Linux uses Typo metrics unless the hhea values are greater. Win and hhea metrics must match, including an hhea linegap of zero. Typo linegap has to be zero too, or lines of text are spaced unpredictably across browsers.
The specific values to which metrics should be changed are unique to each font file. Our internal tools for foundry partners make recommendations based on the conditions I just mentioned, and also based on the maximum ascent/descent of glyphs in the font file.
Note TypoLineGap has to be zero comment.
Would it be feasible for the report generated by font-line to include values for:
I am interested in this functionality as a command line friendly alternative to using http://fontforge.github.io as suggested by this informative article to discover metrics for a given font.
Notice that this project will be eliminating support for Python 2.7 in the near term.
Coming soon.
The fontTools library is transitioning to Py3.6+ support as of the v4.0.0 library release. This project will be updated with changes that eliminate support for Py2.7 and bump the Py3 interpreter version to Py3.6+.
In the lib/fontline/commands.py
Also, it doesn't make sense to round the factor
(the conversion of percent to decimal fraction), because it will compound the inaccuracy in later calculations.
Hello,
I'm a Fedora 27 user with Python 2.7.14 version.
When I type pip install font-line
from ./local/share/fonts it gives the following error:
$ pip install font-line
Collecting font-line
Using cached font_line-0.7.1-py2.py3-none-any.whl
Collecting standardstreams (from font-line)
Using cached standardstreams-0.2.0-py2.py3-none-any.whl
Collecting commandlines (from font-line)
Using cached commandlines-0.4.1-py2.py3-none-any.whl
Collecting fontTools (from font-line)
Using cached fonttools-3.21.2-py2.py3-none-any.whl
Installing collected packages: standardstreams, commandlines, fontTools, font-line
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 365, in run
strip_file_prefix=options.strip_file_prefix,
File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 854, in install
strip_file_prefix=strip_file_prefix
File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 1069, in move_wheel_files
strip_file_prefix=strip_file_prefix,
File "/usr/lib/python2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/usr/lib/python2.7/site-packages/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/usr/lib/python2.7/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/usr/lib64/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permiso denegado: '/usr/lib/python2.7/site-packages/standardstreams-0.2.0.dist-info'
It seems it can't write to /usr/lib/
Try getting a font-line report
on these fonts:
I get:
Traceback (most recent call last):
File "/usr/local/bin/font-line", line 11, in <module>
sys.exit(main())
File "/Library/Python/2.7/site-packages/fontline/app.py", line 54, in main
stdout(get_font_report(fontpath))
File "/Library/Python/2.7/site-packages/fontline/commands.py", line 22, in get_font_report
os2_x_height = tt['OS/2'].sxHeight
AttributeError: 'table_O_S_2f_2' object has no attribute 'sxHeight'
Maybe this scenario could be dealt with better?
Maybe there could be a command line option to silence error output?
Until then I will have to hack around it in the shell script I am working on (or not use those fonts).
ps: Thanks for this tool! It surprised me how difficult it is to get the metrics data on the command line.
Dependabot couldn't authenticate with https://pypi.python.org/simple/.
You can provide authentication details in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'.
Version string is not being displayed in the report
subcommand metrics list for fonts that did not include languageID = 0 table.
reported by @alphapapa in source-foundry/Hack#191 (comment):
Hey Chris,
I just tried the 15% command, but it increased the line spacing instead of reducing it:
$ font-line report FiraCode-Regular.otf
=== FiraCode-Regular.otf ===
Version 1.102;PS 001.102;hotconv 1.0.88;makeotf.lib2.5.64775
SHA1: 87fda07094d49978382399e0532b021ef8fb6b02
--- Metrics ---
[head] Units per Em: 1000
[head] yMax: 1050
[head] yMin: -500
[OS/2] TypoAscender: 935
[OS/2] TypoDescender: -265
[OS/2] WinAscent: 935
[OS/2] WinDescent: 265
[hhea] Ascent: 935
[hhea] Descent: -265
[hhea] LineGap: 0
[OS/2] TypoLineGap: 0
--- Height Calculations by Table Values ---
[OS/2] TypoAscender to TypoDescender: 1200
[OS/2] WinAscent to WinDescent: 1200
[hhea] Ascent to Descent: 1200
--- Delta Values ---
WinAscent to TypoAscender: 0
Ascent to TypoAscender: 0
WinDescent to TypoDescender: 0
Descent to TypoDescender: 0
--- Ratios ---
(Typo Asc + Desc + Linegap) / UPM: 1.2
(winAsc + winDesc) / UPM: 1.2
(hhea Asc + Desc) / UPM: 1.2
$ font-line percent 15 FiraCode-*.otf
[font-line] 'FiraCode-Bold.otf' successfully modified to 'FiraCode-Bold-linegap15.otf'.
[font-line] 'FiraCode-Regular.otf' successfully modified to 'FiraCode-Regular-linegap15.otf'.
$ font-line report FiraCode-Regular-linegap15.otf
=== FiraCode-Regular-linegap15.otf ===
Version 1.102;PS 001.102;hotconv 1.0.88;makeotf.lib2.5.64775
SHA1: 269660e4c91ed4de6c91f7823514c4cafe4d3a93
--- Metrics ---
[head] Units per Em: 1000
[head] yMax: 1050
[head] yMin: -500
[OS/2] TypoAscender: 935
[OS/2] TypoDescender: -265
[OS/2] WinAscent: 1025
[OS/2] WinDescent: 355
[hhea] Ascent: 1025
[hhea] Descent: -355
[hhea] LineGap: 0
[OS/2] TypoLineGap: 180
--- Height Calculations by Table Values ---
[OS/2] TypoAscender to TypoDescender: 1200
[OS/2] WinAscent to WinDescent: 1380
[hhea] Ascent to Descent: 1380
--- Delta Values ---
WinAscent to TypoAscender: 90
Ascent to TypoAscender: 90
WinDescent to TypoDescender: 90
Descent to TypoDescender: 90
--- Ratios ---
(Typo Asc + Desc + Linegap) / UPM: 1.38
(winAsc + winDesc) / UPM: 1.38
(hhea Asc + Desc) / UPM: 1.38
Then I uninstalled the original version of the fonts, installed the new fonts, and restarted Emacs, and the line spacing is indeed increased.
didn't convert to proper URL with the file path change yesterday
Sometimes there is a need to have installed a couple versions of the same font with different interline spacing. Therefore, OS should be able to treat these fonts as different.
Be interested in your expertise & thoughts about the approach that we are using to set and modify the line spacing/internal leading in fonts with this tool. Vertical metrics modifications have been a common request among developers who use the Hack typeface because few text editors aimed at developers currently support line spacing adjustments. We are restricted to modification of the font files in order to broadly support tighter and looser line spacing. While highly subjective, the issue matters to developers because some like to fit as much code into a view as humanly possible (the small font size, tightly line spaced crowd) and others want improved legibility that comes with additional whitespace between lines.
I based our vertical metrics modifications approach on Karsten Lücke's approach defined here.
The details of the OpenType table metrics changes are in the project README file here and the calculations are performed in the modify_linegap_percent()
function defined in this module.
had to reinstall this recently and had an issue where python was not found
-bash: /usr/local/bin/font-line: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory
it's recommended to use this instead
#!/usr/bin/env python
Hello, this issue is a feature-request/request-for-advice that is most likely way out of scope and potentially not even possible to apply consistently across different fonts --I am not enough of an expert to know. Perhaps there is an alternate tool that may do what I want.
From the readme, "font-line does not modify the glyph set or hints applied to the font". However, I would like to increase the height of four glyphs: ┬ │ ┼ ┴ ├ ┤┘└┌ ┐ so that the vertical components reach the top and the bottom.
Use case:
I use the monospaced font Inconsolata in a terminal with Tmux (which allows you to have multiple windows inside your terminal by rendering ASCII borders). It looks like this with the font line spacing increased by 80% with this tool:
Once the line spacing is increased, the vertical border characters no longer span the full glyph height and appear broken. I would like it to appear unbroken:
In the image above I have made a hack-ey attempt adjusting the heights in FontForge, but it requires some guesswork and eyeballing and it requires a lot of trial and error. Is there a programmatic way to achieve this, stretch the glyphs to either vertically span from top to bottom, or alternatively, vertically scale these glyphs to compensate for the percentage line space increase?
Font link: https://github.com/ryanoasis/nerd-fonts/releases/download/v2.0.0/InconsolataLGC.zip
font-line command: font-line percent 80 Inconsolata\ LGC\ Nerd\ Font\ Complete.ttf
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.