Esempio n. 1
0
CFGAS_GEFont* CFGAS_FontMgr::LoadFont(CFGAS_GEFont* pSrcFont,
                                      uint32_t dwFontStyles,
                                      uint16_t wCodePage) {
  ASSERT(pSrcFont);
  if (pSrcFont->GetFontStyles() == dwFontStyles)
    return pSrcFont->Retain();
  void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles,
                     (void*)(uintptr_t)wCodePage};
  uint32_t dwHash = FX_HashCode_GetA(
      CFX_ByteStringC((uint8_t*)buffer, sizeof(buffer)), false);
  CFGAS_GEFont* pFont = nullptr;
  if (m_DeriveFonts.GetCount() > 0) {
    m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont);
    if (pFont)
      return pFont->Retain();
  }
  pFont = pSrcFont->Derive(dwFontStyles, wCodePage);
  if (!pFont)
    return nullptr;

  m_DeriveFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
  int32_t index = m_Fonts.Find(pFont);
  if (index < 0) {
    m_Fonts.Add(pFont);
    pFont->Retain();
  }
  return pFont;
}
CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(const uint8_t* pBuffer,
                                            int32_t iLength) {
  ASSERT(pBuffer && iLength > 0);
  CFGAS_GEFont* pFont = nullptr;
  if (m_BufferFonts.Lookup((void*)pBuffer, (void*&)pFont)) {
    if (pFont) {
      return pFont->Retain();
    }
  }
  pFont = CFGAS_GEFont::LoadFont(pBuffer, iLength, this);
  if (pFont) {
    m_Fonts.Add(pFont);
    m_BufferFonts.SetAt((void*)pBuffer, pFont);
    return pFont->Retain();
  }
  return nullptr;
}