00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "PDRExample.h"
00017
00018
00019 CPdrExample::CPdrExample()
00020 {}
00021
00022 CPdrExample::~CPdrExample()
00023 {
00024 _LIT(KExit,"\n\nPress any key to exit the application ");
00025 iConsole->Printf(KExit);
00026 iConsole->Getch();
00027
00028
00029 delete iDriver;
00030 delete iStopper;
00031 RFbsSession::Disconnect();
00032 delete iConsole;
00033 }
00034
00035 CPdrExample* CPdrExample::NewL()
00036 {
00037 CPdrExample* self= new (ELeave) CPdrExample();
00038 CleanupStack::PushL(self);
00039 self->ConstructL();
00040 CleanupStack::Pop();
00041 return self;
00042 }
00043
00044 void CPdrExample::ConstructL()
00045 {
00046 iConsole = Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
00047
00048 _LIT(KTextPressAKey, "\n\nPress any key to step through the example");
00049 iConsole->Printf ( KTextPressAKey );
00050 iConsole->Getch ();
00051
00052 iConsole->Printf ( _L("\nLoading printer driver...\n") );
00053
00054
00055 User::LoadPhysicalDevice(PDD_NAME);
00056
00057 User::LoadLogicalDevice(LDD_NAME);
00058 FbsStartup();
00059
00060
00061 RFbsSession::Connect();
00062 }
00063
00064
00065 void CPdrExample::CreatePrinterDriverL()
00066 {
00067
00068 iStopper=new(ELeave) CPdrPrint();
00069 CActiveScheduler::Add(iStopper);
00070
00071
00072 iDriver=CPrinterDriver::NewL();
00073
00074 TFileName filename( KDriveName );
00075 filename.Append( KDefaultPrinterDriverPath );
00076 filename.Append( KEpsonFileName );
00077
00078 iConsole->Printf ( _L("\nOpening printer driver information file...\n") );
00079
00080
00081 TInt ret;
00082 TRAP(ret,iDriver->OpenPdrL( filename ));
00083 if ( ret == KErrNone )
00084 {
00085 iConsole->Printf(_L("\nNumber of models: %d\n"),iDriver->NumModels());
00086 }
00087
00088
00089 TPrinterModelEntry entry;
00090 for (TInt i=0; i<iDriver->NumModels(); i++)
00091 {
00092 entry=iDriver->Model(i);
00093 iConsole->Printf(_L("Model: %S\n"),&entry.iModelName);
00094 }
00095
00096 iConsole->Getch();
00097 iConsole->Printf(_L("\nSelect model from 1 to %d\n"),iDriver->NumModels());
00098 iConsole->Printf(_L("\nSelecting... %d\n"),iDriver->NumModels());
00099 iConsole->Printf(_L("\nPrinter driver properties:\n"));
00100
00101
00102 iDevice=NULL;
00103 entry=iDriver->Model(iDriver->NumModels()-1);
00104 TRAP(ret,iDevice=iDriver->CreatePrinterDeviceL(entry.iUid));
00105 if ( ret == KErrNone )
00106 {
00107 iConsole->Printf(_L("PDR device: %d\n"),iDevice);
00108 iConsole->Printf(_L("No. of typefaces: %d\n"),iDevice->NumTypefaces());
00109 TPrinterModelName iModelName = iDevice->Model().iModelName;
00110 iConsole->Printf(_L("Model name: %S\n"),&iModelName );
00111 iConsole->Getch();
00112
00113 TPageSpec pagespec(TPageSpec::EPortrait,KA4PaperSizeInTwips);
00114 iDevice->SelectPageSpecInTwips(pagespec);
00115
00116 }
00117 }
00118
00119
00120 void CPdrExample::DisplayTypefaces()
00121 {
00122
00123 TTypefaceSupport support;
00124 iDevice->TypefaceSupport(support,0);
00125 TBuf<KMaxTypefaceNameLength> name;
00126
00127 iConsole->Printf(_L("\nSupported typefaces:\n"));
00128 TInt i;
00129 for (i=0; i<iDevice->NumTypefaces(); i++)
00130 {
00131 iDevice->TypefaceSupport(support,i);
00132 name.Copy(support.iTypeface.iName);
00133 iConsole->Printf(_L(" %S\n"),&name);
00134 }
00135 iConsole->Getch();
00136 }
00137
00138
00139 void CPdrExample::CreatePrinterControl()
00140 {
00141 CPrinterPort* printerport=NULL;
00142
00143 if (iDevice->Model().iRequiresPrinterPort)
00144 {
00145 TInt ret;
00146 TRAP(ret,printerport=CFilePrinterPort::NewL(_L("\\temp.prn")));
00147 if (ret==KErrNone)
00148 {
00149 iConsole->Printf(_L("\nCreate a printer control to process and terminate the print job\n"));
00150 TRAP(ret,iDevice->CreateControlL(printerport));
00151 }
00152 }
00153 }
00154
00155
00156
00157 void CPdrExample::PrintPages()
00158 {
00159
00160 TBandAttributes attributes;
00161 CPrinterControl::TMoreOnPage moreonpage=CPrinterControl::EMoreOnPage;
00162
00163 TInt h=iDevice->HorizontalPixelsToTwips(1000);
00164 TInt v=iDevice->VerticalPixelsToTwips(1000);
00165 TInt k=4800;
00166
00167 TInt nuBands = iDevice->iControl->BandsPerPage();
00168 iConsole->Printf(_L("Number of bands per page: %d\n"), nuBands);
00169 iConsole->Printf(_L("Printing bands on the page...\n"));
00170 iConsole->Getch();
00171
00172 TInt i=0;
00173 do
00174 {
00175 iConsole->Printf(_L("Band %d\n"),i+1);
00176 moreonpage=iDevice->iControl->QueueGetBand(iStopper->Queue(),attributes);
00177 CActiveScheduler::Start();
00178
00179
00180 CGraphicsContext* gc=NULL;
00181 iDevice->CreateContext((CGraphicsContext *&) gc);
00182 gc->SetPenColor(KRgbBlack);
00183 gc->SetPenStyle(CGraphicsContext::ESolidPen);
00184 gc->SetPenSize(TSize(4*k/h,4*k/v));
00185 gc->DrawEllipse(TRect(391,352,1152,601));
00186 delete gc;
00187 i++;
00188 }
00189 while (moreonpage==CPrinterControl::EMoreOnPage);
00190
00191 iConsole->Printf(_L("\nPrinting completed\n"));
00192 iDevice->iControl->QueueEndPrint(iStopper->Queue());
00193 CActiveScheduler::Start();
00194 }
00195
00196 LOCAL_C void MainL()
00197 {
00198 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
00199 CleanupStack::PushL(scheduler);
00200 CActiveScheduler::Install( scheduler );
00201
00202 CPdrExample* app = CPdrExample::NewL();
00203 CleanupStack::PushL(app);
00204
00205
00206 app->CreatePrinterDriverL();
00207
00208 app->DisplayTypefaces();
00209
00210 app->CreatePrinterControl();
00211
00212 app->PrintPages();
00213
00214 CleanupStack::PopAndDestroy(2,scheduler);
00215 }
00216
00217 GLDEF_C TInt E32Main()
00218 {
00219 __UHEAP_MARK;
00220 CTrapCleanup* cleanup = CTrapCleanup::New();
00221 if(cleanup == NULL)
00222 {
00223 return KErrNoMemory;
00224 }
00225 TRAPD(err, MainL());
00226 if(err != KErrNone)
00227 {
00228 User::Panic(_L("Failed to complete"),err);
00229 }
00230
00231 delete cleanup;
00232 __UHEAP_MARKEND;
00233 return KErrNone;
00234 }
00235
00236
00237