void CFGAS_FontMgrImp::Release() {
  for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) {
    delete m_InstalledFonts[i];
  }
  FX_POSITION pos = m_Hash2CandidateList.GetStartPosition();
  while (pos) {
    uint32_t dwHash;
    CFX_FontDescriptorInfos* pDescs;
    m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs);
    delete pDescs;
  }
  pos = m_Hash2Fonts.GetStartPosition();
  while (pos) {
    uint32_t dwHash;
    CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts;
    m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts);
    delete pFonts;
  }
  m_Hash2Fonts.RemoveAll();
  pos = m_IFXFont2FileRead.GetStartPosition();
  while (pos) {
    CFGAS_GEFont* pFont;
    IFX_FileRead* pFileRead;
    m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead);
    pFileRead->Release();
  }
  delete this;
}
FX_BOOL CFGAS_FontMgrImp::EnumFontsFromFontMapper() {
  CFX_FontMapper* pFontMapper =
      CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper();
  if (!pFontMapper)
    return FALSE;

  IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo();
  if (!pSystemFontInfo)
    return FALSE;

  pSystemFontInfo->EnumFontList(pFontMapper);
  for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) {
    IFX_FileRead* pFontStream =
        CreateFontStream(pFontMapper, pSystemFontInfo, i);
    if (!pFontStream)
      continue;

    CFX_WideString wsFaceName =
        CFX_WideString::FromLocal(pFontMapper->GetFaceName(i).c_str());
    RegisterFaces(pFontStream, &wsFaceName);
    pFontStream->Release();
  }
  if (m_InstalledFonts.GetSize() == 0)
    return FALSE;

  return TRUE;
}
void CFGAS_FontMgrImp::RemoveFont(CFGAS_GEFont* pEFont) {
  if (!pEFont) {
    return;
  }
  IFX_FileRead* pFileRead;
  if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) {
    pFileRead->Release();
    m_IFXFont2FileRead.RemoveKey(pEFont);
  }
  FX_POSITION pos;
  pos = m_Hash2Fonts.GetStartPosition();
  while (pos) {
    uint32_t dwHash;
    CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts;
    m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts);
    if (pFonts) {
      for (int32_t i = 0; i < pFonts->GetSize(); i++) {
        if (pFonts->GetAt(i) == pEFont) {
          pFonts->SetAt(i, nullptr);
        }
      }
    } else {
      m_Hash2Fonts.RemoveKey(dwHash);
    }
  }
}
示例#4
0
 unsigned long _FTStreamRead(FXFT_Stream stream, unsigned long offset,
                             unsigned char* buffer, unsigned long count)
 {
     if (count == 0) {
         return 0;
     }
     IFX_FileRead* pFile = (IFX_FileRead*)stream->descriptor.pointer;
     int res = pFile->ReadBlock(buffer, offset, count);
     if (res) {
         return count;
     }
     return 0;
 }
