How to display X-Bar statistics symbol in Java Swing label? - java

What's the best way to insert statistics symbols in a JLabel's text? For example, the x-bar? I tried assigning the text field the following with no success:
<html>x̄

Html codes will not work in Java. However, you can use the unicode escape in Java Strings.
For example:
JLabel label = new JLabel(new String("\u0304"));
Also, here is a cool website for taking Unicode text and turning it into Java String leterals.

Well, that's completely mal-formed HTML, probably even for Swing (I think you would need the </html> at the end for it to work. But I would try to never go that road if you can help it, as Swing's HTML support has many drawbacks and bugs.
You can probably simply insert the appropriate character directly, either directly in the source code if you're using Unicode or with the appropriate Unicode escape:
"x\u0304"
This should work, actually. But it depends on font support and some fonts are pretty bad in positioning combining characters. But short of drawing it yourself it should be your best option.

You can obtain x̄ in adding \u0304 to x character.
In your case, you must generate following string
"x\u0304"
The character \u0304 alone is only a overscore or overline character. It is a special Diacritic character in UNICODE table. You can use it in combination with other normal character to obtain a composite character.
You can find more information on Diacritics characters at following location //en.wikipedia.org/wiki/Combining_character
You can also use
\u0305 to have a longer bar
\u0307 to have a dot above previous character (speed in mechanic)
\u0308 to have 2 dots above previous character (accelaration in
mechanic)
\u0325 to have a circle above previous character
Example
"[x\u0305]" -> x̄
"[z\u0307]" -> x̅
"[t\u0308]" -> ṫ
"[u\u0309]" -> ü
"[A\u030A]" -> Å
In example, only x overlapped with long bar is not correctly displayed in HTML because Chrome browser has a bug (I think).
If you Paste/Copy correctly displayed character in MS Word, you will see correct display of all these characters.
To type a new overlined character in MS Word, you type the character and immediately after you press Alt & 0 774 where 0774 is the base 10 representation of diacritic overline character.

Related

How to use wingdings in java

How to display wingdings2 symbols in java. I tried googling but i couldn't find much help.
http://www.alanwood.net/demos/wingdings-2.html
Please refer the above link. I would like to display the white diamond symbol.
Wingdings is a font-based trick
The old Wingdings was a hack, a font that used alternate designs as the glyph. For example, where a NUMBER SIGN (pound sign, hash mark) was expected when using character position 35, a fountain pen image appears instead.
For this hack to succeed, (a) the user must have the desired Wingdings font installed, and (b) the text being displayed must use that font specifically.
Unicode
Nowadays, it likely makes sense to use emoji or other image characters defined among the 143,859 characters in Unicode. Those characters are each assigned a number, a code point, using numbers over the range of about a million.
Perhaps this character would work for you: ◇ Unicode Character 'WHITE DIAMOND' (U+25C7) at decimal code point 9,671.
System.out.println( "◇ = WHITE DIAMOND" ) ;
Your user needs a font, any font, that provides a glyph for that particular character. Modern OSes are skilled at automatically finding and using a secondary font with such a glyph if a displayed text block’s primary font is lacking. Understand that no single font provides a glyph for each and every character in Unicode.
There are likely other diamond-related characters too that a search might expose.
As a Java programmer, you can simply paste your desired character into your source code. Be sure to use UTF-8 as the character encoding of your file.

How can I put Tolkeins Elvish in Java

I'm wondering, I saw that Tengwar, an Elvish language created by Tolkien, has some Unicode values. How could I get them into a JavaFX window or console output? I just get a question mark in the console and a box in the JavaFX window.
I'm just trying to say hello in Elvish. The character I tried to use is Hyarmen. The website says that I'm supposed to use
"\u1xy28"
but that didn't work so I tried
"\E020"
which at least didn't give me an error. Can anyone help?
First, "\u1xy28" is incorrect because it contains 2 non hexa characters xy after a \u prefix.
For the rest, according to the document from the official Unicode Consortium about Special Areas and Format Characters
23.5 Private-Use Characters
Private-use characters are assigned Unicode code points whose interpretation is not specified
by this standard and whose use may be determined by private agreement among cooperating
users. These characters are designated for private use and do not have defined,
interpretable semantics except by private agreement.
...
The primary Private Use Area consists of code points in the range U+E000 to U+F8FF, for
a total of 6,400 private-use characters.
That means that you can decide to use those code points for Tengwar characters, but you cannot hope that a standard font will know how to display them (because they are reserved for private use), and you will have to find a dedicated font.
Near the end of the wikipedia page you linked, you can find a link to a comprehensive list of tengwar fonts
I must say that I have not tested any of them...

Why deleteSurroundingText doesn't work with emojis and select all?

