我试图了解字体文件和wondering about how glyphs are mapped to keyboard characters的结构。
作为其中的一部分,我还想知道当您拥有不属于unicode的字体字形(例如,使用FontAwesome icons时,您会怎么做)。 FontAwesome像这样在CSS中使用它们:
.fa4-clock-o:before {
content: "\f017";
}
如果我想说使用键盘输入这些图标,则不确定该怎么做。
想知道我是否必须做以下其中之一:
想知道是否可以中等程度地解释如何完成此操作(也就是说,除非很简单,否则我不必知道具体的实现细节,除非这样做)。
答案 0 :(得分:2)
理智的图标字体提供GSUB连字替换,因此,如果您的文本包含一系列代码点(例如与c + a + r
相关的代码点),则 font 会重新映射到内部字形(例如汽车图标),因此在键入时,您会看到:
c
co
com
comp
compu
comput
compute
您键入“计算机”,一旦字体看到最后一个r
,它就会触发c + o + m + p + u + t + e + r -> internal_id_24663
的GSUB规则,并用该替换来成形文本。
当然,如果内部字形ID通过CMAP表公开,则也可以直接访问字形,只需指定将赋予字体形状的USHORT。在您的示例中,您通过使用十六进制值而不是“字母”在Unicode代码点中写出它来直接指定Fontawesome图标:字体使用了(按事实上的标准)与平台无关的Unicode映射,并且您已经问过对于与代码点0xF017相关的字形,它位于“专用区域”块中(从E0x000`到0xF8FF的代码点范围,每个点都没有指定标签:供应商可以在其中放置所需的任何内容,并且不能保证在版本之间解析为相同的字形)。
上写过有关字体内部的信息,包括这些部分。答案 1 :(得分:1)
Glyphs are not "mapped to keyboard characters". It's rather the other way around, and it happens in multiple steps:
Then the component of your operating system that is responsible for the keyboard layout transforms the scancodes into codepoints of the characters. For example, on my current operating system (Linux), the mapping from scancodes to code points is defined in a configuration file somewhere in /usr/share/X11/xkb/symbols
. Here is an excerpt from the configuration file:
key <AD01> { [ q, Q, adiaeresis, Adiaeresis ] };
key <AD02> { [ w, W, aring, Aring ] };
key <AD03> { [ e, E, eacute, Eacute ] };
key <AD04> { [ r, R, registered, registered ] };
key <AD05> { [ t, T, thorn, THORN ] };
key <AD06> { [ y, Y, udiaeresis, Udiaeresis ] };
key <AD07> { [ u, U, uacute, Uacute ] };
key <AD08> { [ i, I, iacute, Iacute ] };
key <AD09> { [ o, O, oacute, Oacute ] };
key <AD10> { [ p, P, odiaeresis, Odiaeresis ] };
For example, it says that the scancode <AD04>
is mapped to the letter "r".
The symbols that you type on your keyboard using your layout somehow end up in the memory of some server, and are then served as a part of an HTML-document.
The CSS that accompanies the HTML document specifies that a particular font (e.g. Font Awesome) is to be used.
This particular font specifies that, for example, the unicode code point U+F420 should be rendered as the logo of Angular, this is why you see a hexagonal glyph with an A
in your browser.
In this whole pathway, there is no fundamental difference between the Angular logo and any other character. The minor differences are:
If you wanted to type text with such glyphs anyway, you would have to: