Example #1
0
int32_t CFX_GEFont::GetGlyphIndex(FX_WCHAR wUnicode,
                                  FX_BOOL bRecursive,
                                  IFX_Font** ppFont,
                                  FX_BOOL bCharCode) {
  FXSYS_assert(m_pFontEncoding != NULL);
  int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode);
  if (iGlyphIndex > 0) {
    if (ppFont != NULL) {
      *ppFont = (IFX_Font*)this;
    }
    return iGlyphIndex;
  }
  FGAS_LPCFONTUSB pFontUSB = FGAS_GetUnicodeBitField(wUnicode);
  if (pFontUSB == NULL) {
    return 0xFFFF;
  }
  FX_WORD wBitField = pFontUSB->wBitField;
  if (wBitField >= 128) {
    return 0xFFFF;
  }
  IFX_Font* pFont = NULL;
  m_FontMapper.Lookup((void*)(uintptr_t)wUnicode, (void*&)pFont);
  if (pFont != NULL && pFont != (IFX_Font*)this) {
    iGlyphIndex =
        ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode);
    if (iGlyphIndex != 0xFFFF) {
      int32_t i = m_SubstFonts.Find(pFont);
      if (i > -1) {
        iGlyphIndex |= ((i + 1) << 24);
        if (ppFont != NULL) {
          *ppFont = pFont;
        }
        return iGlyphIndex;
      }
    }
  }
  if (m_pFontMgr != NULL && bRecursive) {
    CFX_WideString wsFamily;
    GetFamilyName(wsFamily);
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
    IFX_Font* pFont = m_pFontMgr->GetDefFontByUnicode(
        wUnicode, GetFontStyles(), (const FX_WCHAR*)wsFamily);
#else
    IFX_Font* pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(),
                                                   (const FX_WCHAR*)wsFamily);
    if (NULL == pFont) {
      pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), NULL);
    }
#endif
    if (pFont != NULL) {
      if (pFont == (IFX_Font*)this) {
        pFont->Release();
        return 0xFFFF;
      }
      m_FontMapper.SetAt((void*)(uintptr_t)wUnicode, (void*)pFont);
      int32_t i = m_SubstFonts.GetSize();
      m_SubstFonts.Add(pFont);
      iGlyphIndex =
          ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode);
      if (iGlyphIndex != 0xFFFF) {
        iGlyphIndex |= ((i + 1) << 24);
        if (ppFont != NULL) {
          *ppFont = pFont;
        }
        return iGlyphIndex;
      }
    }
  }
  return 0xFFFF;
}
int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode,
                                    FX_BOOL bRecursive,
                                    CFGAS_GEFont** ppFont,
                                    FX_BOOL bCharCode) {
  ASSERT(m_pFontEncoding);
  int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode);
  if (iGlyphIndex > 0) {
    if (ppFont) {
      *ppFont = this;
    }
    return iGlyphIndex;
  }
  const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode);
  if (!pFontUSB) {
    return 0xFFFF;
  }
  uint16_t wBitField = pFontUSB->wBitField;
  if (wBitField >= 128) {
    return 0xFFFF;
  }
  auto it = m_FontMapper.find(wUnicode);
  CFGAS_GEFont* pFont = it != m_FontMapper.end() ? it->second : nullptr;
  if (pFont && pFont != this) {
    iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, nullptr, bCharCode);
    if (iGlyphIndex != 0xFFFF) {
      int32_t i = m_SubstFonts.Find(pFont);
      if (i > -1) {
        iGlyphIndex |= ((i + 1) << 24);
        if (ppFont)
          *ppFont = pFont;
        return iGlyphIndex;
      }
    }
  }
  if (m_pFontMgr && bRecursive) {
    CFX_WideString wsFamily;
    GetFamilyName(wsFamily);
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
    CFGAS_GEFont* pFont = m_pFontMgr->GetDefFontByUnicode(
        wUnicode, GetFontStyles(), wsFamily.c_str());
#else
    CFGAS_GEFont* pFont = m_pFontMgr->GetFontByUnicode(
        wUnicode, GetFontStyles(), wsFamily.c_str());
    if (!pFont)
      pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), nullptr);
#endif
    if (pFont) {
      if (pFont == this) {
        pFont->Release();
        return 0xFFFF;
      }
      m_FontMapper[wUnicode] = pFont;
      int32_t i = m_SubstFonts.GetSize();
      m_SubstFonts.Add(pFont);
      iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, nullptr, bCharCode);
      if (iGlyphIndex != 0xFFFF) {
        iGlyphIndex |= ((i + 1) << 24);
        if (ppFont)
          *ppFont = pFont;
        return iGlyphIndex;
      }
    }
  }
  return 0xFFFF;
}
Example #3
0
IFX_Font* CFX_GEFont::Derive(FX_DWORD dwFontStyles, FX_WORD wCodePage) {
  if (GetFontStyles() == dwFontStyles) {
    return Retain();
  }
  return new CFX_GEFont(*this, dwFontStyles);
}
CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) {
  if (GetFontStyles() == dwFontStyles)
    return Retain();
  return new CFGAS_GEFont(*this, dwFontStyles);
}