From: Jactry Zeng jzeng@codeweavers.com
Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- dlls/riched20/editstr.h | 2 +- dlls/riched20/run.c | 23 ++++++++++++++++++----- dlls/riched20/wrap.c | 20 ++++++++++++++------ 3 files changed, 33 insertions(+), 12 deletions(-)
diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h index db219d7e4df..35e2417298f 100644 --- a/dlls/riched20/editstr.h +++ b/dlls/riched20/editstr.h @@ -171,7 +171,7 @@ typedef struct tagME_Run SCRIPT_ANALYSIS script_analysis; int num_glyphs, max_glyphs; WORD *glyphs; - SCRIPT_VISATTR *vis_attrs; + SCRIPT_GLYPHPROP *glyph_props; int *advances; GOFFSET *offsets; int max_clusters; diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c index f6e6f08d12a..fe889c6ece2 100644 --- a/dlls/riched20/run.c +++ b/dlls/riched20/run.c @@ -357,7 +357,7 @@ ME_Run *run_create( ME_Style *s, int flags ) run->num_glyphs = 0; run->max_glyphs = 0; run->glyphs = NULL; - run->vis_attrs = NULL; + run->glyph_props = NULL; run->advances = NULL; run->offsets = NULL; run->max_clusters = 0; @@ -533,11 +533,17 @@ int ME_CharFromPointContext(ME_Context *c, int cx, ME_Run *run, BOOL closest, BO
if (run->para->nFlags & MEPF_COMPLEX) { - int cp, trailing; + SCRIPT_VISATTR *script_visattrs; + int cp, trailing, i; if (visual_order && run->script_analysis.fRTL) cx = run->nWidth - cx - 1;
- ScriptXtoCP( cx, run->len, run->num_glyphs, run->clusters, run->vis_attrs, run->advances, &run->script_analysis, + script_visattrs = heap_alloc( run->num_glyphs * sizeof(SCRIPT_VISATTR) ); + for (i = 0; i < run->num_glyphs; i++) + script_visattrs[i] = run->glyph_props[i].sva; + ScriptXtoCP( cx, run->len, run->num_glyphs, run->clusters, script_visattrs, run->advances, &run->script_analysis, &cp, &trailing ); + heap_free( script_visattrs ); + TRACE("x %d cp %d trailing %d (run width %d) rtl %d log order %d\n", cx, cp, trailing, run->nWidth, run->script_analysis.fRTL, run->script_analysis.fLogicalOrder); return closest ? cp + trailing : cp; @@ -622,9 +628,16 @@ int ME_PointFromCharContext(ME_Context *c, ME_Run *pRun, int nOffset, BOOL visua
if (pRun->para->nFlags & MEPF_COMPLEX) { - int x; + SCRIPT_VISATTR *script_visattrs; + int x, i; + + script_visattrs = heap_alloc( pRun->num_glyphs * sizeof(SCRIPT_VISATTR) ); + for (i = 0; i < pRun->num_glyphs; i++) + script_visattrs[i] = pRun->glyph_props[i].sva; ScriptCPtoX( nOffset, FALSE, pRun->len, pRun->num_glyphs, pRun->clusters, - pRun->vis_attrs, pRun->advances, &pRun->script_analysis, &x ); + script_visattrs, pRun->advances, &pRun->script_analysis, &x ); + heap_free( script_visattrs ); + if (visual_order && pRun->script_analysis.fRTL) x = pRun->nWidth - x - 1; return x; } diff --git a/dlls/riched20/wrap.c b/dlls/riched20/wrap.c index 8cfb1692ecd..31910486558 100644 --- a/dlls/riched20/wrap.c +++ b/dlls/riched20/wrap.c @@ -51,18 +51,19 @@ typedef struct tagME_WrapContext static BOOL get_run_glyph_buffers( ME_Run *run ) { heap_free( run->glyphs ); - run->glyphs = heap_alloc( run->max_glyphs * (sizeof(WORD) + sizeof(SCRIPT_VISATTR) + sizeof(int) + sizeof(GOFFSET)) ); + run->glyphs = heap_alloc( run->max_glyphs * (sizeof(WORD) + sizeof(SCRIPT_GLYPHPROP) + sizeof(int) + sizeof(GOFFSET)) ); if (!run->glyphs) return FALSE;
- run->vis_attrs = (SCRIPT_VISATTR*)((char*)run->glyphs + run->max_glyphs * sizeof(WORD)); - run->advances = (int*)((char*)run->glyphs + run->max_glyphs * (sizeof(WORD) + sizeof(SCRIPT_VISATTR))); - run->offsets = (GOFFSET*)((char*)run->glyphs + run->max_glyphs * (sizeof(WORD) + sizeof(SCRIPT_VISATTR) + sizeof(int))); + run->glyph_props = (SCRIPT_GLYPHPROP*)((char*)run->glyphs + run->max_glyphs * sizeof(WORD)); + run->advances = (int*)((char*)run->glyphs + run->max_glyphs * (sizeof(WORD) + sizeof(SCRIPT_GLYPHPROP))); + run->offsets = (GOFFSET*)((char*)run->glyphs + run->max_glyphs * (sizeof(WORD) + sizeof(SCRIPT_GLYPHPROP) + sizeof(int)));
return TRUE; }
static HRESULT shape_run( ME_Context *c, ME_Run *run ) { + SCRIPT_VISATTR *script_visattrs = NULL; HRESULT hr; int i;
@@ -83,8 +84,11 @@ static HRESULT shape_run( ME_Context *c, ME_Run *run ) select_style( c, run->style ); while (1) { + heap_free( script_visattrs ); + script_visattrs = heap_alloc( run->max_glyphs * sizeof(SCRIPT_VISATTR) ); + hr = ScriptShape( c->hDC, &run->style->script_cache, get_text( run, 0 ), run->len, run->max_glyphs, - &run->script_analysis, run->glyphs, run->clusters, run->vis_attrs, &run->num_glyphs ); + &run->script_analysis, run->glyphs, run->clusters, script_visattrs, &run->num_glyphs ); if (hr != E_OUTOFMEMORY) break; if (run->max_glyphs > 10 * run->len) break; /* something has clearly gone wrong */ run->max_glyphs *= 2; @@ -92,14 +96,18 @@ static HRESULT shape_run( ME_Context *c, ME_Run *run ) }
if (SUCCEEDED(hr)) - hr = ScriptPlace( c->hDC, &run->style->script_cache, run->glyphs, run->num_glyphs, run->vis_attrs, + hr = ScriptPlace( c->hDC, &run->style->script_cache, run->glyphs, run->num_glyphs, script_visattrs, &run->script_analysis, run->advances, run->offsets, NULL );
if (SUCCEEDED(hr)) { for (i = 0, run->nWidth = 0; i < run->num_glyphs; i++) + { run->nWidth += run->advances[i]; + run->glyph_props[i].sva = script_visattrs[i]; + } } + heap_free( script_visattrs );
return hr; }