... | ... | @@ -196,40 +196,40 @@ a multi-byte string to a Unicode string under the specified white space |
|
|
rule. For example, you can convert a general C string in `UTF-8` or
|
|
|
`GB18030` charset to a `Uchar32` string by calling this function.
|
|
|
|
|
|
```
|
|
|
LOGFONT* lf;
|
|
|
int left_len_text;
|
|
|
|
|
|
char* text = "中华人民共和国万岁!\n中国共产党万岁!";
|
|
|
```C
|
|
|
LOGFONT* lf;
|
|
|
int left_len_text;
|
|
|
|
|
|
if (!(lf = CreateLogFontForMChar2UChar("utf-8"))) {
|
|
|
_ERR_PRINTF("%s: failed to create logfont for utf-8 charset\n",
|
|
|
__FUNCTION__);
|
|
|
exit(1);
|
|
|
}
|
|
|
char* text = "中华人民共和国万岁!\n中国共产党万岁!";
|
|
|
|
|
|
left_len_text = strlen(text);
|
|
|
while (left_len_text > 0) {
|
|
|
Uchar32* ucs = NULL;
|
|
|
int consumed, n;
|
|
|
if (!(lf = CreateLogFontForMChar2UChar("utf-8"))) {
|
|
|
_ERR_PRINTF("%s: failed to create logfont for utf-8 charset\n",
|
|
|
__FUNCTION__);
|
|
|
exit(1);
|
|
|
}
|
|
|
|
|
|
consumed = GetUCharsUntilParagraphBoundary(lf, text, left_len_text,
|
|
|
WSR_NOWRAP, &ucs, &n);
|
|
|
if (consumed > 0) {
|
|
|
left_len_text = strlen(text);
|
|
|
while (left_len_text > 0) {
|
|
|
Uchar32* ucs = NULL;
|
|
|
int consumed, n;
|
|
|
|
|
|
// got a paragraph and go on.
|
|
|
...
|
|
|
consumed = GetUCharsUntilParagraphBoundary(lf, text, left_len_text,
|
|
|
WSR_NOWRAP, &ucs, &n);
|
|
|
if (consumed > 0) {
|
|
|
|
|
|
// when we are done.
|
|
|
free (ucs);
|
|
|
ucs = NULL;
|
|
|
}
|
|
|
// got a paragraph and go on.
|
|
|
...
|
|
|
|
|
|
text += consumed;
|
|
|
left_len_text -= consumed;
|
|
|
// when we are done.
|
|
|
free (ucs);
|
|
|
ucs = NULL;
|
|
|
}
|
|
|
|
|
|
DestroyLogFont(lf);
|
|
|
text += consumed;
|
|
|
left_len_text -= consumed;
|
|
|
}
|
|
|
|
|
|
DestroyLogFont(lf);
|
|
|
```
|
|
|
|
|
|
In the above code, we call `CreateLogFontForMChar2UChar` function to create
|
... | ... | |