IFPF_Font* CFPF_SkiaFontMgr::CreateFont(FX_BSTR bsFamilyname, FX_BYTE uCharset, FX_DWORD dwStyle, FX_DWORD dwMatch)
{
    FX_DWORD dwHash = FPF_SKIAGetFamilyHash(bsFamilyname, dwStyle, uCharset);
    IFPF_Font *pFont = NULL;
    if (m_FamilyFonts.Lookup((void*)(FX_UINTPTR)dwHash, (void*&)pFont)) {
        if (pFont) {
            return pFont->Retain();
        }
    }
    FX_DWORD dwFaceName = FPF_SKIANormalizeFontName(bsFamilyname);
    FX_DWORD dwSubst = FPF_SkiaGetSubstFont(dwFaceName);
    FX_DWORD dwSubstSans = FPF_SkiaGetSansFont(dwFaceName);
    FX_BOOL bMaybeSymbol = FPF_SkiaMaybeSymbol(bsFamilyname);
    if (uCharset != FXFONT_ARABIC_CHARSET && FPF_SkiaMaybeArabic(bsFamilyname)) {
        uCharset = FXFONT_ARABIC_CHARSET;
    } else if (uCharset == FXFONT_ANSI_CHARSET && (dwMatch & FPF_MATCHFONT_REPLACEANSI)) {
        uCharset = FXFONT_DEFAULT_CHARSET;
    }
    FX_INT32 nExpectVal = FPF_SKIAMATCHWEIGHT_NAME1 + FPF_SKIAMATCHWEIGHT_1 * 3 + FPF_SKIAMATCHWEIGHT_2 * 2;
    FX_INT32 nItem = -1;
    FX_INT32 nMax = -1;
    FX_INT32 nGlyphNum = 0;
    for (FX_INT32 i = m_FontFaces.GetUpperBound(); i >= 0; i--) {
        CFPF_SkiaPathFont *pFontDes = (CFPF_SkiaPathFont*)m_FontFaces.ElementAt(i);
        if(!(pFontDes->m_dwCharsets & FPF_SkiaGetCharset(uCharset))) {
            continue;
        }
        FX_INT32 nFind = 0;
        FX_DWORD dwSysFontName = FPF_SKIANormalizeFontName(pFontDes->m_pFamily);
        if (dwFaceName == dwSysFontName) {
            nFind += FPF_SKIAMATCHWEIGHT_NAME1;
        }
        FX_BOOL bMatchedName = (nFind == FPF_SKIAMATCHWEIGHT_NAME1);
        if ((dwStyle & FXFONT_BOLD) == (pFontDes->m_dwStyle & FXFONT_BOLD)) {
            nFind += FPF_SKIAMATCHWEIGHT_1;
        }
        if ((dwStyle & FXFONT_ITALIC) == (pFontDes->m_dwStyle & FXFONT_ITALIC)) {
            nFind += FPF_SKIAMATCHWEIGHT_1;
        }
        if ((dwStyle & FXFONT_FIXED_PITCH) == (pFontDes->m_dwStyle & FXFONT_FIXED_PITCH)) {
            nFind += FPF_SKIAMATCHWEIGHT_2;
        }
        if ((dwStyle & FXFONT_SERIF) == (pFontDes->m_dwStyle & FXFONT_SERIF)) {
            nFind += FPF_SKIAMATCHWEIGHT_1;
        }
        if ((dwStyle & FXFONT_SCRIPT) == (pFontDes->m_dwStyle & FXFONT_SCRIPT)) {
            nFind += FPF_SKIAMATCHWEIGHT_2;
        }
        if (dwSubst == dwSysFontName || dwSubstSans == dwSysFontName) {
            nFind += FPF_SKIAMATCHWEIGHT_NAME2;
            bMatchedName = TRUE;
        }
        if (uCharset == FXFONT_DEFAULT_CHARSET || bMaybeSymbol) {
            if (nFind > nMax && bMatchedName) {
                nMax = nFind;
                nItem = i;
            }
        } else if (FPF_SkiaIsCJK(uCharset)) {
            if (bMatchedName || pFontDes->m_iGlyphNum > nGlyphNum) {
                nItem = i;
                nGlyphNum = pFontDes->m_iGlyphNum;
            }
        } else if (nFind > nMax) {
            nMax = nFind;
            nItem = i;
        }
        if (nExpectVal <= nFind) {
            nItem = i;
            break;
        }
    }
    if (nItem > -1) {
        CFPF_SkiaFontDescriptor *pFontDes = (CFPF_SkiaFontDescriptor*)m_FontFaces.ElementAt(nItem);
        CFPF_SkiaFont *pFont = new CFPF_SkiaFont;
        if (pFont->InitFont(this, pFontDes, bsFamilyname, dwStyle, uCharset)) {
            m_FamilyFonts.SetAt((void*)(FX_UINTPTR)dwHash, (void*)pFont);
            return pFont->Retain();
        }
        pFont->Release();
    }
    return NULL;
}
示例#2
0
CFPF_SkiaFont* CFPF_SkiaFontMgr::CreateFont(const CFX_ByteStringC& bsFamilyname,
                                            uint8_t uCharset,
                                            uint32_t dwStyle,
                                            uint32_t dwMatch) {
  uint32_t dwHash = FPF_SKIAGetFamilyHash(bsFamilyname, dwStyle, uCharset);
  auto it = m_FamilyFonts.find(dwHash);
  if (it != m_FamilyFonts.end() && it->second)
    return it->second->Retain();

  uint32_t dwFaceName = FPF_SKIANormalizeFontName(bsFamilyname);
  uint32_t dwSubst = FPF_SkiaGetSubstFont(dwFaceName);
  uint32_t dwSubstSans = FPF_SkiaGetSansFont(dwFaceName);
  FX_BOOL bMaybeSymbol = FPF_SkiaMaybeSymbol(bsFamilyname);
  if (uCharset != FXFONT_ARABIC_CHARSET && FPF_SkiaMaybeArabic(bsFamilyname)) {
    uCharset = FXFONT_ARABIC_CHARSET;
  } else if (uCharset == FXFONT_ANSI_CHARSET &&
             (dwMatch & FPF_MATCHFONT_REPLACEANSI)) {
    uCharset = FXFONT_DEFAULT_CHARSET;
  }
  int32_t nExpectVal = FPF_SKIAMATCHWEIGHT_NAME1 + FPF_SKIAMATCHWEIGHT_1 * 3 +
                       FPF_SKIAMATCHWEIGHT_2 * 2;
  CFPF_SkiaFontDescriptor* pBestFontDes = nullptr;
  int32_t nMax = -1;
  int32_t nGlyphNum = 0;
  for (auto it = m_FontFaces.rbegin(); it != m_FontFaces.rend(); ++it) {
    CFPF_SkiaPathFont* pFontDes = static_cast<CFPF_SkiaPathFont*>(*it);
    if (!(pFontDes->m_dwCharsets & FPF_SkiaGetCharset(uCharset))) {
      continue;
    }
    int32_t nFind = 0;
    uint32_t dwSysFontName = FPF_SKIANormalizeFontName(pFontDes->m_pFamily);
    if (dwFaceName == dwSysFontName) {
      nFind += FPF_SKIAMATCHWEIGHT_NAME1;
    }
    bool bMatchedName = (nFind == FPF_SKIAMATCHWEIGHT_NAME1);
    if ((dwStyle & FXFONT_BOLD) == (pFontDes->m_dwStyle & FXFONT_BOLD)) {
      nFind += FPF_SKIAMATCHWEIGHT_1;
    }
    if ((dwStyle & FXFONT_ITALIC) == (pFontDes->m_dwStyle & FXFONT_ITALIC)) {
      nFind += FPF_SKIAMATCHWEIGHT_1;
    }
    if ((dwStyle & FXFONT_FIXED_PITCH) ==
        (pFontDes->m_dwStyle & FXFONT_FIXED_PITCH)) {
      nFind += FPF_SKIAMATCHWEIGHT_2;
    }
    if ((dwStyle & FXFONT_SERIF) == (pFontDes->m_dwStyle & FXFONT_SERIF)) {
      nFind += FPF_SKIAMATCHWEIGHT_1;
    }
    if ((dwStyle & FXFONT_SCRIPT) == (pFontDes->m_dwStyle & FXFONT_SCRIPT)) {
      nFind += FPF_SKIAMATCHWEIGHT_2;
    }
    if (dwSubst == dwSysFontName || dwSubstSans == dwSysFontName) {
      nFind += FPF_SKIAMATCHWEIGHT_NAME2;
      bMatchedName = true;
    }
    if (uCharset == FXFONT_DEFAULT_CHARSET || bMaybeSymbol) {
      if (nFind > nMax && bMatchedName) {
        nMax = nFind;
        pBestFontDes = *it;
      }
    } else if (FPF_SkiaIsCJK(uCharset)) {
      if (bMatchedName || pFontDes->m_iGlyphNum > nGlyphNum) {
        pBestFontDes = *it;
        nGlyphNum = pFontDes->m_iGlyphNum;
      }
    } else if (nFind > nMax) {
      nMax = nFind;
      pBestFontDes = *it;
    }
    if (nExpectVal <= nFind) {
      pBestFontDes = *it;
      break;
    }
  }
  if (pBestFontDes) {
    CFPF_SkiaFont* pFont = new CFPF_SkiaFont;
    if (pFont->InitFont(this, pBestFontDes, bsFamilyname, dwStyle, uCharset)) {
      m_FamilyFonts[dwHash] = pFont;
      return pFont->Retain();
    }
    pFont->Release();
  }
  return nullptr;
}