If the buffer passed to GetOutlineTextMetrics isn't big enough then

Windows fills it upto the supplied size rather than returning an
error.
This commit is contained in:
Huw Davies 2003-11-11 20:39:54 +00:00 committed by Alexandre Julliard
parent bec6cfe0d0
commit 39f604b04f
1 changed files with 105 additions and 86 deletions

View File

@ -324,7 +324,7 @@ HFONT WINAPI CreateFontIndirectW( const LOGFONTW *plf )
memcpy( &fontPtr->logfont, plf, sizeof(LOGFONTW) ); memcpy( &fontPtr->logfont, plf, sizeof(LOGFONTW) );
TRACE("(%ld %ld %ld %ld %x %d %x %d %d) %s %s %s => %p\n", TRACE("(%ld %ld %ld %ld %x %d %x %d %d) %s %s %s %s => %p\n",
plf->lfHeight, plf->lfWidth, plf->lfHeight, plf->lfWidth,
plf->lfEscapement, plf->lfOrientation, plf->lfEscapement, plf->lfOrientation,
plf->lfPitchAndFamily, plf->lfPitchAndFamily,
@ -332,7 +332,8 @@ HFONT WINAPI CreateFontIndirectW( const LOGFONTW *plf )
plf->lfQuality, plf->lfCharSet, plf->lfQuality, plf->lfCharSet,
debugstr_w(plf->lfFaceName), debugstr_w(plf->lfFaceName),
plf->lfWeight > 400 ? "Bold" : "", plf->lfWeight > 400 ? "Bold" : "",
plf->lfItalic ? "Italic" : "", hFont); plf->lfItalic ? "Italic" : "",
plf->lfUnderline ? "Underline" : "", hFont);
if (plf->lfEscapement != plf->lfOrientation) { if (plf->lfEscapement != plf->lfOrientation) {
/* this should really depend on whether GM_ADVANCED is set */ /* this should really depend on whether GM_ADVANCED is set */
@ -1229,6 +1230,9 @@ UINT16 WINAPI GetOutlineTextMetrics16(
* GetOutlineTextMetricsA (GDI32.@) * GetOutlineTextMetricsA (GDI32.@)
* Gets metrics for TrueType fonts. * Gets metrics for TrueType fonts.
* *
* NOTES
* If the supplied buffer isn't big enough Windows partially fills it up to
* its given length and returns that length.
* *
* RETURNS * RETURNS
* Success: Non-zero or size of required buffer * Success: Non-zero or size of required buffer
@ -1242,14 +1246,14 @@ UINT WINAPI GetOutlineTextMetricsA(
char buf[512], *ptr; char buf[512], *ptr;
UINT ret, needed; UINT ret, needed;
OUTLINETEXTMETRICW *lpOTMW = (OUTLINETEXTMETRICW *)buf; OUTLINETEXTMETRICW *lpOTMW = (OUTLINETEXTMETRICW *)buf;
OUTLINETEXTMETRICA *output = lpOTM;
INT left, len; INT left, len;
if((ret = GetOutlineTextMetricsW(hdc, sizeof(buf), lpOTMW)) == 0) { if((ret = GetOutlineTextMetricsW(hdc, 0, NULL)) == 0)
if((ret = GetOutlineTextMetricsW(hdc, 0, NULL)) == 0) return 0;
return 0; if(ret > sizeof(buf))
lpOTMW = HeapAlloc(GetProcessHeap(), 0, ret); lpOTMW = HeapAlloc(GetProcessHeap(), 0, ret);
GetOutlineTextMetricsW(hdc, ret, lpOTMW); GetOutlineTextMetricsW(hdc, ret, lpOTMW);
}
needed = sizeof(OUTLINETEXTMETRICA); needed = sizeof(OUTLINETEXTMETRICA);
if(lpOTMW->otmpFamilyName) if(lpOTMW->otmpFamilyName)
@ -1274,87 +1278,91 @@ UINT WINAPI GetOutlineTextMetricsA(
goto end; goto end;
} }
if(needed > cbData) { TRACE("needed = %d\n", needed);
ret = 0; if(needed > cbData)
goto end; /* Since the supplied buffer isn't big enough, we'll alloc one
} that is and memcpy the first cbData bytes into the lpOTM at
the end. */
output = HeapAlloc(GetProcessHeap(), 0, needed);
ret = output->otmSize = min(needed, cbData);
FONT_TextMetricWToA( &lpOTMW->otmTextMetrics, &output->otmTextMetrics );
output->otmFiller = 0;
output->otmPanoseNumber = lpOTMW->otmPanoseNumber;
output->otmfsSelection = lpOTMW->otmfsSelection;
output->otmfsType = lpOTMW->otmfsType;
output->otmsCharSlopeRise = lpOTMW->otmsCharSlopeRise;
output->otmsCharSlopeRun = lpOTMW->otmsCharSlopeRun;
output->otmItalicAngle = lpOTMW->otmItalicAngle;
output->otmEMSquare = lpOTMW->otmEMSquare;
output->otmAscent = lpOTMW->otmAscent;
output->otmDescent = lpOTMW->otmDescent;
output->otmLineGap = lpOTMW->otmLineGap;
output->otmsCapEmHeight = lpOTMW->otmsCapEmHeight;
output->otmsXHeight = lpOTMW->otmsXHeight;
output->otmrcFontBox = lpOTMW->otmrcFontBox;
output->otmMacAscent = lpOTMW->otmMacAscent;
output->otmMacDescent = lpOTMW->otmMacDescent;
output->otmMacLineGap = lpOTMW->otmMacLineGap;
output->otmusMinimumPPEM = lpOTMW->otmusMinimumPPEM;
output->otmptSubscriptSize = lpOTMW->otmptSubscriptSize;
output->otmptSubscriptOffset = lpOTMW->otmptSubscriptOffset;
output->otmptSuperscriptSize = lpOTMW->otmptSuperscriptSize;
output->otmptSuperscriptOffset = lpOTMW->otmptSuperscriptOffset;
output->otmsStrikeoutSize = lpOTMW->otmsStrikeoutSize;
output->otmsStrikeoutPosition = lpOTMW->otmsStrikeoutPosition;
output->otmsUnderscoreSize = lpOTMW->otmsUnderscoreSize;
output->otmsUnderscorePosition = lpOTMW->otmsUnderscorePosition;
lpOTM->otmSize = needed; ptr = (char*)(output + 1);
FONT_TextMetricWToA( &lpOTMW->otmTextMetrics, &lpOTM->otmTextMetrics ); left = needed - sizeof(*output);
lpOTM->otmFiller = 0;
lpOTM->otmPanoseNumber = lpOTMW->otmPanoseNumber;
lpOTM->otmfsSelection = lpOTMW->otmfsSelection;
lpOTM->otmfsType = lpOTMW->otmfsType;
lpOTM->otmsCharSlopeRise = lpOTMW->otmsCharSlopeRise;
lpOTM->otmsCharSlopeRun = lpOTMW->otmsCharSlopeRun;
lpOTM->otmItalicAngle = lpOTMW->otmItalicAngle;
lpOTM->otmEMSquare = lpOTMW->otmEMSquare;
lpOTM->otmAscent = lpOTMW->otmAscent;
lpOTM->otmDescent = lpOTMW->otmDescent;
lpOTM->otmLineGap = lpOTMW->otmLineGap;
lpOTM->otmsCapEmHeight = lpOTMW->otmsCapEmHeight;
lpOTM->otmsXHeight = lpOTMW->otmsXHeight;
lpOTM->otmrcFontBox = lpOTMW->otmrcFontBox;
lpOTM->otmMacAscent = lpOTMW->otmMacAscent;
lpOTM->otmMacDescent = lpOTMW->otmMacDescent;
lpOTM->otmMacLineGap = lpOTMW->otmMacLineGap;
lpOTM->otmusMinimumPPEM = lpOTMW->otmusMinimumPPEM;
lpOTM->otmptSubscriptSize = lpOTMW->otmptSubscriptSize;
lpOTM->otmptSubscriptOffset = lpOTMW->otmptSubscriptOffset;
lpOTM->otmptSuperscriptSize = lpOTMW->otmptSuperscriptSize;
lpOTM->otmptSuperscriptOffset = lpOTMW->otmptSuperscriptOffset;
lpOTM->otmsStrikeoutSize = lpOTMW->otmsStrikeoutSize;
lpOTM->otmsStrikeoutPosition = lpOTMW->otmsStrikeoutPosition;
lpOTM->otmsUnderscoreSize = lpOTMW->otmsUnderscoreSize;
lpOTM->otmsUnderscorePosition = lpOTMW->otmsUnderscorePosition;
ptr = (char*)(lpOTM + 1);
left = needed - sizeof(*lpOTM);
if(lpOTMW->otmpFamilyName) { if(lpOTMW->otmpFamilyName) {
lpOTM->otmpFamilyName = (LPSTR)(ptr - (char*)lpOTM); output->otmpFamilyName = (LPSTR)(ptr - (char*)output);
len = WideCharToMultiByte(CP_ACP, 0, len = WideCharToMultiByte(CP_ACP, 0,
(WCHAR*)((char*)lpOTMW + (ptrdiff_t)lpOTMW->otmpFamilyName), -1, (WCHAR*)((char*)lpOTMW + (ptrdiff_t)lpOTMW->otmpFamilyName), -1,
ptr, left, NULL, NULL); ptr, left, NULL, NULL);
left -= len; left -= len;
ptr += len; ptr += len;
} else } else
lpOTM->otmpFamilyName = 0; output->otmpFamilyName = 0;
if(lpOTMW->otmpFaceName) { if(lpOTMW->otmpFaceName) {
lpOTM->otmpFaceName = (LPSTR)(ptr - (char*)lpOTM); output->otmpFaceName = (LPSTR)(ptr - (char*)output);
len = WideCharToMultiByte(CP_ACP, 0, len = WideCharToMultiByte(CP_ACP, 0,
(WCHAR*)((char*)lpOTMW + (ptrdiff_t)lpOTMW->otmpFaceName), -1, (WCHAR*)((char*)lpOTMW + (ptrdiff_t)lpOTMW->otmpFaceName), -1,
ptr, left, NULL, NULL); ptr, left, NULL, NULL);
left -= len; left -= len;
ptr += len; ptr += len;
} else } else
lpOTM->otmpFaceName = 0; output->otmpFaceName = 0;
if(lpOTMW->otmpStyleName) { if(lpOTMW->otmpStyleName) {
lpOTM->otmpStyleName = (LPSTR)(ptr - (char*)lpOTM); output->otmpStyleName = (LPSTR)(ptr - (char*)output);
len = WideCharToMultiByte(CP_ACP, 0, len = WideCharToMultiByte(CP_ACP, 0,
(WCHAR*)((char*)lpOTMW + (ptrdiff_t)lpOTMW->otmpStyleName), -1, (WCHAR*)((char*)lpOTMW + (ptrdiff_t)lpOTMW->otmpStyleName), -1,
ptr, left, NULL, NULL); ptr, left, NULL, NULL);
left -= len; left -= len;
ptr += len; ptr += len;
} else } else
lpOTM->otmpStyleName = 0; output->otmpStyleName = 0;
if(lpOTMW->otmpFullName) { if(lpOTMW->otmpFullName) {
lpOTM->otmpFullName = (LPSTR)(ptr - (char*)lpOTM); output->otmpFullName = (LPSTR)(ptr - (char*)output);
len = WideCharToMultiByte(CP_ACP, 0, len = WideCharToMultiByte(CP_ACP, 0,
(WCHAR*)((char*)lpOTMW + (ptrdiff_t)lpOTMW->otmpFullName), -1, (WCHAR*)((char*)lpOTMW + (ptrdiff_t)lpOTMW->otmpFullName), -1,
ptr, left, NULL, NULL); ptr, left, NULL, NULL);
left -= len; left -= len;
} else } else
lpOTM->otmpFullName = 0; output->otmpFullName = 0;
assert(left == 0); assert(left == 0);
ret = needed; if(output != lpOTM) {
memcpy(lpOTM, output, cbData);
HeapFree(GetProcessHeap(), 0, output);
}
end: end:
if(lpOTMW != (OUTLINETEXTMETRICW *)buf) if(lpOTMW != (OUTLINETEXTMETRICW *)buf)
@ -1373,14 +1381,20 @@ UINT WINAPI GetOutlineTextMetricsW(
LPOUTLINETEXTMETRICW lpOTM) /* [out] Address of metric data array */ LPOUTLINETEXTMETRICW lpOTM) /* [out] Address of metric data array */
{ {
DC *dc = DC_GetDCPtr( hdc ); DC *dc = DC_GetDCPtr( hdc );
OUTLINETEXTMETRICW *output = lpOTM;
UINT ret; UINT ret;
TRACE("(%p,%d,%p)\n", hdc, cbData, lpOTM); TRACE("(%p,%d,%p)\n", hdc, cbData, lpOTM);
if(!dc) return 0; if(!dc) return 0;
if(dc->gdiFont) { if(dc->gdiFont) {
ret = WineEngGetOutlineTextMetrics(dc->gdiFont, cbData, lpOTM); ret = WineEngGetOutlineTextMetrics(dc->gdiFont, cbData, output);
if(ret && ret <= cbData) { if(lpOTM && ret) {
if(ret > cbData) {
output = HeapAlloc(GetProcessHeap(), 0, ret);
WineEngGetOutlineTextMetrics(dc->gdiFont, ret, output);
}
#define WDPTOLP(x) ((x<0)? \ #define WDPTOLP(x) ((x<0)? \
(-abs(INTERNAL_XDSTOWS(dc, (x)))): \ (-abs(INTERNAL_XDSTOWS(dc, (x)))): \
(abs(INTERNAL_XDSTOWS(dc, (x))))) (abs(INTERNAL_XDSTOWS(dc, (x)))))
@ -1388,40 +1402,45 @@ UINT WINAPI GetOutlineTextMetricsW(
(-abs(INTERNAL_YDSTOWS(dc, (y)))): \ (-abs(INTERNAL_YDSTOWS(dc, (y)))): \
(abs(INTERNAL_YDSTOWS(dc, (y))))) (abs(INTERNAL_YDSTOWS(dc, (y)))))
lpOTM->otmTextMetrics.tmHeight = HDPTOLP(lpOTM->otmTextMetrics.tmHeight); output->otmTextMetrics.tmHeight = HDPTOLP(output->otmTextMetrics.tmHeight);
lpOTM->otmTextMetrics.tmAscent = HDPTOLP(lpOTM->otmTextMetrics.tmAscent); output->otmTextMetrics.tmAscent = HDPTOLP(output->otmTextMetrics.tmAscent);
lpOTM->otmTextMetrics.tmDescent = HDPTOLP(lpOTM->otmTextMetrics.tmDescent); output->otmTextMetrics.tmDescent = HDPTOLP(output->otmTextMetrics.tmDescent);
lpOTM->otmTextMetrics.tmInternalLeading = HDPTOLP(lpOTM->otmTextMetrics.tmInternalLeading); output->otmTextMetrics.tmInternalLeading = HDPTOLP(output->otmTextMetrics.tmInternalLeading);
lpOTM->otmTextMetrics.tmExternalLeading = HDPTOLP(lpOTM->otmTextMetrics.tmExternalLeading); output->otmTextMetrics.tmExternalLeading = HDPTOLP(output->otmTextMetrics.tmExternalLeading);
lpOTM->otmTextMetrics.tmAveCharWidth = WDPTOLP(lpOTM->otmTextMetrics.tmAveCharWidth); output->otmTextMetrics.tmAveCharWidth = WDPTOLP(output->otmTextMetrics.tmAveCharWidth);
lpOTM->otmTextMetrics.tmMaxCharWidth = WDPTOLP(lpOTM->otmTextMetrics.tmMaxCharWidth); output->otmTextMetrics.tmMaxCharWidth = WDPTOLP(output->otmTextMetrics.tmMaxCharWidth);
lpOTM->otmTextMetrics.tmOverhang = WDPTOLP(lpOTM->otmTextMetrics.tmOverhang); output->otmTextMetrics.tmOverhang = WDPTOLP(output->otmTextMetrics.tmOverhang);
lpOTM->otmAscent = HDPTOLP(lpOTM->otmAscent); output->otmAscent = HDPTOLP(output->otmAscent);
lpOTM->otmDescent = HDPTOLP(lpOTM->otmDescent); output->otmDescent = HDPTOLP(output->otmDescent);
lpOTM->otmLineGap = HDPTOLP(lpOTM->otmLineGap); output->otmLineGap = HDPTOLP(output->otmLineGap);
lpOTM->otmsCapEmHeight = HDPTOLP(lpOTM->otmsCapEmHeight); output->otmsCapEmHeight = HDPTOLP(output->otmsCapEmHeight);
lpOTM->otmsXHeight = HDPTOLP(lpOTM->otmsXHeight); output->otmsXHeight = HDPTOLP(output->otmsXHeight);
lpOTM->otmrcFontBox.top = HDPTOLP(lpOTM->otmrcFontBox.top); output->otmrcFontBox.top = HDPTOLP(output->otmrcFontBox.top);
lpOTM->otmrcFontBox.bottom = HDPTOLP(lpOTM->otmrcFontBox.bottom); output->otmrcFontBox.bottom = HDPTOLP(output->otmrcFontBox.bottom);
lpOTM->otmrcFontBox.left = WDPTOLP(lpOTM->otmrcFontBox.left); output->otmrcFontBox.left = WDPTOLP(output->otmrcFontBox.left);
lpOTM->otmrcFontBox.right = WDPTOLP(lpOTM->otmrcFontBox.right); output->otmrcFontBox.right = WDPTOLP(output->otmrcFontBox.right);
lpOTM->otmMacAscent = HDPTOLP(lpOTM->otmMacAscent); output->otmMacAscent = HDPTOLP(output->otmMacAscent);
lpOTM->otmMacDescent = HDPTOLP(lpOTM->otmMacDescent); output->otmMacDescent = HDPTOLP(output->otmMacDescent);
lpOTM->otmMacLineGap = HDPTOLP(lpOTM->otmMacLineGap); output->otmMacLineGap = HDPTOLP(output->otmMacLineGap);
lpOTM->otmptSubscriptSize.x = WDPTOLP(lpOTM->otmptSubscriptSize.x); output->otmptSubscriptSize.x = WDPTOLP(output->otmptSubscriptSize.x);
lpOTM->otmptSubscriptSize.y = HDPTOLP(lpOTM->otmptSubscriptSize.y); output->otmptSubscriptSize.y = HDPTOLP(output->otmptSubscriptSize.y);
lpOTM->otmptSubscriptOffset.x = WDPTOLP(lpOTM->otmptSubscriptOffset.x); output->otmptSubscriptOffset.x = WDPTOLP(output->otmptSubscriptOffset.x);
lpOTM->otmptSubscriptOffset.y = HDPTOLP(lpOTM->otmptSubscriptOffset.y); output->otmptSubscriptOffset.y = HDPTOLP(output->otmptSubscriptOffset.y);
lpOTM->otmptSuperscriptSize.x = WDPTOLP(lpOTM->otmptSuperscriptSize.x); output->otmptSuperscriptSize.x = WDPTOLP(output->otmptSuperscriptSize.x);
lpOTM->otmptSuperscriptSize.y = HDPTOLP(lpOTM->otmptSuperscriptSize.y); output->otmptSuperscriptSize.y = HDPTOLP(output->otmptSuperscriptSize.y);
lpOTM->otmptSuperscriptOffset.x = WDPTOLP(lpOTM->otmptSuperscriptOffset.x); output->otmptSuperscriptOffset.x = WDPTOLP(output->otmptSuperscriptOffset.x);
lpOTM->otmptSuperscriptOffset.y = HDPTOLP(lpOTM->otmptSuperscriptOffset.y); output->otmptSuperscriptOffset.y = HDPTOLP(output->otmptSuperscriptOffset.y);
lpOTM->otmsStrikeoutSize = HDPTOLP(lpOTM->otmsStrikeoutSize); output->otmsStrikeoutSize = HDPTOLP(output->otmsStrikeoutSize);
lpOTM->otmsStrikeoutPosition = HDPTOLP(lpOTM->otmsStrikeoutPosition); output->otmsStrikeoutPosition = HDPTOLP(output->otmsStrikeoutPosition);
lpOTM->otmsUnderscoreSize = HDPTOLP(lpOTM->otmsUnderscoreSize); output->otmsUnderscoreSize = HDPTOLP(output->otmsUnderscoreSize);
lpOTM->otmsUnderscorePosition = HDPTOLP(lpOTM->otmsUnderscorePosition); output->otmsUnderscorePosition = HDPTOLP(output->otmsUnderscorePosition);
#undef WDPTOLP #undef WDPTOLP
#undef HDPTOLP #undef HDPTOLP
if(output != lpOTM) {
memcpy(lpOTM, output, cbData);
HeapFree(GetProcessHeap(), 0, output);
ret = cbData;
}
} }
} }