diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-07-10 15:14:26 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-07-10 19:28:59 +0000 |
commit | 92e2276a8be492fd2be8e44a5d62e8a5879644d8 (patch) | |
tree | 0945f5edda0fbfb461ca1cae89a20adb583242e4 /core/fxge/cfx_unicodeencodingex.cpp | |
parent | 1437643bfaca635d52f4cb9ec41e3075cf893f79 (diff) | |
download | pdfium-92e2276a8be492fd2be8e44a5d62e8a5879644d8.tar.xz |
Move core/fxge/ge to core/fxge.
This brings the cpp and h files together and removes the
redundant ge/ path.
Change-Id: I36594b8ae719d362768ba4c2e4ce173e287363eb
Reviewed-on: https://pdfium-review.googlesource.com/7452
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxge/cfx_unicodeencodingex.cpp')
-rw-r--r-- | core/fxge/cfx_unicodeencodingex.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/core/fxge/cfx_unicodeencodingex.cpp b/core/fxge/cfx_unicodeencodingex.cpp new file mode 100644 index 0000000000..3f28d4295e --- /dev/null +++ b/core/fxge/cfx_unicodeencodingex.cpp @@ -0,0 +1,103 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fxge/cfx_unicodeencodingex.h" + +#include <memory> + +#include "core/fpdfapi/font/cpdf_font.h" +#include "core/fxge/fx_font.h" +#include "core/fxge/fx_freetype.h" +#include "third_party/base/ptr_util.h" + +namespace { + +const uint32_t 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, +}; + +std::unique_ptr<CFX_UnicodeEncodingEx> FXFM_CreateFontEncoding( + CFX_Font* pFont, + uint32_t nEncodingID) { + if (FXFT_Select_Charmap(pFont->GetFace(), nEncodingID)) + return nullptr; + return pdfium::MakeUnique<CFX_UnicodeEncodingEx>(pFont, nEncodingID); +} + +} // namespace + +CFX_UnicodeEncodingEx::CFX_UnicodeEncodingEx(CFX_Font* pFont, + uint32_t EncodingID) + : CFX_UnicodeEncoding(pFont), m_nEncodingID(EncodingID) {} + +CFX_UnicodeEncodingEx::~CFX_UnicodeEncodingEx() {} + +uint32_t CFX_UnicodeEncodingEx::GlyphFromCharCode(uint32_t charcode) { + FXFT_Face face = m_pFont->GetFace(); + FT_UInt nIndex = FXFT_Get_Char_Index(face, charcode); + if (nIndex > 0) + return nIndex; + int nmaps = FXFT_Get_Face_CharmapCount(face); + int m = 0; + while (m < nmaps) { + uint32_t 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; + nIndex = FXFT_Get_Char_Index(face, charcode); + if (nIndex > 0) { + m_nEncodingID = nEncodingID; + return nIndex; + } + } + FXFT_Select_Charmap(face, m_nEncodingID); + return 0; +} + +uint32_t CFX_UnicodeEncodingEx::CharCodeFromUnicode(wchar_t Unicode) const { + if (m_nEncodingID == FXFM_ENCODING_UNICODE || + m_nEncodingID == FXFM_ENCODING_MS_SYMBOL) { + return Unicode; + } + FXFT_Face face = m_pFont->GetFace(); + int nmaps = FXFT_Get_Face_CharmapCount(face); + for (int i = 0; i < nmaps; i++) { + int nEncodingID = + FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[i]); + if (nEncodingID == FXFM_ENCODING_UNICODE || + nEncodingID == FXFM_ENCODING_MS_SYMBOL) { + return Unicode; + } + } + return CPDF_Font::kInvalidCharCode; +} + +std::unique_ptr<CFX_UnicodeEncodingEx> FX_CreateFontEncodingEx( + CFX_Font* pFont, + uint32_t nEncodingID) { + if (!pFont || !pFont->GetFace()) + return nullptr; + + if (nEncodingID != FXFM_ENCODING_NONE) + return FXFM_CreateFontEncoding(pFont, nEncodingID); + + for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) { + std::unique_ptr<CFX_UnicodeEncodingEx> pFontEncoding = + FXFM_CreateFontEncoding(pFont, g_EncodingID[i]); + if (pFontEncoding) + return pFontEncoding; + } + return nullptr; +} |