[loc] fix various RTL localization issues

With thanks to Itiel

* Fix a potential buffer overflow in lmprintf for RTL languages
* Automatically apply RLE/PDF to all RTL messages, and remove the RLE/PDFs from the .loc
* Fix Windows messing up of multiline RTL tooltips (The trick is, if you want actually
  want RTL, you need to *disable* RTL... Sure, Microsoft, that makes a lot of sense?!?)
* Also properly scale the length of the multiline tooltips according to the zoom factor
* Closes #1132
This commit is contained in:
Pete Batard 2018-05-17 20:45:32 +01:00
parent 34ee2f6382
commit c3aaa0c252
5 changed files with 82 additions and 97 deletions

View file

@ -365,8 +365,9 @@ char* lmprintf(uint32_t msg_id, ...)
static int buf_id = 0;
static char buf[LOC_MESSAGE_NB][LOC_MESSAGE_SIZE];
char *format = NULL;
size_t pos = 0;
va_list args;
BOOL needs_rtf_rtl_marks = (msg_id & MSG_RTF) && right_to_left_mode;
BOOL is_rtf = (msg_id & MSG_RTF);
buf_id %= LOC_MESSAGE_NB;
buf[buf_id][0] = 0;
@ -379,13 +380,22 @@ char* lmprintf(uint32_t msg_id, ...)
if (format == NULL) {
safe_sprintf(buf[buf_id], LOC_MESSAGE_SIZE-1, "MSG_%03d UNTRANSLATED", msg_id - MSG_000);
} else {
if (needs_rtf_rtl_marks)
safe_strcpy(buf[buf_id], LOC_MESSAGE_SIZE-1, "\\rtlch");
if (right_to_left_mode) {
if (is_rtf) {
safe_strcpy(&buf[buf_id][pos], LOC_MESSAGE_SIZE - 1, "\\rtlch");
pos += 6;
}
safe_strcpy(&buf[buf_id][pos], LOC_MESSAGE_SIZE - 1, RIGHT_TO_LEFT_EMBEDDING);
pos += sizeof(RIGHT_TO_LEFT_EMBEDDING) - 1;
}
va_start(args, msg_id);
safe_vsnprintf(&buf[buf_id][needs_rtf_rtl_marks?6:0], LOC_MESSAGE_SIZE-1, format, args);
safe_vsnprintf(&buf[buf_id][pos], LOC_MESSAGE_SIZE- 1 - 2*pos, format, args);
va_end(args);
if (needs_rtf_rtl_marks)
safe_strcat(buf[buf_id], LOC_MESSAGE_SIZE-1, "\\ltrch");
if (right_to_left_mode) {
safe_strcat(buf[buf_id], LOC_MESSAGE_SIZE - 1, POP_DIRECTIONAL_FORMATTING);
if (is_rtf)
safe_strcat(buf[buf_id], LOC_MESSAGE_SIZE - 1, "\\ltrch");
}
buf[buf_id][LOC_MESSAGE_SIZE-1] = '\0';
}
return buf[buf_id++];

View file

@ -42,6 +42,7 @@
#define LEFT_TO_RIGHT_EMBEDDING ""
#define RIGHT_TO_LEFT_EMBEDDING ""
#define POP_DIRECTIONAL_FORMATTING ""
#define LEFT_TO_RIGHT_OVERRIDE ""
#define RIGHT_TO_LEFT_OVERRIDE ""
#define DRIVE_ACCESS_TIMEOUT 15000 // How long we should retry drive access (in ms)
#define DRIVE_ACCESS_RETRIES 150 // How many times we should retry

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.0.1285"
CAPTION "Rufus 3.0.1286"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -389,8 +389,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,0,1285,0
PRODUCTVERSION 3,0,1285,0
FILEVERSION 3,0,1286,0
PRODUCTVERSION 3,0,1286,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -407,13 +407,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.0.1285"
VALUE "FileVersion", "3.0.1286"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.0.1285"
VALUE "ProductVersion", "3.0.1286"
END
END
BLOCK "VarFileInfo"

View file

@ -1073,7 +1073,9 @@ INT_PTR CALLBACK TooltipCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM
case TTN_GETDISPINFOW:
lpnmtdi = (LPNMTTDISPINFOW)lParam;
lpnmtdi->lpszText = ttlist[i].wstring;
SendMessage(hDlg, TTM_SETMAXTIPWIDTH, 0, 300);
// Don't ask me WHY we need to clear RTLREADING for RTL multiline text to look good
lpnmtdi->uFlags &= ~TTF_RTLREADING;
SendMessage(hDlg, TTM_SETMAXTIPWIDTH, 0, (LPARAM)(int)(150.0f * fScale));
return (INT_PTR)TRUE;
}
break;
@ -1758,7 +1760,7 @@ LPCDLGTEMPLATE GetDialogTemplate(int Dialog_ID)
if (right_to_left_mode) {
// Add the RTL styles into our RC copy, so that we don't have to multiply dialog definitions in the RC
dwBuf = (DWORD*)rcTemplate;
dwBuf[2] = WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL;
dwBuf[2] = WS_EX_APPWINDOW | WS_EX_LAYOUTRTL;
}
// All our dialogs are set to use 'Segoe UI Symbol' by default: