usp10.c 11.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * Implementation of Uniscribe Script Processor (usp10.dll)
 *
 * Copyright 2005 Steven Edwards for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Notes:
 * Uniscribe allows for processing of complex scripts such as joining
 * and filtering characters and bi-directional text with custom line breaks.
 */

#include <stdarg.h>

27 28
#include "windef.h"
#include "winbase.h"
29
#include "wingdi.h"
30 31
#include "winuser.h"
#include "usp10.h"
32 33 34

#include "wine/debug.h"

35 36 37 38 39
/**
 * some documentation here:
 *   http://www.microsoft.com/typography/developers/uniscribe/uniscribe.htm
 */

40 41
WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#define MAX_SCRIPTS  8

/*  Set up a default for ScriptGetProperties    */
static const SCRIPT_PROPERTIES Default_Script_0 = {0, 0, 0, 0, 0, 0, 0, 0, 
                                            0, 0, 0, 0, 0, 0, 0};
static const SCRIPT_PROPERTIES Default_Script_1 = {0, 0, 0, 0, 0, 0, 0, 0, 
                                            0, 0, 0, 0, 0, 0, 0};
static const SCRIPT_PROPERTIES Default_Script_2 = {0, 0, 0, 0, 0, 0, 0, 0, 
                                            0, 0, 0, 0, 0, 0, 0};
static const SCRIPT_PROPERTIES Default_Script_3 = {9, 0, 0, 0, 0, 0, 0, 0, 
                                            0, 0, 0, 0, 0, 0, 0};
static const SCRIPT_PROPERTIES Default_Script_4 = {9, 1, 0, 0, 0, 0, 0, 0, 
                                            0, 0, 0, 0, 0, 0, 0};
static const SCRIPT_PROPERTIES Default_Script_5 = {9, 0, 0, 0, 0, 0, 0, 0, 
                                            0, 0, 0, 0, 1, 0, 0};
static const SCRIPT_PROPERTIES Default_Script_6 = {9, 1, 0, 0, 0, 0, 0, 0, 
                                            0, 0, 0, 0, 1, 0, 0};
static const SCRIPT_PROPERTIES Default_Script_7 = {8, 0, 0, 0, 0, 161, 0, 0, 
                                            0, 0, 0, 0, 0, 0, 0};
static const SCRIPT_PROPERTIES *Global_Script[MAX_SCRIPTS] =
                                      {&Default_Script_0,
                                       &Default_Script_1,
                                       &Default_Script_2,
                                       &Default_Script_3,
                                       &Default_Script_4,
                                       &Default_Script_5,
                                       &Default_Script_6,
                                       &Default_Script_7};

71 72 73 74 75 76 77 78 79 80 81 82
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
{
    switch(fdwReason) {
        case DLL_PROCESS_ATTACH:
            DisableThreadLibraryCalls(hInstDLL);
	    break;
	case DLL_PROCESS_DETACH:
	    break;
    }
    return TRUE;
}

Hans Leidekker's avatar
Hans Leidekker committed
83 84 85 86 87 88 89 90 91 92 93 94
/***********************************************************************
 *      ScriptFreeCache (USP10.@)
 *
 */
HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc)
{
    FIXME("%p\n", psc);

    if (psc) *psc = NULL;
    return 0;
}

95 96 97 98
/***********************************************************************
 *      ScriptGetProperties (USP10.@)
 *
 */
99 100
HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***ppSp, int *piNumScripts)
{
101
    TRACE("%p,%p\n",ppSp, piNumScripts);
Hans Leidekker's avatar
Hans Leidekker committed
102

103 104 105 106 107
/*  Set up a sensible default and intialise pointers  */
    *piNumScripts = MAX_SCRIPTS;
    *ppSp =  Global_Script;
    TRACE("ppSp:%p, *ppSp:%p, **ppSp:%p, %d\n", ppSp, *ppSp, **ppSp, 
                                                *piNumScripts);
Hans Leidekker's avatar
Hans Leidekker committed
108
    return 0;
109 110
}

111 112 113 114
/***********************************************************************
 *      ScriptGetFontProperties (USP10.@)
 *
 */
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp)
{
    FIXME("%p,%p,%p\n", hdc, psc, sfp);
    /* return something sensible? */
    if (NULL != sfp) {
        sfp->cBytes        = sizeof(SCRIPT_FONTPROPERTIES);
        sfp->wgBlank       = 0;
        sfp->wgDefault     = 0;
        sfp->wgInvalid     = 0;
        sfp->wgKashida     = 1;
        sfp->iKashidaWidth = 0;
    }
    return 0;
}

