usp10: Implement digit substitution functions and add stubs
Albert Lee
trisk at jhu.edu
Sat Jul 29 05:33:18 CDT 2006
Hi,
This adds implementations for ScriptRecordDigitSubstitution and
ScriptApplyDigitSubstitution that should be correct. Thanks to Hans
Leiddekker for looking at it.
This also adds stubs for ScriptLayout and ScriptJustify (needed for some
programs).
The test for this is a shell script that runs the small test program with
a huge number of locales and compares the struct contents with the native
dll. Just run usp10test.sh with usp10test.exe in the current dir.
To get the test program to link, I had to get usp10.def and replace
ScriptApplyDigitSubstitution with ScriptApplyDigitSubstitution at 12 and
ScriptRecordDigitSubstitution with ScriptRecordDigitSubstitution at 8, then
do:
dlltool --input-def usp10.def --dllname USP10.dll --output-lib libusp10.a -k
gcc usp10test.c -o usp10test.exe -Ipath/to/usp10.h -L. -lusp10
-Albert
-------------- next part --------------
Index: dlls/usp10/usp10.c
===================================================================
RCS file: /home/wine/wine/dlls/usp10/usp10.c,v
retrieving revision 1.34
diff -u -r1.34 usp10.c
--- dlls/usp10/usp10.c 21 Jul 2006 09:15:54 -0000 1.34
+++ dlls/usp10/usp10.c 29 Jul 2006 09:43:40 -0000
@@ -28,6 +28,7 @@
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
+#include "winnls.h"
#include "usp10.h"
#include "wine/debug.h"
@@ -170,10 +171,50 @@
* ScriptRecordDigitSubstitution (USP10.@)
*
*/
-HRESULT WINAPI ScriptRecordDigitSubstitution(LCID Locale,SCRIPT_DIGITSUBSTITUTE *psds)
+HRESULT WINAPI ScriptRecordDigitSubstitution(LCID Locale, SCRIPT_DIGITSUBSTITUTE *psds)
{
- FIXME("%ld,%p\n",Locale,psds);
- return E_NOTIMPL;
+ DWORD plgid;
+ DWORD sub;
+
+ /* This implementation appears to be correct for all languages, but it's
+ * not clear if psds->DigitSubstitute is ever set to anything except
+ * CONTEXT or NONE in reality */
+
+ if (NULL == psds)
+ return E_POINTER;
+
+ Locale = ConvertDefaultLocale(Locale);
+
+ if (IsValidLocale(Locale, LCID_INSTALLED) == 0)
+ return E_INVALIDARG;
+
+ plgid = PRIMARYLANGID(LANGIDFROMLCID(Locale));
+
+ psds->TraditionalDigitLanguage = plgid;
+
+ psds->NationalDigitLanguage = ((plgid == LANG_ARABIC) || (plgid == LANG_FARSI)) ? plgid : LANG_ENGLISH;
+
+ GetLocaleInfoW(Locale, LOCALE_IDIGITSUBSTITUTION | LOCALE_RETURN_NUMBER, (LPWSTR)&sub, sizeof(sub) / sizeof(WCHAR));
+
+ switch(sub) {
+ /* http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx */
+ case 0:
+ psds->DigitSubstitute = ((plgid == LANG_ARABIC) || (plgid == LANG_FARSI)) ? SCRIPT_DIGITSUBSTITUTE_CONTEXT : SCRIPT_DIGITSUBSTITUTE_NONE;
+ break;
+ case 1:
+ psds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
+ break;
+ case 2:
+ psds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NATIONAL;
+ break;
+ default:
+ psds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_TRADITIONAL;
+ break;
+ }
+
+ psds->dwReserved = 0;
+
+ return S_OK;
}
/***********************************************************************
@@ -183,8 +224,36 @@
HRESULT WINAPI ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE* psds,
SCRIPT_CONTROL* psc, SCRIPT_STATE* pss)
{
- FIXME("%p,%p,%p\n",psds,psc,pss);
- return E_NOTIMPL;
+ SCRIPT_DIGITSUBSTITUTE sds;
+
+ if (NULL == psds)
+ {
+ psds = &sds;
+ ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &sds);
+ }
+
+ psc->uDefaultLanguage = psds->TraditionalDigitLanguage;
+ psc->fContextDigits = FALSE;
+ pss->fDigitSubstitute = TRUE;
+
+ switch (psds->DigitSubstitute) {
+ case SCRIPT_DIGITSUBSTITUTE_CONTEXT:
+ psc->fContextDigits = TRUE;
+ break;
+ case SCRIPT_DIGITSUBSTITUTE_NATIONAL:
+ psc->uDefaultLanguage = psds->NationalDigitLanguage;
+ break;
+ case SCRIPT_DIGITSUBSTITUTE_NONE:
+ pss->fDigitSubstitute = FALSE;
+ break;
+ case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL:
+ break;
+ default:
+ return E_INVALIDARG;
+ break;
+ }
+
+ return S_OK;
}
/***********************************************************************
@@ -526,6 +595,34 @@
}
/***********************************************************************
+ * ScriptJustify (USP10.@)
+ *
+ */
+HRESULT WINAPI ScriptJustify(const SCRIPT_VISATTR* psva,
+ const int* piAdvance,
+ int cGlyphs,
+ int iDx,
+ int iMinKashida,
+ int* piJustify)
+{
+ FIXME("(%p,%p,%d,%d,%d,%p): stub\n", psva, piAdvance, cGlyphs, iDx, iMinKashida, piJustify);
+ return E_NOTIMPL;
+}
+
+/***********************************************************************
+ * ScriptLayout (USP10.@)
+ *
+ */
+HRESULT WINAPI ScriptLayout(int cRuns,
+ const BYTE* pbLevel,
+ int* piVisualToLogical,
+ int* piLogicalToVisual)
+{
+ FIXME("(%d,%p,%p,%p): stub\n", cRuns, pbLevel, piVisualToLogical, piLogicalToVisual);
+ return E_NOTIMPL;
+}
+
+/***********************************************************************
* ScriptPlace (USP10.@)
*
*/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: usp10test.sh
Type: application/x-sh
Size: 1564 bytes
Desc: Script to run test
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20060729/81eb9852/usp10test-0003.sh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: usp10test.exe
Type: application/octet-stream
Size: 6656 bytes
Desc: Executable for test
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20060729/81eb9852/usp10test-0003.obj
-------------- next part --------------
#include <windows.h>
#include <stdio.h>
#include <winnls.h>
#include <usp10.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
{
DWORD err;
SCRIPT_DIGITSUBSTITUTE psds;
SCRIPT_CONTROL psc;
SCRIPT_STATE pss;
if ((err = ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &psds)) != S_OK)
{
printf("ScriptRecordDigitSubstitution failed: %d\n", err);
return 1;
}
printf("SCRIPT_DIGITSUBSTITUTE:\n NationalDigitLanguage=%d,\n TraditionalDigitLanguage=%d,\n DigitSubstitute=%d,\n dwReserved=%d\n\n", psds.NationalDigitLanguage, psds.TraditionalDigitLanguage, psds.DigitSubstitute, psds.dwReserved);
if ((err = ScriptApplyDigitSubstitution(&psds, &psc, &pss)) != S_OK)
{
printf("ScriptRecordDigitSubstitution failed: %d\n", err);
return 1;
}
printf("SCRIPT_CONTROL:\n fContextDigits=%d,\n uDefaultLanguage=%d\n\n", psc.fContextDigits, psc.uDefaultLanguage);
printf("SCRIPT_STATE:\n fDigitSubstitute=%d\n\n", pss.fDigitSubstitute);
return 0;
}
More information about the wine-patches
mailing list