Javascript wrongly decodes unicode - javascript

I'm trying to get an id of a font-awesome icon. It is located in ::before style. When i use
window.getComputedStyle(document.querySelector("[id='5']"), '::before').getPropertyValue('content')
to get it, instead of "\f458", "\"\"" is returned.
I assume that JavaScript is trying to convert the code into a char but fails. Is there any way to prevent this?

The decoding works, the problem is the font. If there's no match for this character in a font you use, it'll be mangled or in the form of the unicode value in a box.
Since it's in the private area, depending on the font it might be resolved into a glyph or be mangled or be just empty/space.
Checking in the Font Awesome Cheatsheet it looks like a an icon for quidditch.
Perhaps there's a text to image/svg map somewhere on the internet (and if not, then just copy-paste localy and create one) which you might use if the font itself isn't good or you are decoding in a problematic environment (can't install fonts, etc).

Related

Using alternate font styles in a photoshop script

I'm writing a script for photoshop in Javascript to read from a list of words in a .txt document one at a time, add them to the image, export and then move onto the next word etc. Thats all well and good but I need to use an alternate style of the font, specifically I need to use single story "a" (circle with a line on the right) rather than the default a (circle with a curvy part on top), Is there a way to specify which stylistic set to use for the font within the script? You can do this within photoshop itself by clicking "Stylistic Alternates" in the type settings part of the text layer properties.
EDIT TLDR: I need my JS Photoshop script to use a stylistic alternate of a font, this setting here. How can I do this in the script?
I think achieving this via script will be a major pain. It may be possible using Action Manager scripting and the cryptic code generated by ScriptListener.
Maybe you'll be better off simply setting on a different font altogether.

Multiple font-families for bidi text

I have unmarked bidi text like
<span>The verb קָרָא has no expressed subject</span>
I want to style it (in the browser) depending on its direction: That is, I want a Hebrew font for the Hebrew and an English font for the English. I don't suppose there's any way of doing it based on whether it's ltr or rtl when it's not marked but perhaps there's some way using unicode ranges or something.
I could use regex to put spans around text that falls in particular unicode ranges but I'm hoping for a CSS only solution (or one that doesn't involve extra markup - it's user generated text and the user needs to be able to modify it as well).
Something like (I know this doesn't exist):
.bidi-text {
font-family-rtl: "EZRA SIL"
font-family-ltr: "Comic Sans"
}
Otherwise, maybe there's a better js solution? Or some way to tell the browser to use certain fonts for certain glyps?

Can a CodeMirror 'mode' replace tags with colors?

I want to display an ansi document (Unix terminal transcripts with escape codes to apply colors) in CodeMirror, but there is no mode for that.
I could try to make my own mode, and although it seems quite complicated, I haven't found any mode to use as a template that actually removes certain characters from the original content.
I need to remove the escape characters and use them to mark the start or end of a color.
Is this at all possible? Or does CodeMirror by design lack the possibility to do this (remove characters in a mode)?
Any other ideas?
This is possible, but awkward. A mode won't do this (as you noticed, it doesn't remove characters -- you could style them display: none, but that'll cause other problems.
An addon that listens for "change" events and uses markText 1 to style and hide pieces of the document could work. But making it clever (only updating the parts that change, rather than re-coloring the whole document on every change) requires some complexity.

Chinese characters encoding

I'm working on a multi-language website. I have a problem with the color of the Chinese characters. My text color is #333333 but the Chinese characters appear darker than the occidental chars. My content comes from a database.
I thought to do it with Javascript / jQuery. The script detects the Unicode from the paragraph with the .fromCharCode() function. But what I read was that function expects an integer and the Unicode for Chinese chars are not integers. And that should be the reason my function is not working.
EDIT
Here's an image from what I got:
My function to check for the Unicode:
if($('#container p').fromCharCode(4E00)){
alert('Chinese');
}
Any help?
The screenshot suggests that different characters have been taken from different fonts. This often happens when the primary font does not contain all the relevant characters. So the odds are that you are trying to solve the wrong problem. Perhaps you should just consider making a font suggestion that is suitable for all the characters that will appear in the content.
The code snippet is in error in several ways. For example, 4E00 should be 0x4E00. And even that way, you would check for a single character only.
You need to post the full code, or a URL, or both, to get more constructive help.
Your problem is that you are displaying Simplified Chinese in a font that was designed for Traditional Chinese. So when the display engine hits a character that's Simplified (and thus not in the Traditional font), it takes the default simplified font and uses that instead. Then it reverses back to the Traditional font. Hence the unseemly look.
You need to look into what would be the most common Simplified Chinese font (or font family) and use that specifically for Simplified Chinese texts. Something like Heiti TC and Heiti SC.

HtmlEditor and increase/decrease font size with Midas commands

I came across some cross-browser weirdness while trying to integrate the ExtJs HtmlEditor into our project:
If you decrease/increase the font size in Firefox3.6, it wraps the selected text in a '' tag with a size attribute (e.g. 'visitor'). If you do the same in Chrome6 or Safari4, it wraps it into a '' tag with 'style=font-size...' attribute ( e.g. 'visitor'). Therefore, once you change the font size in Firefox, you won't be able to modify it in Safari or Chrome and vice versa.
This is done by the browser's Midas engine (as documented here: http://www.mozilla.org/editor/midas-spec.html). The implementation calls:
document.execCommand('FontSize', false, value); // value is the font size as a numeric value
So, there is not much I can change about it. I was about to write my own implementation of the font size changer, but after I went down the route I recognized that that would be a rather complicated implementation.
Has anyone else encountered that problem? Are there any good solutions for this one?
As long as you will save the source somewhere on a server, i would like to recommend to leave the editor as is.
On the server-side you normally will validate the source, so the validation will be a good time to transform the source to a unique style.

Categories

Resources