예제 #1
0
        // ***********************************************************************
        // C1PdfDocuments for Rect
        // ***********************************************************************
        // measure a paragraph, skip a page if it won't fit, render it into a rectangle,
        // and update the rectangle for the next paragraph.
        //
        // optionally mark the paragraph as an outline entry and as a link target.
        //
        // this routine will not break a paragraph across pages. for that, see the Text Flow sample.
        //
        public static Rect RenderParagraph(this C1PdfDocument pdf, string text, Font font, Rect rcPage, Rect rc, bool outline, bool linkTarget)
        {
            // if it won't fit this page, do a page break
            rc.Height = pdf.MeasureString(text, font, rc.Width).Height;
            if (rc.Bottom > rcPage.Bottom)
            {
                pdf.NewPage();
                rc.Y = rcPage.Top;
            }

            // draw the string
            pdf.DrawString(text, font, Colors.Black, rc);

            // show bounds (to check word wrapping)
            //var p = Pen.GetPen(Colors.Orange);
            //pdf.DrawRectangle(p, rc);

            // add headings to outline
            if (outline)
            {
                pdf.DrawLine(Colors.Black, rc.X, rc.Y, rc.Right, rc.Y);
                pdf.AddBookmark(text, 0, rc.Y);
            }

            // add link target
            if (linkTarget)
            {
                pdf.AddTarget(text, rc);
            }

            // update rectangle for next time
            rc = Offset(rc, 0, rc.Height);
            return rc;
        }
예제 #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // get stream to save to
            var dlg = new SaveFileDialog();
            dlg.DefaultExt = ".pdf";
            var dr = dlg.ShowDialog();
            if (!dr.HasValue || !dr.Value)
            {
                return;
            }

            // get sender button
            var btn = sender as Button;

            // create document
            var pdf = new C1PdfDocument(PaperKind.Letter);
            pdf.Clear();

            // set document info
            var di = pdf.DocumentInfo;
            di.Author = "ComponentOne";
            di.Subject = "C1.WPF.Pdf demo.";
            di.Title = "Experimental VisualTree Exporter for PDF";

            // walk visual tree
            CreateDocumentVisualTree(pdf, content);

            // render footers
            // this reopens each page and adds content to them (now we know the page count).
            var font = new Font("Arial", 8, PdfFontStyle.Bold);
            var fmt = new StringFormat();
            fmt.Alignment = HorizontalAlignment.Right;
            fmt.LineAlignment = VerticalAlignment.Bottom;
            for (int page = 0; page < pdf.Pages.Count; page++)
            {
                pdf.CurrentPage = page;
                var text = string.Format("C1.WPF.Pdf: {0}, page {1} of {2}",
                    di.Title,
                    page + 1,
                    pdf.Pages.Count);
                pdf.DrawString(
                    text,
                    font,
                    Colors.DarkGray,
                    PdfUtils.Inflate(pdf.PageRectangle, -72, -36),
                    fmt);
            }

            // save document
            using (var stream = dlg.OpenFile())
            {
                pdf.Save(stream);
            }
            MessageBox.Show("Pdf Document saved to " + dlg.SafeFileName);
        }
예제 #3
0
        public FontMetrics(Font font)
        {
            this.Font = font;

            // Create the TextBlock for all measurements
            txtblk = new TextBlock
            {
                FontFamily = this.Font.FontFamily,
                FontStyle = this.Font.FontStyle,
                FontWeight = this.Font.FontWeight,
                FontSize = EmSize
            };

            // Store the character height
            txtblk.Text = " ";
            height = Math.Ceiling(dpiSize * font.FontFamily.LineSpacing);// txtblk.ActualHeight / EmSize;
        }
예제 #4
0
		public static void ApplyFont(this TextBlock self, Font font)
		{
			if (font.UseNamedSize)
			{
				switch (font.NamedSize)
				{
					case NamedSize.Micro:
						self.FontSize = (double)System.Windows.Application.Current.Resources["PhoneFontSizeSmall"] - 3;
						break;
					case NamedSize.Small:
						self.FontSize = (double)System.Windows.Application.Current.Resources["PhoneFontSizeSmall"];
						break;
					case NamedSize.Medium:
						self.FontSize = (double)System.Windows.Application.Current.Resources["PhoneFontSizeNormal"];
						// use normal instead of  medium as this is the default
						break;
					case NamedSize.Large:
						self.FontSize = (double)System.Windows.Application.Current.Resources["PhoneFontSizeLarge"];
						break;
					default:
						throw new ArgumentOutOfRangeException();
				}
			}
			else
				self.FontSize = font.FontSize;

			if (!string.IsNullOrEmpty(font.FontFamily))
				self.FontFamily = new FontFamily(font.FontFamily);
			else
				self.FontFamily = (FontFamily)System.Windows.Application.Current.Resources["PhoneFontFamilyNormal"];

			if (font.FontAttributes.HasFlag(FontAttributes.Italic))
				self.FontStyle = FontStyles.Italic;
			else
				self.FontStyle = FontStyles.Normal;

			if (font.FontAttributes.HasFlag(FontAttributes.Bold))
				self.FontWeight = FontWeights.Bold;
			else
				self.FontWeight = FontWeights.Normal;
		}
