/***************************************************************************
xmlcode.cpp - description
-------------------
begin : Mo 23.06.2008
copyright : (C) 2008 by Andre Simon
email : andre.simon1@gmx.de
***************************************************************************/
/*
This file is part of Highlight.
Highlight 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 3 of the License, or
(at your option) any later version.
Highlight 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 Highlight. If not, see .
*/
#include
#include
#include "version.h"
#include "svggenerator.h"
using namespace std;
namespace highlight
{
SVGGenerator::SVGGenerator()
: CodeGenerator ( SVG )
{
spacer = " ";
newLineTag = "\n";
styleCommentOpen="/*";
styleCommentClose="*/";
}
SVGGenerator::~SVGGenerator() {}
void SVGGenerator::initOutputTags(){
openTags.push_back ( "" );
openTags.push_back ( getOpenTag ( STY_NAME_STR ) );
openTags.push_back ( getOpenTag ( STY_NAME_NUM ) );
openTags.push_back ( getOpenTag ( STY_NAME_SLC ) );
openTags.push_back ( getOpenTag ( STY_NAME_COM ) );
openTags.push_back ( getOpenTag ( STY_NAME_ESC ) );
openTags.push_back ( getOpenTag ( STY_NAME_DIR ) );
openTags.push_back ( getOpenTag ( STY_NAME_DST ) );
openTags.push_back ( getOpenTag ( STY_NAME_LIN ) );
openTags.push_back ( getOpenTag ( STY_NAME_SYM ) );
closeTags.push_back ( "" );
for ( int i=1;i" );
}
}
string SVGGenerator::getStyleDefinition()
{
if ( styleDefinitionCache.empty() )
{
ostringstream os;
if ( includeStyleDef )
{
os << "";
}
styleDefinitionCache=os.str();
}
return styleDefinitionCache;
}
string SVGGenerator::getAttributes ( const string & elemName,
const ElementStyle & elem )
{
ostringstream s;
if ( !elemName.empty() )
{
s << /*cssClassName<<"."<<*/ elemName<<" { ";
}
s << "fill:#"
<< ( elem.getColour().getRed ( HTML ) )
<< ( elem.getColour().getGreen ( HTML ) )
<< ( elem.getColour().getBlue ( HTML ) )
<< ( elem.isBold() ? "; font-weight:bold" :"" )
<< ( elem.isItalic() ? "; font-style:italic" :"" )
<< ( elem.isUnderline() ? "; text-decoration:underline" :"" );
if ( !elemName.empty() )
{
s << "; }\n" ;
}
return s.str();
}
string SVGGenerator::getOpenTag ( const string& styleName )
{
return "";
}
string SVGGenerator::getHeader()
{
ostringstream header;
header << "\n";
if ( !includeStyleDef )
{
header << "\n";
}
header << "\n";
header << "\n";
os<< "\n";
return os.str();
}
string SVGGenerator::maskCharacter ( unsigned char c )
{
switch ( c )
{
case '<' :
return "<";
break;
case '>' :
return ">";
break;
case '&' :
return "&";
break;
case '\"' :
return """;
break;
default:
return string ( 1, c );
}
}
string SVGGenerator::getKeywordOpenTag ( unsigned int styleID )
{
return getOpenTag ( langInfo.getKeywordClasses() [styleID] );
}
string SVGGenerator::getKeywordCloseTag ( unsigned int styleID )
{
return "";
}
string SVGGenerator::getNewLine()
{
if ( lineNumber>1 )
{
ostringstream os;
int fontSize=0;
StringTools::str2num ( fontSize, getBaseFontSize(), std::dec );
os<< "\n";
return os.str();
}
else
{
return "";
}
}
void SVGGenerator::setSVGSize ( const string& w, const string& h )
{
width=w;
height=h;
}
}