CDC text drawing issue - visual-c++

I'm trying to draw text using CDC::ExtTextOut() to a device context (CDC), but I'm getting garbage outputs. The output text was drawn is weird fonts.
The CDC pointer that got passed to me was originated from a unicode build ActiveX control (.ocx).
The text drawing code resides in an ANSI build DLL.
It seems like there're some kind of incompatibilities in this setup.
Has anyone run into this situation and how did you solve it?
Thanks.

Have you tried setting a font on the CDC?
CFont *oldvalue = dc->SelectObject(GetStockObject(OEM_FIXED_FONT));
dc->ExtTextOut(....);
dc->SelectObject(oldvalue);

Related

Why fonts in Qt are appearing blurry or pixelated?

All my fonts are appearing pixelated, so I used AntiAliasing but it isn't helping out. As you can see the pixelated font in the image itself:
This is the code I am currently using:
butt1 = QtWidgets.QLabel("""Scrappr""")
font = QtGui.QFont()
font.setStyleStrategy(QtGui.QFont.PreferAntialias)
font.setPixelSize(22)
font.setFamily('Segoe UI Bold')
butt1.setFont(QtGui.QFont(font))
I tried different solutions on SO, qtforums etc but nothing works for me :(
I tried:
Different combinations of ClearType text but It didn't work out as, by default all the text appears good on windows and chrome but with Qt only, it becomes pixelated.
Changing windows aero theme to classic one...
But none of them helped.
Here are My PC Specs:
windows: 7 ultimate
PySide2 version: 5.14.2.1
Resolution: 1360 X 768
I'm using BrownPro font and the texts were blurry at all resolutions, but much more evident at low resolutions.
I was able to solve the issue by setting the hinting preference for the font to: PreferNoHinting. Applying it at the application level, fixes the issue everywhere.
Here is the documentation: https://doc.qt.io/qt-5/qfont.html#HintingPreference-enum
And here is the code I used:
QFontDatabase::addApplicationFont(":/fonts/BrownPro-Bold.ttf");
QFontDatabase::addApplicationFont(":/fonts/BrownPro-Regular.ttf");
QFontDatabase::addApplicationFont(":/fonts/BrownPro-Light.ttf");
QFont brown_pro_font("BrownPro");
brown_pro_font.setHintingPreference(QFont::HintingPreference::PreferNoHinting); //This line did the trick
QApplication::setFont(brown_pro_font);
Try to see the fonts used by PyQt5:
import PyQt5
from pyQt5 import QtGui
dir(QtGui.QFont)
the result will show all you need for QFond and the fonts can be used:
[..., 'Helvetica',...,'SansSerif',..., 'Serif',..., 'Times', ...
You can try to add your custom fonts but you need to test each font.
For example, the documentation tells us:
In Windows a request for the “Courier” font is automatically changed to “Courier New”, an improved version of Courier that allows for smooth scaling. The older “Courier” bitmap font can be selected by setting the PreferBitmap style strategy (see setStyleStrategy() ).
Once a font is found, the remaining attributes are matched in order of priority:
fixedPitch()
pointSize() (see below)
weight()
style()
I happen to work with Qt last year and i used qml for building the UI part of my application.
Qt itself prefers us to use qml for building UI, since they have written a UI engine that renders everything better compared to the old engines.
In case of PyQt you are using the python only approach which is only not usually recommended, i am not saying that the qml version is pixel perfect. it still works bad at drawing curves (but that is not the stuff we usually require). As far as your problem is concerned qml will work fine for you (it has much better text rendering).
You might struggle a bit finding the learning resource for qml. But at least give it a shot and yes it is easier much easier than Python only approach.

Drawing Box using Directx11 but do not show

I am writing a code of drawing a colorful box with Directx11 and the graphics do not show. Here's a screenshot of debugging graphics using visualstudio graphics debugger.
It seems like the vertex buffer or indices buffer is wrong, but I cannot find the problem.
I commit my code to github. Here is the url:
https://github.com/christliu/GraphicsAPI/tree/Effect/DirectX11.
Please tell me where is the problem.

How to remove the background from this SVG

I am new to handling graphics and would appreciate some help.
I purchased this particular EPS and trying to edit it.
I am using Vectr for handling EPS/SVG, however, Vectr was not able to open this EPS (bought from iStock).
Tried Gravit and it failed too. Then I converted the EPS to SVG, using an online converter.
This is the graphic I am dealing with:
I just want to remove the checkered background. When I opened this SVG in Gravit, the background shows as a path. There are a large number of paths in this graphic.
Could someone advice on how to remove this checkered background using a SVG editor like Gravit.
Thank you.
You need to use one of these graphic editors: Corel Draw or Adobe Illustrator. You can send the file to me, I will send it to you without a background. kuznetsovasasha86#gmail.com

How do i load a bitmap in Direct2D containing an alpha channel

I'm trying to load a bitmap in Direct2D that already contains an alpha channel, but Direct 2D seems to always ignore the alpha channel surrounding the desired image, replacing it with opaque black. Has anyone had success with this, and could show me their code? has anyone loaded a PNG file, and convert it to a bitmap? (MSDN says it's possible, but i can't find any cases where people have had success) or is this a mask thing?
In any case, could you show me a example code snippet explaining how to do one of these things? i'm trying to make a game, i have everything else working, and this is the literal final step. if someone could show me exactly how this is done, that would make my day! just transparency in an image. that's all i need.

Weird rendering bug in Vim (or feature?)

There are small lines appearing sometimes in front of words. In the pictures they are to the right of +syntax/ and swo and delmenu.vim.
Is this a bug or those lines mean something?
Do this happened to you before?
Would they get worse in the future?
PS: I'm using Microsoft Windows XP SP2 AMD
alt text http://img97.imageshack.us/img97/7673/picpd.jpg
EDIT: I change the font to Consolas and they disappeared. Is there a way to solve the problem while still using my favorite font, Monaco (and not turning off Cleartype)?
This is caused by cleartype font smoothing.
If you use a fixed font for gvim the problem goes away (.fon files). ttf files contain font smoothing information which gets messed up in gvim.
fixedsys renders well. There are a bunch of other ones that also work well.
An alternative is to turn off font smoothing altogher using the display properties, but that will have undesirable effects on all other applications.
This does indeed look like a rendering bug. You should report it to the gvim team. But you should also never use jpegs for screen shots - the compression doesn't work nearly as well as pngs, and could potentially introduce distortion in shots exactly like this one.
Just a guess, but it may be related to the font you are using. Maybe you could try to change it to see if these lines still appear, or disappear, or move to other lines ...

Resources