예제 #5
0
        public override void RenderCustomChart(Character character, string chartName, System.Drawing.Graphics g, int width, int height)
        {
            Rectangle rectSubPoint;
            System.Drawing.Drawing2D.LinearGradientBrush brushSubPointFill;
            System.Drawing.Drawing2D.ColorBlend blendSubPoint;

            CalculationOptionsMage calculationOptions = character.CalculationOptions as CalculationOptionsMage;

            Font fontLegend = new Font("Verdana", 10f, GraphicsUnit.Pixel);
            int legendY;

            Brush[] brushSubPoints;
            Color[] colorSubPointsA;
            Color[] colorSubPointsB;

            float graphStart;
            float graphWidth;
            float graphTop;
            float graphBottom;
            float graphHeight;
            float maxScale;
            float graphEnd;
            float[] ticks;
            Pen black200 = new Pen(Color.FromArgb(200, 0, 0, 0));
            Pen black150 = new Pen(Color.FromArgb(150, 0, 0, 0));
            Pen black75 = new Pen(Color.FromArgb(75, 0, 0, 0));
            Pen black50 = new Pen(Color.FromArgb(50, 0, 0, 0));
            Pen black25 = new Pen(Color.FromArgb(25, 0, 0, 0));
            StringFormat formatTick = new StringFormat();
            formatTick.LineAlignment = StringAlignment.Far;
            formatTick.Alignment = StringAlignment.Center;
            Brush black200brush = new SolidBrush(Color.FromArgb(200, 0, 0, 0));
            Brush black150brush = new SolidBrush(Color.FromArgb(150, 0, 0, 0));
            Brush black75brush = new SolidBrush(Color.FromArgb(75, 0, 0, 0));
            Brush black50brush = new SolidBrush(Color.FromArgb(50, 0, 0, 0));
            Brush black25brush = new SolidBrush(Color.FromArgb(25, 0, 0, 0));

            string[] statNames = new string[] { "11.7 Spell Power", "4 Mana per 5 sec", "10 Crit Rating", "10 Haste Rating", "10 Hit Rating", "10 Intellect", "10 Spirit" };
            Color[] statColors = new Color[] { Color.FromArgb(255, 255, 0, 0), Color.DarkBlue, Color.FromArgb(255, 255, 165, 0), Color.Olive, Color.FromArgb(255, 154, 205, 50), Color.Aqua, Color.FromArgb(255, 0, 0, 255) };

            DisplayCalculations calculations = calculationOptions.Calculations;

            List<float> X = new List<float>();
            List<ComparisonCalculationBase[]> Y = new List<ComparisonCalculationBase[]>();

            height -= 2;

            Stats[] statsList = new Stats[] {
                        new Stats() { SpellPower = 1.17f },
                        new Stats() { Mp5 = 0.4f },
                        new Stats() { CritRating = 1 },
                        new Stats() { HasteRating = 1 },
                        new Stats() { HitRating = 1 },
                        new Stats() { Intellect = 1 },
                        new Stats() { Spirit = 1 },
                    };

            switch (chartName)
            {
                case "Stats Graph":
                    Base.Graph.RenderStatsGraph(g, width, height, character, statsList, statColors, 100, "", "Dps Rating", Base.Graph.Style.Mage);
                    break;
                case "Proc Uptime":
                    List<SpecialEffect> effectList = new List<SpecialEffect>();
                    effectList.AddRange(calculations.SpellPowerEffects);
                    effectList.AddRange(calculations.HasteRatingEffects);

                    #region Legend
                    legendY = 2;

                    Color[] colors = new Color[] {
                        Color.FromArgb(255,202,180,96), 
                        Color.FromArgb(255,101,225,240),
                        Color.FromArgb(255,0,4,3), 
                        Color.FromArgb(255,238,238,30),
                        Color.FromArgb(255,45,112,63), 
                        Color.FromArgb(255,121,72,210), 
                        Color.FromArgb(255,217,100,54), 
                        Color.FromArgb(255,210,72,195), 
                        Color.FromArgb(255,206,189,191), 
                        Color.FromArgb(255,255,0,0), 
                        Color.FromArgb(255,0,255,0), 
                        Color.FromArgb(255,0,0,255), 
                    };

                    brushSubPoints = new Brush[effectList.Count];
                    colorSubPointsA = new Color[effectList.Count];
                    colorSubPointsB = new Color[effectList.Count];
                    for (int i = 0; i < effectList.Count; i++)
                    {
                        Color baseColor = colors[i];
                        brushSubPoints[i] = new SolidBrush(Color.FromArgb(baseColor.R / 2, baseColor.G / 2, baseColor.B / 2));
                        colorSubPointsA[i] = Color.FromArgb(baseColor.A / 2, baseColor.R / 2, baseColor.G / 2, baseColor.B / 2);
                        colorSubPointsB[i] = Color.FromArgb(baseColor.A / 2, baseColor);
                    }

                    for (int i = 0; i < effectList.Count; i++)
                    {
                        g.DrawLine(new Pen(colors[i]), new Point(20, legendY + 7), new Point(50, legendY + 7));
                        //g.DrawString(effectList[i].ToString(), fontLegend, Brushes.Black, new Point(60, legendY));

                        legendY += 16;
                    }

                    #endregion

                    #region Graph Ticks
                    graphStart = 30f;
                    graphWidth = width - 50f;
                    graphTop = legendY;
                    graphBottom = height - 4 - 4 * effectList.Count;
                    graphHeight = graphBottom - graphTop - 40;
                    maxScale = calculationOptions.FightDuration;
                    graphEnd = graphStart + graphWidth;
                    ticks = new float[] {(float)Math.Round(graphStart + graphWidth * 0.5f),
                            (float)Math.Round(graphStart + graphWidth * 0.75f),
                            (float)Math.Round(graphStart + graphWidth * 0.25f),
                            (float)Math.Round(graphStart + graphWidth * 0.125f),
                            (float)Math.Round(graphStart + graphWidth * 0.375f),
                            (float)Math.Round(graphStart + graphWidth * 0.625f),
                            (float)Math.Round(graphStart + graphWidth * 0.875f)};

                    for (int i = 0; i <= 10; i++)
                    {
                        float h = (float)Math.Round(graphBottom - graphHeight * i / 10.0);
                        g.DrawLine(black25, graphStart - 4, h, graphEnd, h);
                        //g.DrawLine(black200, graphStart - 4, h, graphStart, h);

                        g.DrawString((i / 10.0).ToString("F1"), fontLegend, black200brush, graphStart - 15, h + 6, formatTick);
                    }

                    g.DrawLine(black150, ticks[1], graphTop + 36, ticks[1], graphTop + 39);
                    g.DrawLine(black150, ticks[2], graphTop + 36, ticks[2], graphTop + 39);
                    g.DrawLine(black75, ticks[3], graphTop + 36, ticks[3], graphTop + 39);
                    g.DrawLine(black75, ticks[4], graphTop + 36, ticks[4], graphTop + 39);
                    g.DrawLine(black75, ticks[5], graphTop + 36, ticks[5], graphTop + 39);
                    g.DrawLine(black75, ticks[6], graphTop + 36, ticks[6], graphTop + 39);
                    g.DrawLine(black75, graphEnd, graphTop + 41, graphEnd, height - 4);
                    g.DrawLine(black75, ticks[0], graphTop + 41, ticks[0], height - 4);
                    g.DrawLine(black50, ticks[1], graphTop + 41, ticks[1], height - 4);
                    g.DrawLine(black50, ticks[2], graphTop + 41, ticks[2], height - 4);
                    g.DrawLine(black25, ticks[3], graphTop + 41, ticks[3], height - 4);
                    g.DrawLine(black25, ticks[4], graphTop + 41, ticks[4], height - 4);
                    g.DrawLine(black25, ticks[5], graphTop + 41, ticks[5], height - 4);
                    g.DrawLine(black25, ticks[6], graphTop + 41, ticks[6], height - 4);
                    g.DrawLine(black200, graphStart - 4, graphTop + 40, graphEnd + 4, graphTop + 40);
                    g.DrawLine(black200, graphStart, graphTop + 36, graphStart, height - 4);
                    g.DrawLine(black200, graphEnd, graphTop + 36, graphEnd, height - 4);
                    g.DrawLine(black200, graphStart - 4, graphBottom, graphEnd + 4, graphBottom);

                    g.DrawString(TimeFormat(0f), fontLegend, black200brush, graphStart, graphTop + 36, formatTick);
                    g.DrawString(TimeFormat(maxScale), fontLegend, black200brush, graphEnd, graphTop + 36, formatTick);
                    g.DrawString(TimeFormat(maxScale * 0.5f), fontLegend, black200brush, ticks[0], graphTop + 36, formatTick);
                    g.DrawString(TimeFormat(maxScale * 0.75f), fontLegend, black150brush, ticks[1], graphTop + 36, formatTick);
                    g.DrawString(TimeFormat(maxScale * 0.25f), fontLegend, black150brush, ticks[2], graphTop + 36, formatTick);
                    g.DrawString(TimeFormat(maxScale * 0.125f), fontLegend, black75brush, ticks[3], graphTop + 36, formatTick);
                    g.DrawString(TimeFormat(maxScale * 0.375f), fontLegend, black75brush, ticks[4], graphTop + 36, formatTick);
                    g.DrawString(TimeFormat(maxScale * 0.625f), fontLegend, black75brush, ticks[5], graphTop + 36, formatTick);
                    g.DrawString(TimeFormat(maxScale * 0.875f), fontLegend, black75brush, ticks[6], graphTop + 36, formatTick);
                    #endregion

                    for (int i = 0; i < effectList.Count; i++)
                    {
                        float procs = 0.0f;
                        float triggers = 0.0f;
                        for (int j = 0; j < calculations.SolutionVariable.Count; j++)
                        {
                            if (calculations.Solution[j] > 0)
                            {
                                Cycle c = calculations.SolutionVariable[j].Cycle;
                                if (c != null)
                                {
                                    switch (effectList[i].Trigger)
                                    {
                                        case Trigger.DamageSpellCrit:
                                        case Trigger.SpellCrit:
                                            triggers += (float)calculations.Solution[j] * c.Ticks / c.CastTime;
                                            procs += (float)calculations.Solution[j] * c.CritProcs / c.CastTime;
                                            break;
                                        case Trigger.DamageSpellHit:
                                        case Trigger.SpellHit:
                                            triggers += (float)calculations.Solution[j] * c.Ticks / c.CastTime;
                                            procs += (float)calculations.Solution[j] * c.HitProcs / c.CastTime;
                                            break;
                                        case Trigger.SpellMiss:
                                            triggers += (float)calculations.Solution[j] * c.Ticks / c.CastTime;
                                            procs += (float)calculations.Solution[j] * (1 - c.HitProcs) / c.CastTime;
                                            break;
                                        case Trigger.DamageSpellCast:
                                        case Trigger.SpellCast:
                                            if (effectList[i].Stats.ValkyrDamage > 0)
                                            {
                                                triggers += (float)calculations.Solution[j] * c.CastProcs2 / c.CastTime;
                                                procs += (float)calculations.Solution[j] * c.CastProcs2 / c.CastTime;
                                            }
                                            else
                                            {
                                                triggers += (float)calculations.Solution[j] * c.CastProcs / c.CastTime;
                                                procs += (float)calculations.Solution[j] * c.CastProcs / c.CastTime;
                                            }
                                            break;
                                        case Trigger.MageNukeCast:
                                            triggers += (float)calculations.Solution[j] * c.NukeProcs / c.CastTime;
                                            procs += (float)calculations.Solution[j] * c.NukeProcs / c.CastTime;
                                            break;
                                        case Trigger.DamageDone:
                                        case Trigger.DamageOrHealingDone:
                                            triggers += (float)calculations.Solution[j] * c.DamageProcs / c.CastTime;
                                            procs += (float)calculations.Solution[j] * c.DamageProcs / c.CastTime;
                                            break;
                                        case Trigger.DoTTick:
                                            triggers += (float)calculations.Solution[j] * c.DotProcs / c.CastTime;
                                            procs += (float)calculations.Solution[j] * c.DotProcs / c.CastTime;
                                            break;
                                    }
                                }
                            }
                        }
                        float triggerInterval = calculations.CalculationOptions.FightDuration / triggers;
                        float triggerChance = Math.Min(1.0f, procs / triggers);

                        int steps = 200;
                        PointF[] plot = new PointF[steps + 1];
                        for (int tick = 0; tick <= steps; tick++)
                        {
                            float time = tick / (float)steps * calculations.CalculationOptions.FightDuration;
                            plot[tick] = new PointF(graphStart + time / maxScale * graphWidth, graphBottom - graphHeight * effectList[i].GetUptimePlot(triggerInterval, triggerChance, 3.0f, time));
                        }

                        g.DrawLines(new Pen(colors[i]), plot);

                        g.DrawString(string.Format("{0} (average uptime {1:F}%)", effectList[i], effectList[i].GetAverageUptime(triggerInterval, triggerChance, 3.0f, calculations.CalculationOptions.FightDuration) * 100), fontLegend, Brushes.Black, new Point(60, 2 + i * 16));
                    }
                    break;
                case "Sequence Reconstruction":

                    if (calculationOptions.SequenceReconstruction == null)
                    {
                        g.DrawString("Sequence reconstruction data is not available.", fontLegend, Brushes.Black, 2, 2);
                    }
                    else
                    {
        #region Legend
                        legendY = 2;

                        List<EffectCooldown> cooldownList = calculationOptions.Calculations.CooldownList;

                        brushSubPoints = new Brush[cooldownList.Count];
                        colorSubPointsA = new Color[cooldownList.Count];
                        colorSubPointsB = new Color[cooldownList.Count];
                        for (int i = 0; i < cooldownList.Count; i++)
                        {
                            Color baseColor = cooldownList[i].Color;
                            brushSubPoints[i] = new SolidBrush(Color.FromArgb(baseColor.R / 2, baseColor.G / 2, baseColor.B / 2));
                            colorSubPointsA[i] = Color.FromArgb(baseColor.A / 2, baseColor.R / 2, baseColor.G / 2, baseColor.B / 2);
                            colorSubPointsB[i] = Color.FromArgb(baseColor.A / 2, baseColor);
                        }
                        StringFormat formatSubPoint = new StringFormat();
                        formatSubPoint.Alignment = StringAlignment.Center;
                        formatSubPoint.LineAlignment = StringAlignment.Center;

                        int maxWidth = 1;
                        for (int i = 0; i < cooldownList.Count; i++)
                        {
                            string subPointName = cooldownList[i].Name;
                            int widthSubPoint = (int)Math.Ceiling(g.MeasureString(subPointName, fontLegend).Width + 2f);
                            if (widthSubPoint > maxWidth) maxWidth = widthSubPoint;
                        }
                        for (int i = 0; i < cooldownList.Count; i++)
                        {
                            string cooldownName = cooldownList[i].Name;
                            rectSubPoint = new Rectangle(2, legendY, maxWidth, 16);
                            blendSubPoint = new System.Drawing.Drawing2D.ColorBlend(3);
                            blendSubPoint.Colors = new Color[] { colorSubPointsA[i], colorSubPointsB[i], colorSubPointsA[i] };
                            blendSubPoint.Positions = new float[] { 0f, 0.5f, 1f };
                            brushSubPointFill = new System.Drawing.Drawing2D.LinearGradientBrush(rectSubPoint, colorSubPointsA[i], colorSubPointsB[i], 67f);
                            brushSubPointFill.InterpolationColors = blendSubPoint;

                            g.FillRectangle(brushSubPointFill, rectSubPoint);
                            g.DrawRectangle(new Pen(brushSubPointFill), rectSubPoint);
                            g.DrawRectangle(new Pen(brushSubPointFill), rectSubPoint);
                            g.DrawRectangle(new Pen(brushSubPointFill), rectSubPoint);

                            g.DrawString(cooldownName, fontLegend, brushSubPoints[i], rectSubPoint, formatSubPoint);
                            legendY += 16;
                        }

                        if (calculationOptions.AdviseAdvancedSolver)
                        {
                            g.DrawString("Sequence Reconstruction was not fully successful, it is recommended that you enable more options in advanced solver (segment cooldowns, integral mana consumables, advanced constraints options)!", fontLegend, Brushes.Black, new RectangleF(5 + maxWidth, 40, width - maxWidth - 10, 100));
                        }

                        g.DrawLine(Pens.Aqua, new Point(maxWidth + 40, 10), new Point(maxWidth + 80, 10));
                        g.DrawString("Mana", fontLegend, Brushes.Black, new Point(maxWidth + 90, 2));
                        g.DrawLine(Pens.Red, new Point(maxWidth + 40, 26), new Point(maxWidth + 80, 26));
                        g.DrawString("Dps", fontLegend, Brushes.Black, new Point(maxWidth + 90, 18));
                        #endregion

        #region Graph Ticks
                        graphStart = 20f;
                        graphWidth = width - 40f;
                        graphTop = legendY;
                        graphBottom = height - 4 - 4 * cooldownList.Count;
                        graphHeight = graphBottom - graphTop - 40;
                        maxScale = calculationOptions.FightDuration;
                        graphEnd = graphStart + graphWidth;
                        ticks = new float[] {(float)Math.Round(graphStart + graphWidth * 0.5f),
                            (float)Math.Round(graphStart + graphWidth * 0.75f),
                            (float)Math.Round(graphStart + graphWidth * 0.25f),
                            (float)Math.Round(graphStart + graphWidth * 0.125f),
                            (float)Math.Round(graphStart + graphWidth * 0.375f),
                            (float)Math.Round(graphStart + graphWidth * 0.625f),
                            (float)Math.Round(graphStart + graphWidth * 0.875f)};

                        g.DrawLine(black150, ticks[1], graphTop + 36, ticks[1], graphTop + 39);
                        g.DrawLine(black150, ticks[2], graphTop + 36, ticks[2], graphTop + 39);
                        g.DrawLine(black75, ticks[3], graphTop + 36, ticks[3], graphTop + 39);
                        g.DrawLine(black75, ticks[4], graphTop + 36, ticks[4], graphTop + 39);
                        g.DrawLine(black75, ticks[5], graphTop + 36, ticks[5], graphTop + 39);
                        g.DrawLine(black75, ticks[6], graphTop + 36, ticks[6], graphTop + 39);
                        g.DrawLine(black75, graphEnd, graphTop + 41, graphEnd, height - 4);
                        g.DrawLine(black75, ticks[0], graphTop + 41, ticks[0], height - 4);
                        g.DrawLine(black50, ticks[1], graphTop + 41, ticks[1], height - 4);
                        g.DrawLine(black50, ticks[2], graphTop + 41, ticks[2], height - 4);
                        g.DrawLine(black25, ticks[3], graphTop + 41, ticks[3], height - 4);
                        g.DrawLine(black25, ticks[4], graphTop + 41, ticks[4], height - 4);
                        g.DrawLine(black25, ticks[5], graphTop + 41, ticks[5], height - 4);
                        g.DrawLine(black25, ticks[6], graphTop + 41, ticks[6], height - 4);
                        g.DrawLine(black200, graphStart - 4, graphTop + 40, graphEnd + 4, graphTop + 40);
                        g.DrawLine(black200, graphStart, graphTop + 36, graphStart, height - 4);
                        g.DrawLine(black200, graphEnd, graphTop + 36, graphEnd, height - 4);
                        g.DrawLine(black200, graphStart - 4, graphBottom, graphEnd + 4, graphBottom);

                        g.DrawString(TimeFormat(0f), fontLegend, black200brush, graphStart, graphTop + 36, formatTick);
                        g.DrawString(TimeFormat(maxScale), fontLegend, black200brush, graphEnd, graphTop + 36, formatTick);
                        g.DrawString(TimeFormat(maxScale * 0.5f), fontLegend, black200brush, ticks[0], graphTop + 36, formatTick);
                        g.DrawString(TimeFormat(maxScale * 0.75f), fontLegend, black150brush, ticks[1], graphTop + 36, formatTick);
                        g.DrawString(TimeFormat(maxScale * 0.25f), fontLegend, black150brush, ticks[2], graphTop + 36, formatTick);
                        g.DrawString(TimeFormat(maxScale * 0.125f), fontLegend, black75brush, ticks[3], graphTop + 36, formatTick);
                        g.DrawString(TimeFormat(maxScale * 0.375f), fontLegend, black75brush, ticks[4], graphTop + 36, formatTick);
                        g.DrawString(TimeFormat(maxScale * 0.625f), fontLegend, black75brush, ticks[5], graphTop + 36, formatTick);
                        g.DrawString(TimeFormat(maxScale * 0.875f), fontLegend, black75brush, ticks[6], graphTop + 36, formatTick);
                        #endregion

                        List<SequenceReconstruction.SequenceItem> sequence = calculationOptions.SequenceReconstruction.sequence;

                        float mana = calculations.StartingMana;
                        int gemCount = 0;
                        float time = 0;
                        Color manaFill = Color.FromArgb(50, Color.FromArgb(255, 0, 0, 255));
                        float lastMana = mana;
                        float maxMana = calculations.BaseStats.Mana;
                        float maxDps = 100;
                        for (int i = 0; i < sequence.Count; i++)
                        {
                            int index = sequence[i].Index;
                            VariableType type = sequence[i].VariableType;
                            float duration = (float)sequence[i].Duration;
                            Cycle cycle = sequence[i].Cycle;
                            if (cycle != null && cycle.DamagePerSecond > maxDps) maxDps = cycle.DamagePerSecond;
                            CastingState state = sequence[i].CastingState;
                            float mps = (float)sequence[i].Mps;
                            if (sequence[i].IsManaPotionOrGem)
                            {
                                duration = 0;
                                if (sequence[i].VariableType == VariableType.ManaGem)
                                {
                                    mana += (float)((1 + calculations.BaseStats.BonusManaGem) * calculations.ManaGemValue);
                                    gemCount++;
                                }
                                else if (sequence[i].VariableType == VariableType.ManaPotion)
                                {
                                    mana += (float)((1 + calculations.BaseStats.BonusManaPotion) * calculations.ManaPotionValue);
                                }
                                if (mana < 0) mana = 0;
                                if (mana > maxMana)
                                {
                                    mana = maxMana;
                                }
                                g.DrawLine(Pens.Aqua, graphStart + time / maxScale * graphWidth, graphBottom - graphHeight * lastMana / maxMana, graphStart + time / maxScale * graphWidth, height - 44 - graphHeight * mana / maxMana);
                            }
                            else
                            {
                                if (sequence[i].IsEvocation)
                                {
                                    switch (sequence[i].VariableType)
                                    {
                                        case VariableType.Evocation:
                                            mps = -(float)calculationOptions.Calculations.EvocationRegen;
                                            break;
                                        case VariableType.EvocationIV:
                                            mps = -(float)calculationOptions.Calculations.EvocationRegenIV;
                                            break;
                                        case VariableType.EvocationHero:
                                            mps = -(float)calculationOptions.Calculations.EvocationRegenHero;
                                            break;
                                        case VariableType.EvocationIVHero:
                                            mps = -(float)calculationOptions.Calculations.EvocationRegenIVHero;
                                            break;
                                    }
                                }
                                float partTime = duration;
                                if (mana - mps * duration < 0) partTime = mana / mps;
                                else if (mana - mps * duration > maxMana) partTime = (mana - maxMana) / mps;
                                mana -= mps * duration;
                                if (mana < 0) mana = 0;
                                if (mana > maxMana)
                                {
                                    mana = maxMana;
                                }
                                float x1 = graphStart + time / maxScale * graphWidth;
                                float x2 = graphStart + (time + partTime) / maxScale * graphWidth;
                                float x3 = graphStart + (time + duration) / maxScale * graphWidth;
                                float y1 = graphBottom - graphHeight * lastMana / maxMana;
                                float y2 = graphBottom - graphHeight * mana / maxMana;
                                float y3 = graphBottom;
                                g.FillPolygon(new SolidBrush(manaFill), new PointF[] { new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y2), new PointF(x3, y3), new PointF(x1, y3) });
                                g.DrawLine(Pens.Aqua, x1, y1, x2, y2);
                                g.DrawLine(Pens.Aqua, x2, y2, x3, y2);
                            }
                            lastMana = mana;
                            time += duration;
                        }

                        maxDps *= 1.1f;
                        List<PointF> list = new List<PointF>();
                        time = 0.0f;
                        for (int i = 0; i < sequence.Count; i++)
                        {
                            int index = sequence[i].Index;
                            VariableType type = sequence[i].VariableType;
                            float duration = (float)sequence[i].Duration;
                            Cycle cycle = sequence[i].Cycle;
                            CastingState state = sequence[i].CastingState;
                            float mps = (float)sequence[i].Mps;
                            if (sequence[i].IsManaPotionOrGem) duration = 0;
                            float dps = 0;
                            if (cycle != null)
                            {
                                dps = cycle.DamagePerSecond;
                            }
                            if (duration > 0)
                            {
                                list.Add(new PointF(graphStart + (time + 0.1f * duration) / maxScale * graphWidth, graphBottom - graphHeight * dps / maxDps));
                                list.Add(new PointF(graphStart + (time + 0.9f * duration) / maxScale * graphWidth, graphBottom - graphHeight * dps / maxDps));
                            }
                            time += duration;
                        }
                        if (list.Count > 0) g.DrawLines(Pens.Red, list.ToArray());

                        for (int cooldown = 0; cooldown < cooldownList.Count; cooldown++)
                        {
                            blendSubPoint = new System.Drawing.Drawing2D.ColorBlend(3);
                            blendSubPoint.Colors = new Color[] { colorSubPointsA[cooldown], colorSubPointsB[cooldown], colorSubPointsA[cooldown] };
                            blendSubPoint.Positions = new float[] { 0f, 0.5f, 1f };
                            bool on = false;
                            float timeOn = 0.0f;
                            time = 0;
                            for (int i = 0; i < sequence.Count; i++)
                            {
                                float duration = (float)sequence[i].Duration;
                                if (sequence[i].IsManaPotionOrGem) duration = 0;
                                if (on && !sequence[i].CastingState.EffectsActive(cooldownList[cooldown]) && !sequence[i].IsManaPotionOrGem)
                                {
                                    on = false;
                                    if (time > timeOn)
                                    {
                                        RectangleF rect = new RectangleF(graphStart + graphWidth * timeOn / maxScale, graphBottom + cooldown * 4, graphWidth * (time - timeOn) / maxScale, 4);
                                        brushSubPointFill = new System.Drawing.Drawing2D.LinearGradientBrush(rect, colorSubPointsA[cooldown], colorSubPointsB[cooldown], 67f);
                                        brushSubPointFill.InterpolationColors = blendSubPoint;

                                        g.FillRectangle(brushSubPointFill, rect);
                                        g.DrawRectangle(new Pen(brushSubPointFill), rect.X, rect.Y, rect.Width, rect.Height);
                                        g.DrawRectangle(new Pen(brushSubPointFill), rect.X, rect.Y, rect.Width, rect.Height);
                                        g.DrawRectangle(new Pen(brushSubPointFill), rect.X, rect.Y, rect.Width, rect.Height);
                                    }
                                }
                                else if (!on && sequence[i].CastingState.EffectsActive(cooldownList[cooldown]))
                                {
                                    on = true;
                                    timeOn = time;
                                }
                                time += duration;
                            }
                            if (on)
                            {
                                if (time - timeOn > 0)
                                {
                                    RectangleF rect = new RectangleF(graphStart + graphWidth * timeOn / maxScale, graphBottom + cooldown * 4, graphWidth * (time - timeOn) / maxScale, 4);
                                    brushSubPointFill = new System.Drawing.Drawing2D.LinearGradientBrush(rect, colorSubPointsA[cooldown], colorSubPointsB[cooldown], 67f);
                                    brushSubPointFill.InterpolationColors = blendSubPoint;

                                    g.FillRectangle(brushSubPointFill, rect);
                                    g.DrawRectangle(new Pen(brushSubPointFill), rect.X, rect.Y, rect.Width, rect.Height);
                                    g.DrawRectangle(new Pen(brushSubPointFill), rect.X, rect.Y, rect.Width, rect.Height);
                                    g.DrawRectangle(new Pen(brushSubPointFill), rect.X, rect.Y, rect.Width, rect.Height);
                                }
                            }
                        }
                    }
                    break;
                case "Scaling vs Spell Power":
                    Base.Graph.RenderScalingGraph(g, width, height, character, statsList, new Stats() { SpellPower = 5 }, true, statColors, 100, "", "Dps Rating", Base.Graph.Style.Mage);
                    break;
                case "Scaling vs Crit Rating":
                    Base.Graph.RenderScalingGraph(g, width, height, character, statsList, new Stats() { CritRating = 5 }, true, statColors, 100, "", "Dps Rating", Base.Graph.Style.Mage);
                    break;
                case "Scaling vs Haste Rating":
                    Base.Graph.RenderScalingGraph(g, width, height, character, statsList, new Stats() { HasteRating = 5 }, true, statColors, 100, "", "Dps Rating", Base.Graph.Style.Mage);
                    break;
                case "Scaling vs Intellect":
                    Base.Graph.RenderScalingGraph(g, width, height, character, statsList, new Stats() { Intellect = 5 }, true, statColors, 100, "", "Dps Rating", Base.Graph.Style.Mage);
                    break;
                case "Scaling vs Spirit":
                    Base.Graph.RenderScalingGraph(g, width, height, character, statsList, new Stats() { Spirit = 5 }, true, statColors, 100, "", "Dps Rating", Base.Graph.Style.Mage);
                    break;
            }
        }
