2018-03-16 20:27:12 +00:00
|
|
|
//
|
|
|
|
|
// Font definitions for the Fast Light Tool Kit (FLTK).
|
|
|
|
|
//
|
|
|
|
|
// Copyright 1998-2018 by Bill Spitzak and others.
|
|
|
|
|
//
|
|
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
|
//
|
2020-07-01 16:03:10 +00:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2018-03-16 20:27:12 +00:00
|
|
|
//
|
2020-07-01 16:03:10 +00:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2018-03-16 20:27:12 +00:00
|
|
|
//
|
2020-07-01 16:03:10 +00:00
|
|
|
// https://www.fltk.org/bugs.php
|
2018-03-16 20:27:12 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef FL_ANDROID_GRAPHICS_FONT_H
|
|
|
|
|
#define FL_ANDROID_GRAPHICS_FONT_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Fl_Android_Graphics_Driver.H"
|
2018-03-17 17:41:16 +00:00
|
|
|
|
|
|
|
|
// We violate FLTKs avoidance of STL because we live in a defined driver space
|
2018-03-31 21:29:33 +00:00
|
|
|
#define FL_ALLOW_STL 1
|
|
|
|
|
#ifdef FL_ALLOW_STL
|
2018-03-17 17:41:16 +00:00
|
|
|
#include <map>
|
2018-03-31 21:29:33 +00:00
|
|
|
#endif
|
2018-03-17 17:41:16 +00:00
|
|
|
|
2018-03-16 21:49:58 +00:00
|
|
|
#include "stb_truetype.h"
|
2018-03-16 20:27:12 +00:00
|
|
|
|
|
|
|
|
|
2018-03-17 16:23:40 +00:00
|
|
|
/**
|
2018-06-23 20:50:22 +00:00
|
|
|
A bytemap is an array of bytes, used as an alpha channel when redering glyphs
|
|
|
|
|
in a given color.
|
|
|
|
|
TODO: reate a class for RGB only and for grayscale and grayscale with alpha
|
|
|
|
|
TODO: derive all this from a baseclass, so we can create the correct class for the required image
|
2018-03-17 16:23:40 +00:00
|
|
|
*/
|
2018-03-17 13:15:39 +00:00
|
|
|
class Fl_Android_Bytemap
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Fl_Android_Bytemap();
|
2018-03-26 21:28:18 +00:00
|
|
|
Fl_Android_Bytemap(int w, int h);
|
2018-03-17 13:15:39 +00:00
|
|
|
~Fl_Android_Bytemap();
|
|
|
|
|
|
|
|
|
|
public:
|
2018-03-26 21:28:18 +00:00
|
|
|
int pWidth = 0, pHeight = 0, pStride = 0;
|
|
|
|
|
int pXOffset = 0, pYOffset = 0, pAdvance = 0;
|
|
|
|
|
unsigned char *pBytes = nullptr;
|
2018-03-17 13:15:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2018-03-27 21:54:04 +00:00
|
|
|
/**
|
2018-06-23 20:50:22 +00:00
|
|
|
A 565a map is an array of words for interleaved RGB and Alpha data.
|
|
|
|
|
565 is the number of bit per component, compatible with our screen memory
|
|
|
|
|
scheme. The second word is actually a byt containing the alpha value for
|
|
|
|
|
the previous pixel: rrrrrggg.gggbbbbb.aaaaaaaa.00000000
|
2018-03-27 21:54:04 +00:00
|
|
|
*/
|
|
|
|
|
class Fl_Android_565A_Map
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Fl_Android_565A_Map();
|
|
|
|
|
Fl_Android_565A_Map(int w, int h);
|
|
|
|
|
~Fl_Android_565A_Map();
|
2018-03-31 21:29:33 +00:00
|
|
|
static inline uint32_t toRGBA(uchar r, uchar g, uchar b, uchar a)
|
|
|
|
|
{
|
|
|
|
|
return ((((r << 8) & 0xf800) |
|
|
|
|
|
((g << 3) & 0x07e0) |
|
|
|
|
|
((b >> 3) & 0x001f)) << 16) | a;
|
|
|
|
|
}
|
2018-03-27 21:54:04 +00:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
int pWidth = 0, pHeight = 0, pStride = 0;
|
|
|
|
|
int pXOffset = 0, pYOffset = 0;
|
|
|
|
|
uint32_t *pWords = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2018-03-17 16:23:40 +00:00
|
|
|
/**
|
2018-06-23 20:50:22 +00:00
|
|
|
This class reads True Type Font files and creates Bytemaps for glyphs at the
|
|
|
|
|
requested height.
|
2018-03-17 16:23:40 +00:00
|
|
|
*/
|
2018-03-17 13:15:39 +00:00
|
|
|
class Fl_Android_Font_Source
|
2018-03-16 20:27:12 +00:00
|
|
|
{
|
2018-03-16 21:49:58 +00:00
|
|
|
private:
|
|
|
|
|
stbtt_fontinfo pFont;
|
|
|
|
|
uint8_t *pFileBuffer;
|
2018-03-17 13:15:39 +00:00
|
|
|
const char *pName;
|
|
|
|
|
Fl_Font pFontIndex;
|
2018-03-17 19:32:05 +00:00
|
|
|
bool pError;
|
|
|
|
|
|
|
|
|
|
bool load_font(const char *name);
|
|
|
|
|
bool load_font_file(const char *name);
|
|
|
|
|
bool load_font_asset(const char *name);
|
2018-03-17 13:15:39 +00:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Fl_Android_Font_Source(const char *fname, Fl_Font fnum);
|
2018-03-17 16:23:40 +00:00
|
|
|
~Fl_Android_Font_Source();
|
2018-03-17 13:15:39 +00:00
|
|
|
void load_font();
|
|
|
|
|
Fl_Android_Bytemap *get_bytemap(uint32_t c, int size);
|
|
|
|
|
float get_advance(uint32_t c, Fl_Fontsize size);
|
2018-03-17 20:33:51 +00:00
|
|
|
int get_descent(Fl_Fontsize size);
|
2018-03-17 13:15:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2018-03-17 16:23:40 +00:00
|
|
|
/**
|
2018-06-23 20:50:22 +00:00
|
|
|
This class caches glyphs of a font for a specified height.
|
2018-03-17 16:23:40 +00:00
|
|
|
*/
|
2018-03-17 13:15:39 +00:00
|
|
|
class Fl_Android_Font_Descriptor : public Fl_Font_Descriptor
|
|
|
|
|
{
|
2018-03-31 21:29:33 +00:00
|
|
|
#ifdef FL_ALLOW_STL
|
2018-03-18 13:44:37 +00:00
|
|
|
typedef std::map<uint32_t, Fl_Android_Bytemap*> BytemapTable;
|
2018-03-31 21:29:33 +00:00
|
|
|
#else
|
|
|
|
|
typedef Fl_Android_Bytemap* BytemapTable[256];
|
|
|
|
|
#endif
|
2018-03-17 13:15:39 +00:00
|
|
|
private:
|
|
|
|
|
Fl_Android_Font_Source *pFontSource;
|
|
|
|
|
Fl_Font pFontIndex;
|
2018-03-18 13:44:37 +00:00
|
|
|
BytemapTable pBytemapTable;
|
2018-03-16 21:49:58 +00:00
|
|
|
|
2018-03-16 20:27:12 +00:00
|
|
|
public:
|
2018-03-17 13:15:39 +00:00
|
|
|
Fl_Android_Font_Descriptor(const char *fname, Fl_Android_Font_Source *fsrc, Fl_Font fnum, Fl_Fontsize size);
|
2018-03-17 17:41:16 +00:00
|
|
|
~Fl_Android_Font_Descriptor();
|
2018-03-16 21:49:58 +00:00
|
|
|
float get_advance(uint32_t c);
|
2018-03-17 13:15:39 +00:00
|
|
|
Fl_Android_Bytemap *get_bytemap(uint32_t c);
|
|
|
|
|
Fl_Android_Font_Source *get_font_source() { return pFontSource; }
|
2018-03-17 20:33:51 +00:00
|
|
|
int get_descent();
|
2018-03-16 20:27:12 +00:00
|
|
|
|
2018-03-17 16:23:40 +00:00
|
|
|
static Fl_Android_Font_Descriptor* find(Fl_Font fnum, Fl_Fontsize size);
|
2018-03-16 20:27:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // FL_ANDROID_GRAPHICS_FONT_H
|