【他山之石】Leading-Trim: The Future of Digital Typesetting:数字排版的未来 —— Leading-Trim

文章目录

  • 【他山之石】Leading-Trim: The Future of Digital Typesetting:数字排版的未来 —— Leading-Trim
    • How an emerging CSS standard can fix old problems and raise the bar for web apps
    • 1. The problem with text boxes today
    • 2. How we got here: a history lesson
    • 3. Workarounds are just workarounds
    • 4. Introducing leading-trim
    • 5. Leading-trim fixes alignment issues
    • 6. Other immediate impacts: consistency and workflow improvements
    • 7. Small change, big implications
    • 8. Microsoft’s role in this effort
      • 8.1 Special thanks
      • 8.2 Questions or comments?
      • 8.3 Reference

写在前面
本文是《CSS in Depth》全新第2版12.1节(详见我的 CSS 同名翻译专栏 【CSS in Depth 2 精译_073】)中提到的一篇延伸阅读材料。由于没找到免费的完整版转载,特此整理,择日再翻译成中文,敬请关注!

【他山之石】Leading-Trim: The Future of Digital Typesetting:数字排版的未来 —— Leading-Trim

How an emerging CSS standard can fix old problems and raise the bar for web apps

by Ethan Wang, Aug 18, 2020 (9 min read)

fig12.8.1

1. The problem with text boxes today

In a standard text box, there’s almost always extra space above and below the actual text. Because of this, when you use a text box to measure and implement spacing, it ends up larger than you intended. The bigger the line height, the bigger the problem. The example below shows distances between text boxes set to 32px. As you can see, all the vertical spacing is visually much bigger than 32px, even though you set them all to the same value.

fig12.8.2

This is a common problem that spans tools and platforms. In my last Medium article, I talked about how I use the 4px baseline grid to measure spacing around text and achieve better visual accuracy. Knowing the imperfections of this approach, I kept searching for a better solution. Last June, I came across an emerging CSS feature spec called leading-trim. I’ve been working with the author of the spec, an expert from the W3C CSS Working Group, fantasai, to make sure Microsoft Design can be a part of this transformative work.

Today, we’re excited to announce that Microsoft Design is sponsoring the authoring of this new spec. This article gives an introduction to this new CSS standard, leading-trim, and what it could mean for web designers and developers.


2. How we got here: a history lesson

To understand how this became a problem, specifically on the web, we need to go back in the history of typography. Around 140 years ago, type was still set manually with individual lead boxes. To make text more readable, typesetters would put strips of lead to space lines out. (That’s where the word “leading” came from 😉) The height of the type block plus the leading add up to the total line height.

fig12.8.3

Early graphic design software in the ’80s kept the same tradition where people could add bottom leading directly to control spacing between lines, and line height would increase as a result. Other software made it a two-way street, where people could adjust the line height directly. But behind the scenes, bottom leading was always the part that was changing.

Things diverged after the invention of the web, with CSS1 debuting in 1996. The people who created CSS1 decided to split leading in half and put it above and below each line. They called it “half-leading.” Their reason was simple: make text boxes looks even.

fig12.8.4

【Leading was split in half and put above and below each line since CSS1. The browser window shown above is Internet Explorer 3.0. IE3 was the first commercial browser with CSS support. The font used is Verdana, released with the Core Fonts for the web project initiated by Microsoft back in 1996. In case you are wondering, the curves in the browser chrome are not a watermark.】

While half-leading creatively avoided uneven bounding boxes, it introduced its own problems. Each font size in a font family comes with a default line height. Default line height is usually designed to be taller than the text it contains to accommodate certain characters and accent signs. Increasing line height then adds two half-leadings, making the text box even bigger. Half-leading, together with the extra space reserved in the default line height, is the root of our text box frustrations today.

fig12.8.5 The anatomy of your average text box

【The anatomy of your average text box】


3. Workarounds are just workarounds

Some of our most popular UI design tools, such as Figma and Sketch, seem to have adopted the half-leading model and render text this way. So we experience this problem in both our design tools and browsers.

The workaround on the design side is relatively easy: you can ignore the bounding box and directly measure space against text’s cap height and baseline. It’s a manual process because most design tools don’t have snap targets for cap height and baseline, but I know we designers will do anything to make our design look good!

But if we take this approach, developers still implement only the bounding box spacing in CSS. Therefore, they would get seemingly random spacing values.

To mitigate this randomness issue, developers can “crop” the text box in CSS with negative margins. But the negative margins would need to be determined manually and are font specific, and therefore “random.” Any font, browser, operating system or locale change will inevitably throw off your carefully set margins. Besides, this technique is generally not a good coding practice and can cause unintended side effects.


