⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textsvcs.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{	    FT_Done_Face(m_hFace);	    m_hFace = NULL;	}    }    if (!m_hFace)    {#if defined(XXXEH_USE_CACHED_FONT_FACE_OBJECTS)	// /FT_New_Memory_Face() takes a pointer to the font file buffer and	// its size in bytes instead of a file pathname. Other than that, it	// has exactly the same semantics as FT_New_Face().	// /NOTE: the FT_Open_Face function can be used to open a new font	// face with a custom input stream as another option.	ftError = FT_New_Memory_Face(m_hLibrary,		buffer,    /* first byte in memory */		size,      /* size in bytes        */		0,         /* face_index           */		&face );#else// /XXXEH- TODO: move this out into a function, and save the value returned// after the first time it's called:#ifdef _WINDOWS	if (!m_pFontDirectory)	{	    // Try to read Font directory from Windows registry:	    HKEY hKey(0);	    if (::RegOpenKeyEx(HKEY_CURRENT_USER,		    "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",		    0,		    KEY_READ,		    &hKey) == ERROR_SUCCESS)	    {		// Read the default value		BYTE pData[MAX_PATH] = {0};		DWORD cbData(MAX_PATH);		if (ERROR_SUCCESS  == ::RegQueryValueEx(hKey, "Fonts",			0, 0, pData, &cbData))		{		    const char* pTmpPtr = (const char*)pData;		    UINT32 ulBackslashCount = 0;		    while (*pTmpPtr)		    {			if ('\\' == *pTmpPtr)			{			    ulBackslashCount++;			}			pTmpPtr++;		    }		    // /Note: cbData includes extra for null-terminator, but		    // we'll just put an extra "+1" on there just to be sure.		    // Also, add terminating backslashes so filename can be		    // appended on directly: 		    m_pFontDirectory = new char[cbData + ulBackslashCount+2 +			    TXTSVCS_MAX_FONT_NOPATH_FILENAME +1];		    if (m_pFontDirectory)		    {			pTmpPtr = (const char*)pData;			char* pTmpFntDir = m_pFontDirectory;			while (*pTmpPtr)			{			    *pTmpFntDir = *pTmpPtr;			    if ('\\' == *pTmpPtr)			    {				// /Double each backslash:				*(++pTmpFntDir) = *pTmpPtr;			    }			    pTmpPtr++; pTmpFntDir++;			}			// /Now add final backslash(es):			*pTmpFntDir = '\\';			*(++pTmpFntDir) = '\\';			*(++pTmpFntDir) = '\0'; // /Null-terminate it.			m_ulStrLenFontDir = pTmpFntDir - m_pFontDirectory;		    }		    else		    {			hxrslt = HXR_OUTOFMEMORY;			goto cleanup;		    }		}		::RegCloseKey(hKey);	    }	}#elif defined(_MACINTOSH)#pragma message("####### Need to find where font files are stored by this OS")#elif defined(_UNIX)#pragma message("####### Need to find where font files are stored by this OS")#else#pragma message("####### Need to find where font files are stored by this OS")#endif //if _WINDOWS / elif...//	if (!m_pFontDirectory  ||  !m_ulStrLenFontDir)	{	    HX_ASSERT(m_pFontDirectory  &&  m_ulStrLenFontDir);	    hxrslt = HXR_INVALID_PATH;	    goto cleanup;	}	char* pszFontFilename = m_pFontDirectory;	CHXString CHXStrFontFileName;	hxrslt = getFontFileName(pszFontFamily, bIsBold, bIsItalicized,		CHXStrFontFileName);	if (HXR_OK != hxrslt)	{	    goto cleanup; // /Font is not installed.	}	// /This is an optimization that prevents us from having to allocate	// new space for combining the path and the filename into one string.	// The filename part is "removed" below by adding back in the old	// NULL terminator:	strcpy(&pszFontFilename[m_ulStrLenFontDir], /* Flawfinder: ignore */		(const char*)CHXStrFontFileName);	// /Load from file:	ftError = FT_New_Face(m_hLibrary,		pszFontFilename,		0, // /This index tells which face to load from the font file.		&m_hFace );	pszFontFilename[m_ulStrLenFontDir] = '\0'; // /Restore to path only.#endif /* END elif of ifdef(XXXEH_USE_CACHED_FONT_FACE_OBJECTS). */	// /To get the # of faces a given font file contains, simply load its first	// face (use face_index=0), then see the value of face->num_faces.  Each	// face corresponds to something different, like "Arial Regular"	// and "Arial Bold".	/* FROM FreeType tutorial:	The complete list of available fields in in the FT_FaceRec structure	description. However, we'll describe here a few of them in more details:	    - num_glyphs  Gives the number of glyphs available in the font face.	    A glyph is simply a character image. It doesn't necessarily	    correspond to a character code though.	    - flags  A 32-bit integer containing bit flags used to describe some	    face properties. For example, the flag FT_FACE_FLAG_SCALABLE is used	    to indicate that the face's font format is scalable and that glyph	    images can be rendered for all character pixel sizes. For more	    information on face flags, please read the FreeType 2 API Reference.	    - units_per_EM  This field is only valid for scalable formats (it is	    set to 0 otherwise). It indicates the number of font units covered by	    the EM.	    - num_fixed_sizes  This field gives the number of embedded bitmap	    strikes in the current face. A strike is simply a series of glyph	    images for a given character pixel size. For example, a font face	    could include strikes for pixel sizes 10, 12 and 14. Note that even	    scalable font formats can have embedded bitmap strikes.	    - fixed_sizes  this is a pointer to an array of FT_Bitmap_Size	    elements. Each FT_Bitmap_Size indicates the horizontal and vertical	    character pixel sizes for each of the strikes that are present in	    the face.	    Note that, generally speaking, these are not the cell size of the bitmap strikes	 */	if (FT_Err_Unknown_File_Format == ftError )	{	    hxrslt = HXR_INVALID_VERSION;	    goto cleanup;	}	else if (ftError)	{	    // /The font file could not be opened or read, or it is broken:	    hxrslt = HXR_RESOURCE_BADFILE;	    goto cleanup;	}    } // /END creating m_hFace        // /NOTE: FT_Set_Char_Size() should be used to use true point sizes, and    // FT_Set_Pixel_Sizes() when physical size of each pixel doesn't matter:    ftError = FT_Set_Pixel_Sizes(	    m_hFace,	    ulAvgCharWidthPixels,   // /(0 means same as height)	    ulCharHeightPixels);    if (ftError)    {	// /Error setting size usually means fixed-size font format (e.g.,	// FNT, PCF) that doesn't handle the requested size:	// /XXXEH- TODO: look at m_hFace->fixed_sizes array and find closest	// size.	HX_ASSERT(0  &&  "size_not_available_in_requested_font");    }    // /XXXEH- this does UNICODE charmap by default, then Latin-1 if no    // UNICODE charmap, then US-ASCII if no Latin-1 charmap.  We need to    // default to Latin-1:    // /This returns 0 if glyph not found; by convention, this always    // corresponds to a special glyph image called the "missing glyph",    // commonly displayed as a box or a space:#if defined(XXXEH_HANDLE_CHARSETS_IN_FREETYPE)    //There are two ways to select a different charmap with FreeType 2.    // The easiest is when the encoding you need already has a corresponding    // enumeration defined in FT_FREETYPE_H, as ft_encoding_big5. In this    // case, simply call FT_Select_CharMap as in:    error = FT_Select_CharMap(m_hFace,                 /* target face object */	    ft_encoding_none);   /* encoding.  Pre-defined values are:	    ft_encoding_symbol, ft_encoding_unicode, ft_encoding_latin_2,	    ft_encoding_sjis, ft_encoding_gb2312, ft_encoding_big5,	    ft_encoding_wansung (appears to be Hangeul AKA KSC5601),	    ft_encoding_johab, ft_encoding_apple_roman	    */    for (lIndx = 0; lIndx < face->num_charmaps; lIndx++ )    {	charmap = face->charmaps[lIndx];	if ( charmap->platform_id == my_platform_id &&		charmap->encoding_id == my_encoding_id )	{	    found = charmap;	    break;	}    }    if (!bFound)    {#error: XXXEH- decide what to do here.    }    /* now, select the charmap for the face object */    error = FT_Set_CharMap(m_hFace, bFound);    if (ftError)    {#error: XXXEH- decide what to do here.    }#endif /* XXXEH_HANDLE_CHARSETS_IN_FREETYPE. */#if defined(XXXEH_DO_GLYPH_TRANSFORMS)    error = FT_Set_Transform(m_hFace,	    &pMatrix, // /Ppointer to 2x2 FT_Matrix (members: xx, xy, yx, yy)	    &pDelta); // /Pointer to 2-D FT_Vector  (members: x, y)*/#endif /* XXXEH_DO_GLYPH_TRANSFORMS */    for (lIndx=0; lIndx < lStringlen; lIndx++ )    {#if 1	ftError = FT_Load_Char(m_hFace, pszString[lIndx],		// /FT_LOAD_RENDER indicates that the glyph image be		// immediately converted to an anti-aliased bitmap, a shortcut		// that avoids calling FT_Render_Glyph() explicitly:		FT_LOAD_RENDER | (bDoAntialias? 0 : FT_LOAD_MONOCHROME));#else /*XXXEH- remove this block as soon as the above is tested: */	// /The following sequence of calls to FT_Load_Glyph()	// FT_Get_Char_Index() and FT_Render_Glyph() can be consolidated into	// one call to FT_Load_Char():	// retrieve glyph index from character code	FT_UInt glyph_index = FT_Get_Char_Index(m_hFace,		// /XXXEH- need to handle DBCS & UNICODE indexing here:		pszString[lIndx]);	// load glyph image into the slot (erase previous one)	ftError = FT_Load_Glyph(m_hFace, glyph_index, FT_LOAD_DEFAULT);	if (ftError)	{	    continue;  // /XXXEH- handle errors or ignore?	}	// convert to an anti-aliased bitmap	ftError = FT_Render_Glyph(m_hFace->glyph, ftRenderMode); // /ft_render_mode_normal);#endif /* one call to FT_Load_Char() VS. calls to FT_Get_Char(), FT_Load_Glyph(), FT_Render_Glyph */	if (ftError)	{	    HX_ASSERT(0); // /XXXEH- debug this.	    continue; 	}#if defined(XXXEH_TESTING)	// /This is the distance above the origin (baseline) for horizontal-	// layout text.  (>>6 because it's in 64ths):	LONG32 lBearingY = m_hFace->glyph->metrics.horiBearingY >> 6;	HX_ASSERT(lBearingY == m_hFace->glyph->bitmap_top);#endif /*END (_DEBUG)*/	// now, draw to our overall offscreen area:	bltToBitmapFromBitmap(pOffscreenBitmap,		lOffscreenWidth, lOffscreenHeight, lOffscreenDepth,		lCurPenX + m_hFace->glyph->bitmap_left, // /X: left to right		lCurPenY +     // /Y: bottom to top		// /Fixes CROSSPLAT-TEXT-BUG-0001:		(ulCharHeightPixels-m_hFace->glyph->bitmap_top),		&(m_hFace->glyph->bitmap),		ulARGBforegroundColor);     	// increment pen position 	lCurPenX += m_hFace->glyph->advance.x >> 6; // />>6 because it's in 64ths	// Freetype demo's cryptic comment for this is: "unuseful for now..":	lCurPenY += m_hFace->glyph->advance.y >> 6;    }cleanup:    return hxrslt;}/////////////////////////////////////////////////////////////////////////////HX_RESULTCTextServices::getFontFileName(const char* pszFontFamily,		BOOL bIsBold,		BOOL bIsItalicized,		CHXString& CHXStrFontFileName){    HX_RESULT hxrslt = HXR_RESOURCE_NOT_FOUND;    BOOL bUse_bd_insteadOf_b = FALSE;    BOOL bFontHasBoldVer = TRUE;    BOOL bFontHasItalicsVer = TRUE;    CHXStrFontFileName = "times.ttf";        if (!pszFontFamily)    {	HX_ASSERT(pszFontFamily);	hxrslt = HXR_INVALID_PARAMETER;	goto cleanup;    }#if defined(_MACINTOSH)  ||  defined(_UNIX)#pragma message("####### XXXEH- need to TEST getFontFileName() on UNIX and MAC")#endif            // /XXXEH- need to get font file names as mapped to font names in the    // Windows registry (and in ?? on Mac and UNIX):    // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts    // For now, just map based on initial installed font file names.  If they    // get changed on a system, however, the following will then fail.        // /Default to Times New Roman (but still return HXR_FAIL if requested font    // is not found):    if (!stricmp(pszFontFamily, "times new roman")  ||	    !stricmp(pszFontFamily, "times"))    {	hxrslt = HXR_OK;	CHXStrFontFileName = "times";	bUse_bd_insteadOf_b = TRUE;    }    else if (!strnicmp(pszFontFamily, "arial", 5))    {	hxrslt = HXR_OK;	CHXStrFontFileName = "arial";	bUse_bd_insteadOf_b = TRUE;	if (!strnicmp(pszFontFamily+5, " narrow", 5))	{	    CHXStrFontFileName += "N";	    bUse_bd_insteadOf_b = FALSE;	}	// /XXXEH- should handle arial black & arial black italic	// which are named "AriBlk.TTF" & "ARBLI___.TTF".    }    else if (!strnicmp(pszFontFamily, "courier", 7))    {	hxrslt = HXR_OK;	CHXStrFontFileName = "COUR";	if (!strnicmp(pszFontFamily+7, " new", 5))	{	    bUse_bd_insteadOf_b = TRUE;	}	else // /cour	{	    CHXStrFontFileName += "E";	}	// /XXXEH- should handle arial black & arial black italic	// which are installed as "AriBlk.TTF" & "ARBLI___.TTF" on Windows.    }    else if (!strnicmp(pszFontFamily, "osaka", 7))    {	hxrslt = HXR_OK;	CHXStrFontFileName = "arialuni.ttf"; // /XXXEH!	// /XXXEH- there is no bold or italics version of the mincho font, so	// ignore these (until we find a better system for dealing with this):	bFontHasBoldVer = bFontHasItalicsVer = FALSE;	goto cleanup;    }    // /XXXEH- TODO: add others here.    if (bIsBold  &&  bFontHasBoldVer)    {	if (bIsItalicized  &&  bFontHasItalicsVer)	{	    CHXStrFontFileName += "bi";	}	else	{	    CHXStrFontFileName += "b";	    if (bUse_bd_insteadOf_b)	    {		CHXStrFontFileName += "d";	    }	}    }    else if (bIsItalicized  &&  bFontHasItalicsVer)    {	CHXStrFontFileName += "i";    }    CHXStrFontFileName += ".ttf";cleanup:    return hxrslt;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -