summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/include/fxge/fx_font.h14
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp27
-rw-r--r--core/src/fxge/ge/fx_ge_font.cpp45
-rw-r--r--core/src/fxge/ge/text_int.h16
4 files changed, 34 insertions, 68 deletions
diff --git a/core/include/fxge/fx_font.h b/core/include/fxge/fx_font.h
index 8e0f5a1615..d9b557a87b 100644
--- a/core/include/fxge/fx_font.h
+++ b/core/include/fxge/fx_font.h
@@ -134,18 +134,18 @@ class CFX_Font {
#define ENCODING_INTERNAL 0
#define ENCODING_UNICODE 1
-class IFX_FontEncoding {
+class CFX_UnicodeEncoding {
public:
- virtual ~IFX_FontEncoding() {}
+ explicit CFX_UnicodeEncoding(CFX_Font* pFont);
+ ~CFX_UnicodeEncoding();
- virtual FX_DWORD GlyphFromCharCode(FX_DWORD charcode) = 0;
+ FX_DWORD GlyphFromCharCode(FX_DWORD charcode);
- virtual CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const = 0;
-
- virtual FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const = 0;
+ private:
+ // Unowned, not nullptr.
+ CFX_Font* m_pFont;
};
-IFX_FontEncoding* FXGE_CreateUnicodeEncoding(CFX_Font* pFont);
#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 fa21ac1058..ed055459d4 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 8be177ed14..d72adc36bf 100644
--- a/core/src/fxge/ge/fx_ge_font.cpp
+++ b/core/src/fxge/ge/fx_ge_font.cpp
@@ -379,48 +379,27 @@ 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) {
- return new CFX_UnicodeEncoding(pFont);
-}
diff --git a/core/src/fxge/ge/text_int.h b/core/src/fxge/ge/text_int.h
index e9f81b3ca7..61f47eac9c 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