Hey guys thanks for the code and input.
The route I think I'm taking because it's html text and formatted, is to
keep trimming at <br>'s and checking if page is not too high.
The page to print symbol I'm using has an aspect ratio for an A4 page (1:
1.414) and one big html text field (with 20px blank padding around it)
Here's the code (which works) so far:
private function processPagesToPrint():Void
{
_pagesToPrint=[];
_excessText=entireHtmlFormattedTextContent;// can be a few lines or
pages
constructPage();
}
private function constructPage():Void
{
var pageToPrint=this.attachMovie
('pageToPrint_justText','p'+(_pagesToPrint.length+1),getNextHighestDepth(),{_x:720});
_pagesToPrint.push(pageToPrint);
var tf:TextField=pageToPrint.tf;
tf.styleSheet=STYLESHEET;
tf.htmlText=_excessText;
// if the page is not too high without having to trim we're good to
go
if(tf.textHeight<=tf._height){
trace('pages processed, and number to print
='+_pagesToPrint.length);
// display this info to user so they know before they hit print
}
// otherwise we'll trim and then construct another page
else{
_excessText="";
trimPage(tf);
}
}
private function trimPage(tf:TextField):Void
{
// cut the text after the last '<br>'
var str:String=tf.htmlText;
var lastBr=str.lastIndexOf('<br>');
tf.htmlText=str.substring(0,lastBr);
_excessText=str.substring(lastBr,str.length)+_excessText;
// if page is trimmed enough
if(tf.textHeight<=tf._height){
constructPage();
}
// otherwise keep trimmin
else{
trimPage(tf);
}
}
private function printPages():Void
{
_printJob=new PrintJob();
if(_printJob.start()){
var len=_pagesToPrint.length;
for(var i=0;i<len;i++){
_printJob.addPage(_pagesToPrint[i]);
}
_printJob.send();
}
}
On 8/18/06, Danny Kodicek <[EMAIL PROTECTED]> wrote:
> How can you efficiently fill a textfield to the point in which you know
it
> is completely full?
Here's a revised version using a word array. But as I said, including
formatting would be more difficult and significantly slower. I tend to
agree
with Meinte that in this case you're better off using scrolling (although
the function below may be of interest in any case)
function fillField(fld:TextField, txt:Array, curr:String) {
if (curr == undefined) {
curr = "";
}
var len:Number = txt.length;
if (len == 0) {
} else if (len == 1) {
fld.text = curr + txt[0];
if (fld.textHeight > fld._height) {
fld.text = curr;
}
} else {
var half:Array = txt.slice(0, len / 2);
fld.text = curr + half.join(" ");
if (fld.textHeight > fld._height) {
fillField(fld, half, curr);
} else {
fillField(fld, txt.slice(len / 2), fld.text + "
");
}
}
}
I tested it with
fillField(test, src.text.split(" "));
Danny
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com