Пример #1
0
        public static double ToPoint(this StringValue?value, double ifNull = 0)
        {
            if (value is null)
            {
                return(ifNull);
            }

            var(v, u) = value.ToValueWithUnit();
            switch (u)
            {
            case "mm":
                return(XUnit.FromMillimeter(v));

            case "cm":
                return(XUnit.FromCentimeter(v));

            case "in":
                return(0);    // v.InchToPoint();

            case "pt":
                return(v.DxaToPoint());

            case "pi":
                return(XUnit.FromPresentation(v));

            case "pc":
            default:
                throw new Exception($"Unhandled string value: {value}");
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="style"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        private static XPen ToXPen(Core2D.BaseStyle style, Func <double, double> scale)
        {
            var pen = new XPen(ToXColor(style.Stroke), XUnit.FromPresentation(style.Thickness));

            switch (style.LineCap)
            {
            case Core2D.LineCap.Flat:
                pen.LineCap = XLineCap.Flat;
                break;

            case Core2D.LineCap.Square:
                pen.LineCap = XLineCap.Square;
                break;

            case Core2D.LineCap.Round:
                pen.LineCap = XLineCap.Round;
                break;
            }
            if (style.Dashes != null)
            {
                // TODO: Convert to correct dash values.
                pen.DashPattern = style.Dashes;
            }
            pen.DashOffset = style.DashOffset;
            return(pen);
        }
Пример #3
0
        internal PdfPage CreatePage(PdfDocument doc, FixedPage fixedPage)
        {
            PdfPage page = doc.Pages.Add();

            page.Width  = XUnit.FromPresentation(fixedPage.Width);
            page.Height = XUnit.FromPresentation(fixedPage.Height);
            return(page);
        }
Пример #4
0
        /// <summary>
        /// HACK
        /// </summary>
        public PdfPage CreatePage(int xpsPageIndex)
        {
            FixedPage fixedPage = xpsDocument.GetDocument().GetFixedPage(xpsPageIndex);

            PdfPage page = pdfDocument.AddPage();

            page.Width  = XUnit.FromPresentation(fixedPage.Width);
            page.Height = XUnit.FromPresentation(fixedPage.Height);
            return(page);
        }
Пример #5
0
        private void ExportCanvasToPDF()
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.FileName = Strings.ResStrings.File + ".pdf";
            saveFileDialog.Filter   = Strings.FormatStrings.PDF + "| *.pdf|" + Strings.ResStrings.AllFiles + "| *.*";

            if (saveFileDialog.ShowDialog() == true)
            {
                PdfDocument pdf = new PdfDocument();

                for (int i = 0; i < data.pages.Count; i++)
                {
                    Canvas can = CanvasSaveLoad.LoadSpecificCanvas(data, i);
                    CanvasSaveLoad.ToPresentationMode(can);
                    CanvasSaveLoad.SimulateCanvas(can);


                    can.UpdateLayout();
                    Size size = new Size();
                    can.Measure(size);
                    can.Arrange(new Rect(size));

                    BitmapSource bs;

                    if (RB_BQuality.IsChecked == true)
                    {
                        bs = (BitmapSource)ImageWorker.ByteDataToImage(CanvasWriter.SaveCanvasToImgSimulateFullPng(can));
                    }
                    else
                    {
                        int quality = 90;

                        int.TryParse(TB_Quality.Text, out quality);

                        bs = (BitmapSource)ImageWorker.ByteDataToImage(CanvasWriter.SaveCanvasToImgSimulateFullJpg(can, quality));
                    }

                    var ximg = XImage.FromBitmapSource(bs);
                    ximg.Interpolate = false;

                    PdfPage pdfPage = pdf.AddPage();
                    pdfPage.Width  = XUnit.FromPresentation(data.CanvasW);
                    pdfPage.Height = XUnit.FromPresentation(data.CanvasH);
                    XGraphics xgr = XGraphics.FromPdfPage(pdfPage);

                    xgr.DrawImage(
                        ximg,
                        0, 0, pdfPage.Width, pdfPage.Height);
                }

                pdf.Info.Creator      = Strings.ResStrings.AppName;
                pdf.Info.CreationDate = DateTime.Now;
                pdf.Info.Subject      = TB_Subject.Text;
                pdf.Info.Author       = TB_Author.Text;
                pdf.Info.Title        = TB_Title.Text;
                pdf.Info.Keywords     = TB_Keywords.Text;

                pdf.Save(saveFileDialog.FileName);

                IsExported = true;
                Close();
            }
        }
Пример #6
0
        private void ExportOutputToPDF()
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.FileName = Strings.ResStrings.File + ".pdf";
            saveFileDialog.Filter   = Good_Teacher.Strings.FormatStrings.PDF + "| *.pdf|" + Good_Teacher.Strings.ResStrings.AllFiles + "| *.*";

            if (saveFileDialog.ShowDialog() == true)
            {
                PdfDocument pdf = new PdfDocument();

                for (int i = 0; i < output.Pages.Count; i++)
                {
                    InkCanvas canvas = new InkCanvas();
                    canvas.Width  = output.W;
                    canvas.Height = output.H;
                    canvas.Margin = new Thickness(0, 0, 0, 0);

                    if (output.Pages[i].strokeCollection != null)
                    {
                        using (Stream stream = new MemoryStream(output.Pages[i].strokeCollection))
                        {
                            StrokeCollection strokes = new StrokeCollection(stream);
                            canvas.Strokes.Add(strokes);
                        }
                    }

                    canvas.Background = new ImageBrush(GetImage(output.Pages[i].Image));

                    BitmapSource bs;

                    if (RB_BQuality.IsChecked == true)
                    {
                        bs = (BitmapSource)ImageWorker.ByteDataToImage(SaveInkCanvasToPng(canvas));
                    }
                    else
                    {
                        int quality = 90;

                        int.TryParse(TB_Quality.Text, out quality);

                        bs = (BitmapSource)ImageWorker.ByteDataToImage(SaveInkCanvasToJpg(canvas, quality));
                    }

                    var ximg = XImage.FromBitmapSource(bs);
                    ximg.Interpolate = false;

                    PdfPage pdfPage = pdf.AddPage();
                    pdfPage.Width  = XUnit.FromPresentation(output.W);
                    pdfPage.Height = XUnit.FromPresentation(output.H);
                    XGraphics xgr = XGraphics.FromPdfPage(pdfPage);


                    xgr.DrawImage(
                        ximg,
                        0, 0, pdfPage.Width, pdfPage.Height);

                    /*
                     * BitmapSource bs = (BitmapSource)GetImage(output.Pages[i].Image);
                     *
                     * var ximg = XImage.FromBitmapSource(bs);
                     * ximg.Interpolate = false;
                     *
                     * PdfPage pdfPage = pdf.AddPage();
                     * pdfPage.Width = XUnit.FromPresentation(output.W);
                     * pdfPage.Height = XUnit.FromPresentation(output.H);
                     * XGraphics xgr = XGraphics.FromPdfPage(pdfPage);
                     *
                     *
                     * xgr.DrawImage(
                     * ximg,
                     * 0, 0, pdfPage.Width, pdfPage.Height);
                     */
                }

                pdf.Info.Creator      = Strings.ResStrings.AppName;
                pdf.Info.CreationDate = DateTime.Now;
                pdf.Info.Subject      = TB_Subject.Text;
                pdf.Info.Author       = TB_Author.Text;
                pdf.Info.Title        = TB_Title.Text;
                pdf.Info.Keywords     = TB_Keywords.Text;

                pdf.Save(saveFileDialog.FileName);

                IsExported = true;
                Close();
            }
        }