Displaying unicode string using opengl, qt and freetype - qt

I want to display text in OGL using FTGL(wrapper for FreeType2) in Qt. I have problem with unicode->FTGL must have charcode of actually rendering char, to get glyph from truetype font, which is problematic when this char is for example one of: 'Zażółć gęślą jaźń'.
Do you have any ideas, why this code:
const unsigned char *string=(const unsigned char*)"POCZUJ GĘŚLĄ JAŹŃ";
// for multibyte - we can't rely on sizeof(T) == character
FTUnicodeStringItr<T> ustr(string);
for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++)
{
unsigned int thisChar = *ustr++;
unsigned int nextChar = *ustr;
if(CheckGlyph(thisChar))
{
position += glyphList->Render(thisChar, nextChar,
position, renderMode);
}
}
works in Visual, but in Qt doesn't(it doesn't get proper charcodes, so it displays brackets)?
FTUnicodeStringItr template looks like this: http://www.nopaste.pl/11xt
Thanks.

The problem you're running into is, that C/C++ don't really support Unicode/wide characters in the source code. To be done properly you'd have to specify unicode characters either by \uXXXX escape sequences (if the compiler supports these), or by \xXX\xXX sequences building the code points from scratch. Visual C++ has wide character support (for the simple reason that all string manipulation in Windows is done in wide characters – don't confuse that with Unicode code points!).
I suggest you do the following: Qt has internationalization support built in. It boils down to define strings through the tr(...) helper function/macro with default language, i.e. english strings. Qt Linguist can then is used to create substitution rules, that are applied through the usage of tr(...) and does this with full Unicode support.

Related

make the middle letter blink

