2013-07-26 08:58:13 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 Zynga Inc.
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-10-24 14:09:59 +08:00
|
|
|
Copyright (c) 2021 Bytedance Inc.
|
2013-07-26 08:58:13 +08:00
|
|
|
|
2021-10-24 14:09:59 +08:00
|
|
|
https://adxe.org
|
2013-07-26 08:58:13 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _CCFontFNT_h_
|
|
|
|
#define _CCFontFNT_h_
|
|
|
|
|
2015-03-24 20:23:51 +08:00
|
|
|
/// @cond DO_NOT_SHOW
|
|
|
|
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "2d/CCFont.h"
|
2020-01-06 09:35:52 +08:00
|
|
|
#include <set>
|
|
|
|
#include <unordered_map>
|
2013-07-26 08:58:13 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2020-01-06 09:35:52 +08:00
|
|
|
/**
|
|
|
|
@struct BMFontDef
|
|
|
|
BMFont definition
|
|
|
|
*/
|
|
|
|
typedef struct _BMFontDef {
|
|
|
|
//! ID of the character
|
|
|
|
unsigned int charID;
|
|
|
|
//! origin and size of the font
|
|
|
|
Rect rect;
|
|
|
|
//! The X amount the image should be offset when drawing the image (in pixels)
|
|
|
|
short xOffset;
|
|
|
|
//! The Y amount the image should be offset when drawing the image (in pixels)
|
|
|
|
short yOffset;
|
|
|
|
//! The amount to move the current position after drawing the character (in pixels)
|
|
|
|
short xAdvance;
|
|
|
|
} BMFontDef;
|
|
|
|
|
|
|
|
/** @struct BMFontPadding
|
|
|
|
BMFont padding
|
|
|
|
@since v0.8.2
|
|
|
|
*/
|
|
|
|
typedef struct _BMFontPadding {
|
|
|
|
/// padding left
|
|
|
|
int left;
|
|
|
|
/// padding top
|
|
|
|
int top;
|
|
|
|
/// padding right
|
|
|
|
int right;
|
|
|
|
/// padding bottom
|
|
|
|
int bottom;
|
|
|
|
} BMFontPadding;
|
|
|
|
|
|
|
|
/** @brief BMFontConfiguration has parsed configuration of the .fnt file
|
|
|
|
@since v0.8
|
|
|
|
*/
|
|
|
|
class CC_DLL BMFontConfiguration : public Ref
|
|
|
|
{
|
|
|
|
// FIXME: Creating a public interface so that the bitmapFontArray[] is accessible
|
|
|
|
public://@public
|
|
|
|
// BMFont definitions
|
|
|
|
std::unordered_map<int /* key */, BMFontDef /* fontDef */> _fontDefDictionary;
|
|
|
|
|
|
|
|
//! FNTConfig: Common Height Should be signed (issue #1343)
|
|
|
|
int _commonHeight;
|
|
|
|
|
|
|
|
//! Padding
|
|
|
|
BMFontPadding _padding;
|
|
|
|
|
|
|
|
//! atlas name
|
|
|
|
std::string _atlasName;
|
|
|
|
|
|
|
|
//! values for kerning
|
|
|
|
std::unordered_map<uint64_t /* key */, int /* amount */> _kerningDictionary;
|
|
|
|
|
|
|
|
// Character Set defines the letters that actually exist in the font
|
|
|
|
std::set<unsigned int>* _characterSet;
|
|
|
|
|
2021-10-24 14:09:59 +08:00
|
|
|
//! Font size
|
2020-01-06 09:35:52 +08:00
|
|
|
int _fontSize;
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
|
|
|
BMFontConfiguration();
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~BMFontConfiguration();
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
std::string description() const;
|
|
|
|
|
|
|
|
/** allocates a BMFontConfiguration with a FNT file */
|
|
|
|
static BMFontConfiguration* create(const std::string& FNTfile);
|
|
|
|
|
|
|
|
/** initializes a BitmapFontConfiguration with a FNT file */
|
|
|
|
bool initWithFNTfile(const std::string& FNTfile);
|
|
|
|
|
|
|
|
const std::string& getAtlasName() { return _atlasName; }
|
|
|
|
void setAtlasName(const std::string& atlasName) { _atlasName = atlasName; }
|
|
|
|
|
|
|
|
std::set<unsigned int>* getCharacterSet() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual std::set<unsigned int>* parseConfigFile(const std::string& controlFile);
|
2021-09-02 13:39:28 +08:00
|
|
|
virtual std::set<unsigned int>* parseBinaryConfigFile(unsigned char* pData, uint32_t size, const std::string& controlFile);
|
2020-01-06 09:35:52 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned int parseCharacterDefinition(const char* line);
|
|
|
|
void parseInfoArguments(const char* line);
|
|
|
|
void parseCommonArguments(const char* line);
|
|
|
|
void parseImageFileName(const char* line, const std::string& fntFile);
|
|
|
|
void parseKerningEntry(const char* line);
|
|
|
|
void purgeKerningDictionary();
|
|
|
|
void purgeFontDefDictionary();
|
|
|
|
};
|
2014-01-17 13:35:58 +08:00
|
|
|
|
2014-08-08 15:22:43 +08:00
|
|
|
class CC_DLL FontFNT : public Font
|
2013-07-26 08:58:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2020-01-06 09:35:52 +08:00
|
|
|
static FontFNT* create(const std::string& fntFilePath, const Rect& imageRect, bool imageRotated);
|
|
|
|
static FontFNT* create(const std::string& fntFilePath, const std::string& subTextureKey);
|
|
|
|
static FontFNT* create(const std::string& fntFilePath);
|
|
|
|
|
|
|
|
CC_DEPRECATED_ATTRIBUTE static FontFNT* create(const std::string& fntFilePath, const Vec2& imageOffset = Vec2::ZERO);
|
|
|
|
|
2014-02-20 22:33:52 +08:00
|
|
|
/** Purges the cached data.
|
|
|
|
Removes from memory the cached configurations and the atlas name dictionary.
|
|
|
|
*/
|
|
|
|
static void purgeCachedData();
|
2017-02-06 16:41:52 +08:00
|
|
|
virtual int* getHorizontalKerningForTextUTF32(const std::u32string& text, int &outNumLetters) const override;
|
2021-11-11 17:20:21 +08:00
|
|
|
virtual FontAtlas* newFontAtlas() override;
|
2020-01-06 09:35:52 +08:00
|
|
|
|
2015-11-19 16:06:13 +08:00
|
|
|
void setFontSize(float fontSize);
|
2020-01-06 09:35:52 +08:00
|
|
|
float getFontSize() const { return _fontSize; }
|
|
|
|
|
2015-11-19 16:06:13 +08:00
|
|
|
int getOriginalFontSize()const;
|
2015-11-12 09:49:49 +08:00
|
|
|
|
|
|
|
static void reloadBMFontResource(const std::string& fntFilePath);
|
|
|
|
|
2013-08-06 06:56:18 +08:00
|
|
|
protected:
|
|
|
|
|
2020-01-06 09:35:52 +08:00
|
|
|
FontFNT(BMFontConfiguration* theContfig, const Rect& imageRect, bool imageRotated);
|
|
|
|
FontFNT(BMFontConfiguration* theContfig);
|
|
|
|
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-08-06 06:56:18 +08:00
|
|
|
virtual ~FontFNT();
|
2020-01-06 09:35:52 +08:00
|
|
|
|
|
|
|
BMFontConfiguration* _configuration;
|
|
|
|
|
2017-02-06 16:41:52 +08:00
|
|
|
int getHorizontalKerningForChars(char32_t firstChar, char32_t secondChar) const;
|
2020-01-06 09:35:52 +08:00
|
|
|
|
|
|
|
Rect _imageRectInPoints;
|
|
|
|
bool _imageRotated;
|
|
|
|
|
2015-11-19 16:06:13 +08:00
|
|
|
//User defined font size
|
|
|
|
float _fontSize;
|
2013-07-26 08:58:13 +08:00
|
|
|
};
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/// @endcond
|
|
|
|
|
2013-07-26 08:58:13 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif /* defined(__cocos2d_libs__CCFontFNT__) */
|