summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/include/fxge/fx_font.h42
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp27
-rw-r--r--core/src/fxge/ge/fx_ge_font.cpp205
-rw-r--r--core/src/fxge/ge/text_int.h36
4 files changed, 103 insertions, 207 deletions
diff --git a/core/include/fxge/fx_font.h b/core/include/fxge/fx_font.h
index ff664f9532..7eaa323717 100644
--- a/core/include/fxge/fx_font.h
+++ b/core/include/fxge/fx_font.h
@@ -140,18 +140,6 @@ class CFX_Font {
#define ENCODING_INTERNAL 0
#define ENCODING_UNICODE 1
-class IFX_FontEncoding {
- public:
- virtual ~IFX_FontEncoding() {}
-
- virtual FX_DWORD GlyphFromCharCode(FX_DWORD charcode) = 0;
-
- virtual CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const = 0;
-
- virtual FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const = 0;
-};
-
-IFX_FontEncoding* FXGE_CreateUnicodeEncoding(CFX_Font* pFont);
#define FXFM_ENC_TAG(a, b, c, d) \
(((FX_DWORD)(a) << 24) | ((FX_DWORD)(b) << 16) | ((FX_DWORD)(c) << 8) | \
(FX_DWORD)(d))
@@ -169,17 +157,37 @@ IFX_FontEncoding* FXGE_CreateUnicodeEncoding(CFX_Font* pFont);
#define FXFM_ENCODING_ADOBE_LATIN_1 FXFM_ENC_TAG('l', 'a', 't', '1')
#define FXFM_ENCODING_OLD_LATIN_2 FXFM_ENC_TAG('l', 'a', 't', '2')
#define FXFM_ENCODING_APPLE_ROMAN FXFM_ENC_TAG('a', 'r', 'm', 'n')
-class IFX_FontEncodingEx : public IFX_FontEncoding {
+
+class CFX_UnicodeEncoding {
+ public:
+ explicit CFX_UnicodeEncoding(CFX_Font* pFont);
+ virtual ~CFX_UnicodeEncoding();
+
+ virtual FX_DWORD GlyphFromCharCode(FX_DWORD charcode);
+
+ protected:
+ // Unowned, not nullptr.
+ CFX_Font* m_pFont;
+};
+
+class CFX_UnicodeEncodingEx : public CFX_UnicodeEncoding {
public:
- virtual FX_DWORD GlyphIndexFromName(const FX_CHAR* pStrName) = 0;
+ CFX_UnicodeEncodingEx(CFX_Font* pFont, FX_DWORD EncodingID);
+ ~CFX_UnicodeEncodingEx() override;
- virtual CFX_ByteString NameFromGlyphIndex(FX_DWORD dwGlyphIndex) = 0;
+ // CFX_UnicodeEncoding:
+ FX_DWORD GlyphFromCharCode(FX_DWORD charcode) override;
- virtual FX_DWORD CharCodeFromGlyphIndex(FX_DWORD dwGlyphIndex) = 0;
+ FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const;
+
+ private:
+ FX_DWORD m_nEncodingID;
};
-IFX_FontEncodingEx* FX_CreateFontEncodingEx(
+
+CFX_UnicodeEncodingEx* FX_CreateFontEncodingEx(
CFX_Font* pFont,
FX_DWORD nEncodingID = FXFM_ENCODING_NONE);
+
#define FXFONT_SUBST_MM 0x01
#define FXFONT_SUBST_GLYPHPATH 0x04
#define FXFONT_SUBST_CLEARTYPE 0x08
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
index 925693079f..1ff9876acc 100644
--- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
+++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
@@ -426,6 +426,7 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont,
return LoadFont(pBaseDict);
}
#endif
+
#if (_FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_)
uint32_t FX_GetLangHashCode(const FX_CHAR* pStr) {
FXSYS_assert(pStr != NULL);
@@ -791,9 +792,10 @@ CPDF_Font* CPDF_Document::AddMacFont(CTFontRef pFont,
CFRelease(languages);
return LoadFont(pBaseDict);
}
-#endif
+#endif // (_FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_)
+
static void _InsertWidthArray1(CFX_Font* pFont,
- IFX_FontEncoding* pEncoding,
+ CFX_UnicodeEncoding* pEncoding,
FX_WCHAR start,
FX_WCHAR end,
CPDF_Array* pWidthArray) {
@@ -821,6 +823,7 @@ static void _InsertWidthArray1(CFX_Font* pFont,
}
FX_Free(widths);
}
+
CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) {
if (pFont == NULL) {
return NULL;
@@ -843,7 +846,8 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) {
}
CPDF_Dictionary* pBaseDict = new CPDF_Dictionary;
pBaseDict->SetAtName("Type", "Font");
- IFX_FontEncoding* pEncoding = FXGE_CreateUnicodeEncoding(pFont);
+ nonstd::unique_ptr<CFX_UnicodeEncoding> pEncoding(
+ new CFX_UnicodeEncoding(pFont));
CPDF_Dictionary* pFontDict = pBaseDict;
if (!bCJK) {
CPDF_Array* pWidths = new CPDF_Array;
@@ -921,35 +925,35 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) {
ordering = "CNS1";
supplement = 4;
pWidthArray->AddInteger(1);
- _InsertWidthArray1(pFont, pEncoding, 0x20, 0x7e, pWidthArray);
+ _InsertWidthArray1(pFont, pEncoding.get(), 0x20, 0x7e, pWidthArray);
break;
case FXFONT_GB2312_CHARSET:
cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H";
ordering = "GB1", supplement = 2;
pWidthArray->AddInteger(7716);
- _InsertWidthArray1(pFont, pEncoding, 0x20, 0x20, pWidthArray);
+ _InsertWidthArray1(pFont, pEncoding.get(), 0x20, 0x20, pWidthArray);
pWidthArray->AddInteger(814);
- _InsertWidthArray1(pFont, pEncoding, 0x21, 0x7e, pWidthArray);
+ _InsertWidthArray1(pFont, pEncoding.get(), 0x21, 0x7e, pWidthArray);
break;
case FXFONT_HANGEUL_CHARSET:
cmap = bVert ? "KSCms-UHC-V" : "KSCms-UHC-H";
ordering = "Korea1";
supplement = 2;
pWidthArray->AddInteger(1);
- _InsertWidthArray1(pFont, pEncoding, 0x20, 0x7e, pWidthArray);
+ _InsertWidthArray1(pFont, pEncoding.get(), 0x20, 0x7e, pWidthArray);
break;
case FXFONT_SHIFTJIS_CHARSET:
cmap = bVert ? "90ms-RKSJ-V" : "90ms-RKSJ-H";
ordering = "Japan1";
supplement = 5;
pWidthArray->AddInteger(231);
- _InsertWidthArray1(pFont, pEncoding, 0x20, 0x7d, pWidthArray);
+ _InsertWidthArray1(pFont, pEncoding.get(), 0x20, 0x7d, pWidthArray);
pWidthArray->AddInteger(326);
- _InsertWidthArray1(pFont, pEncoding, 0xa0, 0xa0, pWidthArray);
+ _InsertWidthArray1(pFont, pEncoding.get(), 0xa0, 0xa0, pWidthArray);
pWidthArray->AddInteger(327);
- _InsertWidthArray1(pFont, pEncoding, 0xa1, 0xdf, pWidthArray);
+ _InsertWidthArray1(pFont, pEncoding.get(), 0xa1, 0xdf, pWidthArray);
pWidthArray->AddInteger(631);
- _InsertWidthArray1(pFont, pEncoding, 0x7e, 0x7e, pWidthArray);
+ _InsertWidthArray1(pFont, pEncoding.get(), 0x7e, 0x7e, pWidthArray);
break;
}
pBaseDict->SetAtName("Subtype", "Type0");
@@ -1003,7 +1007,6 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) {
}
}
}
- delete pEncoding;
pFontDesc->SetAtInteger("StemV", nStemV);
AddIndirectObject(pFontDesc);
pFontDict->SetAtReference("FontDescriptor", this, pFontDesc);
diff --git a/core/src/fxge/ge/fx_ge_font.cpp b/core/src/fxge/ge/fx_ge_font.cpp
index 63e9b52954..c3e887146f 100644
--- a/core/src/fxge/ge/fx_ge_font.cpp
+++ b/core/src/fxge/ge/fx_ge_font.cpp
@@ -7,10 +7,39 @@
#include "../../../include/fxge/fx_ge.h"
#include "../../../include/fxge/fx_freetype.h"
#include "text_int.h"
+
#define EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em)
extern void _FPDFAPI_GetInternalFontData(int id1,
const uint8_t*& data,
FX_DWORD& size);
+
+namespace {
+
+const FX_DWORD g_EncodingID[] = {
+ FXFM_ENCODING_MS_SYMBOL,
+ FXFM_ENCODING_UNICODE,
+ FXFM_ENCODING_MS_SJIS,
+ FXFM_ENCODING_MS_GB2312,
+ FXFM_ENCODING_MS_BIG5,
+ FXFM_ENCODING_MS_WANSUNG,
+ FXFM_ENCODING_MS_JOHAB,
+ FXFM_ENCODING_ADOBE_STANDARD,
+ FXFM_ENCODING_ADOBE_EXPERT,
+ FXFM_ENCODING_ADOBE_CUSTOM,
+ FXFM_ENCODING_ADOBE_LATIN_1,
+ FXFM_ENCODING_OLD_LATIN_2,
+ FXFM_ENCODING_APPLE_ROMAN,
+};
+
+CFX_UnicodeEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont,
+ FX_DWORD nEncodingID) {
+ if (FXFT_Select_Charmap(pFont->m_Face, nEncodingID))
+ return nullptr;
+ return new CFX_UnicodeEncodingEx(pFont, nEncodingID);
+}
+
+} // namespace
+
CFX_Font::CFX_Font() {
m_pSubstFont = NULL;
m_Face = NULL;
@@ -420,67 +449,41 @@ int CFX_Font::GetULthickness() {
FXFT_Get_Face_UnderLineThickness(m_Face));
return thickness;
}
-CFX_UnicodeEncoding::CFX_UnicodeEncoding(CFX_Font* pFont) {
- m_pFont = pFont;
+
+CFX_UnicodeEncoding::CFX_UnicodeEncoding(CFX_Font* pFont) : m_pFont(pFont) {
}
+
+CFX_UnicodeEncoding::~CFX_UnicodeEncoding() {
+}
+
FX_DWORD CFX_UnicodeEncoding::GlyphFromCharCode(FX_DWORD charcode) {
FXFT_Face face = m_pFont->GetFace();
- if (!face) {
+ if (!face)
return charcode;
- }
- if (FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE) == 0) {
+
+ if (FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE) == 0)
return FXFT_Get_Char_Index(face, charcode);
- }
+
if (m_pFont->m_pSubstFont && m_pFont->m_pSubstFont->m_Charset == 2) {
FX_DWORD index = 0;
- if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0) {
+ if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0)
index = FXFT_Get_Char_Index(face, charcode);
- }
- if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN)) {
+ if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN))
return FXFT_Get_Char_Index(face, charcode);
- }
}
return charcode;
}
-FX_DWORD CFX_UnicodeEncoding::GlyphFromCharCodeEx(FX_DWORD charcode,
- int encoding) {
- FXFT_Face face = m_pFont->GetFace();
- if (!face) {
- return charcode;
- }
- if (encoding == ENCODING_UNICODE) {
- return GlyphFromCharCode(charcode);
- }
- int nmaps = FXFT_Get_Face_CharmapCount(m_pFont->m_Face);
- int i = 0;
- while (i < nmaps) {
- int encoding = FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[i++]);
- if (encoding != FXFT_ENCODING_UNICODE) {
- FXFT_Select_Charmap(face, encoding);
- break;
- }
- }
- return FXFT_Get_Char_Index(face, charcode);
-}
-IFX_FontEncoding* FXGE_CreateUnicodeEncoding(CFX_Font* pFont) {
- CFX_UnicodeEncoding* pEncoding = NULL;
- pEncoding = new CFX_UnicodeEncoding(pFont);
- return pEncoding;
-}
-CFX_FontEncodingEX::CFX_FontEncodingEX() {
- m_pFont = NULL;
- m_nEncodingID = FXFM_ENCODING_NONE;
+
+CFX_UnicodeEncodingEx::CFX_UnicodeEncodingEx(CFX_Font* pFont,
+ FX_DWORD EncodingID)
+ : CFX_UnicodeEncoding(pFont), m_nEncodingID(EncodingID) {
}
-FX_BOOL CFX_FontEncodingEX::Init(CFX_Font* pFont, FX_DWORD EncodingID) {
- if (!pFont) {
- return FALSE;
- }
- m_pFont = pFont;
- m_nEncodingID = EncodingID;
- return TRUE;
+
+CFX_UnicodeEncodingEx::~CFX_UnicodeEncodingEx() {
}
-FX_DWORD CFX_FontEncodingEX::GlyphFromCharCode(FX_DWORD charcode) {
- FXFT_Face face = m_pFont->m_Face;
+
+FX_DWORD CFX_UnicodeEncodingEx::GlyphFromCharCode(FX_DWORD charcode) {
+ FXFT_Face face = m_pFont->GetFace();
FT_UInt nIndex = FXFT_Get_Char_Index(face, charcode);
if (nIndex > 0) {
return nIndex;
@@ -506,14 +509,8 @@ FX_DWORD CFX_FontEncodingEX::GlyphFromCharCode(FX_DWORD charcode) {
FXFT_Select_Charmap(face, m_nEncodingID);
return 0;
}
-CFX_WideString CFX_FontEncodingEX::UnicodeFromCharCode(
- FX_DWORD charcode) const {
- if (m_nEncodingID == FXFM_ENCODING_UNICODE) {
- return CFX_WideString((FX_WCHAR)charcode);
- }
- return CFX_WideString((FX_WCHAR)0);
-}
-FX_DWORD CFX_FontEncodingEX::CharCodeFromUnicode(FX_WCHAR Unicode) const {
+
+FX_DWORD CFX_UnicodeEncodingEx::CharCodeFromUnicode(FX_WCHAR Unicode) const {
if (m_nEncodingID == FXFM_ENCODING_UNICODE ||
m_nEncodingID == FXFM_ENCODING_MS_SYMBOL) {
return Unicode;
@@ -530,94 +527,18 @@ FX_DWORD CFX_FontEncodingEX::CharCodeFromUnicode(FX_WCHAR Unicode) const {
}
return -1;
}
-FX_BOOL CFX_FontEncodingEX::IsUnicodeCompatible() const {
- return m_nEncodingID == FXFM_ENCODING_UNICODE;
-}
-FX_DWORD CFX_FontEncodingEX::GlyphIndexFromName(const FX_CHAR* pStrName) {
- FXFT_Face face = m_pFont->m_Face;
- return FT_Get_Name_Index(face, (FT_String*)pStrName);
-}
-CFX_ByteString CFX_FontEncodingEX::NameFromGlyphIndex(FX_DWORD dwGlyphIndex) {
- FXFT_Face face = m_pFont->m_Face;
- CFX_ByteString glyphName(" ");
- if (FT_HAS_GLYPH_NAMES(((FT_Face)face))) {
- if (FT_Get_Glyph_Name((FT_Face)face, dwGlyphIndex,
- (FT_Pointer)(const FX_CHAR*)glyphName, 16)) {
- glyphName.Empty();
- return glyphName;
- }
- return glyphName;
- } else {
- return glyphName;
- }
-}
-FX_DWORD CFX_FontEncodingEX::CharCodeFromGlyphIndex(FX_DWORD dwGlyphIndex) {
- FXFT_Face face = m_pFont->GetFace();
- FX_DWORD charcode;
- FT_UInt gid;
- charcode = FT_Get_First_Char((FT_Face)face, &gid);
- while (gid != 0) {
- if (dwGlyphIndex == gid) {
- return charcode;
- }
- charcode = FT_Get_Next_Char((FT_Face)face, charcode, &gid);
- }
- int nmaps = FXFT_Get_Face_CharmapCount(face);
- int m = 0;
- while (m < nmaps) {
- int nEncodingID =
- FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[m++]);
- if (m_nEncodingID == nEncodingID) {
- continue;
- }
- int error = FXFT_Select_Charmap(face, nEncodingID);
- if (error) {
- continue;
- }
- charcode = FT_Get_First_Char((FT_Face)face, &gid);
- while (gid != 0) {
- if (dwGlyphIndex == gid) {
- m_nEncodingID = nEncodingID;
- return charcode;
- }
- charcode = FT_Get_Next_Char((FT_Face)face, charcode, &gid);
- }
- }
- return (FX_DWORD)-1;
-}
-static const FX_DWORD gs_EncodingID[] = {
- FXFM_ENCODING_MS_SYMBOL, FXFM_ENCODING_UNICODE,
- FXFM_ENCODING_MS_SJIS, FXFM_ENCODING_MS_GB2312,
- FXFM_ENCODING_MS_BIG5, FXFM_ENCODING_MS_WANSUNG,
- FXFM_ENCODING_MS_JOHAB, FXFM_ENCODING_ADOBE_STANDARD,
- FXFM_ENCODING_ADOBE_EXPERT, FXFM_ENCODING_ADOBE_CUSTOM,
- FXFM_ENCODING_ADOBE_LATIN_1, FXFM_ENCODING_OLD_LATIN_2,
- FXFM_ENCODING_APPLE_ROMAN};
-static IFX_FontEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont,
- FX_DWORD nEncodingID) {
- int error = FXFT_Select_Charmap(pFont->m_Face, nEncodingID);
- if (error) {
- return NULL;
- }
- CFX_FontEncodingEX* pFontEncoding = new CFX_FontEncodingEX;
- if (pFontEncoding && !pFontEncoding->Init(pFont, nEncodingID)) {
- delete pFontEncoding;
- pFontEncoding = NULL;
- }
- return pFontEncoding;
-}
-IFX_FontEncodingEx* FX_CreateFontEncodingEx(CFX_Font* pFont,
- FX_DWORD nEncodingID) {
- if (!pFont || !pFont->m_Face) {
- return NULL;
- }
- if (nEncodingID != FXFM_ENCODING_NONE) {
+
+CFX_UnicodeEncodingEx* FX_CreateFontEncodingEx(CFX_Font* pFont,
+ FX_DWORD nEncodingID) {
+ if (!pFont || !pFont->m_Face)
+ return nullptr;
+
+ if (nEncodingID != FXFM_ENCODING_NONE)
return _FXFM_CreateFontEncoding(pFont, nEncodingID);
- }
- static int s_count = sizeof(gs_EncodingID) / sizeof(FX_DWORD);
- for (int i = 0; i < s_count; i++) {
- IFX_FontEncodingEx* pFontEncoding =
- _FXFM_CreateFontEncoding(pFont, gs_EncodingID[i]);
+
+ for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) {
+ CFX_UnicodeEncodingEx* pFontEncoding =
+ _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]);
if (pFontEncoding) {
return pFontEncoding;
}
diff --git a/core/src/fxge/ge/text_int.h b/core/src/fxge/ge/text_int.h
index 9279969e0a..b0193c4f2e 100644
--- a/core/src/fxge/ge/text_int.h
+++ b/core/src/fxge/ge/text_int.h
@@ -41,23 +41,7 @@ class CTTFontDesc {
uint8_t* m_pFontData;
int m_RefCount;
};
-class CFX_UnicodeEncoding : public IFX_FontEncoding {
- public:
- CFX_UnicodeEncoding(CFX_Font* pFont);
- virtual FX_DWORD GlyphFromCharCodeEx(FX_DWORD charcode,
- int encoding = ENCODING_UNICODE);
- private:
- CFX_Font* m_pFont;
- virtual FX_DWORD GlyphFromCharCode(FX_DWORD charcode);
- virtual CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const {
- return CFX_WideString((FX_WCHAR)charcode);
- }
- virtual FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const {
- return Unicode;
- }
- virtual FX_BOOL IsUnicodeCompatible() const { return TRUE; }
-};
#define CHARSET_FLAG_ANSI 1
#define CHARSET_FLAG_SYMBOL 2
#define CHARSET_FLAG_SHIFTJIS 4
@@ -105,25 +89,5 @@ class CFontFileFaceInfo {
int m_PitchFamily;
CFX_ByteString m_FontTables;
};
-class CFX_FontEncodingEX : public IFX_FontEncodingEx {
- public:
- CFX_FontEncodingEX();
- FX_BOOL Init(CFX_Font* pFont, FX_DWORD EncodingID);
- virtual FX_DWORD GlyphIndexFromName(const FX_CHAR* pStrName);
- virtual CFX_ByteString NameFromGlyphIndex(FX_DWORD dwGlyphIndex);
- virtual FX_DWORD CharCodeFromGlyphIndex(FX_DWORD dwGlyphIndex);
- virtual FX_DWORD GlyphFromCharCode(FX_DWORD charcode);
- virtual CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const;
- virtual FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const;
- virtual FX_BOOL IsUnicodeCompatible() const;
- virtual FX_DWORD GlyphFromCharCodeEx(FX_DWORD charcode,
- int encoding = ENCODING_UNICODE) {
- return GlyphFromCharCode(charcode);
- }
-
- private:
- CFX_Font* m_pFont;
- FX_DWORD m_nEncodingID;
-};
#endif // CORE_SRC_FXGE_GE_TEXT_INT_H_