* add a new export format to get the vector icon data as C source
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22953 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
647c0044ff
commit
f688476148
@ -44,6 +44,7 @@
|
||||
#include "SavePanel.h"
|
||||
#include "ShapeContainer.h"
|
||||
#include "SimpleFileSaver.h"
|
||||
#include "SourceExporter.h"
|
||||
#include "SVGExporter.h"
|
||||
#include "SVGImporter.h"
|
||||
|
||||
@ -532,6 +533,9 @@ IconEditorApp::_CreateSaver(const entry_ref& ref, uint32 exportMode)
|
||||
case EXPORT_MODE_ICON_RDEF:
|
||||
saver = new SimpleFileSaver(new RDefExporter(), ref);
|
||||
break;
|
||||
case EXPORT_MODE_ICON_SOURCE:
|
||||
saver = new SimpleFileSaver(new SourceExporter(), ref);
|
||||
break;
|
||||
|
||||
case EXPORT_MODE_BITMAP:
|
||||
saver = new SimpleFileSaver(new BitmapExporter(64), ref);
|
||||
|
@ -40,6 +40,7 @@ enum {
|
||||
EXPORT_MODE_ICON_ATTR,
|
||||
EXPORT_MODE_ICON_MIME_ATTR,
|
||||
EXPORT_MODE_ICON_RDEF,
|
||||
EXPORT_MODE_ICON_SOURCE,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
|
@ -222,6 +222,7 @@ Application Icon-O-Matic :
|
||||
# import_export/flat_icon
|
||||
FlatIconExporter.cpp
|
||||
RDefExporter.cpp
|
||||
SourceExporter.cpp
|
||||
|
||||
# import_export/message
|
||||
MessageExporter.cpp
|
||||
|
@ -243,6 +243,9 @@ SavePanel::SetExportMode(int32 mode)
|
||||
case EXPORT_MODE_ICON_RDEF:
|
||||
fRDefMI->SetMarked(true);
|
||||
break;
|
||||
case EXPORT_MODE_ICON_SOURCE:
|
||||
fSourceMI->SetMarked(true);
|
||||
break;
|
||||
}
|
||||
|
||||
if (mode != EXPORT_MODE_MESSAGE)
|
||||
@ -386,6 +389,10 @@ SavePanel::_BuildMenu()
|
||||
EXPORT_MODE_ICON_RDEF);
|
||||
fFormatM->AddItem(fRDefMI);
|
||||
|
||||
fSourceMI = new SaveItem("HVIF Source Code", new BMessage(MSG_FORMAT),
|
||||
EXPORT_MODE_ICON_SOURCE);
|
||||
fFormatM->AddItem(fSourceMI);
|
||||
|
||||
fFormatM->AddSeparatorItem();
|
||||
|
||||
fSVGMI = new SaveItem("SVG", new BMessage(MSG_FORMAT),
|
||||
|
@ -75,6 +75,7 @@ class SavePanel : public BFilePanel,
|
||||
SaveItem* fNativeMI;
|
||||
SaveItem* fHVIFMI;
|
||||
SaveItem* fRDefMI;
|
||||
SaveItem* fSourceMI;
|
||||
SaveItem* fSVGMI;
|
||||
SaveItem* fBitmapMI;
|
||||
SaveItem* fBitmapSetMI;
|
||||
|
122
src/apps/icon-o-matic/import_export/flat_icon/SourceExporter.cpp
Normal file
122
src/apps/icon-o-matic/import_export/flat_icon/SourceExporter.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright 2006-2007, Haiku. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Stephan Aßmus <superstippi@gmx.de>
|
||||
*/
|
||||
|
||||
#include "SourceExporter.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <DataIO.h>
|
||||
|
||||
// constructor
|
||||
SourceExporter::SourceExporter()
|
||||
: FlatIconExporter()
|
||||
{
|
||||
}
|
||||
|
||||
// destructor
|
||||
SourceExporter::~SourceExporter()
|
||||
{
|
||||
}
|
||||
|
||||
// Export
|
||||
status_t
|
||||
SourceExporter::Export(const Icon* icon, BPositionIO* stream)
|
||||
{
|
||||
BMallocIO buffer;
|
||||
status_t ret = FlatIconExporter::Export(icon, &buffer);
|
||||
if (ret < B_OK)
|
||||
return ret;
|
||||
|
||||
return _Export((const uint8*)buffer.Buffer(), buffer.BufferLength(),
|
||||
stream);
|
||||
}
|
||||
|
||||
// MIMEType
|
||||
const char*
|
||||
SourceExporter::MIMEType()
|
||||
{
|
||||
return "text/x-source-code";
|
||||
}
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
// _Export
|
||||
status_t
|
||||
SourceExporter::_Export(const uint8* source, size_t sourceSize,
|
||||
BPositionIO* stream) const
|
||||
{
|
||||
char buffer[2048];
|
||||
// write header
|
||||
sprintf(buffer, "\nconst unsigned char kIconName = {\n");
|
||||
size_t size = strlen(buffer);
|
||||
|
||||
ssize_t written = stream->Write(buffer, size);
|
||||
if (written < 0)
|
||||
return (status_t)written;
|
||||
if (written < (ssize_t)size)
|
||||
return B_ERROR;
|
||||
|
||||
status_t ret = B_OK;
|
||||
const uint8* b = source;
|
||||
|
||||
// print one line (12 values)
|
||||
while (sourceSize > 12) {
|
||||
sprintf(buffer, " 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x"
|
||||
", 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x"
|
||||
", 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,\n",
|
||||
b[0], b[1], b[2], b[3],
|
||||
b[4], b[5], b[6], b[7],
|
||||
b[8], b[9], b[10], b[11]);
|
||||
|
||||
size = strlen(buffer);
|
||||
written = stream->Write(buffer, size);
|
||||
if (written != (ssize_t)size) {
|
||||
if (written >= 0)
|
||||
ret = B_ERROR;
|
||||
else
|
||||
ret = (status_t)written;
|
||||
break;
|
||||
}
|
||||
|
||||
sourceSize -= 12;
|
||||
b += 12;
|
||||
}
|
||||
// last line (up to 12 values)
|
||||
if (ret >= B_OK && sourceSize > 0) {
|
||||
for (size_t i = 0; i < sourceSize; i++) {
|
||||
if (i == 0)
|
||||
sprintf(buffer, " 0x%.2x", b[i]);
|
||||
else
|
||||
sprintf(buffer, ", 0x%.2x", b[i]);
|
||||
size = strlen(buffer);
|
||||
written = stream->Write(buffer, size);
|
||||
if (written != (ssize_t)size) {
|
||||
if (written >= 0)
|
||||
ret = B_ERROR;
|
||||
else
|
||||
ret = (status_t)written;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ret >= B_OK) {
|
||||
// finish
|
||||
sprintf(buffer, "\n};\n");
|
||||
size = strlen(buffer);
|
||||
written = stream->Write(buffer, size);
|
||||
if (written != (ssize_t)size) {
|
||||
if (written >= 0)
|
||||
ret = B_ERROR;
|
||||
else
|
||||
ret = (status_t)written;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2006-2007, Haiku. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Stephan Aßmus <superstippi@gmx.de>
|
||||
*/
|
||||
|
||||
#ifndef SOURCE_EXPORTER_H
|
||||
#define SOURCE_EXPORTER_H
|
||||
|
||||
#include "FlatIconExporter.h"
|
||||
|
||||
class SourceExporter : public FlatIconExporter {
|
||||
public:
|
||||
SourceExporter();
|
||||
virtual ~SourceExporter();
|
||||
|
||||
// FlatIconExporter interface
|
||||
virtual status_t Export(const Icon* icon,
|
||||
BPositionIO* stream);
|
||||
|
||||
virtual const char* MIMEType();
|
||||
|
||||
private:
|
||||
status_t _Export(const uint8* source,
|
||||
size_t sourceSize,
|
||||
BPositionIO* stream) const;
|
||||
};
|
||||
|
||||
#endif // SOURCE_EXPORTER_H
|
Loading…
Reference in New Issue
Block a user