I've already solved this by not displaying the last letter of the word then locating the last letter and making it blink then I displayed the word inversely minus the last letter of course.
#include<string.h>
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
char text[255];
int txtposition,txtlength;
void main()
{
clrscr();
gets(text);
txtlength=strlen(text);
char lastchar=text[txtlength-1];
cout<<"Your text is: ";
for(txtposition=0;txtposition<txtlength-1;txtposition++)
{
cout<<text[txtposition];
}
textcolor(WHITE+128);
cprintf("%c", lastchar);
for(txtposition=txtlength-2;txtposition>=0;txtposition--)
{
cout<<text[txtposition];
}
getch();
}
Thank you for all your help!
To make the middle character blink, either your output terminal needs to be capable to present blinking characters using a special terminal control code as described here, or use the gotoxy() function from a separate thread, that displays a ' ' or the actual character, alternating for a specific blink frequency.
The standard C++ library does not provide any facility for making characters blink.
You can do that in platform-specific ways, but it's worth noting that Windows console windows do not (as far as I know) directly support text blinking, like the original IBM PC's text screen mode did. On the original IBM PC one bit of the color specification could be configured to either yield high intensity or blinking, with blinking control as the default. I always reconfigured it to high intensity in my programs, and in the corresponding mechanism for Windows console windows the bits always determine color.
So, it would be complicated to do even in Windows, unless you're running in a DOSBox, which emulates the old PC. I don't know what functionality it offers. Maybe it even does blinking.
But you can easily mark the relevant letters in other ways.
For example, you could use
uppercase versus lowercase,
underlining characters placed on the next line,
parentheses (as you did in your example here),
colors (platform specific),
a different font, boldness, whatever.
I recommend updating to a modern compiler, if you have an ordinary modern PC. Compilers are free. Also you need better learning material, e.g. void main is non-standard and is only accepted by a few compilers.
Looks like for Turbo C/C++ you can you use the Graphics library and/or builtin conio functions. ( https://answers.yahoo.com/question/index?qid=20080813072809AAEguz0 )
But the above is not portable as the graphics library is specific to Turbo and conio is specific to some dos based compilers/libraries.
If you move to the a complier like gcc/g++ then you might want to look at curses library: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/

Model non-deterministic value integer in Frama-C

Could anyone please tell me is this the right model for non-deterministic values of integer and unsigned integer in Frama-C?
/* Suppose Frama-C is installed in /usr/local -default prefix */
#include "/usr/local/share/frama-c/builtin.h"
#include "/usr/local/share/frama-c/libc/limits.h"
...
#define nondet_int() Frama_C_interval(INT_MIN, INT_MAX)
#define nondet_uint() Frama_C_interval(0, UINT_MAX)
...
Are there any exceptions if I use the above code with different architectures in option -machdep?
No, in the Neon version you have to manually define the appropriate macro if you want to use another -machdep. You would typically end up with a command-line like that:
frama-c -cpp-extra-args="-D__FC_MACHDEP_X86_64" -machdep x86_64
Forthcoming Sodium release will make the -cpp-extra-args unnecessary, as well as providing by default a -I option to let preprocessor search into Frama-C's libc header, so that you won't have to provide it yourself or rely on absolute paths in your #include directive
NB: This answer is not a commitment to any particular date for the Sodium release.
One reason Frama_C_interval(0, UINT_MAX) may not work as intended is that Frama_C_interval has type int (int, int). When you happen to want the entire range of unsigned int values, that actually tends to help because the conversions that are introduced are subject to approximation, but in general the fact that Frama_C_interval is declared as returning an int is a nuisance.
The latest released version already has Frama_C_unsigned_int_interval, but it is in share/libc/__fc_builtin.h (installed to /usr/local/share/frama-c/libc/__fc_builtin.h. The file builtin.h looks like a vestigial remnant, especially with the $Id$ line dating back to when development was done under SVN.
For specifying that a value should be all possible unsigned intvalues, Frama_C_unsigned_int_interval(0, -1) saves yourself the trouble of including limit.h. The int value -1 passed as argument is converted to the largest unsigned int as per C rules.

Building argv and argc

I'm a student programmer using Qt to build a GUI application for work. The primary purpose of this application is to open some of our old style files, allows better editing and then save the file in a new format and file extension. Recently I have been asked to allow this conversion to take place from a terminal. While I do know what argv and argc are along with what they represent I am unsure how to accomplish what they want. For instance how to handle relative paths vs. absolute... maybe how to get absolute from relative; perhaps none of that is even needed. My programming experience has been primarily with guis so this is a little new to me.
Users would like the following to be ran from the terminal
application -o /fileLocation /fileDestination template(to determine new format)
I began to use for loops and if statements to begin accomplishing this when I relized that I might be taking the worng approach to all of this. I WOULD ALSO BE REALLY INTERESTED IF QT HAS SOMETHING FOR THIS! Here is what I have began coming up with:
int main(int argc, char *argv[])
{
if(argc > 1)
{
for(int i = 0; i < argc; i++)
{
if(argv[i] == "-c")
{
QString fileName = QString::fromStdString(argv[i+1]);
QString fileDestination = QString::fromStdString(argv[i+2]);
QString templateName = QString::fromStdString(argv[i+3]);
QFile fileToConvert(fileName);
if(fileToConvert.open(QFile::ReadOnly))
{
//do stuff
Thanks for reading my post and a big thanks for any contributions you make to helping me overcome this issue.
if(argv[i] == "-c")
You can't compare C strings like that. You can compare characters, so you could do
if(argv[i][0] == '-' && argv[i][1] == 'c')
But in Qt you should be using the QApplication::arguments see Obtaining command line arguments in a Qt application

Convert integer/decimal to hex on an Arduino?

How can an integer or decimal variable be converted into a hex string? I can do the opposite (convert hex to int) but I can't figure out the other way.
This is for Serial.print() hex values in an array.
Take a look at the Arduino String tutorial here. The code below was taken from that example.
// using an int and a base (hexadecimal):
stringOne = String(45, HEX);
// prints "2d", which is the hexadecimal version of decimal 45:
Serial.println(stringOne);
There are plenty of other examples on that page, though I think for floating point numbers you'll have to roll your own.
There's a simple solution, just use:
Serial.print(yourVariable, HEX);
The Streaming library provides a built in way to do this:
#include <Streaming.h>
...
Serial << "45 in hex is " << _HEX(45) << endl;
You will need to download the Library from http://arduiniana.org/libraries/streaming/ and place it in a subdirectory of your Sketchbook folder. The Menu File-Preferences will show you where that is.
This library can also be used when outputting to LCDs.

QT Can not write to a unicode file unicode strings

I am using QT Creator, created a console app. Everything is up to date. OS is Windows XP.
I have created a QString that holds some Hungarian chars. Most of the Hungarian chars do not require unicode but the chars that have double slashes for accents require unicode.
I try to write the QString contents to a file but my unicode chars lose their accents in the file. In other words, the unicode info is lost along the way.
My code is bellow.
#include <QtCore/QCoreApplication>
#include <QString>
#include <QTextStream>
#include <QDate>
#include <QFile>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QString szqLine = "NON-UnicodeIsOK: áéüúöóí NEED-Unicode: űő";
//These are Hungarian chars and require unicode. Actually, only the u & o, each having double
//slashes for eccents require unicode encoding.
//Open file for writing unicode chars to.
QFile file("out.txt");
if ( !file.open(QIODevice::WriteOnly | QIODevice::Text) ){
return 1;
}
//Stream the QString text to the file.
QTextStream out(&file);
out.setCodec("UTF-8");
out << szqLine << endl; //Use endl for flush. Does not properly write ű and ő chars.
//Accents missing in file.
file.close(); //Done with file.
return app.exec();
}
What is the encoding of your file? Using non-ascii encodings in source files often causes problems, at least when working cross-platform. I think MSVC has some problems there.
QString foo = "unicode string" uses the implicit conversion from ascii to unicode, which will also cause problems. Always explicitely specify what encoding the literal uses, e.g. by wrapping the literal using QLatin1String() if it's latin1:
QString foo = QLatin1String("some latin1 string");
or, utf-8, as it should be in your case, QString::fromUtf8():
QString foo = QString::fromUtf8( "funny characters" );
Before writing the string to a file (which is another source for possible errors, although your code looks correct), check if a qt widget (QLineEdit, for example) displays it correctly.
To avoid such errors, I prefer to keep source files pure ascii, with english strings, and then translate them using Qt's internationalization tools.
Edit: Also see the accepted answer to this question about UTF-8 literals in MSVC 2008.
Are you sure that szqLine really contains the correct characters?
Try this: QString line = QString::fromStdWString(L"NON-UnicodeIsOK: \x00E1\x00E9... NEED-Unicode: \x+0171\x0151";
... and don't use Hungarian notation ;-)

Resources