130 131 132 133
/***********************************************************************
 *      ScriptRecordDigitSubstitution (USP10.@)
 *
 */
134 135 136 137 138 139
HRESULT WINAPI ScriptRecordDigitSubstitution(LCID Locale,SCRIPT_DIGITSUBSTITUTE *psds)
{
    FIXME("%ld,%p\n",Locale,psds);
    return E_NOTIMPL;
}

140 141 142 143
/***********************************************************************
 *      ScriptApplyDigitSubstitution (USP10.@)
 *
 */
144 145 146 147 148 149 150
HRESULT WINAPI ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE* psds, 
                                            SCRIPT_CONTROL* psc, SCRIPT_STATE* pss)
{
    FIXME("%p,%p,%p\n",psds,psc,pss);
    return E_NOTIMPL;
}

151 152 153 154
/***********************************************************************
 *      ScriptItemize (USP10.@)
 *
 */
155 156 157 158
HRESULT WINAPI ScriptItemize(const WCHAR *pwcInChars, int cInChars, int cMaxItems, 
                             const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState, 
                             SCRIPT_ITEM *pItems, int *pcItems)
{
159 160 161
    /* This implementation currently treats the entire string represented in 
     * pwcInChars as a single entity.  Hence pcItems will be set to 1.          */

162 163
    FIXME("%s,%d,%d,%p,%p,%p,%p\n", debugstr_w(pwcInChars), cInChars, cMaxItems, 
          psControl, psState, pItems, pcItems);
Hans Leidekker's avatar
Hans Leidekker committed
164 165 166 167

    if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2)
        return E_INVALIDARG;

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
    /*  Set a sensible default                              */
    /*  Set SCRIPT_ITEM                                     */
    pItems[0].iCharPos = 0;
    /*  Set the SCRIPT_ANALYSIS                             */
    pItems[0].a.eScript = SCRIPT_UNDEFINED;
    pItems[0].a.fRTL = 0;
    pItems[0].a.fLayoutRTL = 0;
    pItems[0].a.fLinkBefore = 0;
    pItems[0].a.fLinkAfter = 0;
    pItems[0].a.fLogicalOrder = 0;
    pItems[0].a.fNoGlyphIndex = 0;
    /*  set the SCRIPT_STATE                                */
    pItems[0].a.s.uBidiLevel = 0;
    pItems[0].a.s.fOverrideDirection = 0;
    pItems[0].a.s.fInhibitSymSwap = FALSE;
    pItems[0].a.s.fCharShape = 0;
    pItems[0].a.s.fDigitSubstitute = 0;
    pItems[0].a.s.fInhibitLigate = 0;
    pItems[0].a.s.fDisplayZWG = 0;
    pItems[0].a.s.fArabicNumContext = 0;
    pItems[0].a.s.fGcpClusters = 0;
    pItems[0].a.s.fReserved = 0;
    pItems[0].a.s.fEngineReserved = 0;

    /* While not strickly necessary according to the spec, make sure the n+1
     * item is set up to prevent random behaviour if the caller eroneously
     * checks the n+1 structure                                              */
    pItems[1].a.eScript = 0;
    pItems[1].a.fRTL = 0;
    pItems[1].a.fLayoutRTL = 0;
    pItems[1].a.fLinkBefore = 0;
    pItems[1].a.fLinkAfter = 0;
    pItems[1].a.fLogicalOrder = 0;
    pItems[1].a.fNoGlyphIndex = 0;
    /*  set the SCRIPT_STATE                                */
    pItems[1].a.s.uBidiLevel = 0;
    pItems[1].a.s.fOverrideDirection = 0;
    pItems[1].a.s.fInhibitSymSwap = FALSE;
    pItems[1].a.s.fCharShape = 0;
    pItems[1].a.s.fDigitSubstitute = 0;
    pItems[1].a.s.fInhibitLigate = 0;
    pItems[1].a.s.fDisplayZWG = 0;
    pItems[1].a.s.fArabicNumContext = 0;
    pItems[1].a.s.fGcpClusters = 0;
    pItems[1].a.s.fReserved = 0;
    pItems[1].a.s.fEngineReserved = 0;

    /*  Set one SCRIPT_STATE item being returned  */
    *pcItems = 1;

    /*  Set SCRIPT_ITEM                                     */
    pItems[1].iCharPos = cInChars - pItems[0].iCharPos ; /* the last + 1 item
                                             contains the ptr to the lastchar */
    TRACE("%s,%d,%d,%p,%p,%p,%p,%d\n", debugstr_w(pwcInChars), cInChars, cMaxItems, 
          psControl, psState, pItems, pcItems, *pcItems);
    TRACE("Start Pos in string: %d, Stop Pos %d\n", pItems[0].iCharPos, pItems[1].iCharPos);
