Widen font ptrs to ints

Hopefully we'd be overflowing shorts otherwise.
This commit is contained in:
Tamás Bálint Misius 2020-07-24 20:27:20 +02:00
parent 5c190c1a7a
commit 6d95ad898e
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
4 changed files with 14 additions and 14 deletions

View File

@ -610,7 +610,7 @@ extern const unsigned char font_data[] = {
0x0A, 0x00, 0x00, 0x00, 0x74, 0x00, 0xD0, 0x1F, 0x40, 0x8B, 0x07, 0x3D, 0xF3, 0xF1, 0x3F, 0x3F, 0xFD, 0xF8, 0x41, 0xFF, 0x07, 0xD0, 0x1C, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x74, 0x00, 0xD0, 0x1F, 0x40, 0x8B, 0x07, 0x3D, 0xF3, 0xF1, 0x3F, 0x3F, 0xFD, 0xF8, 0x41, 0xFF, 0x07, 0xD0, 0x1C, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}; };
extern const unsigned short font_ptrs[] = { extern const unsigned int font_ptrs[] = {
0x0000, 0x0010, 0x0020, 0x0030, 0x0040, 0x0050, 0x0060, 0x0070, 0x0000, 0x0010, 0x0020, 0x0030, 0x0040, 0x0050, 0x0060, 0x0070,
0x0080, 0x0090, 0x00A0, 0x00B0, 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0080, 0x0090, 0x00A0, 0x00B0, 0x00C0, 0x00D0, 0x00E0, 0x00F0,
0x0100, 0x0110, 0x0120, 0x0130, 0x0140, 0x0150, 0x0160, 0x0170, 0x0100, 0x0110, 0x0120, 0x0130, 0x0140, 0x0150, 0x0160, 0x0170,

View File

@ -2,10 +2,10 @@
#define FONT_H 12 #define FONT_H 12
#ifndef FONTEDITOR #ifndef FONTEDITOR
extern const unsigned char font_data[]; extern const unsigned char font_data[];
extern const unsigned short font_ptrs[]; extern const unsigned int font_ptrs[];
extern const unsigned int font_ranges[][2]; extern const unsigned int font_ranges[][2];
#else #else
extern unsigned char *font_data; extern unsigned char *font_data;
extern unsigned short *font_ptrs; extern unsigned int *font_ptrs;
extern unsigned int (*font_ranges)[2]; extern unsigned int (*font_ranges)[2];
#endif #endif

View File

@ -18,7 +18,7 @@
#ifdef FONTEDITOR #ifdef FONTEDITOR
unsigned char *font_data; unsigned char *font_data;
unsigned short *font_ptrs; unsigned int *font_ptrs;
unsigned int (*font_ranges)[2]; unsigned int (*font_ranges)[2];
void FontEditor::ReadDataFile(ByteString dataFile) void FontEditor::ReadDataFile(ByteString dataFile)
@ -122,7 +122,7 @@ void FontEditor::ReadDataFile(ByteString dataFile)
file.close(); file.close();
} }
void FontEditor::WriteDataFile(ByteString dataFile, std::vector<unsigned char> const &fontData, std::vector<unsigned short> const &fontPtrs, std::vector<std::array<unsigned int, 2> > const &fontRanges) void FontEditor::WriteDataFile(ByteString dataFile, std::vector<unsigned char> const &fontData, std::vector<unsigned int> const &fontPtrs, std::vector<std::array<unsigned int, 2> > const &fontRanges)
{ {
std::fstream file; std::fstream file;
file.open(dataFile, std::ios_base::out | std::ios_base::trunc); file.open(dataFile, std::ios_base::out | std::ios_base::trunc);
@ -155,7 +155,7 @@ void FontEditor::WriteDataFile(ByteString dataFile, std::vector<unsigned char> c
else else
file << " "; file << " ";
first = false; first = false;
file << "0x" << std::setw(4) << (unsigned int)fontPtrs[pos++] << ","; file << "0x" << std::setw(8) << (unsigned int)fontPtrs[pos++] << ",";
} }
file << std::endl; file << std::endl;
} }
@ -171,7 +171,7 @@ void FontEditor::UnpackData(
std::map<String::value_type, unsigned char> &fontWidths, std::map<String::value_type, unsigned char> &fontWidths,
std::map<String::value_type, std::array<std::array<char, MAX_WIDTH>, FONT_H> > &fontPixels, std::map<String::value_type, std::array<std::array<char, MAX_WIDTH>, FONT_H> > &fontPixels,
std::vector<unsigned char> const &fontData, std::vector<unsigned char> const &fontData,
std::vector<unsigned short> const &fontPtrs, std::vector<unsigned int> const &fontPtrs,
std::vector<std::array<unsigned int, 2> > const &fontRanges) std::vector<std::array<unsigned int, 2> > const &fontRanges)
{ {
fontWidths.clear(); fontWidths.clear();
@ -204,7 +204,7 @@ void FontEditor::PackData(
std::map<String::value_type, unsigned char> const &fontWidths, std::map<String::value_type, unsigned char> const &fontWidths,
std::map<String::value_type, std::array<std::array<char, MAX_WIDTH>, FONT_H> > const &fontPixels, std::map<String::value_type, std::array<std::array<char, MAX_WIDTH>, FONT_H> > const &fontPixels,
std::vector<unsigned char> &fontData, std::vector<unsigned char> &fontData,
std::vector<unsigned short> &fontPtrs, std::vector<unsigned int> &fontPtrs,
std::vector<std::array<unsigned int, 2> > &fontRanges) std::vector<std::array<unsigned int, 2> > &fontRanges)
{ {
fontData.clear(); fontData.clear();
@ -490,7 +490,7 @@ FontEditor::FontEditor(ByteString target, ByteString source):
tgtFontPixels[p.first] = p.second; tgtFontPixels[p.first] = p.second;
} }
std::vector<unsigned char> tmpFontData; std::vector<unsigned char> tmpFontData;
std::vector<unsigned short> tmpFontPtrs; std::vector<unsigned int> tmpFontPtrs;
std::vector<std::array<unsigned int, 2> > tmpFontRanges; std::vector<std::array<unsigned int, 2> > tmpFontRanges;
PackData(tgtFontWidths, tgtFontPixels, tmpFontData, tmpFontPtrs, tmpFontRanges); PackData(tgtFontWidths, tgtFontPixels, tmpFontData, tmpFontPtrs, tmpFontRanges);
WriteDataFile(target, tmpFontData, tmpFontPtrs, tmpFontRanges); WriteDataFile(target, tmpFontData, tmpFontPtrs, tmpFontRanges);
@ -652,7 +652,7 @@ void FontEditor::Render()
void FontEditor::Save() void FontEditor::Save()
{ {
std::vector<unsigned char> tmpFontData; std::vector<unsigned char> tmpFontData;
std::vector<unsigned short> tmpFontPtrs; std::vector<unsigned int> tmpFontPtrs;
std::vector<std::array<unsigned int, 2> > tmpFontRanges; std::vector<std::array<unsigned int, 2> > tmpFontRanges;
PackData(fontWidths, fontPixels, tmpFontData, tmpFontPtrs, tmpFontRanges); PackData(fontWidths, fontPixels, tmpFontData, tmpFontPtrs, tmpFontRanges);
WriteDataFile(dataFile, tmpFontData, tmpFontPtrs, tmpFontRanges); WriteDataFile(dataFile, tmpFontData, tmpFontPtrs, tmpFontRanges);

View File

@ -25,7 +25,7 @@ private:
std::map<String::value_type, std::array<std::array<char, MAX_WIDTH>, FONT_H> > fontPixels; std::map<String::value_type, std::array<std::array<char, MAX_WIDTH>, FONT_H> > fontPixels;
std::vector<unsigned char> fontData; std::vector<unsigned char> fontData;
std::vector<unsigned short> fontPtrs; std::vector<unsigned int> fontPtrs;
std::vector<std::array<unsigned int, 2> > fontRanges; std::vector<std::array<unsigned int, 2> > fontRanges;
ByteString beforeFontData; ByteString beforeFontData;
@ -34,18 +34,18 @@ private:
ByteString afterFontRanges; ByteString afterFontRanges;
void ReadDataFile(ByteString dataFile); void ReadDataFile(ByteString dataFile);
void WriteDataFile(ByteString dataFile, std::vector<unsigned char> const &fontData, std::vector<unsigned short> const &fontPtrs, std::vector<std::array<unsigned int, 2> > const &fontRanges); void WriteDataFile(ByteString dataFile, std::vector<unsigned char> const &fontData, std::vector<unsigned int> const &fontPtrs, std::vector<std::array<unsigned int, 2> > const &fontRanges);
static void PackData( static void PackData(
std::map<String::value_type, unsigned char> const &fontWidths, std::map<String::value_type, unsigned char> const &fontWidths,
std::map<String::value_type, std::array<std::array<char, MAX_WIDTH>, FONT_H> > const &fontPixels, std::map<String::value_type, std::array<std::array<char, MAX_WIDTH>, FONT_H> > const &fontPixels,
std::vector<unsigned char> &fontData, std::vector<unsigned char> &fontData,
std::vector<unsigned short> &fontPtrs, std::vector<unsigned int> &fontPtrs,
std::vector<std::array<unsigned int, 2> > &fontRanges); std::vector<std::array<unsigned int, 2> > &fontRanges);
static void UnpackData( static void UnpackData(
std::map<String::value_type, unsigned char> &fontWidths, std::map<String::value_type, unsigned char> &fontWidths,
std::map<String::value_type, std::array<std::array<char, MAX_WIDTH>, FONT_H> > &fontPixels, std::map<String::value_type, std::array<std::array<char, MAX_WIDTH>, FONT_H> > &fontPixels,
std::vector<unsigned char> const &fontData, std::vector<unsigned char> const &fontData,
std::vector<unsigned short> const &fontPtrs, std::vector<unsigned int> const &fontPtrs,
std::vector<std::array<unsigned int, 2> > const &fontRanges); std::vector<std::array<unsigned int, 2> > const &fontRanges);
ui::Textbox *currentCharTextbox; ui::Textbox *currentCharTextbox;