Giter Club home page Giter Club logo

fontdiff's Introduction

Build Status

fontdiff

fontdiff is a utility for testing fonts. When you modify a TrueType or OpenType font, fontdiff generates a PDF showing the typeset text both before and after the change. You can use this PDF to easily review the changes and spot any errors caused by a font switch.

For every line in the text sample, the tool renders two raster images in high resolution. One image is typeset using the original font, and the second uses the new font. If there is any difference between these two high-resolution images (even if it’s just whitespace caused by kerning changes), the output PDF highlights the difference in color.

Screenshot

Since fontdiff is using HarfBuzz for OpenType shaping, text gets rendered in a similar way across Firefox, Chrome, Android, LibreOffice, XeTeX, GNOME, KDE, ChromeOS, and other products.

Sample text

To provide sample text, use HTML with embedded CSS styling:

<html lang="la">
  <p>Lorem <span style="font-weight:700">ipsum</span> dolor sit amet.</p>
</html>

The lang tag can make a difference for rendering. For example, when diffing a font with Polish letter forms, you can write <span lang="pl">ćńóśź</span> to see the Polish variants of accented letters, or <span lang="und">ćńóśź</span> to see the default design. As with HTML, you can combine spans in multiple languages into the same document. fontdiff recognizes the same language tags as modern web browsers; “und” is the “undefined” or default language.

Limitations

This is not an official Google product. We needed a lightweight tool to test our font production pipeline, so we built fontdiff, and we hope you’ll find it useful, too. However, please understand that there are some limitations:

  • Not a full renderer: HTML and CSS are much richer than what this little testing tool supports. If you miss something, please do not hesitate to make the change yourself and send a pull request.

  • Lousy codebase: The current state of the codebase isn’t something we’d be proud to call production-ready: no tests, too many dependencies, and so on. fontdiff isn’t a “real” product, and definitely not a showcase for writing production code.

  • Not secure: Do not run this tool on untrusted input. It parses complicated input formats (TrueType, OpenType, HTML) but it isn’t hardened in any way. Use it at your own risk.

  • Not a sample generator: This tool compares how an existing sample text gets rendered in two versions of the same font. However, it won’t find text for you to render. Some font designers may want to manually craft samples. Others may want to see how an entire volume of text is rendered, or check the output of a font-affecting tool or script. Because the use cases for fontdiff are wildly different, we felt it would be best to limit its scope to the actual diffing operation.

Building

$ git clone --recursive https://github.com/googlefonts/fontdiff.git
$ cd fontdiff
$ ./src/third_party/gyp/gyp -f make --depth . --generator-output build src/fontdiff/fontdiff.gyp
$ make --directory build
$ build/out/Default/fontdiff \
    --before path/to/old/FooFont*.ttf \
    --after path/to/new/FooFont*.ttf \
    --specimen src/fontdiff/specimen.html \
    --out out.pdf

This incantation works on reasonably recent versions of Linux and MacOS X. If you want to support other platforms, feel free to make the change. Pull requests are very welcome!

Contributing

Here are a few features and concepts we’d love your help implementing, if you’re bored and/or want to get your hands dirty (or are just a magnanimous person who loves fontdiff):

  • Port to other platforms. This should be a very easy starter task for people familiar with the respective platforms. It shouldn’t take more than a few hours, since the project already uses cross-platform libraries and a cross-platform build system.

  • Testing. Currently, the codebase is entirely untested, which makes it hard to maintain the code.

  • More constructs from CSS and HTML.

  • MathML. With (even limited) support for MathML rendering, font designers could use fontdiff to test their mathematical fonts.

  • Sandboxing. To protect users against attacks that use malicious font or text sample files, set up a sandbox early in the tool’s execution and then do all the rendering inside the sandbox.

  • CSS box model. It might be nice to properly support the layout of CSS and HTML, where boxes can be inside boxes. Not sure if this is terribly important for testing/diffing fonts, but if this tickles your interest, go ahead.

  • Paragraph layout. The current paragraph layout is rather ad-hoc. On the positive side, fontdiff uses ICU for finding potential line breaks, so it can be used in testing fonts for Thai and other languages that don’t mark word boundaries. However, there is currently no hyphenation or justification, and the current support for bidirectional text is rather iffy. One option for doing this properly could be Raqm, another might be Minikin. If you want to look into this, make sure to think about the special needs for diffing fonts. In particular, a changed glyph width should not require a re-flow in the entire paragraph — the resulting diffs would become meaningless. When fontdiff breaks paragraphs into lines, it currently measures the width of text runs using both the old and the new font version. The decision about line breaking is then made based on the maximum of both these values, which means fontdiff doesn’t run into this reflowing problem. It will probably be difficult to replicate this logic when using an existing paragraph layout library. However, being able to precisely locate the difference between two fonts is important for font designers, which is why we wrote the tool in the first place.

  • Reduce binary size. To avoid dependency hell and to maintain reproducible versioning, fontdiff is statically linked to all its dependencies. This is a very intentional choice, but ICU’s data files are huge. By building a static ICU data library with only the needed data files (the break iterators), the size of the compiled fontdiff binary would shrink by about 20MB. If you are interested in this task, check out how NodeJS does it. This task shouldn’t be very difficult, but it’s probably also not the biggest problem fontdiff needs to solve.

