-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please add a code example for converting OTF to TTF #1283
Comments
There is already a snippet that shows how to do that: |
Can this be be imported as a function from the ttLib library? I would prefer to properly import this from a library rather than copying 90 lines of code, because that is problematic licensing wise unless they are explicitly stated as public domain (which they don't appear to be). |
Not currently. But I agree we should make that a module. Maybe try to unify with the CFF-to-CFF2 as well. |
What modifications does |
@anthrotype are the things you mentioned at #802 (comment) still needed? |
@Jonast the snippets all fall under the repository MIT license unless explicitly stated otherwise. You should be able to use any snippet source under that license until a library approach is available as requested |
@chrissimpkins this is not the problem. The problem is that I can't import them, so it "infects" the project source code when I need to include them into the repository - this complicates the project license (especially for projects that are under a similarly liberal, but different license). Having it properly separate as installable dependencies doesn't do that at least for source code installs / projects that don't ship packaged with full deps, which applies to many simpler, smaller projects which are also those that suffer the most from the license complexity. |
I'm not sure if writing a “universal font flavor converter” should be in scope of the fontTools library. Would it convert a TTC into multiple TTFs? Would it convert a TTF+gvar into a set of static TTFs? Would it convert an OTF+SVG into a TTF+sbix? CFF2 to CFF and vice versa? With our without variations? And if not, why not? I don't think it's so trivial anymore to define what exactly "convert" means. Such a converter would be great but I don't think it should be placed inside fontTools. It should be a separate lib and tool. E.g. the OTF+SVG to TTF+sbix conversion obviously would require an SVG rasterizer, other conversions might require FreeType or other dependencies. I think having a library and tool that would do that (some kind of fontmake v2) would be great. It'd need to define exactly what kinds of conversions might need to happen:
Then, at least for some of these conversions, we'd need to map out what exactly needs to happen at the conversion time. Then, we'd need to be implement some of these conversions. And we'd need to clarify what is out of scope, what's not implemented etc. Compression schemes like compositization of TTF and subroutinization of CFF/CFF2 would need to be taken into account, and hinting. Potentially, there would be a lot of dependencies, and more could appear over time. I'd prefer not to cram all this potentially complex logic into the fontTools lib. |
Well, I can only speak for myself, but I only needed that exact conversion (OTF/postscript to TTF) because reportlab kinda sucks and can't handle those fonts. So I wouldn't be hugely interested in a generic conversion library - although if it existed and handled that case I'd probably use it, but right now it's just a packaging nitpick for me. |
For anyone looking to convert OTF to TTF fonts, I have packaged up the above reference script into a separate package here: https://github.com/awesometoolbox/otf2ttf It can be installed via pip: And run: Pypi package: Feedback and PRs welcome. |
Is there a way to losslessly convert TTF TrueType outlines to OTF PostScript outlines using fonttools or similar "raw" tool? I'm comfortable with fonttools TTX converting TTF to WOFF and vice versa, and with OTF2TTF converting OTF with PostScript outlines to TTF with TrueType outlines. Both tools work very well in terms of lossless quality. I've even assembled standalone TTX.EXE & OTF2TTF using PyInstaller and added EXE to my Windows 10 system PATH variable for quick and easy scripting. But I cannot find any lightweight CLI way to losslessly convert TTF TrueType to OTF PostScript. Every search result brings me to FontForge which doesn't fit my needs. I've also stumbled upon Adobe Font Development Kit for OpenType (AFDKO) but have no idea if it's any good for my needs. |
@Zopolis4 you can use bash:
|
Thank you so much for this. It worked perfectly |
A quick update with the solution to my question since Google still outputs my post and not an actual solution: 2,5 years later @ftCLI created a fonttools snippet just for that — TTF2OTF (discusion). This is awesome! |
We should probably adopt that into fonttools. |
Thanks! I've implemented a better solution in FondryTools-CLI.
Usage: https://ftcli.github.io/FoundryTools-CLI/commands/ftcli_converter.html#ftcli-converter-ttf2otf |
Thank you so much @ftCLI, it worked flawlessly with |
FWIW fonttools works just fine with PyInstaller, I use it all the time. |
Ok. For your info, with Regarding PyInstaller, I'm aware of that. Being this the module that handles the whole CLI, I fear there's not much to do: import sys
from pathlib import Path
from loguru import logger
import click
this_directory = Path(__file__).parent
plugin_folder = this_directory.joinpath("CLI")
class FoundryToolsCLI(click.MultiCommand):
def list_commands(self, ctx):
rv = []
for file in plugin_folder.iterdir():
if file.name.endswith(".py") and file.name.startswith("ftcli_"):
rv.append(file.name[6:-3])
rv.sort()
return rv
def get_command(self, ctx, cmd_name):
try:
mod = __import__(f"foundryToolsCLI.CLI.ftcli_{cmd_name}", None, None, ["cli"])
except ImportError as e:
logger.error(e)
return
return mod.cli
main = FoundryToolsCLI(help="FoundryTools Command Line Interface.")
if __name__ == "__main__":
sys.exit(main()) I'm rewriting the CLI from scratch, and it will work with PyInstaller. As a workaround, you can use PyInstaller with the files in the CLI folder by adding |
@justvanrossum I agree, FontTools do work with PyInstaller very well indeed. However my comment addressed FoundryTools-CLI issue. I'm sorry for hijacking the discussion.
Thank you for clarification, @ftCLI! Probably worth mentioning PyInstaller incompatibility in README.md for the time being. Unfortunately I couldn't succeed with creating a working executable for any of I'd like to add a small problem I faced when used ttf2otf. It fails to convert Microsoft's official Fluent UI System Icons font — FluentSystemIcons-Regular.ttf. Traceback is quite lengthy but it ends with |
Sorry, I didn't clarify. Add the following two lines to ftcli_converter.py, and then generate the executable:
I'll invesigate. Maybe open an issue. |
This worked perfectly for all variations of that font, I'm forever grateful for looking into it. FoundryTools-CLI is an extremely powerful tool indeed!
Unfortunately adding mentioned lines to
|
You have to add those lines at the end of the file. |
Worked like a charm for
P.S. I will be posting to Discussions of FoundryTools-CLI repository next time so more users could benefit. I think your work deserves to be highlighted in the community! |
Please add a code example for converting OTF to TTF. The TTX tool is mentioned which apparently can do this somehow, but I can't find it in the API. When using ttLib.TTFont.save(), the written font will remain in otf/postscript format even when saved with ".ttf" ending, so at least that function doesn't seem to do a conversion from postscript outlines to truetype outlines...
The text was updated successfully, but these errors were encountered: