/usr/include/OpenLayer/Glyph.hpp is in libopenlayer-dev 2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | #ifndef OL_GLYPH_HPP
#define OL_GLYPH_HPP
#include <math.h>
#include <map>
#include "Rgba.hpp"
#include "Bitmap.hpp"
#include "Point.hpp"
#include "Canvas.hpp"
#include "Declspec.hpp"
#ifdef USE_NEW_TTF
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#endif
#define GLYPH_PI 3.14159265358979323846
#define GLYPH_SQRT2 1.41421356237309504880
namespace ol
{
// Forward decleration of Glyph for libFreeType
class OL_LIB_DECLSPEC Glyph;
/*
* These items are so that we can maintain compatibility with Glyph Keeper
* until TextRender adopts the new system and replaces references to
* GlyphKeeper in the future.
*/
class OL_LIB_DECLSPEC GLYPH_FACE
{
public:
GLYPH_FACE();
~GLYPH_FACE();
Glyph *glyphFace;
};
class OL_LIB_DECLSPEC GLYPH_REND
{
public:
GLYPH_REND();
~GLYPH_REND();
Glyph *glyphFace;
};
class OL_LIB_DECLSPEC GLYPH_TEXTURE
{
public:
GLYPH_TEXTURE();
~GLYPH_TEXTURE();
Glyph *glyphFace;
};
OL_LIB_DECLSPEC GLYPH_FACE *gk_load_face_from_file(const char *filename, int index);
OL_LIB_DECLSPEC GLYPH_REND *gk_create_renderer( GLYPH_FACE* const face, int index );
OL_LIB_DECLSPEC void gk_rend_set_italic( GLYPH_REND* const rend, int italics );
OL_LIB_DECLSPEC void gk_rend_set_size_pixels( GLYPH_REND* const rend, const unsigned int width, const unsigned int height);
OL_LIB_DECLSPEC void gk_rend_set_hinting_default( GLYPH_REND* const rend );
OL_LIB_DECLSPEC void gk_rend_set_hinting_off( GLYPH_REND* const rend );
OL_LIB_DECLSPEC void rend_set_render_mode_normal( GLYPH_REND* const rend );
OL_LIB_DECLSPEC void gk_rend_set_text_alpha_color( GLYPH_REND* const rend, const unsigned alpha_color);
OL_LIB_DECLSPEC int gk_rend_ascender_pixels( GLYPH_REND* const rend );
OL_LIB_DECLSPEC int gk_rend_height_pixels( GLYPH_REND* const rend );
OL_LIB_DECLSPEC int gk_text_width_utf8(GLYPH_REND* const rend,const char* const text);
OL_LIB_DECLSPEC GLYPH_TEXTURE *gk_create_texture( GLYPH_REND *rend, int rangeStart, int rangeLength );
OL_LIB_DECLSPEC void gk_unload_texture_from_gpu( GLYPH_TEXTURE *texture );
OL_LIB_DECLSPEC void gk_destroy_texture( GLYPH_TEXTURE *texture );
OL_LIB_DECLSPEC void gk_render_line_gl_utf8( GLYPH_TEXTURE *texture, const char *text, int x, int y );
OL_LIB_DECLSPEC void gk_send_texture_to_gpu( GLYPH_TEXTURE *texture );
// OL_LIB_DECLSPEC Rgba colorConvert(const unsigned char *c,short ext);
// OL_LIB_DECLSPEC Rgba colorConvert(const unsigned int c);
inline Rgba colorConvert(const unsigned char *c,short ext)
{
const float component = *c / (float)(ext-1);
return Rgba(component, component, component, component);
}
inline Rgba colorConvert(const unsigned int c)
{
return Rgba(
(((c >> 16) & 0xff )/255.0f)
,(((c >> 8) & 0xff )/255.0f)
,(((c ) & 0xff )/255.0f)
,(((c >> 24) & 0xff )/255.0f)
);
}
class OL_LIB_DECLSPEC dimension
{
public:
dimension()
{
width = height = 0;
italics = 0;
}
~dimension(){}
bool operator<(const dimension &d) const
{
if(width < d.width || height < d.height || italics < d.italics)return true;
return false;
}
int width;
int height;
double italics;
};
class OL_LIB_DECLSPEC character
{
public:
//! Constructor
character();
//! Destructor
~character();
//! Unicode representation of character
signed long unicode;
//! Width of character
int width;
//! Height of character
int height;
//! Space on the left of a character (assists on positioning the character)
int left;
//! Space on top of the character (assists on positioning the character)
int top;
//! Space on the right of a character (assists on positioning the character)
int right;
//! Pitch of a character (assists on positioning the character)
int pitch;
//! Amount of shades of grays the FT_Bitmap holds
int grays;
//! Entire rows of the FT_Bitmap
int rows;
//! Entire length of the character with spacing and all
int length;
//! FT_Bitmap raw data
unsigned char *line;
};
// This class handles face objects
class OL_LIB_DECLSPEC Glyph
{
private:
//! ID
int ID;
//! Comparison of IDs
bool operator==(Glyph *g);
//! Current file
std::string currentFilename;
//! Is the face loaded
bool faceLoaded;
//! Does the face have kerning
bool kerning;
//! Current index default 0
int currentIndex;
//! Font size
dimension size;
//! Workspace bitmap
Bitmap *workBitmap;
#ifdef USE_NEW_TTF
//! Face
FT_Face face;
#endif
//! Face Name
std::string faceName;
//! Current character
character *currentChar;
//! Lookup Table by size
std::map<dimension, std::map<signed long, character> >fontTable;
//! Load flags
unsigned hintingFlag;
unsigned renderFlag;
//! Extract glyph
character extractGlyph(signed long unicode);
//! Create single index
void createIndex();
//! Render a character from the lookup table (utilizing the workBitmap)
void drawCharacter(signed long unicode, double &x1, double &y1, Bitmap *bitmap, const Rgba & col);
friend class GLYPH_FACE;
friend class GLYPH_REND;
friend class GLYPH_TEXTURE;
public:
//! Constructor
Glyph();
//! Destructor
~Glyph();
//! Load font from memory
bool loadFromMemory(const unsigned char *memoryFont, unsigned int length, int index=0, unsigned int width=14, unsigned int height=8);
//! Load font from file
bool load(const std::string & filename, int index=0, unsigned int width=14, unsigned int height=8);
//! Get text length
double getLength(const char* text);
//! Render font to a bitmap
void render(double x, double y, const Rgba& col, Bitmap *bmp, int alignment, const char* text, ...);
void renderFixed(double x, double y, const Rgba& col, Bitmap *bmp, int alignment, const char* text);
//! Set size
void setSize(int w, int h);
//! Set italics
void setItalics(int i);
//! Set FreeType LoadFlags
void setHinting(bool on=true);
//! Set FreeType LoadFlags
void setAntialias(bool on=false);
//! Get width
int getWidth();
//! Get height
int getHeight();
//! Get total height
int getTotalHeight();
//! Get italics
int getItalics();
//! Color
Rgba color;
//! Enumerator for positioning of text when rendering
enum
{
LEFT=0,
CENTERED,
RIGHT
};
};
}
#endif /* OL_GLYPH_HPP */
|