FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, CFX_WordArray* pageArray, int nCount) { if (rangstring.GetLength() != 0) { rangstring.Remove(' '); int nLength = rangstring.GetLength(); CFX_ByteString cbCompareString("0123456789-,"); for (int i = 0; i < nLength; ++i) { if (cbCompareString.Find(rangstring[i]) == -1) return FALSE; } CFX_ByteString cbMidRange; int nStringFrom = 0; int nStringTo = 0; while (nStringTo < nLength) { nStringTo = rangstring.Find(',', nStringFrom); if (nStringTo == -1) nStringTo = nLength; cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom); int nMid = cbMidRange.Find('-'); if (nMid == -1) { long lPageNum = atol(cbMidRange); if (lPageNum <= 0 || lPageNum > nCount) return FALSE; pageArray->Add((FX_WORD)lPageNum); } else { int nStartPageNum = atol(cbMidRange.Mid(0, nMid)); if (nStartPageNum == 0) return FALSE; ++nMid; int nEnd = cbMidRange.GetLength() - nMid; if (nEnd == 0) return FALSE; int nEndPageNum = atol(cbMidRange.Mid(nMid, nEnd)); if (nStartPageNum < 0 || nStartPageNum > nEndPageNum || nEndPageNum > nCount) { return FALSE; } for (int i = nStartPageNum; i <= nEndPageNum; ++i) { pageArray->Add(i); } } nStringFrom = nStringTo + 1; } } return TRUE; }
int32_t CBC_OnedUPCAWriter::CalcChecksum(const CFX_ByteString& contents) { int32_t odd = 0; int32_t even = 0; int32_t j = 1; for (int32_t i = contents.GetLength() - 1; i >= 0; i--) { if (j % 2) { odd += FXSYS_atoi(contents.Mid(i, 1).c_str()); } else { even += FXSYS_atoi(contents.Mid(i, 1).c_str()); } j++; } int32_t checksum = (odd * 3 + even) % 10; checksum = (10 - checksum) % 10; return (checksum); }
int32_t CBC_OnedCode128Writer::Encode128C(const CFX_ByteString& contents, CFX_PtrArray& patterns) { int32_t checkSum = 0; int32_t checkWeight = 1; int32_t position = 0; patterns.Add((int32_t*)CBC_OnedCode128Reader::CODE_PATTERNS[CODE_START_C]); checkSum += CODE_START_C * checkWeight; while (position < contents.GetLength()) { int32_t patternIndex = 0; FX_CHAR ch = contents.GetAt(position); if (ch < '0' || ch > '9') { patternIndex = (int32_t)ch; position++; } else { patternIndex = FXSYS_atoi(contents.Mid(position, 2)); if (contents.GetAt(position + 1) < '0' || contents.GetAt(position + 1) > '9') { position += 1; } else { position += 2; } } patterns.Add((int32_t*)CBC_OnedCode128Reader::CODE_PATTERNS[patternIndex]); checkSum += patternIndex * checkWeight; if (position != 0) { checkWeight++; } } return checkSum; }
FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name, FX_BOOL bTrueType, FX_DWORD flags, int weight, int italic_angle, int WindowCP, CFX_SubstFont* pSubstFont) { if (!(flags & FXFONT_USEEXTERNATTR)) { weight = FXFONT_FW_NORMAL; italic_angle = 0; } CFX_ByteString SubstName = name; SubstName.Remove(0x20); if (bTrueType) { if (name[0] == '@') { SubstName = name.Mid(1); } } _PDF_GetStandardFontName(SubstName); if (SubstName == FX_BSTRC("Symbol") && !bTrueType) { pSubstFont->m_Family = "Chrome Symbol"; pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; if (m_FoxitFaces[12]) { return m_FoxitFaces[12]; } FX_LPCBYTE pFontData = NULL; FX_DWORD size = 0; m_pFontMgr->GetStandardFont(pFontData, size, 12); m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0); return m_FoxitFaces[12]; } if (SubstName == FX_BSTRC("ZapfDingbats")) { pSubstFont->m_Family = "Chrome Dingbats"; pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; if (m_FoxitFaces[13]) { return m_FoxitFaces[13]; } FX_LPCBYTE pFontData = NULL; FX_DWORD size = 0; m_pFontMgr->GetStandardFont(pFontData, size, 13); m_FoxitFaces[13] = m_pFontMgr->GetFixedFace(pFontData, size, 0); return m_FoxitFaces[13]; } int iBaseFont = 0; CFX_ByteString family, style; FX_BOOL bHasComma = FALSE; FX_BOOL bHasHypen = FALSE; int find = SubstName.Find(FX_BSTRC(","), 0); if (find >= 0) { family = SubstName.Left(find); _PDF_GetStandardFontName(family); style = SubstName.Mid(find + 1); bHasComma = TRUE; } else { family = SubstName; } for (; iBaseFont < 12; iBaseFont ++) if (family == CFX_ByteStringC(g_Base14FontNames[iBaseFont])) { break; } int PitchFamily = 0; FX_BOOL bItalic = FALSE; FX_DWORD nStyle = 0; FX_BOOL bStyleAvail = FALSE; FX_BOOL bFamilyStyleIsWhole = FALSE; FX_BOOL bNextF = FALSE; if (iBaseFont < 12) { family = g_Base14FontNames[iBaseFont]; if ((iBaseFont % 4) == 1 || (iBaseFont % 4) == 2) { nStyle |= FX_FONT_STYLE_Bold; } if ((iBaseFont % 4) / 2) { nStyle |= FX_FONT_STYLE_Italic; } if (iBaseFont < 4) { PitchFamily |= FXFONT_FF_FIXEDPITCH; } if (iBaseFont >= 8) { PitchFamily |= FXFONT_FF_ROMAN; } } else { if (!bHasComma) { find = family.ReverseFind('-'); if (find >= 0) { style = family.Mid(find + 1); family = family.Left(find); bHasHypen = TRUE; } } if (!bHasHypen) { int nLen = family.GetLength(); FX_INT32 nRet = GetStyleType(family, TRUE); if (nRet > -1) { family = family.Left(nLen - g_FontStyles[nRet].len); if (nRet == 0) { nStyle |= FX_FONT_STYLE_Bold; } if (nRet == 1) { nStyle |= FX_FONT_STYLE_Italic; } if (nRet == 2) { nStyle |= (FX_FONT_STYLE_Bold | FX_FONT_STYLE_Italic); } } } if (flags & FXFONT_SERIF) { PitchFamily |= FXFONT_FF_ROMAN; } if (flags & FXFONT_SCRIPT) { PitchFamily |= FXFONT_FF_SCRIPT; } if (flags & FXFONT_FIXED_PITCH) { PitchFamily |= FXFONT_FF_FIXEDPITCH; } } if (!style.IsEmpty()) { int nLen = style.GetLength(); FX_LPCSTR pStyle = style; int i = 0; FX_BOOL bFirstItem = TRUE; CFX_ByteString buf; while (i < nLen) { buf = ParseStyle(pStyle, nLen, i); FX_INT32 nRet = GetStyleType(buf, FALSE); if ((i && !bStyleAvail) || (!i && nRet < 0)) { family = SubstName; iBaseFont = 12; break; } else if (nRet >= 0) { bStyleAvail = TRUE; } if (nRet == 0) { if (nStyle & FX_FONT_STYLE_Bold) { nStyle |= FX_FONT_STYLE_BoldBold; } else { nStyle |= FX_FONT_STYLE_Bold; } bFirstItem = FALSE; } if (nRet == 1) { if (bFirstItem) { nStyle |= FX_FONT_STYLE_Italic; } else { family = SubstName; iBaseFont = 12; } break; } if (nRet == 2) { nStyle |= FX_FONT_STYLE_Italic; if (nStyle & FX_FONT_STYLE_Bold) { nStyle |= FX_FONT_STYLE_BoldBold; } else { nStyle |= FX_FONT_STYLE_Bold; } bFirstItem = FALSE; } i += buf.GetLength() + 1; } } weight = weight ? weight : FXFONT_FW_NORMAL; int old_weight = weight; if (nStyle) { weight = nStyle & FX_FONT_STYLE_BoldBold ? 900 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL); } if (nStyle & FX_FONT_STYLE_Italic) { bItalic = TRUE; } FX_BOOL bCJK = FALSE; FX_BOOL bExact = FALSE; int Charset = FXFONT_ANSI_CHARSET; if (WindowCP) { Charset = _GetCharsetFromCodePage(WindowCP); } else if (iBaseFont == 12 && (flags & FXFONT_SYMBOLIC)) { Charset = FXFONT_SYMBOL_CHARSET; } if (Charset == FXFONT_SHIFTJIS_CHARSET || Charset == FXFONT_GB2312_CHARSET || Charset == FXFONT_HANGEUL_CHARSET || Charset == FXFONT_CHINESEBIG5_CHARSET) { bCJK = TRUE; } if (m_pFontInfo == NULL) { pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, PitchFamily); } family = _GetFontFamily(family, nStyle); CFX_ByteString match = MatchInstalledFonts(_TT_NormalizeName(family)); if (match.IsEmpty() && family != SubstName && (!bHasComma && (!bHasHypen || (bHasHypen && !bStyleAvail)))) { match = MatchInstalledFonts(_TT_NormalizeName(SubstName)); } if (match.IsEmpty() && iBaseFont >= 12) { if (!bCJK) { if (!CheckSupportThirdPartFont(family, PitchFamily)) { if (italic_angle != 0) { bItalic = TRUE; } else { bItalic = FALSE; } weight = old_weight; } } else { pSubstFont->m_bSubstOfCJK = TRUE; if (nStyle) { pSubstFont->m_WeightCJK = weight; } else { pSubstFont->m_WeightCJK = FXFONT_FW_NORMAL; } if (nStyle & FX_FONT_STYLE_Italic) { pSubstFont->m_bItlicCJK = TRUE; } } } else { italic_angle = 0; weight = nStyle & FX_FONT_STYLE_BoldBold ? 900 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL); } if (!match.IsEmpty() || iBaseFont < 12) { pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT; if (!match.IsEmpty()) { family = match; } if (iBaseFont < 12) { if (nStyle && !(iBaseFont % 4)) { if ((nStyle & 0x3) == 1) { iBaseFont += 1; } if ((nStyle & 0x3) == 2) { iBaseFont += 3; } if ((nStyle & 0x3) == 3) { iBaseFont += 2; } } if (m_pFontMgr->m_ExternalFonts[iBaseFont].m_pFontData) { if (m_FoxitFaces[iBaseFont]) { return m_FoxitFaces[iBaseFont]; } m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(m_pFontMgr->m_ExternalFonts[iBaseFont].m_pFontData, m_pFontMgr->m_ExternalFonts[iBaseFont].m_dwSize, 0); if (m_FoxitFaces[iBaseFont]) { return m_FoxitFaces[iBaseFont]; } } else { family = g_Base14FontNames[iBaseFont]; } pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; } } else { if (flags & FXFONT_ITALIC) { bItalic = TRUE; } } bExact = !match.IsEmpty(); void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, family, bExact); if (bExact) { pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT; } if (hFont == NULL) { if (bCJK) { if (italic_angle != 0) { bItalic = TRUE; } else { bItalic = FALSE; } weight = old_weight; } if (!match.IsEmpty()) { hFont = m_pFontInfo->GetFont(match); if (hFont == NULL) { return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, PitchFamily); } } else { if (Charset == FXFONT_SYMBOL_CHARSET) { #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ if (SubstName == FX_BSTRC("Symbol")) { pSubstFont->m_Family = "Chrome Symbol"; pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; if (m_FoxitFaces[12]) { return m_FoxitFaces[12]; } FX_LPCBYTE pFontData = NULL; FX_DWORD size = 0; m_pFontMgr->GetStandardFont(pFontData, size, 12); m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0); return m_FoxitFaces[12]; } else { pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL; return FindSubstFont(family, bTrueType, flags & ~FXFONT_SYMBOLIC, weight, italic_angle, 0, pSubstFont); } #else pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL; return FindSubstFont(family, bTrueType, flags & ~FXFONT_SYMBOLIC, weight, italic_angle, 0, pSubstFont); #endif } if (Charset == FXFONT_ANSI_CHARSET) { pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, PitchFamily); } int index = m_CharsetArray.Find(Charset); if (index < 0) { return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, PitchFamily); } else { hFont = m_pFontInfo->GetFont(m_FaceArray[index]); } } } pSubstFont->m_ExtHandle = m_pFontInfo->RetainFont(hFont); if (hFont == NULL) { return NULL; } m_pFontInfo->GetFaceName(hFont, SubstName); if (Charset == FXFONT_DEFAULT_CHARSET) { m_pFontInfo->GetFontCharset(hFont, Charset); } FX_DWORD ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, NULL, 0); FX_DWORD font_size = m_pFontInfo->GetFontData(hFont, 0, NULL, 0); if(font_size == 0 && ttc_size == 0) { m_pFontInfo->DeleteFont(hFont); return NULL; } FXFT_Face face = NULL; if (ttc_size) { FX_BYTE temp[1024]; m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024); FX_DWORD checksum = 0; for (int i = 0; i < 256; i ++) { checksum += ((FX_DWORD*)temp)[i]; } FX_LPBYTE pFontData; face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_size, pFontData); if (face == NULL) { pFontData = FX_Alloc(FX_BYTE, ttc_size); if (pFontData) { m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size); face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, ttc_size, ttc_size - font_size); } } } else { FX_LPBYTE pFontData; face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData); if (face == NULL) { pFontData = FX_Alloc(FX_BYTE, font_size); if (!pFontData) { m_pFontInfo->DeleteFont(hFont); return NULL; } m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size); face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontData, font_size, m_pFontInfo->GetFaceIndex(hFont)); } } if (face == NULL) { m_pFontInfo->DeleteFont(hFont); return NULL; } pSubstFont->m_Family = SubstName; pSubstFont->m_Charset = Charset; FX_BOOL bNeedUpdateWeight = FALSE; if (FXFT_Is_Face_Bold(face)) { if (weight == FXFONT_FW_BOLD) { bNeedUpdateWeight = FALSE; } else { bNeedUpdateWeight = TRUE; } } else { if (weight == FXFONT_FW_NORMAL) { bNeedUpdateWeight = FALSE; } else { bNeedUpdateWeight = TRUE; } } if (bNeedUpdateWeight) { pSubstFont->m_Weight = weight; } if (bItalic && !FXFT_Is_Face_Italic(face)) { if (italic_angle == 0) { italic_angle = -12; } else if (FXSYS_abs(italic_angle) < 5) { italic_angle = 0; } pSubstFont->m_ItalicAngle = italic_angle; } m_pFontInfo->DeleteFont(hFont); return face; }
void CBC_OnedUPCAWriter::ShowChars(const CFX_WideStringC& contents, CFX_DIBitmap* pOutBitmap, CFX_RenderDevice* device, const CFX_Matrix* matrix, int32_t barWidth, int32_t multiple, int32_t& e) { if (!device && !pOutBitmap) { e = BCExceptionIllegalArgument; return; } int32_t leftPadding = 7 * multiple; int32_t leftPosition = 10 * multiple + leftPadding; CFX_ByteString str = FX_UTF8Encode(contents); int32_t iLen = str.GetLength(); FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen); FXSYS_memset(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen); CFX_ByteString tempStr = str.Mid(1, 5); FX_FLOAT strWidth = (FX_FLOAT)35 * multiple; FX_FLOAT blank = 0.0; CFX_FxgeDevice geBitmap; if (pOutBitmap) geBitmap.Attach(pOutBitmap, false, nullptr, false); iLen = tempStr.GetLength(); int32_t iFontSize = (int32_t)fabs(m_fFontSize); int32_t iTextHeight = iFontSize + 1; if (!pOutBitmap) { CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); CFX_FloatRect rect( (FX_FLOAT)leftPosition, (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)(leftPosition + strWidth - 0.5), (FX_FLOAT)m_Height); matr.Concat(*matrix); matr.TransformRect(rect); FX_RECT re = rect.GetOutterRect(); device->FillRect(&re, m_backgroundColor); CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); CFX_FloatRect rect1( (FX_FLOAT)(leftPosition + 40 * multiple), (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)((leftPosition + 40 * multiple) + strWidth - 0.5), (FX_FLOAT)m_Height); matr1.Concat(*matrix); matr1.TransformRect(rect1); re = rect1.GetOutterRect(); device->FillRect(&re, m_backgroundColor); FX_FLOAT strWidth1 = (FX_FLOAT)multiple * 7; CFX_Matrix matr2(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); CFX_FloatRect rect2(0.0, (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)strWidth1 - 1, (FX_FLOAT)m_Height); matr2.Concat(*matrix); matr2.TransformRect(rect2); re = rect2.GetOutterRect(); device->FillRect(&re, m_backgroundColor); CFX_Matrix matr3(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); CFX_FloatRect rect3( (FX_FLOAT)(leftPosition + 85 * multiple), (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)((leftPosition + 85 * multiple) + strWidth1 - 0.5), (FX_FLOAT)m_Height); matr3.Concat(*matrix); matr3.TransformRect(rect3); re = rect3.GetOutterRect(); device->FillRect(&re, m_backgroundColor); } if (!pOutBitmap) strWidth = strWidth * m_outputHScale; CalcTextInfo(tempStr, pCharPos + 1, m_pFont, strWidth, iFontSize, blank); CFX_Matrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize); CFX_FxgeDevice ge; if (pOutBitmap) { ge.Create((int)strWidth, iTextHeight, FXDIB_Argb, nullptr); ge.GetBitmap()->Clear(m_backgroundColor); ge.DrawNormalText(iLen, pCharPos + 1, m_pFont, CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize, &affine_matrix, m_fontColor, FXTEXT_CLEARTYPE); geBitmap.SetDIBits(ge.GetBitmap(), leftPosition, m_Height - iTextHeight); } else { CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)leftPosition * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize)); if (matrix) { affine_matrix1.Concat(*matrix); } device->DrawNormalText( iLen, pCharPos + 1, m_pFont, CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize, &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } tempStr = str.Mid(6, 5); iLen = tempStr.GetLength(); CalcTextInfo(tempStr, pCharPos + 6, m_pFont, strWidth, iFontSize, blank); if (pOutBitmap) { FX_RECT rect2(0, 0, (int)strWidth, iTextHeight); ge.FillRect(&rect2, m_backgroundColor); ge.DrawNormalText(iLen, pCharPos + 6, m_pFont, CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize, &affine_matrix, m_fontColor, FXTEXT_CLEARTYPE); geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 40 * multiple, m_Height - iTextHeight); } else { CFX_Matrix affine_matrix1( 1.0, 0.0, 0.0, -1.0, (FX_FLOAT)(leftPosition + 40 * multiple) * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize)); if (matrix) { affine_matrix1.Concat(*matrix); } device->DrawNormalText( iLen, pCharPos + 6, m_pFont, CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize, &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } tempStr = str.Mid(0, 1); iLen = tempStr.GetLength(); strWidth = (FX_FLOAT)multiple * 7; if (!pOutBitmap) strWidth = strWidth * m_outputHScale; CalcTextInfo(tempStr, pCharPos, m_pFont, strWidth, iFontSize, blank); if (pOutBitmap) { delete ge.GetBitmap(); ge.Create((int)strWidth, iTextHeight, FXDIB_Argb, nullptr); ge.GetBitmap()->Clear(m_backgroundColor); ge.DrawNormalText(iLen, pCharPos, m_pFont, CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize, &affine_matrix, m_fontColor, FXTEXT_CLEARTYPE); geBitmap.SetDIBits(ge.GetBitmap(), 0, m_Height - iTextHeight); } else { CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0, (FX_FLOAT)(m_Height - iTextHeight + iFontSize)); if (matrix) { affine_matrix1.Concat(*matrix); } device->DrawNormalText( iLen, pCharPos, m_pFont, CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize, &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } tempStr = str.Mid(11, 1); iLen = tempStr.GetLength(); CalcTextInfo(tempStr, pCharPos + 11, m_pFont, strWidth, iFontSize, blank); if (pOutBitmap) { delete ge.GetBitmap(); ge.Create((int)strWidth, iTextHeight, FXDIB_Argb, nullptr); ge.GetBitmap()->Clear(m_backgroundColor); ge.DrawNormalText(iLen, pCharPos + 11, m_pFont, CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize, &affine_matrix, m_fontColor, FXTEXT_CLEARTYPE); geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 85 * multiple, m_Height - iTextHeight); } else { CFX_Matrix affine_matrix1( 1.0, 0.0, 0.0, -1.0, (FX_FLOAT)(leftPosition + 85 * multiple) * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize)); if (matrix) { affine_matrix1.Concat(*matrix); } device->DrawNormalText( iLen, pCharPos + 11, m_pFont, CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize, &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } FX_Free(pCharPos); }
FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name, FX_BOOL bTrueType, uint32_t flags, int weight, int italic_angle, int WindowCP, CFX_SubstFont* pSubstFont) { if (!(flags & FXFONT_USEEXTERNATTR)) { weight = FXFONT_FW_NORMAL; italic_angle = 0; } CFX_ByteString SubstName = name; SubstName.Remove(' '); if (bTrueType && name[0] == '@') SubstName = name.Mid(1); PDF_GetStandardFontName(&SubstName); if (SubstName == "Symbol" && !bTrueType) { pSubstFont->m_Family = "Chrome Symbol"; pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; if (m_FoxitFaces[12]) return m_FoxitFaces[12]; const uint8_t* pFontData = nullptr; uint32_t size = 0; m_pFontMgr->GetBuiltinFont(12, &pFontData, &size); m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0); return m_FoxitFaces[12]; } if (SubstName == "ZapfDingbats") { pSubstFont->m_Family = "Chrome Dingbats"; pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; if (m_FoxitFaces[13]) return m_FoxitFaces[13]; const uint8_t* pFontData = nullptr; uint32_t size = 0; m_pFontMgr->GetBuiltinFont(13, &pFontData, &size); m_FoxitFaces[13] = m_pFontMgr->GetFixedFace(pFontData, size, 0); return m_FoxitFaces[13]; } int iBaseFont = 0; CFX_ByteString family; CFX_ByteString style; bool bHasComma = false; bool bHasHyphen = false; int find = SubstName.Find(",", 0); if (find >= 0) { family = SubstName.Left(find); PDF_GetStandardFontName(&family); style = SubstName.Mid(find + 1); bHasComma = true; } else { family = SubstName; } for (; iBaseFont < kExternalFontIndex; iBaseFont++) { if (family == CFX_ByteStringC(g_Base14FontNames[iBaseFont])) break; } int PitchFamily = 0; bool bItalic = false; uint32_t nStyle = 0; bool bStyleAvail = false; if (iBaseFont < kExternalFontIndex) { if ((iBaseFont % 4) == 1 || (iBaseFont % 4) == 2) nStyle |= FX_FONT_STYLE_Bold; if ((iBaseFont % 4) / 2) nStyle |= FX_FONT_STYLE_Italic; if (iBaseFont < 4) PitchFamily |= FXFONT_FF_FIXEDPITCH; if (iBaseFont >= 8) PitchFamily |= FXFONT_FF_ROMAN; } else { if (!bHasComma) { find = family.ReverseFind('-'); if (find >= 0) { style = family.Mid(find + 1); family = family.Left(find); bHasHyphen = true; } } if (!bHasHyphen) { int nLen = family.GetLength(); int32_t nRet = GetStyleType(family, true); if (nRet > -1) { family = family.Left(nLen - g_FontStyles[nRet].len); if (nRet == 0) nStyle |= FX_FONT_STYLE_Bold; else if (nRet == 1) nStyle |= FX_FONT_STYLE_Italic; else if (nRet == 2) nStyle |= (FX_FONT_STYLE_Bold | FX_FONT_STYLE_Italic); } } UpdatePitchFamily(flags, PitchFamily); } if (!style.IsEmpty()) { int nLen = style.GetLength(); const FX_CHAR* pStyle = style.c_str(); int i = 0; bool bFirstItem = true; CFX_ByteString buf; while (i < nLen) { buf = ParseStyle(pStyle, nLen, i); int32_t nRet = GetStyleType(buf, false); if ((i && !bStyleAvail) || (!i && nRet < 0)) { family = SubstName; iBaseFont = kExternalFontIndex; break; } if (nRet >= 0) { bStyleAvail = true; } if (nRet == 1) { if (bFirstItem) { nStyle |= FX_FONT_STYLE_Italic; } else { family = SubstName; iBaseFont = kExternalFontIndex; } break; } if (nRet == 0) { if (nStyle & FX_FONT_STYLE_Bold) nStyle |= FX_FONT_STYLE_BoldBold; else nStyle |= FX_FONT_STYLE_Bold; bFirstItem = false; } else if (nRet == 2) { nStyle |= FX_FONT_STYLE_Italic; if (nStyle & FX_FONT_STYLE_Bold) nStyle |= FX_FONT_STYLE_BoldBold; else nStyle |= FX_FONT_STYLE_Bold; bFirstItem = false; } i += buf.GetLength() + 1; } } weight = weight ? weight : FXFONT_FW_NORMAL; int old_weight = weight; if (nStyle) { weight = nStyle & FX_FONT_STYLE_BoldBold ? 900 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL); } if (nStyle & FX_FONT_STYLE_Italic) bItalic = true; int iExact = 0; int Charset = FXFONT_ANSI_CHARSET; if (WindowCP) Charset = GetCharsetFromCodePage(WindowCP); else if (iBaseFont == kExternalFontIndex && (flags & FXFONT_SYMBOLIC)) Charset = FXFONT_SYMBOL_CHARSET; bool bCJK = (Charset == FXFONT_SHIFTJIS_CHARSET || Charset == FXFONT_GB2312_CHARSET || Charset == FXFONT_HANGUL_CHARSET || Charset == FXFONT_CHINESEBIG5_CHARSET); if (!m_pFontInfo) { pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, PitchFamily); } family = GetFontFamily(family, nStyle); CFX_ByteString match = MatchInstalledFonts(TT_NormalizeName(family.c_str())); if (match.IsEmpty() && family != SubstName && (!bHasComma && (!bHasHyphen || (bHasHyphen && !bStyleAvail)))) { match = MatchInstalledFonts(TT_NormalizeName(SubstName.c_str())); } if (match.IsEmpty() && iBaseFont >= kExternalFontIndex) { if (!bCJK) { if (!CheckSupportThirdPartFont(family, PitchFamily)) { bItalic = italic_angle != 0; weight = old_weight; } } else { pSubstFont->m_bSubstCJK = true; if (nStyle) pSubstFont->m_WeightCJK = nStyle ? weight : FXFONT_FW_NORMAL; if (nStyle & FX_FONT_STYLE_Italic) pSubstFont->m_bItalicCJK = true; } } else { italic_angle = 0; weight = nStyle & FX_FONT_STYLE_BoldBold ? 900 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL); } if (!match.IsEmpty() || iBaseFont < kExternalFontIndex) { if (!match.IsEmpty()) family = match; if (iBaseFont < kExternalFontIndex) { if (nStyle && !(iBaseFont % 4)) { if ((nStyle & 0x3) == 1) iBaseFont += 1; if ((nStyle & 0x3) == 2) iBaseFont += 3; if ((nStyle & 0x3) == 3) iBaseFont += 2; } family = g_Base14FontNames[iBaseFont]; pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; } } else { if (flags & FXFONT_ITALIC) bItalic = true; } iExact = !match.IsEmpty(); void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, family.c_str(), iExact); if (iExact) pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT; if (!hFont) { #ifdef PDF_ENABLE_XFA if (flags & FXFONT_EXACTMATCH) return nullptr; #endif // PDF_ENABLE_XFA if (bCJK) { bItalic = italic_angle != 0; weight = old_weight; } if (!match.IsEmpty()) { hFont = m_pFontInfo->GetFont(match.c_str()); if (!hFont) { return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, PitchFamily); } } else { if (Charset == FXFONT_SYMBOL_CHARSET) { #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ if (SubstName == "Symbol") { pSubstFont->m_Family = "Chrome Symbol"; pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; if (m_FoxitFaces[12]) return m_FoxitFaces[12]; const uint8_t* pFontData = nullptr; uint32_t size = 0; m_pFontMgr->GetBuiltinFont(12, &pFontData, &size); m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0); return m_FoxitFaces[12]; } #endif pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL; return FindSubstFont(family, bTrueType, flags & ~FXFONT_SYMBOLIC, weight, italic_angle, 0, pSubstFont); } if (Charset == FXFONT_ANSI_CHARSET) { pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, PitchFamily); } auto it = std::find_if(m_FaceArray.begin(), m_FaceArray.end(), [Charset](const FaceData& face) { return face.charset == static_cast<uint32_t>(Charset); }); if (it == m_FaceArray.end()) { return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, PitchFamily); } hFont = m_pFontInfo->GetFont(it->name.c_str()); } } if (!hFont) return nullptr; m_pFontInfo->GetFaceName(hFont, SubstName); if (Charset == FXFONT_DEFAULT_CHARSET) m_pFontInfo->GetFontCharset(hFont, Charset); uint32_t ttc_size = m_pFontInfo->GetFontData(hFont, kTableTTCF, nullptr, 0); uint32_t font_size = m_pFontInfo->GetFontData(hFont, 0, nullptr, 0); if (font_size == 0 && ttc_size == 0) { m_pFontInfo->DeleteFont(hFont); return nullptr; } FXFT_Face face = nullptr; if (ttc_size) face = GetCachedTTCFace(hFont, kTableTTCF, ttc_size, font_size); else face = GetCachedFace(hFont, SubstName, weight, bItalic, font_size); if (!face) { m_pFontInfo->DeleteFont(hFont); return nullptr; } pSubstFont->m_Family = SubstName; pSubstFont->m_Charset = Charset; bool bNeedUpdateWeight = false; if (FXFT_Is_Face_Bold(face)) bNeedUpdateWeight = weight != FXFONT_FW_BOLD; else bNeedUpdateWeight = weight != FXFONT_FW_NORMAL; if (bNeedUpdateWeight) pSubstFont->m_Weight = weight; if (bItalic && !FXFT_Is_Face_Italic(face)) { if (italic_angle == 0) italic_angle = -12; else if (FXSYS_abs(italic_angle) < 5) italic_angle = 0; pSubstFont->m_ItalicAngle = italic_angle; } m_pFontInfo->DeleteFont(hFont); return face; }