DrawText/DrawText,字符串换行和长字符串(word wrapping and long strings)

Hi all, got what seems like a really simple problem but can work out how to
solve it.  I'm coding up a function in a DLL that will print a registration
card for the user to send to use.

Instead of having the hassel of using a reporting tool, i decided to simply
use the TPrinter object and write directly to the canvas.  All seems pretty
fine and dandy until i came to try and display the registration code.  It is
the product of an public / private encryption system and the resultant data
/ ansistring is 172 characters long and is a solid block of text without any
spaces in it.

When I use this with DrawText or DrawTextEx it will not wrap the test so the
string goes of the end of the canvas / page.  I assum this is because it
can't find any blank spaces between 'words'.  I've tried all variations of
the flags but i get the same results...
翻译:

碰到了一个看似简单却不知如何解决的问题。我正在写一个DLL中的一个函数,用来输出一个注册码给用户使用。
  为了避免使用报表工具带来的争论,我直接使用TPrinter 对象和然后直接向Canvas输出。当我显示这个注册码的时候,问题出现了。这个注册码是公钥/密名钥系统生成的,大概有172个字符,中间没有任何空格。
 当我使用 DrawText/DrawTextEx时,它没有分行,以致于这个字符串超出了Canvas. 个人认为可能是这个字符串之间没有任何空格。我已经试过了DrawText/DrawTextEx中所有的标志,但是结果仍是一样的。

 The encrypted block of text looks like this:
            "U8m8Kr2hMPiT7Fs2XfDgtKVaID+XVSILmivZ3u/4gwjp6+ehDRo5NOUPSbIQWN7oUkdc0tMgKahe1dFr1joY1OtJ10wq7f87LLSVP0ZmhkG3hdrzKaMnZwxHozhGmHZLUgkoIVSpUb+hz/iGbvTYKUg7eljYjg0Ntbs72qoNFwk="

- the newsreader might wrap this...  I'm passing it into the DLL as a char
pointer.  I'm trying to write it out into a block with the canvas

翻译:这些字符看起来是这样子的:
"U8m8Kr2hMPiT7Fs2XfDgtKVaID+XVSILmivZ3u/4gwjp6+ehDRo5NOUPSbIQWN7oUkdc0tMgKahe1dFr1joY1OtJ10wq7f87LLSVP0ZmhkG3hdrzKaMnZwxHozhGmHZLUgkoIVSpUb+hz/iGbvTYKUg7eljYjg0Ntbs72qoNFwk="
在DLL我把它中我把它做为一个字符串指针。我想把它整块输出到Canvas中

That is a base64-encoded string.  There are no characters in base64 that
allow adequate word breaking.  You will have to break up the string
manually, such as every xx number of characters.  That is what email does,
for instance - each line is a fixed number of characters (usually around 76)
regardless of the encoding used.  You could use 86 to break the line into of
2 lines of even length.  Alternatively, you will likely have to query your
Canvas for the number of available pixels per line, and the number of pixels
per character, and then manually draw different portions of the string
accordingly on multiple lines.

翻译:这是一个采用Base64-编码的字符串。在Base64编码中没有适当的字符去断行。你不得不采用手工分行,例如每行  xx 个字符。 例如:Email也是这样做的,不管使用什么编码,每行都是固定的字符个数(通常是76)。你可以使用86个字符去分行。或者,查询一下Canvas中每行的最大像素数,每个字符的像素数,然后再手工画出这个字符串的不同部分

Cool, that is what i figured - can't expect everything from the api's.  It's
not a huge issue, the canvas size should not change drastically and I know
the size of encrypted block.

Just out of interest, do you know any good references on this sort of
thing - i want to create a more advanced print out i.e. watermarks and
possibly angled or rotated text but i can seem to find much other that
DrawText and TextOut...

翻译:这正是我所想要的-不能什么事都依靠API来解决。它不再是一个难题了,Canvas的大小不是发生太大的变化,加密字符串的大小我也知道。
仅仅想了解一下,你知道其它类似的问题的解决方法-我想输出一些更高级的内容-例如:水印,旋转文字,但是从DrawText/TextOut中没有找到相关的东西

Use CreateFontIndirect() to use rotated fonts.  Set the lfOrientation member
of the LOGFONT structure to the angle of rotation.  You can then use
SelectObject() to apply the font to any Canvas prior to writing text on it.
Make sure that you are using a TrueType font, though.


用CreatefontIndirect()去创建旋转文字。设置一下LOGFONT结构体的lfOrientation 成员要旋转的角度。
在输入出文字之前,你可以用SelectObject()方法将这个字体应用到任何的Canvas上,前提是你使用的是TrueType 字体。

你可能感兴趣的:(BCB)