예제 #6
0
        static void CreateDocumentPaperSizes(C1PdfDocument pdf)
        {
            // add title
            Font titleFont = new Font("Tahoma", 24, PdfFontStyle.Bold);
            Rect rc = PdfUtils.PageRectangle(pdf);
            PdfUtils.RenderParagraph(pdf, pdf.DocumentInfo.Title, titleFont, rc, rc, false);

            // create constant font and StringFormat objects
            Font font = new Font("Tahoma", 18);
            StringFormat sf = new StringFormat();
            sf.Alignment = HorizontalAlignment.Center;
            sf.LineAlignment = VerticalAlignment.Center;

            // create one page with each paper size
            bool firstPage = true;
            foreach (var fi in typeof(PaperKind).GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                // Silverlight/Phone doesn't have Enum.GetValues
                PaperKind pk = (PaperKind)fi.GetValue(null);

                // skip custom size
                if (pk == PaperKind.Custom) continue;

                // add new page for every page after the first one
                if (!firstPage) pdf.NewPage();
                firstPage = false;

                // set paper kind and orientation
                pdf.PaperKind = pk;
                pdf.Landscape = !pdf.Landscape;

                // draw some content on the page
                rc = PdfUtils.PageRectangle(pdf);
                rc = PdfUtils.Inflate(rc, -6, -6);
                string text = string.Format("PaperKind: [{0}];\r\nLandscape: [{1}];\r\nFont: [Tahoma 18pt]",
                    pdf.PaperKind, pdf.Landscape);
                pdf.DrawString(text, font, Colors.Black, rc, sf);
                pdf.DrawRectangle(Colors.Black, rc);
            }
        }
