Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
characters using MBCS |
Post Reply |
Author | |
Tullhead
Beginner Joined: 24 Jun 21 Location: Paso Robles, CA Status: Offline Points: 2 |
Post Options
Thanks(0)
Posted: 24 Jun 21 at 12:56AM |
I'm using MBCS in MFC C++. When I am ready to pass the string to Debenu, I use
LPCWSTR CString2Wide(CString s) { _bstr_t bs = s; return (wchar_t*)bs; } So, a call looks something like: pPDF->DrawText(160, 100, CString2Wide(MyTitle)); All this works fine for plain English strings. Now I want to support German, French, and Spanish. So, just umlauts and accents. This can all be done in MBCS (in theory) with no need to go to UNICODE. I want to avoid UNICODE for now. Now when I pass it a German string like: ist für alle It shows up in the PDF like this: ist für alle How can I fix this? Thanks if you can help. Don't tell me to use UNICODE. |
|
tfrost
Senior Member Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
Post Options
Thanks(0)
|
I can't avoid "telling you not to use Unicode", because you are already using Unicode in your MBCS. You may think that "ist für alle" is in Windows (USA) default encoding. If it was in default encoding, it would contain the bytes: 69 73 74 20 66 FC 72 20 61 6C 6C 65 i s t f ü r a l l e But what you are passing to your CString2Wide function is in a Multibyte Character Set (MBCS) encoding of Unicode, UTF8: 69 73 74 20 66 C3 BC 72 20 61 6C 6C 65 i s t f ü r a l l e When you simply 'cast' this to a Wide String, the program assumes that it is default encoding, so interprets it as such: 69 73 74 20 66 C3 BC 72 20 61 6C 6C 65 i s t f à ¼ r a l l e And this becomes, as a Wide String: 0069 0073 0074 0020 0066 00C3 00BC 0072 0020 0061 006C 006C 0065 i s t f à ¼ r a l l e To fix this in your program and continue to use MBCS elsewhere, I suggest converting your MBCS (UTF8) string to WideChars (UTF16) using MultiByteToWideChar, using CP_UTF8 as the first parameter. The method you have used works only for ASCII, as you have found. You will find plenty of examples for MultibyteToWideChar; since it takes an input and an output buffer as parameters, it is easiest to use inline, not as a function.
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store