PDA

View Full Version : Arrays in QScript



tsrplatelayer
5th March 2015, 19:26
The following doesn't seem to work - please can someone tell me where I am gong wrong. (this is QScript.)


var Styles =[];
Styles[1] = {};
Styles[1].font = New Font();
Styles[1].font.family = "Arial"; //f1 is for left side

I am trying to create an array of font styles.

Where can I find the syntax for new Font()? ideally iwould like to do something like


Styles[1].font = New Font("Arial",12, true,false, false); //Font (style, pointsize, bold, italic, underline)


Any Advice greatly appreciated.

Thanks

Allan

wysota
6th March 2015, 07:56
What is Font? To add an element to an Array you need to either push it explicitly or use empty brackets as the index operator to append the element. See JavaScript docs on Array.

anda_skoa
6th March 2015, 08:42
Where can I find the syntax for new Font()?
Look for the constructor function in the code that you register for handling that type.

Cheers,
_

tsrplatelayer
6th March 2015, 12:12
Thankyou for your replies. let me explain. I inherited this compiled project, the guy that coded it is no longer with us. It includes a QScript 'module' which allows prnted output to be configured. Hiwever the work was poorly done and instead of a nice template this print mode requires raw coade to be modified in order to change that page layout. am trying to work it out and make a few changes.
I had assumed that Font() was a livbrary function but from the commnet from wysota I must conclude it is not.

I think I have managed to work out what it needed
I created a function


function buildstyle ( face, size, bd, it, bg, fg, h ) //face, size, bold, italic, backgroundColor, foregroundColor, row height
{
var ff = new Font (); //create the font
ff.family = face;
ff.pointSize = size;
ff.bold = bd;
ff.italic = it;
this.bg = bg; //set the colours, height and font
this.fg = fg;
this.h = h;
this.fnt = ff;
}


Although I bet there is a tidier way.

and then used it:


var aStyles = [];
aStyles[0] = new buildstyle ("Arial", 12, true, false, "#ffffff", "#000000", 10);
aStyles[1] = new buildstyle ("Arial", 12, false, false, "#ffffff", "#000000", 10);
aStyles[2] = new buildstyle ("Arial", 12, false, true, "#ffffff", "#000000", 10);
aStyles[3] = new buildstyle ("Arial", 12, false, false, "#ffffff", "#000000", 10);
aStyles[4] = new buildstyle ("Arial", 10, false, false, "#ffffff", "#000000", 0);
aStyles[5] = new buildstyle ("Arial", 10, false, false, "#333333", "#ffffff", 7.5);
aStyles[6] = new buildstyle ("Arial", 10, false, false, "#ffffff", "#000000", 7.5);
aStyles[7] = new buildstyle ("Arial", 10, false, false, "#666666", "#ffffff", 7.5);
aStyles[8] = new buildstyle ("Arial", 10, false, false, "#dddddd", "#000000", 15);



This seems to work