5

这张图说明了我的困境:

图片1

所有字符的大小似乎都相同,但在 RichEdit 控件中显示时与使用 ExtTextOut 时相比,它们之间的空间不同。

我想呈现与 RichEdit 控件中相同的字符(理想情况下),以保留换行位置。

谁能告诉我:

a)哪个是更正确的表示?

b)为什么 RichEdit 控件显示的文本在亚洲字符之间没有间隙?

c)有没有办法让 ExtTextOut 在绘制这些字符时重现 RichEdit 控件的行为?

d)如果我使用的是亚洲版本的 Windows,这会有什么不同吗?

也许我很乐观,但如果有人有任何暗示,我很想听听。

如果有帮助:

这是我的文字:

快的棕色狐狸跳在懶惰狗1 2 3 4 5 6 7 8 9 0

向亚洲读者道歉,这只是为了测试我们的 Unicode 实现,我什至不知道这些字符来自什么语言,更不用说它们是否意味着什么

为了通过将这些字符粘贴到 RichEdit 控件(例如写字板)中来查看效果,您可能会发现您必须滑动它们并将字体设置为“Arial”。

我获得的富文本是:

{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 Arial;}}{\colortbl;\red0\green0\blue0;}\viewkind4\uc1\pard\sa200\sl276\slmult1\ lang9\fs22\u24555?\u30340?\u26837?\u33394?\u29392?\u29432?\u36339?\u22312?\u25078?\u24816?\u29399?1 2 3 4 5 6 7 8 9 0\par\pard \'a3 $$ \'80\'80\cf1\lang2057\fs16\par}

它似乎不包含我第一个想到的角色“音高”的值。

4

3 回答 3

3

我不知道答案,但有几件事值得怀疑:

  • 富编辑控件有多个版本。也许您使用的旧版没有最新的排版改进。
  • 有许多样式和标志会影响富编辑控件的行为,因此您可能想了解设置了哪些样式和标志以及它们的作用。例如,查看EM_GETEDITSTYLE
  • 许多亚洲字体在 Windows 上有两个版本。一个针对水平布局进行了优化,另一个针对垂直布局进行了优化。后者通常具有相同的名称,但已@添加到它的前面。也许您在富编辑控件中使用了错误的控件。

更新:通过使用写字板,我能够重现富编辑控件中拥挤文本的问题。

  1. 在 Windows 7 上的写字板中打开一个新文档。请注意,所选字体是 Calibri。
  2. 将示例文本粘贴到文档中。
  3. 文本显示正确,但写字板将字体更改为 SimSun。
  4. 选择文本并将字体改回 Calibri 或 Arial。

文本现在将过于拥挤,与您的示例非常相似。因此,看起来根本问题在于字体链接和回退。 ExtTextOut可能是自动为脚本选择合适的字体。您的挑战是弄清楚如何为脚本识别正确的字体并在富编辑控件中设置该字体。

于 2011-02-24T18:28:13.060 回答
1

ExtTextOut allows you to specify the logical spacing between records. It has the parameter lpDx which is a const pointer to an array of values that indicate the distance between origins of adjacent character cells. The Microsoft API documentation notes that if you don't set it, then it sets it's own default spacing. I would have to say that's why ExtTextOut is working fine.

In particular, when you construct a EMR_EXTTEXTOUTW record in EMF, it populates an EMR_TEXT structure with this DX array - which looking at one of your comments, allowed the RichEdit to insert the EMF with the information contained in the record, whereby if you didn't set a font binding then the RTF record does some matching to work out what font to use.

In terms of the RichEdit control, the following article might be useful:

Use Font Binding in a Rich Edit Control

After character sets are assigned, Rich Edit scans the text around the insertion point forward and backward to find the nearest fonts that have been used for the character sets. If no font is found for a character set, Rich Edit uses the font chosen by the client for that character set. If the client hasn't specified a font for the character set, Rich Edit uses the default font for that character set. If the client wants some other font, the client can always change it, but this approach will work most of the time. The current default font choices are based on the following table. Note that the default fonts are set per-process, and there are separate lists for UI usage and for non-UI usage.

If you haven't set the characterset, then it further explains that it falls back to ANSI_CHARSET. However, it's most definitely a lot more complicated than that, as that blog article by Murray Sargent (a programmer at Microsoft) shows.

于 2015-01-15T01:13:25.097 回答
1

这只会帮助您解决部分问题,但有一种方法可以将文本绘制到 DC,看起来与 RichEdit 完全相同:所谓的无窗口 RichEdit 控件。它不太容易使用:几年前我写了一篇关于它的CodeProject 文章。我用它来解决文本块的可滚动显示问题,每个文本块都可以通过单击来编辑:正常的绘图是用无窗口的 RichEdit 完成的,而编辑是通过显示一个“真实的”RichEdit 控件来完成的它的顶部。

这至少会让你的文本在两种情况下看起来都一样,但不幸的是,两种情况下的字符间距都太小了。

进一步的想法:如果您可以依赖安装的 Microsoft Office,您还可以尝试 Office 附带的更高版本的 RichEdit。在Murray Sargent 的博客上有更多关于这些的内容,以及一些关于字体绑定的有趣文章也可能有所帮助。

于 2011-03-01T08:49:28.293 回答