Commit 4df49291 authored by Aric Stewart's avatar Aric Stewart Committed by Alexandre Julliard

usp10: Use a bsearch function to find a glyph in the LogClust array.

parent 2ab625bf
......@@ -438,9 +438,12 @@ void OpenType_GDEF_UpdateGlyphProps(HDC hdc, ScriptCache *psc, const WORD *pwGly
int char_count = 0;
int k;
for (k = 0; k < cChars; k++)
if (pwLogClust[k] == i)
k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
if (k >= 0)
{
for (; k < cChars && pwLogClust[k] == i; k++)
char_count++;
}
class = GDEF_get_glyph_class(psc->GDEF_Table, pwGlyphs[i]);
......
......@@ -2359,13 +2359,11 @@ static void ShapeCharGlyphProp_Default( HDC hdc, ScriptCache* psc, SCRIPT_ANALYS
int char_index[20];
int char_count = 0;
for (k = 0; k < cChars; k++)
k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
if (k>=0)
{
if (pwLogClust[k] == i)
{
char_index[char_count] = k;
char_count++;
}
for (; k < cChars && pwLogClust[k] == i; k++)
char_index[char_count++] = k;
}
if (char_count == 0)
......@@ -2425,13 +2423,11 @@ static void ShapeCharGlyphProp_Arabic( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSI
int char_count = 0;
BOOL isInit, isFinal;
for (k = 0; k < cChars; k++)
k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
if (k>=0)
{
if (pwLogClust[k] == i)
{
char_index[char_count] = k;
char_count++;
}
for (; k < cChars && pwLogClust[k] == i; k++)
char_index[char_count++] = k;
}
isInit = (i == initGlyph || (i+dirR > 0 && i+dirR < cGlyphs && spaces[i+dirR]));
......@@ -2534,13 +2530,11 @@ static void ShapeCharGlyphProp_Thai( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS
int char_index[20];
int char_count = 0;
for (k = 0; k < cChars; k++)
k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
if (k>=0)
{
if (pwLogClust[k] == i)
{
char_index[char_count] = k;
char_count++;
}
for (; k < cChars && pwLogClust[k] == i; k++)
char_index[char_count++] = k;
}
if (char_count == 0)
......@@ -2581,13 +2575,11 @@ static void ShapeCharGlyphProp_None( HDC hdc, ScriptCache* psc, SCRIPT_ANALYSIS*
int char_index[20];
int char_count = 0;
for (k = 0; k < cChars; k++)
k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
if (k>=0)
{
if (pwLogClust[k] == i)
{
char_index[char_count] = k;
char_count++;
}
for (; k < cChars && pwLogClust[k] == i; k++)
char_index[char_count++] = k;
}
if (char_count == 0)
......@@ -2614,13 +2606,11 @@ static void ShapeCharGlyphProp_Tibet( HDC hdc, ScriptCache* psc, SCRIPT_ANALYSIS
int char_index[20];
int char_count = 0;
for (k = 0; k < cChars; k++)
k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
if (k>=0)
{
if (pwLogClust[k] == i)
{
char_index[char_count] = k;
char_count++;
}
for (; k < cChars && pwLogClust[k] == i; k++)
char_index[char_count++] = k;
}
if (char_count == 0)
......@@ -2658,13 +2648,11 @@ static void ShapeCharGlyphProp_BaseIndic( HDC hdc, ScriptCache *psc, SCRIPT_ANAL
int char_index[20];
int char_count = 0;
for (k = 0; k < cChars; k++)
k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
if (k>=0)
{
if (pwLogClust[k] == i)
{
char_index[char_count] = k;
char_count++;
}
for (; k < cChars && pwLogClust[k] == i; k++)
char_index[char_count++] = k;
}
if (override_gsub)
......
......@@ -25,6 +25,7 @@
*/
#include <stdarg.h>
#include <stdlib.h>
#include "windef.h"
#include "winbase.h"
......@@ -703,6 +704,11 @@ typedef struct {
int* logical2visual;
} StringAnalysis;
typedef struct {
BOOL ascending;
WORD target;
} FindGlyph_struct;
static inline void *heap_alloc(SIZE_T size)
{
return HeapAlloc(GetProcessHeap(), 0, size);
......@@ -881,6 +887,46 @@ static WORD get_char_script( LPCWSTR str, INT index, INT end, INT *consumed)
return SCRIPT_UNDEFINED;
}
static int compare_FindGlyph(const void *a, const void* b)
{
const FindGlyph_struct *find = (FindGlyph_struct*)a;
const WORD *idx= (WORD*)b;
int rc = 0;
if ( find->target > *idx)
rc = 1;
else if (find->target < *idx)
rc = -1;
if (!find->ascending)
rc *= -1;
return rc;
}
int USP10_FindGlyphInLogClust(const WORD* pwLogClust, int cChars, WORD target)
{
FindGlyph_struct fgs;
WORD *ptr;
INT k;
if (pwLogClust[0] < pwLogClust[cChars-1])
fgs.ascending = TRUE;
else
fgs.ascending = FALSE;
fgs.target = target;
ptr = bsearch(&fgs, pwLogClust, cChars, sizeof(WORD), compare_FindGlyph);
if (!ptr)
return -1;
for (k = (ptr - pwLogClust)-1; k >= 0 && pwLogClust[k] == target; k--)
;
k++;
return k;
}
/***********************************************************************
* DllMain
*
......@@ -1873,13 +1919,9 @@ error:
static inline BOOL does_glyph_start_cluster(const SCRIPT_VISATTR *pva, const WORD *pwLogClust, int cChars, int glyph, int direction)
{
int i;
if (pva[glyph].fClusterStart)
return TRUE;
for (i = 0; i < cChars; i++)
if (pwLogClust[i] == glyph) break;
if (i != cChars)
if (USP10_FindGlyphInLogClust(pwLogClust, cChars, glyph) >= 0)
return TRUE;
return FALSE;
......
......@@ -204,6 +204,8 @@ typedef void (*reorder_function)(LPWSTR pwChar, IndicSyllable *syllable, lexical
#define BIDI_WEAK 2
#define BIDI_NEUTRAL 0
int USP10_FindGlyphInLogClust(const WORD* pwLogClust, int cChars, WORD target) DECLSPEC_HIDDEN;
BOOL BIDI_DetermineLevels( LPCWSTR lpString, INT uCount, const SCRIPT_STATE *s,
const SCRIPT_CONTROL *c, WORD *lpOutLevels ) DECLSPEC_HIDDEN;
BOOL BIDI_GetStrengths(LPCWSTR lpString, INT uCount, const SCRIPT_CONTROL *c,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment