以字体当前大小来计算当前字体的上升量。
上升代表最高字符的距离,以像素为单位,高于基线。
示例
let font;
function preload() {
font = loadFont('/assets/inconsolata.otf');
}
function setup() {
createCanvas(100, 100);
background(200);
// Style the text.
textFont(font);
// Different for each font.
let fontScale = 0.8;
let baseY = 75;
strokeWeight(0.5);
// Draw small text.
textSize(24);
text('dp', 0, baseY);
// Draw baseline and ascent.
let a = textAscent() * fontScale;
line(0, baseY, 23, baseY);
line(23, baseY - a, 23, baseY);
// Draw large text.
textSize(48);
text('dp', 45, baseY);
// Draw baseline and ascent.
a = textAscent() * fontScale;
line(45, baseY, 91, baseY);
Returns
数字: 以像素为单位测量的上升值。
Notice any errors or typos? Please let us know. Please feel free to edit src/typography/attributes.js and open a pull request!