[DEL]

Hi guys,

This question is not related to server-side programming, but VC++.

I want to know which DCs I have to use to get the bitmap of chars in a font, using the GetGlyphOutline() GDI func.

Please tell me the DC related statements in [b:816ca4c086]detail[/b:816ca4c086], and [b:816ca4c086]how to initialize them[/b:816ca4c086]. The other thing is the handle of the window that is required to be passed to them, [b:816ca4c086]and how to get it![/b:816ca4c086] :confused:

I know the arguments of the GetGlyphOutline() function, except the first one, in case of the GDI function (Not the CDC member func.) and the format of a two color bitmap.

Anyway, which is better (and easier)? GetGlyphOutline() or CDC::GetGlyphOutline() ? Note that I'm having confusion over the former's first argument.

The last thing is CreateCompatibleDC(). Why (and more importantly how) should we use this!! :confused:

I have tried a lot of permutations and combinations(!), but the GDI func. always returns 0, and CDC member function returns 4, instead of the buffer length!:( (I have passed NULL as the buffer ptr and 0 as buffer size, and GGO_BITMAP as the other option). I guess all this is correct, so the only problem I think is with DCs and HWND. I don't have much of a clue about what they(DCs) are! And what's the use of GGO_METRICS??

I have to finish this program ASAP, and I want someone to help me out. I'll be grateful! I'll learn the DC stuff in detail later, but not now! No time! :)

________________________________________________

[b:816ca4c086]Oops! Forgot to add one thing - my program is Dialog-based, not SDI or MDI.[/b:816ca4c086]


well, it is very important to figure out what you are doing...

are you writing a program that will create custom font previews?

or

are you writing a windows application and you are trying to simply draw a string text on a custom control or something?


if the 2nd one then you should be overloading OnPaint() function or DrawItem, depending if you declared the control as BS_OWNERDRAW

if the 1st one, i haven't done that in vc++, but cant you just use CDC's DrawText function?

another thing, this is definition of CDC that i found and i has more than just 1 arg:

DWORD GetGlyphOutline(

UINT nChar,

UINT nFormat,

LPGLYPHMETRICS lpgm,

DWORD cbBuffer,

LPVOID lpBuffer,

const MAT2* lpmat2

) const;

also, post the function that you are trying to write.


[DEL]

Thanks Alex, but I'm not trying to do any of the things that you have mentioned. My program doesn't need to print that anywhere on the screen. My program shows a small preview of the font which the user has selected, but there are absolutely no problems with this, you need not worry about this one!

What I want to do is [b:d5ff16e12b] to get the BITMAP of a character of the font, convert it to something else and save it in a file.[/b:d5ff16e12b] The bitmap which will be returned by GetGlyphOutline() with GGO_BITMAP will be in two-color format.

[b:d5ff16e12b] My trouble is that I'm not able to initialize the DCs in a correct way, that's why I think I'm getting zero as return value. Since the character will not be printed anywhere on the screen, how should I initialize the DCs? If it requires some HANDLE, what should this handle be? [/b:d5ff16e12b]

In short, I want to know (with statements :) )how to do all this:

1) Initialize the DC that I have created - CDC dc;

2) When to select a font into it, using select object

3) Do I need to create a compatible DC, using CreateCompatibleDC();? And how?

4) Which DC's GetGlyphOutline() function to use - dc 's or the compatible dc's?

Just in case you wanted to know, my application is MFC based.

Thanks for the earlier replies, but my prog doesn't do any of that stuff.


if you are not printing it anywhere on the screen that means you can do with just CreateCompatibleDC()

once again, CDC::GetGlyphOutline() has the following arguments:

DWORD GetGlyphOutline(

UINT nChar,

UINT nFormat,

LPGLYPHMETRICS lpgm,

DWORD cbBuffer,

LPVOID lpBuffer,

const MAT2* lpmat2

) const;

[b:4672d4a11f]CDC dc;

MAT2 mat;

char ch = 'a';

mat.eM11 = 1;

mat.eM12 = 0;

mat.eM21 = 0;

mat.eM22 = 1;

dc.CreateCompatibleDC(NULL);

dc.SelectObject( font );

int bufferSize = dc.GetGlyphOutline( ch, GGO_BITMAP, 0, NULL, &mat );

dc.GetGlyphOutline( ch, GGO_BITMAP, bufferSize, pointerToBitmap, &mat );[/b:4672d4a11f]

provide a pointer to the bitmap and it should be filled in with the bitmap... there probably are some syntax errors but the idea is similar... try it and let me know


[DEL]

Alex, your code looks a lot simpler. I tried it, and it doesn't return zero. But it returns 4, no matter which font I select! Even ::GetGlyphOutline() which earlier returned zero, now returns 4. (See my question, end part).

I wrote the buffer to a file, and checked those four bytes it had written and they all turned out to be zeroes.

I'm posting the code of my function here, see if you can find any problems!

[b:790d19a291]

CDC dc;

CFont font;

font.CreateFontIndirect(&logfont);

dc.CreateCompatibleDC(NULL);

dc.SelectObject(&font);

char tmpstr[50]="";

void* buffer;//=NULL;

const MAT2 transmat={1,0,0,1};

GLYPHMETRICS glyphmetrics;

int bufsize=0;

bufsize=dc.GetGlyphOutline('A',GGO_BITMAP,&glyphmetrics,0,NULL,&transmat);

if(bufsize==GDI_ERROR)

MessageBox("error");

buffer=malloc(bufsize);

dc.GetGlyphOutline('A',GGO_BITMAP,&glyphmetrics,bufsize,buffer,&transmat);

