PDA

View Full Version : Paint svg on QTextDocument transparent.



patrik08
15th July 2007, 00:20
i have to render on QTextDocument XSL-FO file and
all QTextBlockFormat, QTextCharFormat, QTextTableCell QText format class
its does not know to make border color and border size left 3pt bottom 10pt as example..

i found to be useful use the inline svg to thisplay border ....

the tag sample... ( fo:block is like html <P>)



<fo:block>
A text line below the instream object.
</fo:block>
<fo:block>
<fo:instream-foreign-object>
<svg:svg width="250" height="50">
<svg:g style="fill:red; stroke:#000000">
<svg:rect x="0" y="0" width="15" height="15"/>
<svg:rect x="5" y="5" width="15" height="15"/>
</svg:g>
<svg:text x="10" y="30">SVG placed in a block</svg:text>
</svg:svg>
</fo:instream-foreign-object>
</fo:block>


here is the svg class function that render & take domelement svg transorm and paint..
the problem if i not fill pix.fill(QColor("#ffffff")); the svg is display black ...
now to display varius layer on a scene how i can make this background color transparent?
To to overlap 3 or moore layer ...




QPixmap FopFormat::RenderSvg( const QDomElement e )
{
nrloop++; /* count element to addresource ! */
/* QString trytosave = QString("svg_%1.svg").arg(nrloop); */
QDomDocument em;
QDomProcessingInstruction header = em.createProcessingInstruction( "xml", "version=\"1.0\" standalone=\"no\"" );
em.appendChild( header );
em.appendChild( e.firstChildElement() );
QDomElement root = em.documentElement();
root.setAttribute ("xmlns","http://www.w3.org/2000/svg");
root.setAttribute ("version","1.2");
root.setAttribute ("baseProfile","tiny");
QString srcsv = em.toString();
if (srcsv.contains("svg:svg")) {
srcsv = srcsv.replace("svg:","");
}
/* try to save to show on firefox if work
QFile f( trytosave );
if ( f.open( QFile::WriteOnly | QFile::Text ) )
{
QTextStream sw( &f );
sw << srcsv;
f.close();
}
*/
QByteArray streamsvg;
streamsvg.append ( srcsv );
QSvgRenderer svgRenderer( streamsvg );
QPixmap pix( svgRenderer.defaultSize() );
pix.fill(QColor("#ffffff"));
QPainter paint(&pix);
svgRenderer.render(&paint);
if (pix.isNull() ) {
QPixmap pixe(22,22);
pixe.fill(QColor("crimson")); /* a error red pixel */
return pixe;
} else {
return pix;
}
}


bool FopFormat::ObjectParserTag( const QDomElement &e )
{
nrloop++;
QDomElement domObject = e.firstChildElement();
if ( domObject.tagName().toLower() == "svg:svg" || domObject.tagName().toLower() == "svg" ) {
QPixmap paintsvg = RenderSvg(e);
Tdoc->addResource( QTextDocument::ImageResource, QUrl(QString("%1").arg(nrloop)), paintsvg );
QTextImageFormat format;
format.setName( QString("%1").arg(nrloop) );
format.setToolTip(QString("SVG dom."));
Tcursor.insertImage( format ); /* cursor insert image QPixmap */
return true;
}

return false;
}