EStatusCode CFFDescendentFontWriter::WriteFont(	ObjectIDType inDecendentObjectID, 
														const std::string& inFontName,
														FreeTypeFaceWrapper& inFontInfo,
														const UIntAndGlyphEncodingInfoVector& inEncodedGlyphs,
														ObjectsContext* inObjectsContext,
														bool inEmbedFont)
{
	// reset embedded font object ID (and flag...to whether it was actually embedded or not, which may 
	// happen due to font embedding restrictions)
	mEmbeddedFontFileObjectID = 0;

	// Logically speaking, i shouldn't be getting to CID writing
	// if in type 1. at least, this is the current assumption, since
	// i don't intend to support type 1 CIDs, but just regular type 1s.
	// as such - fail if got here for type 1
	const char* fontType = inFontInfo.GetTypeString();
	if(strcmp(scType1,fontType) == 0)
	{
		TRACE_LOG1("CFFDescendentFontWriter::WriteFont, Exception. identified type1 font when writing CFF CID font, font name - %s. type 1 CIDs are not supported.",inFontName.substr(0, MAX_TRACE_SIZE - 200).c_str());
		return PDFHummus::eFailure;
	}

	if (inEmbedFont)
	{
		CFFEmbeddedFontWriter embeddedFontWriter;
		UIntAndGlyphEncodingInfoVector encodedGlyphs = inEncodedGlyphs;
		UIntVector orderedGlyphs;
		UShortVector cidMapping;

		// Gal: the following sort completely ruins everything.
		// the order of the glyphs should be maintained per the ENCODED characthers
		// which is how the input is recieved. IMPORTANT - the order is critical
		// for the success of the embedding, as the order determines the order of the glyphs
		// in the subset font and so their GID which MUST match the encoded char.
		//sort(encodedGlyphs.begin(), encodedGlyphs.end(), sEncodedGlypsSort);

		for (UIntAndGlyphEncodingInfoVector::const_iterator it = encodedGlyphs.begin();
			it != encodedGlyphs.end();
			++it)
		{
			orderedGlyphs.push_back(it->first);
			cidMapping.push_back(it->second.mEncodedCharacter);
		}
		EStatusCode status = embeddedFontWriter.WriteEmbeddedFont(inFontInfo,
			orderedGlyphs,
			scCIDFontType0C,
			inFontName,
			inObjectsContext,
			&cidMapping,
			mEmbeddedFontFileObjectID);
		if (status != PDFHummus::eSuccess)
			return status;
	}

	DescendentFontWriter descendentFontWriter;

	return descendentFontWriter.WriteFont(inDecendentObjectID,inFontName,inFontInfo,inEncodedGlyphs,inObjectsContext,this);
}
示例#2
0
EStatusCode CFFANSIFontWriter::WriteFont(	FreeTypeFaceWrapper& inFontInfo,
        WrittenFontRepresentation* inFontOccurrence,
        ObjectsContext* inObjectsContext)
{
    const char* postscriptFontName = FT_Get_Postscript_Name(inFontInfo);
    if(!postscriptFontName)
    {
        TRACE_LOG("CFFANSIFontWriter::WriteFont, unexpected failure. no postscript font name for font");
        return PDFHummus::eFailure;
    }
    std::string subsetFontName = inObjectsContext->GenerateSubsetFontPrefix() + scPlus + postscriptFontName;

    const char* fontType = inFontInfo.GetTypeString();

    // reset embedded font object ID (and flag...to whether it was actually embedded or not, which may
    // happen due to font embedding restrictions)
    mEmbeddedFontFileObjectID = 0;

    EStatusCode status;
    if(strcmp(scType1Type,fontType) == 0)
    {
        Type1ToCFFEmbeddedFontWriter embeddedFontWriter;

        status = embeddedFontWriter.WriteEmbeddedFont(inFontInfo,
                 inFontOccurrence->GetGlyphIDsAsOrderedVector(),
                 scType1C,
                 subsetFontName,
                 inObjectsContext,
                 mEmbeddedFontFileObjectID);
    }
    else if(strcmp(scCFF,fontType) == 0)
    {
        CFFEmbeddedFontWriter embeddedFontWriter;

        status = embeddedFontWriter.WriteEmbeddedFont(inFontInfo,
                 inFontOccurrence->GetGlyphIDsAsOrderedVector(),
                 scType1C,
                 subsetFontName,
                 inObjectsContext,
                 mEmbeddedFontFileObjectID);
    }
    else
    {

        TRACE_LOG("CFFANSIFontWriter::WriteFont, Exception, unfamilar font type for embedding representation");
        status = PDFHummus::eFailure;
    }
    if(status != PDFHummus::eSuccess)
        return status;

    ANSIFontWriter fontWriter;

    return fontWriter.WriteFont(inFontInfo,inFontOccurrence,inObjectsContext,this,subsetFontName);
}