4. Introducing leading-trim

Leading-trim seeks to change the standard we’ve been using for 24 years.

Leading-trim is a new CSS property that the CSS Working Group is introducing. Just as the name suggests, it works like a text box scissor. You can trim off all the extra space from reference points of your choice with just two lines of CSS.

fig12.8.6

h1 { text-edge: cap alphabetic;leading-trim: both;
}

The example above first uses text-edge (also a new property) to tell the browser the desired edge of the text is the cap height and the alphabetic baseline. Then it uses leading-trim to trim it from both sides. Note that leading-trim only affects the text box; it doesn’t cut off the text within it.

These two simple lines of CSS create a clean text box that hugs your text. This helps you achieve much more accurate spacings and create a better visual hierarchy.

fig12.8.7


5. Leading-trim fixes alignment issues

With leading-trim, you can finally fix all the mysterious alignment issues you see on your site. For example, maybe your text doesn’t always look vertically centered in a container even though the text box is.

fig12.8.8

The extra space reserved in the default line height causes text to not always be centered in the text box. With leading-trim, you can reliably vertically center your text.

fig12.8.9

Each font is also designed differently. It comes with its own default line height and the text within it could have a different size and baseline position. So sometimes even if font size, line height, and text box position stay the same, changing the font changes the alignment of the text, just like the example below.

fig12.8.10

In the second example, you can see how leading-trim prevents this and keeps the text true to form.

fig12.8.11


6. Other immediate impacts: consistency and workflow improvements

Leading-trim goes beyond making spacings and alignment more accurate. It plays a key role in enabling an accurate spacing system, paving the way for design accuracy and consistency and efficient design-to-dev handoff.

A spacing system is like t-shirt sizes for spacing values. Like how a color palette or type ramp is set up in code today, spacing values can also be represented using CSS classes. (To learn more about spacing systems, check out Nathan Curtis’s Space in Design System.)

There are a lot of benefits to having a spacing system. Designers can make spacing decisions faster, and developers can set up corresponding spacing variables to eliminate random, hard-coded values in code. But today, even if we set up a spacing system, it wouldn’t be accurate for text elements because of the extra space in the text box. If we try to ignore the bounding box in our design and “crop” the text box in code, we run into those tricky workaround issues.

fig12.8.12

【A spacing system applied to text elements without leading-trim 😕】

With leading-trim, designers can finally unlock the power of a spacing system. Starting from design, we can apply a spacing system on top of measuring optical spacing (measure against type’s cap height and baseline). In addition to accurate spacings, it will help us establish better visual hierarchies and have more confidence in our layout.Overall, we can improve design consistency across the board.

The design-to-dev handoff process will also be much smoother because developers will be able to set up the exact same system and avoid spending tons of time on layout bugs. Most importantly, the spacing systems leading-trim enables will help us deliver more visually polished products that our users trust and enjoy.


7. Small change, big implications

Beyond craftsmanship and making handoff more efficient, we hope leading-trim will turn a new page for digital typesetting, eventually motivating improvements to other standards and platforms, starting with OpenType.

Leading-trim works by browsers accessing the font metrics to find, for example, the cap height and baseline. As the standard font format, OpenType specifies what metrics to include in the font file. OpenType has been jointly developed by Microsoft and Adobe as an extension of Apple’s TrueType font format since 1997. While today OpenType has robust support for Latin scripts and CJK languages, it still lacks key metrics for other less commonly used writing systems such as Hebrew or Thai. As people adopt leading-trim, we hope this leads the way for us to add more font metrics of other writing systems to OpenType.

Ultimately, we hope leading-trim helps improve OpenType and its internationalization by ensuring equal typographical capabilities across the world. That’s just the start of the ecosystem. Once leading-trim becomes available in all the modern browsers, desktop applications that are built using web technologies, such as Figma, Teams, and VS Code, will also be able to utilize it.

The impact can also go beyond the web. Sketch has already added snap targets for cap height and baseline. Instead of holding down the Option key to show bounding box to bounding box spacing, you can hold down Control + Option to see baseline to cap height spacing. It makes measuring optical spacing a lot easier. More importantly, this shows the slow shift in the way people approach digital typesetting. We are hoping leading-trim can further encourage this change. And through this mindset change, beyond just snap targets, leading-trim might just become a new text rendering standard in our design tools and extend to our operating systems.


8. Microsoft’s role in this effort

Leading-trim is a part of the CSS Inline Layout Module Level 3 specification that fantasai is working on. There are four other proposals included in the spec with a common goal of fixing CSS text layout.

