惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Webroot Blog
Webroot Blog
AI
AI
P
Palo Alto Networks Blog
Attack and Defense Labs
Attack and Defense Labs
WordPress大学
WordPress大学
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
Spread Privacy
Spread Privacy
T
Tor Project blog
罗磊的独立博客
小众软件
小众软件
S
Security Affairs
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
Apple Machine Learning Research
Apple Machine Learning Research
T
Threatpost
NISL@THU
NISL@THU
博客园_首页
PCI Perspectives
PCI Perspectives
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
N
News and Events Feed by Topic
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Forbes - Security
Forbes - Security
博客园 - 叶小钗
D
Darknet – Hacking Tools, Hacker News & Cyber Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
L
LINUX DO - 热门话题
T
Threat Research - Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Security Latest
Security Latest
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The Cloudflare Blog
A
About on SuperTechFans
爱范儿
爱范儿
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
TaoSecurity Blog
TaoSecurity Blog
宝玉的分享
宝玉的分享
G
GRAHAM CLULEY
雷峰网
雷峰网
F
Full Disclosure
I
Intezer
Cloudbric
Cloudbric
博客园 - 三生石上(FineUI控件)
U
Unit 42

User Agent Man

Introducing Enable: Accessible Web Components You Can Learn From R.I.P. Internet Explorer: A Hate Filled Love Letter How to Fix Seizure Inducing Sequences In Videos How To Style Resized Text and Quickly Fix WCAG 1.4.4 Issues Creating Accessible HTML5 Modal Dialogs For Desktop and Mobile Using PEAT To Create Seizureless Web Animations Fixing Firefox’s Keyboard Accessibility Bug With Flex Layout Implementing An Accessible Skip Navigation Link Requires More Thought Than You’d Think Making Framework Agnostic Isomorphic Web Applications with Query Strings and HTML5 pushState
How To Fix Transformed Text in HTML5 Canvas In Firefox For Windows
zoltan · 2016-05-10 · via User Agent Man

I was on Twitter yesterday, and saw a thread regarding a great HTML5 Canvas pie chart with rotated text made by Matei Copot. In it, Ana Tudor noted that the typography didn’t look quite right in Firefox:

Refuse to use excel for piecharts for homework, so… https://t.co/xjAa82O841
play with "render" and "data.typeList" pic.twitter.com/o7NxHdqXbW

— towc (@MateiCopot) April 30, 2016

@MateiCopot Ugh, that rotated text in Firefox :(

— Ana Tudor (@anatudor) April 30, 2016

@MateiCopot Firefox 46 (current stable). pic.twitter.com/FpmJH5APmD

— Ana Tudor (@anatudor) April 30, 2016

Let’s see these screenshots up close (IE10 Windows is on the left, Firefox is on the right):

I noticed that this was only happening in Windows version of Firefox, so I initially thought it was a variation of a common issue that browsers have with rendering live text using CSS transforms. However, the fix to that problem wouldn’t apply since the chart above was using HTML5 Canvas to transform the text. I dug a little deeper, and noticed that this problem was happening because of some unique decisions the Firefox team about how Firefox renders typography in Windows. In a very lengthy blogpost, John Daggett explains how Firefox implemented DirectWrite in Firefox 6. I encourage everyone reading this to look at that post, but for the impatient out there: Mozilla received complaints that DirectWrite (the newer graphics API introduced in Windows 7) blurred some fonts at small font-sizes, so Mozilla decided Firefox should use GDI (the older graphics API for Windows) for these fonts when their font-size is below 16 pixels.

I wasn’t sure if this was the culprit for Matei’s chart, so I replaced Verdana (which is one of the fonts that uses GDI at small font-sizes) with Calibri (which isn’t on the list) and, bingo, the typography didn’t look so ugly:

For completeness sake, here is the original demo by Matei Copot, and here is my version using Calibri. Keep in mind that, as far as I’m aware, the problem only appears in Firefox for Windows.

You can change this using the about:config URL in Firefox by altering the gfx.font_rendering.cleartype_params.force_gdi_classic_for_families preference, but this is not really a way for a web developer to fix how fonts render on a user’s machine. You should just keep in mind that Firefox will not render Arial, Consolas, Courier New, Microsoft Sans Serif, Segoe UI, Tahoma, Trebuchet and MS, Verdana well when transformed in font-sizes 16 pixels and below. This is true with CSS transforms as well. Here’s an example of some CSS transformed text in Tahoma in Firefox and IE10 under Windows 8:

CSS Live Text Firefox 46
Windows 8
IE10
Windows 8

Transformed text

However, since this is CSS, you can use the filter hack that I describe in my previous blog post:

CSS Live Text Firefox 46
Windows 8
IE10
Windows 8

Transformed text

I hope this post will save someone a lot of time in how to fix this issue in both canvas and CSS.

Further Reading

  1. DirectWrite Text Rendering in Firefox 6 by John Daggett
  2. A Closer Look At Font Rendering by Tim Ahrens (an older article, but some of the information in it is still quite relevant).