I'm working on a custom keyboard and I'm using deleteSurroundingText to delete characters. I only have two issue with this. deleteSurroundingText doesn't work well while deleting emojis. I need to press del button twice in order to get rid of single emoji. And second del key is not working with select all option.
case Keyboard.KEYCODE_DELETE:
getCurrentInputConnection().deleteSurroundingText(1,0);
break;
This is what happens to emoji when I press try to del an emoji:
?
It turns into a question mark.
Also, when I try to del text by doing select all nothing happens.
Any help would be appreciated
Java use 16-bit characters (see note in the documentation). So one character can store codepoint from U+0000 to U+FFFF.
Modern unicode define codepoint range from U+0000 to U+10FFFF.
Most of emojis have codepoints beyond U+FFFF. To represent such codepoints so called "surrogate pairs" are used.
In other words each emoji (and all other codepoints beyond U+FFFF boundary) are represented by two consequent characters in the string.
When you call deleteSurroundingText(1,0); you corrupt surrogate pair. Not yet deleted part of surrogate pair are rendered as an ? mark.
Documentation for deleteSurroundingText() specially emphasize this case:
IME authors: please be careful not to delete only half of a surrogate pair. Also take care not to delete more characters than are in the editor, as that may have ill effects on the application. Calling this method will cause the editor to call onUpdateSelection(int, int, int, int, int, int) on your service after the batch input is over.
Please next time read method documentation carefully before trying to use it.
To determine if character is a part of surrogate pair use Chracter::isSurrogate() method.
In the case where there is some selection, and all of it should be deleted, commitText("", 1) could be used - this will replace the selected text with an empty string.

Encoding a string in 128c barcode symbology

I am having some trouble with encoding this string into barcode symbology - Code 128.
Text to encode:
1021448642241082212700794828592311
I am using the universal encoder from idautomation.com:
https://www.bcgen.com/fontencoder/
I get the following output for the encoded text for Code 128:
Í*5LvJ8*r5;ÂoP<[7+.Î
However, in ";Âo" the character between the semi-colon and o (let us call it special A) - is not part of the extended character set used in Code128. (See the Latin Supplements at https://www.fonts2u.com/code-128.font)
Yet the same string shows a valid barcode at
https://www.bcgen.com/linear-barcode-creator.html
How?
If I use the output with the Special A on a webpage with a font face for barcodes, the special A character does not show up as the barcode (and that seems correct since the special A is not part of the character set).
What gives? Please help.
I am using the IDAutomation utility to encode the string to 128c symbology. If you can share code to do the encoding (in Java/Python/C/Perl) that would help too.
There are multiple fonts for Code128 that may use different characters to represent the barcode symbols. Make sure the font and the encoding logic match each other.
I used this one http://www.jtbarton.com/Barcodes/Code128.aspx (there is also sample code how to encode it on the site, but you have to translate it from VB). The font works for all three encodings (A, B and C).
Sorry, this is very late.
When you are dealing with the encoding of code 128, in any subset, it's a good idea to think of that coding in terms of numbers, not characters. At this level, when you have shifts, code-changes, checksums and stuff, intermixed with the data, the whole concept of "character" is lost.
However, this is what is happening:
The semicolon in the output corresponds to "27"
The lowercase o corresponds to "48" and the P to "79"
The "A with Macron" corresponds to your "00" sequence. This is why you should be dealing with numbers, not characters, at this level of encoding.
How would you expect it to show a character with a code of 00 ? That would be a space of NULL, neither of which is particularly visible.
Your software has simply rendered it the best way it can, which is to make the character 'visible' by adding 0x80 to it. If you look at charmap, you will see that code 0x80 is indeed A with macron.
The rest (indeed all) of your encoded string looks correct for a setc-encodation.

Adding Annotation with Hebrew letters in Itext

When i add annotaion using:
PdfAnnotation.createFileAttachment(writer,null,null , null, , "שם קובץ", "שם קובץ");
the Hebrew letters in the annotaion are not shown.
Is there a way to fix it?
You're using Hebrew characters in your code. That's not safe. Please replace them with a unicode notation (you'll need to know their unicode value; for instance \u00a0 is the value for a non-breaking space). If you don't do this, compilers could interpret the characters incorrectly (see the remarks that were given).
It appears to me that you don't have the correct number of parameters in the method. I assume that you're using this method.
You're using a 'short-cut' method that assumes that the characters aren't Unicode characters. Please don't. Use the method where you create a PdfFileSpecification object, and use methods such as setUnicodeFileName() with the unicode parameter set to true. This way, iText knows that the characters should be interpreted as Unicode characters.
You probably want the characters to appear from right to left. I don't know if this is supported in PDF. I browsed ISO-32000-1 and looked at Table 44 (Entries in a file specification dictionary), but all I saw was: Unicode text string that provides file specification of the form described in 7.11.2, "File Specification Strings." This is a text string encoded using PDFDocEncoding or UTF-16BE with a leading byte-order marker (as defined in 7.9.2.2, "Text String Type"). You'll have to dig into those sections if you want to know more.
You pass null as value for the Rectangle. That doesn't make sense. Are you sure you want to add a file attachment annotation? Based on your code I would assume that you want to add a document-level attachment instead. That's done like this: writer.addFileAttachment(fs); with fs an instance of the FileSpecification class.

Categories