Hans Leidekker's avatar
Hans Leidekker committed
224
    return 0;
225
}
226

227 228 229 230
/***********************************************************************
 *      ScriptStringAnalyse (USP10.@)
 *
 */
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
HRESULT WINAPI ScriptStringAnalyse(HDC hdc, 
				   const void *pString, 
				   int cString, 
				   int cGlyphs,
				   int iCharset,
				   DWORD dwFlags,
				   int iReqWidth,
				   SCRIPT_CONTROL *psControl,
				   SCRIPT_STATE *psState,
				   const int *piDx,
				   SCRIPT_TABDEF *pTabdef,
				   const BYTE *pbInClass,
				   SCRIPT_STRING_ANALYSIS *pssa)
{
  FIXME("(%p,%p,%d,%d,%d,0x%lx,%d,%p,%p,%p,%p,%p,%p): stub\n",
	hdc, pString, cString, cGlyphs, iCharset, dwFlags,
	iReqWidth, psControl, psState, piDx, pTabdef, pbInClass, pssa);
  if (1 > cString || NULL == pString) {
    return E_INVALIDARG;
  }
  if ((dwFlags & SSA_GLYPHS) && NULL == hdc) {
    return E_INVALIDARG;
  }

  return E_NOTIMPL;
}

258 259 260 261
/***********************************************************************
 *      ScriptStringFree (USP10.@)
 *
 */
262 263 264 265 266
HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa) {
  FIXME("(%p): stub\n",pssa);
  return S_OK;
}

267 268 269 270
/***********************************************************************
 *      ScriptIsComplex (USP10.@)
 *
 */
271 272 273 274
HRESULT WINAPI ScriptIsComplex(const WCHAR* pwcInChars, int cInChars, DWORD dwFlags) {
  FIXME("(%s,%d,0x%lx): stub\n",  debugstr_w(pwcInChars), cInChars, dwFlags);
   return E_NOTIMPL;
}
Jeff Latimer's avatar
Jeff Latimer committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
/***********************************************************************
 *      ScriptShape (USP10.@)
 *
 */
HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars, 
                           int cChars, int cMaxGlyphs,
                           SCRIPT_ANALYSIS *psa, WORD *pwOutGlyphs, WORD *pwLogClust, 
                           SCRIPT_VISATTR *psva, int *pcGlyphs)
{
    FIXME("(%p,%p,%p,%s,%d,%d, %p, %p, %p, %p): stub\n",  hdc, psc, pwcChars,
                                       debugstr_w(pwcChars), 
                                       cChars, cMaxGlyphs,
                                       psa, pwOutGlyphs, psva, pcGlyphs);
    return E_NOTIMPL;

}
/***********************************************************************
 *      ScriptPlace (USP10.@)
 *
 */
HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs, 
                           int cGlyphs, const SCRIPT_VISATTR *psva,
                           SCRIPT_ANALYSIS *psa, int *piAdvance, GOFFSET *pGoffset, ABC *pABC )
{
    FIXME("(%p,%p,%p,%s,%d, %p, %p, %p): stub\n",  hdc, psc, pwGlyphs,
                                                debugstr_w(pwGlyphs), 
                                                cGlyphs, psva, psa, 
                                                piAdvance);
    return E_NOTIMPL;

}
306 307 308 309 310 311 312 313 314 315 316

/***********************************************************************
 *      ScriptGetCMap (USP10.@)
 *
 */
HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars,
			      int cChars, DWORD dwFlags, WORD *pwOutGlyphs)
{
    FIXME("(%p,%p,%s,%d,0x%lx,%p): stub\n", hdc, psc, debugstr_w(pwcInChars), cChars, dwFlags, pwOutGlyphs);
    return E_NOTIMPL;
}