Why can't I display emoji on Pebble using Symbola font? - c

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

Related

display indian rupee character in an iText PDF [duplicate]

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.

Printing Greek characters in C

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 :)

C language printf and fprintf mess up when printing a string containing accented French characters

Here below, the extracts from the code compiled in linux:
char *Message;
Message = “Vous êtes connecté maintenant.“
printf(%s\n”, Message);
=> mess up by printing => Vous êtes connecté maintenant.
The same error happens when printing withfprintf(fout,”%s\n”, Message);
For this case the encoding in my source file was utf-8 that I edit with vim under linux. However for the output on the browser, I was using iso-8859-1:
I have changed this one to utf-8 and the output is now correct with both printf and fprintf for the above example. However, I don’t get consistent answer for another case, where, fprintf provide expected output but printf still mess up on é character:
char *line;
line = “<input type="submit" name="SignOut" value="Se déconnecter" class="btn" />”;
printf(“%s”, line); => <input type="submit" name="SignOut" value="Se d�connecter" class="btn" /> => Not OK
fprintf(fout, “%s”, line); => <input type="submit" name="SignOut" value="Se déconnecter" class="btn" /> => OK
In summary, It is surprising to see different behavior of printf under the same encoding condition (utf-8).
It worth to mention that this second example was working under output encoding iso-8859-1, while the input file was in utf-8.
There is no consistency! Whatever the encoding scheme, utf-8 or iso-8859-1, there may be something unexpected! Why?
An alternative would be to directly pass in the ASCII code for the desired letter and append them in your string.
char characterInAscii = INSERT_NUMBER_OF_ASCII_CHAR_HERE
Please check the following link for the ASCII table:
ASCII TABLE
You need to make sure that you are using iso-8859-1 character set:
and NOT utf-8. This requirement applies everywhere including your source files in C: Open them in wordpad and check the accented characters. Then save under iso and not utf, which is always the source of problem for the accented European characters.

Wrong glyphs displayed when using emWin and Korean fonts

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.

Checking for a blank line in C - Regex

Goal:
Find if a string contains a blank line. Whether it be '\n\n',
'\r\n\r\n', '\r\n\n', '\n\r\n'
Issues:
I don't think my current regex for finding '\n\n' is right. This is my first time really using regex outside of simple use of * when removing files in command line.
Is it possible to check for all of these cases (listed above) in one regex? or do I have to do 4 seperate calls to compile_regex?
Code:
int checkForBlankLine(char *reader) {
regex_t r;
compile_regex(&r, "*\n\n");
match_regex(&r, reader);
return 0;
}
void compile_regex(regex_t *r, char *matchText) {
int status;
regcomp(r, matchText, 0);
}
int match_regex(regex_t *r, char *reader) {
regmatch_t match[1];
int nomatch = regexec(r, reader, 1, match, 0);
if (nomatch) {
printf("No matches.\n");
} else {
printf("MATCH!\n");
}
return 0;
}
Notes:
I only need to worry about finding one blank line, that's why my regmatch_t match[1] is only one item long
reader is the char array containing the text I am checking for a blank line.
I have seen other examples and tried to base the code off of those examples, but I still seem to be missing something.
Thank you kindly for the help/advice.
If anything needs to be clarified please let me know.
It seems that you have to compile the regex as extended:
regcomp(&re, "\r?\n\r?\n", REG_EXTENDED);
The first atom, \r? is probably unnecessary, because it doesn't add to the blank-line condition if you don't capture the result.
In the above, blank line really means empty line. If you want blank line to mean a line that has no characters except for white space, you can use:
regcomp(&re, "\r?\n[ \t]*\r?\n", REG_EXTENDED);
(I don't think you can use the space character pattern, \s here instead of [ \t], because that would include carriage return and new-line.)
As others have already hinted at, the "simple use of * in the command line` is not a regular expression. This wildcard-matching is called file globbing and has different semantics.
Check what the * in a regex means. It's not like the wildcard "anything" in the command line. The * means that the previous component can appear any amount of times. The wildcard in regex is the .. So if you want to say match anything you can do .*, which would be anything, any amount of times.
So in your case you can do .*\n\n.* which would match anything that has \n\n.
Finally, you can use or in a regex and ( ) to group stuff. So you can do something like .*(\n\n|\r\n\r\n).* And that would match anything that has a \n\n or a \r\n\r\n.
Hope that helps.
Rather than looking for only \r or \n, look for not \r or \n?
Your regex would simply be
'[^\r\n]'
and a match result of false indicates a blank line to your specification.

Resources