请问如何判断UTF-16字符集中哪些字符是折词字符

fhw217 2023-12-04 12:06:10

正在做一个纯文本编辑器,使用的字符集是UTF-16,比如有一行字符串 "ABCDEFGH [空格] XYZ" (此处XYZ代表任意字符),因为XYZ已经超过右边界,所以此时可能需要折词,就是把XYZ折到下一行,现在只知道XYZ是英文时需要折词,是中文时不需要折词,请问XYZ的内码是哪些范围时需要折词?

下图中的方框代表窗口区

 

 

...全文
489 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2024-02-19
  • 打赏
  • 举报
回复

DrawTextEx
The DrawTextEx function draws formatted text in the specified rectangle.

int DrawTextEx(
HDC hdc, // handle to device context
LPTSTR lpchText, // pointer to string to draw
int cchText, // length of string to draw
LPRECT lprc, // pointer to rectangle coordinates
UINT dwDTFormat, // formatting options
LPDRAWTEXTPARAMS lpDTParams // pointer to struct with options
);

dwDTFormat
Specifies formatting options. This parameter can be one or more of these values: Value Meaning
DT_BOTTOM Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.
DT_CALCRECT Determines the width and height of the rectangle. If there are multiple lines of text, DrawTextEx uses the width of the rectangle pointed to by the lprc parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawTextEx modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawTextEx returns the height of the formatted text, but does not draw the text.

Graphics::MeasureString(string, length, font, origin, boundingBox)
The MeasureString method measures the extent of the string in the specified font and layout rectangle.

Status MeasureString(
const WCHAR* string,
INT length,
const Font* font,
const PointF& origin,
RectF* boundingBox
) const;
Parameters
string
[in] Pointer to a wide-character string to be measured.
length
[in] Integer that specifies the number of characters in the string array. The length parameter can be set to –1 if the string is null terminated.
font
[in] Pointer to a Font object that specifies the family name, size, and style of the font that is applied to the string.
origin
[in] Reference to the point at which the string starts.
boundingBox
[out] Pointer to a RectF object that receives the rectangle that bounds the string.
Return Values
If the method succeeds, it returns Ok, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.

Example Code [C++]
The following example measures the size of a string and then draws a rectangle that represents that size.

VOID Example_MeasureString4(HDC hdc)
{
Graphics graphics(hdc);

// Set up the string.
WCHAR string[256];
wcscpy(string, L"Measure Text");
Font font(L"Arial", 16);
PointF origin(0.0f, 0.0f);
RectF boundRect;

// Measure the string.
graphics.MeasureString(string, wcslen(string), &font, origin, &boundRect);

// Draw a rectangle that represents the size of the string.
graphics.DrawRectangle(&Pen(Color(255, 0, 0, 0)), boundRect);
}
Requirements
Windows NT/2000/XP: Included in Windows XP and Windows .NET Server.
Redistributable: Requires GDI+ on Windows NT 4.0 SP6; Windows 2000; and Windows 98/Me.
Header: Declared in Gdiplusgraphics.h; include Gdiplus.h.

fhw217 2023-12-06
  • 打赏
  • 举报
回复

自己顶一下!

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