本文整理汇总了C++中CAtlFile::GetPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ CAtlFile::GetPosition方法的具体用法?C++ CAtlFile::GetPosition怎么用?C++ CAtlFile::GetPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAtlFile
的用法示例。
在下文中一共展示了CAtlFile::GetPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetProperties
bool CTrueType::GetProperties(LPCTSTR pszFilePath, TTF_PROPERTIES* pProperties)
{
CAtlFile FontFile;
HRESULT hr = FontFile.Create(pszFilePath, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING);
if (FAILED(hr))
return false;
TTF_OFFSET_TABLE ttOffsetTable;
FontFile.Read(&ttOffsetTable, sizeof(TTF_OFFSET_TABLE));
ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
// See if this is a true type font and the version is 1.0
if (ttOffsetTable.uMajorVersion != 1 || ttOffsetTable.uMinorVersion != 0)
return false;
TTF_TABLE_DIRECTORY tblDir;
TTF_TABLE_DIRECTORY tblName;
TTF_TABLE_DIRECTORY tblOS2;
bool bFoundNameTable = false;
bool bFoundOS2Table = false;
for (int i=0; i< ttOffsetTable.uNumOfTables; i++)
{
FontFile.Read(&tblDir, sizeof(TTF_TABLE_DIRECTORY));
CString strName = CString(tblDir.szTag, 4);
if (strName.IsEmpty())
break;
if (!strName.CompareNoCase("name"))
{
bFoundNameTable = true;
tblName = tblDir;
tblName.uLength = SWAPLONG(tblName.uLength);
tblName.uOffset = SWAPLONG(tblName.uOffset);
}
else
if (!strName.CompareNoCase("OS/2"))
{
bFoundOS2Table = true;
tblOS2 = tblDir;
tblOS2.uLength = SWAPLONG(tblOS2.uLength);
tblOS2.uOffset = SWAPLONG(tblOS2.uOffset);
}
if (bFoundNameTable && bFoundOS2Table)
break;
}
if (bFoundNameTable)
{
FontFile.Seek(tblName.uOffset, FILE_BEGIN);
TTF_NAME_TABLE_HEADER ttNTHeader;
FontFile.Read(&ttNTHeader, sizeof(TTF_NAME_TABLE_HEADER));
ttNTHeader.uFSelector = SWAPWORD(ttNTHeader.uFSelector);
ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
for (int i=0; i<ttNTHeader.uNRCount; i++)
{
TTF_NAME_RECORD ttRecord;
FontFile.Read(&ttRecord, sizeof(TTF_NAME_RECORD));
ttRecord.uPlatformID = SWAPWORD(ttRecord.uPlatformID);
ttRecord.uEncodingID = SWAPWORD(ttRecord.uEncodingID);
ttRecord.uLanguageID = SWAPWORD(ttRecord.uLanguageID);
ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
if (ttRecord.uPlatformID != 3) // Microsoft
continue;
ULONGLONG nPos = 0;
FontFile.GetPosition(nPos);
FontFile.Seek(tblName.uOffset + ttRecord.uStringOffset + ttNTHeader.uStorageOffset, FILE_BEGIN);
int iUnicodeChars = (ttRecord.uStringLength + 1) / 2;
WCHAR* pUnicodeBuffer = new WCHAR[iUnicodeChars];
FontFile.Read(pUnicodeBuffer, ttRecord.uStringLength);
for (int i = 0; i < iUnicodeChars; i++)
pUnicodeBuffer[i] = SWAPWORD(pUnicodeBuffer[i]);
CString strName = CString(pUnicodeBuffer, iUnicodeChars);
delete [] pUnicodeBuffer;
FontFile.Seek(nPos, FILE_BEGIN);
if (strName.IsEmpty())
continue;
switch (ttRecord.uNameID)
{
case 1: // Font family
pProperties->strFamily.IsEmpty() ? pProperties->strFamily = strName : void();
break;
case 0: // Copyright notice
pProperties->strCopyright.IsEmpty() ? pProperties->strCopyright = strName : void();
break;
case 7: // Trademark notice
pProperties->strTrademark.IsEmpty() ? pProperties->strTrademark = strName : void();
//.........这里部分代码省略.........