-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'gfx-font-converter' into 'master'
Add gfx-font-converter application See merge request embedded/general-support-library!35
- Loading branch information
Showing
13 changed files
with
627 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
|
||
#include <iosfwd> | ||
#include <cstdint> | ||
|
||
template <typename Stream> | ||
class BitStream | ||
{ | ||
public: | ||
explicit BitStream(Stream &stream) : stream(stream) {} | ||
BitStream& operator<<(bool bit) | ||
{ | ||
if (bit) | ||
{ | ||
buffer |= 1 << (7 - bitCount); | ||
} | ||
if (++bitCount == 8) | ||
{ | ||
stream << buffer; | ||
buffer = 0; | ||
bitCount = 0; | ||
} | ||
return *this; | ||
} | ||
|
||
BitStream& operator<<(uint8_t byte) | ||
{ | ||
if (bitCount == 0) | ||
{ | ||
stream << byte; | ||
} | ||
else | ||
{ | ||
buffer |= byte >> bitCount; | ||
stream << buffer; | ||
buffer = byte << (8 - bitCount); | ||
} | ||
return *this; | ||
} | ||
|
||
void flush() | ||
{ | ||
if (bitCount != 0) | ||
{ | ||
stream << buffer; | ||
buffer = 0; | ||
bitCount = 0; | ||
} | ||
} | ||
private: | ||
Stream &stream; | ||
int bitCount = 0; | ||
uint8_t buffer = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
add_executable(gfx-font-converter | ||
main.cpp | ||
FontConverterConfig.cpp | ||
EncodingConverter.cpp | ||
) | ||
target_link_libraries(gfx-font-converter | ||
PRIVATE | ||
general-support-library-graphics | ||
Freetype::Freetype | ||
Iconv::Iconv | ||
) | ||
target_compile_features(gfx-font-converter PUBLIC cxx_std_17) | ||
target_compile_options(gfx-font-converter PRIVATE -Wall -Wextra -pedantic) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "EncodingConverter.h" | ||
|
||
#include <sstream> | ||
|
||
EncodingConverter::EncodingConverter(const char* from, const char* to) { | ||
descriptor = iconv_open(to, from); | ||
if (descriptor == (iconv_t) -1) | ||
{ | ||
std::stringstream str; | ||
if (errno == EINVAL) | ||
{ | ||
str << "conversion from " << from <<" to " << to << " not available"; | ||
} | ||
else | ||
{ | ||
str << "iconv_open filed, errno is " << errno; | ||
} | ||
|
||
throw(std::runtime_error(str.str())); | ||
} | ||
} | ||
|
||
std::string EncodingConverter::convert(char symbol) { | ||
buf[inSize] = symbol; | ||
size_t inBufSize = 1 + inSize; | ||
char outBuf[4] = {}; | ||
size_t outBytesLeft = sizeof(outBuf); | ||
char *inptr = &buf[0]; | ||
char *outptr = &outBuf[0]; | ||
if(iconv(descriptor, &inptr, &inBufSize, &outptr, &outBytesLeft) == (size_t) -1) | ||
{ | ||
if (errno == EINVAL) | ||
{ | ||
inSize = (inSize + 1) % 3; | ||
} | ||
else | ||
{ | ||
inSize = 0; | ||
} | ||
return {}; | ||
} | ||
return {outBuf, sizeof(outBuf) - outBytesLeft}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <iconv.h> | ||
#include <string> | ||
|
||
class EncodingConverter | ||
{ | ||
public: | ||
EncodingConverter(const char *from, const char *to); | ||
|
||
std::string convert(char symbol); | ||
|
||
~EncodingConverter() | ||
{ | ||
iconv_close(descriptor); | ||
} | ||
|
||
private: | ||
iconv_t descriptor; | ||
char buf[4] = {}; | ||
size_t inSize = 0; | ||
}; |
Oops, something went wrong.