本文整理汇总了C++中FontPlatformData::openTypeTable方法的典型用法代码示例。如果您正苦于以下问题:C++ FontPlatformData::openTypeTable方法的具体用法?C++ FontPlatformData::openTypeTable怎么用?C++ FontPlatformData::openTypeTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FontPlatformData
的用法示例。
在下文中一共展示了FontPlatformData::openTypeTable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadMetrics
void OpenTypeVerticalData::loadMetrics(const FontPlatformData& platformData) {
// Load hhea and hmtx to get x-component of vertical origins.
// If these tables are missing, it's not an OpenType font.
RefPtr<SharedBuffer> buffer = platformData.openTypeTable(OpenType::HheaTag);
const OpenType::HheaTable* hhea =
OpenType::validateTable<OpenType::HheaTable>(buffer);
if (!hhea)
return;
uint16_t countHmtxEntries = hhea->numberOfHMetrics;
if (!countHmtxEntries) {
WTF_LOG_ERROR("Invalid numberOfHMetrics");
return;
}
buffer = platformData.openTypeTable(OpenType::HmtxTag);
const OpenType::HmtxTable* hmtx =
OpenType::validateTable<OpenType::HmtxTable>(buffer, countHmtxEntries);
if (!hmtx) {
WTF_LOG_ERROR("hhea exists but hmtx does not (or broken)");
return;
}
m_advanceWidths.resize(countHmtxEntries);
for (uint16_t i = 0; i < countHmtxEntries; ++i)
m_advanceWidths[i] = hmtx->entries[i].advanceWidth;
// Load vhea first. This table is required for fonts that support vertical
// flow.
buffer = platformData.openTypeTable(OpenType::VheaTag);
const OpenType::VheaTable* vhea =
OpenType::validateTable<OpenType::VheaTable>(buffer);
if (!vhea)
return;
uint16_t countVmtxEntries = vhea->numOfLongVerMetrics;
if (!countVmtxEntries) {
WTF_LOG_ERROR("Invalid numOfLongVerMetrics");
return;
}
// Load VORG. This table is optional.
buffer = platformData.openTypeTable(OpenType::VORGTag);
const OpenType::VORGTable* vorg =
OpenType::validateTable<OpenType::VORGTable>(buffer);
if (vorg && buffer->size() >= vorg->requiredSize()) {
m_defaultVertOriginY = vorg->defaultVertOriginY;
uint16_t countVertOriginYMetrics = vorg->numVertOriginYMetrics;
if (!countVertOriginYMetrics) {
// Add one entry so that hasVORG() becomes true
m_vertOriginY.set(0, m_defaultVertOriginY);
} else {
for (uint16_t i = 0; i < countVertOriginYMetrics; ++i) {
const OpenType::VORGTable::VertOriginYMetrics& metrics =
vorg->vertOriginYMetrics[i];
m_vertOriginY.set(metrics.glyphIndex, metrics.vertOriginY);
}
}
}
// Load vmtx then. This table is required for fonts that support vertical
// flow.
buffer = platformData.openTypeTable(OpenType::VmtxTag);
const OpenType::VmtxTable* vmtx =
OpenType::validateTable<OpenType::VmtxTable>(buffer, countVmtxEntries);
if (!vmtx) {
WTF_LOG_ERROR("vhea exists but vmtx does not (or broken)");
return;
}
m_advanceHeights.resize(countVmtxEntries);
for (uint16_t i = 0; i < countVmtxEntries; ++i)
m_advanceHeights[i] = vmtx->entries[i].advanceHeight;
// VORG is preferred way to calculate vertical origin than vmtx,
// so load topSideBearing from vmtx only if VORG is missing.
if (hasVORG())
return;
size_t sizeExtra =
buffer->size() - sizeof(OpenType::VmtxTable::Entry) * countVmtxEntries;
if (sizeExtra % sizeof(OpenType::Int16)) {
WTF_LOG_ERROR("vmtx has incorrect tsb count");
return;
}
size_t countTopSideBearings =
countVmtxEntries + sizeExtra / sizeof(OpenType::Int16);
m_topSideBearings.resize(countTopSideBearings);
size_t i;
for (i = 0; i < countVmtxEntries; ++i)
m_topSideBearings[i] = vmtx->entries[i].topSideBearing;
if (i < countTopSideBearings) {
const OpenType::Int16* pTopSideBearingsExtra =
reinterpret_cast<const OpenType::Int16*>(
&vmtx->entries[countVmtxEntries]);
for (; i < countTopSideBearings; ++i, ++pTopSideBearingsExtra)
m_topSideBearings[i] = *pTopSideBearingsExtra;
}
}