ntdll: Fix some test failures of RtlGUIDFromString and RtlStringFromGUID
[wine] / dlls / gdi32 / bidi.c
1
2 /*
3  * GDI BiDirectional handling
4  *
5  * Copyright 2003 Shachar Shemesh
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23
24 #include <stdarg.h>
25 #ifdef HAVE_UNICODE_UBIDI_H
26 #include <unicode/ubidi.h>
27 #endif
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "wine/debug.h"
33 #include "gdi_private.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(bidi);
36
37 #ifdef HAVE_ICU
38 BOOL BidiAvail = TRUE;
39 #else
40 BOOL BidiAvail = FALSE;
41 #endif
42
43
44 /*************************************************************
45  *    BIDI_Reorder
46  */
47 BOOL BIDI_Reorder(
48                 LPCWSTR lpString,       /* [in] The string for which information is to be returned */
49                 INT uCount,     /* [in] Number of WCHARs in string. */
50                 DWORD dwFlags,  /* [in] GetCharacterPlacement compatible flags specifying how to process the string */
51                 DWORD dwWineGCP_Flags,       /* [in] Wine internal flags - Force paragraph direction */
52                 LPWSTR lpOutString, /* [out] Reordered string */
53                 INT uCountOut,  /* [in] Size of output buffer */
54                 UINT *lpOrder /* [out] Logical -> Visual order map */
55     )
56 {
57     TRACE("%s, %d, 0x%08x lpOutString=%p, lpOrder=%p\n",
58           debugstr_wn(lpString, uCount), uCount, dwFlags,
59           lpOutString, lpOrder);
60
61 #ifdef HAVE_ICU
62     if ((dwFlags & GCP_REORDER) != 0) {
63         UBiDi *bidi;
64         UErrorCode err=0;
65         UBiDiLevel level=0;
66
67         bidi=ubidi_open();
68         if( bidi==NULL ) {
69             WARN("Failed to allocate structure\n");
70             SetLastError(ERROR_NOT_ENOUGH_MEMORY);
71             return FALSE;
72         }
73
74         switch( dwWineGCP_Flags&WINE_GCPW_DIR_MASK )
75         {
76         case WINE_GCPW_FORCE_LTR:
77             level=0;
78             break;
79         case WINE_GCPW_FORCE_RTL:
80             level=1;
81             break;
82         case WINE_GCPW_LOOSE_LTR:
83             level=UBIDI_DEFAULT_LTR;
84             break;
85         case WINE_GCPW_LOOSE_RTL:
86             level=UBIDI_DEFAULT_RTL;
87             break;
88         }
89
90         ubidi_setPara( bidi, lpString, uCount, level, NULL, &err );
91         if( lpOutString!=NULL ) {
92             ubidi_writeReordered( bidi, lpOutString, uCount,
93                     (dwFlags&GCP_SYMSWAPOFF)?0:UBIDI_DO_MIRRORING, &err );
94         }
95
96         if( lpOrder!=NULL ) {
97             ubidi_getLogicalMap( bidi, lpOrder, &err );
98         }
99
100         ubidi_close( bidi );
101
102         if( U_FAILURE(err) ) {
103             FIXME("ICU Library return error code %d.\n", err );
104             FIXME("Please report this error to wine-devel@winehq.org so we can place "
105                     "descriptive Windows error codes here\n");
106             SetLastError(ERROR_INVALID_LEVEL); /* This error is cryptic enough not to mean anything, I hope */
107
108             return FALSE;
109         }
110     }
111     return TRUE;
112 #else  /* HAVE_ICU */
113     return FALSE;
114 #endif  /* HAVE_ICU */
115 }