From 50a92db14631e65cde4cc76484e20eeeb8e15af6 Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Thu, 16 May 2013 20:35:08 -0700 Subject: [PATCH 1/3] Cleanup. --- examples/10-font/font.cpp | 76 ++++++++++++++++----------------- examples/11-fontsdf/fontsdf.cpp | 50 +++++++++------------- 2 files changed, 56 insertions(+), 70 deletions(-) diff --git a/examples/10-font/font.cpp b/examples/10-font/font.cpp index 7b0003aa..ab9742ef 100644 --- a/examples/10-font/font.cpp +++ b/examples/10-font/font.cpp @@ -1,7 +1,7 @@ /* - * Copyright 2013 Jeremie Roy. All rights reserved. - * License: http://www.opensource.org/licenses/BSD-2-Clause - */ +* Copyright 2013 Jeremie Roy. All rights reserved. +* License: http://www.opensource.org/licenses/BSD-2-Clause +*/ #include #include @@ -34,17 +34,17 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Set view 0 clear state. bgfx::setViewClear(0 - , BGFX_CLEAR_COLOR_BIT | BGFX_CLEAR_DEPTH_BIT - , 0x303030ff - , 1.0f - , 0 - ); + , BGFX_CLEAR_COLOR_BIT | BGFX_CLEAR_DEPTH_BIT + , 0x303030ff + , 1.0f + , 0 + ); - //init the text rendering system + // Init the text rendering system. FontManager* fontManager = new FontManager(512); TextBufferManager* textBufferManager = new TextBufferManager(fontManager); - //load some truetype files + // Load some TTF files. const char* fontNames[7] = { "font/droidsans.ttf", @@ -56,83 +56,79 @@ int _main_(int /*_argc*/, char** /*_argv*/) "font/five_minutes.otf" }; - const uint32_t fontCount = sizeof(fontNames) / sizeof(const char*); + const uint32_t fontCount = countof(fontNames); TrueTypeHandle fontFiles[fontCount]; FontHandle fonts[fontCount]; for (uint32_t ii = 0; ii < fontCount; ++ii) { - //instantiate a usable font + // Instantiate a usable font. fontFiles[ii] = fontManager->loadTrueTypeFromFile(fontNames[ii]); fonts[ii] = fontManager->createFontByPixelSize(fontFiles[ii], 0, 32); - //preload glyphs and blit them to atlas + + // Preload glyphs and blit them to atlas. fontManager->preloadGlyph(fonts[ii], L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. \n"); - //You can unload the truetype files at this stage, but in that case, the set of glyph's will be limited to the set of preloaded glyph + + // You can unload the truetype files at this stage, but in that + // case, the set of glyph's will be limited to the set of preloaded + // glyph. fontManager->unloadTrueType(fontFiles[ii]); } TrueTypeHandle console_tt = fontManager->loadTrueTypeFromFile("font/visitor1.ttf"); - //this font doesn't have any preloaded glyph's but the truetype file is loaded - //so glyph will be generated as needed + // This font doesn't have any preloaded glyph's but the truetype file + // is loaded so glyph will be generated as needed. FontHandle consola_16 = fontManager->createFontByPixelSize(console_tt, 0, 10); //create a static text buffer compatible with alpha font //a static text buffer content cannot be modified after its first submit. TextBufferHandle staticText = textBufferManager->createTextBuffer(FONT_TYPE_ALPHA, STATIC); - //the pen position represent the top left of the box of the first line of text + // The pen position represent the top left of the box of the first line + // of text. textBufferManager->setPenPosition(staticText, 24.0f, 100.0f); for (uint32_t ii = 0; ii < fontCount; ++ii) { - //add some text to the buffer + // Add some text to the buffer. + // The position of the pen is adjusted when there is an endline. textBufferManager->appendText(staticText, fonts[ii], L"The quick brown fox jumps over the lazy dog\n"); - //the position of the pen is adjusted when there is an endline } - // Now write some styled text + // Now write some styled text. - //setup style colors + // Setup style colors. textBufferManager->setBackgroundColor(staticText, 0x551111FF); textBufferManager->setUnderlineColor(staticText, 0xFF2222FF); textBufferManager->setOverlineColor(staticText, 0x2222FFFF); textBufferManager->setStrikeThroughColor(staticText, 0x22FF22FF); - //text + bkg + // Background. textBufferManager->setStyle(staticText, STYLE_BACKGROUND); textBufferManager->appendText(staticText, fonts[0], L"The quick "); - //text + strike-through + // Strike-through. textBufferManager->setStyle(staticText, STYLE_STRIKE_THROUGH); textBufferManager->appendText(staticText, fonts[0], L"brown fox "); - //text + overline + // Overline. textBufferManager->setStyle(staticText, STYLE_OVERLINE); textBufferManager->appendText(staticText, fonts[0], L"jumps over "); - //text + underline + // Underline. textBufferManager->setStyle(staticText, STYLE_UNDERLINE); textBufferManager->appendText(staticText, fonts[0], L"the lazy "); - //text + bkg + strike-through + // Background + strike-through. textBufferManager->setStyle(staticText, STYLE_BACKGROUND | STYLE_STRIKE_THROUGH); textBufferManager->appendText(staticText, fonts[0], L"dog\n"); - //create a transient buffer for realtime data + // Create a transient buffer for real-time data. TextBufferHandle transientText = textBufferManager->createTextBuffer(FONT_TYPE_ALPHA, TRANSIENT); - uint32_t w = 0, h = 0; while (!processEvents(width, height, debug, reset) ) { - if (w != width - || h != height) - { - w = width; - h = height; - printf("ri: %d,%d\n", width, height); - } - // Set view 0 default viewport. bgfx::setViewRect(0, 0, 0, width, height); @@ -156,7 +152,6 @@ int _main_(int /*_argc*/, char** /*_argv*/) //Use transient text to display debug information //Code below is similar to commented code above wchar_t fpsText[64]; - //swprintf(fpsText,L"Frame: % 7.3f[ms]", double(frameTime)*toMs); swprintf(fpsText, countof(fpsText), L"Frame: % 7.3f[ms]", double(frameTime) * toMs); textBufferManager->clearTextBuffer(transientText); @@ -178,10 +173,10 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Set view and projection matrix for view 0. bgfx::setViewTransform(0, view, proj); - //submit the debug text + // Submit the debug text. textBufferManager->submitTextBuffer(transientText, 0); - //submit the static text + // Submit the static text. textBufferManager->submitTextBuffer(staticText, 0); // Advance to next frame. Rendering thread will be kicked to @@ -190,7 +185,8 @@ int _main_(int /*_argc*/, char** /*_argv*/) } fontManager->unloadTrueType(console_tt); - //destroy the fonts + + // Destroy the fonts. fontManager->destroyFont(consola_16); for (uint32_t ii = 0; ii < fontCount; ++ii) { diff --git a/examples/11-fontsdf/fontsdf.cpp b/examples/11-fontsdf/fontsdf.cpp index 8fd4daef..e8967c35 100644 --- a/examples/11-fontsdf/fontsdf.cpp +++ b/examples/11-fontsdf/fontsdf.cpp @@ -1,7 +1,7 @@ /* - * Copyright 2013 Jeremie Roy. All rights reserved. - * License: http://www.opensource.org/licenses/BSD-2-Clause - */ +* Copyright 2013 Jeremie Roy. All rights reserved. +* License: http://www.opensource.org/licenses/BSD-2-Clause +*/ #include #include @@ -48,46 +48,35 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Set view 0 clear state. bgfx::setViewClear(0 - , BGFX_CLEAR_COLOR_BIT | BGFX_CLEAR_DEPTH_BIT - //, 0x303030ff - //, 0xffffffff - , 0x000000FF - , 1.0f - , 0 - ); + , BGFX_CLEAR_COLOR_BIT | BGFX_CLEAR_DEPTH_BIT + , 0x303030ff + , 1.0f + , 0 + ); - //init the text rendering system + // Init the text rendering system. FontManager* fontManager = new FontManager(512); TextBufferManager* textBufferManager = new TextBufferManager(fontManager); - //load a truetype files - /* - "font/droidsans.ttf", - "font/chp-fire.ttf", - "font/bleeding_cowboys.ttf", - "font/mias_scribblings.ttf", - "font/ruritania.ttf", - "font/signika-regular.ttf", - "font/five_minutes.otf" - */ TrueTypeHandle times_tt = fontManager->loadTrueTypeFromFile("font/bleeding_cowboys.ttf"); - //create a distance field font + // Create a distance field font. FontHandle distance_font = fontManager->createFontByPixelSize(times_tt, 0, 48, FONT_TYPE_DISTANCE); - //create a scalled down version of the same font (without adding anything to the atlas) + + // Create a scalled down version of the same font (without adding + // anything to the atlas). FontHandle smaller_font = fontManager->createScaledFontToPixelSize(distance_font, 32); - //preload glyph and generate (generate bitmap's) + // Preload glyph and generate (generate bitmap's). fontManager->preloadGlyph(distance_font, L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.,\" \n"); - //You can unload the truetype files at this stage, but in that case, the set of glyph's will be limited to the set of preloaded glyph + // You can unload the TTF files at this stage, but in that case, the + // set of glyph's will be limited to the set of preloaded glyph. fontManager->unloadTrueType(times_tt); TextBufferHandle staticText = textBufferManager->createTextBuffer(FONT_TYPE_DISTANCE, STATIC); textBufferManager->setTextColor(staticText, 0xDD0000FF); - //textBufferManager->appendText(staticText, distance_font, L"The quick brown fox jumps over the lazy dog\n"); - //textBufferManager->appendText(staticText, distance_font, L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\n"); textBufferManager->appendText(staticText, distance_font, L"BGFX "); textBufferManager->appendText(staticText, smaller_font, L"bgfx"); @@ -122,7 +111,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) float proj[16]; mtxLookAt(view, eye, at); float centering = 0.5f; - //setup a top-left ortho matrix for screen space drawing + // Setup a top-left ortho matrix for screen space drawing. mtxOrtho(proj, centering, width + centering, height + centering, centering, -1.0f, 1.0f); // Set view and projection matrix for view 0. @@ -147,7 +136,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Set model matrix for rendering. bgfx::setTransform(mtxA); - //draw your text + // Draw your text. textBufferManager->submitTextBuffer(staticText, 0); // Advance to next frame. Rendering thread will be kicked to @@ -155,7 +144,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::frame(); } - //destroy the fonts + // Destroy the fonts. fontManager->destroyFont(distance_font); fontManager->destroyFont(smaller_font); @@ -163,6 +152,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) delete textBufferManager; delete fontManager; + // Shutdown bgfx. bgfx::shutdown(); From 274a5f2321c5930f86d8f3b8da95b067b290484c Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Thu, 16 May 2013 20:37:54 -0700 Subject: [PATCH 2/3] Cleanup. --- examples/10-font/font.cpp | 18 ++++++------------ examples/11-fontsdf/fontsdf.cpp | 7 ++++--- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/examples/10-font/font.cpp b/examples/10-font/font.cpp index ab9742ef..79590379 100644 --- a/examples/10-font/font.cpp +++ b/examples/10-font/font.cpp @@ -1,7 +1,7 @@ /* -* Copyright 2013 Jeremie Roy. All rights reserved. -* License: http://www.opensource.org/licenses/BSD-2-Clause -*/ + * Copyright 2013 Jeremie Roy. All rights reserved. + * License: http://www.opensource.org/licenses/BSD-2-Clause + */ #include #include @@ -143,14 +143,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) const double freq = double(bx::getHPFrequency() ); const double toMs = 1000.0 / freq; - // Use debug font to print information about this example. - //bgfx::dbgTextClear(); - //bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/10-font"); - //bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Use the font system to display text and styled text."); - //bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs); - - //Use transient text to display debug information - //Code below is similar to commented code above + // Use transient text to display debug information. wchar_t fpsText[64]; swprintf(fpsText, countof(fpsText), L"Frame: % 7.3f[ms]", double(frameTime) * toMs); @@ -166,7 +159,8 @@ int _main_(int /*_argc*/, char** /*_argv*/) float view[16]; float proj[16]; mtxLookAt(view, eye, at); - //setup a top-left ortho matrix for screen space drawing + + // Setup a top-left ortho matrix for screen space drawing. float centering = 0.5f; mtxOrtho(proj, centering, width + centering, height + centering, centering, -1.0f, 1.0f); diff --git a/examples/11-fontsdf/fontsdf.cpp b/examples/11-fontsdf/fontsdf.cpp index e8967c35..c8f6f432 100644 --- a/examples/11-fontsdf/fontsdf.cpp +++ b/examples/11-fontsdf/fontsdf.cpp @@ -1,7 +1,7 @@ /* -* Copyright 2013 Jeremie Roy. All rights reserved. -* License: http://www.opensource.org/licenses/BSD-2-Clause -*/ + * Copyright 2013 Jeremie Roy. All rights reserved. + * License: http://www.opensource.org/licenses/BSD-2-Clause + */ #include #include @@ -111,6 +111,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) float proj[16]; mtxLookAt(view, eye, at); float centering = 0.5f; + // Setup a top-left ortho matrix for screen space drawing. mtxOrtho(proj, centering, width + centering, height + centering, centering, -1.0f, 1.0f); From 2ab5b6e1667a4fd1ad60ca750e0d9ceddabdd020 Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Thu, 16 May 2013 20:54:25 -0700 Subject: [PATCH 3/3] Cleanup. --- examples/common/font/font_manager.cpp | 27 ++--- examples/common/font/font_manager.h | 102 ++++++++++--------- examples/common/font/text_buffer_manager.cpp | 6 +- 3 files changed, 73 insertions(+), 62 deletions(-) diff --git a/examples/common/font/font_manager.cpp b/examples/common/font/font_manager.cpp index c9f259d7..120744a4 100644 --- a/examples/common/font/font_manager.cpp +++ b/examples/common/font/font_manager.cpp @@ -56,7 +56,7 @@ struct FTHolder FT_Face face; }; -class FontManager::TrueTypeFont +class TrueTypeFont { public: TrueTypeFont(); @@ -84,15 +84,16 @@ public: /// update the GlyphInfo according to the raster strategy /// @ remark buffer min size: glyphInfo.m_width * glyphInfo * height * sizeof(char) bool bakeGlyphDistance(CodePoint_t _codePoint, GlyphInfo& _outGlyphInfo, uint8_t* _outBuffer); + private: FTHolder* m_font; }; -FontManager::TrueTypeFont::TrueTypeFont() : m_font(NULL) +TrueTypeFont::TrueTypeFont() : m_font(NULL) { } -FontManager::TrueTypeFont::~TrueTypeFont() +TrueTypeFont::~TrueTypeFont() { if (m_font != NULL) { @@ -104,7 +105,7 @@ FontManager::TrueTypeFont::~TrueTypeFont() } } -bool FontManager::TrueTypeFont::init(const uint8_t* _buffer, uint32_t _bufferSize, int32_t _fontIndex, uint32_t _pixelHeight) +bool TrueTypeFont::init(const uint8_t* _buffer, uint32_t _bufferSize, int32_t _fontIndex, uint32_t _pixelHeight) { BX_CHECK( (_bufferSize > 256 && _bufferSize < 100000000), "TrueType buffer size is suspicious"); @@ -163,7 +164,7 @@ bool FontManager::TrueTypeFont::init(const uint8_t* _buffer, uint32_t _bufferSiz return true; } -FontInfo FontManager::TrueTypeFont::getFontInfo() +FontInfo TrueTypeFont::getFontInfo() { BX_CHECK(m_font != NULL, "TrueTypeFont not initialized"); FTHolder* holder = (FTHolder*) m_font; @@ -179,12 +180,12 @@ FontInfo FontManager::TrueTypeFont::getFontInfo() outFontInfo.descender = metrics.descender / 64.0f; outFontInfo.lineGap = (metrics.height - metrics.ascender + metrics.descender) / 64.0f; - outFontInfo.underline_position = FT_MulFix(holder->face->underline_position, metrics.y_scale) / 64.0f; - outFontInfo.underline_thickness = FT_MulFix(holder->face->underline_thickness, metrics.y_scale) / 64.0f; + outFontInfo.underlinePosition = FT_MulFix(holder->face->underline_position, metrics.y_scale) / 64.0f; + outFontInfo.underlineThickness = FT_MulFix(holder->face->underline_thickness, metrics.y_scale) / 64.0f; return outFontInfo; } -bool FontManager::TrueTypeFont::bakeGlyphAlpha(CodePoint_t _codePoint, GlyphInfo& _glyphInfo, uint8_t* _outBuffer) +bool TrueTypeFont::bakeGlyphAlpha(CodePoint_t _codePoint, GlyphInfo& _glyphInfo, uint8_t* _outBuffer) { BX_CHECK(m_font != NULL, "TrueTypeFont not initialized"); FTHolder* holder = (FTHolder*) m_font; @@ -238,7 +239,7 @@ bool FontManager::TrueTypeFont::bakeGlyphAlpha(CodePoint_t _codePoint, GlyphInfo return true; } -bool FontManager::TrueTypeFont::bakeGlyphSubpixel(CodePoint_t _codePoint, GlyphInfo& _glyphInfo, uint8_t* _outBuffer) +bool TrueTypeFont::bakeGlyphSubpixel(CodePoint_t _codePoint, GlyphInfo& _glyphInfo, uint8_t* _outBuffer) { BX_CHECK(m_font != NULL, "TrueTypeFont not initialized"); FTHolder* holder = (FTHolder*) m_font; @@ -394,7 +395,7 @@ void make_distance_map(unsigned char* img, unsigned char* outImg, unsigned int w free(inside); } -bool FontManager::TrueTypeFont::bakeGlyphDistance(CodePoint_t _codePoint, GlyphInfo& _glyphInfo, uint8_t* _outBuffer) +bool TrueTypeFont::bakeGlyphDistance(CodePoint_t _codePoint, GlyphInfo& _glyphInfo, uint8_t* _outBuffer) { BX_CHECK(m_font != NULL, "TrueTypeFont not initialized"); FTHolder* holder = (FTHolder*) m_font; @@ -500,7 +501,7 @@ struct FontManager::CachedFont } FontInfo fontInfo; GlyphHash_t cachedGlyphs; - FontManager::TrueTypeFont* trueTypeFont; + TrueTypeFont* trueTypeFont; // an handle to a master font in case of sub distance field font FontHandle masterFontHandle; int16_t padding; @@ -673,8 +674,8 @@ FontHandle FontManager::createScaledFontToPixelSize(FontHandle _baseFontHandle, newFontInfo.ascender = (newFontInfo.ascender * newFontInfo.scale); newFontInfo.descender = (newFontInfo.descender * newFontInfo.scale); newFontInfo.lineGap = (newFontInfo.lineGap * newFontInfo.scale); - newFontInfo.underline_thickness = (newFontInfo.underline_thickness * newFontInfo.scale); - newFontInfo.underline_position = (newFontInfo.underline_position * newFontInfo.scale); + newFontInfo.underlineThickness = (newFontInfo.underlineThickness * newFontInfo.scale); + newFontInfo.underlinePosition = (newFontInfo.underlinePosition * newFontInfo.scale); uint16_t fontIdx = m_fontHandles.alloc(); BX_CHECK(fontIdx != bx::HandleAlloc::invalid, "Invalid handle used"); diff --git a/examples/common/font/font_manager.h b/examples/common/font/font_manager.h index 7164c695..763b1ff7 100644 --- a/examples/common/font/font_manager.h +++ b/examples/common/font/font_manager.h @@ -21,23 +21,23 @@ enum FontType struct FontInfo { - //the font height in pixel + /// The font height in pixel. uint16_t pixelSize; - /// Rendering type used for the font + /// Rendering type used for the font. int16_t fontType; - /// The pixel extents above the baseline in pixels (typically positive) + /// The pixel extents above the baseline in pixels (typically positive). float ascender; - /// The extents below the baseline in pixels (typically negative) + /// The extents below the baseline in pixels (typically negative). float descender; - /// The spacing in pixels between one row's descent and the next row's ascent + /// The spacing in pixels between one row's descent and the next row's ascent. float lineGap; - /// The thickness of the under/hover/striketrough line in pixels - float underline_thickness; - /// The position of the underline relatively to the baseline - float underline_position; + /// The thickness of the under/hover/strike-trough line in pixels. + float underlineThickness; + /// The position of the underline relatively to the baseline. + float underlinePosition; - //scale to apply to glyph data + /// Scale to apply to glyph data. float scale; }; @@ -78,7 +78,7 @@ typedef int32_t CodePoint_t; /// A structure that describe a glyph. struct GlyphInfo { - /// Index for faster retrieval + /// Index for faster retrieval. int32_t glyphIndex; /// Glyph's width in pixels. @@ -90,23 +90,24 @@ struct GlyphInfo /// Glyph's left offset in pixels float offset_x; - /// Glyph's top offset in pixels - /// Remember that this is the distance from the baseline to the top-most - /// glyph scan line, upwards y coordinates being positive. + /// Glyph's top offset in pixels. + /// + /// @remark This is the distance from the baseline to the top-most glyph + /// scan line, upwards y coordinates being positive. float offset_y; - /// For horizontal text layouts, this is the unscaled horizontal distance in pixels - /// used to increment the pen position when the glyph is drawn as part of a string of text. + /// For horizontal text layouts, this is the unscaled horizontal + /// distance in pixels used to increment the pen position when the + /// glyph is drawn as part of a string of text. float advance_x; - /// For vertical text layouts, this is the unscaled vertical distance in pixels - /// used to increment the pen position when the glyph is drawn as part of a string of text. + /// For vertical text layouts, this is the unscaled vertical distance + /// in pixels used to increment the pen position when the glyph is + /// drawn as part of a string of text. float advance_y; - /// region index in the atlas storing textures + /// Region index in the atlas storing textures. uint16_t regionIndex; - ///32 bits alignment - int16_t padding; }; BGFX_HANDLE(TrueTypeHandle); @@ -115,67 +116,78 @@ BGFX_HANDLE(FontHandle); class FontManager { public: - /// create the font manager using an external cube atlas (doesn't take ownership of the atlas) + /// Create the font manager using an external cube atlas (doesn't take + /// ownership of the atlas). FontManager(Atlas* _atlas); - /// create the font manager and create the texture cube as BGRA8 with linear filtering + + /// Create the font manager and create the texture cube as BGRA8 with + /// linear filtering. FontManager(uint32_t _textureSideWidth = 512); ~FontManager(); - /// retrieve the atlas used by the font manager (e.g. to add stuff to it) + /// Retrieve the atlas used by the font manager (e.g. to add stuff to it) Atlas* getAtlas() { return m_atlas; } - /// load a TrueType font from a file path - /// @return invalid handle if the loading fail + /// Load a TrueType font from a file path. + /// + /// @return INVALID_HANDLE if the loading fail. TrueTypeHandle loadTrueTypeFromFile(const char* _fontPath); - /// load a TrueType font from a given buffer. - /// the buffer is copied and thus can be freed or reused after this call + /// Load a TrueType font from a given buffer. The buffer is copied and + /// thus can be freed or reused after this call. + /// /// @return invalid handle if the loading fail TrueTypeHandle loadTrueTypeFromMemory(const uint8_t* _buffer, uint32_t _size); - /// unload a TrueType font (free font memory) but keep loaded glyphs + /// Unload a TrueType font (free font memory) but keep loaded glyphs. void unloadTrueType(TrueTypeHandle _handle); - /// return a font whose height is a fixed pixel size + /// Return a font whose height is a fixed pixel size. FontHandle createFontByPixelSize(TrueTypeHandle _handle, uint32_t _typefaceIndex, uint32_t _pixelSize, FontType _fontType = FONT_TYPE_ALPHA); - /// return a scaled child font whose height is a fixed pixel size + /// Return a scaled child font whose height is a fixed pixel size. FontHandle createScaledFontToPixelSize(FontHandle _baseFontHandle, uint32_t _pixelSize); - /// load a baked font (the set of glyph is fixed) - /// @return INVALID_HANDLE if the loading fail + /// Load a baked font (the set of glyph is fixed). + /// + /// @return INVALID_HANDLE if the loading fail. FontHandle loadBakedFontFromFile(const char* _imagePath, const char* _descriptorPath); - /// load a baked font (the set of glyph is fixed) - /// @return INVALID_HANDLE if the loading fail + /// Load a baked font (the set of glyph is fixed). + /// + /// @return INVALID_HANDLE if the loading fail. FontHandle loadBakedFontFromMemory(const uint8_t* _imageBuffer, uint32_t _imageSize, const uint8_t* _descriptorBuffer, uint32_t _descriptorSize); /// destroy a font (truetype or baked) void destroyFont(FontHandle _handle); - /// Preload a set of glyphs from a TrueType file - /// @return true if every glyph could be preloaded, false otherwise - /// if the Font is a baked font, this only do validation on the characters + /// Preload a set of glyphs from a TrueType file. + /// + /// @return True if every glyph could be preloaded, false otherwise if + /// the Font is a baked font, this only do validation on the characters. bool preloadGlyph(FontHandle _handle, const wchar_t* _string); - /// Preload a single glyph, return true on success + /// Preload a single glyph, return true on success. bool preloadGlyph(FontHandle _handle, CodePoint_t _character); - /// bake a font to disk (the set of preloaded glyph) + /// Bake a font to disk (the set of preloaded glyph). + /// /// @return true if the baking succeed, false otherwise bool saveBakedFont(FontHandle _handle, const char* _fontDirectory, const char* _fontName); - /// return the font descriptor of a font + /// Return the font descriptor of a font. + /// /// @remark the handle is required to be valid const FontInfo& getFontInfo(FontHandle _handle); - /// Return the rendering informations about the glyph region - /// Load the glyph from a TrueType font if possible - /// @return true if the Glyph is available + /// Return the rendering informations about the glyph region. Load the + /// glyph from a TrueType font if possible + /// + /// @return True if the Glyph is available. bool getGlyphInfo(FontHandle _handle, CodePoint_t _codePoint, GlyphInfo& _outInfo); GlyphInfo& getBlackGlyph() @@ -183,9 +195,7 @@ public: return m_blackGlyph; } - class TrueTypeFont; //public to shut off Intellisense warning private: - struct CachedFont; struct CachedFile { diff --git a/examples/common/font/text_buffer_manager.cpp b/examples/common/font/text_buffer_manager.cpp index 0f9cbd64..c131f9e5 100644 --- a/examples/common/font/text_buffer_manager.cpp +++ b/examples/common/font/text_buffer_manager.cpp @@ -428,7 +428,7 @@ void TextBuffer::appendGlyph(CodePoint_t _codePoint, const FontInfo& _font, cons float x0 = (m_penX - kerning); float y0 = (m_penY - m_lineDescender / 2); float x1 = ( (float)x0 + (_glyphInfo.advance_x) ); - float y1 = y0 + _font.underline_thickness; + float y1 = y0 + _font.underlineThickness; m_fontManager->getAtlas()->packUV(blackGlyph.regionIndex, (uint8_t*)m_vertexBuffer, sizeof(TextVertex) * m_vertexCount + offsetof(TextVertex, u), sizeof(TextVertex) ); @@ -453,7 +453,7 @@ void TextBuffer::appendGlyph(CodePoint_t _codePoint, const FontInfo& _font, cons float x0 = (m_penX - kerning); float y0 = (m_penY - _font.ascender); float x1 = ( (float)x0 + (_glyphInfo.advance_x) ); - float y1 = y0 + _font.underline_thickness; + float y1 = y0 + _font.underlineThickness; m_fontManager->getAtlas()->packUV(blackGlyph.regionIndex, (uint8_t*)m_vertexBuffer, sizeof(TextVertex) * m_vertexCount + offsetof(TextVertex, u), sizeof(TextVertex) ); @@ -478,7 +478,7 @@ void TextBuffer::appendGlyph(CodePoint_t _codePoint, const FontInfo& _font, cons float x0 = (m_penX - kerning); float y0 = (m_penY - _font.ascender / 3); float x1 = ( (float)x0 + (_glyphInfo.advance_x) ); - float y1 = y0 + _font.underline_thickness; + float y1 = y0 + _font.underlineThickness; m_fontManager->getAtlas()->packUV(blackGlyph.regionIndex, (uint8_t*)m_vertexBuffer, sizeof(TextVertex) * m_vertexCount + offsetof(TextVertex, u), sizeof(TextVertex) );