Home > Software engineering >  MFC DrawText Chinese English string to print a newline
MFC DrawText Chinese English string to print a newline

Time:11-13

Cstrings _data while forming="HTTP://https://bbs.csdn.net/topics/the People's Republic NBDZT";//need to print the data
DrawText - & gt; DT_WORDBREAK | DT_EDITCONTROL | DT_LEFT | DT_NOPREFIX print way

Print goals:
The People's Republic in nb
DZT

The actual printing results:
The People's Republic of China
NBDZT

To solve the problem: if there is space left behind in Chinese, let English not line ahead of time,

Prerequisite: don't adjust the printing area, fixed font adjustment, both in English and Chinese word wrap and continuous

CodePudding user response:

DrawText DT_CALCRECT using parameters, can return to need the size of the drawing area,
Can increase char, calculate the size of a suitable length and sectional output

CodePudding user response:

Thank the moderator, but the current problems in the way you said to do should be more troublesome,

Is facing the problem: in a 13 mm x 40 mm area to print 1 ~ 7 data, each data of 8 ~ 92 characters,
Printing solutions: using \ n joining together every piece of data, and then use the DT_CALCRECT can calculate the full size of print data, then once a complete variable data printing,

I mention above problems, however, leads to waste print height, solution how to solve the above problems, or have any way to avoid,

CodePudding user response:

Then output their word by word line breaks

 
Void CSDI3View: : ontouch * pDC (CDC)
{
CSDI3Doc * pDoc=GetDocument ();
ASSERT_VALID (pDoc);
if (! PDoc)
return;

Cstrings STR=_T (" ABCDEFGHIJKLMNOPQRSTUVWXYZ of the People's Republic of China ")
_T (" \ n ABCDEFGHIJKLMNOPQRSTUVWXYZ of the People's Republic of China ");

//boundary
CRect rcBound;
GetClientRect (& amp; RcBound);

//get line height attribute
The TEXTMETRIC txMetric;
PDC - & gt; GetTextMetrics (& amp; TxMetric);
Int iLineHeight=txMetric. TmHeight;

//x, y
Int x=rcBound left, sy=rcBound. Top;
For (int n=0; N{
Cstrings s; S=STR [n].

//force line breaks
If (s==_T (' \ n '))
{
Sx=rcBound. Left;
Sy +=iLineHeight;
continue;
}

//calculate character area
CRect rcTxt (sx, sy, 0, 0);
PDC - & gt; DrawText (s, 1, rcTxt, DT_CALCRECT);

//over the border exit map
If (rcTxt. Bottom & gt; RcBound. Bottom)
{
break;
}

//more than right boundary line
If (rcTxt. Right & gt; RcBound. Right)
{
Sx=rcBound. Left;
Sy +=iLineHeight;

//next redraw the current character
N -;
continue;
}

//output characters
PDC - & gt; TextOut (sx, sy, s, 1);

//modify coordinates
Sx=rcTxt. Right;
}

}

CodePudding user response:

Simple solution is to use monospaced font, and then fixed length insert a newline
  • Related