[NTGDI][FREETYPE] Simplify font rendering (#4865)

- Add ftGdiGetRealGlyph and ftGdiGetTextWidth helper functions.
- Optimize font rendering.
CORE-11848
This commit is contained in:
Katayama Hirofumi MZ 2022-11-24 11:51:04 +09:00 committed by GitHub
parent 968b264300
commit a620c6f82e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4241,6 +4241,62 @@ ftGdiGetGlyphOutline(
return needed; return needed;
} }
FT_BitmapGlyph
APIENTRY
ftGdiGetRealGlyph(
FT_Face face,
INT glyph_index,
LONG lfHeight,
FT_Render_Mode RenderMode,
PMATRIX pmxWorldToDevice,
BOOL EmuBold,
BOOL EmuItalic)
{
INT error;
FT_GlyphSlot glyph;
FT_BitmapGlyph realglyph;
if (EmuBold || EmuItalic)
{
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_BITMAP);
}
else
{
realglyph = ftGdiGlyphCacheGet(face, glyph_index, lfHeight,
RenderMode, pmxWorldToDevice);
if (realglyph)
return realglyph;
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
}
if (error)
{
DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index);
return NULL;
}
glyph = face->glyph;
if (EmuBold || EmuItalic)
{
if (EmuBold)
FT_GlyphSlot_Embolden(glyph);
if (EmuItalic)
FT_GlyphSlot_Oblique(glyph);
realglyph = ftGdiGlyphSet(face, glyph, RenderMode);
}
else
{
realglyph = ftGdiGlyphCacheSet(face, glyph_index, lfHeight,
pmxWorldToDevice, glyph, RenderMode);
}
if (!realglyph)
DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index);
return realglyph;
}
BOOL BOOL
FASTCALL FASTCALL
TextIntGetTextExtentPoint(PDC dc, TextIntGetTextExtentPoint(PDC dc,
@ -4255,16 +4311,13 @@ TextIntGetTextExtentPoint(PDC dc,
{ {
PFONTGDI FontGDI; PFONTGDI FontGDI;
FT_Face face; FT_Face face;
FT_GlyphSlot glyph;
FT_BitmapGlyph realglyph; FT_BitmapGlyph realglyph;
INT error, glyph_index, i, previous; INT glyph_index, i, previous;
ULONGLONG TotalWidth64 = 0; ULONGLONG TotalWidth64 = 0;
BOOL use_kerning;
FT_Render_Mode RenderMode; FT_Render_Mode RenderMode;
BOOLEAN Render;
PMATRIX pmxWorldToDevice; PMATRIX pmxWorldToDevice;
LOGFONTW *plf; LOGFONTW *plf;
BOOL EmuBold, EmuItalic; BOOL use_kerning, EmuBold, EmuItalic;
LONG ascender, descender; LONG ascender, descender;
FontGDI = ObjToGDI(TextObj->Font, FONT); FontGDI = ObjToGDI(TextObj->Font, FONT);
@ -4283,8 +4336,7 @@ TextIntGetTextExtentPoint(PDC dc,
EmuBold = EMUBOLD_NEEDED(FontGDI->OriginalWeight, plf->lfWeight); EmuBold = EMUBOLD_NEEDED(FontGDI->OriginalWeight, plf->lfWeight);
EmuItalic = (plf->lfItalic && !FontGDI->OriginalItalic); EmuItalic = (plf->lfItalic && !FontGDI->OriginalItalic);
Render = IntIsFontRenderingEnabled(); if (IntIsFontRenderingEnabled())
if (Render)
RenderMode = IntGetFontRenderMode(plf); RenderMode = IntGetFontRenderMode(plf);
else else
RenderMode = FT_RENDER_MODE_MONO; RenderMode = FT_RENDER_MODE_MONO;
@ -4300,49 +4352,10 @@ TextIntGetTextExtentPoint(PDC dc,
{ {
glyph_index = get_glyph_index_flagged(face, *String, GTEF_INDICES, fl); glyph_index = get_glyph_index_flagged(face, *String, GTEF_INDICES, fl);
if (EmuBold || EmuItalic) realglyph = ftGdiGetRealGlyph(face, glyph_index, plf->lfHeight, RenderMode,
realglyph = NULL; pmxWorldToDevice, EmuBold, EmuItalic);
else if (!realglyph)
realglyph = ftGdiGlyphCacheGet(face, glyph_index, plf->lfHeight, break;
RenderMode, pmxWorldToDevice);
if (EmuBold || EmuItalic || !realglyph)
{
if (EmuItalic)
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_BITMAP);
else
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
if (error)
{
DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index);
break;
}
glyph = face->glyph;
if (EmuBold || EmuItalic)
{
if (EmuBold)
FT_GlyphSlot_Embolden(glyph);
if (EmuItalic)
FT_GlyphSlot_Oblique(glyph);
realglyph = ftGdiGlyphSet(face, glyph, RenderMode);
}
else
{
realglyph = ftGdiGlyphCacheSet(face,
glyph_index,
plf->lfHeight,
pmxWorldToDevice,
glyph,
RenderMode);
}
if (!realglyph)
{
DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index);
break;
}
}
/* Retrieve kerning distance */ /* Retrieve kerning distance */
if (use_kerning && previous && glyph_index) if (use_kerning && previous && glyph_index)
@ -5880,6 +5893,59 @@ ScaleLong(LONG lValue, PFLOATOBJ pef)
return lValue; return lValue;
} }
/* Calculate width of the text. */
BOOL
APIENTRY
ftGdiGetTextWidth(
LONGLONG *pTextWidth64,
LPCWSTR String,
INT Count,
FT_Face face,
LONG lfHeight,
UINT fuOptions,
FT_Render_Mode RenderMode,
PMATRIX pmxWorldToDevice,
BOOL EmuBold,
BOOL EmuItalic)
{
LONGLONG TextLeft64 = 0;
INT glyph_index;
FT_BitmapGlyph realglyph;
BOOL use_kerning = FT_HAS_KERNING(face);
ULONG previous = 0;
FT_Vector delta;
ASSERT_FREETYPE_LOCK_HELD();
while (Count-- > 0)
{
glyph_index = get_glyph_index_flagged(face, *String, ETO_GLYPH_INDEX, fuOptions);
realglyph = ftGdiGetRealGlyph(face, glyph_index, lfHeight, RenderMode,
pmxWorldToDevice, EmuBold, EmuItalic);
if (!realglyph)
return FALSE;
/* Retrieve kerning distance */
if (use_kerning && previous && glyph_index)
{
FT_Get_Kerning(face, previous, glyph_index, 0, &delta);
TextLeft64 += delta.x;
}
TextLeft64 += realglyph->root.advance.x >> 10;
if (EmuBold || EmuItalic)
FT_Done_Glyph((FT_Glyph)realglyph);
previous = glyph_index;
String++;
}
*pTextWidth64 = TextLeft64;
return TRUE;
}
BOOL BOOL
APIENTRY APIENTRY
IntExtTextOutW( IntExtTextOutW(
@ -5900,37 +5966,30 @@ IntExtTextOutW(
*/ */
PDC_ATTR pdcattr; PDC_ATTR pdcattr;
SURFOBJ *SurfObj; SURFOBJ *SurfObj, *SourceGlyphSurf;
SURFACE *psurf = NULL; SURFACE *psurf;
int error, glyph_index, i; INT glyph_index, i, yoff;
FT_Face face; FT_Face face;
FT_GlyphSlot glyph;
FT_BitmapGlyph realglyph; FT_BitmapGlyph realglyph;
LONGLONG TextLeft, RealXStart; LONGLONG TextLeft64, RealXStart64, TextWidth64;
ULONG TextTop, previous, BackgroundLeft; ULONG TextTop, previous;
FT_Bool use_kerning;
RECTL DestRect, MaskRect; RECTL DestRect, MaskRect;
POINTL SourcePoint, BrushOrigin; POINTL SourcePoint, BrushOrigin;
HBITMAP HSourceGlyph; HBITMAP HSourceGlyph;
SURFOBJ *SourceGlyphSurf;
SIZEL bitSize; SIZEL bitSize;
INT yoff;
FONTOBJ *FontObj; FONTOBJ *FontObj;
PFONTGDI FontGDI; PFONTGDI FontGDI;
PTEXTOBJ TextObj = NULL; PTEXTOBJ TextObj;
EXLATEOBJ exloRGB2Dst, exloDst2RGB; EXLATEOBJ exloRGB2Dst, exloDst2RGB;
FT_Render_Mode RenderMode; FT_Render_Mode RenderMode;
BOOLEAN Render;
POINT Start; POINT Start;
BOOL DoBreak = FALSE;
USHORT DxShift; USHORT DxShift;
PMATRIX pmxWorldToDevice; PMATRIX pmxWorldToDevice;
LONG fixAscender, fixDescender; LONG lfHeight, fixAscender, fixDescender;
FLOATOBJ Scale; FLOATOBJ Scale;
LOGFONTW *plf; LOGFONTW *plf;
BOOL EmuBold, EmuItalic; BOOL use_kerning, EmuBold, EmuItalic, bResult, DoBreak;
int thickness; FT_Vector delta;
BOOL bResult;
/* Check if String is valid */ /* Check if String is valid */
if ((Count > 0xFFFF) || (Count > 0 && String == NULL)) if ((Count > 0xFFFF) || (Count > 0 && String == NULL))
@ -5939,8 +5998,6 @@ IntExtTextOutW(
return FALSE; return FALSE;
} }
Render = IntIsFontRenderingEnabled();
if (PATH_IsPathOpen(dc->dclevel)) if (PATH_IsPathOpen(dc->dclevel))
{ {
bResult = PATH_ExtTextOut(dc, bResult = PATH_ExtTextOut(dc,
@ -5963,13 +6020,12 @@ IntExtTextOutW(
goto Cleanup; goto Cleanup;
} }
pdcattr = dc->pdcattr;
if (lprc && (fuOptions & (ETO_OPAQUE | ETO_CLIPPED))) if (lprc && (fuOptions & (ETO_OPAQUE | ETO_CLIPPED)))
{ {
IntLPtoDP(dc, (POINT *)lprc, 2); IntLPtoDP(dc, (POINT *)lprc, 2);
} }
pdcattr = dc->pdcattr;
if (pdcattr->flTextAlign & TA_UPDATECP) if (pdcattr->flTextAlign & TA_UPDATECP)
{ {
Start.x = pdcattr->ptlCurrent.x; Start.x = pdcattr->ptlCurrent.x;
@ -5980,7 +6036,7 @@ IntExtTextOutW(
} }
IntLPtoDP(dc, &Start, 1); IntLPtoDP(dc, &Start, 1);
RealXStart = ((LONGLONG)Start.x + dc->ptlDCOrig.x) << 6; RealXStart64 = ((LONGLONG)Start.x + dc->ptlDCOrig.x) << 6;
YStart = Start.y + dc->ptlDCOrig.y; YStart = Start.y + dc->ptlDCOrig.y;
SourcePoint.x = 0; SourcePoint.x = 0;
@ -5990,12 +6046,12 @@ IntExtTextOutW(
BrushOrigin.x = 0; BrushOrigin.x = 0;
BrushOrigin.y = 0; BrushOrigin.y = 0;
if ((fuOptions & ETO_OPAQUE) && lprc) psurf = dc->dclevel.pSurface;
SurfObj = &psurf->SurfObj;
if (lprc && (fuOptions & ETO_OPAQUE))
{ {
DestRect.left = lprc->left; RtlCopyMemory(&DestRect, lprc, sizeof(DestRect));
DestRect.top = lprc->top;
DestRect.right = lprc->right;
DestRect.bottom = lprc->bottom;
DestRect.left += dc->ptlDCOrig.x; DestRect.left += dc->ptlDCOrig.x;
DestRect.top += dc->ptlDCOrig.y; DestRect.top += dc->ptlDCOrig.y;
@ -6009,12 +6065,12 @@ IntExtTextOutW(
if (pdcattr->ulDirty_ & DIRTY_BACKGROUND) if (pdcattr->ulDirty_ & DIRTY_BACKGROUND)
DC_vUpdateBackgroundBrush(dc); DC_vUpdateBackgroundBrush(dc);
if (dc->dctype == DCTYPE_DIRECT) if (dc->dctype == DCTYPE_DIRECT)
MouseSafetyOnDrawStart(dc->ppdev, DestRect.left, DestRect.top, DestRect.right, DestRect.bottom); MouseSafetyOnDrawStart(dc->ppdev, DestRect.left, DestRect.top, DestRect.right, DestRect.bottom);
psurf = dc->dclevel.pSurface;
IntEngBitBlt( IntEngBitBlt(
&psurf->SurfObj, SurfObj,
NULL, NULL,
NULL, NULL,
(CLIPOBJ *)&dc->co, (CLIPOBJ *)&dc->co,
@ -6055,10 +6111,11 @@ IntExtTextOutW(
face = FontGDI->SharedFace->Face; face = FontGDI->SharedFace->Face;
plf = &TextObj->logfont.elfEnumLogfontEx.elfLogFont; plf = &TextObj->logfont.elfEnumLogfontEx.elfLogFont;
lfHeight = plf->lfHeight;
EmuBold = EMUBOLD_NEEDED(FontGDI->OriginalWeight, plf->lfWeight); EmuBold = EMUBOLD_NEEDED(FontGDI->OriginalWeight, plf->lfWeight);
EmuItalic = (plf->lfItalic && !FontGDI->OriginalItalic); EmuItalic = (plf->lfItalic && !FontGDI->OriginalItalic);
if (Render) if (IntIsFontRenderingEnabled())
RenderMode = IntGetFontRenderMode(plf); RenderMode = IntGetFontRenderMode(plf);
else else
RenderMode = FT_RENDER_MODE_MONO; RenderMode = FT_RENDER_MODE_MONO;
@ -6071,7 +6128,7 @@ IntExtTextOutW(
} }
/* NOTE: Don't trust face->size->metrics.ascender and descender values. */ /* NOTE: Don't trust face->size->metrics.ascender and descender values. */
if (dc->pdcattr->iGraphicsMode == GM_ADVANCED) if (pdcattr->iGraphicsMode == GM_ADVANCED)
{ {
pmxWorldToDevice = DC_pmxWorldToDevice(dc); pmxWorldToDevice = DC_pmxWorldToDevice(dc);
FtSetCoordinateTransform(face, pmxWorldToDevice); FtSetCoordinateTransform(face, pmxWorldToDevice);
@ -6101,244 +6158,64 @@ IntExtTextOutW(
#undef VALIGN_MASK #undef VALIGN_MASK
use_kerning = FT_HAS_KERNING(face); use_kerning = FT_HAS_KERNING(face);
previous = 0;
/* /* Calculate the text width if necessary */
* Process the horizontal alignment and modify XStart accordingly. if ((fuOptions & ETO_OPAQUE) || (pdcattr->flTextAlign & (TA_CENTER | TA_RIGHT)))
*/
DxShift = (fuOptions & ETO_PDY) ? 1 : 0;
if (pdcattr->flTextAlign & (TA_RIGHT | TA_CENTER))
{ {
ULONGLONG TextWidth = 0; if (!ftGdiGetTextWidth(&TextWidth64,
LPCWSTR TempText = String; String, Count,
int iStart; face,
lfHeight,
/* fuOptions,
* Calculate width of the text. RenderMode,
*/ pmxWorldToDevice,
EmuBold, EmuItalic))
if (NULL != Dx)
{ {
iStart = Count < 2 ? 0 : Count - 2; IntUnLockFreeType();
TextWidth = Count < 2 ? 0 : (Dx[(Count-2)<<DxShift] << 6); bResult = FALSE;
} goto Cleanup;
else
{
iStart = 0;
}
TempText = String + iStart;
for (i = iStart; i < Count; i++)
{
glyph_index = get_glyph_index_flagged(face, *TempText, ETO_GLYPH_INDEX, fuOptions);
if (EmuBold || EmuItalic)
realglyph = NULL;
else
realglyph = ftGdiGlyphCacheGet(face, glyph_index, plf->lfHeight,
RenderMode, pmxWorldToDevice);
if (!realglyph)
{
if (EmuItalic)
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_BITMAP);
else
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
if (error)
{
DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index);
}
glyph = face->glyph;
if (EmuBold || EmuItalic)
{
if (EmuBold)
FT_GlyphSlot_Embolden(glyph);
if (EmuItalic)
FT_GlyphSlot_Oblique(glyph);
realglyph = ftGdiGlyphSet(face, glyph, RenderMode);
}
else
{
realglyph = ftGdiGlyphCacheSet(face,
glyph_index,
plf->lfHeight,
pmxWorldToDevice,
glyph,
RenderMode);
}
if (!realglyph)
{
DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index);
IntUnLockFreeType();
bResult = FALSE;
goto Cleanup;
}
}
/* Retrieve kerning distance */
if (use_kerning && previous && glyph_index)
{
FT_Vector delta;
FT_Get_Kerning(face, previous, glyph_index, 0, &delta);
TextWidth += delta.x;
}
TextWidth += realglyph->root.advance.x >> 10;
if (EmuBold || EmuItalic)
{
FT_Done_Glyph((FT_Glyph)realglyph);
realglyph = NULL;
}
previous = glyph_index;
TempText++;
} }
previous = 0; /* Adjust the horizontal position by horizontal alignment */
if ((pdcattr->flTextAlign & TA_CENTER) == TA_CENTER) if ((pdcattr->flTextAlign & TA_CENTER) == TA_CENTER)
RealXStart64 -= TextWidth64 / 2;
else if ((pdcattr->flTextAlign & TA_RIGHT) == TA_RIGHT)
RealXStart64 -= TextWidth64;
/* Fill background */
if (fuOptions & ETO_OPAQUE)
{ {
RealXStart -= TextWidth / 2; DestRect.left = (RealXStart64 + 32) >> 6;
} DestRect.right = (RealXStart64 + TextWidth64 + 32) >> 6;
else DestRect.top = YStart;
{ DestRect.bottom = YStart + ((fixAscender + fixDescender) >> 6);
RealXStart -= TextWidth;
}
}
psurf = dc->dclevel.pSurface; if (dc->fs & (DC_ACCUM_APP | DC_ACCUM_WMGR))
SurfObj = &psurf->SurfObj ; IntUpdateBoundsRect(dc, &DestRect);
if ((fuOptions & ETO_OPAQUE) && (dc->pdcattr->ulDirty_ & DIRTY_BACKGROUND)) if (pdcattr->ulDirty_ & DIRTY_BACKGROUND)
DC_vUpdateBackgroundBrush(dc) ; DC_vUpdateBackgroundBrush(dc);
if(dc->pdcattr->ulDirty_ & DIRTY_TEXT) if (dc->dctype == DCTYPE_DIRECT)
DC_vUpdateTextBrush(dc) ;
if (!face->units_per_EM)
{
thickness = 1;
}
else
{
thickness = face->underline_thickness *
face->size->metrics.y_ppem / face->units_per_EM;
if (thickness <= 0)
thickness = 1;
}
if ((fuOptions & ETO_OPAQUE) && plf->lfItalic)
{
/* Draw background */
TextLeft = RealXStart;
TextTop = YStart;
BackgroundLeft = (RealXStart + 32) >> 6;
for (i = 0; i < Count; ++i)
{
glyph_index = get_glyph_index_flagged(face, String[i], ETO_GLYPH_INDEX, fuOptions);
if (EmuItalic)
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_BITMAP);
else
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
if (error)
{ {
DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index); MouseSafetyOnDrawStart(dc->ppdev, DestRect.left, DestRect.top,
IntUnLockFreeType(); DestRect.right, DestRect.bottom);
bResult = FALSE;
goto Cleanup;
} }
glyph = face->glyph; IntEngBitBlt(SurfObj,
if (EmuBold) NULL,
FT_GlyphSlot_Embolden(glyph); NULL,
if (EmuItalic) (CLIPOBJ *)&dc->co,
FT_GlyphSlot_Oblique(glyph); NULL,
realglyph = ftGdiGlyphSet(face, glyph, RenderMode); &DestRect,
if (!realglyph) &SourcePoint,
{ &SourcePoint,
DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index); &dc->eboBackground.BrushObject,
IntUnLockFreeType(); &BrushOrigin,
bResult = FALSE; ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY));
goto Cleanup;
}
/* retrieve kerning distance and move pen position */ if (dc->dctype == DCTYPE_DIRECT)
if (use_kerning && previous && glyph_index && NULL == Dx) MouseSafetyOnDrawEnd(dc->ppdev);
{
FT_Vector delta;
FT_Get_Kerning(face, previous, glyph_index, 0, &delta);
TextLeft += delta.x;
}
DPRINT("TextLeft: %I64d\n", TextLeft);
DPRINT("TextTop: %lu\n", TextTop);
DPRINT("Advance: %d\n", realglyph->root.advance.x);
DestRect.left = BackgroundLeft;
DestRect.right = (TextLeft + (realglyph->root.advance.x >> 10) + 32) >> 6;
DestRect.top = TextTop + yoff - ((fixAscender + 32) >> 6);
DestRect.bottom = DestRect.top + ((fixAscender + fixDescender) >> 6);
MouseSafetyOnDrawStart(dc->ppdev, DestRect.left, DestRect.top, DestRect.right, DestRect.bottom);
if (dc->fs & (DC_ACCUM_APP|DC_ACCUM_WMGR))
{
IntUpdateBoundsRect(dc, &DestRect);
}
IntEngBitBlt(
&psurf->SurfObj,
NULL,
NULL,
(CLIPOBJ *)&dc->co,
NULL,
&DestRect,
&SourcePoint,
&SourcePoint,
&dc->eboBackground.BrushObject,
&BrushOrigin,
ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY));
MouseSafetyOnDrawEnd(dc->ppdev);
BackgroundLeft = DestRect.right;
DestRect.left = ((TextLeft + 32) >> 6) + realglyph->left;
DestRect.right = DestRect.left + realglyph->bitmap.width;
DestRect.top = TextTop + yoff - realglyph->top;
DestRect.bottom = DestRect.top + realglyph->bitmap.rows;
bitSize.cx = realglyph->bitmap.width;
bitSize.cy = realglyph->bitmap.rows;
MaskRect.right = realglyph->bitmap.width;
MaskRect.bottom = realglyph->bitmap.rows;
if (NULL == Dx)
{
TextLeft += realglyph->root.advance.x >> 10;
DPRINT("New TextLeft: %I64d\n", TextLeft);
}
else
{
// FIXME this should probably be a matrix transform with TextTop as well.
Scale = pdcattr->mxWorldToDevice.efM11;
if (FLOATOBJ_Equal0(&Scale))
FLOATOBJ_Set1(&Scale);
/* do the shift before multiplying to preserve precision */
FLOATOBJ_MulLong(&Scale, Dx[i<<DxShift] << 6);
TextLeft += FLOATOBJ_GetLong(&Scale);
DPRINT("New TextLeft2: %I64d\n", TextLeft);
}
if (DxShift)
{
TextTop -= Dx[2 * i + 1] << 6;
}
previous = glyph_index;
if (EmuBold || EmuItalic)
{
FT_Done_Glyph((FT_Glyph)realglyph);
realglyph = NULL;
}
} }
} }
@ -6348,114 +6225,51 @@ IntExtTextOutW(
/* Assume success */ /* Assume success */
bResult = TRUE; bResult = TRUE;
if (pdcattr->ulDirty_ & DIRTY_TEXT)
DC_vUpdateTextBrush(dc);
/* /*
* The main rendering loop. * The main rendering loop.
*/ */
TextLeft = RealXStart; TextLeft64 = RealXStart64;
TextTop = YStart; TextTop = YStart;
BackgroundLeft = (RealXStart + 32) >> 6; DxShift = (fuOptions & ETO_PDY) ? 1 : 0;
previous = 0;
DoBreak = FALSE;
for (i = 0; i < Count; ++i) for (i = 0; i < Count; ++i)
{ {
glyph_index = get_glyph_index_flagged(face, String[i], ETO_GLYPH_INDEX, fuOptions); glyph_index = get_glyph_index_flagged(face, *String++, ETO_GLYPH_INDEX, fuOptions);
if (EmuBold || EmuItalic) realglyph = ftGdiGetRealGlyph(face, glyph_index, lfHeight, RenderMode,
realglyph = NULL; pmxWorldToDevice, EmuBold, EmuItalic);
else
realglyph = ftGdiGlyphCacheGet(face, glyph_index, plf->lfHeight,
RenderMode, pmxWorldToDevice);
if (!realglyph) if (!realglyph)
{ {
if (EmuItalic) bResult = FALSE;
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_BITMAP); break;
else
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
if (error)
{
DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index);
bResult = FALSE;
break;
}
glyph = face->glyph;
if (EmuBold || EmuItalic)
{
if (EmuBold)
FT_GlyphSlot_Embolden(glyph);
if (EmuItalic)
FT_GlyphSlot_Oblique(glyph);
realglyph = ftGdiGlyphSet(face, glyph, RenderMode);
}
else
{
realglyph = ftGdiGlyphCacheSet(face,
glyph_index,
plf->lfHeight,
pmxWorldToDevice,
glyph,
RenderMode);
}
if (!realglyph)
{
DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index);
bResult = FALSE;
break;
}
} }
/* retrieve kerning distance and move pen position */ /* retrieve kerning distance and move pen position */
if (use_kerning && previous && glyph_index && NULL == Dx) if (use_kerning && previous && glyph_index && NULL == Dx)
{ {
FT_Vector delta;
FT_Get_Kerning(face, previous, glyph_index, 0, &delta); FT_Get_Kerning(face, previous, glyph_index, 0, &delta);
TextLeft += delta.x; TextLeft64 += delta.x;
} }
DPRINT("TextLeft: %I64d\n", TextLeft);
DPRINT("TextLeft64: %I64d\n", TextLeft64);
DPRINT("TextTop: %lu\n", TextTop); DPRINT("TextTop: %lu\n", TextTop);
DPRINT("Advance: %d\n", realglyph->root.advance.x); DPRINT("Advance: %d\n", realglyph->root.advance.x);
if ((fuOptions & ETO_OPAQUE) && !plf->lfItalic)
{
DestRect.left = BackgroundLeft;
DestRect.right = (TextLeft + (realglyph->root.advance.x >> 10) + 32) >> 6;
DestRect.top = TextTop + yoff - ((fixAscender + 32) >> 6);
DestRect.bottom = DestRect.top + ((fixAscender + fixDescender) >> 6);
if (dc->dctype == DCTYPE_DIRECT)
MouseSafetyOnDrawStart(dc->ppdev, DestRect.left, DestRect.top, DestRect.right, DestRect.bottom);
if (dc->fs & (DC_ACCUM_APP|DC_ACCUM_WMGR))
{
IntUpdateBoundsRect(dc, &DestRect);
}
IntEngBitBlt(
&psurf->SurfObj,
NULL,
NULL,
(CLIPOBJ *)&dc->co,
NULL,
&DestRect,
&SourcePoint,
&SourcePoint,
&dc->eboBackground.BrushObject,
&BrushOrigin,
ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY));
if (dc->dctype == DCTYPE_DIRECT)
MouseSafetyOnDrawEnd(dc->ppdev);
BackgroundLeft = DestRect.right;
}
DestRect.left = ((TextLeft + 32) >> 6) + realglyph->left;
DestRect.right = DestRect.left + realglyph->bitmap.width;
DestRect.top = TextTop + yoff - realglyph->top;
DestRect.bottom = DestRect.top + realglyph->bitmap.rows;
bitSize.cx = realglyph->bitmap.width; bitSize.cx = realglyph->bitmap.width;
bitSize.cy = realglyph->bitmap.rows; bitSize.cy = realglyph->bitmap.rows;
MaskRect.right = realglyph->bitmap.width; MaskRect.right = realglyph->bitmap.width;
MaskRect.bottom = realglyph->bitmap.rows; MaskRect.bottom = realglyph->bitmap.rows;
DestRect.left = ((TextLeft64 + 32) >> 6) + realglyph->left;
DestRect.right = DestRect.left + bitSize.cx;
DestRect.top = TextTop + yoff - realglyph->top;
DestRect.bottom = DestRect.top + bitSize.cy;
/* Check if the bitmap has any pixels */ /* Check if the bitmap has any pixels */
if ((bitSize.cx != 0) && (bitSize.cy != 0)) if ((bitSize.cx != 0) && (bitSize.cy != 0))
{ {
@ -6470,8 +6284,9 @@ IntExtTextOutW(
if ( !HSourceGlyph ) if ( !HSourceGlyph )
{ {
DPRINT1("WARNING: EngCreateBitmap() failed!\n"); DPRINT1("WARNING: EngCreateBitmap() failed!\n");
// FT_Done_Glyph(realglyph);
bResult = FALSE; bResult = FALSE;
if (EmuBold || EmuItalic)
FT_Done_Glyph((FT_Glyph)realglyph);
break; break;
} }
SourceGlyphSurf = EngLockSurface((HSURF)HSourceGlyph); SourceGlyphSurf = EngLockSurface((HSURF)HSourceGlyph);
@ -6480,6 +6295,8 @@ IntExtTextOutW(
EngDeleteSurface((HSURF)HSourceGlyph); EngDeleteSurface((HSURF)HSourceGlyph);
DPRINT1("WARNING: EngLockSurface() failed!\n"); DPRINT1("WARNING: EngLockSurface() failed!\n");
bResult = FALSE; bResult = FALSE;
if (EmuBold || EmuItalic)
FT_Done_Glyph((FT_Glyph)realglyph);
break; break;
} }
@ -6487,19 +6304,21 @@ IntExtTextOutW(
* Use the font data as a mask to paint onto the DCs surface using a * Use the font data as a mask to paint onto the DCs surface using a
* brush. * brush.
*/ */
if (lprc && (fuOptions & ETO_CLIPPED) && if (lprc && (fuOptions & ETO_CLIPPED))
DestRect.right >= lprc->right + dc->ptlDCOrig.x)
{ {
// We do the check '>=' instead of '>' to possibly save an iteration // We do the check '>=' instead of '>' to possibly save an iteration
// through this loop, since it's breaking after the drawing is done, // through this loop, since it's breaking after the drawing is done,
// and x is always incremented. // and x is always incremented.
DestRect.right = lprc->right + dc->ptlDCOrig.x; if (DestRect.right >= lprc->right + dc->ptlDCOrig.x)
DoBreak = TRUE; {
} DestRect.right = lprc->right + dc->ptlDCOrig.x;
if (lprc && (fuOptions & ETO_CLIPPED) && DoBreak = TRUE;
DestRect.bottom >= lprc->bottom + dc->ptlDCOrig.y) }
{
DestRect.bottom = lprc->bottom + dc->ptlDCOrig.y; if (DestRect.bottom >= lprc->bottom + dc->ptlDCOrig.y)
{
DestRect.bottom = lprc->bottom + dc->ptlDCOrig.y;
}
} }
if (dc->dctype == DCTYPE_DIRECT) if (dc->dctype == DCTYPE_DIRECT)
@ -6528,55 +6347,15 @@ IntExtTextOutW(
if (DoBreak) if (DoBreak)
{ {
if (EmuBold || EmuItalic)
FT_Done_Glyph((FT_Glyph)realglyph);
break; break;
} }
if (plf->lfUnderline)
{
int i, position;
if (!face->units_per_EM)
{
position = 0;
}
else
{
position = face->underline_position *
face->size->metrics.y_ppem / face->units_per_EM;
}
for (i = -thickness / 2; i < -thickness / 2 + thickness; ++i)
{
EngLineTo(SurfObj,
(CLIPOBJ *)&dc->co,
&dc->eboText.BrushObject,
(TextLeft >> 6),
TextTop + yoff - position + i,
((TextLeft + (realglyph->root.advance.x >> 10)) >> 6),
TextTop + yoff - position + i,
NULL,
ROP2_TO_MIX(R2_COPYPEN));
}
}
if (plf->lfStrikeOut)
{
int i;
for (i = -thickness / 2; i < -thickness / 2 + thickness; ++i)
{
EngLineTo(SurfObj,
(CLIPOBJ *)&dc->co,
&dc->eboText.BrushObject,
(TextLeft >> 6),
TextTop + yoff - (fixAscender >> 6) / 3 + i,
((TextLeft + (realglyph->root.advance.x >> 10)) >> 6),
TextTop + yoff - (fixAscender >> 6) / 3 + i,
NULL,
ROP2_TO_MIX(R2_COPYPEN));
}
}
if (NULL == Dx) if (NULL == Dx)
{ {
TextLeft += realglyph->root.advance.x >> 10; TextLeft64 += realglyph->root.advance.x >> 10;
DPRINT("New TextLeft: %I64d\n", TextLeft); DPRINT("New TextLeft64: %I64d\n", TextLeft64);
} }
else else
{ {
@ -6587,8 +6366,8 @@ IntExtTextOutW(
/* do the shift before multiplying to preserve precision */ /* do the shift before multiplying to preserve precision */
FLOATOBJ_MulLong(&Scale, Dx[i<<DxShift] << 6); FLOATOBJ_MulLong(&Scale, Dx[i<<DxShift] << 6);
TextLeft += FLOATOBJ_GetLong(&Scale); TextLeft64 += FLOATOBJ_GetLong(&Scale);
DPRINT("New TextLeft2: %I64d\n", TextLeft); DPRINT("New TextLeft64 2: %I64d\n", TextLeft64);
} }
if (DxShift) if (DxShift)
@ -6601,12 +6380,63 @@ IntExtTextOutW(
if (EmuBold || EmuItalic) if (EmuBold || EmuItalic)
{ {
FT_Done_Glyph((FT_Glyph)realglyph); FT_Done_Glyph((FT_Glyph)realglyph);
realglyph = NULL;
} }
} }
if (pdcattr->flTextAlign & TA_UPDATECP) { if (pdcattr->flTextAlign & TA_UPDATECP)
pdcattr->ptlCurrent.x = DestRect.right - dc->ptlDCOrig.x; pdcattr->ptlCurrent.x = DestRect.right - dc->ptlDCOrig.x;
if (plf->lfUnderline || plf->lfStrikeOut) /* Underline or strike-out? */
{
/* Calculate the position and the thickness */
INT i, underline_position, thickness;
if (!face->units_per_EM)
{
underline_position = 0;
thickness = 1;
}
else
{
underline_position =
face->underline_position * face->size->metrics.y_ppem / face->units_per_EM;
thickness =
face->underline_thickness * face->size->metrics.y_ppem / face->units_per_EM;
if (thickness <= 0)
thickness = 1;
}
if (plf->lfUnderline) /* Draw underline */
{
for (i = -thickness / 2; i < -thickness / 2 + thickness; ++i)
{
EngLineTo(SurfObj,
(CLIPOBJ *)&dc->co,
&dc->eboText.BrushObject,
(RealXStart64 + 32) >> 6,
TextTop + yoff - underline_position + i,
(TextLeft64 + 32) >> 6,
TextTop + yoff - underline_position + i,
NULL,
ROP2_TO_MIX(R2_COPYPEN));
}
}
if (plf->lfStrikeOut) /* Draw strike-out */
{
for (i = -thickness / 2; i < -thickness / 2 + thickness; ++i)
{
EngLineTo(SurfObj,
(CLIPOBJ *)&dc->co,
&dc->eboText.BrushObject,
(RealXStart64 + 32) >> 6,
TextTop + yoff - (fixAscender >> 6) / 3 + i,
(TextLeft64 + 32) >> 6,
TextTop + yoff - (fixAscender >> 6) / 3 + i,
NULL,
ROP2_TO_MIX(R2_COPYPEN));
}
}
} }
IntUnLockFreeType(); IntUnLockFreeType();
@ -6615,7 +6445,6 @@ IntExtTextOutW(
EXLATEOBJ_vCleanup(&exloDst2RGB); EXLATEOBJ_vCleanup(&exloDst2RGB);
Cleanup: Cleanup:
DC_vFinishBlit(dc, NULL); DC_vFinishBlit(dc, NULL);
if (TextObj != NULL) if (TextObj != NULL)