diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h index 5383f827d99..de95448f120 100644 --- a/dlls/riched20/editor.h +++ b/dlls/riched20/editor.h @@ -142,6 +142,7 @@ void ME_CheckCharOffsets(ME_TextEditor *editor) DECLSPEC_HIDDEN; void ME_PropagateCharOffset(ME_DisplayItem *p, int shift) DECLSPEC_HIDDEN; /* this one accounts for 1/2 char tolerance */ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run) DECLSPEC_HIDDEN; +int ME_PointFromCharContext(ME_Context *c, ME_Run *pRun, int nOffset) DECLSPEC_HIDDEN; int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset) DECLSPEC_HIDDEN; int ME_CanJoinRuns(const ME_Run *run1, const ME_Run *run2) DECLSPEC_HIDDEN; void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p) DECLSPEC_HIDDEN; diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c index 37445a173a0..2808045178e 100644 --- a/dlls/riched20/run.c +++ b/dlls/riched20/run.c @@ -487,43 +487,56 @@ static void ME_GetTextExtent(ME_Context *c, LPCWSTR szText, int nChars, ME_Style } /****************************************************************************** - * ME_PointFromChar + * ME_PointFromCharContext * * Returns a run-relative pixel position given a run-relative character * position (character offset) */ -int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset) +int ME_PointFromCharContext(ME_Context *c, ME_Run *pRun, int nOffset) { SIZE size; - ME_Context c; ME_String *mask_text = NULL; WCHAR *str; - ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost)); if (pRun->nFlags & MERF_GRAPHICS) { if (nOffset) - ME_GetOLEObjectSize(&c, pRun, &size); - ME_DestroyContext(&c); + ME_GetOLEObjectSize(c, pRun, &size); return nOffset != 0; } else if (pRun->nFlags & MERF_ENDPARA) { nOffset = 0; } - if (editor->cPasswordMask) + if (c->editor->cPasswordMask) { - mask_text = ME_MakeStringR(editor->cPasswordMask, pRun->len); + mask_text = ME_MakeStringR(c->editor->cPasswordMask, pRun->len); str = mask_text->szData; } else str = get_text( pRun, 0 ); - ME_GetTextExtent(&c, str, nOffset, pRun->style, &size); - ME_DestroyContext(&c); + ME_GetTextExtent(c, str, nOffset, pRun->style, &size); ME_DestroyString( mask_text ); return size.cx; } +/****************************************************************************** + * ME_PointFromChar + * + * Calls ME_PointFromCharContext after first creating a context. + */ +int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset) +{ + ME_Context c; + int ret; + + ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost)); + ret = ME_PointFromCharContext( &c, pRun, nOffset ); + ME_DestroyContext(&c); + + return ret; +} + /****************************************************************************** * ME_GetRunSizeCommon *