char* Win32_Select( filter_t *p_filter, const char* family, bool b_bold, bool b_italic, int i_size, int *i_idx ) { VLC_UNUSED( i_size ); VLC_UNUSED( i_idx ); VLC_UNUSED( p_filter ); if( !family || strlen( family ) < 1 ) goto fail; /* */ LOGFONT lf; lf.lfCharSet = DEFAULT_CHARSET; if( b_italic ) lf.lfItalic = true; if( b_bold ) lf.lfWeight = FW_BOLD; LPTSTR psz_fbuffer = ToT( family ); _tcsncpy( (LPTSTR)&lf.lfFaceName, psz_fbuffer, LF_FACESIZE ); free( psz_fbuffer ); /* */ char *psz_filename = NULL; HDC hDC = GetDC( NULL ); EnumFontFamiliesEx(hDC, &lf, (FONTENUMPROC)&EnumFontCallback, (LPARAM)&psz_filename, 0); ReleaseDC(NULL, hDC); /* */ if( psz_filename != NULL ) { /* FIXME: increase i_idx, when concatenated strings */ i_idx = 0; /* Prepend the Windows Font path, when only a filename was provided */ if( strchr( psz_filename, DIR_SEP_CHAR ) ) return psz_filename; else { /* Get Windows Font folder */ char *psz_win_fonts_path = GetWindowsFontPath(); char *psz_tmp; if( asprintf( &psz_tmp, "%s\\%s", psz_win_fonts_path, psz_filename ) == -1 ) { free( psz_filename ); free( psz_win_fonts_path ); return NULL; } free( psz_filename ); free( psz_win_fonts_path ); return psz_tmp; } } else /* Let's take any font we can */ fail: { char *psz_win_fonts_path = GetWindowsFontPath(); char *psz_tmp; if( asprintf( &psz_tmp, "%s\\%s", psz_win_fonts_path, SYSTEM_DEFAULT_FONT_FILE ) == -1 ) return NULL; else return psz_tmp; } }
void Win32Popup::addItem( const std::string &rLabel, int pos ) { MENUITEMINFO menuItem; menuItem.cbSize = sizeof( MENUITEMINFO ); // menuItem.fMask = MIIM_FTYPE | MIIM_ID | MIIM_TYPE | MIIM_STRING; // menuItem.fType = MFT_STRING; menuItem.fMask = MIIM_ID | MIIM_STRING; menuItem.wID = pos; menuItem.dwTypeData = ToT(rLabel.c_str()); menuItem.cch = rLabel.size(); InsertMenuItem( m_hMenu, findInsertionPoint( pos ), TRUE, &menuItem ); }
const vlc_family_t *Win32_GetFamily( filter_t *p_filter, const char *psz_family ) { filter_sys_t *p_sys = p_filter->p_sys; char *psz_lc = ToLower( psz_family ); if( unlikely( !psz_lc ) ) return NULL; vlc_family_t *p_family = vlc_dictionary_value_for_key( &p_sys->family_map, psz_lc ); free( psz_lc ); if( p_family ) return p_family; p_family = NewFamily( p_filter, psz_family, &p_sys->p_families, &p_sys->family_map, psz_family ); if( unlikely( !p_family ) ) return NULL; LOGFONT lf; lf.lfCharSet = DEFAULT_CHARSET; LPTSTR psz_fbuffer = ToT( psz_family ); _tcsncpy( (LPTSTR)&lf.lfFaceName, psz_fbuffer, LF_FACESIZE ); free( psz_fbuffer ); /* */ HDC hDC = GetDC( NULL ); EnumFontFamiliesEx(hDC, &lf, (FONTENUMPROC)&EnumFontCallback, (LPARAM)p_family, 0); ReleaseDC(NULL, hDC); return p_family; }
/* * This is a hack used by Chrome and WebKit to expose the fallback font used * by Uniscribe for some given text for use with custom shapers / font engines. */ static char *UniscribeFallback( const char *psz_family, uni_char_t codepoint ) { HDC hdc = NULL; HDC meta_file_dc = NULL; HENHMETAFILE meta_file = NULL; LPTSTR psz_fbuffer = NULL; char *psz_result = NULL; hdc = CreateCompatibleDC( NULL ); if( !hdc ) return NULL; meta_file_dc = CreateEnhMetaFile( hdc, NULL, NULL, NULL ); if( !meta_file_dc ) goto error; LOGFONT lf; memset( &lf, 0, sizeof( lf ) ); psz_fbuffer = ToT( psz_family ); if( !psz_fbuffer ) goto error; _tcsncpy( ( LPTSTR ) &lf.lfFaceName, psz_fbuffer, LF_FACESIZE ); free( psz_fbuffer ); lf.lfCharSet = DEFAULT_CHARSET; HFONT hFont = CreateFontIndirect( &lf ); if( !hFont ) goto error; HFONT hOriginalFont = SelectObject( meta_file_dc, hFont ); TCHAR text = codepoint; SCRIPT_STRING_ANALYSIS script_analysis; HRESULT hresult = ScriptStringAnalyse( meta_file_dc, &text, 1, 0, -1, SSA_METAFILE | SSA_FALLBACK | SSA_GLYPHS | SSA_LINK, 0, NULL, NULL, NULL, NULL, NULL, &script_analysis ); if( SUCCEEDED( hresult ) ) { hresult = ScriptStringOut( script_analysis, 0, 0, 0, NULL, 0, 0, FALSE ); ScriptStringFree( &script_analysis ); } SelectObject( meta_file_dc, hOriginalFont ); DeleteObject( hFont ); meta_file = CloseEnhMetaFile( meta_file_dc ); if( SUCCEEDED( hresult ) ) { LOGFONT log_font; log_font.lfFaceName[ 0 ] = 0; EnumEnhMetaFile( 0, meta_file, MetaFileEnumProc, &log_font, NULL ); if( log_font.lfFaceName[ 0 ] ) psz_result = FromT( log_font.lfFaceName ); } DeleteEnhMetaFile(meta_file); DeleteDC( hdc ); return psz_result; error: if( meta_file_dc ) DeleteEnhMetaFile( CloseEnhMetaFile( meta_file_dc ) ); if( hdc ) DeleteDC( hdc ); return NULL; }
static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out, subpicture_region_t *p_region_in, const vlc_fourcc_t *p_chroma_list ) { filter_sys_t *p_sys = p_filter->p_sys; int i_font_color, i_font_alpha, i_font_size; uint8_t *p_bitmap; TCHAR *psz_string; int i, i_width, i_height; HBITMAP bitmap, bitmap_bak; BITMAPINFO *p_bmi; RECT rect = { 0, 0, 0, 0 }; /* Sanity check */ if( !p_region_in || !p_region_out ) return VLC_EGENERIC; if( !p_region_in->psz_text || !*p_region_in->psz_text ) return VLC_EGENERIC; psz_string = ToT(p_region_in->psz_text); if( psz_string == NULL ) return VLC_EGENERIC; if( !*psz_string ) { free( psz_string ); return VLC_EGENERIC; } if( p_region_in->p_style ) { i_font_color = VLC_CLIP( p_region_in->p_style->i_font_color, 0, 0xFFFFFF ); i_font_alpha = VLC_CLIP( p_region_in->p_style->i_font_alpha, 0, 255 ); i_font_size = VLC_CLIP( p_region_in->p_style->i_font_size, 0, 255 ); } else { i_font_color = p_sys->i_font_color; i_font_alpha = 255 - p_sys->i_font_opacity; i_font_size = p_sys->i_default_font_size; } SetFont( p_filter, i_font_size ); SetTextColor( p_sys->hcdc, RGB( (i_font_color >> 16) & 0xff, (i_font_color >> 8) & 0xff, i_font_color & 0xff) ); DrawText( p_sys->hcdc, psz_string, -1, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX ); i_width = rect.right; i_height = rect.bottom; p_bmi = malloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*16); memset( p_bmi, 0, sizeof(BITMAPINFOHEADER) ); p_bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); p_bmi->bmiHeader.biWidth = (i_width+3) & ~3; p_bmi->bmiHeader.biHeight = - i_height; p_bmi->bmiHeader.biPlanes = 1; p_bmi->bmiHeader.biBitCount = 8; p_bmi->bmiHeader.biCompression = BI_RGB; p_bmi->bmiHeader.biClrUsed = 16; for( i = 0; i < 16; i++ ) { p_bmi->bmiColors[i].rgbBlue = p_bmi->bmiColors[i].rgbGreen = p_bmi->bmiColors[i].rgbRed = pi_gamma[i]; } bitmap = CreateDIBSection( p_sys->hcdc, p_bmi, DIB_RGB_COLORS, (void **)&p_bitmap, NULL, 0 ); if( !bitmap ) { msg_Err( p_filter, "could not create bitmap" ); free( psz_string ); return VLC_EGENERIC; } bitmap_bak = SelectObject( p_sys->hcdc, bitmap ); FillRect( p_sys->hcdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) ); if( !DrawText( p_sys->hcdc, psz_string, -1, &rect, DT_CENTER | DT_NOPREFIX ) ) { msg_Err( p_filter, "could not draw text" ); } p_region_out->i_x = p_region_in->i_x; p_region_out->i_y = p_region_in->i_y; Render( p_filter, p_region_out, p_bitmap, i_width, i_height ); SelectObject( p_sys->hcdc, bitmap_bak ); DeleteObject( bitmap ); free( psz_string ); return VLC_SUCCESS; }