Have fun!

fontdiff's People

Contributors

brawer avatar iverg avatar jamesgk avatar khaledhosny avatar marekjez86 avatar waldyrious avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fontdiff's Issues

Split text into script runs

Currently, fontdiff asks ICU for the most likely script code given the user-supplied BCP47 language tag, and passes this to HarfBuzz. Instead, fontdiff needs to determine script runs. For an example how to do this, see the function _raqm_resolve_scripts().

To reproduce, render this snippet with NotoSansCJK.ttc:

<html>
  <div>
    <span lang="ja"></span>
    <span lang="zh-Hani"></span>
    <span lang="zh-Hans"></span>
    <span lang="zh-Hant"></span>
    <span lang="ko"></span>
  </div>
</html>

Currently, it looks like this:

The first two letterforms are correct. However, all Chinese letterforms should have the shape of the second glyph, i.e. with a diagonal instead of horizontal stroke in the middle.

(Proposal) Allow arbitrary font-weight values

fontdiff seems to round weights to the nearest 100. I'd guess this existing behavior is CSS spec-compliant, but I wonder if it would be useful to allow any arbitrary weight? Perhaps in anticipation of the spec changing for variable fonts.

colors to highlight glyph differences are confusing

cannot tell the difference between green/red colors and the lighter green/red colors. looks like a bug.

build/out/Default/fontdiff --before before/NotoSansCherokee-Regular.ttf --after after/NotoSansCherokee-Regular.ttf --specimen ~/out/chr-Cher_udhr.html --out NotoSansCherokee-Regular.pdf

image

Files to reproduce this bug is
here

Bad shaping with Noto Sans Cherokee

fontdiff uses Harfbuzz, but the shaping is currently broken sometimes.

To reproduce, use fontdiff on NotoSansCherokee-Regular.otf with the following command:

fontdiff --before NotoSansCherokee-Regular.otf --after NotoSansCherokee-Regular.otf
    --specimen sample.html --out output.pdf

with the following sample.html file:

<html lang="chr">
  <div>Ꭰ̋ Ꭱ̋ Ꭲ̋ Ꭳ̋ Ꭴ̋ Ꭵ̋ Ꭶ̋ Ꭷ̋ Ꭸ̋ Ꭹ̋ Ꭺ̋ Ꭻ̋ Ꭼ̋ Ꭽ̋ Ꭾ̋ Ꭿ̋</div>
</html>

Expected to see the same shapes as rendered by hb-view:

expected-hb-view

Observed:

observed-fontdiff

A recent release for OSX/macOS?

The latest release was roughly a year ago, and building the whole thing was quite a hassle, with all those submodule dependencies. The binary is quite small (great job!), so could you release binaries for OSX please?

Tatweel should force joining

The Arabic Tatweel should force joining.

