J :
* Add multilingual support for utf-8.
* Use japanese as a test case (removing the old tentative support).
* A number of shortcomings affect this code.
+ Bugs :
- This splits algorithms used to determine the length of a string
and to render it in two: either the string starts with an ascii
char and the monobyte, variable-space algorithm is used, or it
does not and a multibyte but fixed-space algorithm is used.
This shortcoming also exists in the code to support chinese.
- From the above comes the biggest limitation: any string that
starts with an ascii character but include non-ascii characters
will not be rendered correctly.
- This does not and cannot support chars outside the BMP. This
probably won't matter, ever.
+ Todos, fixmes, wishlist :
- Single-width characters with diacritics are reported as
double-space chars. It doesn't matter too much at the moment, but
should be fixed in the future.
- Font support currently only includes japanese.
+ Performance and compatibility notes :
- Chinese code has not been switched to utf-8, to maintain backward
compatibility. We should switch it at some point in the future,
but ponder the right way to do it first.
- Retaining the support for chinese with a non-international
charset hurts performance (by making some methods uselessly
virtual).
* Still, this generally works and is extensible (it can be used to
implement korean, traditional chinese, etc, without any more code).
Implementing languages with diacritics needs an improvement of the
bool doubleWidthChar() method.
This commit is contained in:
@@ -18,7 +18,7 @@ namespace Fonts
|
||||
};
|
||||
|
||||
// when using gbk languages and we need to keep around single byte font variants,
|
||||
// the single byte fonts will be offset by this value
|
||||
// the single byte fonts will be offset by this value
|
||||
const unsigned int kSingleByteFontOffset = 100;
|
||||
}
|
||||
|
||||
@@ -75,27 +75,29 @@ class WFBFont : public WFont
|
||||
{
|
||||
public:
|
||||
WFBFont(int inFontID, const char *fontname, int lineheight, bool useVideoRAM=false);
|
||||
WFBFont(int inFontID) : WFont(inFontID) {}; // Legacy : remove it when possible
|
||||
~WFBFont();
|
||||
|
||||
void DrawString(const char *s, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float width = 0);
|
||||
void DrawString(std::string s, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float width = 0);
|
||||
void SetColor(PIXEL_TYPE color);
|
||||
PIXEL_TYPE GetColor() const {return mColor0;};
|
||||
void SetScale(float scale);
|
||||
float GetScale() const;
|
||||
float GetHeight() const;
|
||||
float GetStringWidth(const char *s) const;
|
||||
virtual float GetStringWidth(const char *s) const;
|
||||
void SetTracking(float tracking) {};
|
||||
void SetBase(int base) {};
|
||||
|
||||
virtual int GetCode(const u8 *ch, bool *dualByteFont) const = 0;
|
||||
virtual void DrawString(const char *s, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float width = 0);
|
||||
virtual int GetCode(const u8 *ch, int *charLength) const = 0;
|
||||
virtual int GetMana(const u8 *ch) const = 0;
|
||||
|
||||
private:
|
||||
static JRenderer * mRenderer;
|
||||
protected:
|
||||
static JRenderer* mRenderer;
|
||||
|
||||
u8 * mEngFont;
|
||||
u8 * mChnFont;
|
||||
u16* mIndex;
|
||||
u8* mStdFont;
|
||||
u8* mExtraFont;
|
||||
|
||||
PIXEL_TYPE mColor0;
|
||||
PIXEL_TYPE mColor;
|
||||
@@ -116,26 +118,28 @@ private:
|
||||
|
||||
u32 * mCharBuffer;
|
||||
|
||||
int PreCacheChar(const u8 *ch);
|
||||
virtual int PreCacheChar(const u8 *ch);
|
||||
};
|
||||
|
||||
class WGBKFont : public WFBFont
|
||||
{
|
||||
public:
|
||||
WGBKFont(int inFontID, const char *fontname, int lineheight, bool useVideoRAM=false)
|
||||
: WFBFont(inFontID, fontname, lineheight, useVideoRAM) {};
|
||||
WGBKFont(int inFontID, const char *fontname, int lineheight, bool useVideoRAM = false);
|
||||
|
||||
int GetCode(const u8 *ch, bool *dualByteFont) const;
|
||||
int PreCacheChar(const u8 *ch);
|
||||
float GetStringWidth(const char *s) const;
|
||||
void DrawString(const char *s, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float width = 0);
|
||||
int GetCode(const u8 *ch, int *charLength) const;
|
||||
int GetMana(const u8 *ch) const;
|
||||
};
|
||||
|
||||
class WSJISFont : public WFBFont
|
||||
class WUFont : public WFBFont
|
||||
{
|
||||
public:
|
||||
WSJISFont(int inFontID, const char *fontname, int lineheight, bool useVideoRAM=false)
|
||||
WUFont(int inFontID, const char *fontname, int lineheight, bool useVideoRAM = false)
|
||||
: WFBFont(inFontID, fontname, lineheight, useVideoRAM) {};
|
||||
|
||||
int GetCode(const u8 *ch, bool *dualByteFont) const;
|
||||
int GetCode(const u8 *ch, int *charLength) const;
|
||||
int GetMana(const u8 *ch) const;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user