Is it possible to print Bengali language with C in console? - c++

Is it possible to print Bengali Language with C in console? If it can be done, how can I do it?
I tried:
wprintf (L"Character: %lc %lc \n", L'ঈ', 2440);
This does not work. It just shows an unknown symbol. What is the best formula for working with UTF-8 format data in console? If it is possible with C++, I want to know that.

To use a language & display it is very much an OS dependent task and below are few generic possible ways to do it.
On linux :
Set Locale,
In your case it should be : setlocale(LC_ALL, 'bn_IN.utf8');
Refer : (http://www.linuxquestions.org/questions/linux-newbie-8/displaying-hindi-in-linux-command-prompt-terminal-4175448642/)
Download appropriate font & install in your system.
Check your : cd /usr/share/fonts/ for the font.
edit your .bashrc file and add your font like this:
export LANG=bn_IN.UTF-8
(Side effect your whole os may start using this font if it supports).
On Windows :
Necessary criteria for fonts to be available in a command window
How to print a unicode string to console?
Refer
Note : Your Terminal must support Unicode for any of this to work.

Related

Strikethrough text in ncurses

I am developing a terminal TUI application for myself using the ncurses library. (Running on Linux)
I cannot seem to find much info regarding the use of a "strikethrough/strikeout" text attribute when adding a string to a ncurses window using addstr and friends.
The only information I've found online was on this site:
https://midnight-commander.org/ticket/3264
Ncurses will not add [strikethrough text] because the bitfield is already fully packed.
I was wondering if there are any workarounds to this, or any official way to do this.
Any help would be appreciated.
Thanks.
ncurses has 16 bits allocated for video-attributes. SVr4 curses used 8; XOpen Curses added 7. Those 15 are defined for X/Open Curses compatibility.
Referring to the X/Open Curses documentation, there are two sets of definitions:
A_ALTCHARSET Alternate character set
A_BLINK Blinking
A_BOLD Extra bright or bold
A_DIM Half bright
A_INVIS Invisible
A_PROTECT Protected
A_REVERSE Reverse video
A_STANDOUT Best highlighting mode of the terminal
A_UNDERLINE Underlining
and
WA_ALTCHARSET Alternate character set
WA_BLINK Blinking
WA_BOLD Extra bright or bold
WA_DIM Half bright
WA_HORIZONTAL Horizontal highlight
WA_INVIS Invisible
WA_LEFT Left highlight
WA_LOW Low highlight
WA_PROTECT Protected
WA_REVERSE Reverse video
WA_RIGHT Right highlight
WA_STANDOUT Best highlighting mode of the terminal
WA_TOP Top highlight
WA_UNDERLINE Underlining
WA_VERTICAL Vertical highlight
depending on whether the bits are stored in a attr_t or a chtype (X/Open and SVr4 respectively). In ncurses, those are the same (see the manual page), so that it does not matter if one refers to A_BOLD or WA_BOLD (Solaris xpg4 curses does store those differently).
Discounting the A_ vs WA_, the two lists are different. The newer ones from X/Open Curses are rarely used. Since ncurses doesn't know what it looks like on the screen, someone could add the corresponding terminfo capability to a terminal description and ncurses would handle it.
The terminfo manual page mentions these:
The XSI Curses standard added these hardcopy capabilities. They were
used in some post-4.1 versions of System V curses, e.g., Solaris 2.5
and IRIX 6.x. Except for YI, the ncurses termcap names for them are
invented. According to the XSI Curses standard, they have no termcap
names. If your compiled terminfo entries use these, they may not be
binary-compatible with System V terminfo entries after SVr4.1; beware!
(Explaining how to modify a terminal description can be found in thousands of webpages, and is off-topic for this forum).
Possible attributes in ncurses are:
A_NORMAL Normal display (no highlight)
A_STANDOUT Best highlighting mode of the terminal.
A_UNDERLINE Underlining
A_REVERSE Reverse video
A_BLINK Blinking
A_DIM Half bright
A_BOLD Extra bright or bold
A_PROTECT Protected mode
A_INVIS Invisible or blank mode
A_ALTCHARSET Alternate character set
A_CHARTEXT Bit−mask to extract a character
COLOR_PAIR(n) Color−pair number n
Functions like attron(), attroff(), attrset() may be used to work with attributes,
Strikethrough is not and will not be available.
If you know your terminal and want your software to be able to to work just on such an terminal type AND the terminal supports strikethrough, then you can use control characters or escape sequences to activate such a funcionality.
You can use Unicode for that:
(I know it's an old question, but I had a similar issue, and this is the top result for "curses strikethrough" on Google, so this answer might be helpful to someone.)
I made it work using Python, but the strategy should work in any language:
import curses
def strike(text: str) -> str:
# See <https://stackoverflow.com/a/25244576/4039050>
return "\u0336".join(text) + "\u0336"
def main(stdscr):
message = "The quick brown fox jumps over the lazy dog."
stdscr.addstr(strike(message))
stdscr.refresh()
stdscr.getch()
if __name__ == "__main__":
curses.wrapper(main)

What is the argument for Graphics.set_font from the OCaml Graphics package?

I'm trying to use the Ocaml Graphics package. I want to create a GUI for my chat server application. My code is:
let window = Graphics.open_graph "";
Graphics.set_window_title "caml-chat";
Graphics.set_font "ubuntu";
Graphics.set_text_size 12;
Graphics.draw_string "hello!"
However, Graphics.set_font "ubuntu" does not work. The documentation says that the string argument is system dependent, but I cannot find any more information than that. The only mention I found was in the answers to this question, and it didn't work.
Does anyone know anything else about setting the font? (Or can point me in the direction of a simple graphics library with better documentation?)
Although you didn't specify your system, I will assume that it is Linux (I doubt that Windows has an ubuntu font).
On Linux, the set_font function passes the argument to the X Lib's XLoadFont function. You can use the fc-list or xfontsel utilities to query for the available fonts on your system, or call directly to the XListFonts function.
For example,
fc-list | cut -d: -f2 | sort -u
will give you a list of font families, which you can pass to set_font function. Some lines will have more than one family per line, separated with comman (,). There are many more options, you can specify various styles, sizes, etc. But this is all out of the scope. You can the fontconfig guide to learn more about the font subsystem. For example, [here], at the section "Font Names", you can find the explanation of how the font name is constructed.

How do I fix opening terminal error with c++ ncurses

I'm using CLion 2018.2.6 on MacOS. I'm trying to use ncurses but getting the error "Error opening terminal: unknown." I'm not sure how to fix this. Any help appreciated. Code below.
#include <iostream>
#include <ncurses.h>
using namespace std;
int main(){
initscr();
clear();
printw("Seems legit!");
refresh();
getch();
endwin();
}
The initscr manual page mentions this:
Unset TERM Variable
If the TERM variable is missing or empty, initscr uses the value "unknown", which normally corresponds to a terminal entry with the generic
(gn) capability. Generic entries are detected by setupterm (see
curs_terminfo(3x)) and cannot be used for full-screen operation. Other
implementations may handle a missing/empty TERM variable differently.
Also, depending on how your system is configured, ncurses may not even find the terminal database, e.g., if it is installed in a different location than the compiled-in default location. Like TERM, that can be fixed using the TERMINFO or TERMINFO_DIRS environments. As an additional complication, MacOS by default uses case-insensitive filesystems, and ncurses uses a different directory organization for that. The term(5) manual page mentions that:
A small number of terminal descriptions use uppercase characters in
their names. If the underlying filesystem ignores the difference
between uppercase and lowercase, ncurses represents the "first character" of the terminal name used as the intermediate level of a directory
tree in (two-character) hexadecimal form.
Check the path of terminfo folder in the application running system and the same path in your application like this,
Ex:- setenv("TERMINFO","/usr/share/terminfo", 1);
It working.

how to use of unicode fonts in Verifone VX675

I have a problem to write Arabic text on VeriFone vx675 pay pose model.
i trying this codes line:
int ret=set_font("Tahoma.ttf");
if (ret!=0)
{
printf("con : %d, err: %s\n",ret,strerror(errno));
}
display_at(0,0,"سلام", NO_CLEAR);
but device show an error as
Invalid Argument
could anyone say to me how i should to resolve this problem. or how i can write Unicode Arabic text in Vx675 Model.
Thanks in Advance
Disclaimer: I have not worked with the Vx675 before, nor have I tried to use an Arabic font, but I think this will work...
You can't use .ttf fonts on the VeriFone terminals. Instead, you need to use VeriFone's "Font Generation Tool" to convert a .ttf to either a .vft or .fon file.
Start "Font Generation Tool". If you installed the DTK, then it should be in your start menu under "VeriFone"
Go to the "Font" menu item and select "Convert Font".
Select "Windows Unicode Font"
Select "Arabic" as the "Custom Unicode Fonts" choice. Set whatever other styles you want.
Click through the rest of the wizard and save the font file somewhere.
Download that new font file to your terminal with the rest of your program (this is typically the step I forget to do on my first run)
When you do your "display_at" function, I'm noting that you are using the Arabic character(s) directly. I have no experience with this as to whether or not it will work, but one thing you can try if it isn't working is to use printf with numerical offsets. I don't think you'll want to do that in the long-run, but it can help you get started:
printf("%c%c%c%c%c%c%c%c", 0, 1, 2, 3, 4, 5, 6, 7);

Calls to system() do not behave the same way as in command prompt (cmd)

I need to cut&paste a folder into another folder through code in C++. But some directory names are problematic, such as the ones which have japanese symbols. However, the same commands introduced through cmd all work fine.
system("move dirName dirName2"); //work
system("move ディレクトリ dirName2"); //does not work (system cannot find the specified file)
system("move ディレクトリ.txt dirName2"); //work
Funny enough, if the item which has the japanese symbols is a file and not a folder, the operation works fine even using calls to system().
I have no idea why the second call to system() does not work or how to solve it.
PS: I'm working with Windows7.
"move dirName dirName2", it is a const char* type, while the Japanese chars are not ASII chars, you should use the unicode API here, try:
_wsystem(L"move ディレクトリ dirName2")
It is likely that you need to use _wsystem instead to accomodate the wide characters. See the relevant MSDN pagefor details, but the syntax of the call is the same.