Giter Club home page Giter Club logo

stripfont's Introduction

StripFont

What is it?

stripfont is a dotnet cross-platform command line utility to strip unwanted characters or glyphs from a font file.
The characters we want to keep are identified by the usage of the font in an ASS script file, based on style definitions and tags (\fn).

Technically, it's just a wrapper around fontTools. The most annoying part being parsing the ASS file.

But why?

While western font files are usually light in terms of size on the disk, that's not the case for CJK (Chinese/Japanese/Korean) fonts.
Embedding such fonts in an MKV file just bloats its size and takes more time to load in memory when playing.

Install and prerequisites

Prerequisites:
You're gonna need the following:

  • dotnet 6. Can be downloaded from here
  • Python3. Download link here
  • fontTools : python3 -m pip install fonttools

Install stripfont:
You can install it by cloning this repo and running dotnet build at the root of the stripfont folder.
The binary file (./stripfont on Linux or stripfont.exe on Windows) will be available in the bin/Debug/net6.0 folder.

git clone https://github.com/nipponsei/stripfont.git
cd stripfont
dotnet build

How to run

stripfont -h
Description:
  Strip unwanted glyphs from a font file based on the usage of the font in a ASS subtitle file.

Usage:
  stripfont [options]

Options:
  --ass-file <ass-file> (REQUIRED)    The ASS scritp file to analyze.
  --font-file <font-file> (REQUIRED)  The font used in the ASS script we want to strip.
  --version                           Show version information
  -?, -h, --help                      Show help and usage information

It takes two parameters:

  • --font-file: full path of the font file we want to strip
  • --ass-file: full path of an ASS file as a source to detect the characters we want to keep

If everything goes right, the newly created font will be available in the directory of the source font file, its name being suffixed with -subset.

Example:

./stripfont --ass-file ~/_github/_wip/niehime/subs/NCOP1/NCOP1.ass --font-file ~/_github/_wip/niehime/fonts/DFHanziPenStdN-W5.otf 
Subset of font 'DFHanziPen StdN W5' successfully created.

Some comparisons

Here are a few examples using the following fonts:

Note: The resulting file size could be smaller, but in my case I decided to keep all OpenType layout features.

Font file Originial file size Total # of glyphs # of glyphs used Stripped file size
DFHanziPenStdN-W5.otf 6.64 MB 8310 120 102 KB
FOT-MatisseHatsuhiPro-B.otf 9.4 MB 9804 132 310 KB
A-OTF-SuzumushiStd-Medium.otf 3.77M 8207 52 14.7 KB

For a more visual comparison, you can check this page.

What's next?

  • Because I needed this tool like yesterday, I didn't bother to package it properly at all.That's on my TODO list.
  • I didn't check (yet) if there's a good ASS parser in dotnet out there. Maybe I'll give it a go.

stripfont's People

Contributors

domth avatar

stripfont's Issues

Limit the use of unicodes characters

Most visible characters can be passed 'as is' to pyftsubset: no need to create a list of unicode codepoints (U+xxxx).
Keep that for 'invisible' characters like U+3000 (ideographic space) which can't be used as standard char

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.