int Distance(Coon_Color& o) { int max, diff; max = FXSYS_abs(comp[0] - o.comp[0]); diff = FXSYS_abs(comp[1] - o.comp[1]); if (max < diff) { max = diff; } diff = FXSYS_abs(comp[2] - o.comp[2]); if (max < diff) { max = diff; } return max; }
CBC_ResultPoint* CBC_DataMatrixDetector::CorrectTopRightRectangular( CBC_ResultPoint* bottomLeft, CBC_ResultPoint* bottomRight, CBC_ResultPoint* topLeft, CBC_ResultPoint* topRight, int32_t dimensionTop, int32_t dimensionRight) { FX_FLOAT corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT)dimensionTop; int32_t norm = Distance(topLeft, topRight); FX_FLOAT cos = (topRight->GetX() - topLeft->GetX()) / norm; FX_FLOAT sin = (topRight->GetY() - topLeft->GetY()) / norm; CBC_AutoPtr<CBC_ResultPoint> c1(new CBC_ResultPoint( topRight->GetX() + corr * cos, topRight->GetY() + corr * sin)); corr = Distance(bottomLeft, topLeft) / (FX_FLOAT)dimensionRight; norm = Distance(bottomRight, topRight); cos = (topRight->GetX() - bottomRight->GetX()) / norm; sin = (topRight->GetY() - bottomRight->GetY()) / norm; CBC_AutoPtr<CBC_ResultPoint> c2(new CBC_ResultPoint( topRight->GetX() + corr * cos, topRight->GetY() + corr * sin)); if (!IsValid(c1.get())) { if (IsValid(c2.get())) { return c2.release(); } return NULL; } else if (!IsValid(c2.get())) { return c1.release(); } int32_t l1 = FXSYS_abs(dimensionTop - CBC_AutoPtr<CBC_ResultPointsAndTransitions>( TransitionsBetween(topLeft, c1.get())) ->GetTransitions()) + FXSYS_abs(dimensionRight - CBC_AutoPtr<CBC_ResultPointsAndTransitions>( TransitionsBetween(bottomRight, c1.get())) ->GetTransitions()); int32_t l2 = FXSYS_abs(dimensionTop - CBC_AutoPtr<CBC_ResultPointsAndTransitions>( TransitionsBetween(topLeft, c2.get())) ->GetTransitions()) + FXSYS_abs(dimensionRight - CBC_AutoPtr<CBC_ResultPointsAndTransitions>( TransitionsBetween(bottomRight, c2.get())) ->GetTransitions()); if (l1 <= l2) { return c1.release(); } return c2.release(); }
CFX_DIBitmap* CFX_DIBSource::StretchTo(int dest_width, int dest_height, FX_DWORD flags, const FX_RECT* pClip) const { FX_RECT clip_rect(0, 0, FXSYS_abs(dest_width), FXSYS_abs(dest_height)); if (pClip) { clip_rect.Intersect(*pClip); } if (clip_rect.IsEmpty()) { return NULL; } if (dest_width == m_Width && dest_height == m_Height) { return Clone(&clip_rect); } CFX_ImageStretcher stretcher; CFX_BitmapStorer storer; if (stretcher.Start(&storer, this, dest_width, dest_height, clip_rect, flags)) { stretcher.Continue(NULL); } return storer.Detach(); }
CFX_DIBitmap* CFX_DIBSource::StretchTo(int dest_width, int dest_height, uint32_t flags, const FX_RECT* pClip) const { FX_RECT clip_rect(0, 0, FXSYS_abs(dest_width), FXSYS_abs(dest_height)); if (pClip) clip_rect.Intersect(*pClip); if (clip_rect.IsEmpty()) return nullptr; if (dest_width == m_Width && dest_height == m_Height) return Clone(&clip_rect); CFX_BitmapStorer storer; CFX_ImageStretcher stretcher(&storer, this, dest_width, dest_height, clip_rect, flags); if (stretcher.Start()) stretcher.Continue(nullptr); return storer.Detach().release(); }
CBC_ResultPointsAndTransitions* CBC_DataMatrixDetector::TransitionsBetween( CBC_ResultPoint* from, CBC_ResultPoint* to) { int32_t fromX = (int32_t)from->GetX(); int32_t fromY = (int32_t)from->GetY(); int32_t toX = (int32_t)to->GetX(); int32_t toY = (int32_t)to->GetY(); FX_BOOL steep = FXSYS_abs(toY - fromY) > FXSYS_abs(toX - fromX); if (steep) { int32_t temp = fromX; fromX = fromY; fromY = temp; temp = toX; toX = toY; toY = temp; } int32_t dx = FXSYS_abs(toX - fromX); int32_t dy = FXSYS_abs(toY - fromY); int32_t error = -dx >> 1; int32_t ystep = fromY < toY ? 1 : -1; int32_t xstep = fromX < toX ? 1 : -1; int32_t transitions = 0; FX_BOOL inBlack = m_image->Get(steep ? fromY : fromX, steep ? fromX : fromY); for (int32_t x = fromX, y = fromY; x != toX; x += xstep) { FX_BOOL isBlack = m_image->Get(steep ? y : x, steep ? x : y); if (isBlack != inBlack) { transitions++; inBlack = isBlack; } error += dy; if (error > 0) { if (y == toY) { break; } y += ystep; error -= dx; } } return new CBC_ResultPointsAndTransitions(from, to, transitions); }
void CBC_OneDimWriter::CalcTextInfo(const CFX_ByteString& text, FXTEXT_CHARPOS* charPos, CFX_Font* cFont, FX_FLOAT geWidth, int32_t fontSize, FX_FLOAT& charsLen) { std::unique_ptr<CFX_UnicodeEncodingEx> encoding( FX_CreateFontEncodingEx(cFont)); int32_t length = text.GetLength(); uint32_t* pCharCode = FX_Alloc(uint32_t, text.GetLength()); FX_FLOAT charWidth = 0; for (int32_t j = 0; j < text.GetLength(); j++) { pCharCode[j] = encoding->CharCodeFromUnicode(text[j]); int32_t glyp_code = encoding->GlyphFromCharCode(pCharCode[j]); int32_t glyp_value = cFont->GetGlyphWidth(glyp_code); FX_FLOAT temp = (FX_FLOAT)((glyp_value)*fontSize / 1000.0); charWidth += temp; } charsLen = charWidth; FX_FLOAT leftPositon = (FX_FLOAT)(geWidth - charsLen) / 2.0f; if (leftPositon < 0 && geWidth == 0) { leftPositon = 0; } FX_FLOAT penX = 0.0; FX_FLOAT penY = (FX_FLOAT)FXSYS_abs(cFont->GetDescent()) * (FX_FLOAT)fontSize / 1000.0f; FX_FLOAT left = leftPositon; FX_FLOAT top = 0.0; charPos[0].m_OriginX = penX + left; charPos[0].m_OriginY = penY + top; charPos[0].m_GlyphIndex = encoding->GlyphFromCharCode(pCharCode[0]); charPos[0].m_FontCharWidth = cFont->GetGlyphWidth(charPos[0].m_GlyphIndex); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ charPos[0].m_ExtGID = charPos[0].m_GlyphIndex; #endif penX += (FX_FLOAT)(charPos[0].m_FontCharWidth) * (FX_FLOAT)fontSize / 1000.0f; for (int32_t i = 1; i < length; i++) { charPos[i].m_OriginX = penX + left; charPos[i].m_OriginY = penY + top; charPos[i].m_GlyphIndex = encoding->GlyphFromCharCode(pCharCode[i]); charPos[i].m_FontCharWidth = cFont->GetGlyphWidth(charPos[i].m_GlyphIndex); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ charPos[i].m_ExtGID = charPos[i].m_GlyphIndex; #endif penX += (FX_FLOAT)(charPos[i].m_FontCharWidth) * (FX_FLOAT)fontSize / 1000.0f; } FX_Free(pCharCode); }
void CPDFXFA_DocEnvironment::PageViewEvent(CXFA_FFPageView* pPageView, uint32_t dwFlags) { CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return; if (m_pContext->GetLoadStatus() == FXFA_LOADSTATUS_LOADING || m_pContext->GetLoadStatus() == FXFA_LOADSTATUS_CLOSING || XFA_PAGEVIEWEVENT_StopLayout != dwFlags) return; int nNewCount = m_pContext->GetPageCount(); if (nNewCount == m_pContext->GetOriginalPageCount()) return; CXFA_FFDocView* pXFADocView = m_pContext->GetXFADocView(); if (!pXFADocView) return; for (int iPageIter = 0; iPageIter < m_pContext->GetOriginalPageCount(); iPageIter++) { CPDFXFA_Page* pPage = (*m_pContext->GetXFAPageList())[iPageIter]; if (!pPage) continue; m_pContext->GetFormFillEnv()->RemovePageView(pPage); pPage->SetXFAPageView(pXFADocView->GetPageView(iPageIter)); } int flag = (nNewCount < m_pContext->GetOriginalPageCount()) ? FXFA_PAGEVIEWEVENT_POSTREMOVED : FXFA_PAGEVIEWEVENT_POSTADDED; int count = FXSYS_abs(nNewCount - m_pContext->GetOriginalPageCount()); m_pContext->SetOriginalPageCount(nNewCount); pFormFillEnv->PageEvent(count, flag); }
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; }
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; }
CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap, FXDIB_Format dest_format, int dest_width, int dest_height, const FX_RECT& clip_rect, const CFX_DIBSource* pSrcBitmap, int flags) { m_State = 0; m_DestFormat = dest_format; m_DestBpp = dest_format & 0xff; m_SrcBpp = pSrcBitmap->GetFormat() & 0xff; m_bHasAlpha = pSrcBitmap->GetFormat() & 0x200; m_pSrcPalette = pSrcBitmap->GetPalette(); m_pDestBitmap = pDestBitmap; m_DestWidth = dest_width; m_DestHeight = dest_height; m_pInterBuf = NULL; m_pExtraAlphaBuf = NULL; m_pDestMaskScanline = NULL; m_DestClip = clip_rect; FX_DWORD size = clip_rect.Width(); if (size && m_DestBpp > (int)(INT_MAX / size)) { return; } size *= m_DestBpp; if (size > INT_MAX - 31) { return; } size += 31; size = size / 32 * 4; m_pDestScanline = FX_AllocNL(FX_BYTE, size); if (m_pDestScanline == NULL) { return; } if (dest_format == FXDIB_Rgb32) { FXSYS_memset8(m_pDestScanline, 255, size); } m_InterPitch = (m_DestClip.Width() * m_DestBpp + 31) / 32 * 4; m_ExtraMaskPitch = (m_DestClip.Width() * 8 + 31) / 32 * 4; m_pInterBuf = NULL; m_pSource = pSrcBitmap; m_SrcWidth = pSrcBitmap->GetWidth(); m_SrcHeight = pSrcBitmap->GetHeight(); m_SrcPitch = (m_SrcWidth * m_SrcBpp + 31) / 32 * 4; if ((flags & FXDIB_NOSMOOTH) == 0) { FX_BOOL bInterpol = flags & FXDIB_INTERPOL || flags & FXDIB_BICUBIC_INTERPOL; if (!bInterpol && FXSYS_abs(dest_width) != 0 && FXSYS_abs(dest_height) < m_SrcWidth * m_SrcHeight * 8 / FXSYS_abs(dest_width)) { flags = FXDIB_INTERPOL; } m_Flags = flags; } else { m_Flags = FXDIB_NOSMOOTH; if (flags & FXDIB_DOWNSAMPLE) { m_Flags |= FXDIB_DOWNSAMPLE; } } double scale_x = FXSYS_Div((FX_FLOAT)(m_SrcWidth), (FX_FLOAT)(m_DestWidth)); double scale_y = FXSYS_Div((FX_FLOAT)(m_SrcHeight), (FX_FLOAT)(m_DestHeight)); double base_x = m_DestWidth > 0 ? 0.0f : (FX_FLOAT)(m_DestWidth); double base_y = m_DestHeight > 0 ? 0.0f : (FX_FLOAT)(m_DestHeight); double src_left = FXSYS_Mul(scale_x, (FX_FLOAT)(clip_rect.left) + base_x); double src_right = FXSYS_Mul(scale_x, (FX_FLOAT)(clip_rect.right) + base_x); double src_top = FXSYS_Mul(scale_y, (FX_FLOAT)(clip_rect.top) + base_y); double src_bottom = FXSYS_Mul(scale_y, (FX_FLOAT)(clip_rect.bottom) + base_y); if (src_left > src_right) { double temp = src_left; src_left = src_right; src_right = temp; } if (src_top > src_bottom) { double temp = src_top; src_top = src_bottom; src_bottom = temp; } m_SrcClip.left = (int)FXSYS_floor((FX_FLOAT)src_left); m_SrcClip.right = (int)FXSYS_ceil((FX_FLOAT)src_right); m_SrcClip.top = (int)FXSYS_floor((FX_FLOAT)src_top); m_SrcClip.bottom = (int)FXSYS_ceil((FX_FLOAT)src_bottom); FX_RECT src_rect(0, 0, m_SrcWidth, m_SrcHeight); m_SrcClip.Intersect(src_rect); if (m_SrcBpp == 1) { if (m_DestBpp == 8) { m_TransMethod = 1; } else { m_TransMethod = 2; } } else if (m_SrcBpp == 8) { if (m_DestBpp == 8) { if (!m_bHasAlpha) { m_TransMethod = 3; } else { m_TransMethod = 4; } } else { if (!m_bHasAlpha) { m_TransMethod = 5; } else { m_TransMethod = 6; } } } else { if (!m_bHasAlpha) { m_TransMethod = 7; } else { m_TransMethod = 8; } } }
int32_t CFDE_TxtEdtEngine::MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, FX_BOOL bShift, FX_BOOL bCtrl) { if (IsLocked()) { return 0; } if (m_PagePtrArray.GetSize() <= m_nCaretPage) { return 0; } FX_BOOL bSelChange = FALSE; if (IsSelect()) { ClearSelection(); bSelChange = TRUE; } if (bShift) { if (m_nAnchorPos == -1) { m_nAnchorPos = m_nCaret; } } else { m_nAnchorPos = -1; } FX_BOOL bVertical = m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical; switch (eMoveCaret) { case MC_Left: { if (bVertical) { CFX_PointF ptCaret; if (MoveUp(ptCaret)) { UpdateCaretIndex(ptCaret); } } else { FX_BOOL bBefore = TRUE; int32_t nIndex = MoveBackward(bBefore); if (nIndex >= 0) { UpdateCaretRect(nIndex, bBefore); } } } break; case MC_Right: { if (bVertical) { CFX_PointF ptCaret; if (MoveDown(ptCaret)) { UpdateCaretIndex(ptCaret); } } else { FX_BOOL bBefore = TRUE; int32_t nIndex = MoveForward(bBefore); if (nIndex >= 0) { UpdateCaretRect(nIndex, bBefore); } } } break; case MC_Up: { if (bVertical) { FX_BOOL bBefore = TRUE; int32_t nIndex = MoveBackward(bBefore); if (nIndex >= 0) { UpdateCaretRect(nIndex, bBefore); } } else { CFX_PointF ptCaret; if (MoveUp(ptCaret)) { UpdateCaretIndex(ptCaret); } } } break; case MC_Down: { if (bVertical) { FX_BOOL bBefore = TRUE; int32_t nIndex = MoveForward(bBefore); if (nIndex >= 0) { UpdateCaretRect(nIndex, bBefore); } } else { CFX_PointF ptCaret; if (MoveDown(ptCaret)) { UpdateCaretIndex(ptCaret); } } } break; case MC_WordBackward: break; case MC_WordForward: break; case MC_LineStart: MoveLineStart(); break; case MC_LineEnd: MoveLineEnd(); break; case MC_ParagStart: MoveParagStart(); break; case MC_ParagEnd: MoveParagEnd(); break; case MC_PageDown: break; case MC_PageUp: break; case MC_Home: MoveHome(); break; case MC_End: MoveEnd(); break; default: break; } if (bShift && m_nAnchorPos != -1 && (m_nAnchorPos != m_nCaret)) { AddSelRange(std::min(m_nAnchorPos, m_nCaret), FXSYS_abs(m_nAnchorPos - m_nCaret)); m_Param.pEventSink->On_SelChanged(this); } if (bSelChange) { m_Param.pEventSink->On_SelChanged(this); } return m_nCaret; }
FX_BOOL CPDF_TextStream::ProcessObject(const CPDF_TextObject* pObj, FX_BOOL bFirstLine) { CPDF_Font* pFont = pObj->GetFont(); CFX_AffineMatrix matrix; pObj->GetTextMatrix(&matrix); int item_index = 0; if (m_pLastObj) { int result = FPDFText_ProcessInterObj(m_pLastObj, pObj); if (result == 2) { int len = m_Buffer.GetLength(); if (len && m_bUseLF && m_Buffer.GetBuffer()[len - 1] == L'-') { m_Buffer.Delete(len - 1, 1); if (m_pObjArray) { m_pObjArray->RemoveAt((len - 1) * 2, 2); } } else { if (bFirstLine) { return TRUE; } if (m_bUseLF) { m_Buffer.AppendChar(L'\r'); m_Buffer.AppendChar(L'\n'); if (m_pObjArray) { for (int i = 0; i < 4; i ++) { m_pObjArray->Add(NULL); } } } else { m_Buffer.AppendChar(' '); if (m_pObjArray) { m_pObjArray->Add(NULL); m_pObjArray->Add(NULL); } } } } else if (result == 1) { m_Buffer.AppendChar(L' '); if (m_pObjArray) { m_pObjArray->Add(NULL); m_pObjArray->Add(NULL); } } else if (result == -1) { m_pLastObj = pObj; return FALSE; } else if (result == 3) { item_index = 1; } } m_pLastObj = pObj; int nItems = pObj->CountItems(); FX_FLOAT Ignorekerning = 0; for(int i = 1; i < nItems - 1; i += 2) { CPDF_TextObjectItem item; pObj->GetItemInfo(i, &item); if (item.m_CharCode == (FX_DWORD) - 1) { if(i == 1) { Ignorekerning = item.m_OriginX; } else if(Ignorekerning > item.m_OriginX) { Ignorekerning = item.m_OriginX; } } else { Ignorekerning = 0; break; } } FX_FLOAT spacing = 0; for (; item_index < nItems; item_index ++) { CPDF_TextObjectItem item; pObj->GetItemInfo(item_index, &item); if (item.m_CharCode == (FX_DWORD) - 1) { CFX_WideString wstr = m_Buffer.GetWideString(); if (wstr.IsEmpty() || wstr.GetAt(wstr.GetLength() - 1) == L' ') { continue; } FX_FLOAT fontsize_h = pObj->m_TextState.GetFontSizeH(); spacing = -fontsize_h * (item.m_OriginX - Ignorekerning) / 1000; continue; } FX_FLOAT charSpace = pObj->m_TextState.GetObject()->m_CharSpace; if(nItems > 3 && !spacing) { charSpace = 0; } if((spacing || charSpace) && item_index > 0) { int last_width = 0; FX_FLOAT fontsize_h = pObj->m_TextState.GetFontSizeH(); FX_DWORD space_charcode = pFont->CharCodeFromUnicode(' '); FX_FLOAT threshold = 0; if (space_charcode != -1) { threshold = fontsize_h * pFont->GetCharWidthF(space_charcode) / 1000 ; } if(threshold > fontsize_h / 3) { threshold = 0; } else { threshold /= 2; } if (threshold == 0) { threshold = fontsize_h; int this_width = FXSYS_abs(GetCharWidth(item.m_CharCode, pFont)); threshold = this_width > last_width ? (FX_FLOAT)this_width : (FX_FLOAT)last_width; int nDivide = 6; if (threshold < 300) { nDivide = 2; } else if (threshold < 500) { nDivide = 4; } else if (threshold < 700) { nDivide = 5; } threshold = threshold / nDivide; threshold = fontsize_h * threshold / 1000; } if(charSpace > 0.001) { spacing += matrix.TransformDistance(charSpace); } else if(charSpace < -0.001) { spacing -= matrix.TransformDistance(FXSYS_fabs(charSpace)); } if (threshold && (spacing && spacing >= threshold) ) { m_Buffer.AppendChar(L' '); if (m_pObjArray) { m_pObjArray->Add(NULL); m_pObjArray->Add(NULL); } } if (item.m_CharCode == (FX_DWORD) - 1) { continue; } spacing = 0; } CFX_WideString unicode_str = pFont->UnicodeFromCharCode(item.m_CharCode); if (unicode_str.IsEmpty()) { m_Buffer.AppendChar((FX_WCHAR)item.m_CharCode); if (m_pObjArray) { m_pObjArray->Add((void*)pObj); m_pObjArray->Add((void*)(FX_INTPTR)item_index); } } else { m_Buffer << unicode_str; if (m_pObjArray) { for (int i = 0; i < unicode_str.GetLength(); i ++) { m_pObjArray->Add((void*)pObj); m_pObjArray->Add((void*)(FX_INTPTR)item_index); } } } } return FALSE; }