Microsoft Design is sponsoring the authoring of this spec as the first step of CSS standardization. The spec will provide the blueprint for each browser to implement so web developers and designers around the world can use the features it introduces. But we hope our involvement goes beyond that, from extending the OpenType specification to browser implementation, product integration and testing, and more.

We believe that this new specification will help move the needle in accessibility, internationalization, and craftsmanship, and we are extremely proud to be part of this initiative.

We look forward to the partnership with the CSS Working Group and fantasai, the cross-team collaboration that will happen across Microsoft, and are excited about what the future holds.


8.1 Special thanks

I’d like to extend a special thanks🎉 to my content designer, Perry Holzknecht and my manager Annie Bai for their help and support along this journey. I would also like to thank Jonah Sterling (our General Manager for Cloud+AI Studio), his design leadership team, and Ana Arriola (General Manager & Partner for AI Product Design & UX Research, NeXT.lab) for their help and guidance throughout this process. Thank you so much🎉 for making this happen!

And last, but not least, a huge thank you🎉 to Brook Durant (Senior Design Manager at Web Experience Collective (WXC) Studio) and Albert Shum (CVP of Design for WXC Studio) for sponsoring this effort!

8.2 Questions or comments?

Please don’t hesitate to let me know if you have any questions or comments. Additionally, fantasai is also welcoming feedback on the CSS Inline Layout Module Level 3 spec in the CSSWG’s GitHub repository.

8.3 Reference

Marcin Wichary’s Figma blog post Getting to the bottom of line height in Figma gave me the knowledge and inspiration that led me on this journey. I highly recommend reading it!


To stay in the know with Microsoft Design, follow us on Twitter, Instagram, Facebook or join our Windows Insider program. And if you are interested in joining our team at Microsoft, head over to aka.ms/DesignCareers.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/491175.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

MySQL基础大全(看这一篇足够!!!)

文章目录 前言一、初识MySQL1.1 数据库基础1.2 数据库技术构成1.2.1 数据库系统1.2.2 SQL语言1.2.3 数据库访问接口 1.3 什么是MySQL 二、数据库的基本操作2.1 数据库创建和删除2.2 数据库存储引擎2.2.1 MySQL存储引擎简介2.2.2 InnoDB存储引擎2.2.3 MyISAM存储引擎2.2.4 存储引…

uniapp/HBuilder X引入weex报错weex is not defined

出现错误: ‍[⁠ReferenceError⁠]‍ {message: "weex is not defined"} 在www.iconfont.cn把想要的图标放进个人项目中并且下载css文件: 进入HBuilder自己创建的项目中添加一个目录common,添加一个文件free-icon.css 把刚才下载…

Python随机抽取Excel数据并在处理后整合为一个文件

本文介绍基于Python语言,针对一个文件夹下大量的Excel表格文件,基于其中每一个文件,随机从其中选取一部分数据,并将全部文件中随机获取的数据合并为一个新的Excel表格文件的方法。 首先,我们来明确一下本文的具体需求。…

【数据分析】表结构数据特征、获取、使用

文章目录 表结构数据事实表及维度表表结构数据特征-1表结构数据特征-2处理缺失值-1表结构数据特征-3确定主键的方法“应用”表格结构数据、“引用”表结构数据关系型数据库管理系统商业智能系统-BIETL功能数据仓库 - DWOLAP表结构数据的横向合并表结构数据的横向合并1表结构数据…

【计算机网络】Layer4-Transport layer

目录 传输层协议How demultiplexing works in transport layer(传输层如何进行分用)分用(Demultiplexing)的定义:TCP/UDP段格式: UDPUDP的特点:UDP Format端口号Trivial File Transfer Protocol…

深入剖析MyBatis的架构原理

架构设计 简要画出 MyBatis 的架构图 >> ​​ Mybatis 的功能架构分为哪三层? API 接口层 提供给外部使用的接口 API,开发人员通过这些本地 API 来操纵数据库。接口层一接收到调用请求就会调用数据处理层来完成具体的数据处理。MyBatis 和数据库的…

CTF 攻防世界 Web: FlatScience write-up

题目名称-FlatScience 网址 index 目录中没有发现提示信息,链接会跳转到论文。 目前没有发现有用信息,尝试目录扫描。 目录扫描 注意到存在 robots.txt 和 login.php。 访问 robots.txt 这里表明还存在 admin.php admin.php 分析 在这里尝试一些 sql…

智能客户服务:科技赋能下的新体验

在当今这个数字化时代,客户服务已经不仅仅是简单的售后服务,它已竞争的关键要素之一。随着人工智能、大数据、云计算等技术的飞速发展,智能客户服务正逐步改变着传统的服务模式,为企业和消费者带来了前所未有的新体验。 一、智能客…

