richedit: Optimizations for the style selection.

Use a ME_Context for style selection/unselection.
Store the (x,y) dpi information for a given DC in the corresponding ME_Context structure.
This commit is contained in:
Eric Pouech 2008-01-01 22:05:33 +01:00 committed by Alexandre Julliard
parent 475b45d8ab
commit f43570cbf0
7 changed files with 86 additions and 92 deletions

View File

@ -29,6 +29,8 @@ void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC)
c->pt.y = 0; c->pt.y = 0;
c->hbrMargin = CreateSolidBrush(RGB(224,224,224)); c->hbrMargin = CreateSolidBrush(RGB(224,224,224));
c->rcView = editor->rcFormat; c->rcView = editor->rcFormat;
c->dpi.cx = GetDeviceCaps(hDC, LOGPIXELSX);
c->dpi.cy = GetDeviceCaps(hDC, LOGPIXELSY);
} }
void ME_DestroyContext(ME_Context *c) void ME_DestroyContext(ME_Context *c)

View File

@ -60,8 +60,8 @@ void ME_AddRefStyle(ME_Style *item);
void ME_ReleaseStyle(ME_Style *item); void ME_ReleaseStyle(ME_Style *item);
ME_Style *ME_GetInsertStyle(ME_TextEditor *editor, int nCursor); ME_Style *ME_GetInsertStyle(ME_TextEditor *editor, int nCursor);
ME_Style *ME_ApplyStyle(ME_Style *sSrc, CHARFORMAT2W *style); ME_Style *ME_ApplyStyle(ME_Style *sSrc, CHARFORMAT2W *style);
HFONT ME_SelectStyleFont(ME_TextEditor *editor, HDC hDC, ME_Style *s); HFONT ME_SelectStyleFont(ME_Context *c, ME_Style *s);
void ME_UnselectStyleFont(ME_TextEditor *editor, HDC hDC, ME_Style *s, HFONT hOldFont); void ME_UnselectStyleFont(ME_Context *c, ME_Style *s, HFONT hOldFont);
void ME_InitCharFormat2W(CHARFORMAT2W *pFmt); void ME_InitCharFormat2W(CHARFORMAT2W *pFmt);
void ME_SaveTempStyle(ME_TextEditor *editor); void ME_SaveTempStyle(ME_TextEditor *editor);
void ME_ClearTempStyle(ME_TextEditor *editor); void ME_ClearTempStyle(ME_TextEditor *editor);
@ -213,7 +213,8 @@ BOOL ME_UpdateSelection(ME_TextEditor *editor, const ME_Cursor *pTempCursor);
BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor); BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor);
void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor); void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor);
void ME_SendRequestResize(ME_TextEditor *editor, BOOL force); void ME_SendRequestResize(ME_TextEditor *editor, BOOL force);
int ME_twips2points(ME_Context *c, int x, int dpi); int ME_twips2pointsX(ME_Context *c, int x);
int ME_twips2pointsY(ME_Context *c, int y);
/* para.c */ /* para.c */
ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *run); ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *run);
@ -255,7 +256,7 @@ BOOL ME_GetYScrollVisible(ME_TextEditor *editor);
/* other functions in paint.c */ /* other functions in paint.c */
int ME_GetParaBorderWidth(ME_TextEditor *editor, int); int ME_GetParaBorderWidth(ME_TextEditor *editor, int);
int ME_GetParaLineSpace(ME_TextEditor *editor, ME_Paragraph*, int); int ME_GetParaLineSpace(ME_Context *c, ME_Paragraph*);
/* richole.c */ /* richole.c */
extern LRESULT CreateIRichEditOle(ME_TextEditor *editor, LPVOID *); extern LRESULT CreateIRichEditOle(ME_TextEditor *editor, LPVOID *);

View File

@ -334,6 +334,7 @@ typedef struct tagME_Context
POINT ptRowOffset; POINT ptRowOffset;
RECT rcView; RECT rcView;
HBRUSH hbrMargin; HBRUSH hbrMargin;
SIZE dpi;
/* those are valid inside ME_WrapTextParagraph and related */ /* those are valid inside ME_WrapTextParagraph and related */
POINT ptFirstRun; POINT ptFirstRun;

