CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/Font/PGF.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617// Thanks to the JPCSP project! This sceFont implementation is basically a C++ take on JPCSP's font code.1819#pragma once2021#include <string>22#include <vector>2324#include "Common/CommonTypes.h"2526class PointerWrap;2728enum {29FONT_FILETYPE_PGF = 0x00,30FONT_FILETYPE_BWFON = 0x01,31};3233enum {34FONT_PGF_BMP_H_ROWS = 0x01,35FONT_PGF_BMP_V_ROWS = 0x02,36FONT_PGF_BMP_OVERLAY = 0x03,37// Metric names according to JPCSP findings38FONT_PGF_METRIC_DIMENSION_INDEX = 0x04,39FONT_PGF_METRIC_BEARING_X_INDEX = 0x08,40FONT_PGF_METRIC_BEARING_Y_INDEX = 0x10,41FONT_PGF_METRIC_ADVANCE_INDEX = 0x20,42FONT_PGF_CHARGLYPH = 0x20,43FONT_PGF_SHADOWGLYPH = 0x40,44};4546enum Family {47FONT_FAMILY_SANS_SERIF = 1,48FONT_FAMILY_SERIF = 2,49};5051enum Style {52FONT_STYLE_REGULAR = 1,53FONT_STYLE_ITALIC = 2,54FONT_STYLE_BOLD = 5,55FONT_STYLE_BOLD_ITALIC = 6,56FONT_STYLE_DB = 103, // Demi-Bold / semi-bold57};5859enum Language {60FONT_LANGUAGE_JAPANESE = 1,61FONT_LANGUAGE_LATIN = 2,62FONT_LANGUAGE_KOREAN = 3,63FONT_LANGUAGE_CHINESE = 4,64};6566enum FontPixelFormat {67PSP_FONT_PIXELFORMAT_4 = 0, // 2 pixels packed in 1 byte (natural order)68PSP_FONT_PIXELFORMAT_4_REV = 1, // 2 pixels packed in 1 byte (reversed order)69PSP_FONT_PIXELFORMAT_8 = 2, // 1 pixel in 1 byte70PSP_FONT_PIXELFORMAT_24 = 3, // 1 pixel in 3 bytes (RGB)71PSP_FONT_PIXELFORMAT_32 = 4, // 1 pixel in 4 bytes (RGBA)72};737475struct PGFFontStyle {76float_le fontH;77float_le fontV;78float_le fontHRes;79float_le fontVRes;80float_le fontWeight;81u16_le fontFamily;82u16_le fontStyle;83// Check.84u16_le fontStyleSub;85u16_le fontLanguage;86u16_le fontRegion;87u16_le fontCountry;88char fontName[64];89char fontFileName[64];90u32_le fontAttributes;91u32_le fontExpire;92};939495struct Glyph {96int w;97int h;98int left;99int top;100int flags;101int shadowFlags;102int shadowID;103int advanceH;104int advanceV;105int dimensionWidth, dimensionHeight;106int xAdjustH, xAdjustV;107int yAdjustH, yAdjustV;108u32 ptr;109};110111112#if COMMON_LITTLE_ENDIAN113typedef FontPixelFormat FontPixelFormat_le;114#else115typedef swap_struct_t<FontPixelFormat, swap_32_t<FontPixelFormat> > FontPixelFormat_le;116#endif117118struct GlyphImage {119FontPixelFormat_le pixelFormat;120s32_le xPos64;121s32_le yPos64;122u16_le bufWidth;123u16_le bufHeight;124u16_le bytesPerLine;125u16_le pad;126u32_le bufferPtr;127};128129#pragma pack(push,1)130struct PGFHeader131{132u16_le headerOffset;133u16_le headerSize;134135char PGFMagic[4];136s32_le revision;137s32_le version;138139s32_le charMapLength;140s32_le charPointerLength;141s32_le charMapBpe;142s32_le charPointerBpe;143144// TODO: This has values in it (0404)...145u8 pad1[2];146u8 bpp;147u8 pad2[1];148149s32_le hSize;150s32_le vSize;151s32_le hResolution;152s32_le vResolution;153154u8 pad3[1];155char fontName[64];156char fontType[64];157u8 pad4[1];158159u16_le firstGlyph;160u16_le lastGlyph;161162// TODO: This has a few 01s in it in the official fonts.163u8 pad5[26];164165s32_le maxAscender;166s32_le maxDescender;167s32_le maxLeftXAdjust;168s32_le maxBaseYAdjust;169s32_le minCenterXAdjust;170s32_le maxTopYAdjust;171172s32_le maxAdvance[2];173s32_le maxSize[2];174u16_le maxGlyphWidth;175u16_le maxGlyphHeight;176u8 pad6[2];177178u8 dimTableLength;179u8 xAdjustTableLength;180u8 yAdjustTableLength;181u8 advanceTableLength;182u8 pad7[102];183184s32_le shadowMapLength;185s32_le shadowMapBpe;186float_le unknown1;187s32_le shadowScale[2];188u8 pad8[8];189};190191struct PGFHeaderRev3Extra {192s32_le compCharMapBpe1;193s32_le compCharMapLength1;194s32_le compCharMapBpe2;195s32_le compCharMapLength2;196u32_le unknown;197};198199struct PGFCharInfo {200u32_le bitmapWidth;201u32_le bitmapHeight;202u32_le bitmapLeft;203u32_le bitmapTop;204// Glyph metrics (in 26.6 signed fixed-point).205u32_le sfp26Width;206u32_le sfp26Height;207s32_le sfp26Ascender;208s32_le sfp26Descender;209s32_le sfp26BearingHX;210s32_le sfp26BearingHY;211s32_le sfp26BearingVX;212s32_le sfp26BearingVY;213s32_le sfp26AdvanceH;214s32_le sfp26AdvanceV;215s16_le shadowFlags;216s16_le shadowId;217};218219struct PGFFontInfo {220// Glyph metrics (in 26.6 signed fixed-point).221s32_le maxGlyphWidthI;222s32_le maxGlyphHeightI;223s32_le maxGlyphAscenderI;224s32_le maxGlyphDescenderI;225s32_le maxGlyphLeftXI;226s32_le maxGlyphBaseYI;227s32_le minGlyphCenterXI;228s32_le maxGlyphTopYI;229s32_le maxGlyphAdvanceXI;230s32_le maxGlyphAdvanceYI;231232// Glyph metrics (replicated as float).233float_le maxGlyphWidthF;234float_le maxGlyphHeightF;235float_le maxGlyphAscenderF;236float_le maxGlyphDescenderF;237float_le maxGlyphLeftXF;238float_le maxGlyphBaseYF;239float_le minGlyphCenterXF;240float_le maxGlyphTopYF;241float_le maxGlyphAdvanceXF;242float_le maxGlyphAdvanceYF;243244// Bitmap dimensions.245s16_le maxGlyphWidth;246s16_le maxGlyphHeight;247s32_le numGlyphs;248s32_le shadowMapLength; // Number of elements in the font's shadow charmap.249250// Font style (used by font comparison functions).251PGFFontStyle fontStyle;252253u8 BPP; // Font's BPP.254u8 pad[3];255};256257#pragma pack(pop)258259class PGF {260public:261PGF();262~PGF();263264bool ReadPtr(const u8 *ptr, size_t dataSize);265266bool GetCharInfo(int charCode, PGFCharInfo *ci, int altCharCode, int glyphType = FONT_PGF_CHARGLYPH) const;267void GetFontInfo(PGFFontInfo *fi) const;268void DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipWidth, int clipHeight, int charCode, int altCharCode, int glyphType) const;269270void DoState(PointerWrap &p);271272PGFHeader header;273274private:275bool ReadCharGlyph(const u8 *fontdata, size_t charPtr, Glyph &glyph);276bool ReadShadowGlyph(const u8 *fontdata, size_t charPtr, Glyph &glyph);277bool GetCharGlyph(int charCode, int glyphType, Glyph &glyph) const;278279// Unused280int GetCharIndex(int charCode, const std::vector<int> &charmapCompressed);281282void SetFontPixel(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, u8 pixelColor, FontPixelFormat pixelformat) const;283284PGFHeaderRev3Extra rev3extra;285286// Font character image data287u8 *fontData;288size_t fontDataSize;289290std::string fileName;291292std::vector<int> dimensionTable[2];293std::vector<int> xAdjustTable[2];294std::vector<int> yAdjustTable[2];295std::vector<int> advanceTable[2];296297// Unused298std::vector<int> charmapCompressionTable1[2];299std::vector<int> charmapCompressionTable2[2];300301std::vector<int> charmap_compr;302std::vector<int> charmap;303304std::vector<Glyph> glyphs;305std::vector<Glyph> shadowGlyphs;306int firstGlyph;307};308309310