My Application require is share text with facebook.I'm able to share text using this code.
Here I'm giving parameters like this:
Bundle myParames = new Bundle();
myParames.putString("message", message);asyncFacebook.request("me/feed", myParames,"POST", new FacebookPostListener(), null);
But I want share the text every letter with corresponding font like,
if myString = "stack"; then,
String newString = null;
newString.replace("s", "Ⓢ");
newString.replace("t", "Ⓣ");
newString.replace("a", "Ⓐ");
newString.replace("c", "Ⓒ");
newString.replace("k", "Ⓚ");
Then I'm able to share my text with replaced fonts.
But I want apply font from .ttf file and then share.
I tried SpannableString, But it can't convert into .string().
So I need to change library?
Those characters you are doing your replacements with are no font, but characters. Unicode characters, to be precise.
Enclosed C or circled Latin C (Ⓒ or ⓒ) is a typographical symbol. As one of many enclosed alphanumerics, the symbol is a "C" within a circle.
The capitalized symbol (Ⓒ) can be generated with the unicode encoding "U+24B8" and the UTF-8 (hex.) encoding "e2 92 b8".
Source: http://en.wikipedia.org/wiki/%E2%92%B8
So, you are replacing one character with another, and that is all you can do.
You can't pass a custom font embedded in your text to another application through something like an intent. This is not possible.
Related
I have a problem when adding characters such as "Č" or "Ć" while generating a PDF. I'm mostly using paragraphs for inserting some static text into my PDF report. Here is some sample code I used:
var document = new Document();
document.Open();
Paragraph p1 = new Paragraph("Testing of letters Č,Ć,Š,Ž,Đ", new Font(Font.FontFamily.HELVETICA, 10));
document.Add(p1);
The output I get when the PDF file is generated, looks like this: "Testing of letters ,,Š,Ž,Đ"
For some reason iTextSharp doesn't seem to recognize these letters such as "Č" and "Ć".
THE PROBLEM:
First of all, you don't seem to be talking about Cyrillic characters, but about central and eastern European languages that use Latin script. Take a look at the difference between code page 1250 and code page 1251 to understand what I mean. [NOTE: I have updated the question so that it talks about Czech characters instead of Cyrillic.]
Second observation. You are writing code that contains special characters:
"Testing of letters Č,Ć,Š,Ž,Đ"
That is a bad practice. Code files are stored as plain text and can be saved using different encodings. An accidental switch from encoding (for instance: by uploading it to a versioning system that uses a different encoding), can seriously damage the content of your file.
You should write code that doesn't contain special characters, but that use a different notations. For instance:
"Testing of letters \u010c,\u0106,\u0160,\u017d,\u0110"
This will also make sure that the content doesn't get altered when compiling the code using a compiler that expects a different encoding.
Your third mistake is that you assume that Helvetica is a font that knows how to draw these glyphs. That is a false assumption. You should use a font file such as Arial.ttf (or pick any other font that knows how to draw those glyphs).
Your fourth mistake is that you do not embed the font. Suppose that you use a font you have on your local machine and that is able to draw the special glyphs, then you will be able to read the text on your local machine. However, somebody who receives your file, but doesn't have the font you used on his local machine may not be able to read the document correctly.
Your fifth mistake is that you didn't define an encoding when using the font (this is related to your second mistake, but it's different).
THE SOLUTION:
I have written a small example called CzechExample that results in the following PDF: czech.pdf
I have added the same text twice, but using a different encoding:
public static final String FONT = "resources/fonts/FreeSans.ttf";
public void createPdf(String dest) throws IOException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(DEST));
document.open();
Font f1 = FontFactory.getFont(FONT, "Cp1250", true);
Paragraph p1 = new Paragraph("Testing of letters \u010c,\u0106,\u0160,\u017d,\u0110", f1);
document.add(p1);
Font f2 = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, true);
Paragraph p2 = new Paragraph("Testing of letters \u010c,\u0106,\u0160,\u017d,\u0110", f2);
document.add(p2);
document.close();
}
To avoid your third mistake, I used the font FreeSans.ttf instead of Helvetica. You can choose any other font as long as it supports the characters you want to use. To avoid your fourth mistake, I have set the embedded parameter to true.
As for your fifth mistake, I introduced two different approaches.
In the first case, I told iText to use code page 1250.
Font f1 = FontFactory.getFont(FONT, "Cp1250", true);
This will embed the font as a simple font into the PDF, meaning that each character in your String will be represented using a single byte. The advantage of this approach is simplicity; the disadvantage is that you shouldn't start mixing code pages. For instance: this won't work for Cyrillic glyphs.
In the second case, I told iText to use Unicode for horizontal writing:
Font f2 = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, true);
This will embed the font as a composite font into the PDF, meaning that each character in your String will be represented using more than one byte. The advantage of this approach is that it is the recommended approach in the newer PDF standards (e.g. PDF/A, PDF/UA), and that you can mix Cyrillic with Latin, Chinese with Japanese, etc... The disadvantage is that you create more bytes, but that effect is limited by the fact that content streams are compressed anyway.
When I decompress the content stream for the text in the sample PDF, I see the following PDF syntax:
As I explained, single bytes are used to store the text of the first line. Double bytes are used to store the text of the second line.
You may be surprised that these characters look OK on the outside (when looking at the text in Adobe Reader), but don't correspond with what you see on the inside (when looking at the second screen shot), but that's how it works.
CONCLUSION:
Many people think that creating PDF is trivial, and that tools for creating PDF should be a commodity. In reality, it's not always that simple ;-)
If you are using the FontProvider, I managed to solve the display of the special characters by setting the registerShippedFreeFonts parameter to true:
FontProvider dfp = new DefaultFontProvider(true, true, false);
See also: https://itextpdf.com/en/resources/books/itext-7-converting-html-pdf-pdfhtml/chapter-6-using-fonts-pdfhtml
I want to symbolize a space in an Android Button so:
in the strings.xml file I define <string name="SpaceSymbol">␣</string>
in the layout XML file I set android:text to "#string/SpaceSymbol"
When I run the application the button shows nothing.
Any ideas?
If any other character that symbolizes a space works other than ␣ I'll be glad to use it
Use the Html code corresponding to ␣ character, HTML Codes Table or HTML Special Characters
the define into the strings.xml
<string name="SpaceSymbol">␣</string>
This is an example with & character:
How can I write character & in android strings.xml
Update:
Answering your question, ␣ is non-printable character, it is just a "Space", if you want show this symbol into the button, try loading an image of that symbol into an ImageButton.
You can wrap the space char in
![CDATA[ ... ]] in the string resource..that may help you bring it in. You should check that the character is in the roboto font also
Given that the character is not represented in the Roboto font, you can use a SpannableString to replace the special character with your own image:
you should create a Drawable (or Bitmap) with the space image in it that you want to use. in this example it would be assigned to the variable 'drawable':
SpannableString textspan = new SpannableString(sb);
Pattern pattern = Pattern.compile("#_", Pattern.CASE_INSENSITIVE);
matcher = pattern.matcher(textspan);
while(matcher.find()) {
textspan.setSpan(new ImageSpan(this, drawable, ImageSpan.ALIGN_BASELINE), matcher.start(), matcher.end(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}
In your string (in this code example) you would have replaced your space symbol with the two characters "#_". The pattern will find each occurence of "#_" and replace it with the drawable.
Then you can use the SpannableString as a CharSequence argument anywhere it's defined (Toast.makeText, TextView.setText, etc)
like this :
TextView tv = (TextView) findViewById(..);
tv.setText(textspan);
I am coding a maths app and I want to show special characters such as PI, E, or subscripts and all those things.
I want to show them on the xml file of the layout.
How can I do it?
Thank you guys for all!
You can use the Unicode value for the symbol, preceded by \u. For example, the pi character is "\u03C0"
This site: http://www.dionysia.org/html/entities/symbols.html has list of elements which can be used in xml. Just watch the second element. For example:
square = √
THen you need to conver it. For example:
String symbol = Html.fromHtml(square);
Alternative link is here: http://www.hrupin.com/2011/12/how-to-put-some-special-math-symbols-in-textview-editview-or-other-android-ui-element
The characters in a string resource are unicode. You can include special characters using the \unnnn notation.
There are many places to look up the unicode values on the web. Google found this one for me:
http://inamidst.com/stuff/unidata/
I discovered today that Android can't display a small handful of Japanese characters that I'm using in my Japanese-English dictionary app.
The problem comes when I attempt to display the character via TextView.setText(). All of the characters below show up as blank when I attempt to display them in a TextView. It doesn't appear to be an issue with encoding, though - I'm storing the characters in a SQLite database and have verified that Android can understand the characters. Casting the characters to (int) retrieves proper Unicode decimal escapes for all but one of the characters:
String component = cursor.getString(cursor.getColumnIndex("component"));
Log.i("CursorAdapterGridComponents", "Character Code: " + (int) component.charAt(0) + "(" + component + ")");
I had to use Character.codePointAt() to get the decimal escape for the one problematic character:
int codePoint = Character.codePointAt(component, 0);
I don't think I'm doing anything wrong, and as String's are by default UTF-16 encoded, there should be nothing preventing them from displaying the characters.
Below are all of the decimal escapes for the seven problematic characters:
⺅ Character Code: 11909(⺅)
⺌ Character Code: 11916(⺌)
⺾ Character Code: 11966(⺾)
⻏ Character Code: 11983(⻏)
⻖ Character Code: 11990(⻖)
⺹ Character Code: 11961(⺹)
𠆢 Character Code: 131490(𠆢)
Plugging the first six values into http://unicode-table.com/en/ revealed their corresponding Unicode numbers, so I have no doubt that they're valid UTF-8 characters.
The seventh character could only be retrieved from a table of UTF-16 characters: http://www.fileformat.info/info/unicode/char/201a2/browsertest.htm. I could not use its 5-character Unicode number in setText() (as in "\u201a2") because, as I discovered earlier today, Android has no support for Unicode strings past 0xFFFF. As a result, the string was evaluated as "\u201a" + "2". That still doesn't explain why the first six characters won't show up.
What are my options at this point? My first instinct is to just make graphics out of the problematic characters, but Android's highly variable DPI environment makes this a challenging proposition. Is using another font in my app an option? Aside from that, I really have no idea how to proceed.
Is using another font in my app an option?
Sure. Find a font that you are licensed to distribute with your app and has these characters. Package the font in your assets/ directory. Create a Typeface object for that font face. Apply that font to necessary widgets using setTypeface() on TextView.
Here is a sample application demonstrating applying a custom font to a TextView.
I'm trying to generate PDF file that contains Hebrew words.
When file is created all the Hebrew letters are deleted and only the English one are
in the file.
Can any one help me with this problem?
I'm using iText 5.4.3
This is my code when i add a new paragraph
Paragraph p0 = new Paragraph("טופס קריאת שירות");
BaseFont unicode = BaseFont.createFont("assets/fonts/arial.ttf", BaseFont.IDENTITY_H , BaseFont.EMBEDDED);
Font fontHebrew = new Font(unicode, 12, Font.NORMAL);
p0.setAlignment(Paragraph.ALIGN_CENTER);
p0.setFont(fontHebrew);
//add paragraph to document
doc.add(p0);
Thank's.
The code you added is wrong on many levels.
You're adding Hebrew characters in source code. These characters can get lost if the file is saved using the wrong encoding, if the file is compiled using the wrong encoding, etc... Use the Unicode notation instead of actual characters.
Maybe not wrong, but to be checked: you're using arial.ttf, shouldn't you be using arialuni.ttf? Also: make sure you pack the ttf in your APK (you wouldn't be the first to forget to ship a resource).
I can't read Hebrew, but I know it's written from right to left. RTL isn't supported in the Paragraph class, only in PdfPCell and ColumnText.
See the examples to find out how it's done: say_peace.pdf is done using a table; ligatures_2.pdf is done using a column (the second example is in Arabic, but it's the same principle as Hebrew).