1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: t -*- */
/* AbiSource
*
* Copyright (C) 2008 Firat Kiyak <firatkiyak@gmail.com>
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*/
#include <string>
#include "ut_types.h"
#include "ut_misc.h"
#include "pd_Document.h"
#include "fg_Graphic.h"
// Class definition include
#include "OXML_Image.h"
// Internal includes
#include "OXML_Types.h"
#include "OXML_Document.h"
OXML_Image::OXML_Image()
: m_data(NULL)
, m_graphic(NULL)
{
}
OXML_Image::~OXML_Image()
{
DELETEP(m_graphic);
}
void OXML_Image::setId(const std::string & imageId)
{
m_id = imageId;
}
void OXML_Image::setMimeType(const std::string & imageMimeType)
{
m_mimeType = imageMimeType;
}
void OXML_Image::setData(const UT_ByteBuf* imageData)
{
DELETEP(m_graphic);
m_data = imageData;
}
void OXML_Image::setGraphic(const FG_Graphic * graphic)
{
DELETEP(m_graphic);
m_data = NULL;
m_graphic = graphic;
}
UT_Error OXML_Image::serialize(IE_Exp_OpenXML* exporter)
{
std::string filename = m_id;
std::string mimeType;
if(m_graphic) {
mimeType = m_graphic->getMimeType();
}
else {
mimeType = m_mimeType;
}
if(mimeType.empty() || (mimeType == "image/png"))
{
filename += ".png";
}
else if(mimeType == "image/jpeg")
{
filename += ".jpg";
}
else if(mimeType == "image/svg+xml")
{
filename += ".svg";
}
else
{
UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
}
return exporter->writeImage(filename.c_str(), m_graphic ? m_graphic->getBuffer() : m_data);
}
UT_Error OXML_Image::addToPT(PD_Document * pDocument)
{
if (!pDocument->createDataItem(m_id.c_str(), false, m_graphic ? m_graphic->getBuffer() : m_data,
m_graphic ? m_graphic->getMimeType().c_str() : m_mimeType,
NULL))
{
UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
return UT_ERROR;
}
return UT_OK;
}
|