I am trying to understand the anatomy of a font file, and wondering about how glyphs are mapped to keyboard characters.
As part of that, I am also wondering what you do when you have font glyphs that are not part of unicode, such as with FontAwesome icons. FontAwesome uses them in CSS like this:
.fa4-clock-o:before {
content: "\f017";
}
If I wanted to let's say type these icons out using the keyboard, not sure what I would need to do to make that possible.
Wondering if I would have to do one of these:
Build another font that maps them to ALT keycodes somehow (not sure how ALT codes work in the definition of a font).
Build a custom keyboard tool that places the correct CSS class on a div (basically don't use the font file / character mapping at all, just build a keyboard tool from scratch).
Some other approach.
Wondering if one could explain how to accomplish this at a medium level of detail (that is, I don't necessarily need to know the implementation specific details of how to do it yet, unless it's straightforward).
A sane icon font offers GSUB ligature substitution, so that if your text contains a sequence of codepoints (like those associated with c + a + r) the font does a remapping to an internal glyph (like the car icon) so while typing, you see this:
c
co
com
comp
compu
comput
compute
💻
You typed "computer", once the font sees that last r it triggers the GSUB rule for c + o + m + p + u + t + e + r -> internal_id_24663 and it shapes the text with that replacement instead.
Of course, if the internal glyph id is exposed through a CMAP table, you can also just access the glyph directly, by just specifying the USHORT that the font will be given to shape. In your example, you're directly specifying your Fontawesome icon by writing out its unicode codepoint using a hex value rather than "a letter": the font uses the (by now defacto standard) platform-agnostic Unicode mapping, and you've asked for the glyph associated with code point 0xF017, which is in the "Private Use Area" block (a range of code points from E0x000` to 0xF8FF that don't have prescribed labels for each point: vendors can put whatever they need in them, and are not guaranteed to resolve to the same glyph between versions).
I've written about font internals, including these parts, over on http://pomax.github.io/CFF-glyphlet-fonts
Glyphs are not "mapped to keyboard characters". It's rather the other way around, and it happens in multiple steps:
Your keyboard controller picks up the physical signals that are generated by the movement of the keys, converts them into scancodes, and then sends them to your computer.
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:
The angular logo is not part of the Unicode, that is, the Unicode
consortium has not defined a code point for the Angular logo.
Instead, a code point U+F420 from a private usage area is used. In
this case, "private" means that it is used only by you, by Twitter,
and by few hundred million other people (anyone who visits a website
that uses Font Awesome implicitly agrees to play on this "private"
playground by the rules defined in the font).
There is no predefined keyboard layout that maps scancodes to code points from some obscure private usage area.
There is no hardware that has all those funny logos printed on the key caps (since you probably don't use such symbols all that often, it might be a problem).
If you wanted to type text with such glyphs anyway, you would have to:
Somehow specify that you want to use a font that renders code points from the private usage area as the glyphs that you want (e.g. specify it in the CSS of a webpage)
In order to type it, you would have to define your own keyboard layout. For example on Linux, you could copy-paste some configuration file from /usr/share/X11/xkb/symbols, and modify it accordingly.
When you try to use this layout with an actual keyboard, you will probably need some hints which physical key corresponds to which glyph. E.g. you could put an image of the keyboard layout on the desktop background.
Related
I'm trying to create runic style font without meaning in any language, using FontForge.
I want it to have three to four slighty different base looks per glyph, with an option to modify them with kerning.
Is possible to assign all or part of keyboard glyphs buttons (eg.: q, w, e, t, r, ..., 1, 2, 3, ... , [, ], , ;, ', ...) to work in most text editors for keyboard combinations:
button
SHIFT + button
ALT + button
ALT + SHIFT + button
First and second can be done with just auto generated unicode versions in FontForge.
For third and fourth i have only few symbols working in my computer (Polish language) ę€óąśłńćźżĘÓĄŚŁŻŹĆŃ, so i can add their equivalents to font.
Is somewhere list of unicode numbers matching others ALT+keyboard glyph combinations?
Is needed to do something more to do like defining font language or application/system language to make it work?
Or another approach is possible to take?
Im using Windows 10 as a system and as i found correct answer to my problem is in two parts:
Create custom encoding in FontForge:
a) Custom Encodings file location: $Disk$:\Users\$Username$\AppData\Roaming\FontForge\Encodings.ps. As it is in AppData folder wise is to have its backup somewhere else. Example of custom encoding:
/fontname [
/1
/exclam
/2
/at
/3
/numbersign
/4
/dollar
/n
/nacute
/N
/Nacute
/m
/M
] def
b) Use some FontForge encoding creation options:
Save encoding to file, basing on currently active font (point a) location): Encoding->Make From Font.
Load pre-defined encoding (last ones are custom, if exists): Encoding->Reencode.
Remove not existing glyphs: Encoding->Compact (remove not existing glyphs)
Remove not existing glyphs and sort them: Encoding->Reencode
Check glyph names for FontForge in Glyph info or Glyphs editing options.
Download Microsoft Keyboard Layout Creator and use it to add matching keyboard layout to font glyphs, then add it to system layouts in system settings.
I'm working on a document describing keyboard shortcuts in GNOME and want to make text better looking than: ALT + TAB. A common way seems to be like in this thread where the buttons appear to be within the text:
https://unix.stackexchange.com/q/465681
Is this possible in LibreOffice in a proper way, or is it just inserting images inline? That doesn't seem like it would work every well with changing font size, etc. later, so I was hoping for a better solution.
You could insert real push buttons that don't do anything by following steps 1 thru 6 outlined at https://help.libreoffice.org/Common/Inserting_and_Editing_Buttons. But that approach, as well as inserting inline images, would be awkward because you'd have to worry at least about sizing, anchoring, and wrapping of surrounding text.
The approach you appear to be trying to avoid seems much more palatable, so long as you're not looking to exactly duplicate to Stack Exchange look.
As an example to demonstrate that it's workable, I did the following by applying the same Character formatting settings to each key word. This involved changing font family and size, setting light gray highlighting, adding a gray border, and changing left and right border padding from 0.02 to 0.06...
To make things easy, the settings could all be done with a single button press by creating a macro that could be applied to selected text. And since the result is just formatted text, there are no sizing, anchoring, or text wrapping issues to worry about.
One other option, as an alternative to significant text formatting, is to acquire and use a keyboard font, such as that discussed at How is the Keyboard font automatically styled as keyboard-like keys for the letters in Alt, Shift, Ctrl, Esc, and Backspace?. That would only require changing to that font to type in key representations.
Having trouble finding a way to do this, maybe it is not even possible?
In my case, for testing flow of if-statements/user-interaction, am temporarily adding 40 lines of console.log('trigger-fired-1'); throughout our code.
However, to tell them apart would like each to end with a different number, so in this case, numbers one to forty like so:
In the screen recorded gif, to replicate what I am going for, all I did was copy/paste the numbers one to nine. What I really would like is a shortcut key to generate those numbers at the end for me to eliminate that step of typing out each unique number.
Am primarily coding in Visual Studio Code or Sublime Text, and in some cases shortcuts are similar, or at least have same support but for different shortcut keys.
There are a few extensions that allow you to do this:
Text Pastry
Increment Selection
NumberMonger
For Sublime Text, the solution to this problem is the internal Arithmetic command. Something similar may or may not be available in VS Code (possibly with an extension of some sort) but I'm not familiar enough with it to say for sure.
This command allows you to provide an expression of some sort to apply to all of the cursor locations and/or selected text.
By way of demonstration, here's the example you outlined above:
The expression you provide is evaluated once for every selection/caret in the buffer at the time, and the result of the expression is inserted into the buffer (or in the case of selected text, it replaces the selection). Note also that when you invoke this command from the input panel (as in the screen recording) the panel shows you a preview of what the expression output is going to be.
The special variable i references the selection number; selections are numbered starting at 0, so the expression i + 1 has the effect of inserting the selection numbers starting at 1 instead of 0.
The special variable x refers to the text in a particular selection instead. That allows you to select some text and then transform it based on your expression. An example would be to use x * 2 immediately after the above example (make sure all of the selections are still present and wrapping the numbers) to double everything.
You can use both variables at once if you like, as well as anything in the Python math library, for example math.sqrt(i) if you want some really esoteric logs.
The example above shows the command being selected from the command palette interactively, where the expression automatically defaults to the one that you want for your example (i + 1).
If you want to have this as a key binding, you can bind a key to the arithmetic command and provide the expression directly. For example:
{
"keys": ["super+a"],
"command": "arithmetic",
"args": {
"expr": "i+1"
},
},
Try this one ...
its not like sublime
but works g
https://github.com/kuone314/VSCodeExtensionInsertSequence
I would like to be able to see all whitespace and control character explicitly in my text editor. Example Hi world! This is a new line! (pretend the new line is actually on a new line) as something like Hi\sworld!\nThis\sis\sa\snew\sline!.
Or another example: Some people like spaces while others... like tabs (pretend there is a tab after the three periods) would render as \s\sSome\speople\slike\sspaces\swhile\sothers...\tlike\tabs How can I go about doing this? Also is there a way I can explicitly enter control characters, perhaps using their Unicode value?
I'm sure some of you will want to know why I care to do this. Hacker types would find inherent appeal but, beyond the joy of knowing, an esoteric programing language like Whitespace would be much easier to write for in VS Code if this kind of explicit control were allowed.
So. Can it be done? Are the worlds great text editors powerful and flexible enough to allow for this kind of functionality?
In CudaText (free, cross platform) I can config this. I have tweaked few options (in user.json) with names unprinted_*, here is user.json for new app install:
{
"unprinted_show": true,
"unprinted_content": "sed",
"unprinted_tab_len": 0,
"unprinted_space_dot_scale": 40,
"unprinted_tab_ptr_scale": 40,
}
This makes space-chars - big dots (40%) and tab-chars - big arrows (40% pointer size). Here's screenshot
I tested CudaText with all white space chars from Wikipedia list https://en.wikipedia.org/wiki/Whitespace_character#Unicode . Most are shown by one way or another, high unicode chars (0x2000+) not shown:
line ends 0x0A or 0x0D: shown as marker "un" or "mac" or "win" at line ends
tab char 0x09: shown as arrow with pale color
space char 0x20: shown as dot with pale color
char 0x0B, 0x0C: shown as "x0B", "x0C" with pale color
char 0x85: shown as font glyph
char 0xA0: shown as pale dot, like space
char 0x1680: shown as font glyph
chars 0x2000...0x200A: shown in hex form like "x200A"
This is a follow up question to this topic:
Creating custom keyboard controls [Elm]
I'm adding a feature that allows players to customize controls. But the way arrow keys represent themselves is really weird. I'll get to that in a bit. What I have looks like this:
ck2up : Input [KeyCode]
ck2up = input [toCode 'W']
ck2down : Input [KeyCode]
ck2down = input [toCode 'S']
ck2left : Input [KeyCode]
ck2left = input [toCode 'A']
ck2right : Input [KeyCode]
ck2right = input [toCode 'D']
They receive input from Keyboard.keysDown while I'm clicking a button. This works fine for normal Char input, but when I want to use symbols I get some weird things. I wanted to give one player arrow keys by default, but since it has to be customized, I cannot use Keyboard.arrows. Player one will have:
ck1up : Input [KeyCode]
ck1up = input [8593]
ck1down : Input [KeyCode]
ck1down = input [8595]
ck1left : Input [KeyCode]
ck1left = input [8592]
ck1right : Input [KeyCode]
ck1right = input [8594]
This is taken from http://character-code.com/arrows-html-codes.php. These are the html codes for the arrow keys. I show the current keys on my buttons and the arrows show up properly:
(button ck1up.handle kd (append "up: " (fromList [fromCode pkeys1.up])))
with pkeys1.up containing the keycode. However, ingame the arrow keys don't respond. This is to be expected since html is made for layout, but when I try to use the unicode, as described http://library.elm-lang.org/catalog/elm-lang-Elm/0.13/Char toCode and fromCode, the keys ingame still don't work and I get an error icon where I expected the arrow symbols on the buttons. This might be because the unicode is in hexadecimals.
But! I can use my newly gained feature to customize controls by holding down keys while pressing a button. This did make my arrow keys work, but it showed the following symbols instead:
up: &
down: (
left: %
right: '
This means that the same unicode that made my arrow keys functional, are displaying these random symbols. Isn't that weird? If anyone know where I can find the unicode values Elm uses, that'd be great. I want to set up the arrow keys as default if no keys are entered. Does anything exist to convert these unicode to html as well, for proper display?
In case it matters, I'm still using Elm version 13.
Update
So I figured out the KeyCodes 38, 40, 37 and 39 respectively correspond to the arrow characters (and the display symbols correspond to these same values, but in html).
As you've already figured out, key codes 37-40 are the ones you need. These can also be found in the source code of Keyboard.arrows.
KeyCode is not just some random name but alludes to JavaScripts keycodes being used. I cannot find the definition with a quick search in the ECMAScript docs and other internet sources suggest that browsers were not always compatible in their use of keycodes. So this is your standard web-programming mess that's getting slowly easier to deal with. That this bleeds through into Elm is arguably bad design though, best continue this discussion on the mailing list.