예제 #7
0
        // Generates content of fontTablePart1.
        private void GenerateFontTablePart1Content(FontTablePart fontTablePart1)
        {
            Fonts fonts1 = new Fonts() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 w15 w16se" } };
            fonts1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            fonts1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            fonts1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            fonts1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            fonts1.AddNamespaceDeclaration("w15", "http://schemas.microsoft.com/office/word/2012/wordml");
            fonts1.AddNamespaceDeclaration("w16se", "http://schemas.microsoft.com/office/word/2015/wordml/symex");

            Font font1 = new Font() { Name = "Symbol" };
            Panose1Number panose1Number1 = new Panose1Number() { Val = "05050102010706020507" };
            FontCharSet fontCharSet1 = new FontCharSet() { Val = "02" };
            FontFamily fontFamily1 = new FontFamily() { Val = FontFamilyValues.Roman };
            Pitch pitch1 = new Pitch() { Val = FontPitchValues.Variable };
            FontSignature fontSignature1 = new FontSignature() { UnicodeSignature0 = "00000000", UnicodeSignature1 = "10000000", UnicodeSignature2 = "00000000", UnicodeSignature3 = "00000000", CodePageSignature0 = "80000000", CodePageSignature1 = "00000000" };

            font1.Append(panose1Number1);
            font1.Append(fontCharSet1);
            font1.Append(fontFamily1);
            font1.Append(pitch1);
            font1.Append(fontSignature1);

            Font font2 = new Font() { Name = "Times New Roman" };
            Panose1Number panose1Number2 = new Panose1Number() { Val = "02020603050405020304" };
            FontCharSet fontCharSet2 = new FontCharSet() { Val = "00" };
            FontFamily fontFamily2 = new FontFamily() { Val = FontFamilyValues.Roman };
            Pitch pitch2 = new Pitch() { Val = FontPitchValues.Variable };
            FontSignature fontSignature2 = new FontSignature() { UnicodeSignature0 = "E0002EFF", UnicodeSignature1 = "C000784B", UnicodeSignature2 = "00000009", UnicodeSignature3 = "00000000", CodePageSignature0 = "000001FF", CodePageSignature1 = "00000000" };

            font2.Append(panose1Number2);
            font2.Append(fontCharSet2);
            font2.Append(fontFamily2);
            font2.Append(pitch2);
            font2.Append(fontSignature2);

            Font font3 = new Font() { Name = "Courier New" };
            Panose1Number panose1Number3 = new Panose1Number() { Val = "02070309020205020404" };
            FontCharSet fontCharSet3 = new FontCharSet() { Val = "00" };
            FontFamily fontFamily3 = new FontFamily() { Val = FontFamilyValues.Modern };
            Pitch pitch3 = new Pitch() { Val = FontPitchValues.Fixed };
            FontSignature fontSignature3 = new FontSignature() { UnicodeSignature0 = "E0002EFF", UnicodeSignature1 = "C0007843", UnicodeSignature2 = "00000009", UnicodeSignature3 = "00000000", CodePageSignature0 = "000001FF", CodePageSignature1 = "00000000" };

            font3.Append(panose1Number3);
            font3.Append(fontCharSet3);
            font3.Append(fontFamily3);
            font3.Append(pitch3);
            font3.Append(fontSignature3);

            Font font4 = new Font() { Name = "Wingdings" };
            Panose1Number panose1Number4 = new Panose1Number() { Val = "05000000000000000000" };
            FontCharSet fontCharSet4 = new FontCharSet() { Val = "02" };
            FontFamily fontFamily4 = new FontFamily() { Val = FontFamilyValues.Auto };
            Pitch pitch4 = new Pitch() { Val = FontPitchValues.Variable };
            FontSignature fontSignature4 = new FontSignature() { UnicodeSignature0 = "00000000", UnicodeSignature1 = "10000000", UnicodeSignature2 = "00000000", UnicodeSignature3 = "00000000", CodePageSignature0 = "80000000", CodePageSignature1 = "00000000" };

            font4.Append(panose1Number4);
            font4.Append(fontCharSet4);
            font4.Append(fontFamily4);
            font4.Append(pitch4);
            font4.Append(fontSignature4);

            Font font5 = new Font() { Name = "Calibri" };
            Panose1Number panose1Number5 = new Panose1Number() { Val = "020F0502020204030204" };
            FontCharSet fontCharSet5 = new FontCharSet() { Val = "00" };
            FontFamily fontFamily5 = new FontFamily() { Val = FontFamilyValues.Swiss };
            Pitch pitch5 = new Pitch() { Val = FontPitchValues.Variable };
            FontSignature fontSignature5 = new FontSignature() { UnicodeSignature0 = "E0002AFF", UnicodeSignature1 = "C000247B", UnicodeSignature2 = "00000009", UnicodeSignature3 = "00000000", CodePageSignature0 = "000001FF", CodePageSignature1 = "00000000" };

            font5.Append(panose1Number5);
            font5.Append(fontCharSet5);
            font5.Append(fontFamily5);
            font5.Append(pitch5);
            font5.Append(fontSignature5);

            Font font6 = new Font() { Name = "Arial" };
            Panose1Number panose1Number6 = new Panose1Number() { Val = "020B0604020202020204" };
            FontCharSet fontCharSet6 = new FontCharSet() { Val = "00" };
            FontFamily fontFamily6 = new FontFamily() { Val = FontFamilyValues.Swiss };
            Pitch pitch6 = new Pitch() { Val = FontPitchValues.Variable };
            FontSignature fontSignature6 = new FontSignature() { UnicodeSignature0 = "E0002EFF", UnicodeSignature1 = "C0007843", UnicodeSignature2 = "00000009", UnicodeSignature3 = "00000000", CodePageSignature0 = "000001FF", CodePageSignature1 = "00000000" };

            font6.Append(panose1Number6);
            font6.Append(fontCharSet6);
            font6.Append(fontFamily6);
            font6.Append(pitch6);
            font6.Append(fontSignature6);

            Font font7 = new Font() { Name = "Cambria" };
            Panose1Number panose1Number7 = new Panose1Number() { Val = "02040503050406030204" };
            FontCharSet fontCharSet7 = new FontCharSet() { Val = "00" };
            FontFamily fontFamily7 = new FontFamily() { Val = FontFamilyValues.Roman };
            Pitch pitch7 = new Pitch() { Val = FontPitchValues.Variable };
            FontSignature fontSignature7 = new FontSignature() { UnicodeSignature0 = "E00002FF", UnicodeSignature1 = "400004FF", UnicodeSignature2 = "00000000", UnicodeSignature3 = "00000000", CodePageSignature0 = "0000019F", CodePageSignature1 = "00000000" };

            font7.Append(panose1Number7);
            font7.Append(fontCharSet7);
            font7.Append(fontFamily7);
            font7.Append(pitch7);
            font7.Append(fontSignature7);

            Font font8 = new Font() { Name = "Verdana" };
            Panose1Number panose1Number8 = new Panose1Number() { Val = "020B0604030504040204" };
            FontCharSet fontCharSet8 = new FontCharSet() { Val = "00" };
            FontFamily fontFamily8 = new FontFamily() { Val = FontFamilyValues.Swiss };
            Pitch pitch8 = new Pitch() { Val = FontPitchValues.Variable };
            FontSignature fontSignature8 = new FontSignature() { UnicodeSignature0 = "A10006FF", UnicodeSignature1 = "4000205B", UnicodeSignature2 = "00000010", UnicodeSignature3 = "00000000", CodePageSignature0 = "0000019F", CodePageSignature1 = "00000000" };

            font8.Append(panose1Number8);
            font8.Append(fontCharSet8);
            font8.Append(fontFamily8);
            font8.Append(pitch8);
            font8.Append(fontSignature8);

            Font font9 = new Font() { Name = "Tahoma" };
            Panose1Number panose1Number9 = new Panose1Number() { Val = "020B0604030504040204" };
            FontCharSet fontCharSet9 = new FontCharSet() { Val = "00" };
            FontFamily fontFamily9 = new FontFamily() { Val = FontFamilyValues.Swiss };
            Pitch pitch9 = new Pitch() { Val = FontPitchValues.Variable };
            FontSignature fontSignature9 = new FontSignature() { UnicodeSignature0 = "E1002EFF", UnicodeSignature1 = "C000605B", UnicodeSignature2 = "00000029", UnicodeSignature3 = "00000000", CodePageSignature0 = "000101FF", CodePageSignature1 = "00000000" };

            font9.Append(panose1Number9);
            font9.Append(fontCharSet9);
            font9.Append(fontFamily9);
            font9.Append(pitch9);
            font9.Append(fontSignature9);

            Font font10 = new Font() { Name = "Arial Black" };
            Panose1Number panose1Number10 = new Panose1Number() { Val = "020B0A04020102020204" };
            FontCharSet fontCharSet10 = new FontCharSet() { Val = "00" };
            FontFamily fontFamily10 = new FontFamily() { Val = FontFamilyValues.Swiss };
            Pitch pitch10 = new Pitch() { Val = FontPitchValues.Variable };
            FontSignature fontSignature10 = new FontSignature() { UnicodeSignature0 = "A00002AF", UnicodeSignature1 = "400078FB", UnicodeSignature2 = "00000000", UnicodeSignature3 = "00000000", CodePageSignature0 = "0000009F", CodePageSignature1 = "00000000" };

            font10.Append(panose1Number10);
            font10.Append(fontCharSet10);
            font10.Append(fontFamily10);
            font10.Append(pitch10);
            font10.Append(fontSignature10);

            Font font11 = new Font() { Name = "MS Gothic" };
            AltName altName1 = new AltName() { Val = "MS ゴシック" };
            Panose1Number panose1Number11 = new Panose1Number() { Val = "020B0609070205080204" };
            FontCharSet fontCharSet11 = new FontCharSet() { Val = "80" };
            FontFamily fontFamily11 = new FontFamily() { Val = FontFamilyValues.Modern };
            Pitch pitch11 = new Pitch() { Val = FontPitchValues.Fixed };
            FontSignature fontSignature11 = new FontSignature() { UnicodeSignature0 = "E00002FF", UnicodeSignature1 = "6AC7FDFB", UnicodeSignature2 = "08000012", UnicodeSignature3 = "00000000", CodePageSignature0 = "0002009F", CodePageSignature1 = "00000000" };

            font11.Append(altName1);
            font11.Append(panose1Number11);
            font11.Append(fontCharSet11);
            font11.Append(fontFamily11);
            font11.Append(pitch11);
            font11.Append(fontSignature11);

            Font font12 = new Font() { Name = "MS Mincho" };
            AltName altName2 = new AltName() { Val = "Yu Gothic UI" };
            Panose1Number panose1Number12 = new Panose1Number() { Val = "02020609040205080304" };
            FontCharSet fontCharSet12 = new FontCharSet() { Val = "80" };
            FontFamily fontFamily12 = new FontFamily() { Val = FontFamilyValues.Modern };
            Pitch pitch12 = new Pitch() { Val = FontPitchValues.Fixed };
            FontSignature fontSignature12 = new FontSignature() { UnicodeSignature0 = "E00002FF", UnicodeSignature1 = "6AC7FDFB", UnicodeSignature2 = "00000012", UnicodeSignature3 = "00000000", CodePageSignature0 = "0002009F", CodePageSignature1 = "00000000" };

            font12.Append(altName2);
            font12.Append(panose1Number12);
            font12.Append(fontCharSet12);
            font12.Append(fontFamily12);
            font12.Append(pitch12);
            font12.Append(fontSignature12);

            Font font13 = new Font() { Name = "Segoe UI" };
            Panose1Number panose1Number13 = new Panose1Number() { Val = "020B0502040204020203" };
            FontCharSet fontCharSet13 = new FontCharSet() { Val = "00" };
            FontFamily fontFamily13 = new FontFamily() { Val = FontFamilyValues.Swiss };
            Pitch pitch13 = new Pitch() { Val = FontPitchValues.Variable };
            FontSignature fontSignature13 = new FontSignature() { UnicodeSignature0 = "E4002EFF", UnicodeSignature1 = "C000E47F", UnicodeSignature2 = "00000009", UnicodeSignature3 = "00000000", CodePageSignature0 = "000001FF", CodePageSignature1 = "00000000" };

            font13.Append(panose1Number13);
            font13.Append(fontCharSet13);
            font13.Append(fontFamily13);
            font13.Append(pitch13);
            font13.Append(fontSignature13);

            fonts1.Append(font1);
            fonts1.Append(font2);
            fonts1.Append(font3);
            fonts1.Append(font4);
            fonts1.Append(font5);
            fonts1.Append(font6);
            fonts1.Append(font7);
            fonts1.Append(font8);
            fonts1.Append(font9);
            fonts1.Append(font10);
            fonts1.Append(font11);
            fonts1.Append(font12);
            fonts1.Append(font13);

            fontTablePart1.Fonts = fonts1;
        }
