// ************************************************************************************************************
// Author: Marcin Załęczny
// Release Date: 2010-11-08
// Licence: The GNU Lesser General Public License, version 3.0 (LGPLv3)
// ************************************************************************************************************
#include "mzXpsResources.h"
#include "mzFileUtils.h"

CXpsBinaryData::CXpsBinaryData(CString filename, BYTE* imageBuffer, DWORD bufferSize) {
    this->setRealClassName(L"CXpsBinaryData");
    HANDLE heap = GetProcessHeap();
    
    this->filename = filename;
    this->imageBuffer = (BYTE*)HeapAlloc(heap, 0, bufferSize);
    memcpy(this->imageBuffer, imageBuffer, bufferSize);
    this->bufferSize = bufferSize;
}

CXpsBinaryData::~CXpsBinaryData() {
    HANDLE heap = GetProcessHeap();
    
    if (this->imageBuffer) {
        HeapFree(heap, 0, this->imageBuffer);
        this->imageBuffer = NULL;
    }
}

VOID CXpsBinaryData::save(CString dirname) {
    CString fname = this->filename;
    
    if (this->imageBuffer) {
        if (dirname != COMMON_EMPTY_STRING) {
            AddPathPart(dirname, CString(L"\\") + this->filename);
            fname = dirname;
        }
        WriteFile(fname, this->imageBuffer, this->bufferSize);
    }
}




CXpsMetadataThumbnail::CXpsMetadataThumbnail(CString filename, BYTE* imageBuffer, DWORD bufferSize)
    : CXpsBinaryData(filename, imageBuffer, bufferSize)
{
    this->setRealClassName(L"CXpsMetadataThumbnail");
}

CXpsMetadataThumbnail::~CXpsMetadataThumbnail() {
}





CXpsFontResource::CXpsFontResource(CString filename, BYTE* imageBuffer, DWORD bufferSize)
    : CXpsBinaryData(filename, imageBuffer, bufferSize)
{
    this->setRealClassName(L"CXpsFontResource");
}

CXpsFontResource::~CXpsFontResource() {
}
