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