Ejemplo n.º 1
0
        /*private void AddParagraph(Chunk chunk, int alignment = Element.ALIGN_LEFT)
         * {
         *  fDocument.Add(new Paragraph(chunk) { Alignment = alignment });
         * }*/

        protected override void InternalGenerate()
        {
            try
            {
                PrepareData();

                fDocument.AddTitle("FamilyBook");
                fDocument.AddSubject("FamilyBook");
                fDocument.AddAuthor("");
                fDocument.AddCreator(GKData.APP_TITLE);
                fDocument.Open();

                BaseFont baseFont = BaseFont.CreateFont(Environment.ExpandEnvironmentVariables(@"%systemroot%\fonts\Times.ttf"), "CP1251", BaseFont.EMBEDDED);
                fTitleFont   = new itFont(baseFont, 30f, Font.BOLD);
                fChapFont    = new itFont(baseFont, 16f, Font.BOLD, BaseColor.BLACK);
                fSubchapFont = new itFont(baseFont, 14f, Font.BOLD, BaseColor.BLACK);
                fLinkFont    = new itFont(baseFont, 8f, Font.UNDERLINE, BaseColor.BLUE);
                fTextFont    = new itFont(baseFont, 8f, Font.NORMAL, BaseColor.BLACK);
                fBoldFont    = new itFont(baseFont, 8f, Font.BOLD, BaseColor.BLACK);
                fSymFont     = new itFont(baseFont, 12f, Font.BOLD, BaseColor.BLACK);

                baseFont = BaseFont.CreateFont(Environment.ExpandEnvironmentVariables(@"%systemroot%\fonts\Calibri.ttf"), "CP1251", BaseFont.EMBEDDED);
                //Font page_font = new Font(base_font, 9f, Font.NORMAL);

                fPdfWriter.PageEvent = new PDFWriterEvents(baseFont, LangMan.LS(LSID.LSID_Page) + ": ");

                float halfpage = (fDocument.Top - fDocument.Bottom - (fTitleFont.Size) * 4) / 2f;
                fDocument.Add(new Paragraph(Chunk.NEWLINE)
                {
                    SpacingAfter = halfpage
                });
                fDocument.Add(new Paragraph(LangMan.LS(LSID.LSID_FamilyBook), fTitleFont)
                {
                    Alignment = Element.ALIGN_CENTER
                });
                fDocument.NewPage();

                Chunk chapChunk = new Chunk(LangMan.LS(LSID.LSID_TableOfContents), fChapFont);
                fDocument.Add(new Paragraph(chapChunk));
                fDocument.Add(new Paragraph(Chunk.NEWLINE));

                chapChunk = new Chunk("1. " + LangMan.LS(LSID.LSID_PersonalRecords), fLinkFont);
                chapChunk.SetLocalGoto("IndividualRecords");
                fDocument.Add(new Paragraph(chapChunk));

                chapChunk = new Chunk("2. " + LangMan.LS(LSID.LSID_Indexes), fLinkFont);
                chapChunk.SetLocalGoto("Catalogs");
                fDocument.Add(new Paragraph(chapChunk));

                // debug

                /*Rectangle pgSize = fDocument.PageSize;
                 *              fDocument.Add(new Paragraph(Chunk.NEWLINE));
                 *              chap_chunk = new Chunk(pgSize.Height.ToString() + " / " + pgSize.Width.ToString(), fChapFont);
                 *              fDocument.Add(new Paragraph(chap_chunk) { Alignment = 1 });*/

                int catNum = 0;
                for (BookCatalog cat = BookCatalog.Catalog_First; cat <= BookCatalog.Catalog_Last; cat++)
                {
                    CatalogProps catProps = BookCatalogs[(int)cat];

                    if (!SkipEmptyCatalogs || catProps.Index.Count > 0)
                    {
                        catNum++;
                        string title = "2." + catNum.ToString() + ". " + catProps.Title;

                        chapChunk = new Chunk(title, fLinkFont);
                        chapChunk.SetLocalGoto(catProps.Sign);
                        fDocument.Add(new Paragraph(chapChunk)
                        {
                            IndentationLeft = 1f
                        });
                    }
                }

                fDocument.NewPage();

                chapChunk = new Chunk(LangMan.LS(LSID.LSID_PersonalRecords), fChapFont);
                chapChunk.SetLocalDestination("IndividualRecords");
                fDocument.Add(new Paragraph(chapChunk)
                {
                    Alignment = 1, SpacingAfter = 20f
                });
                fDocument.Add(new Paragraph(Chunk.NEWLINE));

                SimpleColumnText columnText = new SimpleColumnText(fDocument, fPdfWriter.DirectContent, 3, 10f);
                float            pageWidth  = fDocument.PageSize.Width - fDocument.LeftMargin - fDocument.RightMargin;
                float            colWidth   = (pageWidth - (10f * 2)) / 3;

                char sym = '!';
                int  num = mainIndex.Count;
                for (int i = 0; i < num; i++)
                {
                    string text = mainIndex[i];
                    GEDCOMIndividualRecord iRec = mainIndex.GetObject(i) as GEDCOMIndividualRecord;

                    char isym = text[0];
                    if ((isym >= 'A' && isym <= 'Z') || (isym >= 'А' && isym <= 'Я'))
                    {
                        if (sym != isym)
                        {
                            Paragraph ps = new Paragraph(new Chunk(isym, fSymFont));
                            ps.Alignment = 1;
                            columnText.AddElement(ps);
                            columnText.AddElement(new Paragraph(Chunk.NEWLINE));
                            sym = isym;
                        }
                    }

                    ExposePerson(columnText, iRec, text, colWidth);

                    columnText.AddElement(new Paragraph(Chunk.NEWLINE));
                }

                fDocument.NewPage();

                chapChunk = new Chunk(LangMan.LS(LSID.LSID_Indexes), fChapFont);
                chapChunk.SetLocalDestination("Catalogs");
                fDocument.Add(new Paragraph(chapChunk)
                {
                    Alignment = 1
                });
                fDocument.Add(new Paragraph(Chunk.NEWLINE));

                //SimpleColumnText columnText;
                if (!CatalogNewPages)
                {
                    columnText = new SimpleColumnText(fDocument, fPdfWriter.DirectContent, 3, 10f);
                }

                for (BookCatalog cat = BookCatalog.Catalog_First; cat <= BookCatalog.Catalog_Last; cat++)
                {
                    CatalogProps catProps = BookCatalogs[(int)cat];

                    if (!SkipEmptyCatalogs || catProps.Index.Count > 0)
                    {
                        if (CatalogNewPages)
                        {
                            fDocument.NewPage();
                            columnText = new SimpleColumnText(fDocument, fPdfWriter.DirectContent, 3, 10f);
                        }

                        ExposeCatalog(fDocument, columnText, catProps);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogWrite("FamilyBookExporter.InternalGenerate(): " + ex.Message);
                throw;
            }
        }
Ejemplo n.º 2
0
        protected override void InternalGenerate()
        {
            try
            {
                {
                    string title = "Trees Album";//LangMan.LS(LSID.LSID_TreesAlbum)

                    fDocument.AddTitle(title);
                    fDocument.AddSubject("");
                    fDocument.AddAuthor("");
                    fDocument.AddCreator(GKData.APP_TITLE);
                    fDocument.Open();

                    BaseFont baseFont = BaseFont.CreateFont(Environment.ExpandEnvironmentVariables(@"%systemroot%\fonts\Times.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                    fTitleFont   = new itFont(baseFont, 30f, itFont.BOLD);
                    fChapFont    = new itFont(baseFont, 16f, itFont.BOLD, BaseColor.BLACK);
                    fSubchapFont = new itFont(baseFont, 14f, itFont.BOLD, BaseColor.BLACK);
                    fLinkFont    = new itFont(baseFont, 8f, itFont.UNDERLINE, BaseColor.BLUE);
                    fTextFont    = new itFont(baseFont, 8f, itFont.NORMAL, BaseColor.BLACK);
                    fBoldFont    = new itFont(baseFont, 8f, itFont.BOLD, BaseColor.BLACK);
                    fSymFont     = new itFont(baseFont, 12f, itFont.BOLD, BaseColor.BLACK);

                    float halfpage = (fDocument.Top - fDocument.Bottom - (fTitleFont.Size) * 4) / 2f;
                    fDocument.Add(new Paragraph(Chunk.NEWLINE)
                    {
                        SpacingAfter = halfpage
                    });
                    fDocument.Add(new Paragraph(title, fTitleFont)
                    {
                        Alignment = Element.ALIGN_CENTER
                    });
                    fDocument.NewPage();

                    PreparePatriarchs();

                    var   itPS       = fDocument.PageSize;
                    float pageHeight = itPS.Height;
                    float pageWidth  = itPS.Width;

                    var renderer = new TreeChartPDFRenderer(pageWidth, pageHeight);
                    renderer.SetTarget(fPdfWriter.DirectContent, false);

                    // TODO: replace by local options in TreeChartBox
                    bool prevKinship = GlobalOptions.Instance.ChartOptions.Kinship;
                    GlobalOptions.Instance.ChartOptions.Kinship = false;

                    var treeBox = AppHost.Container.Resolve <ITreeChartBox>();
                    treeBox.SetRenderer(renderer);
                    treeBox.Base       = fBase;
                    treeBox.Options    = GlobalOptions.Instance.ChartOptions;
                    treeBox.DepthLimit = 3;
                    treeBox.Height     = (int)pageHeight;
                    treeBox.Width      = (int)pageWidth;

                    int num = fPatList.Count;
                    for (int i = 0; i < num; i++)
                    {
                        string iName = fPatList[i];
                        GEDCOMIndividualRecord iRec = fPatList.GetObject(i) as GEDCOMIndividualRecord;

                        treeBox.SetScale(1.0f);
                        treeBox.GenChart(iRec, TreeChartKind.ckDescendants, false);

                        ExtSize imageSize   = treeBox.GetImageSize();
                        float   scaleFactor = SysUtils.ZoomToFit(imageSize.Width,
                                                                 imageSize.Height,
                                                                 pageWidth, pageHeight);
                        scaleFactor = (scaleFactor > 1.0f) ? 1.0f : scaleFactor;

                        treeBox.SetScale(scaleFactor);
                        treeBox.RenderStatic(BackgroundMode.bmNone, true);

                        fDocument.NewPage();
                    }

                    GlobalOptions.Instance.ChartOptions.Kinship = prevKinship;
                }
            }
            catch (Exception ex)
            {
                Logger.LogWrite("TreesAlbumExporter.InternalGenerate(): " + ex.Message);
                throw;
            }
        }