sdl ttf windows-1250 encoding - c

In file text.txt I have this sentenc:
"Příliš žluťoučký kůň úpěl ďábelské ódy."
(I think Windows uses Windows-1250 code page to represent this text.)
In my program I save it to a buffer
char string[1000]
and render string with ttf to SDL_Surface *surface
surface = TTF_RenderText_Blended(font, string, color);
/*(font is true type and support this text)*/
But it gives me not correct result:
I need some reputation points to post images
so I can only describe that ř,í,š,ž,ť,ů,ň,ď are not displayed correctly.
Is it possible to use ttf for rendering this sentence correctly?
(I tried also TTF_RenderUTF8_Blended, TTF_RenderUNICODE_Solid... with worse result.)

The docs for TTF_RenderText_Blended say that it takes a Latin-1 string (Windows-1252) - this will be why it isn't working.
You'll need to convert your input text to UTF-8 and use RenderUTF8, or to UTF-16 and use RenderUNICODE to ensure it is interpreted correctly.
How you do this depends on what platform your app is targeted to - if it is Windows, then the easiest way would be to use the MultiByteToWideChar Win32 API to convert it to UTF-16 and then use the TTF_RenderUNICODE_Blended to draw it.

My solution will be this:
Three input files. In first file there will be a set of symbols from czech alphabet.
Second file will be sprite bitmap file where graphic symbols will be sorted in the
same order as in first file. In my program symbols from third input file will be compared with symbols from first file and right section of sprite will be copied on sreen one by one.
I will leave out sdl_ttf. It has some advantages and disadvantages but I think it will work for my purposes.
Thanks for all responses

Related

How to check the given file is binary file or not in C programming?

I'm trying to check the given file is binary or not.
I refer the link given below to find the solution,
How can I check if file is text (ASCII) or binary in C
But the given solutions is not working properly, If I pass the .c file as argument, Its not working, It gives wrong output.
The possible files I may pass as argument:
a.out
filename.c
filename.txt
filename.pl
filename.php
So I need to know whether there is any function or way to solve the problem?
Thanks...
Note : [ Incase of any query, Please ask me before down vote ]
You need to clearly define what a binary file is for you, and then base your checking on that.
If you just want to filter based on file extensions, then create a list of the ones you consider binary files, and a list of the ones you don't consider binary files and then check based on that.
If you have a list of known formats rather then file extensions, attempt to parse the file in the formats, and if it doesn't parse / the parse result makes no sense, it's a binary file (for your purposes).
Depending on your OS, binary files begin with a header specifying that they are an executable and contain several informations about them (architecture, size, byte order etc.). So by trying to parse this header, you should know if a file is binary or not. If you are on mac, check the Mach-O file format, if you are on Linux, it should be ELF format. But beware, it's a lot of documentation.

how to get stream from an Image in c

Is there anyway in C to get an image, stream by stream and how can I understand how many stream there are in an Image?
the Image is in JPEEG type.
and for saving this stream in another file I'll have any problem?
You can have a look to the free OpenCV library : http://opencv.org/
Here there is a tutorial with some examples : http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/
It's largely used for this kind of treatments.
Without using any external library what you have as a jpeg image is simply a binary file. You may do whatever with it via fopen(), fscanf() or any other file functions.
for saving this stream in another file I'll have any problem?
No problem if you are just coping a jpeg image to another new file. But problem may be there if you change the image extension. Please have a look at here

'windows-1255' is not a supported encoding name

I'm writing a silverlight 5 application in which I need to read a text file from the user.
Here is a snippet of my code:
using (StreamReader reader = new StreamReader(fileStream, Encoding.GetEncoding("windows-1255")))
But I get the exception: "'windows-1255' is not a supported encoding name".
Why is that?
And then, how do I read a file in the "windows-1255" encoding? (Hebrew)
There are not many supported encodings in Silverlight. Basically, you get UTF8 and UTF16, see http://msdn.microsoft.com/en-us/library/t9a3kf7c%28VS.95%29.aspx
You can read your file as binary then convert yourself to UTF (8 or 32, I don't know Hebrew). You'll need a table of all the characters (256), then you can loop on your input file and translate directly.
i ran into this problem again,
And after lots and lots of Googleing i found this amazing tool!
http://www.hardcodet.net/2010/03/silverlight-text-encoding-class-generator
this little piece of art that was created by "Philipp Sumi (#phsumi)", takes the name or code page of a well known encoding, and creates a custom Encoding class which compiles under Silverlight.
it does so by reading the existing encoding in wpf, and redactor it to work under silverlight.

Imagettftext like C function

I need to implement a functionality similar to PHP's imagettftext function. I need to enter a text and output a bmp image based on that. I already looked at freetype but it converts character by character and is not suitable to convert the whole text to an image. I am stuck at the moment. How can I access the source code of imagettftext function or is there another library inc to do that?
OK. I solved the question. In GD library there is a function to do (but requires FreeType) that and then you can save the image in PNG format.

Extracting Spot Color equivalents from TIFF

I'm trying to get the Spot color information from a TIFF file, it normally shows up under 'channels' in Photoshop. Each extra channel would have a name, which is usually a Pantone swatch name, and a CMYK equivalent.
So far, I'm getting the TIFFTAG_PHOTOSHOP with libtiff, and stepping through the blocks within. I'm finding the IRB WORD 0x03EE, which gives me the channel names, and IRB WORD 0x03EF which gives me their color equivalents...
BUT the color equivalents are in CIELab format (Luminance, and two axis of color space data) so I'm trying to use littleCMS to convert just a few TIFF packed Lab color to CMYK.
My question: Is there an easier way? The CMYK is just an approximation of the Pantone, so if there was a quick rough translation from Lab to CMYK, I would use it.
The answer was to use the photoshop docs to parse out the binary photoshop block in the tiff file and grab the fields I needed with bit manipulation.
littleCMS did the job of LAB -> CMYK just right.

Resources