예제 #8
0
        static Rect RenderTableRow(C1PdfDocument pdf, Font font, Font hdrFont, Rect rcPage, Rect rc, string[] fields, DataRow dr)
        {
            // calculate cell width (same for all columns)
            Rect rcCell = rc;
            rcCell.Width = rc.Width / fields.Length;
            rcCell.Height = 0;

            // calculate cell height (max of all columns)
            rcCell = PdfUtils.Inflate(rcCell, -4, 0);
            foreach (string field in fields)
            {
                string text = dr[field].ToString();
                var height = pdf.MeasureString(text, font, rcCell.Width).Height;
                rcCell.Height = Math.Max(rcCell.Height, height);
            }
            rcCell = PdfUtils.Inflate(rcCell, 4, 0); // add 4 point margin
            rcCell.Height += 2;

            // break page if we have to
            if (rcCell.Bottom > rcPage.Bottom)
            {
                pdf.NewPage();
                rc = RenderTableHeader(pdf, hdrFont, rcPage, fields);
                rcCell.Y = rc.Y;
            }

            // center vertically just to show how
            StringFormat fmt = new StringFormat();
            fmt.LineAlignment = VerticalAlignment.Center;

            // render data cells
            foreach (string field in fields)
            {
                // get content
                string text = dr[field].ToString();

                // set horizontal alignment
                double d;
                fmt.Alignment = (double.TryParse(text, NumberStyles.Any, CultureInfo.CurrentCulture, out d))
                    ? HorizontalAlignment.Right
                    : HorizontalAlignment.Left;

                // render cell
                pdf.DrawRectangle(Colors.LightGray, rcCell);
                rcCell = PdfUtils.Inflate(rcCell, -4, 0);
                pdf.DrawString(text, font, Colors.Black, rcCell, fmt);
                rcCell = PdfUtils.Inflate(rcCell, 4, 0);
                rcCell = PdfUtils.Offset(rcCell, rcCell.Width, 0);
            }

            // update rectangle and return it
            return PdfUtils.Offset(rc, 0, rcCell.Height);
        }