View File

@ -141,12 +141,20 @@ ME_RewrapRepaint(ME_TextEditor *editor)
ME_Repaint(editor); ME_Repaint(editor);
} }
int ME_twips2points(ME_Context *c, int x, int dpi) int ME_twips2pointsX(ME_Context *c, int x)
{ {
if (c->editor->nZoomNumerator == 0) if (c->editor->nZoomNumerator == 0)
return x * dpi / 1440; return x * c->dpi.cx / 1440;
else else
return x * dpi * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator; return x * c->dpi.cx * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
}
int ME_twips2pointsY(ME_Context *c, int y)
{
if (c->editor->nZoomNumerator == 0)
return y * c->dpi.cy / 1440;
else
return y * c->dpi.cy * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
} }
static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, int nChars, static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, int nChars,
@ -158,7 +166,7 @@ static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, in
SIZE sz; SIZE sz;
COLORREF rgb; COLORREF rgb;
hOldFont = ME_SelectStyleFont(c->editor, hDC, s); hOldFont = ME_SelectStyleFont(c, s);
if ((s->fmt.dwMask & CFM_LINK) && (s->fmt.dwEffects & CFE_LINK)) if ((s->fmt.dwMask & CFM_LINK) && (s->fmt.dwEffects & CFE_LINK))
rgb = RGB(0,0,255); rgb = RGB(0,0,255);
else if ((s->fmt.dwMask & CFM_COLOR) && (s->fmt.dwEffects & CFE_AUTOCOLOR)) else if ((s->fmt.dwMask & CFM_COLOR) && (s->fmt.dwEffects & CFE_AUTOCOLOR))
@ -174,8 +182,7 @@ static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, in
if (s->fmt.dwEffects & CFE_SUBSCRIPT) yTwipsOffset = -s->fmt.yHeight/12; if (s->fmt.dwEffects & CFE_SUBSCRIPT) yTwipsOffset = -s->fmt.yHeight/12;
} }
if (yTwipsOffset) if (yTwipsOffset)
yOffset = ME_twips2points(c, yTwipsOffset, GetDeviceCaps(hDC, LOGPIXELSY)); yOffset = ME_twips2pointsY(c, yTwipsOffset);
ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nChars, NULL); ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nChars, NULL);
GetTextExtentPoint32W(hDC, szText, nChars, &sz); GetTextExtentPoint32W(hDC, szText, nChars, &sz);
if (width) *width = sz.cx; if (width) *width = sz.cx;
@ -223,7 +230,7 @@ static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, in
PatBlt(hDC, x, ymin, sz.cx, cy, DSTINVERT); PatBlt(hDC, x, ymin, sz.cx, cy, DSTINVERT);
} }
SetTextColor(hDC, rgbOld); SetTextColor(hDC, rgbOld);
ME_UnselectStyleFont(c->editor, hDC, s, hOldFont); ME_UnselectStyleFont(c, s, hOldFont);
} }
static void ME_DebugWrite(HDC hDC, const POINT *pt, LPCWSTR szText) { static void ME_DebugWrite(HDC hDC, const POINT *pt, LPCWSTR szText) {
@ -366,7 +373,7 @@ int ME_GetParaBorderWidth(ME_TextEditor* editor, int flags)
return width; return width;
} }
int ME_GetParaLineSpace(ME_TextEditor* editor, ME_Paragraph* para, int dpi) int ME_GetParaLineSpace(ME_Context* c, ME_Paragraph* para)
{ {
int sp = 0, ls = 0; int sp = 0, ls = 0;
if (!(para->pFmt->dwMask & PFM_LINESPACING)) return 0; if (!(para->pFmt->dwMask & PFM_LINESPACING)) return 0;
@ -378,18 +385,18 @@ int ME_GetParaLineSpace(ME_TextEditor* editor, ME_Paragraph* para, int dpi)
case 0: sp = ls; break; case 0: sp = ls; break;
case 1: sp = (3 * ls) / 2; break; case 1: sp = (3 * ls) / 2; break;
case 2: sp = 2 * ls; break; case 2: sp = 2 * ls; break;
case 3: sp = para->pFmt->dyLineSpacing * dpi / 1440; if (sp < ls) sp = ls; break; case 3: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); if (sp < ls) sp = ls; break;
case 4: sp = para->pFmt->dyLineSpacing * dpi / 1440; break; case 4: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); break;
case 5: sp = para->pFmt->dyLineSpacing / 20; break; case 5: sp = para->pFmt->dyLineSpacing / 20; break;
default: FIXME("Unsupported spacing rule value %d\n", para->pFmt->bLineSpacingRule); default: FIXME("Unsupported spacing rule value %d\n", para->pFmt->bLineSpacingRule);
} }
if (editor->nZoomNumerator == 0) if (c->editor->nZoomNumerator == 0)
return sp; return sp;
else else
return sp * editor->nZoomNumerator / editor->nZoomDenominator; return sp * c->editor->nZoomNumerator / c->editor->nZoomDenominator;
} }
static int ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, int dpi) static int ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y)
{ {
int idx, border_width; int idx, border_width;
int ybefore, yafter; int ybefore, yafter;
@ -402,7 +409,7 @@ static int ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, int d
rc.left = c->rcView.left; rc.left = c->rcView.left;
rc.right = c->rcView.right; rc.right = c->rcView.right;
rc.top = y; rc.top = y;
ybefore = ME_twips2points(c, para->pFmt->dySpaceBefore, dpi); ybefore = ME_twips2pointsY(c, para->pFmt->dySpaceBefore);
rc.bottom = y + ybefore; rc.bottom = y + ybefore;
FillRect(c->hDC, &rc, c->editor->hbrBackground); FillRect(c->hDC, &rc, c->editor->hbrBackground);
} }
@ -412,7 +419,7 @@ static int ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, int d
rc.left = c->rcView.left; rc.left = c->rcView.left;
rc.right = c->rcView.right; rc.right = c->rcView.right;
rc.bottom = y + para->nHeight; rc.bottom = y + para->nHeight;
yafter = ME_twips2points(c, para->pFmt->dySpaceAfter, dpi); yafter = ME_twips2pointsY(c, para->pFmt->dySpaceAfter);
rc.top = rc.bottom - yafter; rc.top = rc.bottom - yafter;
FillRect(c->hDC, &rc, c->editor->hbrBackground); FillRect(c->hDC, &rc, c->editor->hbrBackground);
} }
@ -489,7 +496,6 @@ static int ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, int d
void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) { void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) {
int align = SetTextAlign(c->hDC, TA_BASELINE); int align = SetTextAlign(c->hDC, TA_BASELINE);
int dpi = GetDeviceCaps(c->hDC, LOGPIXELSX);
ME_DisplayItem *p; ME_DisplayItem *p;
ME_Run *run; ME_Run *run;
ME_Paragraph *para = NULL; ME_Paragraph *para = NULL;
@ -508,12 +514,12 @@ void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) {
case diParagraph: case diParagraph:
para = &p->member.para; para = &p->member.para;
assert(para); assert(para);
nMargWidth = ME_twips2points(c, para->pFmt->dxStartIndent, dpi); nMargWidth = ME_twips2pointsX(c, para->pFmt->dxStartIndent);
if (pno != 0) if (pno != 0)
nMargWidth += ME_twips2points(c, para->pFmt->dxOffset, dpi); nMargWidth += ME_twips2pointsX(c, para->pFmt->dxOffset);
xs = c->rcView.left+nMargWidth; xs = c->rcView.left+nMargWidth;
xe = c->rcView.right - ME_twips2points(c, para->pFmt->dxRightIndent, dpi); xe = c->rcView.right - ME_twips2pointsX(c, para->pFmt->dxRightIndent);
y += ME_DrawParaDecoration(c, para, y, dpi); y += ME_DrawParaDecoration(c, para, y);
break; break;
case diStartRow: case diStartRow:
y += height; y += height;

View File

@ -509,7 +509,7 @@ int ME_CharFromPoint(ME_Context *c, int cx, ME_Run *run)
return 0; return 0;
return 1; return 1;
} }
hOldFont = ME_SelectStyleFont(c->editor, c->hDC, run->style); hOldFont = ME_SelectStyleFont(c, run->style);
if (c->editor->cPasswordMask) if (c->editor->cPasswordMask)
{ {
@ -524,7 +524,7 @@ int ME_CharFromPoint(ME_Context *c, int cx, ME_Run *run)
cx, &fit, NULL, &sz); cx, &fit, NULL, &sz);
} }
ME_UnselectStyleFont(c->editor, c->hDC, run->style, hOldFont); ME_UnselectStyleFont(c, run->style, hOldFont);
return fit; return fit;
} }
@ -546,8 +546,8 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
/* This could point to either the run's real text, or it's masked form in a password control */ /* This could point to either the run's real text, or it's masked form in a password control */
int fit = 0, fit1 = 0; int fit = 0, fit1 = 0;
ME_Context c;
HGDIOBJ hOldFont; HGDIOBJ hOldFont;
HDC hDC;
SIZE sz, sz2, sz3; SIZE sz, sz2, sz3;
if (!run->strText->nLen) if (!run->strText->nLen)
return 0; return 0;
@ -572,17 +572,17 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
else else
strRunText = run->strText; strRunText = run->strText;
hDC = GetDC(editor->hWnd); ME_InitContext(&c, editor, GetDC(editor->hWnd));
hOldFont = ME_SelectStyleFont(editor, hDC, run->style); hOldFont = ME_SelectStyleFont(&c, run->style);
GetTextExtentExPointW(hDC, strRunText->szData, strRunText->nLen, GetTextExtentExPointW(c.hDC, strRunText->szData, strRunText->nLen,
cx, &fit, NULL, &sz); cx, &fit, NULL, &sz);
if (fit != strRunText->nLen) if (fit != strRunText->nLen)
{ {
int chars = 1; int chars = 1;
GetTextExtentPoint32W(hDC, strRunText->szData, fit, &sz2); GetTextExtentPoint32W(c.hDC, strRunText->szData, fit, &sz2);
fit1 = ME_StrRelPos(strRunText, fit, &chars); fit1 = ME_StrRelPos(strRunText, fit, &chars);
GetTextExtentPoint32W(hDC, strRunText->szData, fit1, &sz3); GetTextExtentPoint32W(c.hDC, strRunText->szData, fit1, &sz3);
if (cx >= (sz2.cx+sz3.cx)/2) if (cx >= (sz2.cx+sz3.cx)/2)
fit = fit1; fit = fit1;
} }
@ -590,11 +590,24 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
if (editor->cPasswordMask) if (editor->cPasswordMask)
ME_DestroyString(strRunText); ME_DestroyString(strRunText);
ME_UnselectStyleFont(editor, hDC, run->style, hOldFont); ME_UnselectStyleFont(&c, run->style, hOldFont);
ReleaseDC(editor->hWnd, hDC); ReleaseDC(editor->hWnd, c.hDC);
return fit; return fit;
} }
/******************************************************************************
* ME_GetTextExtent
*
* Finds a width and a height of the text using a specified style
*/
static void ME_GetTextExtent(ME_Context *c, LPCWSTR szText, int nChars, ME_Style *s, SIZE *size)
{
HGDIOBJ hOldFont;
hOldFont = ME_SelectStyleFont(c, s);
GetTextExtentPoint32W(c->hDC, szText, nChars, size);
ME_UnselectStyleFont(c, s, hOldFont);
}
/****************************************************************************** /******************************************************************************
* ME_PointFromChar * ME_PointFromChar
* *
@ -604,8 +617,7 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset) int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset)
{ {
SIZE size; SIZE size;
HDC hDC; ME_Context c;
HGDIOBJ hOldFont;
ME_String *strRunText; ME_String *strRunText;
/* This could point to either the run's real text, or it's masked form in a password control */ /* This could point to either the run's real text, or it's masked form in a password control */
@ -621,30 +633,14 @@ int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset)
else else
strRunText = pRun->strText; strRunText = pRun->strText;
hDC = GetDC(editor->hWnd); ME_InitContext(&c, editor, GetDC(editor->hWnd));
hOldFont = ME_SelectStyleFont(editor, hDC, pRun->style); ME_GetTextExtent(&c, strRunText->szData, nOffset, pRun->style, &size);
GetTextExtentPoint32W(hDC, strRunText->szData, nOffset, &size); ReleaseDC(editor->hWnd, c.hDC);
ME_UnselectStyleFont(editor, hDC, pRun->style, hOldFont);
ReleaseDC(editor->hWnd, hDC);
if (editor->cPasswordMask) if (editor->cPasswordMask)
ME_DestroyString(strRunText); ME_DestroyString(strRunText);
return size.cx; return size.cx;
} }
/******************************************************************************
* ME_GetTextExtent
*
* Finds a width and a height of the text using a specified style
*/
static void ME_GetTextExtent(ME_Context *c, LPCWSTR szText, int nChars, ME_Style *s, SIZE *size)
{
HDC hDC = c->hDC;
HGDIOBJ hOldFont;
hOldFont = ME_SelectStyleFont(c->editor, hDC, s);
GetTextExtentPoint32W(hDC, szText, nChars, size);
ME_UnselectStyleFont(c->editor, hDC, s, hOldFont);
}
/****************************************************************************** /******************************************************************************
* ME_GetRunSizeCommon * ME_GetRunSizeCommon
* *
@ -682,7 +678,7 @@ static SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run
if (run->nFlags & MERF_TAB) if (run->nFlags & MERF_TAB)
{ {
int pos = 0, i = 0, ppos; int pos = 0, i = 0, ppos;
int lpsx = GetDeviceCaps(c->hDC, LOGPIXELSX);
PARAFORMAT2 *pFmt = para->pFmt; PARAFORMAT2 *pFmt = para->pFmt;
do { do {
if (i < pFmt->cTabCount) if (i < pFmt->cTabCount)
@ -694,7 +690,7 @@ static SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run
{ {
pos += 720-(pos%720); pos += 720-(pos%720);
} }
ppos = pos*lpsx/1440; ppos = ME_twips2pointsX(c, pos);
if (ppos>run->pt.x) { if (ppos>run->pt.x) {
size.cx = ppos - run->pt.x; size.cx = ppos - run->pt.x;
break; break;
@ -713,9 +709,7 @@ static SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run
} }
if (run->nFlags & MERF_CELL) if (run->nFlags & MERF_CELL)
{ {
int lpsx = GetDeviceCaps(c->hDC, LOGPIXELSX); size.cx = ME_twips2pointsX(c, run->pCell->nRightBoundary) - run->pt.x;
size.cx = run->pCell->nRightBoundary * lpsx / 1440 - run->pt.x;
return size; return size;
} }
return size; return size;

View File

@ -297,20 +297,12 @@ void ME_DumpStyleToBuf(CHARFORMAT2W *pFmt, char buf[2048])
static void static void
ME_LogFontFromStyle(HDC hDC, LOGFONTW *lf, const ME_Style *s, int nZoomNumerator, int nZoomDenominator) ME_LogFontFromStyle(ME_Context* c, LOGFONTW *lf, const ME_Style *s)
{ {
int rx, ry;
rx = GetDeviceCaps(hDC, LOGPIXELSX);
ry = GetDeviceCaps(hDC, LOGPIXELSY);
ZeroMemory(lf, sizeof(LOGFONTW)); ZeroMemory(lf, sizeof(LOGFONTW));
lstrcpyW(lf->lfFaceName, s->fmt.szFaceName); lstrcpyW(lf->lfFaceName, s->fmt.szFaceName);
if (nZoomNumerator == 0) lf->lfHeight = ME_twips2pointsY(c, -s->fmt.yHeight);
{
nZoomNumerator = 1;
nZoomDenominator = 1;
}
lf->lfHeight = -s->fmt.yHeight*ry*nZoomNumerator/nZoomDenominator/1440;
lf->lfWeight = 400; lf->lfWeight = 400;
if (s->fmt.dwEffects & s->fmt.dwMask & CFM_BOLD) if (s->fmt.dwEffects & s->fmt.dwMask & CFM_BOLD)
@ -363,22 +355,22 @@ static BOOL ME_IsFontEqual(const LOGFONTW *p1, const LOGFONTW *p2)
return TRUE; return TRUE;
} }
HFONT ME_SelectStyleFont(ME_TextEditor *editor, HDC hDC, ME_Style *s) HFONT ME_SelectStyleFont(ME_Context *c, ME_Style *s)
{ {
HFONT hOldFont; HFONT hOldFont;
LOGFONTW lf; LOGFONTW lf;
int i, nEmpty, nAge = 0x7FFFFFFF; int i, nEmpty, nAge = 0x7FFFFFFF;
ME_FontCacheItem *item; ME_FontCacheItem *item;
assert(hDC); assert(c->hDC);
assert(s); assert(s);
ME_LogFontFromStyle(hDC, &lf, s, editor->nZoomNumerator, editor->nZoomDenominator); ME_LogFontFromStyle(c, &lf, s);
for (i=0; i<HFONT_CACHE_SIZE; i++) for (i=0; i<HFONT_CACHE_SIZE; i++)
editor->pFontCache[i].nAge++; c->editor->pFontCache[i].nAge++;
for (i=0, nEmpty=-1, nAge=0; i<HFONT_CACHE_SIZE; i++) for (i=0, nEmpty=-1, nAge=0; i<HFONT_CACHE_SIZE; i++)
{ {
item = &editor->pFontCache[i]; item = &c->editor->pFontCache[i];
if (!item->nRefs) if (!item->nRefs)
{ {
if (item->nAge > nAge) if (item->nAge > nAge)
@ -389,7 +381,7 @@ HFONT ME_SelectStyleFont(ME_TextEditor *editor, HDC hDC, ME_Style *s)
} }
if (i < HFONT_CACHE_SIZE) /* found */ if (i < HFONT_CACHE_SIZE) /* found */
{ {
item = &editor->pFontCache[i]; item = &c->editor->pFontCache[i];
TRACE_(richedit_style)("font reused %d\n", i); TRACE_(richedit_style)("font reused %d\n", i);
s->hFont = item->hFont; s->hFont = item->hFont;
@ -397,7 +389,7 @@ HFONT ME_SelectStyleFont(ME_TextEditor *editor, HDC hDC, ME_Style *s)
} }
else else
{ {
item = &editor->pFontCache[nEmpty]; /* this legal even when nEmpty == -1, as we don't dereference it */ item = &c->editor->pFontCache[nEmpty]; /* this legal even when nEmpty == -1, as we don't dereference it */
assert(nEmpty != -1); /* otherwise we leak cache entries or get too many fonts at once*/ assert(nEmpty != -1); /* otherwise we leak cache entries or get too many fonts at once*/
if (item->hFont) { if (item->hFont) {
@ -412,22 +404,22 @@ HFONT ME_SelectStyleFont(ME_TextEditor *editor, HDC hDC, ME_Style *s)
item->nRefs = 1; item->nRefs = 1;
memcpy(&item->lfSpecs, &lf, sizeof(LOGFONTW)); memcpy(&item->lfSpecs, &lf, sizeof(LOGFONTW));
} }
hOldFont = SelectObject(hDC, s->hFont); hOldFont = SelectObject(c->hDC, s->hFont);
/* should be cached too, maybe ? */ /* should be cached too, maybe ? */
GetTextMetricsW(hDC, &s->tm); GetTextMetricsW(c->hDC, &s->tm);
return hOldFont; return hOldFont;
} }
void ME_UnselectStyleFont(ME_TextEditor *editor, HDC hDC, ME_Style *s, HFONT hOldFont) void ME_UnselectStyleFont(ME_Context *c, ME_Style *s, HFONT hOldFont)
{ {
int i; int i;
assert(hDC); assert(c->hDC);
assert(s); assert(s);
SelectObject(hDC, hOldFont); SelectObject(c->hDC, hOldFont);
for (i=0; i<HFONT_CACHE_SIZE; i++) for (i=0; i<HFONT_CACHE_SIZE; i++)
{ {
ME_FontCacheItem *pItem = &editor->pFontCache[i]; ME_FontCacheItem *pItem = &c->editor->pFontCache[i];
if (pItem->hFont == s->hFont && pItem->nRefs > 0) if (pItem->hFont == s->hFont && pItem->nRefs > 0)
{ {
pItem->nRefs--; pItem->nRefs--;

View File

@ -341,7 +341,6 @@ static void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp);
static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD beginofs) { static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD beginofs) {
ME_DisplayItem *p; ME_DisplayItem *p;
ME_WrapContext wc; ME_WrapContext wc;
int dpi;
int border = 0; int border = 0;
int linespace = 0; int linespace = 0;
@ -351,18 +350,17 @@ static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD begino
} }
ME_PrepareParagraphForWrapping(c, tp); ME_PrepareParagraphForWrapping(c, tp);
dpi = GetDeviceCaps(c->hDC, LOGPIXELSX);
wc.context = c; wc.context = c;
/* wc.para_style = tp->member.para.style; */ /* wc.para_style = tp->member.para.style; */
wc.style = NULL; wc.style = NULL;
wc.nFirstMargin = ME_twips2points(c, tp->member.para.pFmt->dxStartIndent, dpi) + beginofs; wc.nFirstMargin = ME_twips2pointsX(c, tp->member.para.pFmt->dxStartIndent) + beginofs;
wc.nLeftMargin = wc.nFirstMargin + ME_twips2points(c, tp->member.para.pFmt->dxOffset, dpi) + beginofs; wc.nLeftMargin = wc.nFirstMargin + ME_twips2pointsX(c, tp->member.para.pFmt->dxOffset) + beginofs;
wc.nRightMargin = ME_twips2points(c, tp->member.para.pFmt->dxRightIndent, dpi); wc.nRightMargin = ME_twips2pointsX(c, tp->member.para.pFmt->dxRightIndent);
wc.nRow = 0; wc.nRow = 0;
wc.pt.x = 0; wc.pt.x = 0;
wc.pt.y = 0; wc.pt.y = 0;
if (tp->member.para.pFmt->dwMask & PFM_SPACEBEFORE) if (tp->member.para.pFmt->dwMask & PFM_SPACEBEFORE)
wc.pt.y += ME_twips2points(c, tp->member.para.pFmt->dySpaceBefore, dpi); wc.pt.y += ME_twips2pointsY(c, tp->member.para.pFmt->dySpaceBefore);
if (tp->member.para.pFmt->dwMask & PFM_BORDER) if (tp->member.para.pFmt->dwMask & PFM_BORDER)
{ {
border = ME_GetParaBorderWidth(c->editor, tp->member.para.pFmt->wBorders); border = ME_GetParaBorderWidth(c->editor, tp->member.para.pFmt->wBorders);
@ -380,7 +378,7 @@ static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD begino
wc.nAvailWidth = wc.nTotalWidth - wc.nFirstMargin - wc.nRightMargin; wc.nAvailWidth = wc.nTotalWidth - wc.nFirstMargin - wc.nRightMargin;
wc.pRowStart = NULL; wc.pRowStart = NULL;
linespace = ME_GetParaLineSpace(c->editor, &tp->member.para, dpi); linespace = ME_GetParaLineSpace(c, &tp->member.para);
ME_BeginRow(&wc); ME_BeginRow(&wc);
for (p = tp->next; p!=tp->member.para.next_para; ) { for (p = tp->next; p!=tp->member.para.next_para; ) {
@ -396,7 +394,7 @@ static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD begino
if ((tp->member.para.pFmt->dwMask & PFM_BORDER) && (tp->member.para.pFmt->wBorders & 8)) if ((tp->member.para.pFmt->dwMask & PFM_BORDER) && (tp->member.para.pFmt->wBorders & 8))
wc.pt.y += border; wc.pt.y += border;
if (tp->member.para.pFmt->dwMask & PFM_SPACEAFTER) if (tp->member.para.pFmt->dwMask & PFM_SPACEAFTER)
wc.pt.y += ME_twips2points(c, tp->member.para.pFmt->dySpaceAfter, dpi); wc.pt.y += ME_twips2pointsY(c, tp->member.para.pFmt->dySpaceAfter);
tp->member.para.nFlags &= ~MEPF_REWRAP; tp->member.para.nFlags &= ~MEPF_REWRAP;
tp->member.para.nHeight = wc.pt.y; tp->member.para.nHeight = wc.pt.y;