• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include <memory>
8 
9 #include "core/fxge/cfx_fontmapper.h"
10 #include "core/fxge/ifx_systemfontinfo.h"
11 
GetStringFromTable(const uint8_t * string_ptr,uint32_t string_ptr_length,uint16_t offset,uint16_t length)12 static CFX_ByteString GetStringFromTable(const uint8_t* string_ptr,
13                                          uint32_t string_ptr_length,
14                                          uint16_t offset,
15                                          uint16_t length) {
16   if (string_ptr_length < static_cast<uint32_t>(offset + length)) {
17     return CFX_ByteString();
18   }
19   return CFX_ByteString(string_ptr + offset, length);
20 }
21 
GetNameFromTT(const uint8_t * name_table,uint32_t name_table_size,uint32_t name_id)22 CFX_ByteString GetNameFromTT(const uint8_t* name_table,
23                              uint32_t name_table_size,
24                              uint32_t name_id) {
25   if (!name_table || name_table_size < 6) {
26     return CFX_ByteString();
27   }
28   uint32_t name_count = GET_TT_SHORT(name_table + 2);
29   uint32_t string_offset = GET_TT_SHORT(name_table + 4);
30   // We will ignore the possibility of overlap of structures and
31   // string table as if it's all corrupt there's not a lot we can do.
32   if (name_table_size < string_offset) {
33     return CFX_ByteString();
34   }
35 
36   const uint8_t* string_ptr = name_table + string_offset;
37   uint32_t string_ptr_size = name_table_size - string_offset;
38   name_table += 6;
39   name_table_size -= 6;
40   if (name_table_size < name_count * 12) {
41     return CFX_ByteString();
42   }
43 
44   for (uint32_t i = 0; i < name_count; i++, name_table += 12) {
45     if (GET_TT_SHORT(name_table + 6) == name_id &&
46         GET_TT_SHORT(name_table) == 1 && GET_TT_SHORT(name_table + 2) == 0) {
47       return GetStringFromTable(string_ptr, string_ptr_size,
48                                 GET_TT_SHORT(name_table + 10),
49                                 GET_TT_SHORT(name_table + 8));
50     }
51   }
52   return CFX_ByteString();
53 }
54 #ifdef PDF_ENABLE_XFA
MapFontByUnicode(uint32_t dwUnicode,int weight,bool bItalic,int pitch_family)55 void* IFX_SystemFontInfo::MapFontByUnicode(uint32_t dwUnicode,
56                                            int weight,
57                                            bool bItalic,
58                                            int pitch_family) {
59   return nullptr;
60 }
61 #endif  // PDF_ENABLE_XFA
62 
GetFaceIndex(void * hFont)63 int IFX_SystemFontInfo::GetFaceIndex(void* hFont) {
64   return 0;
65 }
66 
67 extern "C" {
68 unsigned long _FTStreamRead(FXFT_Stream stream,
69                             unsigned long offset,
70                             unsigned char* buffer,
71                             unsigned long count);
72 void _FTStreamClose(FXFT_Stream stream);
73 };
74 
75 #if _FX_OS_ == _FX_ANDROID_
CreateDefault(const char ** pUnused)76 std::unique_ptr<IFX_SystemFontInfo> IFX_SystemFontInfo::CreateDefault(
77     const char** pUnused) {
78   return nullptr;
79 }
80 #endif
81 
CFX_FontFaceInfo(CFX_ByteString filePath,CFX_ByteString faceName,CFX_ByteString fontTables,uint32_t fontOffset,uint32_t fileSize)82 CFX_FontFaceInfo::CFX_FontFaceInfo(CFX_ByteString filePath,
83                                    CFX_ByteString faceName,
84                                    CFX_ByteString fontTables,
85                                    uint32_t fontOffset,
86                                    uint32_t fileSize)
87     : m_FilePath(filePath),
88       m_FaceName(faceName),
89       m_FontTables(fontTables),
90       m_FontOffset(fontOffset),
91       m_FileSize(fileSize),
92       m_Styles(0),
93       m_Charsets(0) {}
94