Files
pdf/engine/src/fonts/pdf_fonts/font_validator.cpp
T

29 lines
898 B
C++
Raw Normal View History

2026-08-06 14:58:44 +05:30
#include "font_validator.hpp"
namespace pdfengine::fonts::pdf_fonts {
bool FontValidator::isValidSFNT(const std::vector<uint8_t>& bytes) {
if (bytes.size() < 12) { // Minimum SFNT header size
return false;
}
// Check SFNT version / magic bytes
// 0x00010000 for TrueType
// 0x4F54544F ("OTTO") for OpenType CFF
// 0x74727565 ("true") for Apple TrueType
// 0x74797031 ("typ1") for Mac PostScript Type 1
const uint8_t* b = bytes.data();
uint32_t magic = (static_cast<uint32_t>(b[0]) << 24) |
(static_cast<uint32_t>(b[1]) << 16) |
(static_cast<uint32_t>(b[2]) << 8) |
static_cast<uint32_t>(b[3]);
if (magic == 0x00010000 || magic == 0x4F54544F || magic == 0x74727565 || magic == 0x74797031) {
return true;
}
return false;
}
} // namespace pdfengine::fonts::pdf_fonts