I'm having trouble drawing multilingual text using PIL. Let's say I want to draw text - "ひらがな - Hiragana, 히라가나". But PIL's ImageDraw.text() function takes only one font at a time, so I cannot draw this text correctly, because it requires English, Japanese, and Korean fonts all together.
So far, I had no luck finding a simple solution like passing multiple fonts to PIL, so that it can choose appropriate font for each Unicode character (Like modern SDK or web browsers do).
What I'm thinking is, I should iterate over each character, and determine which font to use for each character by myself. But I can't help thinking that there must be an easier way to do this.
Am I going in the right direction? Isn't there an easier way?
PS) It's OK to use another language or another imaging library if there's a much better solution.
You just need to pick a Unicode font. Example:
import Image
import ImageFont, ImageDraw
image=Image.new("RGB",[320,320])
draw = ImageDraw.Draw(image)
a=u"ひらがな - Hiragana, 히라가나"
font=ImageFont.truetype("/Library/Fonts/Arial Unicode.ttf",14)
draw.text((50, 50), a, font=font)
image.save("a.png")
Related
In xcode, developing for iOS "\u{1F3F3}\u{FE0F}\u{200D}\u{1F308}" is a rainbow flag.
"\u{1F3F3}" is a white flag, and "\u{1F308}" is a rainbow. The middle symbols "\u{FE0F}\u{200D}" are invisible symbols used to join these two together to make the rainbow flag symbol.
I am trying to combine unicode characters to make a rainbow infinity symbol, but not exactly sure how to implement this.
Not sure if there is an already existing unicode character or apple api I can use to do this, but would appreciate learning how to do this
I wouldn't mind having an infinity symbol over the rainbow flag either (like the apple anti-lgbt flag incident) as an alternative.
Emoji fonts are still just fonts. If they don’t contain a specific glyph, then they cannot display that glyph. The reason “🏳️🌈” looks like a rainbow flag is because someone drew a picture of a rainbow flag and then defined their font in such a way that the sequence <U+1F3F3, U+FE0F, U+200D, U+1F308> would be displayed using that specific image. Much like how someone first had to define the precise shape of the letter “A” in their font and then apply that glyph to the codepoint U+0041.
There is no image-rendering code that instinctively knows how to apply the colours of 🌈 to the shape of 🏳️ and then automatically generates a new glyph on the fly. It’s all explicitly pre-defined.
U+200D is the so-called Zero Width Joiner (ZWJ), so emoji sequences using that character are appropriately named Zero Width Joiner Sequences. They were originally invented by Apple to support emoji that weren’t part of the Unicode standard (in particular, variants of 💏, 💑, and 👪️ with different gender configurations), but later other vendors jumped on board as well and nowadays they are officially part of Unicode as an alternative way for defining new emoji without having to encode entirely new characters. Currently, about a third of all officially recommended emoji are ZWJ sequences.
In theory, any person can make up their own ZWJ sequences just by joining existing characters together (as was their original intent). In your case, “♾️+ZWJ+🌈” or <U+267E, U+FE0F, U+200D, U+1F308> would be an obvious sequence for a rainbow-coloured infinity symbol. You just have to create your own font containing the glyph you want, and then distribute that font to other people so that they can see the same glyph as you. There are just a few problems:
Making fonts with colourful glyphs is not easy. I couldn’t tell you whether there even exist freely available tools for that task.
There are four different formats for emoji fonts (used by Apple, Google, Microsoft, and Mozilla respectively) and they generally do not work on each other’s platforms, so you would need to create not just one, but several fonts unless you don’t care about people on other operating systems.
Installing your own fonts is not possible on most mobile phones, so your custom emoji would mostly only be available to desktop users.
I want to display some single-line badges (with rounded corners) in terminal but I am not aware of any box characters to use for start and end of labels. Are there any?
The label text would be normal text on coloured background, the only issue is that i need some elements to make it more visually appealing.
Not semicircles, but there will be more box-type graphics characters soon. Unicode 13.0, scheduled for March 2020*, will have a new block: "Symbols for Legacy Computing". This was designed for emulation of various 1970s and '80s computers, but some of the characters could also be useful for more modern purposes. This PDF has the code chart.
*Of course, that's just when the codepoints become official, you will still need to find a font that has the characters.
Apparently this is not possible as I failed to find any Unicode characters that do that.
The only one closer to enabling building a badge-like construct is U+258C also known as left half block: ▌.
Its sibling is U+2590.
Obviously that it does not have rounded corners so this would not help a lot visually.
In order to detect if font contains some particular character in javascript I've decided that the best way is to have fallback font where ALL unicode characters have exactly ZERO width spaces. This font would allow me to easily check existing of himself, and existing of any character in any other font (except for conrtol characters). I would just check width of character.
Do you know if such font already exists?
It should be very simple to make it with FontForge and scripting. But it is hard for me to get into FontForge and Unicode docs. If someone is fluent in FontForge, could you teach me, or just make this kind of font. I assume it is, what, like 50 script lines on Python?
https://github.com/adobe-fonts/adobe-blank – answered by Mike 'Pomax' Kamermans
Very nice. Just 7kb for woff version! My own attempts to make such a font myself in FontForge gave about 1mb for 0000-1ffff unicode range.
I am looking for an online service (or collection of images) that can return an image for any unicode code point.
Unicode.org does not have an image for each one, consider for example
http://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=31cf
EDIT: I need to use these images programmatically, so the code chart PDFs provided at unicode.org are not useful.
The images in the PDF are copyrighted, so there are legal issues around extracting them. (I am not a lawyer.) I suspect that those legal issues prevent a simple solution from being provided, unless someone wants to go to the trouble of drawing all of those images. It might happen, but seems unlikely.
Your best bet is to download a selection of fonts that collectively cover the entire range of characters, and display the characters using those fonts. There are two difficulties with this approach: combining characters and invisible characters.
The combining characters can easily be detected from the Unicode database, and you can supply a base character (such as NBSP) to use for displaying them. (There is a special code point intended for this purpose, but I can't find it at the moment.)
Invisible characters could be displayed with a dotted square box containing the abbreviation for the character. Those you may have to locate manually and construct the necessary abbreviations. I am not aware of any shortcuts for that.
Does anybody know a set of typefaces that altogether cover the whole Unicode character range? we know that it is impossible to display all unicode characters using just one or two fonts. But probably, we can find a set of fonts using them the whole Unicode range could be displayed. Does anybody have any experience?
Thank you so much in advance.
One way to find such set of fonts is to look into Windows Font Linking. If you take a look at the registry key HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink you'll see fonts that "link" to cover the complete Unicode set.
as far as i know Arial Unicode is one of the full.
Everson Mono covers a large portion of the Unicode characters, and SIL International makes a lot of different fonts for minority languages.