예제 #9
0
        void CreateDocumentVisualTree(C1PdfDocument pdf, FrameworkElement targetElement)
        {
            // set up to render
            var font = new Font("Courier", 14);
            var img = new WriteableBitmap(CreateBitmap(targetElement));

            // go render
            bool firstPage = true;
            foreach (Stretch stretch in new Stretch[] { Stretch.Fill, Stretch.None, Stretch.Uniform, Stretch.UniformToFill })
            {
                // add page break
                if (!firstPage)
                {
                    pdf.NewPage();
                }
                firstPage = false;

                // set up to render
                var alignment = ContentAlignment.TopLeft;
                var rc = PdfUtils.Inflate(pdf.PageRectangle, -72, -72);
                rc.Height /= 2;

                // render element as image
                pdf.DrawString("Element as Image, Stretch: " + stretch.ToString(), font, Colors.Black, rc);
                rc = PdfUtils.Inflate(rc, -20, -20);
                pdf.DrawImage(img, rc, alignment, stretch);
                pdf.DrawRectangle(Colors.Green, rc);
                rc = PdfUtils.Inflate(rc, +20, +20);
                pdf.DrawRectangle(Colors.Green, rc);

                // move to bottom of the page
                rc = PdfUtils.Offset(rc, 0, rc.Height + 20);

                // render element
                pdf.DrawString("Element as VisualTree, Stretch: " + stretch.ToString(), font, Colors.Black, rc);
                rc = PdfUtils.Inflate(rc, -20, -20);
                pdf.DrawElement(targetElement, rc, alignment, stretch);
                pdf.DrawRectangle(Colors.Green, rc);
                rc = PdfUtils.Inflate(rc, +20, +20);
                pdf.DrawRectangle(Colors.Green, rc);
            }
        }
예제 #10
0
        static void CreateDocumentTOC(C1PdfDocument pdf)
        {
            // create pdf document
            pdf.DocumentInfo.Title = "Document with Table of Contents";

            // add title
            Font titleFont = new Font("Tahoma", 24, PdfFontStyle.Bold);
            Rect rcPage = PdfUtils.PageRectangle(pdf);
            Rect rc = PdfUtils.RenderParagraph(pdf, pdf.DocumentInfo.Title, titleFont, rcPage, rcPage, false);
            rc.Y += 12;

            // create nonsense document
            var bkmk = new List<string[]>();
            Font headerFont = new Font("Arial", 14, PdfFontStyle.Bold);
            Font bodyFont = new Font("Times New Roman", 11);
            for (int i = 0; i < 30; i++)
            {
                // create ith header (as a link target and outline entry)
                string header = string.Format("{0}. {1}", i + 1, BuildRandomTitle());
                rc = PdfUtils.RenderParagraph(pdf, header, headerFont, rcPage, rc, true, true);

                // save bookmark to build TOC later
                int pageNumber = pdf.CurrentPage + 1;
                bkmk.Add(new string[] { pageNumber.ToString(), header });

                // create some text
                rc.X += 36;
                rc.Width -= 36;
                for (int j = 0; j < 3 + _rnd.Next(20); j++)
                {
                    string text = BuildRandomParagraph();
                    rc = PdfUtils.RenderParagraph(pdf, text, bodyFont, rcPage, rc);
                    rc.Y += 6;
                }
                rc.X -= 36;
                rc.Width += 36;
                rc.Y += 20;
            }

            // start Table of Contents
            pdf.NewPage();					// start TOC on a new page
            int tocPage = pdf.CurrentPage;	// save page index (to move TOC later)
            rc = PdfUtils.RenderParagraph(pdf, "Table of Contents", titleFont, rcPage, rcPage, true);
            rc.Y += 12;
            rc.X += 30;
            rc.Width -= 40;

            // render Table of Contents
            Pen dottedPen = new Pen(Colors.Gray, 1.5f);
            dottedPen.DashStyle = DashStyle.Dot;
            StringFormat sfRight = new StringFormat();
            sfRight.Alignment = HorizontalAlignment.Right;
            rc.Height = bodyFont.Size * 1.2;
            foreach (string[] entry in bkmk)
            {
                // get bookmark info
                string page = entry[0];
                string header = entry[1];

                // render header name and page number
                pdf.DrawString(header, bodyFont, Colors.Black, rc);
                pdf.DrawString(page, bodyFont, Colors.Black, rc, sfRight);

            #if true
                // connect the two with some dots (looks better than a dotted line)
                string dots = ". ";
                var wid = pdf.MeasureString(dots, bodyFont).Width;
                var x1 = rc.X + pdf.MeasureString(header, bodyFont).Width + 8;
                var x2 = rc.Right - pdf.MeasureString(page, bodyFont).Width - 8;
                var x = rc.X;
                for (rc.X = x1; rc.X < x2; rc.X += wid)
                {
                    pdf.DrawString(dots, bodyFont, Colors.Gray, rc);
                }
                rc.X = x;
            #else
                // connect with a dotted line (another option)
                var x1 = rc.X + pdf.MeasureString(header, bodyFont).Width + 5;
                var x2 = rc.Right - pdf.MeasureString(page, bodyFont).Width  - 5;
                var y  = rc.Top + bodyFont.Size;
                pdf.DrawLine(dottedPen, x1, y, x2, y);
            #endif
                // add local hyperlink to entry
                pdf.AddLink("#" + header, rc);

                // move on to next entry
                rc = PdfUtils.Offset(rc, 0, rc.Height);
                if (rc.Bottom > rcPage.Bottom)
                {
                    pdf.NewPage();
                    rc.Y = rcPage.Y;
                }
            }

            // move table of contents to start of document
            PdfPage[] arr = new PdfPage[pdf.Pages.Count - tocPage];
            pdf.Pages.CopyTo(tocPage, arr, 0, arr.Length);
            pdf.Pages.RemoveRange(tocPage, arr.Length);
            pdf.Pages.InsertRange(0, arr);
        }
예제 #11
0
        static void CreateDocumentTextFlow(C1PdfDocument pdf)
        {
            // load long string from resource file
            string text = "Resource not found...";
            using (var sr = new StreamReader(DataAccess.GetStream("flow.txt")))
            {
                text = sr.ReadToEnd();
            }
            text = text.Replace("\t", "   ");
            text = string.Format("{0}\r\n\r\n---oOoOoOo---\r\n\r\n{0}", text);

            // create pdf document
            pdf.DocumentInfo.Title = "Text Flow";

            // add title
            Font titleFont = new Font("Tahoma", 24, PdfFontStyle.Bold);
            Font bodyFont = new Font("Tahoma", 9);
            Rect rcPage = PdfUtils.PageRectangle(pdf);
            Rect rc = PdfUtils.RenderParagraph(pdf, pdf.DocumentInfo.Title, titleFont, rcPage, rcPage, false);
            rc.Y += titleFont.Size + 6;
            rc.Height = rcPage.Height - rc.Y;

            // create two columns for the text
            Rect rcLeft = rc;
            rcLeft.Width = rcPage.Width / 2 - 12;
            rcLeft.Height = 300;
            rcLeft.Y = (rcPage.Y + rcPage.Height - rcLeft.Height) / 2;
            Rect rcRight = rcLeft;
            rcRight.X = rcPage.Right - rcRight.Width;

            // start with left column
            rc = rcLeft;

            // render string spanning columns and pages
            for (; ; )
            {
                // render as much as will fit into the rectangle
                rc = PdfUtils.Inflate(rc, -3, -3);
                int nextChar = pdf.DrawString(text, bodyFont, Colors.Black, rc);
                rc = PdfUtils.Inflate(rc, +3, +3);
                pdf.DrawRectangle(Colors.LightGray, rc);

                // break when done
                if (nextChar >= text.Length)
                {
                    break;
                }

                // get rid of the part that was rendered
                text = text.Substring(nextChar);

                // switch to right-side rectangle
                if (rc.Left == rcLeft.Left)
                {
                    rc = rcRight;
                }
                else // switch to left-side rectangle on the next page
                {
                    pdf.NewPage();
                    rc = rcLeft;
                }
            }
        }
예제 #12
0
        static void CreateDocumentText(C1PdfDocument pdf)
        {
            // use landscape for more impact
            pdf.Landscape = true;

            // measure and show some text
            var text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
            var font = new Font("Times New Roman", 9, PdfFontStyle.Italic);

            // create StringFormat used to set text alignment and line spacing
            var fmt = new StringFormat();
            fmt.LineSpacing = -1.5; // 1.5 char height
            fmt.Alignment = HorizontalAlignment.Center;

            // measure it
            var sz = pdf.MeasureString(text, font, 72 * 3, fmt);
            var rc = new Rect(pdf.PageRectangle.Width / 2, 72, sz.Width, sz.Height);
            rc = PdfUtils.Offset(rc, 72, 0);

            // draw a rounded frame
            rc = PdfUtils.Inflate(rc, 10, 10);
            pdf.FillRectangle(Colors.Black, rc, new Size(30, 30));
            pdf.DrawRectangle(new Pen(Colors.Red, 4), rc, new Size(30, 30));
            rc = PdfUtils.Inflate(rc, -10, -10);

            // draw the text
            pdf.DrawString(text, font, Colors.White, rc, fmt);

            // now draw some text rotating about the center of the page
            rc = pdf.PageRectangle;
            rc = PdfUtils.Offset(rc, rc.Width / 2, rc.Height / 2);

            // build StringFormat used to rotate the text
            fmt = new StringFormat();

            // rotate the string in small increments
            var step = 6;
            text = "PDF works in WPF!";
            for (int i = 0; i <= 360; i += step)
            {
                fmt.Angle = i;
                font = new Font("Courier New", 8 + i / 30.0, PdfFontStyle.Bold);
                byte b = (byte)(255 * (1 - i / 360.0));
                pdf.DrawString(text, font, Color.FromArgb(0xff, b, b, b), rc, fmt);
            }
        }
