static void IsInsidePointA(const HDC DC, int X, int Y, LPCSTR Str, int Count) { SIZE Size; if ((Count > 0) && GetTextExtentPoint32A(DC, Str, Count, &Size)) { DWORD Flags = GetTextAlign(DC); POINT Pt; RECT Rect; if (Flags & TA_UPDATECP) { GetCurrentPositionEx(DC, &Pt); } else { Pt.x = X; Pt.y = Y; } if (Flags & TA_CENTER) { Pt.x-=(Size.cx/2); } else if (Flags & TA_RIGHT) { Pt.x-=Size.cx; } if (Flags & TA_BASELINE) { TEXTMETRIC tm; GetTextMetricsA(DC, &tm); Pt.y-=tm.tmAscent; } else if (Flags & TA_BOTTOM) { Pt.y-=Size.cy; } LPtoDP(DC, &Pt, 1); Rect.left = Pt.x; Rect.right = Pt.x + Size.cx; Rect.top = Pt.y; Rect.bottom = Pt.y + Size.cy; if (((Rect.left <= Rect.right) && (CurParams->Pt.x >= Rect.left) && (CurParams->Pt.x <= Rect.right)) || ((Rect.left > Rect.right) && (CurParams->Pt.x <= Rect.left) && (CurParams->Pt.x >= Rect.right))) { int BegPos; //if (PtInRect(&Rect, CurParams->Pt)) { CurParams->Active = !PtInRect(&Rect, CurParams->Pt); //CurParams->Active = FALSE; BegPos = (int)((abs((CurParams->Pt.x - Rect.left) / (Rect.right - Rect.left)) * (Count - 1)) + 0.5); while ((BegPos < Count - 1) && GetTextExtentPoint32A(DC, Str, BegPos + 1, &Size) && (Size.cx < CurParams->Pt.x - Rect.left)) BegPos++; while ((BegPos >= 0) && GetTextExtentPoint32A(DC, Str, BegPos + 1, &Size) && (Size.cx > CurParams->Pt.x - Rect.left)) BegPos--; if (BegPos < Count - 1) BegPos++; CurParams->BeginPos = BegPos; if (Count > 255) CurParams->WordLen = 255; else CurParams->WordLen = Count; CurParams->Unicode = FALSE; CopyMemory(CurParams->MatchedWordA, Str, CurParams->WordLen); } } }
static void init_system_font_height(void) { HDC hDC; TEXTMETRICA tm; hDC = CreateCompatibleDC(NULL); GetTextMetricsA(hDC, &tm); DeleteDC(NULL); system_font_height = tm.tmHeight; }
//***************************************************************************** // "Courier New", 100, 0, EZ_ATTR_BOLD, 0, true) ; void CVListView::set_listview_font(char * szFaceName, int iDeciPtHeight, unsigned iAttributes) { TEXTMETRICA txtm ; hdcSelf = GetDC(hwndVListView) ; hfont = EzCreateFont(hdcSelf, szFaceName, iDeciPtHeight, 0, iAttributes, 0, true) ; SelectObject(hdcSelf, hfont) ; // SetTextAlign(hdcSelf, TA_TOP | TA_LEFT) ; // ?? probably not for listview GetTextMetricsA(hdcSelf, &txtm) ; cxChar = txtm.tmAveCharWidth ; cyChar = txtm.tmHeight + txtm.tmExternalLeading ; SendMessage (hwndVListView, WM_SETFONT, (WPARAM) hfont, TRUE) ; }
static int font_height(HFONT hFont) { TEXTMETRICA tm; HFONT hFontOld; HDC hDC; hDC = CreateCompatibleDC(NULL); hFontOld = SelectObject(hDC, hFont); GetTextMetricsA(hDC, &tm); SelectObject(hDC, hFontOld); DeleteDC(hDC); return tm.tmHeight; }
////////// // // Called typically after some setting on the font is changed to "refresh" // the font with the new settings in its device context. // ////// void iiFont_refresh(SFont* font) { ////////// // Create the font ////// font->_sizeUsedForCreateFont = -MulDiv(font->_size, GetDeviceCaps(GetDC(GetDesktopWindow()), LOGPIXELSY), 72); font->hfont = CreateFont(font->_sizeUsedForCreateFont, 0, 0, 0, font->_weight, (font->isItalic ? 1 : 0), (font->isUnderline ? 1 : 0), false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_NATURAL_QUALITY, FF_DONTCARE, font->name.data_s8); // Find out the text metrics GetTextMetricsA(font->hdc, &font->tm); ////////// // Select the font into its context ////// SelectObject(font->hdc, font->hfont); }
int32_t MCCustomPrinterComputeFontSize(void *p_font) { HDC t_dc; t_dc = static_cast<MCScreenDC *>(MCscreen) -> getsrchdc(); HGDIOBJ t_old_font; t_old_font = SelectObject(t_dc, p_font); TEXTMETRICA t_metrics; GetTextMetricsA(t_dc, &t_metrics); int32_t t_font_size; t_font_size = t_metrics . tmHeight - t_metrics . tmInternalLeading; SelectObject(t_dc, t_old_font); return t_font_size; }
static int CALLBACK check_height_font_enumproc(ENUMLOGFONTEXA *enumlf, NEWTEXTMETRICEXA *ntm, DWORD type, LPARAM lParam) { HWND hwndStatus = (HWND)lParam; HDC hdc = GetDC(NULL); static const int sizes[] = { 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 20, 22, 28, 36, 48, 72 }; DWORD i; INT y; LPSTR facename = (CHAR *)enumlf->elfFullName; /* on win9x, enumlf->elfFullName is only valid for truetype fonts */ if (type != TRUETYPE_FONTTYPE) facename = enumlf->elfLogFont.lfFaceName; for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++) { HFONT hFont; TEXTMETRICA tm; HFONT hCtrlFont; HFONT hOldFont; RECT rcCtrl; enumlf->elfLogFont.lfHeight = sizes[i]; hFont = CreateFontIndirectA(&enumlf->elfLogFont); hCtrlFont = (HFONT)SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE); hOldFont = SelectObject(hdc, hFont); GetClientRect(hwndStatus, &rcCtrl); GetTextMetricsA(hdc, &tm); y = tm.tmHeight + (tm.tmInternalLeading ? tm.tmInternalLeading : 2) + 4; ok( (rcCtrl.bottom == max(y, g_ysize)) || (rcCtrl.bottom == max(y, g_dpisize)), "got %d (expected %d or %d) for %s #%d\n", rcCtrl.bottom, max(y, g_ysize), max(y, g_dpisize), facename, sizes[i]); SelectObject(hdc, hOldFont); SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hCtrlFont, TRUE); DeleteObject(hFont); } ReleaseDC(NULL, hdc); return 1; }
static void test_dtm_get_ideal_size(void) { HWND hwnd; HDC hdc; HFONT hfont; LOGFONTA lf; TEXTMETRICA tm; SIZE size; BOOL r; hwnd = create_datetime_control(0); r = SendMessageA(hwnd, DTM_GETIDEALSIZE, 0, (LPARAM)&size); if (!r) { win_skip("DTM_GETIDEALSIZE is not available\n"); DestroyWindow(hwnd); return; } /* Set font so that the test is consistent on Wine and Windows */ ZeroMemory(&lf, sizeof(lf)); lf.lfWeight = FW_NORMAL; lf.lfHeight = 20; lstrcpyA(lf.lfFaceName, "Tahoma"); hfont = CreateFontIndirectA(&lf); SendMessageA(hwnd, WM_SETFONT, (WPARAM)hfont, (LPARAM)TRUE); hdc = GetDC(hwnd); GetTextMetricsA(hdc, &tm); ReleaseDC(hwnd, hdc); r = SendMessageA(hwnd, DTM_GETIDEALSIZE, 0, (LPARAM)&size); ok(r, "Expect DTM_GETIDEALSIZE message to return true\n"); ok(size.cx > 0 && size.cy >= tm.tmHeight, "Expect size.cx > 0 and size.cy >= %d, got cx:%d cy:%d\n", tm.tmHeight, size.cx, size.cy); DestroyWindow(hwnd); DeleteObject(hfont); }
/*********************************************************************** * DrawTextExA (USER32.@) * * If DT_MODIFYSTRING is specified then there must be room for up to * 4 extra characters. We take great care about just how much modified * string we return. * * @implemented * * Synced with Wine Staging 1.7.37 */ INT WINAPI DrawTextExA( HDC hdc, LPSTR str, INT count, LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp ) { WCHAR *wstr; WCHAR *p; INT ret = 0; int i; DWORD wcount; DWORD wmax; DWORD amax; UINT cp; if (!count) return 0; if (!str && count > 0) return 0; if( !str || ((count == -1) && !(count = strlen(str)))) { int lh; TEXTMETRICA tm; if (dtp && dtp->cbSize != sizeof(DRAWTEXTPARAMS)) return 0; GetTextMetricsA(hdc, &tm); if (flags & DT_EXTERNALLEADING) lh = tm.tmHeight + tm.tmExternalLeading; else lh = tm.tmHeight; if( flags & DT_CALCRECT) { rect->right = rect->left; if( flags & DT_SINGLELINE) rect->bottom = rect->top + lh; else rect->bottom = rect->top; } return lh; } cp = GdiGetCodePage( hdc ); wcount = MultiByteToWideChar( cp, 0, str, count, NULL, 0 ); wmax = wcount; amax = count; if (flags & DT_MODIFYSTRING) { wmax += 4; amax += 4; } wstr = HeapAlloc(GetProcessHeap(), 0, wmax * sizeof(WCHAR)); if (wstr) { MultiByteToWideChar( cp, 0, str, count, wstr, wcount ); if (flags & DT_MODIFYSTRING) for (i=4, p=wstr+wcount; i--; p++) *p=0xFFFE; /* Initialise the extra characters so that we can see which ones * change. U+FFFE is guaranteed to be not a unicode character and * so will not be generated by DrawTextEx itself. */ ret = DrawTextExW( hdc, wstr, wcount, rect, flags, dtp ); if (flags & DT_MODIFYSTRING) { /* Unfortunately the returned string may contain multiple \0s * and so we need to measure it ourselves. */ for (i=4, p=wstr+wcount; i-- && *p != 0xFFFE; p++) wcount++; WideCharToMultiByte( cp, 0, wstr, wcount, str, amax, NULL, NULL ); } HeapFree(GetProcessHeap(), 0, wstr); } return ret; }
/* WINE synced 22-May-2006 */ static LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCWSTR lpstr, INT count, INT cTabStops, const INT *lpTabPos, INT nTabOrg, BOOL fDisplayText ) { INT defWidth; SIZE extent; int i, j; int start = x; if (!lpTabPos) cTabStops=0; if (cTabStops == 1) { defWidth = *lpTabPos; cTabStops = 0; } else { TEXTMETRICA tm; GetTextMetricsA( hdc, &tm ); defWidth = 8 * tm.tmAveCharWidth; } while (count > 0) { RECT r; INT x0; x0 = x; r.left = x0; /* chop the string into substrings of 0 or more <tabs> * possibly followed by 1 or more normal characters */ for (i = 0; i < count; i++) if (lpstr[i] != '\t') break; for (j = i; j < count; j++) if (lpstr[j] == '\t') break; /* get the extent of the normal character part */ GetTextExtentPointW( hdc, lpstr + i, j - i , &extent ); /* and if there is a <tab>, calculate its position */ if( i) { /* get x coordinate for the drawing of this string */ for (; cTabStops > i; lpTabPos++, cTabStops--) { if( nTabOrg + abs( *lpTabPos) > x) { if( lpTabPos[ i - 1] >= 0) { /* a left aligned tab */ x = nTabOrg + lpTabPos[ i-1] + extent.cx; break; } else { /* if tab pos is negative then text is right-aligned * to tab stop meaning that the string extends to the * left, so we must subtract the width of the string */ if (nTabOrg - lpTabPos[ i - 1] - extent.cx > x) { x = nTabOrg - lpTabPos[ i - 1]; x0 = x - extent.cx; break; } } } } /* if we have run out of tab stops and we have a valid default tab * stop width then round x up to that width */ if ((cTabStops <= i) && (defWidth > 0)) { x0 = nTabOrg + ((x - nTabOrg) / defWidth + i) * defWidth; x = x0 + extent.cx; } else if ((cTabStops <= i) && (defWidth < 0)) { x = nTabOrg + ((x - nTabOrg + extent.cx) / -defWidth + i) * -defWidth; x0 = x - extent.cx; } } else x += extent.cx; if (fDisplayText) { r.top = y; r.right = x; r.bottom = y + extent.cy; ExtTextOutW( hdc, x0, y, GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0, &r, lpstr + i, j - i, NULL ); } count -= j; lpstr += j; } return MAKELONG(x - start, extent.cy); }
static void test_ID3DXFont(IDirect3DDevice9 *device) { D3DXFONT_DESC desc; ID3DXFont *font; HRESULT hr; int ref; /* D3DXCreateFont */ ref = get_ref((IUnknown*)device); hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &font); ok(hr == D3D_OK, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3D_OK); check_ref((IUnknown*)device, ref + 1); check_release((IUnknown*)font, 0); check_ref((IUnknown*)device, ref); hr = D3DXCreateFontA(device, 0, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &font); ok(hr == D3D_OK, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3D_OK); ID3DXFont_Release(font); hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, NULL, &font); ok(hr == D3D_OK, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3D_OK); ID3DXFont_Release(font); hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "", &font); ok(hr == D3D_OK, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3D_OK); ID3DXFont_Release(font); hr = D3DXCreateFontA(NULL, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &font); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", NULL); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateFontA(NULL, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", NULL); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); /* D3DXCreateFontIndirect */ desc.Height = 12; desc.Width = 0; desc.Weight = FW_DONTCARE; desc.MipLevels = 0; desc.Italic = FALSE; desc.CharSet = DEFAULT_CHARSET; desc.OutputPrecision = OUT_DEFAULT_PRECIS; desc.Quality = DEFAULT_QUALITY; desc.PitchAndFamily = DEFAULT_PITCH; strcpy(desc.FaceName, "Arial"); hr = D3DXCreateFontIndirectA(device, &desc, &font); ok(hr == D3D_OK, "D3DXCreateFontIndirect returned %#x, expected %#x\n", hr, D3D_OK); ID3DXFont_Release(font); hr = D3DXCreateFontIndirectA(NULL, &desc, &font); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFontIndirect returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateFontIndirectA(device, NULL, &font); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFontIndirect returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateFontIndirectA(device, &desc, NULL); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFontIndirect returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); /* ID3DXFont_GetDevice */ hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &font); if(SUCCEEDED(hr)) { IDirect3DDevice9 *bufdev; hr = ID3DXFont_GetDevice(font, NULL); ok(hr == D3DERR_INVALIDCALL, "ID3DXFont_GetDevice returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); ref = get_ref((IUnknown*)device); hr = ID3DXFont_GetDevice(font, &bufdev); ok(hr == D3D_OK, "ID3DXFont_GetDevice returned %#x, expected %#x\n", hr, D3D_OK); check_release((IUnknown*)bufdev, ref); ID3DXFont_Release(font); } else skip("Failed to create a ID3DXFont object\n"); /* ID3DXFont_GetDesc */ hr = D3DXCreateFontA(device, 12, 8, FW_BOLD, 2, TRUE, ANSI_CHARSET, OUT_RASTER_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH, "Arial", &font); if(SUCCEEDED(hr)) { hr = ID3DXFont_GetDescA(font, NULL); ok(hr == D3DERR_INVALIDCALL, "ID3DXFont_GetDevice returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = ID3DXFont_GetDescA(font, &desc); ok(hr == D3D_OK, "ID3DXFont_GetDevice returned %#x, expected %#x\n", hr, D3D_OK); ok(desc.Height == 12, "ID3DXFont_GetDesc returned font height %d, expected %d\n", desc.Height, 12); ok(desc.Width == 8, "ID3DXFont_GetDesc returned font width %d, expected %d\n", desc.Width, 8); ok(desc.Weight == FW_BOLD, "ID3DXFont_GetDesc returned font weight %d, expected %d\n", desc.Weight, FW_BOLD); ok(desc.MipLevels == 2, "ID3DXFont_GetDesc returned font miplevels %d, expected %d\n", desc.MipLevels, 2); ok(desc.Italic == TRUE, "ID3DXFont_GetDesc says Italic was %d, but Italic should be %d\n", desc.Italic, TRUE); ok(desc.CharSet == ANSI_CHARSET, "ID3DXFont_GetDesc returned font charset %d, expected %d\n", desc.CharSet, ANSI_CHARSET); ok(desc.OutputPrecision == OUT_RASTER_PRECIS, "ID3DXFont_GetDesc returned an output precision of %d, expected %d\n", desc.OutputPrecision, OUT_RASTER_PRECIS); ok(desc.Quality == ANTIALIASED_QUALITY, "ID3DXFont_GetDesc returned font quality %d, expected %d\n", desc.Quality, ANTIALIASED_QUALITY); ok(desc.PitchAndFamily == VARIABLE_PITCH, "ID3DXFont_GetDesc returned pitch and family %d, expected %d\n", desc.PitchAndFamily, VARIABLE_PITCH); ok(strcmp(desc.FaceName, "Arial") == 0, "ID3DXFont_GetDesc returned facename \"%s\", expected \"%s\"\n", desc.FaceName, "Arial"); ID3DXFont_Release(font); } else skip("Failed to create a ID3DXFont object\n"); /* ID3DXFont_GetDC + ID3DXFont_GetTextMetrics */ hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &font); if(SUCCEEDED(hr)) { HDC hdc; hdc = ID3DXFont_GetDC(font); ok(hdc != NULL, "ID3DXFont_GetDC returned an invalid handle\n"); if(hdc) { TEXTMETRICA metrics, expmetrics; BOOL ret; ret = ID3DXFont_GetTextMetricsA(font, &metrics); ok(ret, "ID3DXFont_GetTextMetricsA failed\n"); ret = GetTextMetricsA(hdc, &expmetrics); ok(ret, "GetTextMetricsA failed\n"); ok(metrics.tmHeight == expmetrics.tmHeight, "Returned height %d, expected %d\n", metrics.tmHeight, expmetrics.tmHeight); ok(metrics.tmAscent == expmetrics.tmAscent, "Returned ascent %d, expected %d\n", metrics.tmAscent, expmetrics.tmAscent); ok(metrics.tmDescent == expmetrics.tmDescent, "Returned descent %d, expected %d\n", metrics.tmDescent, expmetrics.tmDescent); ok(metrics.tmInternalLeading == expmetrics.tmInternalLeading, "Returned internal leading %d, expected %d\n", metrics.tmInternalLeading, expmetrics.tmInternalLeading); ok(metrics.tmExternalLeading == expmetrics.tmExternalLeading, "Returned external leading %d, expected %d\n", metrics.tmExternalLeading, expmetrics.tmExternalLeading); ok(metrics.tmAveCharWidth == expmetrics.tmAveCharWidth, "Returned average char width %d, expected %d\n", metrics.tmAveCharWidth, expmetrics.tmAveCharWidth); ok(metrics.tmMaxCharWidth == expmetrics.tmMaxCharWidth, "Returned maximum char width %d, expected %d\n", metrics.tmMaxCharWidth, expmetrics.tmMaxCharWidth); ok(metrics.tmWeight == expmetrics.tmWeight, "Returned weight %d, expected %d\n", metrics.tmWeight, expmetrics.tmWeight); ok(metrics.tmOverhang == expmetrics.tmOverhang, "Returned overhang %d, expected %d\n", metrics.tmOverhang, expmetrics.tmOverhang); ok(metrics.tmDigitizedAspectX == expmetrics.tmDigitizedAspectX, "Returned digitized x aspect %d, expected %d\n", metrics.tmDigitizedAspectX, expmetrics.tmDigitizedAspectX); ok(metrics.tmDigitizedAspectY == expmetrics.tmDigitizedAspectY, "Returned digitized y aspect %d, expected %d\n", metrics.tmDigitizedAspectY, expmetrics.tmDigitizedAspectY); ok(metrics.tmFirstChar == expmetrics.tmFirstChar, "Returned first char %d, expected %d\n", metrics.tmFirstChar, expmetrics.tmFirstChar); ok(metrics.tmLastChar == expmetrics.tmLastChar, "Returned last char %d, expected %d\n", metrics.tmLastChar, expmetrics.tmLastChar); ok(metrics.tmDefaultChar == expmetrics.tmDefaultChar, "Returned default char %d, expected %d\n", metrics.tmDefaultChar, expmetrics.tmDefaultChar); ok(metrics.tmBreakChar == expmetrics.tmBreakChar, "Returned break char %d, expected %d\n", metrics.tmBreakChar, expmetrics.tmBreakChar); ok(metrics.tmItalic == expmetrics.tmItalic, "Returned italic %d, expected %d\n", metrics.tmItalic, expmetrics.tmItalic); ok(metrics.tmUnderlined == expmetrics.tmUnderlined, "Returned underlined %d, expected %d\n", metrics.tmUnderlined, expmetrics.tmUnderlined); ok(metrics.tmStruckOut == expmetrics.tmStruckOut, "Returned struck out %d, expected %d\n", metrics.tmStruckOut, expmetrics.tmStruckOut); ok(metrics.tmPitchAndFamily == expmetrics.tmPitchAndFamily, "Returned pitch and family %d, expected %d\n", metrics.tmPitchAndFamily, expmetrics.tmPitchAndFamily); ok(metrics.tmCharSet == expmetrics.tmCharSet, "Returned charset %d, expected %d\n", metrics.tmCharSet, expmetrics.tmCharSet); } ID3DXFont_Release(font); } else skip("Failed to create a ID3DXFont object\n"); }
MCFontnode::MCFontnode(const MCString &fname, uint2 &size, uint2 style, Boolean printer) { reqname = fname.clone(); reqsize = size; reqstyle = style; reqprinter = printer; font = new MCFontStruct; if (MCnoui) { memset(font, 0, sizeof(MCFontStruct)); return; } LOGFONTA logfont; memset(&logfont, 0, sizeof(LOGFONTA)); uint4 maxlength = MCU_min(LF_FACESIZE - 1U, fname.getlength()); strncpy(logfont.lfFaceName, fname.getstring(), maxlength); logfont.lfFaceName[maxlength] = '\0'; // MW-2012-05-03: [[ Bug 10180 ]] Make sure the default charset for the font // is chosen - otherwise things like WingDings don't work! logfont.lfCharSet = DEFAULT_CHARSET; //parse font and encoding char *sptr = logfont.lfFaceName; if (sptr = strchr(logfont.lfFaceName, ',')) { *sptr = '\0'; sptr++; } HDC hdc; // MW-2013-11-07: [[ Bug 11393 ]] 'printer' in the fontstruct now means use ideal // metrics for rendering and measuring. MCScreenDC *pms = (MCScreenDC *)MCscreen; hdc = pms->getsrchdc(); logfont.lfHeight = MulDiv(MulDiv(size, 7, 8), SCREEN_WIDTH_FOR_FONT_USE, 72); logfont.lfWeight = weighttable[MCF_getweightint(style)]; if (style & FA_ITALIC) logfont.lfItalic = TRUE; if (style & FA_OBLIQUE) logfont.lfOrientation = 3600 - 150; /* 15 degree forward slant */ HFONT newfont = CreateFontIndirectA(&logfont); SelectObject(hdc, newfont); char testname[LF_FACESIZE]; memset(testname, 0, LF_FACESIZE); GetTextFaceA(hdc, LF_FACESIZE, testname); // MW-2012-02-13: If we failed to find an exact match then remap the font name and // try again. if (newfont == NULL || (MCU_strncasecmp(testname, logfont.lfFaceName, strlen(testname) + 1))) { if (newfont != NULL) DeleteObject(newfont); mapfacename(logfont.lfFaceName, logfont.lfFaceName, printer == True); // Force the resulting font to be TrueType and with ANSI charset (otherwise // we get strange UI symbol font on XP). logfont.lfCharSet = ANSI_CHARSET; logfont.lfOutPrecision = OUT_TT_ONLY_PRECIS; newfont = CreateFontIndirectA(&logfont); SelectObject(hdc, newfont); } // At this point we will have either found an exact match for the textFont, mapped // using the defaults table and found a match, or been given a default truetype font. TEXTMETRICA tm; GetTextMetricsA(hdc, &tm); font->fid = (MCSysFontHandle)newfont; font->size = size; // MW-2013-12-19: [[ Bug 11606 ]] Use Mac-style metric adjustment in printer (ideal // layout mode). if (!printer) { font->ascent = MulDiv(tm.tmAscent, 15, 16); font->descent = tm.tmDescent; } else { font -> ascent = size - 1; font -> descent = size * 2 / 14 + 1; } font->printer = printer; }
static void test_TxGetNaturalSize(void) { HRESULT result; BOOL ret; /* This value is used when calling TxGetNaturalSize. MSDN says that this is not supported however a null pointer cannot be used as it will cause a segmentation violation. The values in the structure being pointed to are required to be INT_MAX otherwise calculations can give wrong values. */ const SIZEL psizelExtent = {INT_MAX,INT_MAX}; static const WCHAR oneA[] = {'A',0}; /* Results of measurements */ LONG xdim, ydim; /* The device context to do the tests in */ HDC hdcDraw; /* Variables with the text metric information */ INT charwidth_caps_text[26]; TEXTMETRICA tmInfo_text; if (!init_texthost()) return; hdcDraw = GetDC(NULL); SaveDC(hdcDraw); /* Populate the metric strucs */ SetMapMode(hdcDraw,MM_TEXT); GetTextMetricsA(hdcDraw, &tmInfo_text); SetLastError(0xdeadbeef); ret = GetCharWidth32A(hdcDraw,'A','Z',charwidth_caps_text); if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) { win_skip("GetCharWidth32 is not available\n"); goto cleanup; } /* Make measurements in MM_TEXT */ SetMapMode(hdcDraw,MM_TEXT); xdim = 0; ydim = 0; result = ITextServices_TxSetText(txtserv, oneA); ok(result == S_OK, "ITextServices_TxSetText failed (result = %x)\n", result); if (result != S_OK) { skip("Could not set text\n"); goto cleanup; } SetLastError(0xdeadbeef); result = ITextServices_TxGetNaturalSize(txtserv, DVASPECT_CONTENT, hdcDraw, NULL, NULL, TXTNS_FITTOCONTENT, &psizelExtent, &xdim, &ydim); todo_wine ok(result == S_OK || broken(result == E_FAIL), /* WINXP Arabic Language */ "TxGetNaturalSize gave unexpected return value (result = %x)\n", result); if (result == S_OK) { todo_wine ok(ydim == tmInfo_text.tmHeight, "Height calculated incorrectly (expected %d, got %d)\n", tmInfo_text.tmHeight, ydim); /* The native DLL adds one pixel extra when calculating widths. */ todo_wine ok(xdim >= charwidth_caps_text[0] && xdim <= charwidth_caps_text[0] + 1, "Width calculated incorrectly (expected %d {+1}, got %d)\n", charwidth_caps_text[0], xdim); } else skip("TxGetNaturalSize measurements not performed (xdim = %d, ydim = %d, result = %x, error = %x)\n", xdim, ydim, result, GetLastError()); cleanup: RestoreDC(hdcDraw,1); ReleaseDC(NULL,hdcDraw); free_texthost(); }
static BOOL WINAPI ID3DXFontImpl_GetTextMetricsA(ID3DXFont *iface, TEXTMETRICA *metrics) { struct d3dx_font *This = impl_from_ID3DXFont(iface); TRACE("iface %p, metrics %p\n", iface, metrics); return GetTextMetricsA(This->hdc, metrics); }
static void Test_FontSelectionEntry(HDC hDC, UINT nIndex, FONT_SEL_TEST *Entry) { LOGFONTA lf; HFONT hFont; HGDIOBJ hFontOld; TEXTMETRICA tm; ZeroMemory(&lf, sizeof(lf)); if (Entry->FaceNameBefore[0]) lstrcpynA(lf.lfFaceName, Entry->FaceNameBefore, _countof(lf.lfFaceName)); lf.lfCharSet = Entry->CharSetBefore; if (Entry->BoldBefore == TS_TRUE) lf.lfWeight = FW_BOLD; else if (Entry->BoldBefore == TS_FALSE) lf.lfWeight = FW_NORMAL; else lf.lfWeight = FW_DONTCARE; lf.lfItalic = Entry->ItalicBefore; lf.lfUnderline = Entry->UnderlineBefore; lf.lfStrikeOut = Entry->StruckOutBefore; if (Entry->FixedPitchBefore == TS_TRUE) lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE; else if (Entry->FixedPitchBefore == TS_FALSE) lf.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE; else lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; hFont = CreateFontIndirectA(&lf); ok(hFont != NULL, "Entry #%u: hFont failed\n", nIndex); hFontOld = SelectObject(hDC, hFont); { ok(GetTextMetricsA(hDC, &tm), "Entry #%u: GetTextMetricsA failed\n", nIndex); if (Entry->CharSetAfter != DEFAULT_CHARSET) ok(tm.tmCharSet == Entry->CharSetAfter, "Entry #%u: CharSet mismatched, it was %u\n", nIndex, tm.tmCharSet); if (Entry->BoldAfter == TS_TRUE) ok(tm.tmWeight >= FW_BOLD, "Entry #%u: Weight was non-bold\n", nIndex); else if (Entry->BoldAfter == TS_FALSE) ok(tm.tmWeight <= FW_MEDIUM, "Entry #%u: Weight was bold\n", nIndex); if (Entry->ItalicAfter == TS_TRUE) ok(tm.tmItalic, "Entry #%u: Italic was non-italic\n", nIndex); else if (Entry->ItalicAfter == TS_FALSE) ok(!tm.tmItalic, "Entry #%u: Italic was italic\n", nIndex); if (Entry->UnderlineAfter == TS_TRUE) ok(tm.tmUnderlined, "Entry #%u: Underlined was FALSE\n", nIndex); else if (Entry->UnderlineAfter == TS_FALSE) ok(!tm.tmUnderlined, "Entry #%u: Underlined was TRUE\n", nIndex); if (Entry->StruckOutAfter == TS_TRUE) ok(tm.tmStruckOut, "Entry #%u: Struck-out was FALSE\n", nIndex); else if (Entry->StruckOutAfter == TS_FALSE) ok(!tm.tmStruckOut, "Entry #%u: Struck-out was TRUE\n", nIndex); if (Entry->FixedPitchAfter == TS_TRUE) ok(!(tm.tmPitchAndFamily & _TMPF_VAR_PITCH), "Entry #%u: Pitch mismatched, it was non-fixed-pitch\n", nIndex); else if (Entry->FixedPitchAfter == TS_FALSE) ok((tm.tmPitchAndFamily & _TMPF_VAR_PITCH), "Entry #%u: Pitch mismatched, it was fixed-pitch\n", nIndex); } SelectObject(hDC, hFontOld); DeleteObject(hFont); }