Font loading progress

This commit is contained in:
2023-06-09 09:04:45 -07:00
parent d70ae88359
commit 8b3ecc88a6
18 changed files with 557 additions and 54 deletions

View File

@@ -178,6 +178,16 @@ size_t File::readToBuffer(char **buffer) {
return l;
}
size_t File::readRaw(char *buffer, size_t max) {
assertNotNull(buffer);
assertTrue(max > 0);
if(!this->isOpen()) {
if(!this->open(FILE_MODE_READ)) return 0;
}
assertTrue(this->mode == FILE_MODE_READ);
return fread(buffer, sizeof(char), max, this->file);
}
bool_t File::writeString(std::string in) {
if(!this->isOpen() && !this->open(FILE_MODE_WRITE)) return false;
assertTrue(this->mode == FILE_MODE_WRITE);
@@ -187,10 +197,30 @@ bool_t File::writeString(std::string in) {
bool_t File::writeRaw(char *data, size_t len) {
if(!this->isOpen() && !this->open(FILE_MODE_WRITE)) return false;
assertTrue(this->mode == FILE_MODE_WRITE);
assertTrue(len > 0);
this->length = fwrite(data, sizeof(char_t), len, this->file);
return true;
}
bool_t File::copyRaw(File *otherFile, size_t length) {
assertTrue(length > 0);
assertTrue(otherFile->isOpen());
char buffer[FILE_BUFFER_SIZE];
size_t amountLeftToRead = length;
size_t read = 0;
while(amountLeftToRead > 0) {
auto iRead = otherFile->readRaw(buffer, mathMin<size_t>(FILE_BUFFER_SIZE, amountLeftToRead));
if(iRead == 0) return false;
this->writeRaw(buffer, iRead);
amountLeftToRead -= iRead;
read += iRead;
}
assertTrue(read == length);
return true;
}
void File::setPosition(size_t n) {
fseek(this->file, 0, SEEK_SET);
fseek(this->file, n, SEEK_CUR);

View File

@@ -118,6 +118,15 @@ namespace Dawn {
*/
size_t readToBuffer(char **buffer);
/**
* Reads the contents of this file into a given buffer.
*
* @param buffer Pointer to buffer to read to.
* @param max Max length of the buffer.
* @return Amount of bytes read.
*/
size_t readRaw(char *buffer, size_t max);
/**
* Writes the entire contents of a string to a file.
*
@@ -130,9 +139,19 @@ namespace Dawn {
* Write raw bytes to the file.
*
* @param data Data to write.
* @param size Size of the data to write.
* @return True if written successfully, otherwise false.
*/
bool_t writeRaw(char *data, size_t );
bool_t writeRaw(char *data, size_t size);
/**
* Write raw bytes to the file from another file.
*
* @param otherFile Other file to read from.
* @param length Length of the data to read.
* @return True if written successfully, otherwise false.
*/
bool_t copyRaw(File *otherFile, size_t length);
/**
* Set the position of the cursor of the file reader.