PDFColorSpace PDFAnalyzer::getCSType(PdfObject* cs) { try { // colorspace is either a name or an array if (cs && cs->IsName()) { PdfName csName = cs->GetName(); if (csName == "DeviceGray") return CS_DeviceGray; else if (csName == "DeviceRGB") return CS_DeviceRGB; else if (csName == "DeviceCMYK") return CS_DeviceCMYK; } else if (cs && cs->IsArray()) { PdfArray csArr = cs->GetArray(); PdfObject csTypePdfName = csArr[0]; if (csTypePdfName.IsName()) { PdfName csTypeName = csTypePdfName.GetName(); if (csTypeName == "ICCBased") return CS_ICCBased; else if (csTypeName == "CalGray") return CS_CalGray; else if (csTypeName == "CalRGB") return CS_CalRGB; else if (csTypeName == "Lab") return CS_Lab; else if (csTypeName == "Indexed") { PdfObject base = cs->GetArray()[1]; PdfObject* pBase = &base; if (base.IsReference()) { pBase = cs->GetOwner()->GetObject(base.GetReference()); } pBase->SetOwner(cs->GetOwner()); return getCSType(pBase); } else if (csTypeName == "Separation") return CS_Separation; else if (csTypeName == "DeviceN") return CS_DeviceN; else if (csTypeName == "Pattern") return CS_Pattern; } } } catch (PdfError & e) { qDebug() << "Error in identifying the color type"; e.PrintErrorMsg(); return CS_Unknown; } return CS_Unknown; }
PDFFont PDFAnalyzer::getFontInfo(PdfObject* fontObj) { PDFFont currFont; PdfObject* subtype = fontObj->GetIndirectKey("Subtype"); if (subtype && subtype->IsName()) { PdfObject* fontDesc = fontObj->GetIndirectKey("FontDescriptor"); if (subtype->GetName() == "Type1") currFont.fontType = F_Type1; else if (subtype->GetName() == "MMType1") currFont.fontType = F_MMType1; else if (subtype->GetName() == "TrueType") currFont.fontType = F_TrueType; else if (subtype->GetName() == "Type3") { currFont.fontType = F_Type3; currFont.isEmbedded = true; fontDesc = NULL; } else if (subtype->GetName() == "Type0") { PdfObject* descendantFonts = fontObj->GetIndirectKey("DescendantFonts"); if (descendantFonts && descendantFonts->IsArray()) { PdfObject descendantFont = descendantFonts->GetArray()[0]; descendantFont.SetOwner(descendantFonts->GetOwner()); PdfObject* subtypeDescFont = descendantFont.GetIndirectKey("Subtype"); fontDesc = descendantFont.MustGetIndirectKey("FontDescriptor"); if (subtypeDescFont && subtypeDescFont->IsName()) { if (subtypeDescFont->GetName() == "CIDFontType0") currFont.fontType = F_CIDFontType0; else if (subtypeDescFont->GetName() == "CIDFontType2") currFont.fontType = F_CIDFontType2; } } } if (fontDesc) { PdfObject* fontFile = fontDesc->GetIndirectKey("FontFile"); PdfObject* fontFile2 = fontDesc->GetIndirectKey("FontFile2"); PdfObject* fontFile3 = fontDesc->GetIndirectKey("FontFile3"); if (fontFile && fontFile->HasStream()) currFont.isEmbedded = true; if (fontFile2 && fontFile2->HasStream()) currFont.isEmbedded = true; if (fontFile3 && fontFile3->HasStream()) { currFont.isEmbedded = true; PdfObject* ff3Subtype = fontFile3->GetIndirectKey("Subtype"); if (ff3Subtype && ff3Subtype->IsName() && ff3Subtype->GetName() == "OpenType") currFont.isOpenType = true; } } } return currFont; }
PdfObject* PdfVecObjects::CreateObject( const PdfVariant & rVariant ) { PdfReference ref = this->GetNextFreeObject(); PdfObject* pObj = new PdfObject( ref, rVariant ); pObj->SetOwner( this ); this->push_back( pObj ); return pObj; }
PdfObject* PdfVecObjects::CreateObject( const char* pszType ) { PdfReference ref = this->GetNextFreeObject(); PdfObject* pObj = new PdfObject( ref, pszType ); pObj->SetOwner( this ); this->push_back( pObj ); return pObj; }