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

推荐订阅源

Forbes - Security
Forbes - Security
大猫的无限游戏
大猫的无限游戏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Jina AI
Jina AI
美团技术团队
博客园 - 聂微东
博客园 - 叶小钗
Security Latest
Security Latest
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园_首页
Spread Privacy
Spread Privacy
J
Java Code Geeks
雷峰网
雷峰网
宝玉的分享
宝玉的分享
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Privacy International News Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threat Research - Cisco Blogs
The Hacker News
The Hacker News
量子位
L
LINUX DO - 热门话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
GRAHAM CLULEY
D
Darknet – Hacking Tools, Hacker News & Cyber Security
月光博客
月光博客
腾讯CDC
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tor Project blog
罗磊的独立博客
V
Vulnerabilities – Threatpost
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
Project Zero
Project Zero
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tenable Blog
MyScale Blog
MyScale Blog
T
The Exploit Database - CXSecurity.com
GbyAI
GbyAI
博客园 - 【当耐特】
O
OpenAI News
Schneier on Security
Schneier on Security
S
Secure Thoughts
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Securelist
博客园 - 司徒正美

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).