Friends am using itextpdf-5.3.4.jar for creating pdf. For showing rupee symbol am using custom font. I tried arial.ttf,arialbd.ttf both this font but no luck rupee symbol is not showing. For showing the rupee symbol i have followed these links but it's not working for me.
How to display indian rupee symbol in iText PDF in MVC3. This is the code I have used.
BaseFont rupee =BaseFont.createFont( "assets/arial .ttf", BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
createHeadings(cb,495,60,": " +edt_total.getText().toString(),12,rupee);
private void createHeadings(PdfContentByte cb, float x, float y, String text, int size,BaseFont fb){
cb.beginText();
cb.setFontAndSize(fb, size);
cb.setTextMatrix(x,y);
cb.showText(text.trim());
cb.endText();
}
Please help me guys.
In the comment section, Funkystein wrote that the problem you describe is typical when
you are using a font which doesn't have that glyph. or
you aren't using the right encoding.
I have written an example that illustrates this: RupeeSymbol
public static final String DEST = "results/fonts/rupee.pdf";
public static final String FONT1 = "resources/fonts/PlayfairDisplay-Regular.ttf";
public static final String FONT2 = "resources/fonts/PT_Sans-Web-Regular.ttf";
public static final String FONT3 = "resources/fonts/FreeSans.ttf";
public static final String RUPEE = "The Rupee character \u20B9 and the Rupee symbol \u20A8";
public void createPdf(String dest) throws IOException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(DEST));
document.open();
Font f1 = FontFactory.getFont(FONT1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12);
Font f2 = FontFactory.getFont(FONT2, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12);
Font f3 = FontFactory.getFont(FONT3, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12);
Font f4 = FontFactory.getFont(FONT3, BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
document.add(new Paragraph(RUPEE, f1));
document.add(new Paragraph(RUPEE, f2));
document.add(new Paragraph(RUPEE, f3));
document.add(new Paragraph(RUPEE, f4));
document.close();
}
The RUPEE constant is a String that contains the Rupee character as well as the Rupee symbol: "The Rupee character ₹ and the Rupee symbol ₨".
The characters are stored as Unicode values, because if we store the characters otherwise, they may not be rendered correctly. For instance: if you retrieve the values from a database as Winansi, you will end up with incorrect characters.
I test three different fonts (PlayfairDisplay-Regular.ttf, PT_Sans-Web-Regular.ttf and FreeSans.ttf)
and I use IDENTITY_H as encoding three times. I also use WINANSI a fourth time to show that it goes wrong if you do.
The result is a file named rupee.pdf:
As you can see, the first two fonts know how to draw the Rupee character. The third one doesn't. The first two fonts don't know how to draw the Rupee symbol. The third one does. However, if you use the wrong encoding, none of the fonts draw the correct character or symbol.
In short: you need to find a font that knows how to draw the characters or symbols you need, then you have to make sure that you are using the correct encoding (for the String as well as the Font).
You can download the full sample code here.
Related
I just extracted the problematic part of my program, I use RFID.h and SPI.h,
I just want to know how to read on a RFID card (written with an android phone)
I only write one letter : R, G, B, Y, ... (represent color) , on an Android tool I can See at sector 04 : ?TenR? When the "R" after Ten is the string that I wanna read :
char buffer_data[8];
rfid.read(0x04,buffer_data);
String myString = String(buffer_data);
Serial.println(myString);
I only want to know how to output => "R" (text on the RFID card at sector 04) : It output something like that :
22:05:15.885 ->
22:05:15.885 -> &⸮
22:05:15.885 -> ⸮⸮
With other cards (Y, B char inside) same output...
Screenshot with card data (Mifare classic 1k (716B writable)):
The lib RFID.h with rfid.read doest not work...
https://github.com/song940/RFID-RC522
don't use this lib !
The lib https://github.com/miguelbalboa/rfid is better, up to date, and can read most of tag types !
This is the fixed code to read the first text char on NTAG215 :
if (rfid.PICC_IsNewCardPresent()) {
if ( ! rfid.PICC_ReadCardSerial()) {
return;
}
Serial.println("");
String str;
byte buffer_data[18];
byte size_data = sizeof(buffer_data);
rfid.MIFARE_Read(4,buffer_data,&size_data);
str=String((char *)buffer_data);
Serial.println(str.charAt(9));
}
Ouput the first letter on the tag (if you write text data with Android NFC tools app ) only on NTAG215 (other tag = different adresses/position)!
I assume that the "square" refers to the ASCII number printed to stdout.
I would want to find out, what read_char is in HEX, so instead of printing it as a character to stdout, print the hex representation of it and see what value you get. It's difficult to give you more accurate troubleshooting steps with the limited system information available.
Is there any way to print Greek characters in C?
I'm trying to print out the word "ΑΝΑΓΡΑΜΜΑΤΙΣΜΟΣ"
with:
printf("ΑΝΑΓΡΑΜΜΑΤΙΣΜΟΣ");
but I get some random symbols as output in the console.
Set your console font to a Unicode TrueType font and emit the data using an "ANSI" mechanism (that's assuming Windows... ). For example this code prints γειά σου:
#include "windows.h"
int main()
{
SetConsoleOutputCP(1253); //"ANSI" Greek
printf("\xE3\xE5\xE9\xDC \xF3\xEF\xF5"); // encoded as windows-1253
return 0;
}
Use a console that supports Unicode, like Console2
Use wprintf or similar functions
Always use Unicode :)
I am using SEGGER emWin on an embedded system.
I have downloaded a Korean font: Korean True Type Font
And converted the font to C language data statements.
When I printed the text: 한국어 ("Korean"), nothing printed out.
The hex code for the text (UTF-8) is: \xED\x95\x9C\xEA\xB5\xAD\xEC\x96\xB4
I opened up the font in the Font Creator and noticed the glyph at offset 0xED does not match the first glyph in the text. Also, there are no glyphs at offset 0xED95 or 0x95ED.
I converted the file using 16-bit Unicode.
The hex code for the text was determined by using Google Translate, then copying the text into Notepad, saving the text as UTF-8 and then opening up the text file with a hex editor.
How do I get the hex string to print the appropriate glyphs?
Am I having a Unicode vs. UTF-8 issues?
Edit 1:
I am not calling any functions to change the encoding, as I am confused on that part.
Here's the essential code:
// alphabetize languages for display
static const Languages_t Language_map[] =
{
{"Deutsch", ESG_LANG_German__Deutsch_},
{"English", ESG_LANG_English},
{"Espa\303\361ol", ESG_LANG_Spanish__Espanol_},
{"Fran\303\247ais", ESG_LANG_French__Francais_}, /* parasoft-suppress MISRA2004-7_1 "octal sequence needed for text accents on foreign language text" */
{"Italiano", ESG_LANG_Italian__Italiano_},
{"Nederlands", ESG_LANG_Dutch__Nederlands_},
{"Portugu\303\252s", ESG_LANG_Portuguese__Portugues_}, /* parasoft-suppress MISRA2004-7_1 "octal sequence needed for text accents on foreign language text" */
{"Svenska", ESG_LANG_Swedish__Svenska_},
{"\xED\x95\x9C\xEA\xB5\xAD\xEC\x96\xB4",ESG_LANG_Korean}, // UTF-8
// {"\xFF\xFE\x5c\xD5\x6D\xAD\xB4\xC5", ESG_LANG_Korean}, // Unicode
};
for (index = ESG_LANG_English; index < ESG_LANG_MAX_LANG; index++)
{
if (index == ESG_LANG_Korean)
{
GUI_SetFont(&Font_KTimesSSK22_12pt);
}
else
{
GUI_SetFont(&GUI_FontMyriadPro_Semibold_22pt);
}
if (index == language)
{
GUI_SetColor(ESG_WHITE);
}
else
{
GUI_SetColor(ESG_AMR_BLUE);
}
(void) GUI_SetTextAlign(GUI_TA_HCENTER);
GUI_DispStringAt(Language_map[index].name,
(signed int)Language_position[index].x,
(signed int)Language_position[index].y);
}
//...
void GUI_DispStringAt(const char GUI_UNI_PTR *s, int x, int y) {
GUI_LOCK();
GUI_pContext->DispPosX = x;
GUI_pContext->DispPosY = y;
GUI_DispString(s);
GUI_UNLOCK();
}
The GUI_UNI_PTR is not for Unicode, but for "Universal":
/* Define "universal pointer". Normally, this is not needed (define will expand to nothing)
However, on some systems (AVR - IAR compiler) it can be necessary ( -> __generic),
since a default pointer can access RAM only, not the built-in Flash
*/
#ifndef GUI_UNI_PTR
#define GUI_UNI_PTR
#define GUI_UNI_PTR_USED 0
#else
#define GUI_UNI_PTR_USED 1
#endif
The emWin is performing correctly.
The system is set up for UTF-8 encodings.
The issue is finding a truetype unicode font that contains all the glyphs (bitmaps) for the Korean language. Many fonts claim to support Korean, but their glyphs are in the wrong place for unicode.
I have a long JSON-string and I want to split its logical sections in the editor with new lines. These new lines should get ignored for the output.
Unfortunately "\" (if I remember right) is compiling but leads to altered output (I think it was void spaces).
hal.console->printf("{\"type\":\"pid_cnf\",\"pit_rkp\":%.2f,\"pit_rki\":%.2f,\"pit_rimax\":%.2f,\"rol_rkp\":%.2f,\"rol_rki\":%.2f,\"rol_rimax\":%.2f,\"yaw_rkp\":%.2f,\"yaw_rki\":%.2f,\"yaw_rimax\":%.2f,\"thr_rkp\":%.2f,\"thr_rki\":%.2f,\"thr_rimax\":%.2f,\"acc_rkp\":%.2f,\"acc_rki\":%.2f,\"acc_rimax\":%.2f,\"pit_skp\":%.2f,\"rol_skp\":%.2f,\"yaw_skp\":%.2f,\"thr_skp\":%.2f,\"acc_skp\":%.2f}\n",
(double)pit_rkp, (double)pit_rki, (double)pit_rimax,
(double)rol_rkp, (double)rol_rki, (double)rol_rimax,
(double)yaw_rkp, (double)yaw_rki, (double)yaw_rimax,
(double)thr_rkp, (double)thr_rki, (double)thr_rimax,
(double)acc_rkp, (double)acc_rki, (double)acc_rimax,
(double)pit_skp, (double)rol_skp, (double)yaw_skp), (double)thr_skp), (double)acc_skp);
If you just want to split the format string over multiple lines in the source, your compiler will concatenate adjacent string literals:
hal.console->printf(
"{\"type\":\"pid_cnf\",\"pit_rkp\":%.2f,\"pit_rki\":%.2f,\"pit_rimax\":%.2f,"
"\"rol_rkp\":%.2f,\"rol_rki\":%.2f,\"rol_rimax\":%.2f,"
"\"yaw_rkp\":%.2f,\"yaw_rki\":%.2f,\"yaw_rimax\":%.2f,"
"\"thr_rkp\":%.2f,\"thr_rki\":%.2f,\"thr_rimax\":%.2f,"
"\"acc_rkp\":%.2f,\"acc_rki\":%.2f,\"acc_rimax\":%.2f,"
"\"pit_skp\":%.2f,\"rol_skp\":%.2f,\"yaw_skp\":%.2f,\"thr_skp\":%.2f,\"acc_skp\":%.2f}\n",
(double)pit_rkp, (double)pit_rki, (double)pit_rimax,
(double)rol_rkp, (double)rol_rki, (double)rol_rimax,
(double)yaw_rkp, (double)yaw_rki, (double)yaw_rimax,
(double)thr_rkp, (double)thr_rki, (double)thr_rimax,
(double)acc_rkp, (double)acc_rki, (double)acc_rimax,
(double)pit_skp, (double)rol_skp, (double)yaw_skp), (double)thr_skp), (double)acc_skp);
I added the Symbola font to my watch app, and tried to display some emoji on the Pebble, but alas, no dice.
Here's the relevant vars and functions in my code… be gentle, I'm kind of a C n00b.
Is this even the proper way to format unicode for a C string? I added the colons just as separators.
static char emoji_chars[]=":\xF0\x9F\x98\x81:\xF0\x9F\x98\x93:";
void handle_init(AppContextRef ctx) {
(void)ctx;
window_init(&window, "Window Name");
window_stack_push(&window, true /* Animated */);
text_layer_init(&emoji_layer, GRect(30, 30, 150, 50));
text_layer_set_background_color(&emoji_layer, GColorWhite);
text_layer_set_text_color(&emoji_layer, GColorBlack);
text_layer_set_font(&emoji_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SYMBOLA_24)));
text_layer_set_text(&emoji_layer, emoji_chars);
layer_add_child(&window.layer, &emoji_layer.layer);
}
void pbl_main(void *params) {
resource_init_current_app(&APP_RESOURCES);
PebbleAppHandlers handlers = {
.init_handler = &handle_init
};
app_event_loop(params, &handlers);
}
The documentation says on the argument of text_layer_set_text
The new text to set onto the TextLayer. This must be a null-terminated and valid UTF-8 string!
(note the exclamation point). "Unicode" is not a valid C string encoding, but "UTF-8" is. Inserting your icons' Unicode values as UTF-8 characters should work.
Edit
Hold on -- you already encoded the character U+1F601 as UTF-8. And it is a valid character in your font, according to http://users.teilar.gr/~g1951d/Symbola.pdf.
Have you in the font resource manifest specified those emoji characters in the characterRegex?
I also see that there is a patch for fontgen.py to include unicode here That may assist you.
https://github.com/fisakov/pebble-sdk-characterRegex