REM Demo of creating a multiple page PDF file using the 'pdflib.bbc' library. HIMEM=PAGE+256*256*256*3 : REM Images use a lot of memory ON ERROR IF ERR = 17 CHAIN @lib$ + "../examples/tools/touchide" ELSE \ \ MODE 3 : REPORT : PRINT : END CanvasX% = 2048 : REM max=2560 on windows CanvasY% = 2048 WindowX% = 640 WindowY% = 480 VDU 23,22,WindowX%;WindowY%;8,16,16,128+8 REM PDF line styles, start/end of lines and joining lines. LineCapButt = &00000000 LineCapRound = &01000000 LineCapSquare = &02000000 LineJoinMiter = &00000000 LineJoinRound = &04000000 LineJoinBevel = &08000000 Pixels = &00000000 GrUnits = &10000000 : REM Coordinates are given in BBC graphic units. MilliMeter = &00100000 : REM Use offset, in millimetres, from the top-left corner of the printable area of the paper. REM Draw some coloured filled circles ORIGIN 0, 2 * (WindowX% - CanvasX%) FOR I% = 1 TO 200 X% = RND(CanvasX% * 2) : Y% = RND(CanvasY% * 2) : R% = 20 + RND(300) GCOL RND(15) : CIRCLE FILL X%, Y%, R% GCOL 0 : CIRCLE X%, Y%, R% NEXT ORIGIN 0,0 INSTALL @lib$ + "pdflib" INSTALL @lib$ + "imglib" : PROC_imgInit A%% = FN_imgLoad(@dir$ + "../graphics/world.jpg") B%% = FN_imgLoad(@dir$ + "../graphics/alien.png") C%% = FN_imgLoad(@dir$ + "../graphics/ball.bmp") IF A%%=0 OR B%%=0 OR C%%=0 ERROR 0, "Couldn't load image" PROC_PLpages(2) : REM Must be the first call to PDFlib PRINT "Demo of fonts and text in pixel mode"' REM Demo of fonts and text in pixel mode ******************************************************************** REM pixels from bottom-left corner PROC_PLpage(1) PROC_PLcolour(0,1,MilliMeter) PROC_PLfont("Courier",12,0) : PROC_PLprint(80, 4, " Page 1") Pencolour = 0 Penwidth = 1 Style=Pixels + LineCapButt + LineJoinMiter : REM or Style=MilliMeter, since LineCapButt and LineJoinMiter are both zero. PROC_PLcolour(Pencolour,Penwidth,Style) H%=12 : X%=20 : Y%=800 PROC_PLfont("Times",H%,0) PROC_PLprint(X%,Y%,"Times: ") PROC_PLfont("Times",H%,&FF) : REM colour=blue PROC_PLprint(0,0,"Normal text ") : REM 0,0 = continue print on line PROC_PLfont("TimesB",H%,&8000) : REM colour=green PROC_PLprint(0,0,"Bold text ") PROC_PLfont("TimesI",H%,&FF0000) : REM colour=red PROC_PLprint(0,0,"Italic text") PROCwaterfall(X%, Y%, "Times") PROC_PLfont("Helvetica",H%,0) PROC_PLprint(X%,Y%,"Helvetica: ") PROC_PLfont("Helvetica",H%,&FF) PROC_PLprint(0,0,"Normal text ") PROC_PLfont("HelveticaB",H%,&8000) PROC_PLprint(0,0,"Bold text ") PROC_PLfont("HelveticaO",H%,&FF0000) PROC_PLprint(0,0,"Oblique text") PROCwaterfall(X%, Y%, "Helvetica") PROC_PLfont("Courier",H%,0) PROC_PLprint(X%,Y%,"Courier: ") PROC_PLfont("Courier",H%,&FF) PROC_PLprint(0,0,"Normal text ") PROC_PLfont("CourierB",H%,&8000) PROC_PLprint(0,0,"Bold text ") PROC_PLfont("CourierO",H%,&FF0000) PROC_PLprint(0,0,"Oblique text") PROCwaterfall(X%, Y%, "Courier") PROC_PLfont(@lib$ + "FreeSerif.ttf",H%,0) PROC_PLprint(X%,Y%,"FreeSerif: ") PROC_PLfont(@lib$ + "FreeSerif.ttf",H%,&FF) PROC_PLprint(0,0,"Հայերեն տեքստ ") PROC_PLfont(@lib$ + "FreeSerif.ttf",H%,&8000) PROC_PLprint(0,0,"Ελληνικό κείμενο ") PROC_PLfont(@lib$ + "FreeSerif.ttf",H%,&FF0000) PROC_PLprint(0,0,"Русский текст") PROCwaterfall(X%, Y%, @lib$ + "FreeSerif.ttf") PROC_PLfont(@lib$ + "DejaVuSans.ttf",H%,0) PROC_PLprint(X%,Y%,"DejaVuSans: ") PROC_PLfont(@lib$ + "DejaVuSans.ttf",H%,&FF) PROC_PLprint(0,0,"Հայերեն տեքստ ") PROC_PLfont(@lib$ + "DejaVuSans.ttf",H%,&8000) PROC_PLprint(0,0,"Ελληνικό κείμενο ") PROC_PLfont(@lib$ + "DejaVuSans.ttf",H%,&FF0000) PROC_PLprint(0,0,"Русский текст") PROCwaterfall(X%, Y%, @lib$ + "DejaVuSans.ttf") PROC_PLfont(@lib$ + "FreeMono.ttf",H%,0) PROC_PLprint(X%,Y%,"FreeMono: ") PROC_PLfont(@lib$ + "FreeMono.ttf",H%,&FF) PROC_PLprint(0,0,"English text ") PROC_PLfont(@lib$ + "FreeMono.ttf",H%,&8000) PROC_PLprint(0,0,"Ελληνικό κείμενο ") PROC_PLfont(@lib$ + "FreeMono.ttf",H%,&FF0000) PROC_PLprint(0,0,"Русский текст") PROCwaterfall(X%, Y%, @lib$ + "FreeMono.ttf") PROC_PLfont(@lib$ + "Bedstead.otf",H%,0) PROC_PLprint(X%,Y%,"Bedstead: ") PROC_PLfont(@lib$ + "Bedstead.otf",H%,&FF) PROC_PLprint(0,0,"English text ") PROC_PLfont(@lib$ + "Bedstead.otf",H%,&8000) PROC_PLprint(0,0,"Ελληνικο κειμενο ") PROC_PLfont(@lib$ + "Bedstead.otf",H%,&FF0000) PROC_PLprint(0,0,"Русский текст") PROCwaterfall(X%, Y%, @lib$ + "Bedstead.otf") PRINT "Graphic examples in pixel mode"' REM Graphic examples in pixel mode ****************************************************************** REM pixels from bottom-left corner PROC_PLpage(2) PROC_PLcolour(0,1,MilliMeter) PROC_PLfont("Courier",12,0) : PROC_PLprint(80, 4, " Page 2") REM Straight line Pencolour=0 Penwidth=2 PROC_PLcolour(Pencolour,Penwidth,Style) PROC_PLline(120,500,420,506) PROC_PLprint(200,515,"Near horizontal line") REM Outline rectangle Fill=0 PROC_PLrectangle(20,700,350,100,Fill) REM Filled rectangle Pencolour=&AABBCC Fill=1 PROC_PLcolour(Pencolour,Penwidth,Style) PROC_PLrectangle(25,705,340,90,Fill) PROC_PLprint(40,770,"Filled rectangle inside outline rectangle.") PROC_PLprint(40,740,"Text is always printed on top of graphics.") PROC_PLprint(40,720,"And graphics are drawn over images.") REM Cubic Bezier curve from four control points Pencolour = &0000FF : REM blue Penwidth = 5.5 Style = Pixels + LineCapRound + LineJoinMiter : REM or Style=LineCapRound, since Pixels and LineJoinMiter are both zero. Fill=0 PROC_PLcolour(Pencolour,Penwidth,Style) PROC_PLbezier(30, 680, 100, 450, 200, 750, 400, 550, Fill) : REM startxy,cp1xy,cp2xy,endxy,fill PROC_PLprint(150,640,"Cubic bezier line") REM Circle Pencolour = 0 Penwidth = 2.0 X%=500 : Y%=750 PROC_PLcolour(Pencolour,Penwidth,Style) PROC_PLcircle(X%,Y%,50,0) PROC_PLprint(X%-22,Y%-4,"Circle") REM sector diagram, degrees, 0 degree up, clockwise X%=500 : Y%=600 : R%=60 : Fill=1 PROC_PLcolour(&8040FF,Penwidth,Style) PROC_PLsector(X%,Y%,R%,0,60,Fill) : REM angle=0 extent=60 PROC_PLcolour(&40FF80,Penwidth,Style) PROC_PLsector(X%,Y%,R%,60,30,Fill) : REM angle=60 extent=30 PROC_PLcolour(&FF8040,Penwidth,Style) PROC_PLsector(X%,Y%,R%,90,100,Fill) PROC_PLcolour(&80A0C0,Penwidth,Style) PROC_PLsector(X%,Y%,R%,190,150,Fill) PROC_PLcolour(&BBFF00,Penwidth,Style) PROC_PLsector(X%,Y%,R%,340,20,Fill) PROC_PLprint(X%-R%,Y%+R%+5,"Filled pie chart") PRINT "Graphic examples in BBC graphic units mode"' REM Graphic examples in BBC graphic units mode ****************************************************** REM BBC graphic units from bottom-left corner REM Filled five-pointed star (copy from aagfxdem.bbc) Pencolour = &808080 : REM grey Penwidth = 1.0 Style=GrUnits + LineCapButt + LineJoinMiter : REM or Style=GrUnits, since LineCapButt and LineJoinMiter are both zero. PROC_PLcolour(Pencolour,Penwidth,Style) Fill=1 DIM X(5), Y(5) X() = 1100,900,1060,1000,940,1100 Y() = 430,430,320,500,320,430 : Y()+=300 PROC_PLpolyline(6, X(), Y(), Fill) PROC_PLprint(870,800,"Polyline filled star") REM Angled solid ellipse (copy from aagfxdem.bbc) REM degrees, 0 degree up, clockwise Pencolour = &80A080 angle=30 Fill=1 PROC_PLcolour(Pencolour,Penwidth,Style) PROC_PLellipse(150, 710, 140, 50, angle, Fill) PROC_PLprint(50,850,"Angled solid ellipse") REM Heart shape from polybezier (copy from aagfxdem.bbc) x = 600 : y = 740 DIM x(12), y(12) x() = x, x, x-100, x-100, x-100, x, x, x, x+100, x+100, x+100, x, x y() = y, y+60, y+60, y, y-60, y-70, y-110, y-70, y-60, y, y+60, y+60, y Pencolour = &400000 Penwidth = 1.0 Fill=1 PROC_PLcolour(Pencolour,Penwidth,Style) PROC_PLpolybezier(13, x(), y(), Fill) Pencolour = &C0392B Penwidth = 3.0 Fill=0 PROC_PLcolour(Pencolour,Penwidth,Style) PROC_PLpolybezier(13, x(), y(), Fill) PROC_PLprint(390,800,"Heart shape from polybezier") PRINT "Graphic/text/image examples in millimeter mode"' REM Graphic/text/image examples in millimeter mode ************************************************** REM Millimetres from the top-left corner of PDF sheet Pencolour = 0 Penwidth = 1 Style=MilliMeter + LineCapButt + LineJoinMiter : REM or Style=MilliMeter, since LineCapButt and LineJoinMiter are both zero. PROC_PLcolour(Pencolour,Penwidth,Style) PROC_PLline(0,140,210,140) PROC_PLline(0,200,210,200) PROC_PLprint(5,208,"Using the millimeter style makes it easier to align text, graphics and images.") REM use imglib to display images with scale/flip/rotation REM then get size, plot+offset, convert, hardcopy Pencolour = 0 Penwidth = 1 Style=MilliMeter + LineCapButt + LineJoinMiter : REM or Style=MilliMeter, since LineCapButt and LineJoinMiter are both zero. PROC_PLcolour(Pencolour,Penwidth,Style) X%=1500 : Y%=-1500 : REM offset in BBC graphic units from bottom left of screen PROC_imgSize(A%%,W%,H%) : REM returns size in pixels PROC_imgPlot(A%%,X%+W%,Y%+H%,1,1,0) : REM plot centre of image plus offset PROC_PLimgCanvas(X%,Y%,W%,H%) : REM convert imgPlot() coordinates to hardcopy() coordinates PROC_PLhardcopy(X%,Y%,W%,H%,10,220,40,40) : REM see manual *HARDCOPY PROC_PLrectangle(10,220,40,40,0) PROC_PLprint(10,220-1,"world.jpg") X%=100 : Y%=-500 PROC_imgSize(B%%,W%,H%) PROC_imgPlot(B%%,X%+W%,Y%+H%,0.8,0.8,45) PROC_PLimgCanvas(X%,Y%,W%,H%) PROC_PLhardcopy(X%,Y%,W%,H%,60,220,20,20) PROC_PLrectangle(60,220,20,20,0) PROC_PLprint(60,220-1,"alien.png") X%=100 : Y%=100 PROC_imgSize(C%%,W%,H%) PROC_imgPlot(C%%,X%+W%,Y%+H%,1.1,1.1,0) PROC_PLimgCanvas(X%,Y%,W%,H%) PROC_PLhardcopy(X%,Y%,W%,H%,90,220,20,20) PROC_PLrectangle(90,220,20,20,0) PROC_PLprint(90,220-1,"ball.bmp") W%=75/2560*CanvasX% : H%=60/2048*CanvasY% PROC_PLhardcopy(0,0,CanvasX%*2,CanvasY%*2,120,220,W%,H%) PROC_PLrectangle(120,220,W%,H%,0) PROC_PLprint(120,220-1,"Hardcopy from canvas "+STR$CanvasX%+"*"+STR$CanvasY%) Pencolour = &FF0000 PROC_PLcolour(Pencolour,Penwidth,Style) PROC_PLrectangle(120,220,@vdu%!208/CanvasX%*W%,@vdu%!212/CanvasY%*H%,0) PROC_PLprint(70,260-1,"Output window.") PROC_PLprint(70,260+4,STR$WindowX%+"*"+STR$WindowY%) PROC_PLline(70,260,105,260) PROC_PLline(105,260,120,220+@vdu%!212/CanvasY%*H%) Title$="PDFdemo" Author$="You" Subject$="Text,graphics and images" Creator$="BBC Basic" Producer$="BBCsdl + pdflib" Date$=TIME$ : REM Date$ must be formatted 'exactly' as TIME$ if setting another date than today PROC_PLmetadata(Title$,Author$,Subject$,Creator$,Producer$,Date$) ON CLOSE RETURN IF FN_PLcreatepdf(@usr$+"pdfdemo.pdf")=0 THEN ERROR 0,"Can't create PDF file" ON CLOSE OFF SYS "SDL_ShowSimpleMessageBox", 0, "Created PDF file", @usr$+"pdfdemo.pdf", @hwnd%, @memhdc% REPEAT WAIT 5 : UNTIL FALSE END DEF PROCwaterfall(X%, RETURN Y%, font$) LOCAL H% Y% -= 10 FOR H% = 10 TO 22 STEP 3 Y% -= H% PROC_PLfont(font$,H%,0) : REM colour=0=black PROC_PLprint(X%, Y%, "abcdefghijklmnopqrstuvwxyz £€\1234567890 ") NEXT Y% -= 24 ENDPROC