 |
Gorgon Game Engine
|
Go to the documentation of this file.
10 #include "../Containers/Collection.h"
172 AddGlyph(glyph, bitmap, offset, advance);
185 kerning[{left, right}] = {x, 0.f};
210 auto f =
kerning.find({chr1, chr2});
287 std::string prefix =
"", ImportOptions options = ImportOptions{});
318 if(!bmp.Import(filename))
321 return ImportAtlas(std::move(bmp), grid, start, expand, options);
333 void AutoKern(
Byte opaquelevel = 64,
int reduce = 1,
int capitaloffset = -1);
378 virtual std::pair<int, int>
GetLetterHeight(
bool asciionly =
false)
const override;
385 std::map<Glyph, GlyphDescriptor>::iterator
begin() {
389 std::map<Glyph, GlyphDescriptor>::iterator
end() {
393 std::map<Glyph, GlyphDescriptor>::const_iterator
begin()
const {
397 std::map<Glyph, GlyphDescriptor>::const_iterator
end()
const {
bool IsValid() const
Checks whether the iterator is valid.
Definition: Iterator.h:146
void AutoKern(Byte opaquelevel=64, int reduce=1, int capitaloffset=-1)
Automatically calculates kerning distances between glyphs.
Definition: BitmapFont.cpp:756
bool operator<(const gtog &other) const
Definition: BitmapFont.h:408
ImportOptions(bool pack=true, float baseline=-1, bool trim=true, YesNoAuto converttoalpha=YesNoAuto::Yes, bool prepare=true, bool estimatebaseline=false, bool automatickerning=true, int spacing=-1)
Definition: BitmapFont.h:69
This class represents boundaries of 2D objects.
Definition: Bounds.h:27
void swap(Event< Source_, Args_... > &l, Event< Source_, Args_... > &r)
Swaps two events.
Definition: Event.h:351
Containers::Collection< const RectangularDrawable > destroylist
Definition: BitmapFont.h:404
std::map< gtog, Geometry::Pointf > kerning
Definition: BitmapFont.h:411
This class represents a color information.
Definition: Color.h:91
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: BitmapFont.cpp:74
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string >::type From(const T_ &e)
Definition: Enum.h:303
Graphics::Bitmap CreateAtlas(std::vector< Geometry::Bounds > &bounds, bool tight=false) const
Performs packing without changing the font itself.
Definition: BitmapFont.cpp:956
float advance
Definition: BitmapFont.h:44
bool ForPixels(std::function< bool(int, int)> fn) const
Loops through all pixels of the image, giving coordinates to your function.
Definition: Bitmap.h:638
bool isspaced(Glyph g)
Definition: Font.cpp:75
Bitmap Duplicate() const
Duplicates this image.
Definition: Bitmap.h:117
void DetermineDimensions()
Searches through the currently registered glyphs to determine dimensions.
Definition: BitmapFont.cpp:86
Geometry::Pointf offset
Definition: BitmapFont.h:43
const RectangularDrawable * image
Definition: BitmapFont.h:39
This class is a reference based hashmap.
Definition: Hashmap.h:35
bool Release(RectangularDrawable &img)
If the given resource is owned by this bitmap font, its ownership will be released.
Definition: BitmapFont.h:351
virtual void Prepare(const std::string &) const
Notifies glyph renderer about a text to be rendered.
Definition: Font.h:143
bool Add(T_ *Data)
Adds the given item to the end of the list if it is not already in the list.
Definition: Collection.h:248
float baseline
Definition: BitmapFont.h:419
Iterator Last()
returns the iterator to the last item
Definition: Hashmap.h:430
float baseline
Set baseline to specific height.
Definition: BitmapFont.h:97
@ Zero
If there is transparency, transparent, otherwise black borders.
Definition: Bitmap.h:36
@ Owned
Definition: BitmapFont.h:62
virtual bool IsASCII() const override
This function should return true if this font renderer supports only 7-bit ASCII.
Definition: BitmapFont.h:176
T_ Height
Height of this size object.
Definition: Size.h:261
void Pack(bool tight=false, DeleteConstants del=Owned)
Converts individual glyphs to a single atlas.
Definition: BitmapFont.cpp:920
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
@ Automatic
Filenames will be examined to determine the template.
Definition: BitmapFont.h:50
int GetHeight() const
Returns the height of the bitmap.
Definition: Bitmap.h:480
virtual bool Exists(Glyph g) const override
Returns true if the glyph exists.
Definition: BitmapFont.h:207
BitmapFont(const BitmapFont &)=delete
Should be implemented by the systems aimed to render fonts on the screen.
Definition: Font.h:67
@ Hexadecimal
Hexadecimal code of the character is used as filename.
Definition: BitmapFont.h:57
Represents a four channel 32 bit float per channel color information.
Definition: Color.h:373
int isfixedw
Definition: BitmapFont.h:413
Graphics::ColorMode GetMode() const override
Returns the color mode of the image.
Definition: Bitmap.h:422
void Add(const K_ &key, T_ &obj, bool deleteprev=false)
Adds the given item with the related key.
Definition: Hashmap.h:264
virtual Geometry::Pointf KerningDistance(Glyph chr1, Glyph chr2) const override
This function should return the additional distance between given glyphs.
Definition: BitmapFont.h:209
ImportNamingTemplate
Definition: BitmapFont.h:47
GlyphDescriptor(const RectangularDrawable &image, Geometry::Pointf offset, float advance)
Definition: BitmapFont.h:32
GlyphDescriptor()
Definition: BitmapFont.h:30
std::string Join(std::string path1, const std::string &path2)
Joins two given paths or a path and filename.
Definition: Filesystem.h:154
std::map< Glyph, GlyphDescriptor >::const_iterator end() const
Definition: BitmapFont.h:397
@ None
Atlas will be tight packed.
Definition: Bitmap.h:33
Byte A
Alpha channel.
Definition: Color.h:312
@ Decimal
Decimal code of the character is used as filename.
Definition: BitmapFont.h:55
int ImportAtlas(const std::string &filename, Geometry::Size grid={0, 0}, Glyph start=0x20, bool expand=false, ImportOptions options=ImportOptions{})
Imports the given file as atlas image. See ImportAtlas(Bitmap &&) for details.
Definition: BitmapFont.h:315
void AddGlyph(Glyph glyph, const RectangularDrawable &bitmap, int baseline=0)
Adds a new glyph bitmap to the list.
Definition: BitmapFont.h:154
YesNoAuto converttoalpha
Whether to convert imported images to alpha only images.
Definition: BitmapFont.h:110
bool isspace(Glyph g)
Definition: Font.cpp:96
void SetKerning(Glyph left, Glyph right, float x)
Definition: BitmapFont.h:184
T_ Top
Top margin.
Definition: Margin.h:170
int ImportAtlas(const Bitmap &bmp, Geometry::Size grid={0, 0}, Glyph start=0x20, bool expand=false, ImportOptions options=ImportOptions{})
Imports the given bitmap as atlas image.
Definition: BitmapFont.h:310
bool IsOwned(const RectangularDrawable &img) const
Returns if the given image is owned by this bitmap font.
Definition: BitmapFont.h:364
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
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
~BitmapFont()
Definition: BitmapFont.h:148
virtual Geometry::Size GetSize(const std::string &text) const override
Definition: Font.cpp:678
void AssumeGlyph(Glyph glyph, const RectangularDrawable &bitmap, Geometry::Pointf offset, float advance)
Adds a new glyph bitmap to the list.
Definition: BitmapFont.h:171
Definition: BitmapFont.h:406
virtual float GetCursorAdvance(Glyph g) const override
This function should return the number of pixels the cursor should advance after this glyph.
Definition: BitmapFont.cpp:1066
Geometry::Margin Trim(bool left, bool top, bool right, bool bottom)
Trims the empty parts of the image, alpha channel = 0 is used to determine empty portions.
Definition: Bitmap.cpp:541
int height
Definition: BitmapFont.h:417
int digw
Definition: BitmapFont.h:421
int spacing
Spaces between characters, -1 activates auto detection.
Definition: BitmapFont.h:129
std::string GetExtension(std::string path)
Returns the extension of the given path, also converts the extension to lower case.
Definition: Filesystem.cpp:140
int GetAlphaIndex(ColorMode mode)
Returns the index of alpha channel. If alpha channel does not exists, this function returns -1.
Definition: Color.h:74
@ All
Definition: BitmapFont.h:63
Use this structure to specify options for import operations.
Definition: BitmapFont.h:68
virtual bool IsFixedWidth() const override
This function should return true if this font is fixed width.
Definition: BitmapFont.h:205
float linegap
Definition: BitmapFont.h:431
Collection is a container for reference typed objects.
Definition: Collection.h:21
long GetSize() const
Returns the number of elements in the map.
Definition: Hashmap.h:380
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
int ImportAtlas(Bitmap &&bmp, Geometry::Size grid={0, 0}, Glyph start=0x20, bool expand=false, ImportOptions options=ImportOptions{})
Imports the given bitmap as atlas image.
Definition: BitmapFont.cpp:477
This is a solid texture based image class.
Definition: Texture.h:211
This iterator allows iteration of directories.
Definition: Iterator.h:22
void Resize(const Geometry::Size &size, Graphics::ColorMode mode=Graphics::ColorMode::RGBA)
Resizes the image to the given size and color mode.
Definition: Bitmap.h:264
BitmapFont & operator=(const BitmapFont &)=delete
void SetHeight(int value)
Changes the line height of the font. Adding glyphs may override this value.
Definition: BitmapFont.h:237
void SetGlyphSpacing(int value)
Changes the spacing between glyphs.
Definition: BitmapFont.h:248
int ImportFolder(const std::string &path, ImportNamingTemplate naming=Automatic, Glyph start=0, std::string prefix="", ImportOptions options=ImportOptions{})
Imports bitmap font images from a folder with the specified file naming template.
Definition: BitmapFont.cpp:122
virtual int GetMaxWidth() const override
Returns the width of widest glyph.
Definition: BitmapFont.h:222
This interface defines a class that can be used as a common target for texture based drawing.
Definition: TextureTargets.h:12
int maxwidth
Definition: BitmapFont.h:415
@ Alpha
8bit alpha only color mode
This class represents a 2D point.
Definition: Point.h:32
bool isascii
Definition: BitmapFont.h:423
BitmapFont Duplicate()
Definition: BitmapFont.h:136
std::vector< Geometry::Bounds > CreateLinearAtlas(Containers::Collection< const Bitmap > list, AtlasMargin margins=None)
Assumes all image heights are similar and all images have same color mode.
Definition: Bitmap.cpp:374
virtual float GetLineThickness() const override
Should return the average thickness of a line.
Definition: BitmapFont.h:232
to be used internally.
Definition: BitmapFont.h:28
std::map< Glyph, GlyphDescriptor >::iterator begin()
Definition: BitmapFont.h:385
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
bool trim
Whether to trim whitespace around the glyphs.
Definition: BitmapFont.h:102
Glyph right
Definition: BitmapFont.h:407
This is the basic font, performing the minimal amount of operations necessary to render text on the s...
Definition: Font.h:271
const Geometry::Size GetSize() const
Returns the size of this object.
Definition: Drawables.h:443
virtual int GetDigitWidth() const override
Width of a digit, if digits do not have the same width, maximum should be returned.
Definition: BitmapFont.h:230
@ Graphics
Definition: Template.h:164
Definition: Drawables.h:74
virtual std::pair< int, int > GetLetterHeight(bool asciionly=false) const override
Definition: BitmapFont.cpp:997
virtual Geometry::Size GetSize(const std::string &text) const override
Returns the size of the given text.
Definition: Font.cpp:678
int GetGlyphSpacing() const
Returns the spacing between glyphs.
Definition: BitmapFont.h:251
virtual float GetLineGap() const override
This is the default distance between two consecutive lines.
Definition: BitmapFont.h:228
T_ Area() const
Returns the exact area of the rectangle has the size of this object.
Definition: Size.h:240
virtual void Prepare()
This function prepares image for drawing.
Definition: Bitmap.cpp:14
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
int automatickerningreduction
If automatic kerning is applied, this value will be used to reduce the kerning amount.
Definition: BitmapFont.h:126
T_ Width
Width of this size object.
Definition: Size.h:258
int spacing
Definition: BitmapFont.h:425
void AssumeGlyph(Glyph glyph, const RectangularDrawable &bitmap, int baseline=0)
Adds a new glyph bitmap to the list.
Definition: BitmapFont.h:164
@ None
Definition: BitmapFont.h:61
bool IsFile(const std::string &path)
Checks whether the given path is a file.
Definition: Linux.cpp:46
int GetWidth() const
Returns the width of the bitmap.
Definition: Bitmap.h:476
const RectangularDrawable * GetImage(Glyph g)
Returns the image that represents a glyph.
Definition: BitmapFont.h:336
virtual int GetEMSize() const override
Returns the size of the EM dash.
Definition: BitmapFont.h:220
virtual const GlyphRenderer & GetGlyphRenderer() const override
Returns the glyphrenderer that is used by this text renderer.
Definition: BitmapFont.h:381
bool Next()
Next path in the directory.
Definition: Linux.cpp:438
int GetWidth() const
Returns the width of the drawable.
Definition: Drawables.h:448
std::map< Glyph, GlyphDescriptor >::iterator end()
Definition: BitmapFont.h:389
Font resource.
Definition: Font.h:16
void SetKerning(Glyph left, Glyph right, Geometry::Pointf kern)
Definition: BitmapFont.h:180
std::string GetBasename(std::string path)
Returns the filename from the given path, without extension.
Definition: Filesystem.h:197
int linethickness
Definition: BitmapFont.h:427
BitmapFont(float baseline=0)
Definition: BitmapFont.h:132
bool automatickerning
Whether to apply automatic kerning after import is completed.
Definition: BitmapFont.h:121
@ Alpha
Characters are the filenames, not recommended as some symbols will not be accepted as filename.
Definition: BitmapFont.h:53
void SetBaseline(float value)
Changes the baseline. Might cause problems if the font already has glyphs in it.
Definition: BitmapFont.h:260
int underlinepos
Definition: BitmapFont.h:429
bool prepare
Prepares the loaded bitmaps. If pack option is set, this option is ignored.
Definition: BitmapFont.h:113
void SetMaxWidth(int value)
Changes the maximum width for a character. Adding glyphs may override this value.
Definition: BitmapFont.h:240
long FindLocation(const T_ *item) const
Searches the position of a given item, if not found -1 is returned.
Definition: Collection.h:538
Glyph left
Definition: BitmapFont.h:407
YesNoAuto
This enumeration helps with systems that has boolen parameters that can be detected automatically,...
Definition: Types.h:55
void Clear()
Cleans the contents of the buffer by setting every byte it contains to 0.
Definition: Bitmap.h:730
void SetLineThickness(int value)
Changes the line thickness to the specified value.
Definition: BitmapFont.h:254
virtual float GetBaseLine() const override
Baseline point of glyphs from the top.
Definition: BitmapFont.h:226
DeleteConstants
Definition: BitmapFont.h:60
void NotImplemented(const std::string &what="This feature")
Definition: Assert.h:187
bool estimatebaseline
If baseline is set to -1 (auto), setting this to true will use cheap baseline calculation instead of ...
Definition: BitmapFont.h:118
GlyphDescriptor(int index, Geometry::Pointf offset, float advance)
Definition: BitmapFont.h:35
std::map< Glyph, GlyphDescriptor >::const_iterator begin() const
Definition: BitmapFont.h:393
RGBAf color
Color of this renderer, can be overridden.
Definition: Font.h:423
void Remove(Glyph g)
Removes a glyph from the bitmap font.
Definition: BitmapFont.cpp:977
virtual int GetUnderlineOffset() const override
The position of the underline, if it is to be drawn.
Definition: BitmapFont.h:234
std::map< Glyph, GlyphDescriptor > glyphmap
Definition: BitmapFont.h:403
int index
Definition: BitmapFont.h:40
virtual int GetHeight() const override
Height of glyphs, actual size could be smaller but all glyphs should have the same virtual height.
Definition: BitmapFont.h:224
bool pack
Packs the bitmap font.
Definition: BitmapFont.h:92