<html lang="ar">
  <p>
    <span style="font-weight:100">&#x0634;</span>
    <span style="font-weight:200">&#x0634;</span>
    <span style="font-weight:300">&#x0634;</span>
    <span style="font-weight:400">&#x0634;</span>
    <span style="font-weight:500">&#x0634;</span>
    <span style="font-weight:600">&#x0634;</span>
    <span style="font-weight:700">&#x0634;</span>
    <span style="font-weight:800">&#x0634;</span>
    <span style="font-weight:900">&#x0634;</span>
  </p>

  <p>
    <span style="font-weight:100">&#x0640;&#x0634;&#x0640;</span>
    <span style="font-weight:200">&#x0640;&#x0634;&#x0640;</span>
    <span style="font-weight:300">&#x0640;&#x0634;&#x0640;</span>
    <span style="font-weight:400">&#x0640;&#x0634;&#x0640;</span>
    <span style="font-weight:500">&#x0640;&#x0634;&#x0640;</span>
    <span style="font-weight:600">&#x0640;&#x0634;&#x0640;</span>
    <span style="font-weight:700">&#x0640;&#x0634;&#x0640;</span>
    <span style="font-weight:800">&#x0640;&#x0634;&#x0640;</span>
    <span style="font-weight:900">&#x0640;&#x0634;&#x0640;</span>
  </p>
</html>

Observed rendering:

image

Expected: The second line should have joined characters, as in ـشـ .

Can I change the button image?

Hello I'm a college student who is interested in this project.
I was thinking of changing the button image while looking at this site.
Please see the button image and code I made and reply.

image link :
https://postfiles.pstatic.net/MjAxODA1MjhfMjg2/MDAxNTI3NTA3MjIzMTI4.DHTCus-TvKvQE9jwbFYVaIJcetkekebRlhnm-TS67M4g.9cgwyqrW4_z5mDKDq7JxpNaD-1mZ1fhQLiKsEZq3wogg.PNG.20gmlwl/SUBMIT_이미지.png?type=w773

image

source code :

<title>Image Button</title> "SEARCH THIS SITE: "

"IMAGE SEARCH: "

Char-by-char diffs

Have an option that computes diffs on every character in the before/after fonts. Perhaps this could walk the cmap to find covered Unicode blocks, and then render tables similar to the Unicode charts.

Load every font in TTC collections, not just the first one

fontdiff generates an output when presented with the TTC fonts.

for example,
build/out/Default/fontdiff
--before /Users/marekj/Downloads/SourceHanSerif2ND-Regular.ttc
--after /Users/marekj/Downloads/ThirdInterimDrop/OTC/SourceHanSerif3RD-Regular.ttc
--specimen specimen/zh-cn.html
--out specimen/SourceHanSerif3RD-Regular.pdf

generates specimen/SourceHanSerif3RD-Regular.pdf

However, this TTC has three fonts [0 through 2 (inclusive)]. Does it pick font 0 always? If that's the case then I want ability to specify which font I want. Is it driven by the lang my html?

Just curious.

Hinting changes in CFF

Is there anything special I need to do to detect hinting changes in OpenType-CFF fonts?

I have two versions of a font with differences that are due to a change in the BlueFuzz value, which are clearly visible in DirectWrite and Adobe InDesign rendering. Yet fontdiff sees the fonts as identical.

I expected the FreeType CFF rasterizer to show these differences, as InDesign does show them.

fontdiff is using old tools

For example,

  • gyp is based on python 2.x (and it fails to generate make file)
  • I found an old makefile but it fails to build fontdiff (errors) on Mac OS Catalina
  • I found the old binary on my old computer and I'm going to check if it still works (if it does I might check it in :-))

Hinting changes with ttfautohint

Does this tool display differences in TrueType instruction set writes to *.ttf files with ttfautohint? If these changes in shape are not diff'd by default, is there a way to activate this through the tool? If not possible, then this is a feature request to support this if possible. It would be very useful to us to be able to view and diff unhinted and hinted renders across build versions.

Thanks!

fontdiff doesn't consider font-weights

I used fontdiff to compare Phase 3 normal TTF with a Phase 3 GX font and found that fontdiff doesn't consider "font-weight:400" in the specimen HTML and render Black weight of GX font.

~/fontdiff/build/out/Default/fontdiff --before P3TTF/NotoSansKhmer-Regular.ttf --after GX/NotoSansKhmer-GX.ttf --specimen sample_html_pages/km-Khmr_udhr.html --out out/kmGXP3TTF.PDF

មនុស្សទាំងអស់ កើតមកមានសេរីភាព និងសមភាព ក្នុងផ្នែកសេចក្ដីថ្លៃថ្នូរនិងសិទ្ធិ។ មនុស្ស មានវិចារណញ្ញាណនិងសតិសម្បជញ្ញៈជាប់ពីកំណើត ហើយគប្បីប្រព្រឹត្ដចំពោះគ្នាទៅវិញទៅមក ក្នុង ស្មារតីភាតរភាពជាបងប្អូន។

