Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Qtf and drawing
Qtf and drawing [message #1033] Wed, 15 February 2006 20:55 Go to next message
pivica is currently offline  pivica
Messages: 57
Registered: November 2005
Location: Belgrade, Serbia
Member
Here is situation. I have some input data and then some calculation and some output data. And on the end I generate some Qtf text and all is very nice and good looking:))
But now I want to generate some images, based on calculated data, and put them in qtf document. After some investigation in uppsrc I figure a way how to generate simple png image in qtf:

String GenerateQtfImage() const
{
	int w = 1;
	int dist = 400;
	const Point p1(0, 0);
	const Point p2(dist, 0);
	const Point p3(dist, dist);
	const Point p4(0, dist);
	
	Size simg(p3);
	DrawingDraw dw(simg);
	
	for(int i = 0; i < 10; i++)
		dw.DrawLine(dist/2, dist/2,
		           int(dist/2 + dist/2 * sin(i * M_PI / 10)),
		           int(dist/2 + dist/2 * cos(i * M_PI / 10)),
		           w, SLtGray);
	
	Size sz = dw.GetTextSize("DRAWING", Courier(dist/5).Italic());
	dw.DrawText((p2.x - sz.cx) / 2, (p3.y - sz.cy) / 2, "DRAWING", Courier(dist/5).Italic());
	
	int scale = 4;
	Image img (dist/scale, dist/scale, dw.GetResult(), SWhite());
	
	String qtfimg;
	{	
		RichPara::CharFormat cformat;
		cformat. Face(Font::COURIER).Height(dist/20);
		
		// What's this for??
		/*Size size = dw.Dots() ? img.GetSize()
		: iscale(size, Size(DOTS_PER_METER_INT, DOTS_PER_METER_INT), GetPixelsPerMeter(draw));*/
		
		RichPara para;// rich paragraf
		
		para.Cat(RichObject("PNG",
				            PngEncoder().SaveImage(img), 
				            img.GetSize()
				            )
				 , cformat);
		
		RichText rtext;
		rtext.Cat(para);
		qtfimg = BodyAsQTF(rtext);
	}
	return qtfimg;
}


Now this stuff is working, but is this a good way?
Also I have some problem with resolution when changing scale parameter. With 1 image is looking good, but when I raise scale (2,4,..) image is losing resolution.

What I need is to generate images for pie diagram and gauss distribution diagram. Maybe it's better to use Geom package for this?

One more question. There is DrawArc method for drawing arc, but how to fill arc with some color?
Re: Qtf and drawing [message #1040 is a reply to message #1033] Wed, 15 February 2006 22:11 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
If it is fast enough for you then it is adequate way. Somewhat more straight approach would be to use

RichObject CreateDrawingObject(const Drawing& dwg, Size dot_size, Size out_size);

However, this is drawback that such QTF is not guaranteed to be compatible across platforms (PNG is).

If speed is absolute concern (rarely is), faster would be to generate RichText directly (without QTF), but I would really reserve that just for cases where it is absolutely neccessary.

-----

Image img (dist/scale, dist/scale, dw.GetResult(), SWhite());

- this line renders Drawing (vetor image) into raster Image, scaling it to the size established by first two parameters. No wonder that by increasing scale you are loosing the resolution.

Mirek
Re: Qtf and drawing [message #1058 is a reply to message #1040] Sat, 18 February 2006 19:04 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, as the things were little bit too ugly, I have added direct solution for this problem:

QtfRichObject solves problems when generating qtf by code and combining it with graphics.

It creates simple helper object that stores RichObject and converts itself to string (using ToString) with special QTF syntax that contains the value of the pointer to stored RichObject. QTFParser then picks the pointer...

This both greately simplifies the client code AND reduces all the overhead needed to convert RichObject to QTF and back... The only thing to be careful about is that QtfRichObject MUST exist by the time QTF is parsed (otherwise the pointer stored in QTF text would be dangling).

Demostrated by QtfDrawing example:

GUI_APP_MAIN
{
    DrawingDraw dw(100, 100);
    dw.DrawRect(0, 0, 100, 100, White);
    dw.DrawEllipse(10, 10, 80, 80, Red, 5, Blue);
    dw.DrawRect(50, 50, 50, 50, Yellow);
    QtfRichObject pict(CreateDrawingObject(dw.GetResult(), Size(500, 500), Size(500, 500)));
    String qtf;
    qtf << "[A6 This is some drawing in QTF: " << pict << "&";
    qtf << "[C3*@B And now in the table: {{1:1 " << pict << ":: Another cell " << pict << "}}";
    PromptOK(qtf);
}


Mirek
Previous Topic: tray icon & balloon notification
Next Topic: How to set transparency level for static rectangle?
Goto Forum:
  


Current Time: Mon Apr 29 05:10:14 CEST 2024

Total time taken to generate the page: 0.02279 seconds