예제 #13
0
        static void CreateDocumentTables(C1PdfDocument pdf)
        {
            // get the data
            var ds = DataAccess.GetDataSet();

            // calculate page rect (discounting margins)
            Rect rcPage = PdfUtils.PageRectangle(pdf);
            Rect rc = rcPage;

            // add title
            Font titleFont = new Font("Tahoma", 24, PdfFontStyle.Bold);
            rc = PdfUtils.RenderParagraph(pdf, pdf.DocumentInfo.Title, titleFont, rcPage, rc, false);

            // render some tables
            RenderTable(pdf, rc, rcPage, ds.Tables["Customers"], new string[] { "CompanyName", "ContactName", "Country", "Address", "Phone" });
            pdf.NewPage();
            rc = rcPage;
            RenderTable(pdf, rc, rcPage, ds.Tables["Products"], new string[] { "ProductName", "QuantityPerUnit", "UnitPrice", "UnitsInStock", "UnitsOnOrder" });
            pdf.NewPage();
            rc = rcPage;
            RenderTable(pdf, rc, rcPage, ds.Tables["Employees"], new string[] { "FirstName", "LastName", "Country", "Notes" });
        }
예제 #14
0
        static void CreateDocumentQuotes(C1PdfDocument pdf)
        {
            // calculate page rect (discounting margins)
            Rect rcPage = PdfUtils.PageRectangle(pdf);
            Rect rc = rcPage;

            // initialize output parameters
            Font hdrFont = new Font("Arial", 14, PdfFontStyle.Bold);
            Font titleFont = new Font("Arial", 24, PdfFontStyle.Bold);
            Font txtFont = new Font("Times New Roman", 10, PdfFontStyle.Italic);

            // add title
            rc = PdfUtils.RenderParagraph(pdf, pdf.DocumentInfo.Title, titleFont, rcPage, rc);

            // build document
            foreach (string s in GetQuotes())
            {
                string[] authorQuote = s.Split('\t');

                // render header (author)
                var author = authorQuote[0];
                rc.Y += 20;
                rc = PdfUtils.RenderParagraph(pdf, author, hdrFont, rcPage, rc, true);

                // render body text (quote)
                string text = authorQuote[1];
                rc.X = rcPage.X + 36; // << indent body text by 1/2 inch
                rc.Width = rcPage.Width - 40;
                rc = PdfUtils.RenderParagraph(pdf, text, txtFont, rcPage, rc);
                rc.X = rcPage.X; // << restore indent
                rc.Width = rcPage.Width;
                rc.Y += 12; // << add 12pt spacing after each quote
            }
        }
예제 #15
0
파일: App.cs 프로젝트: JJJohan/DX12Engine
        public void Start()
        {
            // Create an example triangle object.
            _triangleVertices = new List<Vertex>(6)
            {
                new Vertex(new Vector3(-0.25f, 0.25f, 0.0f), Colour.White, new Vector2(0.0f, 0.0f)),
                new Vertex(new Vector3(0.25f, -0.25f, 0.0f), Colour.White, new Vector2(1.0f, 64.0f)),
                new Vertex(new Vector3(-0.25f, -0.25f, 0.0f), Colour.White, new Vector2(0.0f, 64.0f)),

                new Vertex(new Vector3(-0.25f, 0.25f, 0.0f), Colour.White, new Vector2(0.0f, 0.0f)),
                new Vertex(new Vector3(0.25f, 0.25f, 0.0f), Colour.White, new Vector2(1.0f, 0.0f)),
                new Vertex(new Vector3(0.25f, -0.25f, 0.0f), Colour.White, new Vector2(1.0f, 64.0f))
            };

            _vertexBuffer = ResourceFactory.CreateVertexBufferInstance();
            _vertexBuffer.SetVertices(_triangleVertices);

            _pTexture = ResourceFactory.CreateTexture();
            _pTexture.Load(Helpers.GetRelativePath("Textures\\font.dds"));

            _pMaterial = ResourceFactory.CreateMaterial();
            _pMaterial.SetTexture(_pTexture);
            _pMaterial.LoadVertexShader(Helpers.GetRelativePath("Shaders\\DiffuseTexture.hlsl"), "VSMain", "vs_5_1");
            _pMaterial.LoadPixelShader(Helpers.GetRelativePath("Shaders\\DiffuseTexture.hlsl"), "PSMain", "ps_5_1");
            _pMaterial.Finalise(false);

            _pTriangle = new RenderObject("triangle");
            _pTriangle.SetVertexBuffer(_vertexBuffer);
            _pTriangle.SetMaterial(_pMaterial);

            // Create an example triangle object.
            _vertices2 = new List<Vertex>(4)
            {
                new Vertex(new Vector3(-0.25f, 0.25f, 0.0f), Colour.White, new Vector2(0.0f, 0.0f)),
                new Vertex(new Vector3(0.25f, -0.25f, 0.0f), Colour.White, new Vector2(1.0f, 1.0f)),
                new Vertex(new Vector3(0.25f, 0.25f, 0.0f), Colour.White, new Vector2(1.0f, 0.0f)),
                new Vertex(new Vector3(-0.25f, -0.25f, 0.0f), Colour.White, new Vector2(0.0f, 1.0f))
            };

            _indices = new List<int>(6)
            {
                1, 0, 2,
                0, 1, 3
            };

            _vertexBuffer2 = ResourceFactory.CreateVertexBufferInstance();
            _vertexBuffer2.SetVertices(_vertices2);

            _indexBuffer = ResourceFactory.CreateIndexBufferInstance();
            _indexBuffer.SetIndices(_indices);

            _pTexture2 = ResourceFactory.CreateTexture();
            _pTexture2.Load(Helpers.GetRelativePath("Textures\\test2.png"));

            _pMaterial2 = ResourceFactory.CreateMaterial();
            _pMaterial2.SetTexture(_pTexture2);
            _pMaterial2.LoadVertexShader(Helpers.GetRelativePath("Shaders\\DiffuseTexture.hlsl"), "VSMain", "vs_5_1");
            _pMaterial2.LoadPixelShader(Helpers.GetRelativePath("Shaders\\DiffuseTexture.hlsl"), "PSMain", "ps_5_1");
            _pMaterial2.Finalise(false);

            _pTriangle2 = new RenderObject("triangle2");
            _pTriangle2.SetIndexBuffer(_indexBuffer);
            _pTriangle2.SetVertexBuffer(_vertexBuffer2);
            _pTriangle2.SetMaterial(_pMaterial2);

            _pFont = FontManager.LoadFont("Myriad", Helpers.GetRelativePath("Textures\\myriad.dds"), Helpers.GetRelativePath("Textures\\myriad.txt"));
            _pText = new Text("text", _pFont);
            _pText.SetText("test");
            _pText.SetColour(Colour.Yellow);
            _pText.Transform.Position = new Vector3(0.0f, 0.0f, 0.0f);
            _pText2 = new Text("text2", _pFont);
            _pText2.SetText("Hello world!");
            _pText2.Transform.Position = new Vector3(0.0f, 20.0f, 0.0f);
            _pText2.EnableWorldSpace(true);
        }
예제 #16
0
 public static Rect RenderParagraph(this C1PdfDocument doc, string text, Font font, Rect rcPage, Rect rc)
 {
     return RenderParagraph(doc, text, font, rcPage, rc, false, false);
 }
예제 #17
0
        static Rect RenderTable(C1PdfDocument pdf, Rect rc, Rect rcPage, DataTable table, string[] fields)
        {
            // select fonts
            Font hdrFont = new Font("Tahoma", 10, PdfFontStyle.Bold);
            Font txtFont = new Font("Tahoma", 8);

            // build table
            pdf.AddBookmark(table.TableName, 0, rc.Y);
            rc = PdfUtils.RenderParagraph(pdf, "NorthWind " + table.TableName, hdrFont, rcPage, rc, false);

            // build table
            rc = RenderTableHeader(pdf, hdrFont, rc, fields);
            foreach (DataRow dr in table.Rows)
            {
                rc = RenderTableRow(pdf, txtFont, hdrFont, rcPage, rc, fields, dr);
            }

            // done
            return rc;
        }
예제 #18
0
 public double GetHeight(Font font)
 {
     double multiplier = (double)System.Windows.Application.Current.Host.Content.ScaleFactor / 100d;
     return multiplier * font.GetHeight() / this.display.Ydpi;
 }
예제 #19
0
        static Rect RenderTableHeader(C1PdfDocument pdf, Font font, Rect rc, string[] fields)
        {
            // calculate cell width (same for all columns)
            Rect rcCell = rc;
            rcCell.Width = rc.Width / fields.Length;
            rcCell.Height = 0;

            // calculate cell height (max of all columns)
            foreach (string field in fields)
            {
                var height = pdf.MeasureString(field, font, rcCell.Width).Height;
                rcCell.Height = Math.Max(rcCell.Height, height);
            }
            rcCell.Height += 6; // add 6 point margin

            // render header cells
            var fmt = new StringFormat();
            fmt.LineAlignment = VerticalAlignment.Center;
            foreach (string field in fields)
            {
                pdf.FillRectangle(Colors.Black, rcCell);
                pdf.DrawString(field, font, Colors.White, rcCell, fmt);
                rcCell = PdfUtils.Offset(rcCell, rcCell.Width, 0);
            }

            // update rectangle and return it
            return PdfUtils.Offset(rc, 0, rcCell.Height);
        }