@jamesgk

Compare two fonts (ASCII and Unicode) with different text but same display.

I want to compare ASCII and Unicode fonts against ASCII and Unicode text.

Although the ASCII and Unicode text are different, with their respective fonts, they are intended to display the same text.

ASCII text: "PÀ£ÀßqÀ ¨sÁµÉ ¥ÁæaãÀªÁzÀÄzÀÄ. EzÀÄ zÀQët¨sÁgÀvÀzÀ°è ¥Àæ¹zÀÞªÁVgÀĪÀ zÁæ«qÀ ¨sÁµÉUÀ¼À ªÀUÀðPÉÌ ¸ÉÃjzÀÄzÀÄ. vÀ«Ä¼ÀÄ, vÉ®ÄUÀÄ, ªÀÄ®0iÀiÁ¼À, vÀļÀÄUÀ¼ÀÆ D ªÀUÀðPÉÌà ¸ÉÃjzÀªÀÅUÀ¼ÀÄ. F LzÀÆ ¨sÁµÉUÀ¼ÀÄ M§â¼Éà vÁ¬Ä¬ÄAzÀ d£ÀäªÉwÛzÀ CPÀÌvÀAV0iÀÄjzÀÝ ºÁUÉ. ¸ÀĪÀiÁgÀÄ 2 ¸Á«gÀ ªÀµÀðUÀ½AzÀ®Æ ‘PÀ£ÀßqÀ’ JA§ £ÁªÀÅ ªÀiÁvÀ£ÁqÀĪÀ ¨sÁµÉ §¼ÀPÉ0iÀÄ°èzÉ."

Equivalent Unicode text: "ಕನ್ನಡ ಭಾಷೆ ಪ್ರಾಚೀನವಾದುದು. ಇದು ದಕ್ಷಿಣಭಾರತದಲ್ಲಿ ಪ್ರಸಿದ್ಧವಾಗಿರುವ ದ್ರಾವಿಡ ಭಾಷೆಗಳ ವರ್ಗಕ್ಕೆ ಸೇರಿದುದು. ತಮಿಳು, ತೆಲುಗು, ಮಲಯಾಳ, ತುಳುಗಳೂ ಆ ವರ್ಗಕ್ಕೇ ಸೇರಿದವುಗಳು. ಈ ಐದೂ ಭಾಷೆಗಳು ಒಬ್ಬಳೇ ತಾಯಿಯಿಂದ ಜನ್ಮವೆತ್ತಿದ ಅಕ್ಕತಂಗಿಯರಿದ್ದ ಹಾಗೆ. ಸುಮಾರು 2 ಸಾವಿರ ವರ್ಷಗಳಿಂದಲೂ ‘ಕನ್ನಡ’ ಎಂಬ ನಾವು ಮಾತನಾಡುವ ಭಾಷೆ ಬಳಕೆಯಲ್ಲಿದೆ."

I want to compare the ASCII text with ASCII font and Unicode text with Unicode text.

Is it possible with fontdiff tool?

compare AAT vs OT fonts

Apple system fonts have both AAT and OT feature tables in them.

Can we compare single font against its AAT and OT feature tables?

Google summer of docs

Please can someone guide me towards the communication channel for Google summer of docs , i am highly motivated with the project u guys are working on

fontdiff mis-places Cherokee accents

Cherokee accents were mis-placed by fontdiff when running this command:

./build/out/Default/fontdiff --before ~/Downloads/NotoSansCherokee-VF.ttf --after ~/Downloads/NotoSansCherokee-VF.ttf --specimen specimen-Cherokee-diacritic-lowercase.html --out out.pdf && open out.pdf

The specimen file is here; font was taken from here. The same font works perfectly fine with FontView, so this must be a bug in fontdiff.

fontdiff should highlight all changes inside a line

With the attached fonts and specimen, fontdiff correctly detects all lines that have changed, but then it only highlights some parts of the change. @iverg, since you’ve written the code that colorizes chunks of text inside a single line, can you have a look?

fontdiff --before A.ttf --after B.ttf --specimen specimen.html --out out.pdf

screen shot

The files for reproducing this bug are here.

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.