Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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);
    }
  }
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
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();
  }
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
0
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;
}