 |
Gorgon Game Engine
|
Go to the documentation of this file.
6 #include "../Geometry/Point.h"
7 #include "../Containers/Collection.h"
9 namespace Gorgon {
namespace Resource {
class Font; } }
53 class GlyphDescriptor {
57 regular(regular), withoffset(withoffset) {}
64 GlyphDescriptor(Images images,
float advance,
Geometry::Point offset,
unsigned int ftind) :
65 images(images), advance(advance), offset(offset), ftindex(ftind) { }
71 unsigned int ftindex = 0;
107 bool LoadFile(
const std::string &filename);
112 bool LoadFile(
const std::string &filename,
int size,
bool loadascii =
true);
121 bool Load(
const std::vector<Byte> &data);
128 bool Load(
const Byte *data,
long datasize);
137 bool Assume(std::vector<Byte> &data);
169 bool LoadGlyphs(
const std::vector<GlyphRange> &ranges,
bool prepare =
true);
239 void Pack(
bool keeppacked =
true,
bool tight =
true,
float extrasize = 0.2) {
240 this->keeppacked = keeppacked;
241 this->tightpack = tight;
283 virtual bool IsASCII()
const override {
return isascii; }
302 virtual int GetHeight()
const override {
return height; }
312 virtual float GetLineGap()
const override {
return linegap; }
326 virtual void Prepare(
const std::string &text)
const override;
334 virtual std::pair<int, int>
GetLetterHeight(
bool asciionly =
false)
const override;
337 void pack(
float extrasize = 0.2)
const;
339 bool loadglyphs(
GlyphRange range,
bool prepare)
const;
343 bool savedata(std::ostream &stream);
345 void setatlassize(
unsigned size)
const;
350 mutable std::map<Glyph, GlyphDescriptor> glyphmap ;
353 mutable std::map<unsigned int, Glyph> ft_to_map;
358 std::string filename;
360 const std::vector<Byte> *vecdata =
nullptr;
361 const Byte *data =
nullptr;
370 mutable std::vector<bool> used;
373 mutable int rowsused = 0;
375 bool keeppacked =
true;
376 bool tightpack =
true;
379 int isfixedw =
false;
391 mutable int digw = 0;
393 bool isascii =
false;
395 bool issymbol =
false;
397 float linethickness = 1;
399 int underlinepos = 0;
401 bool haskerning =
false;
virtual int GetMaxWidth() const override
Returns the advance the of widest glyph.
Definition: FreeType.h:297
void swap(Event< Source_, Args_... > &l, Event< Source_, Args_... > &r)
Swaps two events.
Definition: Event.h:351
Drawable * GetCharacter(Glyph chr)
This function will return the drawable that is used to render the given glyph.
Definition: FreeType.cpp:554
virtual bool IsFixedWidth() const override
This function should return true if this font is fixed width.
Definition: FreeType.h:287
Graphics::ColorMode GetMode() const
Returns the color mode of the image.
Definition: Image.h:1311
virtual float GetLineThickness() const override
Should return the average thickness of a line.
Definition: FreeType.h:316
virtual void Render(Glyph chr, TextureTarget &target, Geometry::Pointf location, RGBAf color) const override
This function should render the given character to the target at the specified location and color.
Definition: FreeType.cpp:543
void Resize(const Geometry::Size &size, Graphics::ColorMode mode)
Resizes the image to the given size and color mode.
Definition: Image.h:71
basic_Image< Byte > Image
Definition: Image.h:1364
This class represents an image depends on a GL texture.
Definition: Texture.h:17
bool LoadGlyphs(Glyph start, Glyph end, bool prepare=true)
Loads the glyphs in the given range.
Definition: FreeType.h:163
virtual int GetUnderlineOffset() const override
The position of the underline, if it is to be drawn.
Definition: FreeType.h:319
virtual float GetLineGap() const override
Returns the spacing between the lines.
Definition: FreeType.h:312
virtual const Geometry::Pointf * GetCoordinates() const override final
Returns the coordinates of the texture to be used. Declared final to allow inlining.
Definition: Texture.h:161
BitmapFont MoveOutBitmap(bool unpack=false, bool prepare=true)
Moves the loaded glyphs into a new bitmap font.
Definition: FreeType.cpp:703
FreeType & operator=(const FreeType &)=delete
No copy assignment.
void Pack(bool keeppacked=true, bool tight=true, float extrasize=0.2)
Packs current glyphs into a single atlas.
Definition: FreeType.h:239
virtual bool NeedsPrepare() const override
Should return if the glyph renderer requires preparation regarding the text given.
Definition: FreeType.h:322
virtual Geometry::Pointf KerningDistance(Glyph chr1, Glyph chr2) const override
This function should return the additional distance between given glyphs.
Definition: FreeType.cpp:571
constexpr Type Font
Definition: GID.h:199
void SetLineGap(float value)
Changes the distance between two lines. Non-integer values are not recommended.
Definition: BitmapFont.h:263
bool isnewline(Glyph g)
Definition: Font.cpp:79
virtual bool IsASCII() const override
This function should return true if this font renderer supports only 7-bit ASCII.
Definition: FreeType.h:283
FreeType()
Initializes the class without loading any glyphs or files.
Definition: FreeType.cpp:117
int GetHeight() const
Returns the height of the bitmap.
Definition: Bitmap.h:480
GL::Texture Release()
Releases the texture id that might be owned by this object without destroying it.
Definition: Texture.h:180
Glyph End
End point of the range. This value is included in the range.
Definition: Font.h:42
Should be implemented by the systems aimed to render fonts on the screen.
Definition: Font.h:67
Represents a four channel 32 bit float per channel color information.
Definition: Color.h:373
std::vector< int > GetPresetSizes() const
Returns the preset sizes in the font file.
Definition: FreeType.cpp:466
void Discard()
Discards intermediate files.
Definition: FreeType.cpp:1068
bool IsSymbolOnly() const
Returns whether the font is a symbol only font.
Definition: FreeType.h:191
void CreateEmpty(const Geometry::Size &size, ColorMode mode)
Create an empty texture.
Definition: Texture.h:142
void WriteArray(std::ostream &stream, const T_ *data, unsigned long size)
Writes an array to the stream.
Definition: Stream.h:294
int GetWidth() const
Returns the width of the image.
Definition: Image.h:1296
virtual float GetCursorAdvance(Glyph g) const override
This function should return the number of pixels the cursor should advance after this glyph.
Definition: FreeType.cpp:515
void WriteVector(std::ostream &stream, const std::vector< T_ > &data)
Writes a vector to the stream.
Definition: Stream.h:302
virtual Geometry::Size GetSize(const std::string &text) const override
Definition: Font.cpp:678
bool IsReady() const override
Returns if the FreeType is ready to work.
Definition: FreeType.cpp:502
Glyph decode(std::string::const_iterator &it, std::string::const_iterator end)
Decodes a utf-8 character from the given iterator.
Definition: Font.cpp:9
bool LoadGlyphs(GlyphRange range, bool prepare=true)
Loads the glyphs in the given range.
Definition: FreeType.cpp:1058
void AddGlyph(Glyph glyph, const RectangularDrawable &bitmap, int baseline=0)
Adds a new glyph bitmap to the list.
Definition: BitmapFont.h:154
bool isspace(Glyph g)
Definition: Font.cpp:96
FreeType(const std::string &filename, int size, bool loadascii=true)
Initializes the class by loading the given file.
Definition: FreeType.h:89
bool IsScalable() const
Returns if the loaded font is scalable.
Definition: FreeType.cpp:458
unsigned long GetTotalSize() const
Total size of this image in number units.
Definition: Image.h:1306
virtual std::pair< int, int > GetLetterHeight(bool asciionly=false) const override
Returns the offset (first) and maximum height (second) that is used by letters.
Definition: FreeType.cpp:1085
int Count() const
Returns the number of the glyphs in the range.
Definition: Font.h:27
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Glyph Start
Start point of the range.
Definition: Font.h:39
This class represents a 2D geometric size.
Definition: Size.h:23
void SetUnderlineOffset(int value)
Changes the underline position to the specified value.
Definition: BitmapFont.h:257
uint32_t Char
Definition: Types.h:46
void StopPacking()
Stops packing new glyphs.
Definition: FreeType.h:248
void EnableAntiAliasing()
Enables anti aliasing.
Definition: FreeType.h:208
virtual Geometry::Size GetImageSize() const override final
Returns the size of the texture in pixels. Declared final to allow inlining.
Definition: Texture.h:156
uint32_t CeilToPowerOf2(uint32_t v)
Calculate the smalllest power of two larger than this value.
Definition: Types.h:77
FreeType(const FreeType &)=delete
No copy constructor.
virtual int GetEMSize() const override
Returns the size of the EM dash.
Definition: FreeType.h:294
Contains generic 2D graphics related data structures and functions.
Definition: Window.h:24
void Destroy()
Destroys this image by setting width and height to 0 and freeing the memory used by its data.
Definition: Image.h:189
Collection is a container for reference typed objects.
Definition: Collection.h:21
basic_Point< int > Point
Definition: Point.h:598
virtual void Prepare(const std::string &text) const override
Notifies glyph renderer about a text to be rendered.
Definition: FreeType.cpp:584
Gorgon::Char Glyph
Glyph is a symbol for a character. In Gorgon, glyphs are UTF32 chars.
Definition: Font.h:15
This object contains an bitmap image.
Definition: Bitmap.h:25
This is a solid texture based image class.
Definition: Texture.h:211
virtual ~FreeType()
Destructor.
Definition: FreeType.cpp:121
bool LoadFile(const std::string &filename)
Loads the given file.
Definition: FreeType.cpp:182
FreeType(const std::string &filename)
Initializes the class by loading the given file.
Definition: FreeType.h:84
void SetGlyphSpacing(int value)
Changes the spacing between glyphs.
Definition: BitmapFont.h:248
This interface defines a class that can be used as a common target for texture based drawing.
Definition: TextureTargets.h:12
@ Alpha
8bit alpha only color mode
This class represents a 2D point.
Definition: Point.h:32
virtual GL::Texture GetID() const override final
Returns GL::Texture to be drawn. Declared final to allow inlining.
Definition: Texture.h:151
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
virtual bool Exists(Glyph g) const override
Returns true if the glyph exists.
Definition: FreeType.cpp:528
This is the basic font, performing the minimal amount of operations necessary to render text on the s...
Definition: Font.h:271
BitmapFont CopyToBitmap(bool prepare=true) const
Copy the loaded glyphs into a new bitmap font.
Definition: FreeType.cpp:621
@ Graphics
Definition: Template.h:164
Definition: Drawables.h:74
bool LoadMetrics(int size)
Continues loading a file by setting font size and obtaining necessary information.
Definition: FreeType.cpp:314
bool CopyTo(basic_Image &dest, Geometry::Point target={0, 0}) const
Copies data from one image to another.
Definition: Image.h:318
virtual Geometry::Size GetSize(const std::string &text) const override
Returns the size of the given text.
Definition: Font.cpp:678
ColorMode GetMode() const override
Definition: Texture.h:165
T_ Area() const
Returns the exact area of the rectangle has the size of this object.
Definition: Size.h:240
void DisableAntiAliasing()
Disables anti aliasing.
Definition: FreeType.h:202
bool HasKerning() const
Returns whether this font contains kerning table.
Definition: FreeType.h:196
bool Assume(std::vector< Byte > &data)
Loads the given data.
Definition: FreeType.cpp:248
This class is a container for image data.
Definition: Image.h:19
void Adopt(const RectangularDrawable &img)
This will add the given image to the list of images that will be destroyed with this object.
Definition: BitmapFont.h:372
Bitmap fonts provide an easy way to render text on the screen.
Definition: BitmapFont.h:24
T_ Width
Width of this size object.
Definition: Size.h:258
Represents a drawable object, that can be drawn to the given point.
Definition: Drawables.h:17
void AssumeGlyph(Glyph glyph, const RectangularDrawable &bitmap, int baseline=0)
Adds a new glyph bitmap to the list.
Definition: BitmapFont.h:164
This class represents a range of glyphs. Both start and end is included.
Definition: Font.h:18
virtual float GetBaseLine() const override
Baseline point of glyphs from the top.
Definition: FreeType.h:309
bool IsFileLoaded() const
Returns whether the file is loaded. Check IsReady.
Definition: FreeType.cpp:497
std::vector< T_ >::const_iterator end(enum_type_id< T_ >)
Definition: Enum.h:288
void Set(const Containers::Image &image)
Sets the texture to the given id with the given size.
Definition: Texture.h:69
int GetWidth() const
Returns the width of the bitmap.
Definition: Bitmap.h:476
void SetKerning(Glyph left, Glyph right, Geometry::Pointf kern)
Definition: BitmapFont.h:180
int GetHeight() const
Returns the height of the image.
Definition: Image.h:1301
void Swap(basic_Image &other)
Swaps this image with another. This function is used to implement move semantics.
Definition: Image.h:200
std::string GetStyleName() const
Returns the style name of the font.
Definition: FreeType.cpp:489
std::string Canonical(const std::string &path)
Canonicalizes a given relative path.
Definition: Linux.cpp:94
bool Available(Glyph g) const
Returns true if the glyph is available in the font.
Definition: FreeType.cpp:533
virtual void Discard()
This function discards image data.
Definition: Bitmap.cpp:20
void SetBaseline(float value)
Changes the baseline. Might cause problems if the font already has glyphs in it.
Definition: BitmapFont.h:260
void CopyToTexture(Texture texture, const Containers::Image &data, Geometry::Point target)
Copies the data from the given image to the texture starting from the given target.
Definition: OpenGL.cpp:181
void UpdateTexture(Texture texture, const Containers::Image &data)
Updates the given texture to contain the given data.
Definition: OpenGL.cpp:177
virtual int GetDigitWidth() const override
Width of a digit, if digits do not have the same width, maximum should be returned.
Definition: FreeType.h:306
bool Load(const std::vector< Byte > &data)
Loads the given data.
Definition: FreeType.cpp:213
void SetLineThickness(int value)
Changes the line thickness to the specified value.
Definition: BitmapFont.h:254
This class allows using font files for text rendering.
Definition: FreeType.h:49
virtual int GetHeight() const override
Height of glyphs, actual size could be smaller but all glyphs should have the same virtual height.
Definition: FreeType.h:302
std::string GetFamilyName() const
Returns the name of the font.
Definition: FreeType.cpp:481
RGBAf color
Color of this renderer, can be overridden.
Definition: Font.h:423
Geometry::Size GetSize() const
Returns the size of the image.
Definition: Image.h:1291
void Clear()
Clears the glyphs that are loaded.
Definition: FreeType.cpp:812