字体显示(Font display)
Under normal circumstances, developers want their elegant procedure, in order to achieve this one requirement, try to beautify their own procedures, on the other hand, the text is a way to transfer information indispensable program interface, if the interface on the right side to add and display all kinds of special effects of the text it will be a good choice, can achieve a multiplier effect, in this ca for a special display of this problem in the realization of the text of the C++ Visual programming, through the preparation of a simple small program on how to achieve this goal. Readers can change it slightly and apply this method to their own programs.
Graph a string around the display
生日藏头诗
Figure two, 3D text effect
First, the realization method
Before describing the various processing effects of text, let's first introduce the CFont class provided by MFC in Visual C++ to create fonts. For Windows application developers, can create the font has two kinds: Inventory (the direct u of font font font index can be lected into the device context, for example: CDC:: CreateStockObject (int nIndex)) and custom fonts.
CFONT class derived from CgdiObject, the object of this class can create custom font by Createfont (), CreateFontIndirect () and other functions. The two function prototypes are as follows:
CFont:: CreateFontIndirect (const LOGFONT* lpLogFont);
CFont:: CreateFont (int nHeight, int nWidth, int nEscapement, int nOrientation, int nWeight, BYTE bItalic, BYTE bUnderline, BYTE cStrikeOut, BYTE nCharSet, BYTE nOutPrecision, BYTE nClipPrecision, BYTE nQuality, BYTE nPitchAndFamily, LPCTSTR lpszFacename).
The relationship between the parameters of the cond functions and the parameters of the LOGFONT type in the first function has a one-to-one relationship. LOGFONT structure defines the attributes of the font, and its definition can be checked by MSDN help:
Typedef struct tagLOGFONT {
LONG lfHeight; / / character font height;
LONG lfWidth; / / the average width of the characters; LONG lfEscapement; / / text for counter clockwi rotation; LONG lfOrientation; / / font angle;
LONG lfWeight; / / font weight;
BYTE lfItalic; / / tilt;
BYTE lfUnderline; / / underline;
BYTE lfStrikeOut; / / delete line;
......
} LOGFONT;
When tting the LOGFONT structure, veral member variables such as lfOutPrecision, lfClipPrecision, lfQuality and lfPitchAndFamily can be t as follows without need to be changed:
LOGFONT lf; //lf defines font attributes
Lf.lfOutPrecision= OUT_STROKE_PRECIS;
Lf.lfClipPrecision= CLIP_STROKE_PRECIS;
Lf.lfQuality = DRAFT_QUALITY;
Lf.lfPitchAndFamily= VARIABLE_
PITCH|FF_MODERN;
For other member variables, specific ttings should be t according to the actual needs. For example, for there is no line and no delete underline and bold Chine characters have inclined processing, you can take the following ttings:
Lf.lfHeight = 50;
烫豆腐
Lf.lfWidth = 0;
hang电脑笔记本排行榜Lf.lfEscapement = 0;
Lf.lfOrientation = 0;
Lf.lfWeight = FW_HEAVY;
Lf.lfItalic = FALSE;
男洗面奶
Lf.lfUnderline = FALSE;
怀孕后期Lf.lfStrikeOut = FALSE;
Lf.lfCharSet = GB2312_CHARSET; strcpy (lf.lfFaceName, "I");
(1) display slanted text
美颜拍摄
Figure 1 above shows the effect of surround display by displaying a ries of tilted strings. Here's how to implement this effect.
To achieve the above effect is very easy, as long as the u of CFONT class and LOGFONT structure to create a flexible font, t the font attributes, you can achieve the effect of tilted text. The LOGFONT structure contains all the information you want to create the font, one of the ifEscapement members have the font and the horizontal direction created by the tilt angle, readers need to note that the member variable angle unit is 1/10 degrees rather than, for example, if ifEscapement is defined as 450, it said the tilt angle of the font the 45 degrees. In order to ensure that all fonts rotate in one direction, you must t the CLIP_LH_ANGLES ifEscapenent bit, otherwi the font may
be rotated in the opposite direction.
As with other GDI (graphical ur interface interface) objects, before you u the font you have defined, you must lect the font created into the DC (device context).
(two) implementation of 3D characters
The computer screen is two-dimensional plane, we can enjoy the true 3D images like real, becau of different color gray display on the computer screen which makespeople have visual illusion, the computer screen is two-dimensional
改字开头的成语three-dimensional image perception. Bad on the knowledge of color, the protruding part of the edge of the three-dimensional object generally displays high brightness color, while the concave part is dark becau of the light occlusion. This understanding is widely ud in web pages or other applications to draw buttons and 3D lines. For this article is to draw the 3D text is the same, namely in the original position display high brightness color, and in the lower left or right upper position with low brightness color sketched the outline, this text will produce 3D in visual effect. The implementation of the same font rendering, available in two different colors of the 2D text are in a different position, as long as the coordinates of two words, can produce different visual effects 3D characters.
The idea is through the CDC:: (SetTextColor) respectively t the text color to highlight and shadow (3DHILIGHT) (3DSHADOW) under the condition of the display text; while paying attention to stagger a few pixels in the display text two times, so as