public Stream Generate(
            Stream designFile, int[] chapters, bool drawRules, bool drawPageBoxes,
            string mimeType,
            string photoUri, string resourceUri)             //TODO: return byte[]?
        {
            _reportMimeType = mimeType;
            _fonts.Load();

            //	Set up a reference resolver
            DocumentStructure structure     = new DocumentStructure(_documentId, _unitOfWork);
            DocTaggedObjects  taggedObjects = new DocTaggedObjects(_documentId, _unitOfWork);

            _resolver = new Resolver(structure, taggedObjects, _tracePathDelegate);

            //	Load the report structure as it's designed
            _design = new ReportDesign(designFile, _logger);
            _report = _design.Load(this);
            _report.Validate();

            _report.Subset(chapters);

            //	Load properties from the database and prepare them for matching
            //	against expansion strings in text
            LoadProperties();

            //	Resolve all source references from ref-to-template-object
            //	to ref-to-concrete-object, duplicating layouts as necessary
            TraceLayoutActivity("Resolve references");
            _report.ResolveSublayoutReferences();
            TraceLayoutActivity("Validate conditions");
            _report.ValidateConditions();
            TraceLayoutActivity("Apply static conditions");
            _report.ApplyStaticLayoutConditions();

            //	Load content
            TraceLayoutActivity("Load content");
            _report.LoadContent();
            _report.MergeContent(null);

            //	Remove content based on conditions
            TraceLayoutActivity("Apply dynamic conditions");
            _report.ApplyDynamicConditions();
//			TraceLayoutActivity("Remove empty layouts");
//			layout.RemoveEmptyLayouts();
//			TraceLayoutActivity("Redraft");
//			layout.Redraft();

//			//	Measure and cut content
//			TraceLayoutActivity("Measure and cut content");
//			List<PageLayout> pages = layout.LayOut();

            ReportRenderer renderer = null;

            switch (_reportMimeType)
            {
            case Demon.Core.MimeType.PDF:
                renderer = new PDF();
                break;

            case Demon.Core.MimeType.Word:
                renderer = new Word();
                break;

            case Demon.Core.MimeType.HTML:
                renderer = new HTML();
                break;

            case Demon.Core.MimeType.SVG:
                renderer = new SVG();
                break;

            default:
                throw new ArgumentOutOfRangeException($"Unsupported report content type '{_reportMimeType}'.");
            }

            Stream report = renderer.Render(
                _report, _documentId, _design.Id, _design.Name,
                _documentVersion, _timestamp,
                photoUri, resourceUri, drawRules, drawPageBoxes, this, this);

            return(report);
        }