本文整理汇总了C++中Font::GetDpi方法的典型用法代码示例。如果您正苦于以下问题:C++ Font::GetDpi方法的具体用法?C++ Font::GetDpi怎么用?C++ Font::GetDpi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Font
的用法示例。
在下文中一共展示了Font::GetDpi方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CacheResource
/// @copydoc ResourceHandler::CacheResource()
bool FontResourceHandler::CacheResource(
ObjectPreprocessor* pObjectPreprocessor,
Resource* pResource,
const String& rSourceFilePath )
{
HELIUM_ASSERT( pObjectPreprocessor );
HELIUM_ASSERT( pResource );
Font* pFont = Reflect::AssertCast< Font >( pResource );
// Load the font into memory ourselves in order to make sure we properly support Unicode file names.
FileStream* pFileStream = File::Open( rSourceFilePath, FileStream::MODE_READ );
if( !pFileStream )
{
HELIUM_TRACE(
TRACE_ERROR,
TXT( "FontResourceHandler: Source file for font resource \"%s\" failed to open properly.\n" ),
*rSourceFilePath );
return false;
}
uint64_t fileSize64 = static_cast< uint64_t >( pFileStream->GetSize() );
if( fileSize64 > SIZE_MAX )
{
HELIUM_TRACE(
TRACE_ERROR,
( TXT( "FontResourceHandler: Font file \"%s\" exceeds the maximum addressable size of data in memory for " )
TXT( "this platform and will not be cached.\n" ) ),
*rSourceFilePath );
delete pFileStream;
return false;
}
size_t fileSize = static_cast< size_t >( fileSize64 );
uint8_t* pFileData = new uint8_t [ fileSize ];
if( !pFileData )
{
HELIUM_TRACE(
TRACE_ERROR,
( TXT( "FontResourceHandler: Failed to allocate %" ) TPRIuSZ TXT( " bytes for resource data for font " )
TXT( "\"%s\".\n" ) ),
fileSize,
*rSourceFilePath );
delete pFileStream;
return false;
}
size_t bytesRead = pFileStream->Read( pFileData, 1, fileSize );
delete pFileStream;
if( bytesRead != fileSize )
{
HELIUM_TRACE(
TRACE_WARNING,
( TXT( "FontResourceHandler: Attempted to read %" ) TPRIuSZ TXT( " bytes from font resource file \"%s\", " )
TXT( "but only %" ) TPRIuSZ TXT( " bytes were read successfully.\n" ) ),
fileSize,
*rSourceFilePath,
bytesRead );
}
// Create the font face.
FT_Library pLibrary = GetStaticLibrary();
HELIUM_ASSERT( pLibrary );
FT_Face pFace = NULL;
FT_Error error = FT_New_Memory_Face( pLibrary, pFileData, static_cast< FT_Long >( bytesRead ), 0, &pFace );
if( error != 0 )
{
HELIUM_TRACE(
TRACE_ERROR,
TXT( "FontResourceHandler: Failed to create font face from resource file \"%s\".\n" ),
*rSourceFilePath );
delete [] pFileData;
return false;
}
// Set the appropriate font size.
int32_t pointSize = Font::Float32ToFixed26x6( pFont->GetPointSize() );
uint32_t dpi = pFont->GetDpi();
error = FT_Set_Char_Size( pFace, pointSize, pointSize, dpi, dpi );
if( error != 0 )
{
HELIUM_TRACE(
TRACE_ERROR,
TXT( "FontResourceHandler: Failed to set size of font resource \"%s\".\n" ),
*rSourceFilePath );
FT_Done_Face( pFace );
delete [] pFileData;
//.........这里部分代码省略.........