Exemple #1
0
void CFX_FolderFontInfo::ScanFile(CFX_ByteString& path)
{
    FXSYS_FILE* pFile = FXSYS_fopen(path, "rb");
    if (pFile == NULL) {
        return;
    }
    FXSYS_fseek(pFile, 0, FXSYS_SEEK_END);
    FX_DWORD filesize = FXSYS_ftell(pFile);
    FX_BYTE buffer[16];
    FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET);
    size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile);
    if (GET_TT_LONG(buffer) == 0x74746366) {
        FX_DWORD nFaces = GET_TT_LONG(buffer + 8);
        FX_LPBYTE offsets = FX_Alloc(FX_BYTE, nFaces * 4);
        if (!offsets) {
            FXSYS_fclose(pFile);
            return;
        }
        readCnt = FXSYS_fread(offsets, nFaces * 4, 1, pFile);
        for (FX_DWORD i = 0; i < nFaces; i ++) {
            FX_LPBYTE p = offsets + i * 4;
            ReportFace(path, pFile, filesize, GET_TT_LONG(p));
        }
        FX_Free(offsets);
    } else {
        ReportFace(path, pFile, filesize, 0);
    }
    FXSYS_fclose(pFile);
}
FX_BOOL FXFC_LoadFile(FX_LPVOID p, FX_LPCSTR name, FX_LPBYTE& pBuffer, FX_DWORD& size)
{
    FXFC_PACKAGE* pPackage = (FXFC_PACKAGE*)p;
    FXSYS_fseek(pPackage->m_pFile, pPackage->m_IndexOffset, FXSYS_SEEK_SET);
    FX_BYTE buf[128];
    for (int i = 0; i < pPackage->m_nFiles; i ++) {
        FXSYS_fread(buf, pPackage->m_IndexSize, 1, pPackage->m_pFile);
        if (FXSYS_stricmp((FX_LPCSTR)buf, name) == 0) {
            FX_DWORD offset = *(FX_DWORD*)&buf[64];
            size = *(FX_DWORD*)&buf[68];
            pBuffer = FX_Alloc(FX_BYTE, size);
            FXSYS_fseek(pPackage->m_pFile, offset, FXSYS_SEEK_SET);
            FXSYS_fread(pBuffer, size, 1, pPackage->m_pFile);
            if (buf[72]) {
                FX_DWORD orig_size;
                FX_LPBYTE comp_buf = pBuffer;
                CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode(FALSE, comp_buf, size, FALSE,
                        0, 0, 0, 0, 0, pBuffer, orig_size);
                FX_Free(comp_buf);
                size = orig_size;
            }
            return TRUE;
        }
    }
    return FALSE;
}
size_t CFXCRT_FileAccess_CRT::Read(void* pBuffer, size_t szBuffer)
{
    if (!m_hFile) {
        return 0;
    }
    return FXSYS_fread(pBuffer, 1, szBuffer, m_hFile);
}
size_t CFXCRT_FileAccess_CRT::ReadPos(void* pBuffer, size_t szBuffer, FX_FILESIZE pos)
{
    if (!m_hFile) {
        return (FX_FILESIZE) - 1;
    }
    FXSYS_fseek(m_hFile, pos, FXSYS_SEEK_SET);
    return FXSYS_fread(pBuffer, 1, szBuffer, m_hFile);
}
Exemple #5
0
static CFX_ByteString _FPDF_ReadStringFromFile(FXSYS_FILE* pFile, FX_DWORD size)
{
    CFX_ByteString buffer;
    if (!FXSYS_fread(buffer.GetBuffer(size), size, 1, pFile)) {
        return CFX_ByteString();
    }
    buffer.ReleaseBuffer(size);
    return buffer;
}
void CFX_FolderFontInfo::ScanFile(CFX_ByteString& path)
{
    FXSYS_FILE* pFile = FXSYS_fopen(path, "rb");
    if (pFile == NULL) {
        return;
    }
    FXSYS_fseek(pFile, 0, FXSYS_SEEK_END);
    FX_DWORD filesize = FXSYS_ftell(pFile);
    uint8_t buffer[16];
    FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET);
    size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile);
    if (readCnt != 1) {
        FXSYS_fclose(pFile);
        return;
    }

    if (GET_TT_LONG(buffer) == 0x74746366) {
        FX_DWORD nFaces = GET_TT_LONG(buffer + 8);
        if (nFaces > std::numeric_limits<FX_DWORD>::max() / 4) {
            FXSYS_fclose(pFile);
            return;
        }
        FX_DWORD face_bytes = nFaces * 4;
        uint8_t* offsets = FX_Alloc(uint8_t, face_bytes);
        readCnt = FXSYS_fread(offsets, face_bytes, 1, pFile);
        if (readCnt != face_bytes) {
            FX_Free(offsets);
            FXSYS_fclose(pFile);
            return;
        }
        for (FX_DWORD i = 0; i < nFaces; i ++) {
            uint8_t* p = offsets + i * 4;
            ReportFace(path, pFile, filesize, GET_TT_LONG(p));
        }
        FX_Free(offsets);
    } else {
        ReportFace(path, pFile, filesize, 0);
    }
    FXSYS_fclose(pFile);
}
FX_LPVOID FXFC_LoadPackage(FX_LPCSTR name)
{
    FXSYS_FILE* file = FXSYS_fopen(name, (FX_LPCSTR)"rb");
    if (file == NULL) {
        return NULL;
    }
    FX_BYTE buf[256];
    FXSYS_fread(buf, 1, 20, file);
    if (*(FX_DWORD*)buf != 0x43465846) {
        FXSYS_fclose(file);
        return NULL;
    }
    FXFC_PACKAGE* pPackage = FX_Alloc(FXFC_PACKAGE, 1);
    pPackage->m_pFile = file;
    pPackage->m_nFiles = *(int*)(buf + 8);
    pPackage->m_IndexSize = *(int*)(buf + 12);
    pPackage->m_IndexOffset = *(int*)(buf + 16);
    return pPackage;
}
Exemple #8
0
FX_DWORD CFX_FolderFontInfo::GetFontData(void* hFont, FX_DWORD table, FX_LPBYTE buffer, FX_DWORD size)
{
    if (hFont == NULL) {
        return 0;
    }
    CFontFaceInfo* pFont = (CFontFaceInfo*)hFont;
    FXSYS_FILE* pFile = NULL;
    if (size > 0) {
        pFile = FXSYS_fopen(pFont->m_FilePath, "rb");
        if (pFile == NULL) {
            return 0;
        }
    }
    FX_DWORD datasize = 0;
    FX_DWORD offset;
    if (table == 0)	{
        datasize = pFont->m_FontOffset ? 0 : pFont->m_FileSize;
        offset = 0;
    } else if (table == 0x74746366)	{
        datasize = pFont->m_FontOffset ? pFont->m_FileSize : 0;
        offset = 0;
    } else {
        FX_DWORD nTables = pFont->m_FontTables.GetLength() / 16;
        for (FX_DWORD i = 0; i < nTables; i ++) {
            FX_LPCBYTE p = (FX_LPCBYTE)pFont->m_FontTables + i * 16;
            if (GET_TT_LONG(p) == table) {
                offset = GET_TT_LONG(p + 8);
                datasize = GET_TT_LONG(p + 12);
            }
        }
    }
    if (datasize && size >= datasize && pFile) {
        FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET);
        size_t readCnt = FXSYS_fread(buffer, datasize, 1, pFile);
    }
    if (pFile) {
        FXSYS_fclose(pFile);
    }
    return datasize;
}
Exemple #9
0
void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path, FXSYS_FILE* pFile, FX_DWORD filesize, FX_DWORD offset)
{
    FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET);
    char buffer[16];
    if (!FXSYS_fread(buffer, 12, 1, pFile)) {
        return;
    }
    FX_DWORD nTables = GET_TT_SHORT(buffer + 4);
    CFX_ByteString tables = _FPDF_ReadStringFromFile(pFile, nTables * 16);
    CFX_ByteString names = _FPDF_LoadTableFromTT(pFile, tables, nTables, 0x6e616d65);
    CFX_ByteString facename = _FPDF_GetNameFromTT(names, 1);
    CFX_ByteString style = _FPDF_GetNameFromTT(names, 2);
    if (style != "Regular") {
        facename += " " + style;
    }
    FX_LPVOID p;
    if (m_FontList.Lookup(facename, p)) {
        return;
    }
    CFontFaceInfo* pInfo = FX_NEW CFontFaceInfo;
    if (!pInfo) {
        return;
    }
    pInfo->m_FilePath = path;
    pInfo->m_FaceName = facename;
    pInfo->m_FontTables = tables;
    pInfo->m_FontOffset = offset;
    pInfo->m_FileSize = filesize;
    pInfo->m_Charsets = 0;
    CFX_ByteString os2 = _FPDF_LoadTableFromTT(pFile, tables, nTables, 0x4f532f32);
    if (os2.GetLength() >= 86) {
        FX_LPCBYTE p = (FX_LPCBYTE)os2 + 78;
        FX_DWORD codepages = GET_TT_LONG(p);
        if (codepages & (1 << 17)) {
            m_pMapper->AddInstalledFont(facename, FXFONT_SHIFTJIS_CHARSET);
            pInfo->m_Charsets |= CHARSET_FLAG_SHIFTJIS;
        }
        if (codepages & (1 << 18)) {
            m_pMapper->AddInstalledFont(facename, FXFONT_GB2312_CHARSET);
            pInfo->m_Charsets |= CHARSET_FLAG_GB;
        }
        if (codepages & (1 << 20)) {
            m_pMapper->AddInstalledFont(facename, FXFONT_CHINESEBIG5_CHARSET);
            pInfo->m_Charsets |= CHARSET_FLAG_BIG5;
        }
        if ((codepages & (1 << 19)) || (codepages & (1 << 21))) {
            m_pMapper->AddInstalledFont(facename, FXFONT_HANGEUL_CHARSET);
            pInfo->m_Charsets |= CHARSET_FLAG_KOREAN;
        }
        if (codepages & (1 << 31)) {
            m_pMapper->AddInstalledFont(facename, FXFONT_SYMBOL_CHARSET);
            pInfo->m_Charsets |= CHARSET_FLAG_SYMBOL;
        }
    }
    m_pMapper->AddInstalledFont(facename, FXFONT_ANSI_CHARSET);
    pInfo->m_Charsets |= CHARSET_FLAG_ANSI;
    pInfo->m_Styles = 0;
    if (style.Find(FX_BSTRC("Bold")) > -1) {
        pInfo->m_Styles |= FXFONT_BOLD;
    }
    if (style.Find(FX_BSTRC("Italic")) > -1 || style.Find(FX_BSTRC("Oblique")) > -1) {
        pInfo->m_Styles |= FXFONT_ITALIC;
    }
    if (facename.Find(FX_BSTRC("Serif")) > -1) {
        pInfo->m_Styles |= FXFONT_SERIF;
    }
    m_FontList.SetAt(facename, pInfo);
}