예제 #20
0
파일: XamlWindow.cs 프로젝트: koush/Xaml
        public XamlWindow()
        {
            Dispatcher d1 = Dispatcher.CurrentDispatcher;
            Dispatcher d2 = Dispatcher.CurrentDispatcher;

            SolidColorBrush solidBrush = new SolidColorBrush();

            StackPanel stack = new StackPanel();
            Label label = new Label();
            label.Content = "Hello world";
            label.Margin = new Thickness(20, 0, 0, 0);
            stack.Children.Add(label);
            label.ForeBrush = solidBrush;

            label = new Label();
            label.Content = "Hello world";
            label.HorizontalAlignment = HorizontalAlignment.Right;
            label.Margin = new Thickness(0, 0, 20, 0);
            stack.Children.Add(label);

            label = new Label();
            label.Content = "Hello world";
            label.HorizontalAlignment = HorizontalAlignment.Center;
            label.Margin = new Thickness(60, 0, 0, 0);
            Font font = new Font(FontFamily.GenericSerif, 24, FontStyle.Regular);
            label.Font = font;
            stack.Children.Add(label);

            Rectangle rect = new Rectangle();
            rect.Width = 100;
            rect.Height = 100;
            rect.HorizontalAlignment = HorizontalAlignment.Right;
            GradientBrush gradient = new GradientBrush();
            gradient.StartPoint = new Point(0, .5f);
            gradient.EndPoint = new Point(1, .5f);
            gradient.GradientStops.Add(new GradientStop(new Color(1f, 1f, 0f, 1f), 0));
            gradient.GradientStops.Add(new GradientStop(new Color(0, 0, 1f, 1f), 1));
            rect.Fill = gradient;
            stack.Children.Add(rect);

            BitmapSource bitmap;
            using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("XamlTest.Flames.bmp"))
            {
                bitmap = BitmapSource.Create(stream);
            }
            Image image = new Image();
            image.Stretch = Stretch.None;
            image.ImageSource = bitmap;
            stack.Children.Add(image);

            ImageBrush brush = new ImageBrush();
            brush.ImageSource = bitmap;
            brush.Stretch = Stretch.None;
            label.ForeBrush = brush;

            Content = stack;

            FloatAnimation anim = new FloatAnimation();
            anim.From = 50;
            anim.To = 300;
            anim.Duration = new Duration(TimeSpan.FromMilliseconds(10000));
            anim.RepeatBehavior = RepeatBehavior.Forever;
            anim.AutoReverse = true;
            myClock = anim.CreateClock();
            myClock.Animate(rect, Rectangle.WidthProperty);

            //new Thread(() =>
            //    {
            //        //Thread.Sleep(2000);
            //        Random rand = new Random();
            //        while (true)
            //        {
            //            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new EmptyDelegate(() =>
            //                {
            //                    Color newColor = new Color((byte)(rand.Next() % 256), (byte)(rand.Next() % 256), (byte)(rand.Next() % 256), (byte)(rand.Next() % 256));
            //                    solidBrush.Color = newColor;
            //                    rect.Width += 5;
            //                    if (rect.Width > 300)
            //                        rect.Width = 200;
            //                }));
            //        }
            //    }
            //).Start();
        }
예제 #21
0
        static void CreateDocumentGraphics(C1PdfDocument pdf)
        {
            // set up to draw
            Rect rc = new Rect(0, 0, 300, 200);
            string text = "Hello world of .NET Graphics and PDF.\r\nNice to meet you.";
            Font font = new Font("Times New Roman", 12, PdfFontStyle.Italic | PdfFontStyle.Underline);

            // draw to pdf document
            int penWidth = 0;
            byte penRGB = 0;
            pdf.FillPie(Colors.Red, rc, 0, 20f);
            pdf.FillPie(Colors.Green, rc, 20f, 30f);
            pdf.FillPie(Colors.Blue, rc, 60f, 12f);
            pdf.FillPie(Colors.Orange, rc, -80f, -20f);
            for (float startAngle = 0; startAngle < 360; startAngle += 40)
            {
                Color penColor = Color.FromArgb(0xff, penRGB, penRGB, penRGB);
                Pen pen = new Pen(penColor, penWidth++);
                penRGB = (byte)(penRGB + 20);
                pdf.DrawArc(pen, rc, startAngle, 40f);
            }
            pdf.DrawRectangle(Colors.Red, rc);
            pdf.DrawString(text, font, Colors.Black, rc);

            // show a Bezier curve
            var pts = new Point[]
            {
                new Point(400, 100), new Point(420,  30),
                new Point(500, 140), new Point(530,  20),
            };

            // draw Bezier
            pdf.DrawBezier(new Pen(Colors.Blue, 4), pts[0], pts[1], pts[2], pts[3]);

            // show Bezier control points
            pdf.DrawLines(Colors.Gray, pts);
            foreach (Point pt in pts)
            {
                pdf.FillRectangle(Colors.Red, pt.X - 2, pt.Y - 2, 4, 4);
            }

            // title
            pdf.DrawString("Simple Bezier", font, Colors.Black, new Rect(500, 150, 100, 100));
        }
예제 #22
0
파일: GlyphRun.cs 프로젝트: koush/Xaml
 public GlyphRun(string text, Font font, TextAlignment alignment)
     : this(text, font, alignment, float.PositiveInfinity, float.PositiveInfinity, true)
 {
 }
예제 #23
0
파일: GlyphRun.cs 프로젝트: koush/Xaml
        public GlyphRun(string text, Font font, TextAlignment alignment, float maxWidth, float maxHeight, bool autoEllipsis)
        {
            Font = font;
            List<LineBreak> linebreaks = new List<LineBreak>();

            string processingText = text;
            int totalHeight = 0;
            int totalWidth = 0;
            int totalChars = 0;
            int intWidth;
            if (maxWidth != float.PositiveInfinity)
                intWidth = (int)maxWidth;
            else
                intWidth = int.MaxValue;
            int intHeight;
            if (maxHeight != float.PositiveInfinity)
                intHeight = (int)maxHeight;
            else
                intHeight = int.MaxValue;
            LineBreak lineBreak = FitString(processingText, 0, intWidth);

            while (lineBreak.Index != processingText.Length)
            {
                LineBreak nextBreak = FitString(processingText, lineBreak.Index, intWidth);
                // see if this line needs ellipsis
                if (Font.myHeight + Font.myHeight + totalHeight > intHeight && autoEllipsis)
                {
                    string lineText = lineBreak.Text;
                    int ellipsisStart = lineText.Length - 3;
                    if (ellipsisStart < 0)
                        ellipsisStart = 0;
                    lineText = lineText.Substring(0, ellipsisStart) + "...";
                    lineBreak.Width = MeasureString(lineText);
                    lineBreak.Text = lineText;
                    break;
                }

                linebreaks.Add(lineBreak);
                totalWidth = Math.Max(totalWidth, lineBreak.Width);
                totalHeight += Font.myHeight;
                totalChars += lineBreak.Text.Length;
                lineBreak = nextBreak;
            }
            linebreaks.Add(lineBreak);
            totalHeight += Font.myHeight;
            totalWidth = Math.Max(totalWidth, lineBreak.Width);
            totalChars += lineBreak.Text.Length;
            myTriangleCount = totalChars * 2;

            Glyphs = new Point[totalChars * 4];
            FontCoords = new TextureCoordinate[totalChars * 4];
            Indices = new short[totalChars * 6];

            myWidth = totalWidth;
            myHeight = totalHeight;

            float y = 0;
            int curChars = 0;
            for (int i = 0; i < linebreaks.Count; i++)
            {
                LineBreak lbreak = linebreaks[i];
                float x;
                float spaceAdjust = 0;
                string lbreakText = lbreak.Text;
                switch (alignment)
                {
                    case TextAlignment.Left:
                        x = 0;
                        break;
                    case TextAlignment.Right:
                        x = myWidth - lbreak.Width;
                        break;
                    case TextAlignment.Center:
                        x = (myWidth - lbreak.Width) / 2;
                        break;
                    case TextAlignment.Justify:
                        x = 0;
                        if (i != linebreaks.Count - 1)
                        {
                            lbreakText = lbreakText.TrimStart(' ').TrimEnd(' ');
                            int spaceCount = 0;
                            foreach (char c in lbreakText)
                            {
                                if (c == ' ')
                                    spaceCount++;
                            }
                            int newWidth = MeasureString(lbreakText);
                            if (spaceCount != 0)
                                spaceAdjust = (myWidth - newWidth) / spaceCount;
                        }
                        break;
                    default:
                        throw new ArgumentException("Unknown alignment type.");
                }

                BuildLine(lbreakText, curChars, x, y, spaceAdjust);
                y += Font.myHeight;
                curChars += lbreakText.Length;
            }
        }
예제 #24
-1
        public static void HandleButtonClick(object sender, RoutedEventArgs e)
        {
            // get stream to save to
            var dlg = new SaveFileDialog();
            dlg.DefaultExt = ".pdf";
            var dr = dlg.ShowDialog();
            if (!dr.HasValue || !dr.Value)
            {
                return;
            }

            // get sender button
            var btn = sender as Button;

            // create document
            var pdf = new C1PdfDocument(PaperKind.Letter);
            pdf.Clear();

            // set document info
            var di = pdf.DocumentInfo;
            di.Author = "ComponentOne";
            di.Subject = "C1.WPF.Pdf demo.";
            di.Title = (string)btn.Content;

            //// add some security
            //if (false)
            //{
            //    var si = pdf.Security;
            //    si.AllowPrint = false;
            //    si.AllowEditAnnotations = false;
            //    si.AllowEditContent = false;
            //    si.AllowCopyContent = false;
            //    //si.UserPassword = "******";
            //    //si.OwnerPassword = "******";
            //}

            //// set viewer preferences
            //if (false)
            //{
            //    var vp = pdf.ViewerPreferences;
            //    vp.CenterWindow = true;
            //    vp.FitWindow = true;
            //    vp.PageLayout = PageLayout.TwoColumnLeft;
            //    vp.PageMode = PageMode.FullScreen;
            //}

            // create document
            switch (di.Title)
            {
                case "Quotes":
                    CreateDocumentQuotes(pdf);
                    break;
                case "Tables":
                    CreateDocumentTables(pdf);
                    break;
                case "Images":
                    CreateDocumentImages(pdf);
                    break;
                case "Paper Sizes":
                    CreateDocumentPaperSizes(pdf);
                    break;
                case "Table of Contents":
                    CreateDocumentTOC(pdf);
                    break;
                case "Text Flow":
                    CreateDocumentTextFlow(pdf);
                    break;
                case "Text":
                    CreateDocumentText(pdf);
                    break;
                case "Graphics":
                    CreateDocumentGraphics(pdf);
                    break;
            }

            // render footers
            // this reopens each page and adds content to them (now we know the page count).
            var font = new Font("Arial", 8, PdfFontStyle.Bold);
            var fmt = new StringFormat();
            fmt.Alignment = HorizontalAlignment.Right;
            fmt.LineAlignment = VerticalAlignment.Bottom;
            for (int page = 0; page < pdf.Pages.Count; page++)
            {
                pdf.CurrentPage = page;
                var text = string.Format("C1.WPF.Pdf: {0}, page {1} of {2}",
                    di.Title,
                    page + 1,
                    pdf.Pages.Count);
                pdf.DrawString(
                    text,
                    font,
                    Colors.DarkGray,
                    PdfUtils.Inflate(pdf.PageRectangle, -72, -36),
                    fmt);
            }

            // save document
            using (var stream = dlg.OpenFile())
            {
                pdf.Save(stream);
            }
            MessageBox.Show("Pdf Document saved to " + dlg.SafeFileName);
        }