Skip to content

Commit

Permalink
Work in Progress: font glyph packing
Browse files Browse the repository at this point in the history
* Removed font size parameter from loadFont functions
* Font class loads a range of font sizes a prior
* Characters have an outline to enable easy reading
* Updated examples to reflect the change related to loadFont functions
* Added a new FontAtlas class that creates the single texture that
  has all the glphs for all font sizes and characters
  • Loading branch information
9prady9 committed Feb 6, 2016
1 parent 12e367b commit 2673794
Show file tree
Hide file tree
Showing 27 changed files with 878 additions and 247 deletions.
4 changes: 2 additions & 2 deletions examples/cpu/bubblechart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cpu/fractal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cpu/histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cpu/plot3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cpu/plotting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cpu/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cuda/fractal.cu
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cuda/histogram.cu
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cuda/plot3.cu
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cuda/plotting.cu
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/cuda/surface.cu
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/opencl/fractal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/opencl/histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/opencl/plot3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/opencl/plotting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
4 changes: 2 additions & 2 deletions examples/opencl/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ int main(void)
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
fnt.loadSystemFont("Calibri");
#else
fnt.loadSystemFont("Vera", 32);
fnt.loadSystemFont("Vera");
#endif
wnd.setFont(&fnt);

Expand Down
5 changes: 5 additions & 0 deletions include/fg/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ enum ErrorCode {
* */
FG_ERR_NOT_SUPPORTED = 5001, ///< Feature not supported
FG_ERR_NOT_CONFIGURED = 5002, ///< Library configuration mismatch
/*
* Font config related error codes
* '6**'
* */
FG_ERR_FONTCONFIG_ERROR = 6001, ///< Fontconfig related error
/*
* other error codes
* match the following pattern
Expand Down
6 changes: 2 additions & 4 deletions include/fg/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,15 @@ class Font {
Load a given font file
\param[in] pFile True Type Font file path
\param[in] pFontSize the size of the font glyphs that will be created
*/
FGAPI void loadFont(const char* const pFile, int pFontSize);
FGAPI void loadFontFile(const char* const pFile);

/**
Load a system font based on the name
\param[in] pName True Type Font name
\param[in] pFontSize the size of the font glyphs that will be created
*/
FGAPI void loadSystemFont(const char* const pName, int pFontSize);
FGAPI void loadSystemFont(const char* const pName);

/**
Get handle for internal implementation of Font object
Expand Down
4 changes: 2 additions & 2 deletions src/chart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const std::shared_ptr<internal::font_impl>& getChartFont()

std::call_once(flag, []() {
#if defined(OS_WIN)
mChartFont.loadSystemFont("Calibri", 32);
mChartFont.loadSystemFont("Calibri");
#else
mChartFont.loadSystemFont("Vera", 32);
mChartFont.loadSystemFont("Vera");
#endif
});

Expand Down
70 changes: 65 additions & 5 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ GLuint initShaders(const char* pVertShaderSrc, const char* pFragShaderSrc)
return shaderProgram;
}

int nextP2(const int pValue)
{
return int(std::pow(2, (std::ceil(std::log2(pValue)))));
}

float clampTo01(const float pValue)
{
return (pValue < 0.0f ? 0.0f : (pValue>1.0f ? 1.0f : pValue));
Expand Down Expand Up @@ -316,3 +311,68 @@ glm::vec3 trackballPoint(const float pX, const float pY,
a = 1.0f / sqrt(x*x + y*y + z*z);
return glm::vec3(x*a,y*a,z*a);
}

size_t utf8_surrogate_len(const char* character)
{
size_t result = 0;
char test_char;

if (!character)
return 0;

test_char = character[0];

if ((test_char & 0x80) == 0)
return 1;

while (test_char & 0x80) {
test_char <<= 1;
result++;
}

return result;
}

size_t utf8_strlen(const char* string)
{
const char* ptr = string;
size_t result = 0;

while (*ptr) {
ptr += utf8_surrogate_len(ptr);
result++;
}

return result;
}

uint32_t utf8_to_utf32(const char * character)
{
uint32_t result = -1;

if (!character) {
return result;
}

if (( character[0] & 0x80 ) == 0x0) {
result = character[0];
}

if (( character[0] & 0xC0 ) == 0xC0) {
result = ( ( character[0] & 0x3F ) << 6 ) | ( character[1] & 0x3F );
}

if (( character[0] & 0xE0 ) == 0xE0) {
result = ( ( character[0] & 0x1F ) << ( 6 + 6 ) ) | ( ( character[1] & 0x3F ) << 6 ) | ( character[2] & 0x3F );
}

if (( character[0] & 0xF0 ) == 0xF0) {
result = ( ( character[0] & 0x0F ) << ( 6 + 6 + 6 ) ) | ( ( character[1] & 0x3F ) << ( 6 + 6 ) ) | ( ( character[2] & 0x3F ) << 6 ) | ( character[3] & 0x3F );
}

if (( character[0] & 0xF8 ) == 0xF8) {
result = ( ( character[0] & 0x07 ) << ( 6 + 6 + 6 + 6 ) ) | ( ( character[1] & 0x3F ) << ( 6 + 6 + 6 ) ) | ( ( character[2] & 0x3F ) << ( 6 + 6 ) ) | ( ( character[3] & 0x3F ) << 6 ) | ( character[4] & 0x3F );
}

return result;
}
9 changes: 3 additions & 6 deletions src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ GLuint createBuffer(GLenum pTarget, size_t pSize, const T* pPtr, GLenum pUsage)
return retVal;
}

/* compute the next power of two after given integer
*
* @pValue is the value whose next power of two is to be computed
*/
int nextP2(const int pValue);

#ifdef OS_WIN
/* Get the paths to font files in Windows system directory
*
Expand Down Expand Up @@ -134,6 +128,9 @@ std::ostream& operator<<(std::ostream&, const glm::mat4&);
glm::vec3 trackballPoint(const float pX, const float pY,
const float pWidth, const float pHeight);

size_t utf8_surrogate_len(const char* character);
size_t utf8_strlen(const char* string);
uint32_t utf8_to_utf32(const char * character);

namespace internal
{
Expand Down
Loading

0 comments on commit 2673794

Please sign in to comment.