2013-02-22 19:05:07 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
// Thanks to the JPCSP project! This sceFont implementation is basically a C++ take on JPCSP's font code.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Common/Log.h"
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
2014-03-15 18:32:57 +00:00
|
|
|
class PointerWrap;
|
|
|
|
|
2013-02-22 19:05:07 +00:00
|
|
|
enum {
|
|
|
|
FONT_FILETYPE_PGF = 0x00,
|
|
|
|
FONT_FILETYPE_BWFON = 0x01,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FONT_PGF_BMP_H_ROWS = 0x01,
|
|
|
|
FONT_PGF_BMP_V_ROWS = 0x02,
|
|
|
|
FONT_PGF_BMP_OVERLAY = 0x03,
|
2013-08-13 12:59:10 +00:00
|
|
|
// Metric names according to JPCSP findings
|
|
|
|
FONT_PGF_METRIC_DIMENSION_INDEX = 0x04,
|
|
|
|
FONT_PGF_METRIC_BEARING_X_INDEX = 0x08,
|
|
|
|
FONT_PGF_METRIC_BEARING_Y_INDEX = 0x10,
|
2013-11-17 02:35:15 +00:00
|
|
|
FONT_PGF_METRIC_ADVANCE_INDEX = 0x20,
|
2013-02-22 19:05:07 +00:00
|
|
|
FONT_PGF_CHARGLYPH = 0x20,
|
|
|
|
FONT_PGF_SHADOWGLYPH = 0x40,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Family {
|
|
|
|
FONT_FAMILY_SANS_SERIF = 1,
|
|
|
|
FONT_FAMILY_SERIF = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Style {
|
|
|
|
FONT_STYLE_REGULAR = 1,
|
|
|
|
FONT_STYLE_ITALIC = 2,
|
|
|
|
FONT_STYLE_BOLD = 5,
|
|
|
|
FONT_STYLE_BOLD_ITALIC = 6,
|
|
|
|
FONT_STYLE_DB = 103, // Demi-Bold / semi-bold
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Language {
|
|
|
|
FONT_LANGUAGE_JAPANESE = 1,
|
|
|
|
FONT_LANGUAGE_LATIN = 2,
|
|
|
|
FONT_LANGUAGE_KOREAN = 3,
|
|
|
|
FONT_LANGUAGE_CHINESE = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum FontPixelFormat {
|
2014-03-03 16:16:53 +00:00
|
|
|
PSP_FONT_PIXELFORMAT_4 = 0, // 2 pixels packed in 1 byte (natural order)
|
2013-02-22 19:05:07 +00:00
|
|
|
PSP_FONT_PIXELFORMAT_4_REV = 1, // 2 pixels packed in 1 byte (reversed order)
|
2014-03-03 16:16:53 +00:00
|
|
|
PSP_FONT_PIXELFORMAT_8 = 2, // 1 pixel in 1 byte
|
|
|
|
PSP_FONT_PIXELFORMAT_24 = 3, // 1 pixel in 3 bytes (RGB)
|
|
|
|
PSP_FONT_PIXELFORMAT_32 = 4, // 1 pixel in 4 bytes (RGBA)
|
2013-02-22 19:05:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct PGFFontStyle {
|
2013-07-25 07:18:50 +00:00
|
|
|
float_le fontH;
|
|
|
|
float_le fontV;
|
|
|
|
float_le fontHRes;
|
|
|
|
float_le fontVRes;
|
|
|
|
float_le fontWeight;
|
|
|
|
u16_le fontFamily;
|
|
|
|
u16_le fontStyle;
|
2013-02-22 19:05:07 +00:00
|
|
|
// Check.
|
2013-07-25 07:18:50 +00:00
|
|
|
u16_le fontStyleSub;
|
|
|
|
u16_le fontLanguage;
|
|
|
|
u16_le fontRegion;
|
|
|
|
u16_le fontCountry;
|
2014-03-03 16:16:53 +00:00
|
|
|
char fontName[64];
|
|
|
|
char fontFileName[64];
|
2013-07-25 07:18:50 +00:00
|
|
|
u32_le fontAttributes;
|
|
|
|
u32_le fontExpire;
|
2013-02-22 19:05:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-03-21 06:37:18 +00:00
|
|
|
struct Glyph {
|
2013-02-22 19:05:07 +00:00
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
int left;
|
|
|
|
int top;
|
|
|
|
int flags;
|
2013-11-17 05:08:12 +00:00
|
|
|
int shadowFlags;
|
2013-02-22 19:05:07 +00:00
|
|
|
int shadowID;
|
|
|
|
int advanceH;
|
|
|
|
int advanceV;
|
|
|
|
int dimensionWidth, dimensionHeight;
|
|
|
|
int xAdjustH, xAdjustV;
|
|
|
|
int yAdjustH, yAdjustV;
|
|
|
|
u32 ptr;
|
|
|
|
};
|
|
|
|
|
2013-07-25 23:18:40 +00:00
|
|
|
|
2013-07-26 05:25:50 +00:00
|
|
|
#if COMMON_LITTLE_ENDIAN
|
2013-07-25 07:18:50 +00:00
|
|
|
typedef FontPixelFormat FontPixelFormat_le;
|
|
|
|
#else
|
2013-07-29 03:28:32 +00:00
|
|
|
typedef swap_struct_t<FontPixelFormat, swap_32_t<FontPixelFormat> > FontPixelFormat_le;
|
2013-07-25 07:18:50 +00:00
|
|
|
#endif
|
|
|
|
|
2013-05-06 04:13:50 +00:00
|
|
|
struct GlyphImage {
|
2013-07-25 07:18:50 +00:00
|
|
|
FontPixelFormat_le pixelFormat;
|
|
|
|
s32_le xPos64;
|
|
|
|
s32_le yPos64;
|
|
|
|
u16_le bufWidth;
|
|
|
|
u16_le bufHeight;
|
|
|
|
u16_le bytesPerLine;
|
|
|
|
u16_le pad;
|
|
|
|
u32_le bufferPtr;
|
2013-05-06 04:13:50 +00:00
|
|
|
};
|
|
|
|
|
2013-02-22 19:05:07 +00:00
|
|
|
#pragma pack(push,1)
|
|
|
|
struct PGFHeader
|
|
|
|
{
|
2013-07-25 07:18:50 +00:00
|
|
|
u16_le headerOffset;
|
|
|
|
u16_le headerSize;
|
2013-02-22 19:05:07 +00:00
|
|
|
|
|
|
|
char PGFMagic[4];
|
2013-07-25 07:18:50 +00:00
|
|
|
s32_le revision;
|
|
|
|
s32_le version;
|
2013-02-22 19:05:07 +00:00
|
|
|
|
2013-07-25 07:18:50 +00:00
|
|
|
s32_le charMapLength;
|
|
|
|
s32_le charPointerLength;
|
|
|
|
s32_le charMapBpe;
|
|
|
|
s32_le charPointerBpe;
|
2013-02-22 19:05:07 +00:00
|
|
|
|
2013-11-17 06:53:05 +00:00
|
|
|
// TODO: This has values in it (0404)...
|
2013-02-22 19:05:07 +00:00
|
|
|
u8 pad1[2];
|
|
|
|
u8 bpp;
|
|
|
|
u8 pad2[1];
|
|
|
|
|
2013-07-25 07:18:50 +00:00
|
|
|
s32_le hSize;
|
|
|
|
s32_le vSize;
|
|
|
|
s32_le hResolution;
|
|
|
|
s32_le vResolution;
|
2013-02-22 19:05:07 +00:00
|
|
|
|
|
|
|
u8 pad3[1];
|
|
|
|
char fontName[64];
|
|
|
|
char fontType[64];
|
|
|
|
u8 pad4[1];
|
|
|
|
|
2013-07-25 07:18:50 +00:00
|
|
|
u16_le firstGlyph;
|
|
|
|
u16_le lastGlyph;
|
2013-02-22 19:05:07 +00:00
|
|
|
|
2013-11-17 06:53:05 +00:00
|
|
|
// TODO: This has a few 01s in it in the official fonts.
|
2013-02-22 19:05:07 +00:00
|
|
|
u8 pad5[26];
|
|
|
|
|
2013-07-25 07:18:50 +00:00
|
|
|
s32_le maxAscender;
|
|
|
|
s32_le maxDescender;
|
|
|
|
s32_le maxLeftXAdjust;
|
|
|
|
s32_le maxBaseYAdjust;
|
|
|
|
s32_le minCenterXAdjust;
|
|
|
|
s32_le maxTopYAdjust;
|
|
|
|
|
|
|
|
s32_le maxAdvance[2];
|
|
|
|
s32_le maxSize[2];
|
|
|
|
u16_le maxGlyphWidth;
|
|
|
|
u16_le maxGlyphHeight;
|
2013-02-22 19:05:07 +00:00
|
|
|
u8 pad6[2];
|
|
|
|
|
|
|
|
u8 dimTableLength;
|
|
|
|
u8 xAdjustTableLength;
|
|
|
|
u8 yAdjustTableLength;
|
|
|
|
u8 advanceTableLength;
|
|
|
|
u8 pad7[102];
|
|
|
|
|
2013-07-25 07:18:50 +00:00
|
|
|
s32_le shadowMapLength;
|
|
|
|
s32_le shadowMapBpe;
|
|
|
|
float_le unknown1;
|
|
|
|
s32_le shadowScale[2];
|
2013-02-22 19:05:07 +00:00
|
|
|
u8 pad8[8];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PGFHeaderRev3Extra {
|
2013-07-25 07:18:50 +00:00
|
|
|
s32_le compCharMapBpe1;
|
|
|
|
s32_le compCharMapLength1;
|
|
|
|
s32_le compCharMapBpe2;
|
|
|
|
s32_le compCharMapLength2;
|
|
|
|
u32_le unknown;
|
2013-02-22 19:05:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PGFCharInfo {
|
2013-07-25 07:18:50 +00:00
|
|
|
u32_le bitmapWidth;
|
|
|
|
u32_le bitmapHeight;
|
|
|
|
u32_le bitmapLeft;
|
|
|
|
u32_le bitmapTop;
|
2013-02-22 19:05:07 +00:00
|
|
|
// Glyph metrics (in 26.6 signed fixed-point).
|
2013-07-25 07:18:50 +00:00
|
|
|
u32_le sfp26Width;
|
|
|
|
u32_le sfp26Height;
|
|
|
|
s32_le sfp26Ascender;
|
|
|
|
s32_le sfp26Descender;
|
|
|
|
s32_le sfp26BearingHX;
|
|
|
|
s32_le sfp26BearingHY;
|
|
|
|
s32_le sfp26BearingVX;
|
|
|
|
s32_le sfp26BearingVY;
|
|
|
|
s32_le sfp26AdvanceH;
|
|
|
|
s32_le sfp26AdvanceV;
|
2013-11-17 05:08:12 +00:00
|
|
|
s16_le shadowFlags;
|
|
|
|
s16_le shadowId;
|
2013-02-22 19:05:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PGFFontInfo {
|
|
|
|
// Glyph metrics (in 26.6 signed fixed-point).
|
2013-07-25 07:18:50 +00:00
|
|
|
s32_le maxGlyphWidthI;
|
|
|
|
s32_le maxGlyphHeightI;
|
|
|
|
s32_le maxGlyphAscenderI;
|
|
|
|
s32_le maxGlyphDescenderI;
|
|
|
|
s32_le maxGlyphLeftXI;
|
|
|
|
s32_le maxGlyphBaseYI;
|
|
|
|
s32_le minGlyphCenterXI;
|
|
|
|
s32_le maxGlyphTopYI;
|
|
|
|
s32_le maxGlyphAdvanceXI;
|
|
|
|
s32_le maxGlyphAdvanceYI;
|
2013-02-22 19:05:07 +00:00
|
|
|
|
|
|
|
// Glyph metrics (replicated as float).
|
2013-07-25 07:18:50 +00:00
|
|
|
float_le maxGlyphWidthF;
|
|
|
|
float_le maxGlyphHeightF;
|
|
|
|
float_le maxGlyphAscenderF;
|
|
|
|
float_le maxGlyphDescenderF;
|
|
|
|
float_le maxGlyphLeftXF;
|
|
|
|
float_le maxGlyphBaseYF;
|
|
|
|
float_le minGlyphCenterXF;
|
|
|
|
float_le maxGlyphTopYF;
|
|
|
|
float_le maxGlyphAdvanceXF;
|
|
|
|
float_le maxGlyphAdvanceYF;
|
2013-02-22 19:05:07 +00:00
|
|
|
|
|
|
|
// Bitmap dimensions.
|
2013-07-25 07:18:50 +00:00
|
|
|
s16_le maxGlyphWidth;
|
|
|
|
s16_le maxGlyphHeight;
|
2013-11-17 02:33:10 +00:00
|
|
|
s32_le numGlyphs;
|
2013-07-25 07:18:50 +00:00
|
|
|
s32_le shadowMapLength; // Number of elements in the font's shadow charmap.
|
2013-02-22 19:05:07 +00:00
|
|
|
|
|
|
|
// Font style (used by font comparison functions).
|
|
|
|
PGFFontStyle fontStyle;
|
|
|
|
|
2013-11-17 07:39:19 +00:00
|
|
|
u8 BPP; // Font's BPP.
|
|
|
|
u8 pad[3];
|
2013-02-22 19:05:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
class PGF {
|
|
|
|
public:
|
|
|
|
PGF();
|
|
|
|
~PGF();
|
|
|
|
|
2014-02-23 04:35:58 +00:00
|
|
|
bool ReadPtr(const u8 *ptr, size_t dataSize);
|
2013-02-22 19:05:07 +00:00
|
|
|
|
2014-03-01 07:04:34 +00:00
|
|
|
bool GetCharInfo(int charCode, PGFCharInfo *ci, int altCharCode, int glyphType = FONT_PGF_CHARGLYPH) const;
|
2014-02-27 08:19:40 +00:00
|
|
|
void GetFontInfo(PGFFontInfo *fi) const;
|
|
|
|
void DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipWidth, int clipHeight, int charCode, int altCharCode, int glyphType) const;
|
2013-02-22 19:05:07 +00:00
|
|
|
|
|
|
|
void DoState(PointerWrap &p);
|
|
|
|
|
|
|
|
PGFHeader header;
|
|
|
|
|
|
|
|
private:
|
2014-03-01 08:18:19 +00:00
|
|
|
bool ReadCharGlyph(const u8 *fontdata, size_t charPtr, Glyph &glyph);
|
|
|
|
bool ReadShadowGlyph(const u8 *fontdata, size_t charPtr, Glyph &glyph);
|
2014-02-27 08:19:40 +00:00
|
|
|
bool GetCharGlyph(int charCode, int glyphType, Glyph &glyph) const;
|
2013-02-22 19:05:07 +00:00
|
|
|
|
|
|
|
// Unused
|
|
|
|
int GetCharIndex(int charCode, const std::vector<int> &charmapCompressed);
|
|
|
|
|
2014-02-27 08:19:40 +00:00
|
|
|
void SetFontPixel(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int pixelColor, int pixelformat) const;
|
2013-02-22 19:05:07 +00:00
|
|
|
|
|
|
|
PGFHeaderRev3Extra rev3extra;
|
|
|
|
|
|
|
|
// Font character image data
|
|
|
|
u8 *fontData;
|
|
|
|
size_t fontDataSize;
|
|
|
|
|
|
|
|
std::string fileName;
|
|
|
|
|
|
|
|
std::vector<int> dimensionTable[2];
|
|
|
|
std::vector<int> xAdjustTable[2];
|
|
|
|
std::vector<int> yAdjustTable[2];
|
|
|
|
std::vector<int> advanceTable[2];
|
|
|
|
|
|
|
|
// Unused
|
|
|
|
std::vector<int> charmapCompressionTable1[2];
|
|
|
|
std::vector<int> charmapCompressionTable2[2];
|
|
|
|
|
|
|
|
std::vector<int> charmap_compr;
|
|
|
|
std::vector<int> charmap;
|
|
|
|
|
|
|
|
std::vector<Glyph> glyphs;
|
|
|
|
std::vector<Glyph> shadowGlyphs;
|
|
|
|
int firstGlyph;
|
|
|
|
};
|