Ejemplo n.º 1
0
void CFGAS_FontMgr::RegisterFace(FXFT_Face pFace,
                                 const CFX_WideString* pFaceName) {
  if ((pFace->face_flags & FT_FACE_FLAG_SCALABLE) == 0)
    return;

  std::unique_ptr<CFX_FontDescriptor> pFont(new CFX_FontDescriptor);
  pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0;
  pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0;
  pFont->m_dwFontStyles |= GetFlags(pFace);

  std::vector<uint16_t> charsets = GetCharsets(pFace);
  GetUSBCSB(pFace, pFont->m_dwUsb, pFont->m_dwCsb);

  FT_ULong dwTag;
  FT_ENC_TAG(dwTag, 'n', 'a', 'm', 'e');

  std::vector<uint8_t> table;
  unsigned long nLength = 0;
  unsigned int error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, nullptr, &nLength);
  if (error == 0 && nLength != 0) {
    table.resize(nLength);
    if (FXFT_Load_Sfnt_Table(pFace, dwTag, 0, table.data(), nullptr))
      table.clear();
  }
  GetNames(table.empty() ? nullptr : table.data(), pFont->m_wsFamilyNames);

  pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode());
  pFont->m_wsFaceName =
      pFaceName ? *pFaceName
                : CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace));
  pFont->m_nFaceIndex = pFace->face_index;

  m_InstalledFonts.Add(pFont.release());
}
Ejemplo n.º 2
0
QStringList FMPDFFontExtractor::list()
{
	if(!document)
		return mfont.keys();
	
	if(cachedList)
		return mfont.keys();
	else
		cachedList = true;
	
	PoDoFo::TCIVecObjects objIt( document->GetObjects().begin() );
	PoDoFo::PdfName pType("Type");
	PoDoFo::PdfName pSubtype("Subtype");
	PoDoFo::PdfName pFont("Font");
	PoDoFo::PdfName pType1("Type1");
	PoDoFo::PdfName pTrueType("TrueType");
	PoDoFo::PdfName pFontDescriptor( "FontDescriptor" );
	PoDoFo::PdfName pFontFile( "FontFile" );
	PoDoFo::PdfName pFontFile3( "FontFile3" );
	PoDoFo::PdfName pFontName( "FontName" );
	
	while( objIt != document->GetObjects().end() )
	{
		PoDoFo::PdfObject* obj(*objIt);	
		if ( obj->IsDictionary() )
		{
			if(obj->GetIndirectKey(pType))
			{
				PoDoFo::PdfName type( obj->GetIndirectKey(pType)->GetName() );
				if(type == pFont)
				{
					if(obj->GetIndirectKey( pSubtype ))
					{
						PoDoFo::PdfName subtype ( obj->GetIndirectKey( pSubtype )->GetName() );
						if ((subtype == pType1) ||  (subtype == pTrueType))
						{
							PoDoFo::PdfObject * fontDescriptor ( obj->GetIndirectKey ( pFontDescriptor ) );
							if (fontDescriptor )
							{
								bool hasFile(false);
								PoDoFo::PdfObject * fontFile ( fontDescriptor->GetIndirectKey ( pFontFile ) );
								if ( !fontFile )
								{
									fontFile = fontDescriptor->GetIndirectKey(pFontFile3) ;
									if ( !fontFile )
										qWarning ( "Font not embedded not supported yet" );
									else
										hasFile = true;
			
								}
								else
									hasFile = true;
								if(hasFile)
								{
									PoDoFo::PdfName fontName(fontDescriptor->GetIndirectKey(pFontName)->GetName());
									if(1)
									{
										QString n(QString::fromStdString( fontName.GetName() ));
										mfont[n] = fontFile;
										// we know naming it pfb is wrong 
										mType[n] = (subtype == pType1) ? "pfb" : "ttf";
									}
									else
										qDebug()<<"Error: no /FontName key";
								}
							}
		
						}
					}
				}
			}
		}
		objIt++;
	}
	
	return mfont.keys();
	
}