printer.lzx
<library>
<class name="printer" extends="node">
<passthrough when="$as3">
import flash.printing.PrintJob;
import flash.geom.Rectangle;
import flash.printing.PrintJobOptions;
</passthrough>
<doc>
<tag name="shortdesc"><text>Adds the capability to print.</text></tag>
<text>
<p><tagname>printer</tagname> is a <sgmltag class="element" role="LzNode"><node></sgmltag> that gives access to the printer.</p>
<p>The DHTML runtime currently only supports send().</p>
<example><programlisting class="code">
<canvas>
<view id="main" x="10" y="10">
<simplelayout axis="y" spacing="10"/>
<view>
<simplelayout axis="y" spacing="5"/>
<button text="draw line from (10,10) to (50, 50)">
<handler name="onclick">
main.drawLine(drawView, 10, 10, 50, 50);
</handler>
</button>
<button text="draw line from (100,100) to (150, -300)">
<handler name="onclick">
main.drawLine(drawView, 100, 100, 150, -300);
</handler>
</button>
<button text="draw line from (70,70) to (70, -20000)">
<handler name="onclick">
main.drawLine(drawView, 70, 70, 70, -20000);
</handler>
</button>
<button text="Print">
<handler name="onclick">
main.printView();
</handler>
</button>
</view>
<view id="wrapper" width="300" height="200" clip="true" bgcolor="0xCCCCCC">
<drawview id="drawView" width="300" height="200">
</drawview>
</view>
<method name="drawLine" args="drawview, xFrom, yFrom, xTo, yTo">
drawview.beginPath();
drawview.moveTo(xFrom, yFrom);
drawview.lineTo(xTo, yTo);
drawview.strokeStyle = 0x000000;
drawview.lineWidth = 2;
drawview.stroke();
drawview.closePath()
</method>
<printer id="printer"/>
<method name="printView">
if(printer.start()){
printer.addPage(drawView, 0, 0, drawView.width, drawView.height);
printer.send();
}
</method>
</view>
</canvas>
</programlisting></example>
<p><classname>printer</classname> extends <sgmltag class="element" role="LzNode"><node></sgmltag>,
which is the fundamental class in LZX.</p>
</text>
</doc>
<method name="reset">
if ($dhtml) {
//TODO?
} else {
this.__printJob = new PrintJob();
}
</method>
<method name="start">
if ($dhtml) {
// the user can always print
return true;
} else {
this.reset();
return this.__printJob.start();
}
</method>
<method name="send">
if ($dhtml) {
window.print();
} else {
if (! this.__printJob) {
return;
} else {
this.__printJob.send();
}
}
</method>
<method name="addPage" args="view:LzView, minX=null, minY=null, maxX=null, maxY=null, printasbitmap=null">
if ($dhtml) {
//TODO?
if ($debug) {
Debug.warn('%w does not support addPage(). Instead, the entire contents of the web page will print when send() is called.', $runtime);
}
} else {
if (! this.__printJob) return;
if (minX == null && minY == null && maxX == null && maxY == null) {
var pos = null;
} else {
// Set missing values to sensible defaults
if (minX == null) minX = 0;
if (minY == null) minY = 0;
if (maxX == null) maxX = view.width;
if (maxY == null) maxY = view.heightwidth;
if ($as3) {
var pos = new Rectangle(minX, minY, maxX, maxY);
} else {
var pos = {xMin: minX, yMin: minY, xMax: maxX, yMax: maxY};
}
}
if (printasbitmap == null) {
var opts = null;
} else {
if ($as3) {
// !@#&!@#& as3
var opts = new PrintJobOptions();
opts.printAsBitmap = printasbitmap;
} else {
var opts = {printAsBitmap: printasbitmap};
}
}
//Debug.warn('addPage', pos, opts);
this.__printJob.addPage(view.getDisplayObject(), pos, opts);
}
</method>
</class>
</library>
Cross References
Classes
- <class name="printer" extends="node">