commit 9fe81392d4eb536d909702dd65853f43386eacf7 Author: BlubbFish Date: Thu Mar 9 21:27:36 2017 +0000 svgb hinzugefügt diff --git a/svgb.sln b/svgb.sln new file mode 100644 index 0000000..bf8538d --- /dev/null +++ b/svgb.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "svgb", "svgb\svgb.csproj", "{EF378B10-B9FA-4B0F-ADA9-73E386B690A9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EF378B10-B9FA-4B0F-ADA9-73E386B690A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EF378B10-B9FA-4B0F-ADA9-73E386B690A9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EF378B10-B9FA-4B0F-ADA9-73E386B690A9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EF378B10-B9FA-4B0F-ADA9-73E386B690A9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/svgb/Program.cs b/svgb/Program.cs new file mode 100644 index 0000000..b94573a --- /dev/null +++ b/svgb/Program.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; + +namespace svgb +{ + class Program + { + public static int SVGB_EXIT_OK = 0; + public static int SVGB_EXIT_USAGE = 1; + public static int SVGB_EXIT_ERROR = 2; + public static int SVGB_EXIT_UNSUPPORTED = 3; + public static string APP_VERSION = "0.9.1"; + + public static int Main(string[] argv) + { + int argc = argv.Length; + int ret = SVGB_EXIT_ERROR; + MEM_InitModule(); + if(argc == 2 || argc == 3) + { + File * in = FILE_Open(); + if(in) + { + File * out; + if(argc == 2) + { + outfile = "stdout"; + out = FILE_AttachToFile(); + } + else + { + outfile = argv[2]; + out = FILE_Open(); + } + if(out) + { + File * wrap = FILE_Wrap(2); + if(wrap) + { + if(SVGB_Decode()) + { + ret = SVGB_EXIT_OK; + } + FILE_Detach(); + FILE_Close(); + } + else if(SVGB_Decode()) + { + ret = SVGB_EXIT_OK; + } + FILE_Detach(); + FILE_Close(); + } + else + { + Error("%s: can't create output file %s\n"); + } + FILE_Close(); + } + else + { + Error("%s: can't open input file %s\n"); + } + } + else + { + Output("Usage: %s input [output]\n"); + ret = SVGB_EXIT_ERROR; + } + MEM_Shutdown(); + return ret; + } +} + + static void Main(string[] args) + { + int ret = SVGB_EXIT_ERROR; + string outfile; + string infile; + if (args.Length == 2 || args.Length == 3) { + infile = args[1]; + BinaryReader ein = new BinaryReader(File.Open(infile, FileMode.Open), System.Text.Encoding.Default); + if (ein != null) { + StreamWriter aus; + if (args.Length == 2) { + outfile = "stdout"; + aus = new StreamWriter(outfile); + } else { + outfile = args[2]; + aus = new StreamWriter(outfile); + } + if (aus != null) { + SvgDec a = new SvgDec(ein, aus); + if (a.getReturnCode()) { + ret = SVGB_EXIT_OK; + } + aus.Close(); + } else { + Console.WriteLine("{0} can't create output file {1}","svgb.exe",outfile); + } + ein.Close(); + } else { + Console.WriteLine("{0} can't open input file {1}","svgb.exe",infile); + } + } else { + Console.WriteLine("SVGB to SVG converter version "+APP_VERSION); + Console.WriteLine("Usage: {0} input [output]\n", "svgb.exe"); + ret = SVGB_EXIT_ERROR; + } + Environment.ExitCode = ret; + } + } +} diff --git a/svgb/Properties/AssemblyInfo.cs b/svgb/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7bffd8e --- /dev/null +++ b/svgb/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die mit einer Assembly verknüpft sind. +[assembly: AssemblyTitle("svgb")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("svgb")] +[assembly: AssemblyCopyright("Copyright © 2009")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar +// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von +// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("0bbcc8cc-0d8c-48f0-9e86-98b05a1ce2e1")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/svgb/SvgDec.cs b/svgb/SvgDec.cs new file mode 100644 index 0000000..993df0f --- /dev/null +++ b/svgb/SvgDec.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; + +namespace svgb +{ + class SvgDec + { + static const uint SvgFileStart = 0x03FA56CC; + static const string SVG_START = "\n"+ + "\n"+ + "\n"; + private bool ok; + public SvgDec(BinaryReader ein, StreamWriter aus) + { + //Stack stack; + //STACK_Init(&stack, 0); + this.ok = this.SVGB_Decode2(ein, aus); + //STACK_Destroy(&stack); + } + public bool getReturnCode() + { + return this.ok; + } + private bool SVGB_Decode2(BinaryReader ein, StreamWriter aus) + { + uint start; + start = ein.ReadUInt32(); + if (start != null) { + if (start == SvgFileStart) { + byte c; + aus.Write(SVG_START); + while (true) { + try + { + c = ein.ReadByte(); + if (c == SvgFileEnd) { + if (FILE_ReadAll(in,&c,1)) { + FILE_PushBack(in, &c,1); + Warning("%s: trailing date ignored\n",pname); + } + ASSERT(STACK_IsEmpty(stack)); + return True; + } else if (c == SvgElementEnd) { + const SvgElement * elem = STACK_Pop(stack); + if (elem) { + XML_CloseTag(out, elem->name, True); + } else { + Error("%s: parse error (element stack underflow)\n", + pname); + return False; + } + } else if (c == SvgCData) { + char * str = SVGB_ReadString(in); + if (str) { + Bool wrap = WRAP_IsEnabled(out); + if (wrap) WRAP_Enable(out, False); + FILE_Puts(out, str); + if (wrap) WRAP_Enable(out, True); + MEM_Free(str); + } else { + return False; + } + } else if (c < COUNT(SVGB_ELEMS)) { + const SvgElement * elem = SVGB_ELEMS + c; + SvgDecodeElemStatus s = SVGB_DecodeElement(elem,in,out); + ASSERT(elem->code == c); + switch (s) { + case SvgDecodeElemStarted: + STACK_Push(stack, (SElement)elem); + case SvgDecodeElemFinished: + break; + case SvgDecodeError: + default: + return False; + } + } else { + Error("%s: unexpected element %u at offset 0x%06X (%u)\n", + pname,(unsigned int)c, FILE_BytesRead(in)-1, + FILE_BytesRead(in)-1); + return False; + } + } + } else { + Error("%s: this is not an S60 svgb file\n",pname); + return False; + } + } + Error("%s: error reading input\n"); + return False; + } + } +} diff --git a/svgb/svg_dec.c b/svgb/svg_dec.c new file mode 100644 index 0000000..ff4d232 --- /dev/null +++ b/svgb/svg_dec.c @@ -0,0 +1,1050 @@ +/* + * $Id: svgb_dec.c,v 1.5 2007/01/27 04:01:39 slava Exp $ + * + * Copyright (C) 2007 by Slava Monich + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1.Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2.Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING + * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#include "svgb.h" + +static const I32u SvgFileStart = 0x03FA56CC; +static const I8u SvgFileEnd = 0xFF; +static const I8u SvgAtrEnd[2] = {0xE8, 0x03}; +static const I8u SvgElementEnd = 0xFE; +static const I8u SvgCData = 0xFD; +static const I8u SvgRootElement = 0; + +typedef struct _SvgFill { + Str name; + I8u value[4]; +} SvgFill; + +static const SvgFill SVGB_FILL[] = { + { "none", {0xFF, 0xFF, 0xFF, 0x01}}, + { "currentColor", {0xFF, 0xFF, 0xFF, 0x02}} +}; + +typedef struct _SvgPathSegType { + char command; /* command character */ + int params; /* number of parameters */ +} SvgPathSegType; + +static const SvgPathSegType SVG_PATH_SEG [] = { + {'M', 2}, /* moveto */ + {'L', 2}, /* lineto */ + {'Q', 4}, /* quadratic curve */ + {'C', 6}, /* cubic curve */ + {'z', 0} /* closepath */ +}; + +static const Str SVG_START = "\n" +"\n" +"\n"; + +typedef struct _SvgAttr SvgAttr; +typedef struct _SvgElement SvgElement; +typedef Bool (*SvgAttrDecodeCB) (const SvgAttr * attr, + const SvgElement * elem, + File * in, + File * out); + +#define SvgAttrDecodePrototype(f) \ + STATIC Bool f(const SvgAttr * attr, const SvgElement * elem, \ + File * in, File * out) + +SvgAttrDecodePrototype(SVGB_DecodeFail); +SvgAttrDecodePrototype(SVGB_DecodeSize); +SvgAttrDecodePrototype(SVGB_DecodeVisibility); +SvgAttrDecodePrototype(SVGB_DecodeFloat); +SvgAttrDecodePrototype(SVGB_DecodeOpacity); +SvgAttrDecodePrototype(SVGB_DecodeRect); +SvgAttrDecodePrototype(SVGB_DecodeString); +SvgAttrDecodePrototype(SVGB_DecodeGradUnits); +SvgAttrDecodePrototype(SVGB_DecodeDisplay); +SvgAttrDecodePrototype(SVGB_DecodeSpreadMethod); +SvgAttrDecodePrototype(SVGB_DecodeFontStyle); +SvgAttrDecodePrototype(SVGB_DecodeFontWeight); +SvgAttrDecodePrototype(SVGB_DecodeTextAnchor); +SvgAttrDecodePrototype(SVGB_DecodeTextDecor); +SvgAttrDecodePrototype(SVGB_DecodeTrans); +SvgAttrDecodePrototype(SVGB_DecodeGradTrans); +SvgAttrDecodePrototype(SVGB_DecodePoints); +SvgAttrDecodePrototype(SVGB_DecodePath); +SvgAttrDecodePrototype(SVGB_DecodeFill); +SvgAttrDecodePrototype(SVGB_DecodeCssColor); +SvgAttrDecodePrototype(SVGB_DecodeHref); + +typedef struct _SvgElementAttr { + Str name; + Str value; +} SvgElementAttr; + +struct _SvgElement { + Str name; /* element name */ + I16u code; /* element code */ + const SvgElementAttr * attr; /* additional attributes */ + int nattr; /* number of additional attributes */ +}; + +struct _SvgAttr { + Str name; + SvgAttrDecodeCB decode; +}; + +typedef enum _SvgDecodeElemStatus { + SvgDecodeError, + SvgDecodeElemStarted, + SvgDecodeElemFinished +} SvgDecodeElemStatus; + +STATIC const SvgAttr SVGB_ATTRS [] = { + + {"fill", SVGB_DecodeFill }, /* 0 00 */ + {"stroke", SVGB_DecodeCssColor }, /* 1 01 */ + {"stroke-width", SVGB_DecodeFloat }, /* 2 02 */ + {"visibility", SVGB_DecodeVisibility }, /* 3 03 */ + {"font-family", SVGB_DecodeString }, /* 4 04 */ + {"font-size", SVGB_DecodeFloat }, /* 5 05 */ + {"font-style", SVGB_DecodeFontStyle }, /* 6 06 */ + {"font-weight", SVGB_DecodeFontWeight }, /* 7 07 */ + {"stroke-dasharray", SVGB_DecodeFail }, /* 8 08 */ + {"display", SVGB_DecodeDisplay }, /* 9 09 */ + {"fill-rule", SVGB_DecodeString }, /* 10 0A */ + {"stroke-linecap", SVGB_DecodeString }, /* 11 0B */ + {"stroke-linejoin", SVGB_DecodeString }, /* 12 0C */ + {"stroke-dashoffset", SVGB_DecodeFloat }, /* 13 0D */ + {"stroke-miterlimit", SVGB_DecodeFloat }, /* 14 0E */ + {"color", SVGB_DecodeCssColor }, /* 15 0F */ + {"text-anchor", SVGB_DecodeTextAnchor }, /* 16 10 */ + {"text-decoration", SVGB_DecodeTextDecor }, /* 17 11 */ + {"color-interpolation", SVGB_DecodeFail }, /* 18 12 */ + {"color-rendering", SVGB_DecodeFail }, /* 19 13 */ + {"letterSpacing", SVGB_DecodeFail }, /* 20 14 */ + {"word-spacing", SVGB_DecodeFail }, /* 21 15 */ + {"opacity", SVGB_DecodeOpacity }, /* 22 16 */ + {"stroke-opacity", SVGB_DecodeFloat }, /* 23 17 */ + /* {"group-opacity", SVGB_DecodeOpacity }, */ /* 24 18 */ + {"opacity", SVGB_DecodeOpacity }, /* 24 18 */ + + //{"font", SVGB_DecodeFail }, /* 25 19 */ + {"textLength", SVGB_DecodeFail }, /* 25 19 */ + + {"width", SVGB_DecodeSize }, /* 26 1A */ + {"height", SVGB_DecodeSize }, /* 27 1B */ + {"r", SVGB_DecodeFloat }, /* 28 1C */ + {"rx", SVGB_DecodeFloat }, /* 29 1D */ + + {"ry", SVGB_DecodeFloat }, /* 30 1E */ + {"horizAdvX", SVGB_DecodeFail }, /* 31 1F */ + {"horizOriginX", SVGB_DecodeFail }, /* 32 20 */ + {"horizOriginY", SVGB_DecodeFail }, /* 33 21 */ + {"ascent", SVGB_DecodeFail }, /* 34 22 */ + {"descent", SVGB_DecodeFail }, /* 35 23 */ + {"alphabetic", SVGB_DecodeFail }, /* 36 24 */ + {"underlinePosition", SVGB_DecodeFail }, /* 37 25 */ + {"underlineThickness", SVGB_DecodeFail }, /* 38 26 */ + {"overlinePosition", SVGB_DecodeFail }, /* 39 27 */ + + {"overlineThickness", SVGB_DecodeFail }, /* 40 28 */ + {"strikethroughPosition", SVGB_DecodeFail }, /* 41 29 */ + {"strikethroughThickness", SVGB_DecodeFail }, /* 42 2A */ + {"unitsPerEm", SVGB_DecodeFail }, /* 43 2B */ + {"wordSpacing", SVGB_DecodeFail }, /* 44 2C */ + {"letterSpacing", SVGB_DecodeFail }, /* 45 2D */ + {"cx", SVGB_DecodeFloat }, /* 46 2E */ + {"cy", SVGB_DecodeFloat }, /* 47 2F */ + {"y", SVGB_DecodeFloat }, /* 48 30 */ + {"x", SVGB_DecodeFloat }, /* 49 31 */ + + {"y1", SVGB_DecodeFloat }, /* 50 32 */ + {"y2", SVGB_DecodeFloat }, /* 51 33 */ + {"x1", SVGB_DecodeFloat }, /* 52 34 */ + {"x2", SVGB_DecodeFloat }, /* 53 35 */ + {"k", SVGB_DecodeFail }, /* 54 36 */ + {"g1", SVGB_DecodeFail }, /* 55 37 */ + {"g2", SVGB_DecodeFail }, /* 56 38 */ + {"u1", SVGB_DecodeFail }, /* 57 39 */ + {"u2", SVGB_DecodeFail }, /* 58 3A */ + {"unicode", SVGB_DecodeFail }, /* 59 3B */ + + {"glyphName", SVGB_DecodeFail }, /* 60 3C */ + {"lang", SVGB_DecodeFail }, /* 61 3D */ + {"textDecoration", SVGB_DecodeFail }, /* 62 3E */ + {"textAnchor", SVGB_DecodeFail }, /* 63 3F */ + {"rotate", SVGB_DecodeFail }, /* 64 40 */ + {"cdata", SVGB_DecodeFail }, /* 65 41 */ + {"transform", SVGB_DecodeTrans }, /* 66 42 */ + {"style", SVGB_DecodeFail }, /* 67 43 */ + {"fill", SVGB_DecodeFail }, /* 68 44 */ + {"stroke", SVGB_DecodeFail }, /* 69 45 */ + + {"color", SVGB_DecodeFail }, /* 70 46 */ + {"from", SVGB_DecodeFail }, /* 71 47 */ + {"to", SVGB_DecodeFail }, /* 72 48 */ + {"by", SVGB_DecodeFail }, /* 73 49 */ + {"attributeName", SVGB_DecodeFail }, /* 74 4A */ + {"pathLength", SVGB_DecodeFail }, /* 75 4B */ + {"version", SVGB_DecodeFail }, /* 76 4C */ + {"strokeWidth", SVGB_DecodeFail }, /* 77 4D */ + {"points", SVGB_DecodePoints }, /* 78 4E */ + {"d", SVGB_DecodePath }, /* 79 4F */ + {"type", SVGB_DecodeFail }, /* 80 50 */ + + {"stop-color", SVGB_DecodeCssColor }, /* 81 */ + {"fx", SVGB_DecodeFloat }, /* 82 */ + {"fy", SVGB_DecodeFloat }, /* 83 */ + {"offset", SVGB_DecodeFloat }, /* 84 */ + {"spreadMethods", SVGB_DecodeSpreadMethod }, /* 85 */ + {"gradientUnits", SVGB_DecodeGradUnits }, /* 86 */ + {"stopOpacity", SVGB_DecodeFloat }, /* 87 */ + {"viewBox", SVGB_DecodeRect }, /* 88 */ + {"baseProfile", SVGB_DecodeFail }, /* 89 */ + + {"zoomAndPan", SVGB_DecodeFail }, /* 90 */ + {"preserveAspectRatio", SVGB_DecodeFail }, /* 91 */ + {"id", SVGB_DecodeString }, /* 92 */ + {"xml:base", SVGB_DecodeString }, /* 93 */ + {"xml:lang", SVGB_DecodeString }, /* 94 */ + {"xml:space", SVGB_DecodeString }, /* 95 */ + {"requiredExtensions", SVGB_DecodeFail }, /* 96 */ + {"requiredFeatures", SVGB_DecodeFail }, /* 97 */ + {"systemLanguage", SVGB_DecodeFail }, /* 98 */ + {"dx", SVGB_DecodeFail }, /* 99 */ + + {"dy", SVGB_DecodeFail }, /* 100 */ + {"media", SVGB_DecodeFail }, /* 101 */ + {"title", SVGB_DecodeFail }, /* 102 */ + {"xlink:actuate", SVGB_DecodeFail }, /* 103 */ + {"xlink:arcrole", SVGB_DecodeFail }, /* 104 */ + {"xlink:role", SVGB_DecodeFail }, /* 105 */ + {"xlink:show", SVGB_DecodeFail }, /* 106 */ + {"xlink:title", SVGB_DecodeFail }, /* 107 */ + {"xlink:type", SVGB_DecodeFail }, /* 108 */ + {"xlink:href", SVGB_DecodeHref }, /* 109 */ + + {"begin", SVGB_DecodeFail }, /* 110 */ + {"dur", SVGB_DecodeFail }, /* 111 */ + {"repeatCount", SVGB_DecodeFail }, /* 112 */ + {"repeatDur", SVGB_DecodeFail }, /* 113 */ + {"end", SVGB_DecodeFail }, /* 114 */ + {"restart", SVGB_DecodeFail }, /* 115 */ + {"accumulate", SVGB_DecodeFail }, /* 116 */ + {"additive", SVGB_DecodeFail }, /* 117 */ + {"keySplines", SVGB_DecodeFail }, /* 118 */ + {"keyTimes", SVGB_DecodeFail }, /* 119 */ + {"calcMode", SVGB_DecodeFail }, /* 120 */ + {"path", SVGB_DecodeFail }, /* 121 */ + {"animateMotion", SVGB_DecodeFail }, /* 122 */ + {"gradientTransform", SVGB_DecodeGradTrans } /* 123 */ +}; + +#define SvgElementSVG 0 + +STATIC const SvgElementAttr SvgAttrSVG [] = { + {"xmlns", "http://www.w3.org/2000/svg"} +}; + +STATIC const SvgElement SVGB_ELEMS [] = { + {"svg", SvgElementSVG, SvgAttrSVG, COUNT(SvgAttrSVG)}, /* 0 */ + {"altglyph", 1, NULL, 0}, /* 1 */ + {"altglyphdef", 2, NULL, 0}, /* 2 */ + {"defs", 3, NULL, 0}, /* 3 */ + {"desc", 4, NULL, 0}, /* 4 */ + + {"foreignObject", 5, NULL, 0}, /* 5 */ + {"metadata", 6, NULL, 0}, /* 6 */ + {"title", 7, NULL, 0}, /* 7 */ + {"fontfacename", 8, NULL, 0}, /* 8 */ + {"fontfacesrc", 9, NULL, 0}, /* 9 */ + + {"fontfaceuri", 10, NULL, 0}, /* 10 */ + {"g", 11, NULL, 0}, /* 11 */ + {"glyphref", 12, NULL, 0}, /* 12 */ + {"vkern", 13, NULL, 0}, /* 13 */ + {"script", 14, NULL, 0}, /* 14 */ + + {"switch", 15, NULL, 0}, /* 15 */ + {"view", 16, NULL, 0}, /* 16 */ + {"hkern", 17, NULL, 0}, /* 17 */ + {"a", 18, NULL, 0}, /* 18 */ + {"font", 19, NULL, 0}, /* 19 */ + + {"fontface", 20, NULL, 0}, /* 20 */ + {"glyph", 21, NULL, 0}, /* 21 */ + {"image", 22, NULL, 0}, /* 22 */ + {"missingglyph", 23, NULL, 0}, /* 23 */ + {"style", 24, NULL, 0}, /* 24 */ + + {"text", 25, NULL, 0}, /* 25 */ + {"use", 26, NULL, 0}, /* 26 */ + {"circle", 27, NULL, 0}, /* 27 */ + {"ellipse", 28, NULL, 0}, /* 28 */ + {"line", 29, NULL, 0}, /* 29 */ + + {"path", 30, NULL, 0}, /* 30 */ + {"polygon", 31, NULL, 0}, /* 31 */ + {"polyline", 32, NULL, 0}, /* 32 */ + {"rect", 33, NULL, 0}, /* 33 */ + {"animate", 34, NULL, 0}, /* 34 */ + + {"animateColor", 35, NULL, 0}, /* 35 */ + {"animateMotion", 36, NULL, 0}, /* 36 */ + {"animateTransform", 37, NULL, 0}, /* 37 */ + {"set", 38, NULL, 0}, /* 38 */ + {"mpath", 39, NULL, 0}, /* 39 */ + + {"linearGradient", 40, NULL, 0}, /* 40 */ + {"radialGradient", 41, NULL, 0}, /* 41 */ + {"stop", 42, NULL, 0} /* 42 */ +}; + +typedef struct _SvgBlock { + const SvgElement * element; +} SvgBlock; + +/** + * Formats a single precision floating point number + */ +STATIC Str SVGB_FormatFloat(StrBuf * buf, float val, Bool append) +{ + if (!append) STRBUF_Clear(buf); + if (STRBUF_AppendFormat(buf, "%.4f",(double)val)) { + if (STRBUF_EndsWith(buf, ".0000")) { + STRBUF_SetLength(buf, STRBUF_Length(buf)-5); + } else if (STRBUF_EndsWith(buf, "000")) { + STRBUF_SetLength(buf, STRBUF_Length(buf)-3); + } else if (STRBUF_EndsWith(buf, "00")) { + STRBUF_SetLength(buf, STRBUF_Length(buf)-2); + } else if (STRBUF_EndsWith(buf, "0")) { + STRBUF_SetLength(buf, STRBUF_Length(buf)-1); + } + return STRBUF_Text(buf); + } else { + return NULL; + } +} + +/** + * Writes a single precision floating point attribute to the output stream. + * Almost like XML_WriteFloatAttr, but with less precision. + */ +STATIC Bool SVGB_WriteFloatAttr(File * out, Str attr, float val, Bool percent) +{ + Bool ok = False; + if (FILE_Puts(out, TEXT(" ")) && + FILE_Puts(out, attr) && + FILE_Puts(out, TEXT("="))) { + Str text; + StrBuf32 buf; + STRBUF_InitBufXXX(&buf); + + text = SVGB_FormatFloat(&buf.sb, val, False); + if (text) { + + /* disable wrapping while writing attribute value */ + Bool wrap = WRAP_IsEnabled(out); + if (wrap) WRAP_Enable(out, False); + + /* write the attribute value */ + ok = FILE_Putc(out, '"') && + FILE_Puts(out, text) && + (!percent || FILE_Putc(out, '%')) && + FILE_Putc(out, '"'); + + /* re-enable wrapping */ + if (wrap) WRAP_Enable(out, True); + } + STRBUF_Destroy(&buf.sb); + } + return ok; +} + +/** + * Reads string from the stream. Caller must deallocate the returned string. + * Reads UCS-2 characters from SVGB stream, returns UTF-8 encoded string. + */ +STATIC char * SVGB_ReadString(File * in) +{ + int len = FILE_GetByte(in); + if (len >= 0) { + wchar_t * walue; + ASSERT(!(len%2)); + len >>= 1; + walue = MEM_NewArray(wchar_t,len+1); + if (walue) { + char * value; + int i; + for (i=0; iname, FILE_BytesRead(in)-2); + Error("%s: element \"%s\" is not implemented\n",pname, attr->name); + exit(SVGB_EXIT_UNSUPPORTED); + return False; +} + + +STATIC Bool SVGB_DecodeHref(const SvgAttr * attr, const SvgElement * e, + File * in, File * out) +{ + char * str = SVGB_ReadString(in); + if (str) { + int len; + XML_WriteAttrNoEsc(out, attr->name, str); + MEM_Free(str); + + /* Next comes another string, usually the same as the first one */ + len = FILE_GetByte(in); + if (len >= 0 && FILE_SkipAll(in, len)) { + return True; + } else { + Error("%s: read error\n",pname); + } + } + return False; +} + +/** + * XX - flag (0 == color, 1 == URL) + * followed by either 32-bit color or URL string + */ +STATIC Bool SVGB_DecodeFill(const SvgAttr * attr, const SvgElement * elem, + File * in, File * out) +{ + int flag = FILE_GetByte(in); + if (flag >= 0) { + I8u color[4]; + char * url; + switch (flag) { + case 0: + if (FILE_ReadAll(in, color, sizeof(color))) { + int i; + const SvgFill * fill = NULL; + for (i=0; iname, fill->name); + } else { + StrBuf32 buf; + STRBUF_InitBufXXX(&buf); + STRBUF_Format(&buf.sb, "#%02X%02X%02X", + (unsigned int)color[0], (unsigned int)color[1], + (unsigned int)color[2]); + ASSERT(!color[3]); + XML_WriteAttrNoEsc(out, attr->name, STRBUF_Text(&buf.sb)); + STRBUF_Destroy(&buf.sb); + } + return True; + } + break; + + case 1: + url = SVGB_ReadString(in); + if (url) { + StrBuf32 buf; + STRBUF_InitBufXXX(&buf); + STRBUF_Format(&buf.sb, "url(#%s)", url); + XML_WriteAttrNoEsc(out, attr->name, STRBUF_Text(&buf.sb)); + STRBUF_Destroy(&buf.sb); + MEM_Free(url); + return True; + } + default: + Error("%s: unsupported fill flag %u\n",pname,(unsigned int)flag); + return False; + } + } + Error("%s: read error\n",pname); + return False; +} + +/** + * XX XX XX XX - Color + */ +STATIC Bool SVGB_DecodeCssColor(const SvgAttr * attr, const SvgElement * elem, + File * in, File * out) +{ + I8u color[4]; + if (FILE_ReadAll(in, color, sizeof(color))) { + StrBuf32 buf; + STRBUF_InitBufXXX(&buf); + STRBUF_Format(&buf.sb, "#%02X%02X%02X", + (unsigned int)color[0], (unsigned int)color[1], + (unsigned int)color[2]); + XML_WriteAttrNoEsc(out, attr->name, STRBUF_Text(&buf.sb)); + STRBUF_Destroy(&buf.sb); + return True; + } + Error("%s: read error\n",pname); + return False; +} + +/** + * XX - enum value + */ +STATIC Bool SVGB_DecodeEnum(const SvgAttr * attr, File * in, File * out, + const Str values[], int n) +{ + int i = FILE_GetByte(in); + if (i >= 0) { + if (i < n && values[i]) { + XML_WriteAttrNoEsc(out, attr->name, values[i]); + } else { + Warning("%s: unexpected value %d for %s\n",pname,i,attr->name); + } + return True; + } + Error("%s: read error\n",pname); + return False; +} + +STATIC Bool SVGB_DecodeSpreadMethod(const SvgAttr* attr, const SvgElement * e, + File* in, File* out) +{ + static const Str values[] = {"pad", "reflect","repeat"}; + return SVGB_DecodeEnum(attr, in, out, values, COUNT(values)); +} + +STATIC Bool SVGB_DecodeGradUnits(const SvgAttr * attr, const SvgElement * e, + File * in, File * out) +{ + static const Str values[] = {"userSpaceOnUse", "objectBoundingBox"}; + return SVGB_DecodeEnum(attr, in, out, values, COUNT(values)); +} + +/** + * XX XX XX XX - 32-bit enum value + */ +STATIC Bool SVGB_DecodeCssEnum(const SvgAttr * attr, File * in, File * out, + const Str values[], I32u n, Str defval) +{ + I32u i; + if (FILE_ReadI32L(in, &i)) { + if (i < n && values[i]) { + XML_WriteAttrNoEsc(out, attr->name, values[i]); + } else if (defval) { + XML_WriteAttrNoEsc(out, attr->name, defval); + } else { + Warning("%s: unexpected value %d for %s\n",pname,i,attr->name); + } + return True; + } + Error("%s: read error\n",pname); + return False; +} + +STATIC Bool SVGB_DecodeDisplay(const SvgAttr * attr, const SvgElement * e, + File * in, File * out) +{ + static const Str values[] = {"inline", NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "none"}; + return SVGB_DecodeCssEnum(attr, in, out, values, COUNT(values),"inherit"); +} + +STATIC Bool SVGB_DecodeVisibility(const SvgAttr * attr, const SvgElement * e, + File * in, File * out) +{ + static const Str values[] = {"visible", "hidden"}; + return SVGB_DecodeCssEnum(attr, in, out, values, COUNT(values), NULL); +} + +STATIC Bool SVGB_DecodeFontStyle(const SvgAttr * attr, const SvgElement * e, + File * in, File * out) +{ + static const Str values[] = {"normal", "italic", "oblique", "inherit"}; + return SVGB_DecodeCssEnum(attr, in, out, values, COUNT(values), NULL); +} + +STATIC Bool SVGB_DecodeFontWeight(const SvgAttr * attr, const SvgElement * e, + File * in, File * out) +{ + static const Str values[] = {"normal", "bold", "bolder", "lighter", + "100", "200", "300", "400", "500", "600", "700", "800", "900", + "inherit"}; + return SVGB_DecodeCssEnum(attr, in, out, values, COUNT(values), NULL); +} + +STATIC Bool SVGB_DecodeTextAnchor(const SvgAttr * attr, const SvgElement * e, + File * in, File * out) +{ + static const Str values[] = {"start", "middle", "end"}; + return SVGB_DecodeCssEnum(attr, in, out, values, COUNT(values), NULL); +} + +STATIC Bool SVGB_DecodeTextDecor(const SvgAttr * attr, const SvgElement * e, + File * in, File * out) +{ + static const Str values[]={"none","underline","overline","line-through"}; + return SVGB_DecodeCssEnum(attr, in, out, values, COUNT(values), NULL); +} + +/** + * XX - size in bytes + * XXXX XXXX - UCS2 string + */ +STATIC Bool SVGB_DecodeString(const SvgAttr * attr, const SvgElement * elem, + File * in, File * out) +{ + char * str = SVGB_ReadString(in); + if (str) { + XML_WriteAttrNoEsc(out, attr->name, str); + MEM_Free(str); + return True; + } + return False; +} + +/** + * XX XX - number of segments + * XX * n - segment types + * XX XX - number of 32 bit floating point values following + * XX XX XX XX * n - 32 bit floating point values + */ +STATIC Bool SVGB_DecodePath(const SvgAttr * attr, const SvgElement * elem, + File * in, File * out) +{ + I16u nseg; + if (FILE_ReadI16L(in, &nseg)) { + I8u * seg = MEM_Alloc(nseg); + if (seg) { + if (FILE_ReadAll(in, seg, nseg)) { + I16u nval; + if (FILE_ReadI16L(in, &nval)) { + I16u iseg, ival = 0; + StrBuf128 buf; + STRBUF_InitBufXXX(&buf); + + for (iseg=0; isegcommand); + for(i=0; iparams; i++, ival++) { + float val; + ASSERT(ival < nval); + if (ival >= nval) { + STRBUF_Destroy(&buf.sb); + MEM_Free(seg); + return False; + } + if (!FILE_ReadF32L(in, &val)) { + Error("%s: read error\n",pname); + STRBUF_Destroy(&buf.sb); + MEM_Free(seg); + return False; + } + if (i > 0 && val >= 0) { + STRBUF_AppendChar(&buf.sb, ','); + } + SVGB_FormatFloat(&buf.sb, val, True); + } + } else { + STRBUF_Destroy(&buf.sb); + MEM_Free(seg); + return False; + } + } + + ASSERT(ival == nval); + XML_WriteAttrNoEsc(out, attr->name, STRBUF_Text(&buf.sb)); + STRBUF_Destroy(&buf.sb); + MEM_Free(seg); + return True; + } + } + + MEM_Free(seg); + } else { + return False; + } + } + Error("%s: read error\n",pname); + return False; +} + +/** + * XX XX - number of bytes following (n) + * XX * n - bytes (segment types?) + * XX XX - number of 32 bit floating point values following + * XX XX XX XX * n - 32 bit floating point values, 2 for each point + */ +STATIC Bool SVGB_DecodePoints(const SvgAttr * attr, const SvgElement * elem, + File * in, File * out) +{ + I16u nflags; + if (FILE_ReadI16L(in, &nflags)) { + I8u * flags = MEM_Alloc(nflags); + if (flags) { + if (FILE_ReadAll(in, flags, nflags)) { + I16u nval; + if (FILE_ReadI16L(in, &nval)) { + I16u i; + StrBuf128 buf; + STRBUF_InitBufXXX(&buf); + ASSERT(!(nval%2)); + for (i=0; i 0) STRBUF_AppendChar(&buf.sb, ' '); + SVGB_FormatFloat(&buf.sb, x, True); + STRBUF_AppendChar(&buf.sb, ','); + SVGB_FormatFloat(&buf.sb, y, True); + } + + XML_WriteAttrNoEsc(out, attr->name, STRBUF_Text(&buf.sb)); + STRBUF_Destroy(&buf.sb); + MEM_Free(flags); + return True; + } + } + + MEM_Free(flags); + } else { + return False; + } + } + Error("%s: read error\n",pname); + return False; +} + +/** + * XX XX XX XX - 32 bit floating point value (matrix[0][0]) + * XX XX XX XX - 32 bit floating point value (matrix[0][1]) + * XX XX XX XX - 32 bit floating point value (matrix[0][2]) + * XX XX XX XX - 32 bit floating point value (matrix[1][0]) + * XX XX XX XX - 32 bit floating point value (matrix[1][1]) + * XX XX XX XX - 32 bit floating point value (matrix[1][2]) + */ +STATIC Bool SVGB_DecodeMatrix(const SvgAttr * attr, File * in, File * out, + float divisor) +{ + int i; + StrBuf64 buf; + + float matrix[6]; + static const int trans[6] = {0, 3, 1, 4, 2, 5}; + + for (i=0; i 0) STRBUF_AppendChar(&buf.sb, ' '); + SVGB_FormatFloat(&buf.sb, matrix[trans[i]], True); + } + STRBUF_Append(&buf.sb, ")"); + XML_WriteAttrNoEsc(out, attr->name, STRBUF_Text(&buf.sb)); + + STRBUF_Destroy(&buf.sb); + return True; +} + +/** + * XX XX XX XX - 32 bit floating point value (matrix[0][0]) + * XX XX XX XX - 32 bit floating point value (matrix[0][1]) + * XX XX XX XX - 32 bit floating point value (matrix[0][2]) + * XX XX XX XX - 32 bit floating point value (matrix[1][0]) + * XX XX XX XX - 32 bit floating point value (matrix[1][1]) + * XX XX XX XX - 32 bit floating point value (matrix[1][2]) + */ +STATIC Bool SVGB_DecodeGradTrans(const SvgAttr * attr, + const SvgElement * elem, + File * in, File * out) +{ + return SVGB_DecodeMatrix(attr, in, out, 65535.0f); +} + +/** + * XX XX XX XX - 32 bit floating point value (matrix[0][0]) + * XX XX XX XX - 32 bit floating point value (matrix[0][1]) + * XX XX XX XX - 32 bit floating point value (matrix[0][2]) + * XX XX XX XX - 32 bit floating point value (matrix[1][0]) + * XX XX XX XX - 32 bit floating point value (matrix[1][1]) + * XX XX XX XX - 32 bit floating point value (matrix[1][2]) + * XX XX XX XX - transform type? + */ +STATIC Bool SVGB_DecodeTrans(const SvgAttr * attr, const SvgElement * elem, + File * in, File * out) +{ + if (SVGB_DecodeMatrix(attr, in, out, 1.0f)) { + I32u type; + if (FILE_ReadI32L(in, &type)) { + return True; + } + Error("%s: read error\n",pname); + } + return False; +} + +/** + * XX XX XX XX - 32 bit floating point value (X) + * XX XX XX XX - 32 bit floating point value (Y) + * XX XX XX XX - 32 bit floating point value (Width) + * XX XX XX XX - 32 bit floating point value (Height) + */ +STATIC Bool SVGB_DecodeRect(const SvgAttr * attr, const SvgElement * elem, + File * in, File * out) +{ + int i; + StrBuf32 buf; + STRBUF_InitBufXXX(&buf); + + for (i=0; i<4; i++) { + float x; + if (!FILE_ReadF32L(in, &x)) { + Error("%s: read error\n",pname); + STRBUF_Destroy(&buf.sb); + return False; + } + + if (i > 0) STRBUF_AppendChar(&buf.sb, ' '); + SVGB_FormatFloat(&buf.sb, x, True); + } + + XML_WriteAttrNoEsc(out, attr->name, STRBUF_Text(&buf.sb)); + STRBUF_Destroy(&buf.sb); + return True; +} + +/** + * XX XX XX XX - 32 bit floating point value + */ +STATIC Bool SVGB_DecodeFloat(const SvgAttr * attr, const SvgElement * elem, + File * in, File * out) +{ + float value; + if (FILE_ReadF32L(in, &value)) { + SVGB_WriteFloatAttr(out, attr->name, value, False); + return True; + } + Error("%s: read error\n",pname); + return False; +} + +/** + * Need special case for opacity attribute? + */ +STATIC Bool SVGB_DecodeOpacity(const SvgAttr * attr, const SvgElement * elem, + File * in, File * out) +{ + return SVGB_DecodeFloat(attr, elem, in, out); +} + +/** + * XX - 1 for percent, 0 otherwise (root element only) + * XX XX XX XX - 32 bit floating point value + */ +STATIC Bool SVGB_DecodeSize(const SvgAttr * attr, const SvgElement * elem, + File * in, File * out) +{ + float value; + int flag = 0; + if (elem->code == SvgElementSVG) { + flag = FILE_GetByte(in); + } + if (FILE_ReadF32L(in, &value)) { + SVGB_WriteFloatAttr(out, attr->name, value, (flag != 0)); + return True; + } + Error("%s: read error\n",pname); + return False; +} + +/** + * Decodes a single element. + */ +STATIC SvgDecodeElemStatus SVGB_DecodeElement(const SvgElement * elem, + File * in, File * out) +{ + int i; + I8u endmark[sizeof(SvgAtrEnd)]; + + /* Add implied attributes */ + XML_StartTag(out, elem->name); + for (i=0; inattr; i++) { + XML_WriteAttrNoEsc(out, elem->attr[i].name, elem->attr[i].value); + } + + /* Loop until we hit SvgAtrEnd mark */ + while (FILE_ReadAll(in,&endmark,sizeof(endmark))) { + I16u id = 0; + if (!memcmp(endmark, SvgAtrEnd, sizeof(endmark))) { + I8u next; + if (FILE_ReadAll(in, &next, 1)) { + if (next == SvgElementEnd) { + FILE_Puts(out, "/>\n"); + return SvgDecodeElemFinished; + } else { + FILE_PushBack(in, &next, 1); + FILE_Puts(out, (next == SvgCData) ? ">" : ">\n"); + WRAP_Indent(out, +1); + return SvgDecodeElemStarted; + } + } else { + Error("%s: read error\n",pname); + return SvgDecodeError; + } + } + + /* Handle next attribute */ + FILE_PushBack(in, endmark, sizeof(endmark)); + FILE_ReadI16L(in, &id); + if (id < COUNT(SVGB_ATTRS)) { + const SvgAttr * a = SVGB_ATTRS + id; + if (!a->decode(a, elem, in, out)) { + return False; + } + } else { + Error("%s: unexpected attribute %u at offset 0x%06X (%u)\n", + pname, id, FILE_BytesRead(in)-1, FILE_BytesRead(in)-1); + break; + } + } + return SvgDecodeError; +} + +/** + * Decodes SVGB stream, writes XML to the output stream. + */ +STATIC Bool SVGB_Decode2(File * in, File * out, Stack * stack) +{ + I32u start; + if (FILE_ReadI32L(in, &start)) { + if (start == SvgFileStart) { + I8u c; + FILE_Puts(out, SVG_START); + while (FILE_ReadAll(in,&c,1)) { + if (c == SvgFileEnd) { + if (FILE_ReadAll(in,&c,1)) { + FILE_PushBack(in, &c,1); + Warning("%s: trailing date ignored\n",pname); + } + ASSERT(STACK_IsEmpty(stack)); + return True; + } else if (c == SvgElementEnd) { + const SvgElement * elem = STACK_Pop(stack); + if (elem) { + XML_CloseTag(out, elem->name, True); + } else { + Error("%s: parse error (element stack underflow)\n", + pname); + return False; + } + } else if (c == SvgCData) { + char * str = SVGB_ReadString(in); + if (str) { + Bool wrap = WRAP_IsEnabled(out); + if (wrap) WRAP_Enable(out, False); + FILE_Puts(out, str); + if (wrap) WRAP_Enable(out, True); + MEM_Free(str); + } else { + return False; + } + } else if (c < COUNT(SVGB_ELEMS)) { + const SvgElement * elem = SVGB_ELEMS + c; + SvgDecodeElemStatus s = SVGB_DecodeElement(elem,in,out); + ASSERT(elem->code == c); + switch (s) { + case SvgDecodeElemStarted: + STACK_Push(stack, (SElement)elem); + case SvgDecodeElemFinished: + break; + case SvgDecodeError: + default: + return False; + } + } else { + Error("%s: unexpected element %u at offset 0x%06X (%u)\n", + pname,(unsigned int)c, FILE_BytesRead(in)-1, + FILE_BytesRead(in)-1); + return False; + } + } + } else { + Error("%s: this is not an S60 svgb file\n",pname); + return False; + } + } + Error("%s: error reading input\n"); + return False; +} + +/** + * Decodes SVGB stream, writes XML to the output stream. + */ +Bool SVGB_Decode(File * in, File * out) +{ + Bool ok; + Stack stack; + STACK_Init(&stack, 0); + ok = SVGB_Decode2(in, out, &stack); + STACK_Destroy(&stack); + return ok; +} \ No newline at end of file diff --git a/svgb/svgb.c b/svgb/svgb.c new file mode 100644 index 0000000..cc3173d --- /dev/null +++ b/svgb/svgb.c @@ -0,0 +1,83 @@ +/* + * $Id: svgb.c,v 1.1 2007/01/27 02:40:52 slava Exp $ + * + * Copyright (C) 2007 by Slava Monich + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1.Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2.Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING + * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#include "svgb.h" + +const Str pname = "svgb"; + +/** + * Entry point for SVGB decoder + */ +int main(int argc, char * argv[]) +{ + int ret = SVGB_EXIT_ERROR; + MEM_InitModule(); + if (argc == 2 || argc == 3) { + Str infile = argv[1]; + File * in = FILE_Open(infile, READ_BINARY_MODE, NULL); + if (in) { + Str outfile; + File * out; + if (argc == 2) { + outfile = "stdout"; + out = FILE_AttachToFile(stdout, outfile); + } else { + outfile = argv[2]; + out = FILE_Open(outfile, WRITE_TEXT_MODE, NULL); + } + if (out) { + File * wrap = FILE_Wrap(out, 2, INT_MAX); + if (wrap) { + if (SVGB_Decode(in, wrap)) { + ret = SVGB_EXIT_OK; + } + FILE_Detach(wrap); + FILE_Close(wrap); + } else if (SVGB_Decode(in, out)) { + ret = SVGB_EXIT_OK; + } + FILE_Detach(out); + FILE_Close(out); + } else { + Error("%s: can't create output file %s\n",pname,outfile); + } + FILE_Close(in); + } else { + Error("%s: can't open input file %s\n",pname,infile); + } + } else { + Output("SVGB to SVG converter version "APP_VERSION"\n"); + Output("Usage: %s input [output]\n",pname); + ret = SVGB_EXIT_ERROR; + } + MEM_Shutdown(); + return ret; +} \ No newline at end of file diff --git a/svgb/svgb.csproj b/svgb/svgb.csproj new file mode 100644 index 0000000..3e571bf --- /dev/null +++ b/svgb/svgb.csproj @@ -0,0 +1,65 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {EF378B10-B9FA-4B0F-ADA9-73E386B690A9} + Exe + Properties + svgb + svgb + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/svgb/svgb.h b/svgb/svgb.h new file mode 100644 index 0000000..f32a385 --- /dev/null +++ b/svgb/svgb.h @@ -0,0 +1,47 @@ +/* + * $Id: svgb.h,v 1.1 2007/01/27 02:40:52 slava Exp $ + * + * Copyright (C) 2007 by Slava Monich + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1.Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2.Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING + * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#ifndef _SVGB_H_ +#define _SVGB_H_ 1 + +#include "s_lib.h" + +#define SVGB_EXIT_OK 0 +#define SVGB_EXIT_USAGE 1 +#define SVGB_EXIT_ERROR 2 +#define SVGB_EXIT_UNSUPPORTED 3 + +extern const Str pname; +extern Bool SVGB_Decode(File * in, File * out); + +#define APP_VERSION "0.9.1" + +#endif /* _SVGB_H_ */ \ No newline at end of file diff --git a/svgb1/svgb1.sln b/svgb1/svgb1.sln new file mode 100644 index 0000000..3d3ff74 --- /dev/null +++ b/svgb1/svgb1.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "svgb1", "svgb1\svgb1.vcproj", "{7186A3A0-E05D-4920-B7AF-8548E22440B7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7186A3A0-E05D-4920-B7AF-8548E22440B7}.Debug|Win32.ActiveCfg = Debug|Win32 + {7186A3A0-E05D-4920-B7AF-8548E22440B7}.Debug|Win32.Build.0 = Debug|Win32 + {7186A3A0-E05D-4920-B7AF-8548E22440B7}.Release|Win32.ActiveCfg = Release|Win32 + {7186A3A0-E05D-4920-B7AF-8548E22440B7}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/svgb1/svgb1/ReadMe.txt b/svgb1/svgb1/ReadMe.txt new file mode 100644 index 0000000..e3b0764 --- /dev/null +++ b/svgb1/svgb1/ReadMe.txt @@ -0,0 +1,36 @@ +======================================================================== + KONSOLENANWENDUNG: svgb1-Projektübersicht +======================================================================== + +Diese svgb1-Anwendung wurde vom Anwendungs-Assistenten +für Sie erstellt. + +Die Datei enthält eine Zusammenfassung des Inhalts der Dateien, +aus denen die svgb1-Anwendung besteht. + + +svgb1.vcproj + Dies ist die Hauptprojektdatei für VC++-Projekte, die mit dem Anwendungs- + Assistenten generiert werden. + Sie enthält Informationen zu der Version von Visual C++, mit der die Datei + generiert wurde, sowie Informationen zu Plattformen, Konfigurationen und + Projektfeatures, die mit dem dem Anwendungs-Assistenten generiert werden. + +svgb1.cpp + Dies ist die Hauptquelldatei der Anwendung. + +///////////////////////////////////////////////////////////////////////////// +Andere Standarddateien: + +StdAfx.h, StdAfx.cpp + Mit diesen Dateien werden eine vorkompilierte Headerdatei (PCH) + mit dem Namen svgb1.pch sowie eine vorkompilierte + Typendatei mit dem Namen StdAfx.obj erstellt. + +///////////////////////////////////////////////////////////////////////////// +Weitere Hinweise: + +Der Anwendungs-Assistent verwendet "TODO:"-Kommentare, um die Teile des +Quellcodes anzugeben, die hinzugefügt oder bearbeitet werden müssen. + +///////////////////////////////////////////////////////////////////////////// diff --git a/svgb1/svgb1/stdafx.c b/svgb1/svgb1/stdafx.c new file mode 100644 index 0000000..1208004 --- /dev/null +++ b/svgb1/svgb1/stdafx.c @@ -0,0 +1,8 @@ +// stdafx.cpp : Quelldatei, die nur die Standard-Includes einbindet. +// svgb1.pch ist der vorkompilierte Header. +// stdafx.obj enthält die vorkompilierten Typinformationen. + +#include "stdafx.h" + +// TODO: Auf zusätzliche Header verweisen, die in STDAFX.H +// und nicht in dieser Datei erforderlich sind. diff --git a/svgb1/svgb1/stdafx.h b/svgb1/svgb1/stdafx.h new file mode 100644 index 0000000..16a8d0b --- /dev/null +++ b/svgb1/svgb1/stdafx.h @@ -0,0 +1,29 @@ +// stdafx.h : Includedatei für Standardsystem-Includedateien +// oder häufig verwendete projektspezifische Includedateien, +// die nur in unregelmäßigen Abständen geändert werden. +// + +#pragma once + +#include "targetver.h" + +#include +#include + +#ifndef _SVGB_H_ +#define _SVGB_H_ 1 + + +#define SVGB_EXIT_OK 0 +#define SVGB_EXIT_USAGE 1 +#define SVGB_EXIT_ERROR 2 +#define SVGB_EXIT_UNSUPPORTED 3 + +//extern const Str pname; +//extern Bool SVGB_Decode(File * in, File * out); + +#define APP_VERSION "0.9.1" + +#endif /* _SVGB_H_ */ + +// TODO: Hier auf zusätzliche Header, die das Programm erfordert, verweisen. diff --git a/svgb1/svgb1/svgb1.c b/svgb1/svgb1/svgb1.c new file mode 100644 index 0000000..3d6562d --- /dev/null +++ b/svgb1/svgb1/svgb1.c @@ -0,0 +1,55 @@ +// svgb1.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung. +// + +#include "stdafx.h" + +const Str pname = "svgb"; + +/** + * Entry point for SVGB decoder + */ +int _tmain(int argc, _TCHAR* argv[]) +{ + int ret = SVGB_EXIT_ERROR; + MEM_InitModule(); + if (argc == 2 || argc == 3) { + Str infile = argv[1]; + File * in = FILE_Open(infile, READ_BINARY_MODE, NULL); + if (in) { + Str outfile; + File * out; + if (argc == 2) { + outfile = "stdout"; + out = FILE_AttachToFile(stdout, outfile); + } else { + outfile = argv[2]; + out = FILE_Open(outfile, WRITE_TEXT_MODE, NULL); + } + if (out) { + File * wrap = FILE_Wrap(out, 2, INT_MAX); + if (wrap) { + if (SVGB_Decode(in, wrap)) { + ret = SVGB_EXIT_OK; + } + FILE_Detach(wrap); + FILE_Close(wrap); + } else if (SVGB_Decode(in, out)) { + ret = SVGB_EXIT_OK; + } + FILE_Detach(out); + FILE_Close(out); + } else { + Error("%s: can't create output file %s\n",pname,outfile); + } + FILE_Close(in); + } else { + Error("%s: can't open input file %s\n",pname,infile); + } + } else { + Output("SVGB to SVG converter version "APP_VERSION"\n"); + Output("Usage: %s input [output]\n",pname); + ret = SVGB_EXIT_ERROR; + } + MEM_Shutdown(); + return ret; +} diff --git a/svgb1/svgb1/svgb1.vcproj b/svgb1/svgb1/svgb1.vcproj new file mode 100644 index 0000000..a4ff595 --- /dev/null +++ b/svgb1/svgb1/svgb1.vcproj @@ -0,0 +1,229 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/svgb1/svgb1/svgb1.vcproj.Phil.netz.user b/svgb1/svgb1/svgb1.vcproj.Phil.netz.user new file mode 100644 index 0000000..e0cf2bb --- /dev/null +++ b/svgb1/svgb1/svgb1.vcproj.Phil.netz.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/svgb1/svgb1/targetver.h b/svgb1/svgb1/targetver.h new file mode 100644 index 0000000..abf0fc6 --- /dev/null +++ b/svgb1/svgb1/targetver.h @@ -0,0 +1,13 @@ +#pragma once + +// Die folgenden Makros definieren die mindestens erforderliche Plattform. Die mindestens erforderliche Plattform +// ist die früheste Windows-, Internet Explorer-Version usw., die über die erforderlichen Features zur Ausführung +// Ihrer Anwendung verfügt. Die Makros aktivieren alle Funktionen, die auf den Plattformversionen bis +// einschließlich der angegebenen Version verfügbar sind. + +// Ändern Sie folgende Definitionen für Plattformen, die älter als die unten angegebenen sind. +// Unter MSDN finden Sie die neuesten Informationen über die entsprechenden Werte für die unterschiedlichen Plattformen. +#ifndef _WIN32_WINNT // Gibt an, dass Windows Vista die mindestens erforderliche Plattform ist. +#define _WIN32_WINNT 0x0600 // Ändern Sie den entsprechenden Wert, um auf andere Versionen von Windows abzuzielen. +#endif +