using Root.Reports;
using System;
using System.Text;
// Creation date: 08.11.2002
// Checked: 12.12.2002
// Author: Otto Mayer, mot@root.ch
// Version 1.01.00
// copyright (C) 2002 root-software ag - Bürglen Switzerland - www.root.ch; Otto Mayer, Stefan Spirig, Roger Gartenmann
// This library is free software; you can redistribute it and/or modirY it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, version 2.1 of the License.
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You
// should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA www.opensource.org/licenses/lgpl-license.html
namespace Samples.Reports {
/// Flow Layout Manager Sample
class FlowLayoutManagerSample : Report {
//----------------------------------------------------------------------------------------------------x
/// Starts the flow layout manager sample.
public static void Main() {
RT.ViewPDF(new FlowLayoutManagerSample(), "FlowLayoutManagerSample.pdf");
}
//----------------------------------------------------------------------------------------------------x
/// Creates this document
protected override void Create() {
FontDef fd = new FontDef(this, "Arial");
FontProp fp_Title = new FontPropMM(fd, 7.8);
fp_Title.bBold = true;
FontProp fp = new FontPropMM(fd, 2.1);
FontProp fp_Bold = new FontPropMM(fd, 2.1);
fp_Bold.bBold = true;
FlowLayoutManager flm = new FlowLayoutManager(null);
flm.eNewContainer += new FlowLayoutManager.NewContainerEventHandler(NewContainer);
flm.NewContainer();
page_Cur.AddCenteredMM(40, new RepString(fp_Title, "Flow Layout Manager Sample"));
// generate random text
StringBuilder sb = new StringBuilder(20000);
Random random = new Random(unchecked((Int32)DateTime.Now.Ticks));
for (Int32 iItem = 0; iItem < 2000; iItem++) {
Int32 iLength = (Int32)Math.Sqrt(random.NextDouble() * 200) + 2;
for (Int32 iWord = 0; iWord < iLength; iWord++) {
sb.Append((Char)(random.Next((Int32)'z' - (Int32)'a' + 1) + (Int32)'a'));
}
sb.Append(" ");
Int32 iOp = random.Next(40);
if (iOp == 0) {
flm.Add(new RepString(fp_Bold, sb.ToString()));
sb.Length = 0;
}
else if (iOp < 5) {
flm.Add(new RepString(fp, sb.ToString()));
sb.Length = 0;
}
if (iOp == 1) {
flm.NewLine(fp.rLineFeed * 1.5);
}
}
// create footer
foreach (Page page in enum_Page) {
page.AddRightMM(185, 280, new RepString(fp, page.iPageNo.ToString() + " / " + iPageCount.ToString()));
}
}
//----------------------------------------------------------------------------------------------------x
/// Creates a container on a new page.
/// Sender
/// Event argument
private void NewContainer(Object oSender, FlowLayoutManager.NewContainerEventArgs ea) {
new Page(this);
if (page_Cur.iPageNo == 1) {
StaticContainer sc = new StaticContainerMM(155, 215);
page_Cur.AddMM(30, 55, sc);
ea.flm.SetContainer(sc);
}
else {
StaticContainer sc = new StaticContainerMM(155, 230);
page_Cur.AddMM(30, 40, sc);
ea.flm.SetContainer(sc);
}
}
}
}