Why does creating a Font based on a nonexistent FontFamily work? - c++

I am drawing some text with Gdi+ and I'm trying to make sure the Font I create actually exists. I noticed that it was working no matter what font I specified. I have the following code:
Font font(TEXT("SomeGibberishFOEIHSFUE"), 12, 0, UnitPoint);
if (!font.IsAvailable())
exit(0);
// draw text
I have no font installed on my system called SomeGibberishFOEIHSFUE, but IsAvailable returns TRUE and the program runs and draws the text with a font that looks like Arial instead of exiting. Why is this?
If I am using IsAvailable wrong, what function should I use to tell whether the creation of a Font succeeded or not? I have also tried GetLastStatus which returns Ok.

That's the Windows font mapper at work, it will always find a substitute font if it cannot supply the requested one. Falling back to the default GUI font if necessary. You could use the FontFamily class instead. The .NET version of it (looks like you're using it) will throw an ArgumentException when you use its constructor and pass a non-existing font. The native GDI+ version of it has an IsAvailable() method. Yes, kinda screwy behavior but that's not unusual in GDI+.

Related

freeglut's glutStrokeString giving a "stroke font not found error"

I am trying to use glutStrokeString using freeglut.
The program runs fine up to the point it has to call glutStrokeString, then it outputs the console freeglut stroke font not found.
Any idea why?
GLUT_BITMAP_HELVETICA_18, as the name suggests, is a bitmap font. You can't use them with the Stroke rendering commands. So if you want to use that font, you have to use glutBitmapString.
FreeGLUT comes with two stroke fonts: GLUT_STROKE_ROMAN and GLUT_STROKE_MONO_ROMAN. So if you want to use the stroke commands to render the fonts, you have to use one of those kinds of fonts.
Just check out the file, gluit/freeglut_font.c, in your glut source code, contains everything you need to know, Also check fghFontByID() and fghStrokeByID() which are actually used to computed the font id for both the functions that is glutBitmapString() & glutStrokeString()
or check out this

Take OpenCV window and make full screen

I am currently making an OpenCV project in C++ where I look for motion with a kinect and use that to cue a slideshow (sans recognition). Currently, I am displaying the slideshow using OpenCV (as I've only had about a week to whip this up). It looks good and its quick. The only problem is that this is going to be on display for a big production and I can't really afford to have the window showing (I'm talking window decorations like the title bar and such).
I need to get rid of the title bar. I've done a lot of research, and I have found out that you can magically grab the window handle by calling cvGetWindowHandle("SlideShow"), but that is a void function, so I don't really know how I am supposed to get a handle from that to manipulate.
I'm developing this for both windows AND ubuntu, since it will end up on a windows machine, but I can only demo on a laptop running ubuntu.
If anyone can tell me how to take the window and render it fullscreen with a resized image to fill most if not the entire screen in either Windows or Ubuntu, I will be forever grateful.
I am using OpenCV 2.1 on Ubuntu 11.04. On my system CV_WINDOW_FULLSCREEN and CV_WINDOW_AUTOSIZE flags both map to 1
And both flags behave exactly the same. They give you a fixed size window, which would be expected for AUTOSIZE flag but not the FULLSCREEN. I think these two flags are meant for different functions although their simillar appearance is very confusing. The flag CV_WINDOW_NORMAL maps to value 0 which is what you have used. It gives you a resizable window that you could maximize, but it is not a fullscreen window.
Edit: I just found the solution in another stachoverflow post. Here is the solution from that post which worked great on my system:
cvNamedWindow("Name", CV_WINDOW_NORMAL);
cvSetWindowProperty("Name", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
cvShowImage("Name", your_image);
I get a real fullscreen with no title bar etc.
you can use the cv::setWindowProperty function for your purpose, just set it to CV_WINDOW_FULLSCREEN.
Full documentation in the openCV-WIKI
In opencv/4.5.1, this is how it is done:
namedWindow("Name", WINDOW_NORMAL);
setWindowProperty ("Name", WND_PROP_FULLSCREEN, WINDOW_FULLSCREEN);
Assuming you have added using namespace cv;

SDL changing cursor to Windows default

I'm making a simple windowed game and I want a standard system cursor instead of SDL's black one. Is this possible without manual creation of cursor?
This is not possible as far as I know. Because SDL works on all major platforms, even those without default cursors, SDL creators decided to always use a custom cursor. Drawing the default system cursor shouldn't be that hard though - just load the .cur file and paint it as a bitmap.
It is possible for you to to display 4 types of default SDL cursors with the help of SDL_CreateCursor. The SDL documentation provides this information:
http://www.libsdl.org/cgi/docwiki.cgi/SDL_CreateCursor

Why are not all texts of my MFC applicatiopn displayed using ClearType?

I've got an MFC application that is built with VC6. When ClearType is enabled (Windows XP) some texts are rendered smoothly, i.e. with ClearType, and others are not.
Dialog texts don't seem to ever get rendered with ClearType. Some list controls, however, have it enabled completely, others only in their headers.
What could be the reason for this? Where should I look to find out why it works only in some places and doesn't in others?
Update
As requested, here is an enlarged screenshot. Obfuscated but the important parts should be visible.
In List 1 only the heading is smooth, the content is not.
In List 2 both, heading and list items are smooth.
The Dialog at the bottom is not using ClearType either.
Bitmap fonts will never use ClearType. Usually you won't use a bitmap font, but I believe the default selected into a DC is the System font, which is bitmap.
ClearType is a quality property for fonts. You should get the LOGFONT for your CFont and set the lfQuality property. Here's an example.
CFont *pFont = CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT));
LOGFONT logFont;
pFont->GetLogFont(&logFont);
logFont.lfQuality = CLEARTYPE_NATURAL_QUALITY;
CFont font2;
font2.CreateFontIndirect(&logFont);
Note: you can use either CLEARTYPE_QUALITY or CLEARTYPE_NATURAL_QUALITY, test both to see which looks best.

Simple way to set font type in MFC CListBox

I have always used the default ListBox control with the property of OWNER DRAW set to NO. But now I need to set a fixed sized mono font since my formatted strings are not aligning up even though I have the default right aligned and necessary width padding set beyond the actual size of the digit string.
My problem is I don't have a clue the simplest way to code for this nor have I ever coded for OWNER DRAW set to anything other than NO.
Appreciate any input or examples or links.
Additionally would like information on how would I check to even see what fixed mono width fonts are available on the system running my app?
(C++ MFC, Visual Studio)
Declare a CFont object and init it with CFont::CreateFont.
"Courier New" is usually a good choice for fixed width fonts.
Use CListBox's SetFont() method (inherited from CWnd) to replace the default one.
Don't know about CListBox, but in the standard Windows listbox, you can use the WM_SETFONT message to set the font of the control. CListBox probably wraps the native listbox, so if you can get the HWND of the CListBox, it should be easy to set the font of it using WM_SETFONT.