void Test_CreateFontIndirectA(void) { LOGFONTA logfont; HFONT hFont; ULONG ret; ENUMLOGFONTEXDVW elfedv2; logfont.lfHeight = 12; logfont.lfWidth = 0; logfont.lfEscapement = 0; logfont.lfOrientation = 0; logfont.lfWeight = FW_NORMAL; logfont.lfItalic = 0; logfont.lfUnderline = 0; logfont.lfStrikeOut = 0; logfont.lfCharSet = DEFAULT_CHARSET; logfont.lfOutPrecision = OUT_DEFAULT_PRECIS; logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; logfont.lfQuality = PROOF_QUALITY; logfont.lfPitchAndFamily = DEFAULT_PITCH; memset(logfont.lfFaceName, 'A', LF_FACESIZE); hFont = CreateFontIndirectA(&logfont); ok(hFont != 0, "CreateFontIndirectA failed\n"); memset(&elfedv2, 0, sizeof(elfedv2)); ret = GetObjectW(hFont, sizeof(elfedv2), &elfedv2); ok(ret == sizeof(ENUMLOGFONTEXW) + 2*sizeof(DWORD), "ret = %ld\n", ret); ok(elfedv2.elfEnumLogfontEx.elfLogFont.lfFaceName[LF_FACESIZE-1] == 0, "\n"); ok(elfedv2.elfEnumLogfontEx.elfFullName[0] == 0, "\n"); }
LRESULT CALLBACK pinDialogPriv::nonmodalDialogProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch(msg) { case WM_CREATE: { NONCLIENTMETRICSA ncMetrics; ZeroMemory(&ncMetrics,sizeof(ncMetrics)); ncMetrics.cbSize = sizeof(ncMetrics); SystemParametersInfoA(SPI_GETNONCLIENTMETRICS,sizeof(ncMetrics),&ncMetrics,0); HFONT hFont = CreateFontIndirectA(&ncMetrics.lfCaptionFont); CREATESTRUCT * ptr = (CREATESTRUCT *) lParam; pinDialogPriv *dlg = (pinDialogPriv *) ptr->lpCreateParams; std::string tmp = dlg->m_dlg.m_displayName + " ID-card PIN" + (dlg->m_dlg.m_key == EstEidCard::AUTH ? "1" : "2") ; HWND w1 = CreateWindowExA(0, "STATIC", tmp.c_str(), WS_VISIBLE | WS_CHILD, 50, 5, 240, 25, hwnd, (HMENU)1, NULL, NULL); HWND w2 = CreateWindowExA(0, "STATIC", dlg->m_dlg.m_PAD_prompt.c_str(), WS_VISIBLE | WS_CHILD, 50, 30, 240, 25, hwnd, (HMENU)1, NULL, NULL); SendMessage(w1, WM_SETFONT, (WPARAM)hFont, TRUE); SendMessage(w2, WM_SETFONT, (WPARAM)hFont, TRUE); iconHandle *dlgIcon = new iconHandle(iconSet[dlg->m_dlg.m_key].module,iconSet[dlg->m_dlg.m_key].id); HWND b = CreateWindowExA(0, "STATIC","", SS_CENTERIMAGE | SS_REALSIZEIMAGE | SS_ICON | WS_CHILD | WS_VISIBLE, 5,5,40,40,hwnd,(HMENU)-1, NULL, NULL); SendMessage(b, STM_SETIMAGE,(WPARAM)IMAGE_ICON, (LPARAM)*dlgIcon); break; } case WM_COMMAND: case WM_CLOSE: DestroyWindow(hwnd); break; } return (DefWindowProc(hwnd, msg, wParam, lParam)); }
static bool MCTextLayoutFontWithLink(MCTextLayoutFont *p_base, MCTextLayoutLinkedFontEntry *p_link, MCTextLayoutFont*& r_font) { LOGFONTA t_logfont; t_logfont = p_base -> info; MCMemoryCopy(&t_logfont . lfFaceName, p_link -> face, MCMax(MCCStringLength(p_link -> face) + 1, sizeof(t_logfont . lfFaceName))); MCTextLayoutFont *t_font; t_font = MCTextLayoutFontFind(t_logfont); if (t_font != nil) { r_font = t_font; return true; } HFONT t_hfont; t_hfont = CreateFontIndirectA(&t_logfont); if (t_hfont == nil) return false; bool t_success; t_success = MCTextLayoutFontFromHFONT(t_hfont, t_font); DeleteObject(t_hfont); r_font = t_font; return t_success; }
void text_font(TW *tw, const char *name, int size) { /* make a new font */ LOGFONTA lf; TEXTMETRIC tm; LPSTR p; HDC hdc; /* reject inappropriate arguments */ if (name == NULL) return; if (size < 4) return; /* set new name and size */ free(tw->fontname); tw->fontname = (char *)malloc(strlen(name)+1); if (tw->fontname == NULL) return; strcpy(tw->fontname, name); tw->fontsize = size; /* if window not open, hwnd == 0 == HWND_DESKTOP */ hdc = GetDC(tw->hwnd); memset(&lf, 0, sizeof(LOGFONTA)); strncpy(lf.lfFaceName,tw->fontname,LF_FACESIZE); lf.lfHeight = -MulDiv(tw->fontsize, GetDeviceCaps(hdc, LOGPIXELSY), 72); lf.lfPitchAndFamily = FIXED_PITCH; lf.lfCharSet = DEFAULT_CHARSET; if ( (p = strstr(tw->fontname," Italic")) != (LPSTR)NULL ) { lf.lfFaceName[ (unsigned int)(p-tw->fontname) ] = '\0'; lf.lfItalic = TRUE; } if ( (p = strstr(tw->fontname," Bold")) != (LPSTR)NULL ) { lf.lfFaceName[ (unsigned int)(p-tw->fontname) ] = '\0'; lf.lfWeight = FW_BOLD; } if (tw->hfont) DeleteFont(tw->hfont); tw->hfont = CreateFontIndirectA((LOGFONTA FAR *)&lf); /* get text size */ SelectFont(hdc, tw->hfont); GetTextMetrics(hdc,(TEXTMETRIC FAR *)&tm); tw->CharSize.y = tm.tmHeight; tw->CharSize.x = tm.tmAveCharWidth; tw->CharAscent = tm.tmAscent; if (tw->bFocus) CreateCaret(tw->hwnd, 0, tw->CharSize.x, 2+tw->CaretHeight); ReleaseDC(tw->hwnd, hdc); /* redraw window if necessary */ if (tw->hwnd != HWND_DESKTOP) { /* INCOMPLETE */ } }
static bool MCTextLayoutFontFromHFONT(void *p_font, MCTextLayoutFont*& r_font) { bool t_success; t_success = true; // First fetch the HFONT's LOGFONT structure LOGFONTA t_logfont; if (t_success) if (!GetObjectA(p_font, sizeof(LOGFONTA), &t_logfont)) t_success = false; if (t_success) t_logfont . lfHeight = -256; // Now use this to search for an existing layout font MCTextLayoutFont *self; self = nil; if (t_success) { self = MCTextLayoutFontFind(t_logfont); if (self != nil) { r_font = self; return true; } } // Otherwise we must go ahead and create a new font if (t_success) t_success = MCMemoryNew(self); if (t_success) { self -> handle = CreateFontIndirectA(&t_logfont); if (self -> handle == nil) t_success = false; } if (t_success) { MCListPushFront(s_fonts, self); self -> info = t_logfont; // Now see if the font is a linked font for(MCTextLayoutLinkedFont *t_links = s_linked_fonts; t_links != nil; t_links = t_links -> next) if (MCCStringEqualCaseless(t_links -> name, self -> info . lfFaceName)) { self -> linking = t_links; break; } r_font = self; } else MCTextLayoutFontDestroy(self); return t_success; }
static void test_TTGetEmbeddingType(void) { HFONT hfont, old_font; LOGFONTA logfont; ULONG status; LONG ret; HDC hdc; ret = TTGetEmbeddingType(NULL, NULL); ok(ret == E_HDCINVALID, "got %d\n", ret); status = 0xdeadbeef; ret = TTGetEmbeddingType(NULL, &status); ok(ret == E_HDCINVALID, "got %#x\n", ret); ok(status == 0xdeadbeef, "got %u\n", status); status = 0xdeadbeef; ret = TTGetEmbeddingType((HDC)0xdeadbeef, &status); ok(ret == E_NOTATRUETYPEFONT || broken(ret == E_ERRORACCESSINGFONTDATA) /* xp, vista */, "got %#x\n", ret); ok(status == 0xdeadbeef, "got %u\n", status); hdc = CreateCompatibleDC(0); ret = TTGetEmbeddingType(hdc, NULL); ok(ret == E_NOTATRUETYPEFONT, "got %#x\n", ret); status = 0xdeadbeef; ret = TTGetEmbeddingType(hdc, &status); ok(ret == E_NOTATRUETYPEFONT, "got %#x\n", ret); ok(status == 0xdeadbeef, "got %u\n", status); memset(&logfont, 0, sizeof(logfont)); logfont.lfHeight = 12; logfont.lfWeight = FW_NORMAL; strcpy(logfont.lfFaceName, "Tahoma"); hfont = CreateFontIndirectA(&logfont); ok(hfont != NULL, "got %p\n", hfont); old_font = SelectObject(hdc, hfont); status = 0; ret = TTGetEmbeddingType(hdc, &status); ok(ret == E_NONE, "got %#x\n", ret); ok(status != 0, "got %u\n", status); ret = TTGetEmbeddingType(hdc, NULL); ok(ret == E_PERMISSIONSINVALID, "got %#x\n", ret); SelectObject(hdc, old_font); DeleteObject(hfont); /* repeat for all system fonts */ logfont.lfCharSet = DEFAULT_CHARSET; logfont.lfFaceName[0] = 0; EnumFontFamiliesExA(hdc, &logfont, (FONTENUMPROCA)enum_font_proc, 0, 0); DeleteDC(hdc); }
int ReloadFont(WPARAM wParam, LPARAM lParam) { #ifdef _UNICODE if(ServiceExists(MS_FONT_GETW)) { LOGFONTW log_font; if(hFontFirstLine) DeleteObject(hFontFirstLine); colFirstLine = CallService(MS_FONT_GETW, (WPARAM)&font_id_firstlinew, (LPARAM)&log_font); hFontFirstLine = CreateFontIndirectW(&log_font); if(hFontSecondLine) DeleteObject(hFontSecondLine); colSecondLine = CallService(MS_FONT_GETW, (WPARAM)&font_id_secondlinew, (LPARAM)&log_font); hFontSecondLine = CreateFontIndirectW(&log_font); if(hFontTime) DeleteObject(hFontTime); colTime = CallService(MS_FONT_GETW, (WPARAM)&font_id_timew, (LPARAM)&log_font); hFontTime = CreateFontIndirectW(&log_font); colBg = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_bgw, 0); colBorder = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_borderw, 0); colSidebar = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_sidebarw, 0); colTitleUnderline = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_titleunderlinew, 0); } else #endif { LOGFONTA log_font; if(hFontFirstLine) DeleteObject(hFontFirstLine); colFirstLine = CallService(MS_FONT_GET, (WPARAM)&font_id_firstline, (LPARAM)&log_font); hFontFirstLine = CreateFontIndirectA(&log_font); if(hFontSecondLine) DeleteObject(hFontSecondLine); colSecondLine = CallService(MS_FONT_GET, (WPARAM)&font_id_secondline, (LPARAM)&log_font); hFontSecondLine = CreateFontIndirectA(&log_font); if(hFontTime) DeleteObject(hFontTime); colTime = CallService(MS_FONT_GET, (WPARAM)&font_id_time, (LPARAM)&log_font); hFontTime = CreateFontIndirectA(&log_font); colBg = CallService(MS_COLOUR_GET, (WPARAM)&colour_id_bg, 0); colBorder = CallService(MS_COLOUR_GET, (WPARAM)&colour_id_border, 0); colSidebar = CallService(MS_COLOUR_GET, (WPARAM)&colour_id_sidebar, 0); colTitleUnderline = CallService(MS_COLOUR_GET, (WPARAM)&colour_id_titleunderline, 0); } return 0; }
void Font::setFont(const char* psz) { if (m_pNativeObject) { ::DeleteObject((HDC)m_pNativeObject); m_pNativeObject = nullptr; } LogfontActions actions; ParseFont(psz, actions); assert(m_pNativeObject == nullptr); fontdesc = psz; m_pNativeObject = (void*)CreateFontIndirectA(&actions.m_LogFont); }
HWND create_labeled_text(char* label, char* text, HWND hParent, HINSTANCE hInstance, UINT left, UINT top, UINT height, UINT label_width, UINT text_width, UINT uIDLabel, UINT uIDText) { HWND hwnd = NULL; HFONT dlgFont; LOGFONT logFont; HFONT labelFont; // Get the font from the parent dialog dlgFont = (HFONT)SendMessage(hParent,WM_GETFONT,0,0); if (label) { // convert it to a logfont GetObject(dlgFont,sizeof(logFont),&logFont); // make it bold logFont.lfWeight*=2; // convert it back to HFONT labelFont = CreateFontIndirectA(&logFont); } else { labelFont = dlgFont; } if (label) { // create the label text and set the label (bold) font hwnd = create_label(label, hParent, hInstance, left, top, label_width, height, SS_LEFT, uIDLabel); SendMessage(hwnd, WM_SETFONT, (WPARAM)labelFont, TRUE); } if (text) { if (label) { text_width-=5; left+=label_width+5; } // create the label text and set the dialog font hwnd = create_label(text, hParent, hInstance, left, top, text_width, height, SS_LEFT, uIDText); SendMessage(hwnd,WM_SETFONT, (WPARAM)dlgFont, TRUE); } return hwnd; }
bool setFont(const char * pFontName = NULL, int nSize = 0) { bool bRet = false; do { HFONT hDefFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LOGFONTA tNewFont = {0}; LOGFONTA tOldFont = {0}; GetObjectA(hDefFont, sizeof(tNewFont), &tNewFont); if (pFontName) { strcpy_s(tNewFont.lfFaceName, LF_FACESIZE, pFontName); } if (nSize) { tNewFont.lfHeight = -nSize; } GetObjectA(m_hFont, sizeof(tOldFont), &tOldFont); if (tOldFont.lfHeight == tNewFont.lfHeight && ! strcpy(tOldFont.lfFaceName, tNewFont.lfFaceName)) { // already has the font bRet = true; break; } // delete old font if (m_hFont != hDefFont) { DeleteObject(m_hFont); } m_hFont = NULL; // create new font m_hFont = CreateFontIndirectA(&tNewFont); if (! m_hFont) { // create failed, use default font m_hFont = hDefFont; break; } bRet = true; } while (0); return bRet; }
static void ApplySystemParameters(wnd_ctrls *Controls) { if(Controls) { NONCLIENTMETRICS Metrics = {}; Metrics.cbSize = sizeof(Metrics); SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, sizeof(Metrics), &Metrics, 0); HFONT Font = CreateFontIndirectA(&Metrics.lfMessageFont); SendMessageA(Controls->ButtonCancel, WM_SETFONT, (WPARAM)Font, 0); SendMessageA(Controls->ButtonOK, WM_SETFONT, (WPARAM)Font, 0); SendMessageA(Controls->ComboBox, WM_SETFONT, (WPARAM)Font, 0); SendMessageA(Controls->StaticText, WM_SETFONT, (WPARAM)Font, 0); SendMessageA(Controls->CheckBox, WM_SETFONT, (WPARAM)Font, 0); } }
static int CALLBACK enum_font_proc(ENUMLOGFONTEXA *enumlf, NEWTEXTMETRICEXA *ntm, DWORD type, LPARAM lParam) { OUTLINETEXTMETRICA otm; HDC hdc = GetDC(NULL); HFONT hfont, old_font; ULONG status; LONG ret; hfont = CreateFontIndirectA(&enumlf->elfLogFont); old_font = SelectObject(hdc, hfont); otm.otmSize = sizeof(otm); if (GetOutlineTextMetricsA(hdc, otm.otmSize, &otm)) { ULONG expected = 0xffff; UINT fsType = otm.otmfsType & 0xf; ret = TTGetEmbeddingType(hdc, &status); ok(ret == E_NONE, "got %d\n", ret); if (fsType == LICENSE_INSTALLABLE) expected = EMBED_INSTALLABLE; else if (fsType & LICENSE_EDITABLE) expected = EMBED_EDITABLE; else if (fsType & LICENSE_PREVIEWPRINT) expected = EMBED_PREVIEWPRINT; else if (fsType & LICENSE_NOEMBEDDING) expected = EMBED_NOEMBEDDING; ok(expected == status, "%s: status %d, expected %d, fsType %#x\n", enumlf->elfLogFont.lfFaceName, status, expected, otm.otmfsType); } else { status = 0xdeadbeef; ret = TTGetEmbeddingType(hdc, &status); ok(ret == E_NOTATRUETYPEFONT, "%s: got %d\n", enumlf->elfLogFont.lfFaceName, ret); ok(status == 0xdeadbeef, "%s: got status %d\n", enumlf->elfLogFont.lfFaceName, status); } SelectObject(hdc, old_font); DeleteObject(hfont); ReleaseDC(NULL, hdc); return 1; }
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_TTIsEmbeddingEnabled(void) { HFONT old_font, hfont; LONG ret, status; LOGFONTA logfont; HDC hdc; ret = TTIsEmbeddingEnabled(NULL, NULL); ok(ret == E_HDCINVALID, "got %#x\n", ret); status = 123; ret = TTIsEmbeddingEnabled(NULL, &status); ok(ret == E_HDCINVALID, "got %#x\n", ret); ok(status == 123, "got %d\n", status); hdc = CreateCompatibleDC(0); ret = TTIsEmbeddingEnabled(hdc, NULL); ok(ret == E_ERRORACCESSINGFACENAME, "got %#x\n", ret); status = 123; ret = TTIsEmbeddingEnabled(hdc, &status); ok(ret == E_ERRORACCESSINGFACENAME, "got %#x\n", ret); ok(status == 123, "got %u\n", status); memset(&logfont, 0, sizeof(logfont)); logfont.lfHeight = 12; logfont.lfWeight = FW_NORMAL; strcpy(logfont.lfFaceName, "Tahoma"); hfont = CreateFontIndirectA(&logfont); ok(hfont != NULL, "got %p\n", hfont); old_font = SelectObject(hdc, hfont); status = 123; ret = TTIsEmbeddingEnabled(hdc, &status); ok(ret == E_NONE, "got %#x\n", ret); ok(status != 123, "got %u\n", status); SelectObject(hdc, old_font); DeleteObject(hfont); DeleteDC(hdc); }
/*********************************************************************** * IconTitleWndProc */ LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { HWND owner = GetWindow( hWnd, GW_OWNER ); if (!IsWindow(hWnd)) return 0; switch( msg ) { case WM_CREATE: if (!hIconTitleFont) { LOGFONTA logFont; SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 ); SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 ); hIconTitleFont = CreateFontIndirectA( &logFont ); } return (hIconTitleFont ? 0 : -1); case WM_NCHITTEST: return HTCAPTION; case WM_NCMOUSEMOVE: case WM_NCLBUTTONDBLCLK: return SendMessageW( owner, msg, wParam, lParam ); case WM_ACTIVATE: if( wParam ) SetActiveWindow( owner ); return 0; case WM_CLOSE: return 0; case WM_SHOWWINDOW: if (wParam) ICONTITLE_SetTitlePos( hWnd, owner ); return 0; case WM_ERASEBKGND: if( GetWindowLongPtrW( owner, GWL_STYLE ) & WS_CHILD ) lParam = SendMessageW( owner, WM_ISACTIVEICON, 0, 0 ); else lParam = (owner == GetActiveWindow()); if( ICONTITLE_Paint( hWnd, owner, (HDC)wParam, (BOOL)lParam ) ) ValidateRect( hWnd, NULL ); return 1; } return DefWindowProcW( hWnd, msg, wParam, lParam ); }
/** * * rct2: 0x00407978 */ int osinterface_407978(rct2_install_info* install_info, char* source, char* font, uint8 charset) { char subkey[MAX_PATH]; char subkey2[MAX_PATH]; strcpy(subkey, "Software\\Infogrames\\"); strcat(subkey, source); strcpy(subkey2, "Software\\Fish Technology Group\\"); strcat(subkey2, source); LOGFONTA lf; memset(&lf, 0, sizeof(lf)); lf.lfCharSet = charset; lf.lfHeight = 12; lf.lfWeight = 400; strcpy(lf.lfFaceName, font); RCT2_GLOBAL(RCT2_ADDRESS_HFONT, HFONT) = CreateFontIndirectA(&lf); HKEY hkey; if (RegOpenKeyA(HKEY_LOCAL_MACHINE, subkey, &hkey) != ERROR_SUCCESS && RegOpenKeyA(HKEY_LOCAL_MACHINE, subkey2, &hkey) != ERROR_SUCCESS) { return 0; } else { DWORD type; DWORD size = 260; RegQueryValueExA(hkey, "Title", 0, &type, install_info->title, &size); size = 260; RegQueryValueExA(hkey, "Path", 0, &type, install_info->path, &size); install_info->var_20C = 235960; size = 4; RegQueryValueExA(hkey, "InstallLevel", 0, &type, (LPBYTE)&install_info->installlevel, &size); for (int i = 0; i <= 15; i++) { char name[100]; sprintf(name, "AddonPack%d", i); size = sizeof(install_info->addon[i]); if (RegQueryValueExA(hkey, name, 0, &type, install_info->addon[i], &size) == ERROR_SUCCESS) { install_info->addons |= (1 << i); } } RegCloseKey(hkey); 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); }
HOOKFUNC HFONT WINAPI MyCreateFontIndirectA(CONST LOGFONTA *lplf) { ENTER(lplf->lfQuality, lplf->lfCharSet, lplf->lfFaceName); if (lplf->lfQuality != NONANTIALIASED_QUALITY) ((LOGFONTA*)lplf)->lfQuality = ANTIALIASED_QUALITY; // disable ClearType so it doesn't get into AVIs HFONT rv; if (tasflags.appLocale && (lplf->lfCharSet == LocaleToCharset(tasflags.appLocale) || (/*tasflags.movieVersion >= 79 && */(lplf->lfCharSet == DEFAULT_CHARSET || lplf->lfCharSet == OEM_CHARSET))) /*&& lplf->lfCharSet != LocaleToCharset(GetACP())*/) { // since windows 2000, the CreateFont functions can recognize either the localized or unlocalized font name. // but, they still can't recognize the localized font name in the incorrect codepage. str_to_wstr(wstr, lplf->lfFaceName, LocaleToCodePage(tasflags.appLocale)); LOGFONTW fontw; memcpy(&fontw, lplf, (int)&fontw.lfFaceName - (int)&fontw); wcscpy(fontw.lfFaceName, wstr); if (/*tasflags.movieVersion >= 79 && */tasflags.appLocale == 1041 && !DoesFontExistW(&fontw)) { wcscpy(fontw.lfFaceName, _L(DEFAULT_FONT_FOR_LOCALE_1041)); if (!DoesFontExistW(&fontw)) wcscpy(fontw.lfFaceName, wstr); } rv = CreateFontIndirectW(&fontw); } else { rv = CreateFontIndirectA(lplf); } return rv; }
void LoadClcOptions(HWND hwnd,struct ClcData *dat) { int i; // dat->rowHeight=DBGetContactSettingByte(NULL,"CLC","RowHeight",CLCDEFAULT_ROWHEIGHT); { LOGFONTA lf; HFONT holdfont; SIZE fontSize; HDC hdc=GetDC(hwnd); for(i=0;i<=FONTID_MAX;i++) { if(!dat->fontInfo[i].changed) DeleteObject(dat->fontInfo[i].hFont); GetFontSetting(i,&lf,&dat->fontInfo[i].colour); { LONG height; HDC hdc=GetDC(NULL); height=lf.lfHeight; lf.lfHeight=-MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72); ReleaseDC(NULL,hdc); dat->fontInfo[i].hFont=CreateFontIndirectA(&lf); lf.lfHeight=height; } dat->fontInfo[i].changed=0; holdfont=SelectObject(hdc,dat->fontInfo[i].hFont); GetTextExtentPoint32A(hdc,"x",1,&fontSize); dat->fontInfo[i].fontHeight=fontSize.cy; // if(fontSize.cy>dat->rowHeight && (!DBGetContactSettingByte(NULL,"CLC","DoNotCheckFontSize",0))) dat->rowHeight=fontSize.cy; if(holdfont) SelectObject(hdc,holdfont); } ReleaseDC(hwnd,hdc); } // Row dat->row_min_heigh = DBGetContactSettingWord(NULL,"CList","MinRowHeight",CLCDEFAULT_ROWHEIGHT); dat->row_border = DBGetContactSettingWord(NULL,"CList","RowBorder",2); dat->row_variable_height = DBGetContactSettingByte(NULL,"CList","VariableRowHeight",1); dat->row_align_left_items_to_left = DBGetContactSettingByte(NULL,"CList","AlignLeftItemsToLeft",1); dat->row_hide_group_icon = DBGetContactSettingByte(NULL,"CList","HideGroupsIcon",0); dat->row_align_right_items_to_right = DBGetContactSettingByte(NULL,"CList","AlignRightItemsToRight",1); //TODO: Add to settings dat->row_align_group_mode=DBGetContactSettingByte(NULL,"CList","AlignGroupCaptions",0); for (i = 0 ; i < NUM_ITEM_TYPE ; i++) { char tmp[128]; mir_snprintf(tmp, sizeof(tmp), "RowPos%d", i); dat->row_items[i] = DBGetContactSettingWord(NULL, "CList", tmp, i); } // Avatar if (hwndContactTree == hwnd || hwndContactTree==NULL) { dat->avatars_show = DBGetContactSettingByte(NULL,"CList","AvatarsShow",0); dat->avatars_draw_border = DBGetContactSettingByte(NULL,"CList","AvatarsDrawBorders",0); dat->avatars_border_color = (COLORREF)DBGetContactSettingDword(NULL,"CList","AvatarsBorderColor",0); dat->avatars_round_corners = DBGetContactSettingByte(NULL,"CList","AvatarsRoundCorners",1); dat->avatars_use_custom_corner_size = DBGetContactSettingByte(NULL,"CList","AvatarsUseCustomCornerSize",0); dat->avatars_custom_corner_size = DBGetContactSettingWord(NULL,"CList","AvatarsCustomCornerSize",4); dat->avatars_ignore_size_for_row_height = DBGetContactSettingByte(NULL,"CList","AvatarsIgnoreSizeForRow",0); dat->avatars_draw_overlay = DBGetContactSettingByte(NULL,"CList","AvatarsDrawOverlay",0); dat->avatars_overlay_type = DBGetContactSettingByte(NULL,"CList","AvatarsOverlayType",SETTING_AVATAR_OVERLAY_TYPE_NORMAL); dat->avatars_size = DBGetContactSettingWord(NULL,"CList","AvatarsSize",30); } else { dat->avatars_show = 0; dat->avatars_draw_border = 0; dat->avatars_border_color = 0; dat->avatars_round_corners = 0; dat->avatars_use_custom_corner_size = 0; dat->avatars_custom_corner_size = 4; dat->avatars_ignore_size_for_row_height = 0; dat->avatars_draw_overlay = 0; dat->avatars_overlay_type = SETTING_AVATAR_OVERLAY_TYPE_NORMAL; dat->avatars_size = 30; } // Icon if (hwndContactTree == hwnd|| hwndContactTree==NULL) { dat->icon_hide_on_avatar = DBGetContactSettingByte(NULL,"CList","IconHideOnAvatar",0); dat->icon_draw_on_avatar_space = DBGetContactSettingByte(NULL,"CList","IconDrawOnAvatarSpace",0); dat->icon_ignore_size_for_row_height = DBGetContactSettingByte(NULL,"CList","IconIgnoreSizeForRownHeight",0); } else { dat->icon_hide_on_avatar = 0; dat->icon_draw_on_avatar_space = 0; dat->icon_ignore_size_for_row_height = 0; } // Contact time if (hwndContactTree == hwnd|| hwndContactTree==NULL) { dat->contact_time_show = DBGetContactSettingByte(NULL,"CList","ContactTimeShow",0); dat->contact_time_show_only_if_different = DBGetContactSettingByte(NULL,"CList","ContactTimeShowOnlyIfDifferent",1); } else { dat->contact_time_show = 0; dat->contact_time_show_only_if_different = 0; } { const time_t now = time(NULL); struct tm gmt = *gmtime(&now); time_t gmt_time; //gmt.tm_isdst = -1; gmt_time = mktime(&gmt); dat->local_gmt_diff = (int)difftime(now, gmt_time); gmt = *gmtime(&now); gmt.tm_isdst = -1; gmt_time = mktime(&gmt); dat->local_gmt_diff_dst = (int)difftime(now, gmt_time); } // Text dat->text_rtl = DBGetContactSettingByte(NULL,"CList","TextRTL",0); dat->text_align_right = DBGetContactSettingByte(NULL,"CList","TextAlignToRight",0); dat->text_replace_smileys = DBGetContactSettingByte(NULL,"CList","TextReplaceSmileys",1); dat->text_resize_smileys = DBGetContactSettingByte(NULL,"CList","TextResizeSmileys",1); dat->text_smiley_height = 0; dat->text_use_protocol_smileys = DBGetContactSettingByte(NULL,"CList","TextUseProtocolSmileys",1); if (hwndContactTree == hwnd|| hwndContactTree==NULL) { dat->text_ignore_size_for_row_height = DBGetContactSettingByte(NULL,"CList","TextIgnoreSizeForRownHeight",0); } else { dat->text_ignore_size_for_row_height = 0; } // First line dat->first_line_draw_smileys = DBGetContactSettingByte(NULL,"CList","FirstLineDrawSmileys",1); // Second line if (hwndContactTree == hwnd || hwndContactTree==NULL) { dat->second_line_show = DBGetContactSettingByte(NULL,"CList","SecondLineShow",1); dat->second_line_top_space = DBGetContactSettingWord(NULL,"CList","SecondLineTopSpace",2); dat->second_line_draw_smileys = DBGetContactSettingByte(NULL,"CList","SecondLineDrawSmileys",1); dat->second_line_type = DBGetContactSettingWord(NULL,"CList","SecondLineType",TEXT_STATUS_MESSAGE); { DBVARIANT dbv; if (!DBGetContactSettingTString(NULL, "CList","SecondLineText", &dbv)) { lstrcpyn(dat->second_line_text, dbv.ptszVal, SIZEOF(dat->second_line_text)-1); dat->second_line_text[SIZEOF(dat->second_line_text)-1] = '\0'; DBFreeVariant(&dbv); } else { dat->second_line_text[0] = '\0'; } } dat->second_line_xstatus_has_priority = DBGetContactSettingByte(NULL,"CList","SecondLineXStatusHasPriority",1); dat->second_line_show_status_if_no_away=DBGetContactSettingByte(NULL,"CList","SecondLineShowStatusIfNoAway",0); dat->second_line_use_name_and_message_for_xstatus = DBGetContactSettingByte(NULL,"CList","SecondLineUseNameAndMessageForXStatus",0); } else { dat->second_line_show = 0; dat->second_line_top_space = 0; dat->second_line_draw_smileys = 0; dat->second_line_type = TEXT_STATUS_MESSAGE; dat->second_line_text[0] = '\0'; dat->second_line_xstatus_has_priority = 1; dat->second_line_use_name_and_message_for_xstatus = 0; } // Third line if (hwndContactTree == hwnd || hwndContactTree==NULL) { dat->third_line_show = DBGetContactSettingByte(NULL,"CList","ThirdLineShow",0); dat->third_line_top_space = DBGetContactSettingWord(NULL,"CList","ThirdLineTopSpace",2); dat->third_line_draw_smileys = DBGetContactSettingByte(NULL,"CList","ThirdLineDrawSmileys",0); dat->third_line_type = DBGetContactSettingWord(NULL,"CList","ThirdLineType",TEXT_STATUS); { DBVARIANT dbv; if (!DBGetContactSettingTString(NULL, "CList","ThirdLineText", &dbv)) { lstrcpyn(dat->third_line_text, dbv.ptszVal, SIZEOF(dat->third_line_text)-1); dat->third_line_text[SIZEOF(dat->third_line_text)-1] = '\0'; DBFreeVariant(&dbv); } else { dat->third_line_text[0] = '\0'; } } dat->third_line_xstatus_has_priority = DBGetContactSettingByte(NULL,"CList","ThirdLineXStatusHasPriority",1); dat->third_line_show_status_if_no_away=DBGetContactSettingByte(NULL,"CList","ThirdLineShowStatusIfNoAway",0); dat->third_line_use_name_and_message_for_xstatus = DBGetContactSettingByte(NULL,"CList","ThirdLineUseNameAndMessageForXStatus",0); } else { dat->third_line_show = 0; dat->third_line_top_space = 0; dat->third_line_draw_smileys = 0; dat->third_line_type = TEXT_STATUS_MESSAGE; dat->third_line_text[0] = '\0'; dat->third_line_xstatus_has_priority = 1; dat->third_line_use_name_and_message_for_xstatus = 0; } dat->leftMargin=DBGetContactSettingByte(NULL,"CLC","LeftMargin",CLCDEFAULT_LEFTMARGIN); dat->rightMargin=DBGetContactSettingByte(NULL,"CLC","RightMargin",CLCDEFAULT_RIGHTMARGIN); dat->exStyle=DBGetContactSettingDword(NULL,"CLC","ExStyle",GetDefaultExStyle()); dat->scrollTime=DBGetContactSettingWord(NULL,"CLC","ScrollTime",CLCDEFAULT_SCROLLTIME); dat->force_in_dialog=0; dat->groupIndent=DBGetContactSettingByte(NULL,"CLC","GroupIndent",CLCDEFAULT_GROUPINDENT); dat->subIndent=DBGetContactSettingByte(NULL,"CLC","SubIndent",CLCDEFAULT_GROUPINDENT); dat->gammaCorrection=DBGetContactSettingByte(NULL,"CLC","GammaCorrect",CLCDEFAULT_GAMMACORRECT); dat->showIdle=DBGetContactSettingByte(NULL,"CLC","ShowIdle",CLCDEFAULT_SHOWIDLE); dat->noVScrollbar=DBGetContactSettingByte(NULL,"CLC","NoVScrollBar",0); SendMessage(hwnd,INTM_SCROLLBARCHANGED,0,0); //ShowScrollBar(hwnd,SB_VERT,dat->noVScrollbar==1 ? FALSE : TRUE); if(!dat->bkChanged) { DBVARIANT dbv; dat->bkColour=DBGetContactSettingDword(NULL,"CLC","BkColour",CLCDEFAULT_BKCOLOUR); if(dat->hBmpBackground) {DeleteObject(dat->hBmpBackground); dat->hBmpBackground=NULL;} if(DBGetContactSettingByte(NULL,"CLC","UseBitmap",CLCDEFAULT_USEBITMAP)) { if(!DBGetContactSetting(NULL,"CLC","BkBitmap",&dbv)) { dat->hBmpBackground=(HBITMAP)CallService(MS_UTILS_LOADBITMAP,0,(LPARAM)dbv.pszVal); mir_free(dbv.pszVal); DBFreeVariant(&dbv); } } dat->backgroundBmpUse=DBGetContactSettingWord(NULL,"CLC","BkBmpUse",CLCDEFAULT_BKBMPUSE); dat->MenuBkColor=DBGetContactSettingDword(NULL,"Menu","BkColour",CLCDEFAULT_BKCOLOUR); dat->MenuBkHiColor=DBGetContactSettingDword(NULL,"Menu","SelBkColour",CLCDEFAULT_SELBKCOLOUR); dat->MenuTextColor=DBGetContactSettingDword(NULL,"Menu","TextColour",CLCDEFAULT_TEXTCOLOUR); dat->MenuTextHiColor=DBGetContactSettingDword(NULL,"Menu","SelTextColour",CLCDEFAULT_SELTEXTCOLOUR); if (dat->hMenuBackground) {DeleteObject(dat->hMenuBackground); dat->hMenuBackground=NULL;} if(DBGetContactSettingByte(NULL,"Menu","UseBitmap",CLCDEFAULT_USEBITMAP)) { if(!DBGetContactSetting(NULL,"Menu","BkBitmap",&dbv)) { dat->hMenuBackground=(HBITMAP)CallService(MS_UTILS_LOADBITMAP,0,(LPARAM)dbv.pszVal); mir_free(dbv.pszVal); DBFreeVariant(&dbv); } } dat->MenuBmpUse=DBGetContactSettingWord(NULL,"Menu","BkBmpUse",CLCDEFAULT_BKBMPUSE); } dat->greyoutFlags=DBGetContactSettingDword(NULL,"CLC","GreyoutFlags",CLCDEFAULT_GREYOUTFLAGS); dat->offlineModes=DBGetContactSettingDword(NULL,"CLC","OfflineModes",CLCDEFAULT_OFFLINEMODES); dat->selBkColour=DBGetContactSettingDword(NULL,"CLC","SelBkColour",CLCDEFAULT_SELBKCOLOUR); dat->selTextColour=DBGetContactSettingDword(NULL,"CLC","SelTextColour",CLCDEFAULT_SELTEXTCOLOUR); dat->hotTextColour=DBGetContactSettingDword(NULL,"CLC","HotTextColour",CLCDEFAULT_HOTTEXTCOLOUR); dat->quickSearchColour=DBGetContactSettingDword(NULL,"CLC","QuickSearchColour",CLCDEFAULT_QUICKSEARCHCOLOUR); dat->IsMetaContactsEnabled= DBGetContactSettingByte(NULL,"MetaContacts","Enabled",1) && ServiceExists(MS_MC_GETDEFAULTCONTACT); { dat->MetaIgnoreEmptyExtra=DBGetContactSettingByte(NULL,"CLC","MetaIgnoreEmptyExtra",1); dat->expandMeta=DBGetContactSettingByte(NULL,"CLC","MetaExpanding",1); /* style=GetWindowLong(hwnd,GWL_STYLE); if (dat->MetaIgnoreEmptyExtra) style&=CLS_EX_MULTICOLUMNALIGNLEFT; else style&=!(CLS_EX_MULTICOLUMNALIGNLEFT) */ } { NMHDR hdr; hdr.code=CLN_OPTIONSCHANGED; hdr.hwndFrom=hwnd; hdr.idFrom=GetDlgCtrlID(hwnd); SendMessage(GetParent(hwnd),WM_NOTIFY,0,(LPARAM)&hdr); } SendMessage(hwnd,WM_SIZE,0,0); }
bool setFont(const char * pFontName = nullptr, int nSize = 0) { bool bRet = false; do { std::string fontName = pFontName; std::string fontPath; HFONT hDefFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LOGFONTA tNewFont = {0}; LOGFONTA tOldFont = {0}; GetObjectA(hDefFont, sizeof(tNewFont), &tNewFont); if (fontName.c_str()) { // create font from ttf file int nFindttf = fontName.find(".ttf"); int nFindTTF = fontName.find(".TTF"); if (nFindttf >= 0 || nFindTTF >= 0) { fontPath = FileUtils::getInstance()->fullPathForFilename(fontName.c_str()); int nFindPos = fontName.rfind("/"); fontName = &fontName[nFindPos+1]; nFindPos = fontName.rfind("."); fontName = fontName.substr(0,nFindPos); } else { auto nFindPos = fontName.rfind("/"); if (nFindPos != fontName.npos) { if (fontName.length() == nFindPos + 1) { fontName = ""; } else { fontName = &fontName[nFindPos+1]; } } } tNewFont.lfCharSet = DEFAULT_CHARSET; strcpy_s(tNewFont.lfFaceName, LF_FACESIZE, fontName.c_str()); } if (nSize) { tNewFont.lfHeight = -nSize; } GetObjectA(_font, sizeof(tOldFont), &tOldFont); if (tOldFont.lfHeight == tNewFont.lfHeight && 0 == strcmp(tOldFont.lfFaceName, tNewFont.lfFaceName)) { // already has the font bRet = true; break; } // delete old font removeCustomFont(); if (fontPath.size() > 0) { _curFontPath = fontPath; wchar_t * pwszBuffer = utf8ToUtf16(_curFontPath); if (pwszBuffer) { if(AddFontResource(pwszBuffer)) { SendMessage( _wnd, WM_FONTCHANGE, 0, 0); } delete [] pwszBuffer; pwszBuffer = nullptr; } } _font = nullptr; // disable Cleartype tNewFont.lfQuality = ANTIALIASED_QUALITY; // create new font _font = CreateFontIndirectA(&tNewFont); if (! _font) { // create failed, use default font _font = hDefFont; break; } bRet = true; } while (0); return bRet; }
bool setFont(const char * pFontName = NULL, int nSize = 0) { bool bRet = false; do { std::string fontName = pFontName; std::string fontPath; HFONT hDefFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LOGFONTA tNewFont = {0}; LOGFONTA tOldFont = {0}; GetObjectA(hDefFont, sizeof(tNewFont), &tNewFont); if (fontName.c_str()) { // create font from ttf file int nFindttf = fontName.find(".ttf"); int nFindTTF = fontName.find(".TTF"); if (nFindttf >= 0 || nFindTTF >= 0) { fontPath = CCFileUtils::fullPathFromRelativePath(fontName.c_str()); int nFindPos = fontName.rfind("/"); fontName = &fontName[nFindPos+1]; nFindPos = fontName.rfind("."); fontName = fontName.substr(0,nFindPos); } tNewFont.lfCharSet = DEFAULT_CHARSET; strcpy_s(tNewFont.lfFaceName, LF_FACESIZE, fontName.c_str()); } if (nSize) { tNewFont.lfHeight = -nSize; } GetObjectA(m_hFont, sizeof(tOldFont), &tOldFont); if (tOldFont.lfHeight == tNewFont.lfHeight && ! strcpy(tOldFont.lfFaceName, tNewFont.lfFaceName)) { // already has the font bRet = true; break; } // delete old font if (m_hFont != hDefFont) { DeleteObject(m_hFont); // release old font register if (m_curFontPath.size() > 0) { RemoveFontResource(m_curFontPath.c_str()); SendMessage(m_hWnd, WM_FONTCHANGE, 0, 0); } fontPath.size()>0?(m_curFontPath = fontPath):(m_curFontPath.clear()); // register temp font if (m_curFontPath.size() > 0) { AddFontResource(m_curFontPath.c_str()); SendMessage(m_hWnd, WM_FONTCHANGE, 0, 0); } } m_hFont = NULL; // create new font m_hFont = CreateFontIndirectA(&tNewFont); if (! m_hFont) { // create failed, use default font m_hFont = hDefFont; break; } bRet = true; } while (0); return bRet; }
bool setFont(const char * pFontName = NULL, int nSize = 0) { bool bRet = false; do { std::string fontName = pFontName; std::string fontPath; HFONT hDefFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LOGFONTA tNewFont = {0}; LOGFONTA tOldFont = {0}; GetObjectA(hDefFont, sizeof(tNewFont), &tNewFont); if (fontName.c_str()) { // create font from ttf file int nFindttf = fontName.find(".ttf"); int nFindTTF = fontName.find(".TTF"); if (nFindttf >= 0 || nFindTTF >= 0) { fontPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(fontName.c_str()); int nFindPos = fontName.rfind("/"); fontName = &fontName[nFindPos+1]; nFindPos = fontName.rfind("."); fontName = fontName.substr(0,nFindPos); } else { size_t nFindPos = fontName.rfind("/"); if (nFindPos != fontName.npos) { if (fontName.length() == nFindPos + 1) { fontName = ""; } else { fontName = &fontName[nFindPos+1]; } } } tNewFont.lfCharSet = DEFAULT_CHARSET; #if defined(__MINGW32__) strcpy(tNewFont.lfFaceName, fontName.c_str()); #elif defined(_MSC_VER) && _MSC_VER <= 1200 strcpy(tNewFont.lfFaceName, fontName.c_str()); #else strcpy_s(tNewFont.lfFaceName, LF_FACESIZE, fontName.c_str()); #endif } if (nSize) { tNewFont.lfHeight = -nSize; } GetObjectA(m_hFont, sizeof(tOldFont), &tOldFont); if (tOldFont.lfHeight == tNewFont.lfHeight && 0 == strcmp(tOldFont.lfFaceName, tNewFont.lfFaceName)) { // already has the font bRet = true; break; } // delete old font if (m_hFont != hDefFont) { DeleteObject(m_hFont); // release old font register if (m_curFontPath.size() > 0) { wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath); if (pwszBuffer) { if(RemoveFontResourceW(pwszBuffer)) { SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0); } delete [] pwszBuffer; pwszBuffer = NULL; } } if (fontPath.size() > 0) m_curFontPath = fontPath; else #if defined(_MSC_VER) && _MSC_VER <= 1200 m_curFontPath.erase(); #else m_curFontPath.clear(); #endif // register temp font if (m_curFontPath.size() > 0) { wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath); if (pwszBuffer) { if(AddFontResourceW(pwszBuffer)) { SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0); } delete [] pwszBuffer; pwszBuffer = NULL; } } } m_hFont = NULL; // disable Cleartype tNewFont.lfQuality = ANTIALIASED_QUALITY; // create new font m_hFont = CreateFontIndirectA(&tNewFont); if (! m_hFont) { // create failed, use default font m_hFont = hDefFont; break; } bRet = true; } while (0); return bRet; }
// --------------------------------------------------------------------------- // CWinMenubar::AboutProc() // Dialog Window proc for About dialog // --------------------------------------------------------------------------- BOOL CALLBACK CWinMenubar::AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); // unless SDK_REGISTRATION is defined switch (message) { case WM_INITDIALOG: { TCHAR text[128]; CWinMenubar* menubar = (CWinMenubar*)lParam; HINSTANCE hMod = menubar->ModuleHandle(); GetWindowText(GetParent(hDlg), text, sizeof(text)/sizeof(text[0])); SetWindowText(hDlg, text); HBITMAP hBitmap = NULL; UINT textScrollID = IDC_ABOUT_TEXT_SCROLL; UINT textNoScrollID = IDC_ABOUT_TEXT_NO_SCROLL; UINT setTextMsg = WM_SETTEXT; WPARAM setTextParam = 0; SETTEXTEX setText; setText.flags = ST_SELECTION; setText.codepage = CP_ACP; char* aboutText = NULL; if (menubar->iRichEdit) { aboutText = ReadTextFile(ABOUTBOX_RTF_FILE); } if (aboutText) { setTextMsg = EM_SETTEXTEX; textScrollID = textNoScrollID = IDC_ABOUT_RICHTEXT; setTextParam = (WPARAM)&setText; hBitmap = LoadBitmap(hMod,MAKEINTRESOURCE(IDB_JAVA_POWERED)); #ifdef HAVE_WLIB HWND hText = GetDlgItem(hDlg, IDC_ABOUT_RICHTEXT); SendMessage(hText, EM_SETEVENTMASK, 0, SendMessage(hText, EM_GETEVENTMASK, 0,0) | ENM_LINK); SendMessage(hText, EM_AUTOURLDETECT, TRUE, 0); #endif // HAVE_WLIB } if (!aboutText && menubar->iRichEdit) { // Load default about text from the resource void* ptr = NULL; UINT size = 0; HGLOBAL hg = 0; HRSRC hr = FindResourceA(hMod,MAKEINTRESOURCEA(IDR_ABOUT_RTF),"RTF"); if (hr) { size = SizeofResource(ModuleHandle(), hr); hg = LoadResource(ModuleHandle(), hr); ptr = LockResource(hg); } if (ptr) { aboutText = (char*)Alloc(size+1); if (aboutText) { memcpy(aboutText, ptr, size); aboutText[size] = 0; setTextMsg = EM_SETTEXTEX; textScrollID = IDC_ABOUT_RICHTEXT; textNoScrollID = IDC_ABOUT_RICHTEXT; hBitmap = LoadBitmap(hMod,MAKEINTRESOURCE(IDB_JAVA_POWERED)); setTextParam = (WPARAM)&setText; } UnlockResource(hg); } } if (aboutText) { // Check if we need the scrollbar. 12 lines of text // will fit into the edit control. HWND hText = GetDlgItem(hDlg, textNoScrollID); SendMessageA(hText,setTextMsg,setTextParam,(LPARAM)aboutText); if (SendMessageA(hText, EM_GETLINECOUNT,0,0) <= 12) { // No need for the scrollbar, show the edit // control without the WS_VSCROLL style ShowWindow(hText, SW_SHOWNORMAL); } else { // We need the vertical scrollbar, show the edit control // with the WS_VSCROLL style. Note that textScrollID and // textNoScrollID may point to the same window, so reset // the text in the control (bug #DPEV-6JUJSQ) hText = GetDlgItem(hDlg, textScrollID); SendMessageA(hText,WM_SETTEXT,0,(LPARAM)""); SendMessageA(hText,setTextMsg,setTextParam,(LPARAM)aboutText); ShowWindow(hText, SW_SHOWNORMAL); } // Add full SDK name to the RichEdit control by replacing <sdk_name> tag with the // name defined in SdkProductInfo.h. Note that decision between MIDP and C++ SDK // product names is made using CWinMenubar iMidpSdk member. static const TCHAR keywordHeading[] = TEXT("<sdk_name>"); static const UINT keywordHeadingLen = COUNT(keywordHeading)-1; FINDTEXT findHeading; ZeroMemory(&findHeading, sizeof(findHeading)); findHeading.chrg.cpMax = -1; findHeading.lpstrText = (LPTSTR)keywordHeading; // Select whole content SendMessage(hText, EM_SETSEL, 0, 0); // Find from selection int pos = SendMessage(hText,EM_FINDTEXT, FR_MATCHCASE|FR_DOWN, (LPARAM)&findHeading); if (pos >= 0) { // Sdk name tag found IRichEditOle* re = NULL; SendMessage(hText, EM_GETOLEINTERFACE, 0, (LPARAM)&re); if (re) { // Select SDK name tag and replace it with the full SDK name SendMessage(hText, EM_SETSEL, pos, pos+keywordHeadingLen); if(menubar->iMidpSDK) SendMessage(hText, EM_REPLACESEL, true, (LPARAM)TEXT(SDK_FULL_PRODUCT_NAME_MIDP)); else SendMessage(hText, EM_REPLACESEL, true, (LPARAM)TEXT(SDK_FULL_PRODUCT_NAME_CPP)); re->Release(); } } if (hBitmap) { static const TCHAR keyword[] = TEXT("<java logo>"); static const UINT keywordLen = COUNT(keyword)-1; FINDTEXT find; ZeroMemory(&find, sizeof(find)); find.chrg.cpMax = -1; find.lpstrText = (LPTSTR)keyword; SendMessage(hText, EM_SETSEL, 0, 0); int pos = SendMessage(hText,EM_FINDTEXT, FR_MATCHCASE|FR_DOWN, (LPARAM)&find); if (pos >= 0) { IRichEditOle* re = NULL; SendMessage(hText, EM_GETOLEINTERFACE, 0, (LPARAM)&re); if (re) { CImageDataObject* bmp = new CImageDataObject(hBitmap); if (bmp) { SendMessage(hText,EM_SETSEL,pos,pos+keywordLen); bmp->Insert(re); bmp->Release(); } re->Release(); } } } Free(aboutText); } #ifdef SDK_REGISTRATION // Show product key if (gRegProductContext) { HWND hProductKey = GetDlgItem(hDlg, IDC_PRODUCT_KEY); const char* szKey = REG_ProductKey(gRegProductContext); SetWindowTextA(hProductKey, szKey); // The control is created invisible, show it ShowWindow(hProductKey, SW_SHOWNORMAL); if (REG_ProductStatus(gRegProductContext) != RegRegistered) { // Show the Register button ShowWindow(GetDlgItem(hDlg, IDC_REGISTER), SW_SHOWNORMAL); } } #endif // SDK_REGISTRATION // Subclass the product name control HWND hName = GetDlgItem(hDlg, IDC_PRODUCT_NAME); HINSTANCE hInst = (HINSTANCE)GetWindowLong(hDlg,GWL_HINSTANCE); if (hName) { // Allocate TitleData structure. It will be deallocated // by TitleWndProc when it receives WM_DESTROY message TitleData* data = (TitleData*)malloc(sizeof(TitleData)); if (data) { LOGFONTA logFont; ZeroMemory(data, sizeof(*data)); ZeroMemory(&logFont, sizeof(logFont)); logFont.lfHeight = 24; logFont.lfWeight = FW_BOLD; logFont.lfCharSet = ANSI_CHARSET; logFont.lfOutPrecision = OUT_DEFAULT_PRECIS; logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; logFont.lfQuality = ANTIALIASED_QUALITY; logFont.lfPitchAndFamily = VARIABLE_PITCH; // Try Nokia font first strcpy(logFont.lfFaceName, "Nokia Sans"); data->hFont = CreateFontIndirectA(&logFont); if (!data->hFont) { // No Nokia font, try Arial then strcpy(logFont.lfFaceName, "Arial"); data->hFont = CreateFontIndirectA(&logFont); } // Load bitmaps data->hBitmap = LoadBitmapA(hInst, MAKEINTRESOURCEA(IDB_ABOUT_TOP)); // load product name from the file data->productName = ReadTextFile(PRODUCTNAME_FILE); data->productId = menubar->GetProductId(); // Request initial bitmap data->bRepaint = TRUE; #ifdef SDK_REGISTRATION data->hGradientBitmap = LoadBitmapA(hInst, MAKEINTRESOURCEA(IDB_ABOUT_GRADIENT)); if (gRegProductContext) { data->scrollText = TitleCreateScrollData(hName, gRegProductContext); if (data->scrollText) { // Initial delay SetTimer(hName, SCROLL_DELAY_TIMER, SCROLL_TIMER_DELAY, NULL); } } #endif // SDK_REGISTRATION // Subclass the window data->superProc = (WNDPROC)GetWindowLong(hName,GWL_WNDPROC); SetWindowLong(hName, GWL_USERDATA, (LONG)data); SetWindowLong(hName, GWL_WNDPROC, (LONG)TitleWndProc); } } #ifdef HAVE_WLIB WIN32_CenterWindow(hDlg, NULL); #endif // HAVE_WLIB return TRUE; } case WM_COMMAND: switch (wParam) { #ifdef SDK_REGISTRATION case IDC_REGISTER: if (REG_RegisterNow(gRegProductContext, hDlg)) { TitleStopScroller(hDlg); // Update the scroller HWND hTitle = GetDlgItem(hDlg, IDC_PRODUCT_NAME); ScrollTextData* scroll = TitleCreateScrollData( hTitle, gRegProductContext); if (scroll) { TitleData* data; data = (TitleData*)GetWindowLong(hTitle,GWL_USERDATA); TitleDeleteScrollData(data->scrollText); data->scrollText = scroll; } } if (REG_ProductStatus(gRegProductContext) == RegRegistered) { // The button has served its purpose. Hide it ShowWindow(GetDlgItem(hDlg, IDC_REGISTER), SW_HIDE); } return TRUE; #endif // SDK_REGISTRATION case IDOK: case IDCANCEL: EndDialog(hDlg, wParam); return TRUE; default: return FALSE; } #ifdef HAVE_WLIB // Need wlib to use WIN32_BrowseURL case WM_NOTIFY: if (((LPNMHDR)lParam)->idFrom == IDC_ABOUT_RICHTEXT) { char url[256]; ENLINK* link = (ENLINK*)lParam; if (link->msg == WM_LBUTTONDOWN && (link->chrg.cpMax - link->chrg.cpMin) < (COUNT(url)/2-1)) // EM_GETTEXTRANGE may think it's in WCHARs { // Visual effect HWND hText = link->nmhdr.hwndFrom; SendMessage(hText,EM_SETSEL,link->chrg.cpMin,link->chrg.cpMax); // It's not very clear what EM_GETTEXTRANGE message writes // into the buffer. Since we use SendMessageA (ANSI API), // I would expect that it returns ANSI string as most other // text-related messages do. Yet, at least some versions of // RichEdit control seem to return UCS-2 characters. Internet // search produces conflicting results. Let's be prepared for // anything. After all, there are only two possiblities. It's // either UCS-2 or ASCII. TEXTRANGEA range; range.chrg = link->chrg; range.lpstrText = url; url[0] = url[1] = 0; SendMessageA(hText, EM_GETTEXTRANGE, 0, (LPARAM)&range); url[COUNT(url)-1] = url[COUNT(url)-2] = 0; if (!_wcsnicmp((WCHAR*)url,L"http://",7)) { // Looks like UCS-2 string to me. Convert it to ASCII LPWSTR w = (WCHAR*)url; LPSTR p = url; do { *p++ = (char)*w++; } while (*w); *p = 0; } // Start the default browser WIN32_BrowseURL(url); } } // Usually, the return value is ignored return FALSE; #endif // HAVE_WLIB #ifdef SDK_REGISTRATION case WM_CTLCOLORSTATIC: // We don't want the product key edit control to erase its // background because it's drawn on top of the product name // bitmap (white cloud). { int nDlgCtrlID = GetDlgCtrlID((HWND)lParam); switch (nDlgCtrlID) { case IDC_PRODUCT_KEY: // Return transparent brush for the product key control return (BOOL)GetStockObject(HOLLOW_BRUSH); } } return FALSE; case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: // Stop scrolling on mouse click TitleStopScroller(hDlg); return FALSE; #endif // SDK_REGISTRATION default: return FALSE; } }
HDC hdc = GetDC( 0 ); HFONT hfont; QT_WA( { LOGFONTW lf; memset( &lf, 0, sizeof( LOGFONTW ) ); memcpy( lf.lfFaceName, familyName.utf16(), qMin(LF_FACESIZE, familyName.length())*sizeof(QChar) ); lf.lfCharSet = DEFAULT_CHARSET; hfont = CreateFontIndirectW( &lf ); }, { LOGFONTA lf; memset( &lf, 0, sizeof( LOGFONTA ) ); QByteArray lfam = familyName.toLocal8Bit(); memcpy( lf.lfFaceName, lfam, qMin(LF_FACESIZE, lfam.size()) ); lf.lfCharSet = DEFAULT_CHARSET; hfont = CreateFontIndirectA( &lf ); } ); if(!hfont) { ReleaseDC(0, hdc); return QString(); } HGDIOBJ oldobj = SelectObject( hdc, hfont ); const DWORD name_tag = MAKE_TAG( 'n', 'a', 'm', 'e' ); // get the name table unsigned char *table = 0; DWORD bytes = GetFontData( hdc, name_tag, 0, 0, 0 ); if ( bytes == GDI_ERROR ) {
extern "C" int main(int argc, wchar_t* argv[]) { TRACED_HOOK_HANDLE hHook = new HOOK_TRACE_INFO(); NTSTATUS NtStatus; ULONG ACLEntries[1] = {0}; UNICODE_STRING* NameBuffer = NULL; ORIG_CreateFontIndirectW = CreateFontIndirectW; FORCE(LhInstallHook( ORIG_CreateFontIndirectW, IMPL_CreateFontIndirectW, (PVOID)0, hHook)); FORCE(LhSetInclusiveACL(ACLEntries, 1, hHook)); CreateFontIndirectW(0); CreateFontW(10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"system"); LOGFONTA lf = {}; CreateFontIndirectA(&lf); CreateFontA(12, 0, 0, 0, 400, 0, 0, 0, 2, 0, 0, 0, 0, "MARLETT"); #if 0 ORIG_GetTextExtentPoint32A = GetTextExtentPoint32A; FORCE(LhInstallHook( ORIG_GetTextExtentPoint32A, IMPL_GetTextExtentPoint32A, (PVOID)0, hHook)); HDC hdc = GetDC(NULL); SIZE size; FORCE(LhSetInclusiveACL(ACLEntries, 1, hHook)); GetTextExtentPoint32W(hdc, L"abc", 3, &size); GetTextExtentPointW(hdc, L"abc", 3, &size); GetTextExtentPoint32A(hdc, "abc", 3, &size); GetTextExtentPointA(hdc, "abc", 3, &size); #endif #if 0 ORIG_MessageBeepHook = MessageBeep; /* The following shows how to install and remove local hooks... */ FORCE(LhInstallHook( ORIG_MessageBeepHook, MessageBeepHook, (PVOID)0, hHook)); printf(".\n"); // won't invoke the hook handler because hooks are inactive after installation MessageBeep(123); getch(); BOOL flags = 1; FORCE(LhIsThreadIntercepted(hHook, 0, &flags)); printf("Intercepted %d\n", flags); // activate the hook for the current thread FORCE(LhSetInclusiveACL(ACLEntries, 1, hHook)); FORCE(LhIsThreadIntercepted(hHook, 0, &flags)); printf("Intercepted %d\n", flags); printf(".\n"); // will be redirected into the handler... MessageBeep(123); getch(); FORCE(LhSetGlobalExclusiveACL(ACLEntries, 1)); printf(".\n"); // will be redirected into the handler... MessageBeep(123); getch(); FORCE(LhSetGlobalInclusiveACL(ACLEntries, 1)); printf(".\n"); // will be redirected into the handler... MessageBeep(123); getch(); printf(".\n"); // won't invoke the hook handler because hooks are inactive after installation ORIG_MessageBeepHook(123); getch(); #endif // this will also invalidate "hHook", because it is a traced handle... LhUninstallAllHooks(); // this will do nothing because the hook is already removed... LhUninstallHook(hHook); printf(".\n"); // will be redirected into the handler... MessageBeep(123); getch(); // now we can safely release the traced handle delete hHook; hHook = NULL; // even if the hook is removed, we need to wait for memory release LhWaitForPendingRemovals(); return 0; ERROR_ABORT: if(hHook != NULL) delete hHook; if(NameBuffer != NULL) free(NameBuffer ); printf("\n[Error(0x%p)]: \"%S\" (code: %d {0x%p})\n", (PVOID)NtStatus, RtlGetLastErrorString(), RtlGetLastError(), (PVOID)RtlGetLastError()); _getch(); return NtStatus; }
CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont, FX_BOOL bVert, FX_BOOL bTranslateName) { pLogFont->lfHeight = -1000; pLogFont->lfWidth = 0; HGDIOBJ hFont = CreateFontIndirectA(pLogFont); HDC hDC = CreateCompatibleDC(NULL); hFont = SelectObject(hDC, hFont); int tm_size = GetOutlineTextMetrics(hDC, 0, NULL); if (tm_size == 0) { hFont = SelectObject(hDC, hFont); DeleteObject(hFont); DeleteDC(hDC); return NULL; } LPBYTE tm_buf = FX_Alloc(BYTE, tm_size); OUTLINETEXTMETRIC* ptm = (OUTLINETEXTMETRIC*)tm_buf; GetOutlineTextMetrics(hDC, tm_size, ptm); int flags = 0, italicangle, ascend, descend, capheight, bbox[4]; if (pLogFont->lfItalic) { flags |= PDFFONT_ITALIC; } if ((pLogFont->lfPitchAndFamily & 3) == FIXED_PITCH) { flags |= PDFFONT_FIXEDPITCH; } if ((pLogFont->lfPitchAndFamily & 0xf8) == FF_ROMAN) { flags |= PDFFONT_SERIF; } if ((pLogFont->lfPitchAndFamily & 0xf8) == FF_SCRIPT) { flags |= PDFFONT_SCRIPT; } FX_BOOL bCJK = pLogFont->lfCharSet == CHINESEBIG5_CHARSET || pLogFont->lfCharSet == GB2312_CHARSET || pLogFont->lfCharSet == HANGEUL_CHARSET || pLogFont->lfCharSet == SHIFTJIS_CHARSET; CFX_ByteString basefont; if (bTranslateName && bCJK) { basefont = _FPDF_GetPSNameFromTT(hDC); } if (basefont.IsEmpty()) { basefont = pLogFont->lfFaceName; } italicangle = ptm->otmItalicAngle / 10; ascend = ptm->otmrcFontBox.top; descend = ptm->otmrcFontBox.bottom; capheight = ptm->otmsCapEmHeight; bbox[0] = ptm->otmrcFontBox.left; bbox[1] = ptm->otmrcFontBox.bottom; bbox[2] = ptm->otmrcFontBox.right; bbox[3] = ptm->otmrcFontBox.top; FX_Free(tm_buf); basefont.Replace(" ", ""); CPDF_Dictionary* pBaseDict = FX_NEW CPDF_Dictionary; pBaseDict->SetAtName("Type", "Font"); CPDF_Dictionary* pFontDict = pBaseDict; if (!bCJK) { if (pLogFont->lfCharSet == ANSI_CHARSET || pLogFont->lfCharSet == DEFAULT_CHARSET || pLogFont->lfCharSet == SYMBOL_CHARSET) { if (pLogFont->lfCharSet == SYMBOL_CHARSET) { flags |= PDFFONT_SYMBOLIC; } else { flags |= PDFFONT_NONSYMBOLIC; } pBaseDict->SetAtName(FX_BSTRC("Encoding"), "WinAnsiEncoding"); } else { flags |= PDFFONT_NONSYMBOLIC; int i; for (i = 0; i < sizeof g_FX_CharsetUnicodes / sizeof(FX_CharsetUnicodes); i ++) if (g_FX_CharsetUnicodes[i].m_Charset == pLogFont->lfCharSet) { break; } if (i < sizeof g_FX_CharsetUnicodes / sizeof(FX_CharsetUnicodes)) { CPDF_Dictionary* pEncoding = FX_NEW CPDF_Dictionary; pEncoding->SetAtName(FX_BSTRC("BaseEncoding"), "WinAnsiEncoding"); CPDF_Array* pArray = FX_NEW CPDF_Array; pArray->AddInteger(128); const FX_WCHAR* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; for (int j = 0; j < 128; j ++) { CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); if (name.IsEmpty()) { pArray->AddName(FX_BSTRC(".notdef")); } else { pArray->AddName(name); } } pEncoding->SetAt(FX_BSTRC("Differences"), pArray); AddIndirectObject(pEncoding); pBaseDict->SetAtReference(FX_BSTRC("Encoding"), this, pEncoding); } } if (pLogFont->lfWeight > FW_MEDIUM && pLogFont->lfItalic) { basefont += ",BoldItalic"; } else if (pLogFont->lfWeight > FW_MEDIUM) { basefont += ",Bold"; } else if (pLogFont->lfItalic) { basefont += ",Italic"; } pBaseDict->SetAtName("Subtype", "TrueType"); pBaseDict->SetAtName("BaseFont", basefont); pBaseDict->SetAtNumber("FirstChar", 32); pBaseDict->SetAtNumber("LastChar", 255); int char_widths[224]; GetCharWidth(hDC, 32, 255, char_widths); CPDF_Array* pWidths = FX_NEW CPDF_Array; for (int i = 0; i < 224; i ++) { pWidths->AddInteger(char_widths[i]); } pBaseDict->SetAt("Widths", pWidths); } else { flags |= PDFFONT_NONSYMBOLIC; pFontDict = FX_NEW CPDF_Dictionary; CFX_ByteString cmap; CFX_ByteString ordering; int supplement; CPDF_Array* pWidthArray = FX_NEW CPDF_Array; switch (pLogFont->lfCharSet) { case CHINESEBIG5_CHARSET: cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; ordering = "CNS1"; supplement = 4; pWidthArray->AddInteger(1); _InsertWidthArray(hDC, 0x20, 0x7e, pWidthArray); break; case GB2312_CHARSET: cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H"; ordering = "GB1", supplement = 2; pWidthArray->AddInteger(7716); _InsertWidthArray(hDC, 0x20, 0x20, pWidthArray); pWidthArray->AddInteger(814); _InsertWidthArray(hDC, 0x21, 0x7e, pWidthArray); break; case HANGEUL_CHARSET: cmap = bVert ? "KSCms-UHC-V" : "KSCms-UHC-H"; ordering = "Korea1"; supplement = 2; pWidthArray->AddInteger(1); _InsertWidthArray(hDC, 0x20, 0x7e, pWidthArray); break; case SHIFTJIS_CHARSET: cmap = bVert ? "90ms-RKSJ-V" : "90ms-RKSJ-H"; ordering = "Japan1"; supplement = 5; pWidthArray->AddInteger(231); _InsertWidthArray(hDC, 0x20, 0x7d, pWidthArray); pWidthArray->AddInteger(326); _InsertWidthArray(hDC, 0xa0, 0xa0, pWidthArray); pWidthArray->AddInteger(327); _InsertWidthArray(hDC, 0xa1, 0xdf, pWidthArray); pWidthArray->AddInteger(631); _InsertWidthArray(hDC, 0x7e, 0x7e, pWidthArray); break; } pBaseDict->SetAtName("Subtype", "Type0"); pBaseDict->SetAtName("BaseFont", basefont); pBaseDict->SetAtName("Encoding", cmap); pFontDict->SetAt("W", pWidthArray); pFontDict->SetAtName("Type", "Font"); pFontDict->SetAtName("Subtype", "CIDFontType2"); pFontDict->SetAtName("BaseFont", basefont); CPDF_Dictionary* pCIDSysInfo = FX_NEW CPDF_Dictionary; pCIDSysInfo->SetAtString("Registry", "Adobe"); pCIDSysInfo->SetAtString("Ordering", ordering); pCIDSysInfo->SetAtInteger("Supplement", supplement); pFontDict->SetAt("CIDSystemInfo", pCIDSysInfo); CPDF_Array* pArray = FX_NEW CPDF_Array; pBaseDict->SetAt("DescendantFonts", pArray); AddIndirectObject(pFontDict); pArray->AddReference(this, pFontDict); } AddIndirectObject(pBaseDict); CPDF_Dictionary* pFontDesc = FX_NEW CPDF_Dictionary; pFontDesc->SetAtName("Type", "FontDescriptor"); pFontDesc->SetAtName("FontName", basefont); pFontDesc->SetAtInteger("Flags", flags); CPDF_Array* pBBox = FX_NEW CPDF_Array; for (int i = 0; i < 4; i ++) { pBBox->AddInteger(bbox[i]); } pFontDesc->SetAt("FontBBox", pBBox); pFontDesc->SetAtInteger("ItalicAngle", italicangle); pFontDesc->SetAtInteger("Ascent", ascend); pFontDesc->SetAtInteger("Descent", descend); pFontDesc->SetAtInteger("CapHeight", capheight); pFontDesc->SetAtInteger("StemV", pLogFont->lfWeight / 5); AddIndirectObject(pFontDesc); pFontDict->SetAtReference("FontDescriptor", this, pFontDesc); hFont = SelectObject(hDC, hFont); DeleteObject(hFont); DeleteDC(hDC); return LoadFont(pBaseDict); }
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 LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_CREATE: { // Newer rich edit controls are much faster // http://blogs.msdn.com/b/murrays/archive/2006/10/14/richedit-versions.aspx // https://msdn.microsoft.com/en-us/library/windows/desktop/hh298375.aspx LoadLibraryA("riched20.dll"); CreateWindowA( RICHEDIT_CLASS, "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_READONLY, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, (HMENU)IDC_MESSAGE, g_hInstance, NULL ); // Set the background color to match the disabled edit control DWORD dwColor = GetSysColor(COLOR_3DFACE); SendDlgItemMessage(hwnd, IDC_MESSAGE, EM_SETBKGNDCOLOR, FALSE, dwColor); // We used to use GetStockObject(ANSI_FIXED_FONT), but it's known // to lead to unreliable results, particularly on Russion locales // or high-DPI displays, so now we match Notepad's default font. LOGFONTA lf = { 10, // lfHeight 0, // lfWidth 0, // lfEscapement 0, // lfOrientation FW_NORMAL, // lfWeight FALSE, // lfItalic FALSE, // lfUnderline FALSE, // lfStrikeOut ANSI_CHARSET, // lfCharSet 0, // lfOutPrecision 0, // lfClipPrecision DEFAULT_QUALITY, // lfQuality FIXED_PITCH | FF_MODERN, // lfPitchAndFamily "Lucida Console" // lfFaceName }; // Apply the DPI scale factor // https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266.aspx if (lf.lfHeight > 0) { HDC hdc = GetDC(NULL); int dpiY = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL, hdc); lf.lfHeight = -MulDiv(lf.lfHeight, dpiY, 72); } HFONT hFont; hFont = CreateFontIndirectA(&lf); SendDlgItemMessage(hwnd, IDC_MESSAGE, WM_SETFONT, (WPARAM) hFont, MAKELPARAM(TRUE, 0)); SendDlgItemMessage(hwnd, IDC_MESSAGE, EM_LIMITTEXT, ~(WPARAM)0, 0); break; } case WM_USER_APPEND_TEXT: { // http://support.microsoft.com/kb/109550 HWND hEdit = GetDlgItem(hwnd, IDC_MESSAGE); int ndx = GetWindowTextLength(hEdit); SetFocus(hEdit); SendMessage(hEdit, EM_SETSEL, (WPARAM) ndx, (LPARAM) ndx); SendMessage(hEdit, EM_REPLACESEL, (WPARAM) 0, lParam); free((void *)lParam); break; } case WM_SIZE: if(wParam != SIZE_MINIMIZED) MoveWindow(GetDlgItem(hwnd, IDC_MESSAGE), 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE); break; case WM_SETFOCUS: SetFocus(GetDlgItem(hwnd, IDC_MESSAGE)); break; case WM_COMMAND: switch(LOWORD(wParam)) { case CM_FILE_SAVEAS: { OPENFILENAMEA ofn; char szFileName[MAX_PATH]; ZeroMemory(&ofn, sizeof(ofn)); szFileName[0] = 0; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.lpstrDefExt = "txt"; ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if(GetSaveFileNameA(&ofn)) { HANDLE hFile; BOOL bSuccess = FALSE; if((hFile = CreateFileA(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE) { HWND hEdit = GetDlgItem(hwnd, IDC_MESSAGE); DWORD dwTextLength = GetWindowTextLength(hEdit); if(dwTextLength > 0) // No need to bother if there's no text. { LPSTR pszText; if((pszText = GlobalAlloc(GPTR, dwTextLength + 1)) != NULL) { if(GetWindowTextA(hEdit, pszText, dwTextLength + 1)) { DWORD dwWritten; if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL)) bSuccess = TRUE; } GlobalFree(pszText); } } CloseHandle(hFile); } if(!bSuccess) MessageBoxA(hwnd, "Save file failed.", "Error", MB_OK | MB_ICONEXCLAMATION); } break; } case CM_FILE_EXIT: PostMessage(hwnd, WM_CLOSE, 0, 0); break; case CM_HELP_ABOUT: return DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc); } break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, Message, wParam, lParam); } return 0; }
CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont, FX_BOOL bVert, FX_BOOL bTranslateName) { pLogFont->lfHeight = -1000; pLogFont->lfWidth = 0; HGDIOBJ hFont = CreateFontIndirectA(pLogFont); HDC hDC = CreateCompatibleDC(nullptr); hFont = SelectObject(hDC, hFont); int tm_size = GetOutlineTextMetrics(hDC, 0, nullptr); if (tm_size == 0) { hFont = SelectObject(hDC, hFont); DeleteObject(hFont); DeleteDC(hDC); return nullptr; } LPBYTE tm_buf = FX_Alloc(BYTE, tm_size); OUTLINETEXTMETRIC* ptm = reinterpret_cast<OUTLINETEXTMETRIC*>(tm_buf); GetOutlineTextMetrics(hDC, tm_size, ptm); int flags = CalculateFlags(false, pLogFont->lfItalic != 0, (pLogFont->lfPitchAndFamily & 3) == FIXED_PITCH, (pLogFont->lfPitchAndFamily & 0xf8) == FF_ROMAN, (pLogFont->lfPitchAndFamily & 0xf8) == FF_SCRIPT, pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET); bool bCJK = pLogFont->lfCharSet == FXFONT_CHINESEBIG5_CHARSET || pLogFont->lfCharSet == FXFONT_GB2312_CHARSET || pLogFont->lfCharSet == FXFONT_HANGUL_CHARSET || pLogFont->lfCharSet == FXFONT_SHIFTJIS_CHARSET; CFX_ByteString basefont; if (bTranslateName && bCJK) basefont = FPDF_GetPSNameFromTT(hDC); if (basefont.IsEmpty()) basefont = pLogFont->lfFaceName; int italicangle = ptm->otmItalicAngle / 10; int ascend = ptm->otmrcFontBox.top; int descend = ptm->otmrcFontBox.bottom; int capheight = ptm->otmsCapEmHeight; int bbox[4] = {ptm->otmrcFontBox.left, ptm->otmrcFontBox.bottom, ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; FX_Free(tm_buf); basefont.Replace(" ", ""); CPDF_Dictionary* pBaseDict = new CPDF_Dictionary(m_pByteStringPool); pBaseDict->SetNameFor("Type", "Font"); CPDF_Dictionary* pFontDict = pBaseDict; if (!bCJK) { if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET || pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); } else { CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); } int char_widths[224]; GetCharWidth(hDC, 32, 255, char_widths); CPDF_Array* pWidths = new CPDF_Array; for (size_t i = 0; i < 224; i++) pWidths->AddInteger(char_widths[i]); ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM, pLogFont->lfItalic != 0, basefont, pWidths); } else { pFontDict = ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont, [&hDC](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) { InsertWidthArray(hDC, start, end, widthArr); }); } AddIndirectObject(pBaseDict); CPDF_Array* pBBox = new CPDF_Array; for (int i = 0; i < 4; i++) pBBox->AddInteger(bbox[i]); CPDF_Dictionary* pFontDesc = CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend, pBBox, pLogFont->lfWeight / 5); pFontDesc->SetIntegerFor("CapHeight", capheight); pFontDict->SetReferenceFor("FontDescriptor", this, AddIndirectObject(pFontDesc)); hFont = SelectObject(hDC, hFont); DeleteObject(hFont); DeleteDC(hDC); return LoadFont(pBaseDict); }
static int win_choose_font (ClientData cd, Tcl_Interp *interp, int argc, CONST84 char **argv) { CONST84 char *deffont; Tk_Window parent; int i, oldMode; CHOOSEFONTA cf; LOGFONTA lf; HDC hdc; HFONT hfont; char facebuf[LF_FACESIZE]; TEXTMETRIC tm; int pointsize; char *s; Tcl_DString resultStr; /* used to translate result in UTF8 in Tcl/Tk8.1 */ deffont = NULL; parent = Tk_MainWindow (interp); for (i = 1; i < argc; i += 2) { if (i + 1 >= argc) { Tcl_ResetResult (interp); Tcl_AppendStringsToObj (Tcl_GetObjResult (interp), "value for \"", argv[i], "\" missing", (char *) NULL); return TCL_ERROR; } if (strcmp (argv[i], "-default") == 0) deffont = argv[i + 1]; else if (strcmp (argv[i], "-parent") == 0) { parent = Tk_NameToWindow (interp, argv[i + 1], Tk_MainWindow (interp)); if (parent == NULL) return TCL_ERROR; } else { Tcl_ResetResult (interp); Tcl_AppendStringsToObj (Tcl_GetObjResult (interp), "unknown option \"", argv[i], "\"", (char *) NULL); return TCL_ERROR; } } memset (&cf, 0, sizeof (CHOOSEFONT)); cf.lStructSize = sizeof (CHOOSEFONT); if (Tk_WindowId (parent) == None) Tk_MakeWindowExist (parent); cf.hwndOwner = Tk_GetHWND (Tk_WindowId (parent)); cf.lpLogFont = &lf; cf.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST; memset (&lf, 0, sizeof (LOGFONT)); if (deffont != NULL) { Tk_Font tkfont; const TkFontAttributes *fa; tkfont = Tk_GetFont (interp, parent, deffont); if (tkfont == NULL) return TCL_ERROR; cf.Flags |= CF_INITTOLOGFONTSTRUCT; /* In order to initialize LOGFONT, we need to extract the real font attributes from the Tk internal font information. */ fa = &((TkFont *) tkfont)->fa; /* This code is taken from TkpGetFontFromAttributes. It converts a TkFontAttributes structure into a LOGFONT structure. */ #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) lf.lfHeight = - fa->size; #else lf.lfHeight = - fa->pointsize; #endif if (lf.lfHeight < 0) lf.lfHeight = MulDiv (lf.lfHeight, 254 * WidthOfScreen (Tk_Screen (parent)), 720 * WidthMMOfScreen (Tk_Screen (parent))); lf.lfWeight = fa->weight == TK_FW_NORMAL ? FW_NORMAL : FW_BOLD; lf.lfItalic = fa->slant; lf.lfUnderline = fa->underline; lf.lfStrikeOut = fa->overstrike; lf.lfCharSet = DEFAULT_CHARSET; lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = DEFAULT_QUALITY; lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; if (fa->family == NULL) lf.lfFaceName[0] = '\0'; else strncpy (lf.lfFaceName, fa->family, sizeof (lf.lfFaceName)); Tk_FreeFont (tkfont); } oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL); if (!ChooseFontA (&cf)) { DWORD code; code = CommDlgExtendedError (); if (code == 0) { /* The user pressed cancel. */ Tcl_ResetResult (interp); return TCL_OK; } else { char buf[200]; sprintf (buf, "Windows common dialog error 0x%lx", (unsigned long) code); Tcl_ResetResult (interp); #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, buf, -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr, buf, -1); #endif Tcl_AppendStringsToObj (Tcl_GetObjResult (interp), Tcl_DStringValue(&resultStr), (char *) NULL); Tcl_DStringFree(&resultStr); return TCL_ERROR; } } Tcl_SetServiceMode(oldMode); /* We now have a LOGFONT structure. We store it into a device context, and then extract enough information to build a Tk font specification. With luck, when Tk interprets the font specification it will wind up with the font that the user expects to see. Some of this code is taken from AllocFont. */ hfont = CreateFontIndirectA (&lf); if (hfont == NULL) { /* This should be impossible. */ #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, "CreateFontIndirect failed on chosen font", -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr, "CreateFontIndirect failed on chosen font", -1); #endif Tcl_SetResult (interp, Tcl_DStringValue(&resultStr), TCL_STATIC); Tcl_DStringFree(&resultStr); return TCL_ERROR; } hdc = GetDC (cf.hwndOwner); hfont = SelectObject (hdc, hfont); GetTextFaceA (hdc, sizeof (facebuf), facebuf); GetTextMetrics (hdc, &tm); Tcl_ResetResult (interp); #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, facebuf, -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr,facebuf,-1); #endif if (Tcl_ListObjAppendElement (interp, Tcl_GetObjResult (interp), Tcl_NewStringObj (Tcl_DStringValue(&resultStr), -1)) != TCL_OK) { Tcl_DStringFree(&resultStr); return TCL_ERROR; } Tcl_DStringFree(&resultStr); pointsize = MulDiv (tm.tmHeight - tm.tmInternalLeading, 720 * WidthMMOfScreen (Tk_Screen (parent)), 254 * WidthOfScreen (Tk_Screen (parent))); if (Tcl_ListObjAppendElement (interp, Tcl_GetObjResult (interp), Tcl_NewIntObj (pointsize)) != TCL_OK) { return TCL_ERROR; } if (tm.tmWeight > FW_MEDIUM) s = "bold"; else s = "normal"; #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, s, -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr, s, -1); #endif if (Tcl_ListObjAppendElement (interp, Tcl_GetObjResult (interp), Tcl_NewStringObj (Tcl_DStringValue(&resultStr), -1)) != TCL_OK) { Tcl_DStringFree(&resultStr); return TCL_ERROR; } Tcl_DStringFree(&resultStr); if (tm.tmItalic) s = "italic"; else s = "roman"; #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, s, -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr, s, -1); #endif if (Tcl_ListObjAppendElement (interp, Tcl_GetObjResult (interp), Tcl_NewStringObj (Tcl_DStringValue(&resultStr), -1)) != TCL_OK) { Tcl_DStringFree(&resultStr); return TCL_ERROR; } Tcl_DStringFree(&resultStr); if (tm.tmUnderlined) { #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, "underline", -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr,"underline",-1); #endif if (Tcl_ListObjAppendElement (interp, Tcl_GetObjResult (interp), Tcl_NewStringObj (Tcl_DStringValue(&resultStr), -1)) != TCL_OK) { Tcl_DStringFree(&resultStr); return TCL_ERROR; } Tcl_DStringFree(&resultStr); } if (tm.tmStruckOut) { #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, "overstrike", -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr, "overstrike", -1); #endif if (Tcl_ListObjAppendElement (interp, Tcl_GetObjResult (interp), Tcl_NewStringObj (Tcl_DStringValue(&resultStr), -1)) != TCL_OK) { Tcl_DStringFree(&resultStr); return TCL_ERROR; } Tcl_DStringFree(&resultStr); } hfont = SelectObject (hdc, hfont); ReleaseDC (cf.hwndOwner, hdc); DeleteObject (hfont); return TCL_OK; }