blog/cpp/fonts/core/tables/loca/loca.h

60 lines
1.6 KiB
C
Raw Permalink Normal View History

2024-09-13 15:10:58 +08:00
#ifndef __TABLE_LOCA_H__
#define __TABLE_LOCA_H__
#include "../../../reader/reader.h"
#define LocaShortFormat 0
#define LocaLongFormat 1
class LocaTable
{
private:
uint16 _numGlyphs;
public:
LocaTable():_numGlyphs(0){};
~LocaTable(){};
LocaTable(uint16 i):_numGlyphs(i){}
uint16 numGlyphs(){return _numGlyphs;}
};
class LocaTableShort: public LocaTable
{
private:
uint16 _indexToLocFormat;
std::vector<Offset16> _offsets;
public:
LocaTableShort():_indexToLocFormat(LocaShortFormat){};
~LocaTableShort(){};
LocaTableShort(uint16 num):LocaTable(num),_indexToLocFormat(LocaShortFormat){}
LocaTableShort(uint16 num, reader *rd):LocaTable(num),_indexToLocFormat(LocaShortFormat){read(rd);}
void read(reader *rd){
for(auto i=0;i<numGlyphs();i++){
Offset16 o = rd->readOffset16();
_offsets.push_back(o);
}
}
uint16 format(){return _indexToLocFormat;}
std::vector<Offset16> offsets(){return _offsets;}
};
class LocaTableLong: public LocaTable
{
private:
uint16 _indexToLocFormat;
std::vector<Offset32> _offsets;
public:
LocaTableLong():_indexToLocFormat(LocaLongFormat){};
~LocaTableLong(){};
LocaTableLong(uint16 num):LocaTable(num),_indexToLocFormat(LocaLongFormat){}
LocaTableLong(uint16 num, reader *rd):LocaTable(num),_indexToLocFormat(LocaLongFormat){read(rd);}
void read(reader *rd){
for(auto i=0;i<numGlyphs();i++){
Offset32 o = rd->readOffset32();
_offsets.push_back(o);
}
}
uint16 format(){return _indexToLocFormat;}
std::vector<Offset32> offsets(){return _offsets;}
};
#endif