bool ScFace_ttf::EmbedFont(QByteArray &str) const { QByteArray bb; FtFace::RawData(bb); if (formatCode == ScFace::TYPE42) { //easy: str = bb; return true; } QString tmp4; QString tmp2 = ""; QString tmp3 = ""; int counter = 0; char *buf[50]; FT_ULong charcode; FT_UInt gindex; FT_Face face = ftFace(); if (!face) { return false; } const FT_Stream fts = face->stream; if (ftIOFunc(fts, 0L, NULL, 0)) { return(false); } str+="%!PS-TrueTypeFont\n"; str+="11 dict begin\n"; str+="/FontName /" + psName + " def\n"; str+="/Encoding /ISOLatin1Encoding where {pop ISOLatin1Encoding} {StandardEncoding} ifelse def\n"; str+="/PaintType 0 def\n/FontMatrix [1 0 0 1 0 0] def\n"; str+="/FontBBox ["+m_pdfFontBBox+"] def\n"; str+="/FontType 42 def\n"; str+="/FontInfo 8 dict dup begin\n"; str+="/FamilyName (" + psName + ") def\n"; str+="end readonly def\n"; unsigned char *tmp = new unsigned char[65535]; int length; char linebuf[80]; str += "/sfnts ["; int poso=0; do { int posi=0; length= fts->size - fts->pos; if (length > 65534) { length = 65534; } if (!ftIOFunc(fts, 0L, tmp, length)) { str+="\n<\n"; for (int j = 0; j < length; j++) { unsigned char u=tmp[posi]; linebuf[poso]=((u >> 4) & 15) + '0'; if (u>0x9f) linebuf[poso]+='a'-':'; ++poso; u&=15; linebuf[poso]=u + '0'; if (u>0x9) linebuf[poso]+='a'-':'; ++posi; ++poso; if (poso > 70) { linebuf[poso++]='\n'; linebuf[poso++]=0; str += linebuf; poso = 0; } } linebuf[poso++]=0; str += linebuf; poso = 0; str += "00\n>"; } else { sDebug(QObject::tr("Font %1 is broken (read stream), no embedding").arg(fontFile)); str += "\n] def\n"; status = qMax(status,ScFace::BROKENGLYPHS); return false; } } while (length==65534);
/** * tests magic words to determine the fontformat and preliminary fonttype */ void getFontFormat(FT_Face face, ScFace::FontFormat & fmt, ScFace::FontType & type) { static const char* T42_HEAD = "%!PS-TrueTypeFont"; static const char* T1_HEAD = "%!FontType1"; static const char* T1_ADOBE_HEAD = "%!PS-AdobeFont-1"; static const char* PSFONT_ADOBE2_HEAD = "%!PS-Adobe-2.0 Font"; static const char* PSFONT_ADOBE21_HEAD = "%!PS-Adobe-2.1 Font"; static const char* PSFONT_ADOBE3_HEAD = "%!PS-Adobe-3.0 Resource-Font"; static const int FONT_NO_ERROR = 0; const FT_Stream fts = face->stream; char buf[128]; fmt = ScFace::UNKNOWN_FORMAT; type = ScFace::UNKNOWN_TYPE; if (ftIOFunc(fts, 0L, reinterpret_cast<FT_Byte *>(buf), 128) == FONT_NO_ERROR) { if(strncmp(buf,T42_HEAD,strlen(T42_HEAD)) == 0) { fmt = ScFace::TYPE42; type = ScFace::TTF; } else if(strncmp(buf,T1_HEAD,strlen(T1_HEAD)) == 0 || strncmp(buf,T1_ADOBE_HEAD,strlen(T1_ADOBE_HEAD)) == 0) { fmt = ScFace::PFA; type = ScFace::TYPE1; } else if(strncmp(buf,PSFONT_ADOBE2_HEAD,strlen(PSFONT_ADOBE2_HEAD)) == 0 || strncmp(buf,PSFONT_ADOBE21_HEAD,strlen(PSFONT_ADOBE21_HEAD)) == 0 || strncmp(buf,PSFONT_ADOBE3_HEAD,strlen(PSFONT_ADOBE3_HEAD)) ==0) { // Type2(CFF), Type0(Composite/CID), Type 3, Type 14 etc would end here fmt = ScFace::PFA; type = ScFace::UNKNOWN_TYPE; } else if(buf[0] == '\200' && buf[1] == '\1') { fmt = ScFace::PFB; type = ScFace::TYPE1; } else if(buf[0] == '\0' && buf[1] == '\1' && buf[2] == '\0' && buf[3] == '\0') { fmt = ScFace::SFNT; type = ScFace::TTF; } else if(strncmp(buf,"true",4) == 0) { fmt = ScFace::SFNT; type = ScFace::TTF; } else if(strncmp(buf,"ttcf",4) == 0) { fmt = ScFace::TTCF; type = ScFace::OTF; } else if(strncmp(buf,"OTTO",4) == 0) { fmt = ScFace::SFNT; type = ScFace::OTF; } // missing: raw CFF } }