Move builtin font resources out of opengl_gal translation unit
This commit is contained in:
parent
378f5cce33
commit
047f52e7cb
|
@ -55,6 +55,7 @@ set( GAL_SRCS
|
|||
|
||||
# OpenGL GAL
|
||||
gal/opengl/opengl_gal.cpp
|
||||
gal/opengl/gl_resources.cpp
|
||||
gal/opengl/shader.cpp
|
||||
gal/opengl/vertex_item.cpp
|
||||
gal/opengl/vertex_container.cpp
|
||||
|
|
|
@ -1,19 +1,11 @@
|
|||
// Generated by msdf-atlasgen, do not modify.
|
||||
static const struct {
|
||||
unsigned int smooth_pixels;
|
||||
float min_y;
|
||||
float max_y;
|
||||
} font_information = {
|
||||
FONT_INFO_TYPE font_information = {
|
||||
1,
|
||||
-8.16f,
|
||||
39.84f
|
||||
};
|
||||
|
||||
static const struct bitmap_span {
|
||||
unsigned int start;
|
||||
unsigned int end;
|
||||
unsigned int cumulative;
|
||||
} font_codepoint_spans[] = {
|
||||
FONT_SPAN_TYPE font_codepoint_spans[] = {
|
||||
{ 33, 127, 0 },
|
||||
{ 161, 592, 94 },
|
||||
{ 658, 659, 525 },
|
||||
|
@ -105,13 +97,7 @@ static const struct bitmap_span {
|
|||
{ 65533, 65534, 1216 }
|
||||
};
|
||||
|
||||
static const struct bitmap_glyph {
|
||||
unsigned int atlas_x, atlas_y;
|
||||
unsigned int atlas_w, atlas_h;
|
||||
float minx, maxx;
|
||||
float miny, maxy;
|
||||
float advance;
|
||||
} font_codepoint_infos[] = {
|
||||
FONT_GLYPH_TYPE font_codepoint_infos[] = {
|
||||
{ 129, 991, 9, 33, 8.6880f, 15.1200f, -0.5760f, 29.7120f, 24.0000f },
|
||||
{ 77, 440, 14, 14, 6.1920f, 17.8080f, 20.6400f, 32.5920f, 24.0000f },
|
||||
{ 763, 479, 24, 32, 1.2960f, 22.7040f, 0.0000f, 29.7120f, 24.0000f },
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,41 @@
|
|||
// The current font is "Ubuntu Mono" available under Ubuntu Font Licence 1.0
|
||||
// (see ubuntu-font-licence-1.0.txt for details)
|
||||
#include <algorithm>
|
||||
#include "gl_resources.h"
|
||||
|
||||
#define BITMAP_FONT_USE_SPANS
|
||||
|
||||
namespace KIGFX {
|
||||
namespace BUILTIN_FONT {
|
||||
|
||||
#include "bitmap_font_img.c"
|
||||
#include "bitmap_font_desc.c"
|
||||
|
||||
const FONT_GLYPH_TYPE* LookupGlyph( unsigned int aCodepoint )
|
||||
{
|
||||
#ifdef BITMAP_FONT_USE_SPANS
|
||||
auto *end = font_codepoint_spans
|
||||
+ sizeof( font_codepoint_spans ) / sizeof(FONT_SPAN_TYPE);
|
||||
auto ptr = std::upper_bound( font_codepoint_spans, end, aCodepoint,
|
||||
[]( unsigned int codepoint, const FONT_SPAN_TYPE& span )
|
||||
{
|
||||
return codepoint < span.end;
|
||||
}
|
||||
);
|
||||
|
||||
if( ptr != end && ptr->start <= aCodepoint )
|
||||
{
|
||||
unsigned int index = aCodepoint - ptr->start + ptr->cumulative;
|
||||
return &font_codepoint_infos[ index ];
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
return &bitmap_chars[codepoint];
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef GAL_OPENGL_RESOURCES_H___
|
||||
#define GAL_OPENGL_RESOURCES_H___
|
||||
|
||||
#define BITMAP_FONT_USE_SPANS
|
||||
|
||||
namespace KIGFX {
|
||||
|
||||
namespace BUILTIN_FONT {
|
||||
|
||||
struct FONT_IMAGE_TYPE {
|
||||
unsigned int width, height;
|
||||
unsigned int char_border;
|
||||
unsigned int spacing;
|
||||
unsigned char pixels[1024 * 1024 * 3];
|
||||
};
|
||||
|
||||
struct FONT_INFO_TYPE {
|
||||
unsigned int smooth_pixels;
|
||||
float min_y;
|
||||
float max_y;
|
||||
};
|
||||
|
||||
struct FONT_SPAN_TYPE {
|
||||
unsigned int start;
|
||||
unsigned int end;
|
||||
unsigned int cumulative;
|
||||
};
|
||||
|
||||
struct FONT_GLYPH_TYPE {
|
||||
unsigned int atlas_x, atlas_y;
|
||||
unsigned int atlas_w, atlas_h;
|
||||
float minx, maxx;
|
||||
float miny, maxy;
|
||||
float advance;
|
||||
};
|
||||
|
||||
extern FONT_IMAGE_TYPE font_image;
|
||||
extern FONT_INFO_TYPE font_information;
|
||||
|
||||
const FONT_GLYPH_TYPE* LookupGlyph( unsigned int aCodePoint );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -45,11 +45,11 @@ using namespace std::placeholders;
|
|||
|
||||
using namespace KIGFX;
|
||||
|
||||
|
||||
// The current font is "Ubuntu Mono" available under Ubuntu Font Licence 1.0
|
||||
// (see ubuntu-font-licence-1.0.txt for details)
|
||||
#define BITMAP_FONT_USE_SPANS
|
||||
#include "bitmap_font_img.c"
|
||||
#include "bitmap_font_desc.c"
|
||||
#include "gl_resources.h"
|
||||
using namespace KIGFX::BUILTIN_FONT;
|
||||
|
||||
static void InitTesselatorCallbacks( GLUtesselator* aTesselator );
|
||||
static const int glAttributes[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 8, 0 };
|
||||
|
@ -808,7 +808,7 @@ void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition,
|
|||
{
|
||||
const unsigned int c = aText[ii];
|
||||
|
||||
wxASSERT_MSG( lookupGlyph(c) != nullptr, wxT( "Missing character in bitmap font atlas." ) );
|
||||
wxASSERT_MSG( LookupGlyph(c) != nullptr, wxT( "Missing character in bitmap font atlas." ) );
|
||||
wxASSERT_MSG( c != '\n' && c != '\r', wxT( "No support for multiline bitmap text yet" ) );
|
||||
|
||||
// Handle overbar
|
||||
|
@ -1317,7 +1317,7 @@ int OPENGL_GAL::drawBitmapChar( unsigned long aChar )
|
|||
const float TEX_X = font_image.width;
|
||||
const float TEX_Y = font_image.height;
|
||||
|
||||
const bitmap_glyph* glyph = lookupGlyph(aChar);
|
||||
const FONT_GLYPH_TYPE* glyph = LookupGlyph(aChar);
|
||||
if( !glyph ) return 0;
|
||||
|
||||
const float X = glyph->atlas_x + font_information.smooth_pixels;
|
||||
|
@ -1371,7 +1371,7 @@ int OPENGL_GAL::drawBitmapChar( unsigned long aChar )
|
|||
void OPENGL_GAL::drawBitmapOverbar( double aLength, double aHeight )
|
||||
{
|
||||
// To draw an overbar, simply draw an overbar
|
||||
const bitmap_glyph* glyph = lookupGlyph( '_' );
|
||||
const FONT_GLYPH_TYPE* glyph = LookupGlyph( '_' );
|
||||
const float H = glyph->maxy - glyph->miny;
|
||||
|
||||
Save();
|
||||
|
@ -1394,31 +1394,6 @@ void OPENGL_GAL::drawBitmapOverbar( double aLength, double aHeight )
|
|||
Restore();
|
||||
}
|
||||
|
||||
const bitmap_glyph* OPENGL_GAL::lookupGlyph( unsigned int aCodepoint ) const
|
||||
{
|
||||
#ifdef BITMAP_FONT_USE_SPANS
|
||||
auto *end = font_codepoint_spans + sizeof( font_codepoint_spans ) / sizeof( bitmap_span );
|
||||
auto ptr = std::upper_bound( font_codepoint_spans, end, aCodepoint,
|
||||
[]( unsigned int codepoint, const bitmap_span& span )
|
||||
{
|
||||
return codepoint < span.end;
|
||||
}
|
||||
);
|
||||
|
||||
if( ptr != end && ptr->start <= aCodepoint )
|
||||
{
|
||||
unsigned int index = aCodepoint - ptr->start + ptr->cumulative;
|
||||
return &font_codepoint_infos[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
return &bitmap_chars[codepoint];
|
||||
#endif
|
||||
}
|
||||
|
||||
std::pair<VECTOR2D, float> OPENGL_GAL::computeBitmapTextSize( const wxString& aText ) const
|
||||
{
|
||||
VECTOR2D textSize( 0, 0 );
|
||||
|
@ -1444,7 +1419,7 @@ std::pair<VECTOR2D, float> OPENGL_GAL::computeBitmapTextSize( const wxString& aT
|
|||
}
|
||||
}
|
||||
|
||||
const bitmap_glyph* glyph = lookupGlyph(aText[i]);
|
||||
const FONT_GLYPH_TYPE* glyph = LookupGlyph(aText[i]);
|
||||
if( glyph ) {
|
||||
textSize.x += glyph->advance;
|
||||
textSize.y = std::max<float>( textSize.y, font_information.max_y - glyph->miny );
|
||||
|
|
|
@ -380,8 +380,6 @@ private:
|
|||
*/
|
||||
std::pair<VECTOR2D, float> computeBitmapTextSize( const wxString& aText ) const;
|
||||
|
||||
const bitmap_glyph* lookupGlyph( unsigned int aCodepoint ) const;
|
||||
|
||||
// Event handling
|
||||
/**
|
||||
* @brief This is the OnPaint event handler.
|
||||
|
|
Loading…
Reference in New Issue