发布/部署WebApi服务器(IIS+.NET8+ASP.NETCore)

CS软件授权注册系统-发布/部署WebApi服务器(IIS.NET8ASP.NETCore) 目录 本文摘要VS2022配置发布VS2022发布WebApiIIS服务器部署WebApi 将程序文件复制到云服务器添加网站配置应用程序池配置dns域名配置端口阿里云ECS服务器配置19980端口配置https协议 (申请ssl证书)测试WebAp…

安卓 文件管理相关功能记录

文件管理细分为图片、视频、音乐、文件四类 目录 权限 静态声明权限 动态检查和声明权限方法 如何开始上述动态申请的流程 提示 图片 获取图片文件的对象列表 展示 删除 视频 获取视频文件的对象列表 获取视频file列表 按日期装载视频文件列表 展示 播放 删除…

找出1000以内的所有回文数

找出1000以内的所有回文数 方法概述检查回文数的方法伪代码C代码实现代码解析运行结果在计算机科学中,回文数是一种具有对称性质的数,即从左向右读和从右向左读都是相同的。例如,121、1331、12321都是回文数。本文将利用数据结构、C语言和算法的知识来编写一个程序,找出100…

如何在NGINX中实现基于IP的访问控制(IP黑白名单)?

大家好,我是锋哥。今天分享关于【如何在NGINX中实现基于IP的访问控制(IP黑白名单)?】面试题。希望对大家有帮助; 如何在NGINX中实现基于IP的访问控制(IP黑白名单)? 1000道 互联网大…

数据结构day3作业

一、完整功能【顺序表】的创建 【seqList.h】 #ifndef __SEQLIST_H__ #define __SEQLIST_H__#include <stdio.h> #include <string.h> #include <stdlib.h>//宏定义&#xff0c;线性表的最大容量 #define MAX 30//类型重定义&#xff0c;表示要存放数据的类…

云计算HCIP-OpenStack02

书接上回&#xff1a; 云计算HCIP-OpenStack01-CSDN博客 7.OpenStack核心服务 7.1Horizon&#xff1a;界面管理服务 Horizon提供了OpenStack中基于web界面的管理控制页面&#xff0c;用户或者是管理员都需要通过该服务进行OpenStack的访问和控制 界面管理服务需要依赖于keyston…

【Linux】基础IO-----重定向与缓冲区

目录 一、文件描述符分配规则&#xff1a; 二、重定向&#xff1a; 1、本质&#xff08;原理&#xff09;&#xff1a; 2、dup2的使用&#xff1a; 3、添加重定向功能到shell&#xff1a; 4、stdout与stderr&#xff1a; 三、Linux下一切皆文件&#xff1a; 四、缓冲区&…

音频客观测评方法PESQ

一、简介 语音质量感知评估&#xff08;Perceptual Evaluation of Speech Quality&#xff09;是一系列的标准&#xff0c;包括一种用于自动评估电话系统用户所体验到的语音质量的测试方法。该标准于2001年被确定为ITU-T P.862建议书[1]。PESQ被电话制造商、网络设备供应商和电…

ubuntu下anconda装pytorch

1、禁用nouveau sudo vim /etc/modprobe.d/blacklist.conf 在文件最后部分插入以下两行内容 blacklist nouveau options nouveau modeset0 更新系统 sudo update-initramfs -u 重启系统 2、装nvidia驱动 卸载原来驱动 sudo apt-get remove nvidia-* &#xff08;若安装…

Hyperledger Fabric 2.x 环境搭建

Hyperledger Fabric 是一个开源的企业级许可分布式账本技术&#xff08;Distributed Ledger Technology&#xff0c;DLT&#xff09;平台&#xff0c;专为在企业环境中使用而设计&#xff0c;与其他流行的分布式账本或区块链平台相比&#xff0c;它有一些主要的区别。 环境准备…

c++中类的应用综合练习

整理思维导图 课上类实现> 、<、!、||、&#xff01;和后自增、前自减、后自减运算符的重载 代码部分&#xff1a; #include <iostream> using namespace std; class complex {int rel;int vir; public:complex(int rel,int vir):rel(rel),vir(vir){}complex(){}…

视频智能分析平台LiteAIServer未戴安全帽检测算法助力矿山安全:精准监督矿工佩戴安全帽情况

矿山作业环境复杂多变&#xff0c;安全隐患层出不穷。其中&#xff0c;矿工未佩戴安全帽这一行为&#xff0c;看似微不足道&#xff0c;实则潜藏着巨大的安全风险。一旦发生事故&#xff0c;未佩戴安全帽的矿工将极易受到重创&#xff0c;甚至危及生命。因此&#xff0c;确保每…