static unsigned long FPF_SkiaStream_Read(FXFT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count)
{
    IFX_FileRead *pFileRead = (IFX_FileRead*)stream->descriptor.pointer;
    if (!pFileRead) {
        return 0;
    }
    if (count > 0) {
        if (pFileRead->ReadBlock(buffer, (FX_FILESIZE)offset, (size_t)count) != count) {
            return 0;
        }
    }
    return count;
}
FX_BOOL CFGAS_FontMgrImp::VerifyUnicode(CFX_FontDescriptor* pDesc,
                                        FX_WCHAR wcUnicode) {
  IFX_FileRead* pFileRead = CreateFontStream(pDesc->m_wsFaceName.UTF8Encode());
  if (!pFileRead)
    return FALSE;
  FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex);
  FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE);
  FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode);
  pFileRead->Release();
  if (!pFace)
    return FALSE;
  if (FXFT_Get_Face_External_Stream(pFace))
    FXFT_Clear_Face_External_Stream(pFace);
  FXFT_Done_Face(pFace);
  return !retCharmap && retIndex;
}
void CFGAS_FontMgrImp::ClearFontCache() {
  FX_POSITION pos = m_Hash2CandidateList.GetStartPosition();
  while (pos) {
    uint32_t dwHash;
    CFX_FontDescriptorInfos* pDescs;
    m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs);
    delete pDescs;
  }
  pos = m_IFXFont2FileRead.GetStartPosition();
  while (pos) {
    CFGAS_GEFont* pFont;
    IFX_FileRead* pFileRead;
    m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead);
    pFileRead->Release();
  }
}
示例#8
0
IFX_LocaleMgr* FX_LocaleMgr_Create(const FX_WCHAR* pszLocalPath,
                                   FX_WORD wDefaultLCID) {
  void* pPathHandle = FX_OpenFolder(pszLocalPath);
  if (!pPathHandle) {
    return NULL;
  }
  CFX_LocaleMgr* pLocaleMgr = new CFX_LocaleMgr(wDefaultLCID);
  CFX_WideString wsFileName;
  FX_BOOL bFolder = FALSE;
  while (FX_GetNextFile(pPathHandle, wsFileName, bFolder)) {
    if (!bFolder) {
      if (wsFileName.GetLength() < 4) {
        continue;
      }
      CFX_WideString wsExt = wsFileName.Right(4);
      wsExt.MakeLower();
      if (wsExt != L".xml") {
        continue;
      }
      CFX_WideString wsFullPath(pszLocalPath);
      wsFullPath += L"\\" + wsFileName;
      IFX_FileRead* pRead = FX_CreateFileRead(wsFullPath);
      if (!pRead) {
        continue;
      }
      CXML_Element* pXmlLocale = CXML_Element::Parse(pRead);
      pRead->Release();
      CFX_ByteString bssp = pXmlLocale->GetNamespace();
      if (bssp == "http://www.foxitsoftware.com/localization") {
        CFX_WideString wsLCID = pXmlLocale->GetAttrValue("", "lcid");
        wchar_t* pEnd = NULL;
        FX_DWORD dwLCID = wcstol(wsLCID, &pEnd, 16);
        if (pLocaleMgr->m_lcid2xml.GetValueAt((void*)(uintptr_t)dwLCID)) {
          delete pXmlLocale;
        } else {
          pLocaleMgr->m_lcid2xml.SetAt((void*)(uintptr_t)dwLCID, pXmlLocale);
        }
      } else {
        delete pXmlLocale;
      }
    }
  }
  FX_CloseFolder(pPathHandle);
  return pLocaleMgr;
}
FX_BOOL CFGAS_FontMgrImp::EnumFontsFromFiles() {
  CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary();
  FX_POSITION pos = m_pFontSource->GetStartPosition();
  IFX_FileAccess* pFontSource = nullptr;
  IFX_FileRead* pFontStream = nullptr;
  while (pos) {
    pFontSource = m_pFontSource->GetNext(pos);
    pFontStream = pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly);
    if (!pFontStream) {
      pFontSource->Release();
      continue;
    }
    RegisterFaces(pFontStream, nullptr);
    pFontStream->Release();
    pFontSource->Release();
  }
  if (m_InstalledFonts.GetSize() == 0)
    return FALSE;
  return TRUE;
}
CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(const CFX_WideString& wsFaceName,
                                         int32_t iFaceIndex,
                                         int32_t* pFaceCount) {
  CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
  CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper();
  if (!pFontMapper)
    return nullptr;

  IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo();
  if (!pSystemFontInfo)
    return nullptr;

  IFX_FileRead* pFontStream = CreateFontStream(wsFaceName.UTF8Encode());
  if (!pFontStream)
    return nullptr;

  if (!LoadFace(pFontStream, 0)) {
    pFontStream->Release();
    return nullptr;
  }

  CFX_Font* pInternalFont = new CFX_Font();
  if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) {
    pFontStream->Release();
    return nullptr;
  }

  CFGAS_GEFont* pFont = CFGAS_GEFont::LoadFont(pInternalFont, this);
  if (!pFont) {
    pFontStream->Release();
    return nullptr;
  }

  m_IFXFont2FileRead.SetAt(pFont, pFontStream);
  if (pFaceCount)
    *pFaceCount = pFont->GetDevFont()->GetFace()->num_faces;

  return pFont;
}
FX_BOOL CPDF_Stream::Identical(CPDF_Stream* pOther) const {
  if (!m_pDict)
    return !pOther->m_pDict;

  if (!m_pDict->Identical(pOther->m_pDict))
    return FALSE;

  if (m_dwSize != pOther->m_dwSize)
    return FALSE;

  if (!IsMemoryBased() && !pOther->IsMemoryBased()) {
    if (m_pFile == pOther->m_pFile && !m_pFile)
      return TRUE;

    if (!m_pFile || !pOther->m_pFile)
      return FALSE;

    uint8_t srcBuf[kBlockSize];
    uint8_t destBuf[kBlockSize];
    FX_DWORD size = m_dwSize;
    if (m_pFile == pOther->m_pFile)
      return TRUE;

    FX_DWORD offset = 0;
    while (size > 0) {
      FX_DWORD actualSize = std::min(size, kBlockSize);
      m_pFile->ReadBlock(srcBuf, offset, actualSize);
      pOther->m_pFile->ReadBlock(destBuf, offset, actualSize);
      if (FXSYS_memcmp(srcBuf, destBuf, actualSize) != 0)
        return FALSE;

      size -= actualSize;
      offset += actualSize;
    }
    return TRUE;
  }

  if (!IsMemoryBased() || !pOther->IsMemoryBased()) {
    IFX_FileRead* pFile = nullptr;
    uint8_t* pBuf = nullptr;
    if (!pOther->IsMemoryBased()) {
      pFile = pOther->m_pFile;
      pBuf = m_pDataBuf;
    } else if (!IsMemoryBased()) {
      pFile = m_pFile;
      pBuf = pOther->m_pDataBuf;
    }
    if (!pBuf)
      return FALSE;

    uint8_t srcBuf[kBlockSize];
    FX_DWORD size = m_dwSize;
    FX_DWORD offset = 0;
    while (size > 0) {
      FX_DWORD actualSize = std::min(size, kBlockSize);
      pFile->ReadBlock(srcBuf, offset, actualSize);
      if (FXSYS_memcmp(srcBuf, pBuf, actualSize) != 0)
        return FALSE;

      pBuf += actualSize;
      size -= actualSize;
      offset += actualSize;
    }
    return TRUE;
  }
  return FXSYS_memcmp(m_pDataBuf, pOther->m_pDataBuf, m_dwSize) == 0;
}
示例#12
0
FX_BOOL CPDF_Stream::Identical(CPDF_Stream* pOther) const
{
    if (!m_pDict)
        return pOther->m_pDict ? FALSE : TRUE;

    if (!m_pDict->Identical(pOther->m_pDict)) {
        return FALSE;
    }
    if (m_dwSize != pOther->m_dwSize) {
        return FALSE;
    }
    if (m_GenNum != (FX_DWORD) - 1 && pOther->m_GenNum != (FX_DWORD) - 1) {
        if (m_pFile == pOther->m_pFile && m_pFile == NULL) {
            return TRUE;
        }
        if (!m_pFile || !pOther->m_pFile) {
            return FALSE;
        }
        uint8_t srcBuf[1024];
        uint8_t destBuf[1024];
        FX_DWORD size = m_dwSize;
        FX_DWORD srcOffset = m_FileOffset;
        FX_DWORD destOffset = pOther->m_FileOffset;
        if (m_pFile == pOther->m_pFile && srcOffset == destOffset) {
            return TRUE;
        }
        while (size > 0) {
            FX_DWORD actualSize = size > 1024 ? 1024 : size;
            m_pFile->ReadBlock(srcBuf, srcOffset, actualSize);
            pOther->m_pFile->ReadBlock(destBuf, destOffset, actualSize);
            if (FXSYS_memcmp(srcBuf, destBuf, actualSize) != 0) {
                return FALSE;
            }
            size -= actualSize;
            srcOffset += actualSize;
            destOffset += actualSize;
        }
        return TRUE;
    }
    if (m_GenNum != (FX_DWORD) - 1 || pOther->m_GenNum != (FX_DWORD) - 1) {
        IFX_FileRead* pFile = NULL;
        uint8_t* pBuf = NULL;
        FX_DWORD offset = 0;
        if (pOther->m_GenNum != (FX_DWORD) - 1) {
            pFile = pOther->m_pFile;
            pBuf = m_pDataBuf;
            offset = pOther->m_FileOffset;
        } else if (m_GenNum != (FX_DWORD) - 1) {
            pFile = m_pFile;
            pBuf = pOther->m_pDataBuf;
            offset = m_FileOffset;
        }
        if (NULL == pBuf) {
            return FALSE;
        }
        uint8_t srcBuf[1024];
        FX_DWORD size = m_dwSize;
        while (size > 0) {
            FX_DWORD actualSize = std::min(size, 1024U);
            pFile->ReadBlock(srcBuf, offset, actualSize);
            if (FXSYS_memcmp(srcBuf, pBuf, actualSize) != 0) {
                return FALSE;
            }
            pBuf += actualSize;
            size -= actualSize;
            offset += actualSize;
        }
        return TRUE;
    }
    return FXSYS_memcmp(m_pDataBuf, pOther->m_pDataBuf, m_dwSize) == 0;
}