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 » RichText,QTF,RTF... » Can I turn the page a few degrees when printing?
Can I turn the page a few degrees when printing? [message #31826] Wed, 30 March 2011 09:06 Go to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Dear friends! Can I turn the page a few degrees when printing?

I see that the pages before printing is stored as a Drawing. Drawing may be possible to turn a few degrees as a bitmap?


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Can I turn the page a few degrees when printing? [message #31953 is a reply to message #31826] Mon, 11 April 2011 09:37 Go to previous message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
Hello, Sergey.

It possible to draw images, which can be rotated for needed angle, using various Rotate functions or Painting::Rotate. Also, some kind of anti-aliasing needed.

I created following simple application, using ImageDraw, but not tested for printing:
// main.cpp
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class App : public TopWindow {
public:
	typedef App CLASSNAME;
	App();
	// Ctrl widgets
	MenuBar menu;
	WithDropChoice<EditIntSpin> angle;
	ImageCtrl image;
	// Bars
	void MainBar(Bar& bar);
	void FileBar(Bar& bar);
	// Events
	void OnSaveAs();
	void OnPrint();
	void OnPreview();
	// Functions
	void DoDraw(ImageDraw& iw);
	Image GetImage();
};

App::App()
{
	Title("Application for page rotation");
	CenterScreen().Sizeable().MinimizeBox().MaximizeBox();
	const Size sz(640, 480);
	SetRect(sz);
	SetMinSize(sz);

	angle.NotNull().Min(0).Max(360).SetData(0);
	for (int i = 0; i < 9; ++i) angle.AddList(i * 45);

	angle.WhenEnter = angle.WhenSelect = THISBACK(OnPreview);

	AddFrame(menu);
	AddFrame(TopSeparatorFrame());
	menu.Set(THISBACK(MainBar));
	menu.Add(angle, 75);

	Add(image.SizePos());

	OnPreview();
}
// Bars
void App::MainBar(Bar& bar)
{
	bar.Add("File", THISBACK(FileBar));
}

void App::FileBar(Bar& bar)
{
	bar.Add("Save as..", THISBACK(OnSaveAs)).Key(K_CTRL_S);
	bar.Add("Print", THISBACK(OnPrint)).Key(K_ALT_P);
	bar.Add("Preview", THISBACK(OnPreview)).Key(K_ALT_R);
	bar.Separator();
	bar.Add("Exit", THISBACK(Close)).Key(K_ALT_Q);
}
// Events
void App::OnSaveAs()
{
	const String fileName = SelectFileSaveAs("*.png");

	if (!fileName.IsVoid())
	{
		PNGEncoder png;
		Image w = GetImage();
		png.SaveFile(fileName, w);
	}
}

void App::OnPrint()
{
	PrinterJob pj;

	if (pj.Execute())
	{
		Draw& w = pj.GetDraw();
		w.StartPage();
		w.DrawImage(0, 0, GetImage());
		w.EndPage();
	}
}

void App::OnPreview()
{
	if (!angle.Accept())
		return;

	image.SetImage(GetImage());
}
// Functions
void App::DoDraw(ImageDraw& w)
{
	w.DrawRect(w.GetPageSize(), SWhite);

	for (int i = 0; i < 10; ++i)
		w.DrawLine(50, 50,
			int(50 + 50 * sin(i * M_PI / 10)),
			int(50 + 50 * cos(i * M_PI / 10)),
			2, SLtGray);

	const String text("DRAWING");
	Size sz = GetTextSize(text, Courier(16).Italic());
	w.DrawText((100 - sz.cx) / 2, (100 - sz.cy) / 2, text, Courier(16).Italic());
}

Image App::GetImage()
{
	ImageDraw iw(240, 320);
	DoDraw(iw);
	Image w = iw;

	return Rotate(w, angle * 10);
}

GUI_APP_MAIN
{
	App app;
	app.Run();
}

index.php?t=getfile&id=3173&private=0


And using Painting::Rotate:
#include <CtrlLib/CtrlLib.h>
#include <Painter/Painter.h>

using namespace Upp;

GUI_APP_MAIN
{
	const int width = 600, height = 800;

	PaintingPainter sw(width, height);
	sw.DrawRect(sw.GetPageSize(), SWhite);

	sw.Rotate(0.5); // value from working PainterExamples application, about 45 degrees.

	for (int i = 0; i < 10; ++i)
		sw.DrawLine(50, 50,
			int(50 + 50 * sin(i * M_PI / 10)),
			int(50 + 50 * cos(i * M_PI / 10)),
			2, SLtGray);

	const String text("DRAWING");
	Size sz = GetTextSize(text, Courier(16).Italic());
	sw.DrawText((100 - sz.cx) / 2, (100 - sz.cy) / 2, text, Courier(16).Italic());

	const String fileName = SelectFileSaveAs("*.png");

	if (!fileName.IsVoid())
	{
		ImageBuffer ib(width, height);
		BufferPainter bw(ib);
		bw.DrawPainting(0, 0, width, height, sw);

		PNGEncoder png;
		Image w = ib;
		png.SaveFile(fileName, w);
	}

	PrinterJob pj;

	if (PromptYesNo("Do you want to print?") == IDOK)
		if (pj.Execute())
			pj.GetDraw().DrawPainting(0, 0, width, height, sw);
}

[Updated on: Mon, 11 April 2011 12:10]

Report message to a moderator

Previous Topic: QTF editors and styles
Next Topic: Bad rtf import after commit r3579 - CtrlCore/ParseRTF.cpp, EncodeRTF.cpp: table & cell border fi
Goto Forum:
  


Current Time: Thu Mar 28 22:24:39 CET 2024

Total time taken to generate the page: 0.01140 seconds