Hello.
TTF fonts are unicode fonts. What format of string should I put to the
function "pisz", to correctly print letters which have code >255?
void pisz(int x, int y, const char *txt, int font_size, int font_nr) {
fonts[font_nr]->FaceSize(font_size);
glRasterPos2f(x, y);
fonts[font_nr]->Render(txt);
}
|
|
0
|
|
|
|
Reply
|
JacekK
|
12/21/2007 5:59:38 PM |
|
JacekK <jacek.kurzyca@gmail.com> writes:
> Hello.
>
> TTF fonts are unicode fonts. What format of string should I put to the
> function "pisz", to correctly print letters which have code >255?
>
> void pisz(int x, int y, const char *txt, int font_size, int font_nr) {
> fonts[font_nr]->FaceSize(font_size);
> glRasterPos2f(x, y);
> fonts[font_nr]->Render(txt);
> }
You know the charset (unicode), which is the charset used by, for example,
the freetype library. You still have to figure which encoding is used to
encode those characters in the string. It's probably in the documentation
of the library you use (which you didn't tell to us).
Once you know the encoding input of pisz(), converting your input to the
given encoding should be fairly simple, you can for example find how UTF-8
strings are encoded on Wikipedia.
Still, you may have further work depending on which type of input you have
(i.e. some more conversion). I, for example, have in my projet to convert
X keysyms to Unicode before assembling them in a UTF-8 string. Early X
distributions didn't seems to have a easy way to convert a keysym to
Unicode (recently something like Xutf8LookupString was add), so i have to
create a function which convert a keysym to Unicode using some homemade
algorithms and lookups table, which is the method used by xterm for example.
--
folays
|
|
0
|
|
|
|
Reply
|
folays
|
12/21/2007 5:27:09 PM
|
|
JacekK pisze:
> Hello.
>
> TTF fonts are unicode fonts. What format of string should I put to the
> function "pisz", to correctly print letters which have code >255?
>
> void pisz(int x, int y, const char *txt, int font_size, int font_nr) {
> fonts[font_nr]->FaceSize(font_size);
> glRasterPos2f(x, y);
> fonts[font_nr]->Render(txt);
> }
For my purposes I have written a function which returns unicode number
for ISO-8859-2 characters:
unsigned int iso2unicode (char c)
{
switch (c) {
case '�':return 0x0105;
case '�':return 0x0104;
case '�':return 0x0107;
case '�':return 0x0106;
case '�':return 0x0118;
case '�':return 0x0119;
case '�':return 0x0141;
case '�':return 0x0142;
case '�':return 0x0143;
case '�':return 0x0144;
case '�':return 0x00D3;
case '�':return 0x00F3;
case '�':return 0x015A;
case '�':return 0x015B;
case '�':return 0x0179;
case '�':return 0x017A;
case '�':return 0x017B;
case '�':return 0x017C;
default:
return c;
};
}
Then, the unicode number have to be used for getting an index of the glyph.
below you can find the source which I have made to render a TTF
characters into a simple PixMap (this is a part of my TTF class, so for
sure will not works for you by just copy & paste, but I hope it will
give you a hint ):
PixMap *TTF::drawText (const char *text)
{
FT_BBox bbox;
PixMap *pixmap=NULL;
int error;
int ginx;
unsigned int k,i;
unsigned int offset=0, xoffset=0;
unsigned char b;
int width=0, height=0;
int yMin=0, yMax=0;
unsigned int znak;
// 1st pass - oblicz wielko�� pixmapy
for (i=0; i<strlen (text); i++) {
znak = iso2unicode (text[i]);
ginx = FT_Get_Char_Index (face, znak);
FT_Load_Glyph (face, ginx, 0);
FT_Get_Glyph (face->glyph, &glyph);
FT_Render_Glyph (face->glyph, FT_RENDER_MODE_NORMAL);
slot=face->glyph;
width+=(slot->metrics.horiAdvance / 64);
FT_Glyph_Get_CBox (glyph, 0, &bbox);
yMin = MIN (yMin, bbox.yMin);
yMax = MAX (yMax, bbox.yMax);
};
height = (yMax - yMin ) / 64;
width = ((width / 4)+1)*4;
pixmap=new PixMap;
pixmap->width=width;
pixmap->height=height;
pixmap->bpp=4;
pixmap->pixels = (unsigned char *)calloc (width*height*4, 1);
// 2 przebieg - rysujemy
for (k=0; k<strlen (text); k++) {
znak = iso2unicode (text[k]);
ginx = FT_Get_Char_Index (face, znak);
FT_Load_Glyph (face, ginx, 0);
FT_Get_Glyph (face->glyph, &glyph);
FT_Render_Glyph (face->glyph, FT_RENDER_MODE_NORMAL);
slot=face->glyph;
FT_Glyph_Get_CBox (glyph, 0, &bbox);
offset=0;
for (int i=0; i<slot->bitmap.rows; i++) {
for (int j=0; j<slot->bitmap.width; j++) {
b=slot->bitmap.buffer[offset++];
pixmap->draw (xoffset+j, (yMax-bbox.yMax)/64+i,
255,255,255,b);
};
};
xoffset += (slot->metrics.horiAdvance / 64);
};
return pixmap;
}
|
|
0
|
|
|
|
Reply
|
Krzysiek
|
12/22/2007 3:57:37 PM
|
|
|
2 Replies
178 Views
(page loaded in 0.133 seconds)
Similiar Articles: Converting fonts from pfb/pfm to ttf - comp.fontsWhen you print TrueType fonts to a PostScript printer, the printer driver may convert them ... There are occasions when you find a font that isn't the right format for you ... How to recognize a local printer on terminal server? - comp.os.ms ...How to print in TTF correctly? - comp.graphics.api.opengl ... How to recognize a local printer on terminal server? - comp.os.ms ... If I go in "Printers and faxes" I ... Convert Suitcase Font to TTF? - comp.fontsYes, if they were copied correctly from the Mac. Suit(case) is a mac font ... in vc++ project - comp ... TTF? - comp.fonts C# How to Add Fonts ttf True Type Fonts ... How to print error message to another terminal. - comp.unix ...Thank you~~~ let's see if I understood correctly: term1: bash-2.03$ tty /dev/pts ... 80x24 terminal, is ... whole reason I want to do this is so that I can print ... True Type font Installation on AIX. - comp.fontsHi I wanted to install a truetype font( *.ttf ) that i have with me on an AIX box. Can anyone give me a few pointers about, if this is possible at al... How can I add an extra character or symbol to an existing ttf file ...I downloaded a ttf of this file and thought I'd try to add it myself. It's for ... ve never known how to add a > character and then to get it to work with the right ... How to print (write) an arraw in excel from Matlab in colors ...Hi all, I would like to print my results (arrays) to excel from matlab, but ... Right arrow moves one day to the right, Ctrl ... comp.lang.perl.misc email: perl -le ... Converting BitMap fonts (*.fon) to TrueType - comp.fonts ...I have several *.fon fonts that I would like to convert to TrueType fonts. ... Maybe I didn't know how to tweak the conversion right, but the fonts looked like ... disable Save and Print programmatically - comp.text.pdfHi all, I want to disable Save and Print functions programmatically using VB or VB ... Is this possible and if so can you point me in the right direction. If you have any ... Set Page Scaling programmatically - comp.text.pdfI'm creating a PDF document using FOP but to print it correctly, I have to set Page Scaling to None in the print dialog box. Is there a way to progra... How to View a TTF | eHow.com... will enable you to view, organize and print TTF ... How to Make TTF Fonts. Choosing the right font is just as important ... True Type Fonts, or TTF fonts, are used in most ... font viewer - Piano, drums, puzzle, actions online gamesTrueType fonts are not installing correctly ; The TrueType font is installed but is not printing ... Printer - Properties, choose options to make sure "Print True Type as ... 7/10/2012 9:49:03 PM
|