Home | History | Annotate | Download | only in fxge
      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 
     12 static 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 ByteString();
     18   }
     19   return ByteString(string_ptr + offset, length);
     20 }
     21 
     22 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 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 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 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 ByteString();
     53 }
     54 #ifdef PDF_ENABLE_XFA
     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 
     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_OS_ANDROID_
     76 std::unique_ptr<IFX_SystemFontInfo> IFX_SystemFontInfo::CreateDefault(
     77     const char** pUnused) {
     78   return nullptr;
     79 }
     80 #endif
     81