sprintf(tmpstr,"%u",bufsize);

MessageBox(tmpstr);

[/b:790d19a291]

I wonder what the problem is. Outside this func. I have the following code:

[b:790d19a291]fontdialog.GetCurrentFont(&logfont);[/b:790d19a291]

where fontdilaog is a font selection dialog.

What could be the problem :(? In selecting the font in CFont object font? Earlier, I had made font it the member var. of the class which has this function code, and it gave a debug assertion error, and took me to a func called CGDIObject::Attach() or something like that. I wonder where the problem is :(


heeey, i think the buffer is the problem... I think it has to be initialized to the length of bufsize and then you pass a pointer to it in the 2nd GetGlyphOutline call. because if you make the bufsize=0 or buffer=NULL the function will return the needed size without trying to fill the buffer ( since it is NULL )


init it by doing this:

buffer = GlobalAlloc( GPTR, bufsize );

after you get bufsize, of course


[DEL]

I know that, but note that after getting the buffer size, i have a malloc function, and then again, I'm calling Get... to get the bitmap, after allocating memory. So in that call, bufsize won't be zero, and buffer won' be null.

Oops! I didn't wait for your second post to load before posting this! Sorry, I'll try that. But why does it return four always? Even for different fonts?


sorry didnt notice... hmmm...

what would be the next step? craete a bitmap from that? you should try it and see if CraeteBitmap will spew out an error after you will try creating a bitmap with the buffer as the source...

wanna give that a try?


try doing dc.CreateCompatibleDC( GetDC() );

i am assuming that the class you are currently in extends CWnd at some point...


[DEL]

As I said before, the buffer contains only four bytes - 00 00 00 00. I guess this means it has nothing! So that function might surely give an error! But will try it, after some time! Gotta have dinner now, I'm hungry!


[DEL]

Well, I would have surely tried CreateBitmap(), if it wasn't for it's arguments! I mean, for me at this stage, it will be quite difficult to figure out how to get all the arguments. I've just started off with VC++, and learning since 2 months! Anyway, I'm 100% sure the function is not returning a bitmap. I selected a huge font size (72), still it returned 4 as buffer size! Unless it uses some great compression technology, I don't think that's possible! So I feel it will be totally useless to use that function, since Get... will return the data in two-color bitmap, and I'm pretty sure about this.

[b:7c66b9065c]I used the same function calls with GDI_NATIVE, and guess what! That one works perfectly![/b:7c66b9065c] So I feel the trouble is still with the DCs! I tried dc.CreateCompatibleDC( GetDC()); instead of NULL, but the result is the same.

Are there any alternate ways to get the bitmap (without displaying it anywhere, of course). If not, then I guess I'll have to use GDI_NATIVE, and spend some time in figuring out how it works. I know it's return type, but don't know as yet how to extract the information out of it! I can solve my problem with this, but it's not exactly what I was looking for.

Your replies have helped a lot, thanx for that! But the problem is still there!


ouch!!! not NATIVE!!! :D UGLY!!!

i am assuming that you have checked the values of bufsize and buffer to make sure that the 2nd time you are calling they are not 0 and not NULL. ( well, they gotta have values since you got result for NATIVE... )

ok, what does GetLastError() return after the 2nd call to GetGlyphOutline()?

also, try using GGO_GRAY8_BITMAP instead of simply GGO_BITMAP

also, try a different font... try a couple... maybe the font is corrupted...


[DEL]

I changed it to GRAY8 bitmap and result is still the same - 4 as bufsize. That's what it's value is before I call it the second time. I checked the return value of GetLastError(), and it was zero. I guess this means there wasn't any error(?!). It would have returned a non-zero value after some error. And the fonts are not corrupted!! I had tried changing fonts and sizes earlier, and this time also, but the return value is always four bytes. Don't ask me the exact error message, cos I dunno how to use FormatString() for this! But GetLastError()'s return value was zero.

If the trouble is with memory DCs, read that part about CDC::CreateCompatibleDC() with NULL as argument, it had something which I din't understand - [b:b4086b634e]When a memory device context is created, GDI automatically selects a 1-by-1 monochrome stock bitmap for it. GDI output functions can be used with a memory device context only if a bitmap has been created and selected into that context.[/b:b4086b634e] I don't think so, but could the trouble due to this? I have another doubt - will GetStockObject() be required for this?

Looks like I'll have to go ahead with GGO_NATIVE unless we find some solution soon enough! :D


another thing, try declaring buffer as

BYTE buffer[buffsize];

maybe the void thing is screwnig it up... it shouldnt though

native will take you years from what i see... you have to prtty much interpret all of the curves and lines, vectors... crazy

if the error is 0 then you should try using that bitmap... maybe you're not usign a valid char... make sure it is an unsigned char...


[DEL]

Thankfully, there's some sample project in the MSDN Library, which uses GetGlyphOutline() with GGO_NATIVE. According to it's licence, I'm free to copy and paste anything anywhere! :D So I'll just have to copy some functions from that one into mine! That makes my job a lot easier. Not the kind of thing that I would have liked to do, but I've no other option now! Anyway, I'll try the changes you have suggested. There's a small mistake in your code - BYTE buffer[buffsize]; I'll have to use dynamic memory allocation, as bufsize isn't constant. :)

Thanks!


yea... as i typed it i realized that it's my love for PHP is talking... but was too lazy to retype it.. s'all :rolleyes:


Looking for more fonts? Check out our New, Sans, Script, Handwriting fonts or Categories
abstract fontscontact usprivacy policyweb font generator
Processing