Commit 9e8a9f4f authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

riched20: Move the split point calculation to wrap.c.

parent 68a4c30e
......@@ -140,7 +140,6 @@ ME_DisplayItem *ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor,
ME_Style *style, const WCHAR *str, int len, int flags) DECLSPEC_HIDDEN;
void ME_CheckCharOffsets(ME_TextEditor *editor) DECLSPEC_HIDDEN;
void ME_PropagateCharOffset(ME_DisplayItem *p, int shift) DECLSPEC_HIDDEN;
int ME_CharFromPoint(ME_Context *c, int cx, ME_Run *run) 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_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset) DECLSPEC_HIDDEN;
......
......@@ -404,56 +404,6 @@ void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run)
}
/******************************************************************************
* ME_CharFromPoint
*
* Returns a character position inside the run given a run-relative
* pixel horizontal position. This version rounds left (ie. if the second
* character is at pixel position 8, then for cx=0..7 it returns 0).
*/
int ME_CharFromPoint(ME_Context *c, int cx, ME_Run *run)
{
int fit = 0;
HGDIOBJ hOldFont;
SIZE sz;
if (!run->len || cx <= 0)
return 0;
if (run->nFlags & MERF_TAB ||
(run->nFlags & (MERF_ENDCELL|MERF_ENDPARA)) == MERF_ENDCELL)
{
if (cx < run->nWidth/2)
return 0;
return 1;
}
if (run->nFlags & MERF_GRAPHICS)
{
SIZE sz;
ME_GetOLEObjectSize(c, run, &sz);
if (cx < sz.cx)
return 0;
return 1;
}
hOldFont = ME_SelectStyleFont(c, run->style);
if (c->editor->cPasswordMask)
{
ME_String *strMasked = ME_MakeStringR(c->editor->cPasswordMask, run->len);
GetTextExtentExPointW(c->hDC, strMasked->szData, run->len,
cx, &fit, NULL, &sz);
ME_DestroyString(strMasked);
}
else
{
GetTextExtentExPointW(c->hDC, get_text( run, 0 ), run->len,
cx, &fit, NULL, &sz);
}
ME_UnselectStyleFont(c, run->style, hOldFont);
return fit;
}
/******************************************************************************
* ME_CharFromPointCursor
*
* Returns a character position inside the run given a run-relative
......
......@@ -80,6 +80,51 @@ static ME_DisplayItem *split_run_extents(ME_WrapContext *wc, ME_DisplayItem *ite
return cursor.pRun;
}
/******************************************************************************
* find_split_point
*
* Returns a character position to split inside the run given a run-relative
* pixel horizontal position. This version rounds left (ie. if the second
* character is at pixel position 8, then for cx=0..7 it returns 0).
*/
static int find_split_point( ME_Context *c, int cx, ME_Run *run )
{
int fit = 0;
HGDIOBJ hOldFont;
SIZE sz;
if (!run->len || cx <= 0) return 0;
if (run->nFlags & MERF_TAB ||
(run->nFlags & (MERF_ENDCELL|MERF_ENDPARA)) == MERF_ENDCELL)
{
if (cx < run->nWidth / 2) return 0;
return 1;
}
if (run->nFlags & MERF_GRAPHICS)
{
SIZE sz;
ME_GetOLEObjectSize( c, run, &sz );
if (cx < sz.cx) return 0;
return 1;
}
hOldFont = ME_SelectStyleFont( c, run->style );
if (c->editor->cPasswordMask)
{
ME_String *strMasked = ME_MakeStringR( c->editor->cPasswordMask, run->len );
GetTextExtentExPointW( c->hDC, strMasked->szData, run->len, cx, &fit, NULL, &sz );
ME_DestroyString( strMasked );
}
else
{
GetTextExtentExPointW( c->hDC, get_text( run, 0 ), run->len, cx, &fit, NULL, &sz );
}
ME_UnselectStyleFont( c, run->style, hOldFont );
return fit;
}
static ME_DisplayItem *ME_MakeRow(int height, int baseline, int width)
{
......@@ -337,7 +382,7 @@ static ME_DisplayItem *ME_SplitByBacktracking(ME_WrapContext *wc, ME_DisplayItem
int i, idesp, len;
ME_Run *run = &p->member.run;
idesp = i = ME_CharFromPoint(wc->context, loc, run);
idesp = i = find_split_point( wc->context, loc, run );
len = run->len;
assert(len>0);
assert(i<len);
......
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