public static string linearGradientFillTest() { int[] line1 = new int[] { 5, 10, 50, 34, 10, 25 }; LineChart lineChart = new LineChart(250, 150); lineChart.SetTitle("Linear Gradient fill test"); lineChart.SetData(line1); lineChart.AddAxis(new ChartAxis(ChartAxisType.Left)); lineChart.AddAxis(new ChartAxis(ChartAxisType.Bottom)); LinearGradientFill fill = new LinearGradientFill(ChartFillTarget.ChartArea, 45); fill.AddColorOffsetPair("FFFFFF", 0); fill.AddColorOffsetPair("76A4FB", 0.75); SolidFill bgFill = new SolidFill(ChartFillTarget.Background, "EFEFEF"); lineChart.AddLinearGradientFill(fill); lineChart.AddSolidFill(bgFill); return(lineChart.GetUrl()); }
public static IFillStyle ParseFillStyle2(SwfReader r, ShapeType shapeType) { IFillStyle result = null; FillType fsType = (FillType)r.GetByte(); bool useAlpha = shapeType > ShapeType.DefineShape2; switch (fsType) { case FillType.Solid: result = new SolidFill(r, useAlpha); break; case FillType.Linear: result = new Gradient(r, fsType, useAlpha); break; case FillType.Radial: result = new Gradient(r, fsType, useAlpha); break; case FillType.Focal: result = null; //throw new NotSupportedException("Currently FillType.Focal is not supported"); break; case FillType.RepeatingBitmap: case FillType.ClippedBitmap: case FillType.NSRepeatingBitmap: case FillType.NSClippedBitmap: uint charId = r.GetUI16(); Matrix bmpMatrix = new Matrix(r); result = new BitmapFill(charId, bmpMatrix, fsType); break; } return result; }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { FillBase result = null; string className = (string)value; switch (className) { case "Solid": result = new SolidFill(); break; case "LinearGradient": result = new LinearGradientFill(); break; case "PathGradient": result = new PathGradientFill(); break; case "Hatch": result = new HatchFill(); break; case "Glass": result = new GlassFill(); break; case "Texture": result = new TextureFill(); break; } return(result); } return(base.ConvertFrom(context, culture, value)); }
private void FillPaths(FillStyle fill, List <GraphicsPath> paths) { Brush b = null; foreach (GraphicsPath path in paths) { path.Transform(translateMatrix); switch (fill.FillType) { case FillType.Solid: SolidFill sf = (SolidFill)fill; b = new SolidBrush(GetColor(sf.Color)); break; case FillType.Linear: GradientFill lf = (GradientFill)fill; RectangleF rect = Vex.GradientFill.GradientVexRect.SysRectangleF(); LinearGradientBrush lgb = new LinearGradientBrush( rect, Ms.Color.White, Ms.Color.White, 1.0F ); lgb.InterpolationColors = GetColorBlend(lf); lgb.Transform = GetMatrix(lf.Transform); lgb.WrapMode = WrapMode.TileFlipX; ExtendGradientBrush(lgb, path); b = lgb; break; case FillType.Radial: GradientFill rf = (GradientFill)fill; ColorBlend cb = GetColorBlend(rf); SolidBrush bkgCol = new SolidBrush(cb.Colors[0]); g.FillPath(bkgCol, path); bkgCol.Dispose(); // radial fill part GraphicsPath gp = new GraphicsPath(); gp.AddEllipse(Vex.GradientFill.GradientVexRect.SysRectangleF()); PathGradientBrush pgb = new PathGradientBrush(gp); pgb.InterpolationColors = GetColorBlend(rf); pgb.Transform = GetMatrix(rf.Transform); b = pgb; break; case FillType.Image: ImageFill imgFill = (ImageFill)fill; Bitmap bmp = new Bitmap(imgFill.ImagePath); b = new TextureBrush(bmp); break; default: b = new SolidBrush(Ms.Color.Red); break; } g.FillPath(b, path); } if (b != null) { b.Dispose(); } }
public Paragraph CreateStyledParagraph(string text, int fontsize, bool bold, bool italic, Color color) { var run = new Drawing.Run(); var run2 = new Drawing.Run(); var textBody = new Drawing.Text(); var textBody2 = new Drawing.Text(); var newParagraph = new Paragraph(); string[] newStringa = text.Split(new string[] { "<", ">" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < newStringa.Count(); i++) { if (newStringa[i].Contains('(')) { var runProperties2 = new RunProperties(); //set basic styles for paragraph Run ru11 = new Run(); runProperties2.Bold = bold; runProperties2.Italic = italic; runProperties2.FontSize = fontsize; runProperties2.Dirty = false; string rem = newStringa[i].Substring(1); Color col = ColorTranslator.FromHtml("#007AC9"); var hexColor = col.R.ToString("X2") + col.G.ToString("X2") + col.B.ToString("X2");//convert color to hex //convert color to hex var solidFill = new SolidFill(); var rgbColorModelHex = new RgbColorModelHex() { Val = hexColor }; var rgbColorModelHex1 = new LatinFont() { Typeface = "Arial Narrow" }; solidFill.Append(rgbColorModelHex1); solidFill.Append(rgbColorModelHex); runProperties2.Append(solidFill); textBody2 = new Drawing.Text(); textBody2.Text = rem; //assign text run2 = new Drawing.Run(); run2.Append(runProperties2); //append styles run2.Append(textBody2); newParagraph.Append(run2); } else { var runProperties = new RunProperties(); //set basic styles for paragraph runProperties.Bold = false; runProperties.Italic = false; runProperties.FontSize = fontsize; runProperties.Dirty = false; var hexColor = color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");//convert color to hex var solidFill = new SolidFill(); var rgbColorModelHex = new RgbColorModelHex() { Val = hexColor }; solidFill.Append(rgbColorModelHex); runProperties.Append(solidFill); textBody = new Drawing.Text(); textBody.Text = newStringa[i]; //assign text run = new Drawing.Run(); run.Append(runProperties); //append styles run.Append(textBody); newParagraph.Append(run); } } return(newParagraph); //append text //append run to paragraph }
private void ExportHTMLPageLayeredBegin(HTMLData d) { if (!singlePage && !WebMode) { cssStyles.Clear(); } css = new FastString(); htmlPage = new FastString(); ReportPage reportPage = d.page; if (reportPage != null) { maxWidth = ExportUtils.GetPageWidth(reportPage) * Units.Millimeters; maxHeight = ExportUtils.GetPageHeight(reportPage) * Units.Millimeters; if (enableMargins) { leftMargin = reportPage.LeftMargin * Units.Millimeters; topMargin = reportPage.TopMargin * Units.Millimeters; } else { maxWidth -= (reportPage.LeftMargin + reportPage.RightMargin) * Units.Millimeters; maxHeight -= (reportPage.TopMargin + reportPage.BottomMargin) * Units.Millimeters; leftMargin = 0; topMargin = 0; } currentPage = d.PageNumber - 1; ExportHTMLPageStart(htmlPage, d.PageNumber, d.CurrentPage); doPageBreak = (singlePage && pageBreaks); htmlPage.Append(HTMLGetAncor((d.PageNumber).ToString())); htmlPage.Append("<div ").Append(doPageBreak ? "class=\"frpage\"" : String.Empty). Append(" style=\"position:relative;width:").Append(Px(maxWidth * Zoom + 3)). Append("height:").Append(Px(maxHeight * Zoom)); if (reportPage.Fill is SolidFill) { SolidFill fill = reportPage.Fill as SolidFill; htmlPage.Append("; background-color:"). Append(fill.Color.A == 0 ? "transparent" : ExportUtils.HTMLColor(fill.Color)); } htmlPage.Append("\">"); if (!(reportPage.Fill is SolidFill)) { // to-do for picture background } if (reportPage.Watermark.Enabled && !reportPage.Watermark.ShowImageOnTop) { Watermark(htmlPage, reportPage, false); } if (reportPage.Watermark.Enabled && !reportPage.Watermark.ShowTextOnTop) { Watermark(htmlPage, reportPage, true); } } }
public Outline Build() { var outline = new Outline(); switch (this.Options.FillType) { case FillTypes.NoFill: outline.Append(new NoFill()); break; case FillTypes.Solid: var solidFill = new SolidFill(); if (this.Options.SchemaColorOptions != null) { var schemaColorBuilder = new SchemaColorBuilder(this.Options.SchemaColorOptions); solidFill.SchemeColor = schemaColorBuilder.Build(); } outline.Append(solidFill); break; case FillTypes.Gradient: break; } if (this.Options.JoinType.HasValue) { switch (this.Options.JoinType) { case JoinTypes.Round: outline.Append(new Round()); break; case JoinTypes.Bevel: outline.Append(new Bevel()); break; case JoinTypes.Miter: outline.Append(new Miter() { Limit = 800000 }); break; } } if (this.Options.Width.HasValue) { outline.Width = Convert.ToInt32(this.Options.Width * 12700); } if (this.Options.LineCap.HasValue) { outline.CapType = this.Options.LineCap; } if (this.Options.CompoundLine.HasValue) { outline.CompoundLineType = this.Options.CompoundLine; } if (this.Options.PenAlignment.HasValue) { outline.Alignment = this.Options.PenAlignment; } return(outline); }
private DDW.Vex.SolidFill ParseSolidFill(SolidFill tag) { return new DDW.Vex.SolidFill(ParseRGBA(tag.Color)); }
private static void ConsolidatePaths(Symbol symbol, DVexWriter writer) { List <FillStyle> fills = new List <FillStyle>(); List <StrokeStyle> strokes = new List <StrokeStyle>(); fills.Add(new SolidFill(Color.Transparent)); strokes.Add(new SolidStroke(0.0F, Color.Transparent)); ArrayList allPaths = new ArrayList(); ArrayList allSrs = new ArrayList(); // Find all used colors/strokes, and the F0,F1,S info for each seg foreach (Shape sh in symbol.Shapes) { foreach (IShapeData s in sh.ShapeData) { int fill = 0; int stroke = 0; if (!fills.Contains(shape.Fills[s.FillIndex])) { fill = fills.Add(shape.Fills[s.FillIndex]); } else { fill = fills.IndexOf(shape.Fills[s.FillIndex]); } if (!strokes.Contains(shape.Strokes[s.StrokeIndex])) { stroke = strokes.Add(shape.Strokes[s.StrokeIndex]); } else { stroke = strokes.IndexOf(shape.Strokes[s.StrokeIndex]); } // break path into shape records foreach (IPathPrimitive ipp in s.Path) { if (ipp is IShapeData) { IShapeData ip = (IShapeData)ipp; if (allPaths.Contains(ip)) { // this must be a fill1 if it is a dup int index = allPaths.IndexOf(ip); Shrec sr = (Shrec)allSrs[index]; Shrec newShrec = new Shrec(0, 0); newShrec.F0 = (sr.F0 == 0) ? fill : sr.F0; newShrec.F1 = (sr.F1 == 0) ? fill : sr.F1; newShrec.S = (sr.S == 0) ? stroke : sr.S; allSrs[index] = newShrec; } else { allSrs.Add(new Shrec(fill, stroke)); allPaths.Add(ip); } } } } // end groups } // end shapes // ok, now write out colors // sort fills by rgb, argb, and gradients ArrayList orderedFills = new ArrayList(); ArrayList rgbas = new ArrayList(); ArrayList gfs = new ArrayList(); foreach (Fill sf in fills) { if (sf is SolidFill) { if (((SolidFill)sf).Color.A == 255 || (SolidFill)sf == fills[0]) // 'no fill' { orderedFills.Add(sf); } else { rgbas.Add(sf); } } else if (sf is GradientFill) { gfs.Add(sf); } else { // bitmap fills orderedFills.Add(new SolidFill(Color.Gray)); }; } SolidFill[] wrgbs = new SolidFill[orderedFills.Count]; wrgbs[0] = new SolidFill(Color.FromArgb(255, 0, 0, 0)); int fRgb = 1; foreach (Fill f in orderedFills) { if (f != fills[0]) { wrgbs[fRgb++] = (SolidFill)f; } } int fRgba = 0; SolidFill[] wrgbas = new SolidFill[rgbas.Count]; foreach (Fill f in rgbas) { orderedFills.Add(f); wrgbas[fRgba++] = (SolidFill)f; } int fGr = 0; GradientFill[] wgfs = new GradientFill[gfs.Count]; foreach (Fill f in gfs) { orderedFills.Add(f); wgfs[fGr++] = (GradientFill)(f); } writer.WriteNbitColorDefs(wrgbs); writer.WriteNbitColorDefs(wrgbas); writer.WriteNbitGradientDefs(wgfs); //writer.WriteRgbColorDefs(wrgbs); //writer.WriteRgbaColorDefs(wrgbas); //writer.WriteGradientColorDefs(wgfs); // ok, colors written, now strokes // write out all the stroke defs second // get counts int wrgbCount = 0; int wrgbaCount = 0; foreach (Stroke st in strokes) { if (st.Color.A == 255 || st == strokes[0]) { wrgbCount++; } else { wrgbaCount++; } } // create stroke arrays Stroke[] wsrgbs = new Stroke[wrgbCount]; Stroke[] wsrgbas = new Stroke[wrgbaCount]; int sRgb = 0; int sRgba = 0; foreach (Stroke st in strokes) { if (st.Color.A == 255 || st == strokes[0]) { wsrgbs[sRgb++] = st; } else { wsrgbas[sRgba++] = st; } } // now write the stroke data writer.WriteNbitStrokeDefs(wsrgbs); writer.WriteNbitStrokeDefs(wsrgbas); //writer.WriteRgbStrokeDefs(wsrgbs); //writer.WriteRgbaStrokeDefs(wsrgbas); // and now paths // valid pathsegs must have the same F0, F1, and S ArrayList tempPaths = new ArrayList(); ArrayList tempSrsAl = new ArrayList(); PathCollection pc = new PathCollection(); Shrec curShrec = Shrec.Empty; for (int i = 0; i < allSrs.Count; i++) //Shrec sr in srsAl) { Shrec sr = (Shrec)allSrs[i]; if (sr.Equals(curShrec) || curShrec.Equals(Shrec.Empty)) { //add to path pc.Add((IShapeData)allPaths[i]); } else { // write to hash tempPaths.Add(pc); tempSrsAl.Add(curShrec); pc = new PathCollection(); pc.Add((IShapeData)allPaths[i]); } curShrec = sr; } if (!tempSrsAl.Contains(curShrec)) { tempPaths.Add(pc); tempSrsAl.Add(curShrec); } // split non contig paths ArrayList paths = new ArrayList(); ArrayList srsAl = new ArrayList(); foreach (PathCollection pcoll in tempPaths) { //pcoll.ReorderPath(); PathCollection[] pcolls = pcoll.SplitPath(); foreach (PathCollection splitP in pcolls) { paths.Add(splitP); srsAl.Add(tempSrsAl[tempPaths.IndexOf(pcoll)]); //writer.WritePath(splitP.PointSegments); } } IShapeData[][] ips = new IShapeData[paths.Count][]; for (int i = 0; i < paths.Count; i++) { ips[i] = ((PathCollection)paths[i]).PointSegments; } writer.WritePaths(ips); // convert to array Shrec[] srs = new Shrec[srsAl.Count]; for (int i = 0; i < srsAl.Count; i++) { srs[i] = (Shrec)srsAl[i]; } // and finally, uses - must be sorted by fill color // use order Fill1 (no strokes), fill0[stroke], stroke only's // for each fill index{..}, then dangling strokes ArrayList shapeRecords = new ArrayList(); // start at 1 to avoid empty fills foreach (Fill f in orderedFills) { int curFill = fills.IndexOf(f); if (curFill != 0) { // all F1's of this color first ArrayList Fs = new ArrayList(); for (int i = 0; i < srs.Length; i++) { if (srs[i].F0 == curFill) { // add use for F0 ShapeRecord curSr = new ShapeRecord(); curSr.Fill = orderedFills.IndexOf(f); curSr.Stroke = srs[i].S; curSr.Path = i; Fs.Add(curSr); } if (srs[i].F1 == curFill) { // add use for F1 ShapeRecord curSr = new ShapeRecord(); curSr.Fill = orderedFills.IndexOf(f); curSr.Stroke = 0; curSr.Path = i; Fs.Add(curSr); } } //now sort the F1s from tip to tail if (Fs.Count > 0) { ArrayList finalFs = new ArrayList(); finalFs.Add(Fs[0]); PointF end = ((PathCollection)paths[((ShapeRecord)Fs[0]).Path]).LastPoint; Fs.RemoveAt(0); while (Fs.Count > 0) { bool found = false; foreach (ShapeRecord sr in Fs) { PathCollection srp = (PathCollection)paths[sr.Path]; if (srp.FirstPoint == end) { end = srp.LastPoint; finalFs.Add(sr); Fs.Remove(sr); found = true; break; } } if (found == false) { finalFs.Add(Fs[0]); end = ((PathCollection)paths[ ((ShapeRecord)Fs[0]).Path]).LastPoint; Fs.RemoveAt(0); } } // and write them foreach (ShapeRecord sr in finalFs) { shapeRecords.Add(sr); } } } } for (int i = 0; i < srs.Length; i++) { if (srs[i].F0 == 0 && srs[i].F1 == 0) { // must be stroke ShapeRecord curSr = new ShapeRecord(); curSr.Fill = 0; curSr.Stroke = srs[i].S; curSr.Path = i; shapeRecords.Add(curSr); } } // convert to array ShapeRecord[] srecs = new ShapeRecord[shapeRecords.Count]; for (int i = 0; i < shapeRecords.Count; i++) { srecs[i] = (ShapeRecord)shapeRecords[i]; } writer.WriteUses(srecs); }
/// <summary> /// Sets the color of the series using a solidcolor brush /// If a null brush is supplied any color is removed so the color will be automatic /// </summary> /// <param name="line">The line.</param> /// <param name="brush">The brush.</param> public static void UpdateLineBrush(this OpenXmlCompositeElement line, Brush brush) { if (line == null) { return; } // If we have a BarChart, we really want tp update the SolidFill (not the Outline.SolidFill) BarChartSeries barChartSeries = line as BarChartSeries; if (barChartSeries != null) { // For BarCharts, we update the SolidFill barChartSeries.UpdateSeriesColour((SolidColorBrush)brush); } else { // Update the Outline.SolidFill + set the SolidFill to the same colour var chartShapeProperties = line.Descendants <ChartShapeProperties>().FirstOrDefault(); if (brush == null && !(brush is SolidColorBrush)) { if (chartShapeProperties != null) { line.RemoveChild <ChartShapeProperties>(chartShapeProperties); } return; } // the series title, this is the name of the column header var seriesText = line.Descendants <SeriesText>().FirstOrDefault(); if (chartShapeProperties == null) { chartShapeProperties = new ChartShapeProperties(); // if there's a series text then insert afterwards if (seriesText == null) { line.InsertAt <ChartShapeProperties>(chartShapeProperties, 0); } else { line.InsertAfter <ChartShapeProperties>(chartShapeProperties, seriesText); } } var outline = chartShapeProperties.Descendants <Outline>().FirstOrDefault(); if (outline == null) { outline = new Outline(); chartShapeProperties.InsertAt(outline, 0); } var outlineSolidFill = outline.Descendants <SolidFill>().FirstOrDefault(); if (outlineSolidFill == null) { outlineSolidFill = new SolidFill(); outline.Append(outlineSolidFill); } // Update the fill with the supplied brush colour outlineSolidFill.UpdateSolidFill((SolidColorBrush)brush); // Clones the OutlineSolidFill as the SolidFill of the series... var solidFill = chartShapeProperties.GetFirstChild <SolidFill>(); if (solidFill != null) { chartShapeProperties.RemoveChild(solidFill); } chartShapeProperties.InsertAt(outlineSolidFill.CloneNode(true), 0); } }
public MovinShape(MovinLayer layer, BodymovinShape content) { this.content = content; if (content.paths == null || content.paths.Length < 1) { Debug.Log("DON'T DRAW SHAPE -> NO PTS"); return; } this.layer = layer; this.movin = layer.movin; Transform parent = layer.transform; /* FIRST SHAPE PROPS */ points = (BodyPoint[])content.paths[0].points.Clone(); motionSet = content.paths[0].animSets; closed = content.paths[0].closed; /* ANIM SETUP */ MotionSetup(ref animated, ref motion, motionSet); MotionSetup(ref strokeColorAnimated, ref mstrokec, content.strokeColorSets); MotionSetup(ref fillColorAnimated, ref mfillc, content.fillColorSets); /* GAMEOBJECT, MESH, MATERIAL */ gameObject = new GameObject(content.item.ty + " pts: " + points.Length + " closed: " + closed); transform.SetParent(parent, false); transform.localPosition = -layer.content.anchorPoint; mesh = new Mesh(); filter = gameObject.AddComponent <MeshFilter>(); filter.mesh = mesh; renderer = gameObject.AddComponent <MeshRenderer>(); renderer.material = new Material(Shader.Find("Sprites/Default")); //renderer.material = new Material(Shader.Find("Unlit/Vector")); sorting = gameObject.AddComponent <SortingGroup>(); sorting.sortingOrder = movin.sort + layer.sort; /* SETUP VECTOR */ Color stClr = (content.strokeColor == null) ? new Color(1, 1, 1) : new Color(content.strokeColor[0], content.strokeColor[1], content.strokeColor[2]); Color flClr = (content.fillColor == null) ? new Color(1, 1, 1) : new Color(content.fillColor[0], content.fillColor[1], content.fillColor[2]); currentStrokeColor = new Vector3(stClr.r, stClr.g, stClr.b); currentFillColor = new Vector3(flClr.r, flClr.g, flClr.b); fill = content.fillHidden || content.fillColor == null ? null : new SolidFill() { Color = flClr }; stroke = content.strokeHidden || content.strokeColor == null ? null : new Stroke() { Color = stClr, HalfThickness = content.strokeWidth * movin.strokeWidth }; props = new PathProperties() { Stroke = stroke }; shape = new Shape() { Fill = fill, PathProps = props, FillTransform = Matrix2D.identity }; options = movin.options; scene = new Scene() { Root = new SceneNode() { Shapes = new List <Shape> { shape } } }; UpdateMesh(); // ADDITIONAL SHAPE PATHS slaves = new MovinShapeSlave[content.paths.Length - 1]; for (int i = 1; i <= slaves.Length; i++) { slaves[i - 1] = new MovinShapeSlave(this, content.paths[i], movin.strokeWidth); } }
public static void Replace(this Paragraph paragraph, string oldValue, string newValue, SolidFill fill = null) { int index = 0; Run run = null; for (; index < paragraph.Elements <Run>().Count(); index++) { run = paragraph.Elements <Run>().ElementAt(index); if (run.Text.Text.Contains("#")) { break; } } while (!run.Text.Text.Contains(oldValue)) { run.Text.Text = run.Text.Text + paragraph.Elements <Run>().ElementAt(index + 1).Text.Text; paragraph.Elements <Run>().ElementAt(index + 1).Remove(); } run.Replace(oldValue, newValue, fill); paragraph.RemoveAllChildren <Field>(); }
public void SimpleVG(GraphicsDevice device) { ICanvas canvas = new GraphicsCanvas(device, device.SwapChain, new Vector2f(1.0f, 1.0f)); // We first create all needed fills. SolidFill solidFill = new SolidFill(); solidFill.Colour = Colour.LightBlue; GradientFill graFill = GradientFill.CreateGradient( new Colour[] { new Colour(13, 185, 242, 255), new Colour(191, 234, 21, 255), new Colour(112, 62, 193, 255), new Colour(255, 242, 81, 255) }, new float[] { 0.30f, 0.60f }, new Vector2f(1, 1)); TextureFill texFill = new TextureFill(CreateSampleTexture()); RadialFill radFill = new RadialFill(new Vector2f(0.75f, 0.75f), 0.15f, Colour.White, Colour.Black); Quad2f rect = new Quad2f(Vector2f.Zero, new Vector2f(0.5f, 0), new Vector2f(0.5f, 0.5f), new Vector2f(0.0f, 0.5f)); Quad2f rect2 = new Quad2f(new Vector2f(0.5f, 0.5f), new Vector2f(1, 0.5f), new Vector2f(1, 1), new Vector2f(0.5f, 1.0f)); bool exit = false; device.SwapChain.Window.Closed += delegate(Window w) { exit = true; }; float a = 0; while (!exit) { device.SwapChain.Window.DoEvents(); using (DeviceLock l = device.Lock()) { device.Clear(device.SwapChain, Colour.Green); device.SetViewports(new Region2i(0, 0, (int)device.SwapChain.Width, (int)device.SwapChain.Height)); // We render. canvas.Begin(CanvasRenderFlags.None); canvas.FillShape(solidFill, rect, null); canvas.FillShape(radFill, rect2, null); canvas.Transform = new LinearTransform( new Math.Matrix.Matrix4x4f(Math.MathHelper.Cos(a), -Math.MathHelper.Sin(a), 0, 0, Math.MathHelper.Sin(a), Math.MathHelper.Cos(a), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)); canvas.FillShape(graFill, rect, null); canvas.FillShape(texFill, rect2, null); canvas.End(); } Console.WriteLine("FPS: {0}\nTrig Count: {1}", device.DevicePerformance.CurrentFPS, device.DevicePerformance.MaxTrianglesPerFrame); a += 0.003f; device.SwapChain.Present(); } texFill.Texture.Dispose(); }
public void FontRendering2(GraphicsDevice device) { using (ICanvas canvas = new GraphicsCanvas(device, device.SwapChain, new Vector2f(1.0f, 1.0f))) { // We first create all needed fills. //RadialFill solidFill = new RadialFill(new Vector2f(0.2f, 0.3f), .4f, Colour.Blue, Colour.LightBlue); SolidFill solidFill = new SolidFill(Colour.Black); Font font = new Font(SVGFontProvider.ImportSVG("vera.svg")); Pen pen = new Pen(solidFill, 0.007f, 0.0f, OutlineEnd.Square); bool exit = false; device.SwapChain.Window.Closed += delegate(Window w) { exit = true; }; string txt = "ABC�DEFGHIJKLMNOPRS�TUVZ�abc�defghijklmnoprs�tuvz�123456789!?";//"CFGHIJKLMNSTUVZ��cfhklijmnstuvz��12357"; float a = 0, b = 0; while (!exit) { device.SwapChain.Window.DoEvents(); using (DeviceLock l = device.Lock()) { device.Clear(device.SwapChain, Colour.White); device.SetViewports(new Region2i(0, 0, (int)device.SwapChain.Width, (int)device.SwapChain.Height)); DateTime time = DateTime.Now; // We render. canvas.Begin(CanvasRenderFlags.None); font.Render(pen.Fill, canvas, txt, 0.1f, TextOptions.UseCanvasUnits | TextOptions.Top, 1.5f, new Vector2f(0, 0), new Vector2f(1, 1)); canvas.End(); span += DateTime.Now - time; Console.WriteLine("Span 1: {0}", span.TotalSeconds); } device.SwapChain.Present(); Console.WriteLine("FPS: {0}\nTrig Count: {1}", device.DevicePerformance.CurrentFPS, device.DevicePerformance.MaxTrianglesPerFrame); a += 0.002f; b += 0.01f; /* * if (a > 0.005f) * { * txt += (char)(txt[txt.Length - 1] + 1); * a = 0; * }*/ } } }
/// <summary> /// Replaces the content of the shape. /// </summary> /// <param name="shape">The shape.</param> /// <param name="newValue">The new value.</param> /// <param name="fill">The fill.</param> public static void Replace(this DocumentFormat.OpenXml.Presentation.Shape shape, string newValue, SolidFill fill = null) { if (shape.InnerText.Contains("##")) { foreach (Paragraph paragraph in shape.TextBody.Elements <Paragraph>()) { paragraph.Replace("##", newValue, fill); } } else { if (shape.TextBody.Elements <Paragraph>().Any()) { shape.TextBody.Elements <Paragraph>().First().Replace(newValue, fill); } } }
/// <summary> /// Searching for specified template in the table cell and replacing it /// </summary> /// <param name="value">The value.</param> /// <param name="cell">The table cell.</param> /// <returns>true if replacement found</returns> /// <param name="templateString"></param> public static void ReplaceTextInCellTextBody(this TableCell cell, string value, SolidFill fill = null) { Paragraph paragraph = cell.TextBody.Elements <Paragraph>().First(); while (cell.TextBody.Elements <Paragraph>().Count() > 1) { cell.TextBody.RemoveChild <Paragraph>(cell.TextBody.Elements <Paragraph>().Last()); } paragraph.Replace(value); }
private static void AddImage(Func <FileStream> fileStreamFunc, WorksheetPart worksheetPart) { if (fileStreamFunc == null) { return; } DrawingsPart drawingsPart; ImagePart imagePart; Extents extents; using (var fileStream = fileStreamFunc()) { if (fileStream == null) { return; } drawingsPart = worksheetPart.AddNewPart <DrawingsPart>(); imagePart = drawingsPart.AddImagePart(ImagePartType.Png, worksheetPart.GetIdOfPart(drawingsPart)); imagePart.FeedData(fileStream); Image image = Image.FromStream(fileStream); //http://en.wikipedia.org/wiki/English_Metric_Unit#DrawingML //http://stackoverflow.com/questions/1341930/pixel-to-centimeter //http://stackoverflow.com/questions/139655/how-to-convert-pixels-to-points-px-to-pt-in-net-c extents = new Extents { Cx = (long)image.Width * (long)((float)914400 / image.HorizontalResolution), Cy = (long)image.Height * (long)((float)914400 / image.VerticalResolution) }; image.Dispose(); } NonVisualPictureProperties pictureNonVisualPictureProperties = new NonVisualPictureProperties { NonVisualDrawingProperties = new NonVisualDrawingProperties { Id = 1025, Name = "Picture 1", Description = "eventtree" }, NonVisualPictureDrawingProperties = new NonVisualPictureDrawingProperties { PictureLocks = new PictureLocks { NoChangeAspect = true, NoChangeArrowheads = true } } }; Stretch stretch = new Stretch { FillRectangle = new FillRectangle() }; BlipFill blipFill = new BlipFill { Blip = new Blip { Embed = drawingsPart.GetIdOfPart(imagePart), CompressionState = BlipCompressionValues.Print }, SourceRectangle = new SourceRectangle() }; blipFill.Append(stretch); ShapeProperties shapeProperties = new ShapeProperties { BlackWhiteMode = BlackWhiteModeValues.Auto, Transform2D = new Transform2D { Offset = new Offset { X = 0, Y = 0 }, Extents = extents } }; PresetGeometry prstGeom = new PresetGeometry { Preset = ShapeTypeValues.Rectangle, AdjustValueList = new AdjustValueList() }; shapeProperties.Append(prstGeom); shapeProperties.Append(new SolidFill { RgbColorModelHex = new RgbColorModelHex { Val = Color.White.ToSimpleHexValue() } }); DocumentFormat.OpenXml.Drawing.Outline outline = new DocumentFormat.OpenXml.Drawing.Outline { Width = 25400, }; var solidFill1 = new SolidFill { RgbColorModelHex = new RgbColorModelHex { Val = StyleSheetLibrary.BorderColor.ToSimpleHexValue() } }; outline.Append(solidFill1); shapeProperties.Append(outline); DocumentFormat.OpenXml.Drawing.Spreadsheet.Picture picture = new DocumentFormat.OpenXml.Drawing.Spreadsheet.Picture { NonVisualPictureProperties = pictureNonVisualPictureProperties, BlipFill = blipFill, ShapeProperties = shapeProperties }; var iColumnId = 11; var iRowId = 1; var lColumnOffset = 0; var lRowOffset = 0; OneCellAnchor ocanchor = new OneCellAnchor { FromMarker = new DocumentFormat.OpenXml.Drawing.Spreadsheet.FromMarker { ColumnId = new ColumnId { Text = iColumnId.ToString(CultureInfo.InvariantCulture) }, ColumnOffset = new ColumnOffset { Text = lColumnOffset.ToString(CultureInfo.InvariantCulture) }, RowId = new RowId { Text = iRowId.ToString(CultureInfo.InvariantCulture) }, RowOffset = new RowOffset { Text = lRowOffset.ToString(CultureInfo.InvariantCulture) } }, Extent = new Extent { Cx = extents.Cx, Cy = extents.Cy } }; ocanchor.Append(picture); ocanchor.Append(new ClientData()); WorksheetDrawing worksheetDrawing = new WorksheetDrawing(); worksheetDrawing.Append(ocanchor); Drawing drawing = new Drawing { Id = drawingsPart.GetIdOfPart(imagePart) }; worksheetDrawing.Save(drawingsPart); worksheetPart.Worksheet.Append(drawing); }
/// <summary> /// Design settings for Y axis. /// </summary> public ValueAxis SetGanttValueAxis(PlotArea plotArea, TimeSpan minSpan, TimeSpan maxSpan) { MajorGridlines majorGridlines1 = new MajorGridlines(); ChartShapeProperties chartShapeProperties2 = new ChartShapeProperties(); Outline outline2 = new Outline(); SolidFill solidFill2 = new SolidFill(); SchemeColor schemeColor2 = new SchemeColor() { Val = SchemeColorValues.Accent1 }; Alpha alpha1 = new Alpha() { Val = 10000 }; schemeColor2.Append(alpha1); solidFill2.Append(schemeColor2); outline2.Append(solidFill2); chartShapeProperties2.Append(outline2); majorGridlines1.Append(chartShapeProperties2); return(plotArea.AppendChild <ValueAxis>(new ValueAxis(new AxisId() { Val = new UInt32Value(48672768u) }, new Scaling(new Orientation() { Val = new EnumValue <DocumentFormat.OpenXml.Drawing.Charts.OrientationValues>( DocumentFormat.OpenXml.Drawing.Charts.OrientationValues.MinMax) }, new MinAxisValue() { Val = 0 }, new MaxAxisValue() { Val = 0.99 }), new Delete() { Val = false }, new AxisPosition() { Val = new EnumValue <AxisPositionValues>(AxisPositionValues.Left) }, majorGridlines1, new MajorTickMark() { Val = TickMarkValues.None }, new MinorTickMark() { Val = TickMarkValues.None }, new MajorUnit() { Val = 4.1666666666666713E-2D }, new DocumentFormat.OpenXml.Drawing.Charts.NumberingFormat() { FormatCode = "h:mm;@", SourceLinked = false }, new TickLabelPosition() { Val = new EnumValue <TickLabelPositionValues> (TickLabelPositionValues.NextTo) }, new CrossingAxis() { Val = new UInt32Value(48650112U) }, new Crosses() { Val = new EnumValue <CrossesValues>(CrossesValues.AutoZero) }, new CrossBetween() { Val = new EnumValue <CrossBetweenValues>(CrossBetweenValues.Between) }))); }
/// <summary> /// Design settings for Y axis. /// </summary> public virtual ValueAxis SetValueAxis(PlotArea plotArea) { // Postavljanje Gridline-a. MajorGridlines majorGridlines = new MajorGridlines(); ChartShapeProperties chartShapeProperties = new ChartShapeProperties(); Outline outline = new Outline(); SolidFill solidFill = new SolidFill(); SchemeColor schemeColor = new SchemeColor() { Val = SchemeColorValues.Accent1 }; Alpha alpha = new Alpha() { Val = 10000 }; schemeColor.Append(alpha); solidFill.Append(schemeColor); outline.Append(solidFill); chartShapeProperties.Append(outline); majorGridlines.Append(chartShapeProperties); var valueAxis = plotArea.AppendChild <ValueAxis>(new ValueAxis( new AxisId() { Val = new UInt32Value(48672768u) }, new Scaling(new Orientation() { Val = new EnumValue <DocumentFormat.OpenXml.Drawing.Charts.OrientationValues>( DocumentFormat.OpenXml.Drawing.Charts.OrientationValues.MinMax) }), new Delete() { Val = !ChartProperties.AxisY }, new AxisPosition() { Val = new EnumValue <AxisPositionValues>(AxisPositionValues.Left) }, majorGridlines, SetTitle(ChartProperties.AxisYTitle), new NumberingFormat() { FormatCode = ChartProperties.AxisYFormatCode, SourceLinked = new BooleanValue(true) }, new MajorTickMark() { Val = TickMarkValues.None }, new MinorTickMark() { Val = TickMarkValues.None }, new TickLabelPosition() { Val = new EnumValue <TickLabelPositionValues> (TickLabelPositionValues.NextTo) }, new CrossingAxis() { Val = new UInt32Value(48650112U) }, new Crosses() { Val = new EnumValue <CrossesValues>(CrossesValues.AutoZero) }, new CrossBetween() { Val = new EnumValue <CrossBetweenValues>(CrossBetweenValues.Between) })); if (ChartProperties.AxisYFormatCategory == "Time") { valueAxis.Append(new MajorUnit() { Val = getMajorUnitFromSeconds((int)yAxisValue) }); } return(valueAxis); }
/// <summary> /// Converts the paragraph. /// </summary> /// <param name="worksheetPart">The worksheet part.</param> /// <param name="RTFSection">The RTF section.</param> /// <param name="matchShape">The match shape.</param> /// <returns></returns> public static DrawingSpreadsheet.Shape ConvertParagraph(WorksheetPart worksheetPart, Section RTFSection, DrawingSpreadsheet.Shape matchShape) { DrawingSpreadsheet.Shape NewShape = new DrawingSpreadsheet.Shape(); DocumentFormat.OpenXml.Drawing.Run ShapeRun = null; // get the graphic frame from the source anchor var sourceAnchor = worksheetPart.DrawingsPart.WorksheetDrawing.GetFirstChild <DrawingSpreadsheet.TwoCellAnchor>(); var sourceShape = sourceAnchor.Descendants <DrawingSpreadsheet.Shape>().FirstOrDefault(); // add it to the target anchor (ie. the one with the shape removed) DocumentFormat.OpenXml.Drawing.Spreadsheet.Shape targetShape = (DocumentFormat.OpenXml.Drawing.Spreadsheet.Shape)NewShape.CloneNode(true); targetShape.Append(matchShape.NonVisualShapeProperties.CloneNode(true)); targetShape.Append(matchShape.ShapeProperties.CloneNode(true)); targetShape.Append(matchShape.ShapeStyle.CloneNode(true)); targetShape.Append(matchShape.TextBody.CloneNode(true)); //Remove the text associated with the shape foreach (DocumentFormat.OpenXml.Drawing.Paragraph Paragraph in targetShape.TextBody.Descendants <DocumentFormat.OpenXml.Drawing.Paragraph>()) { foreach (DocumentFormat.OpenXml.Drawing.Run RunToRemove in Paragraph.Descendants <DocumentFormat.OpenXml.Drawing.Run>()) { RunToRemove.Remove(); } } try { foreach (System.Windows.Documents.Paragraph p in RTFSection.Blocks) { InlineCollection ParagraphInLines = p.Inlines; DocumentFormat.OpenXml.Drawing.Paragraph ShapeParagraph = new DocumentFormat.OpenXml.Drawing.Paragraph(); foreach (var InLine in ParagraphInLines) { if (InLine.GetType() == typeof(System.Windows.Documents.Span)) { Span s = (Span)InLine; Brush SourceTextColour = s.Foreground; foreach (System.Windows.Documents.Run r in s.Inlines) { if (r.Text != "\n") { ShapeRun = new DocumentFormat.OpenXml.Drawing.Run(); DocumentFormat.OpenXml.Drawing.RunProperties ShapeRunProperties = new DocumentFormat.OpenXml.Drawing.RunProperties(); DocumentFormat.OpenXml.Drawing.Text ShapeText = new DocumentFormat.OpenXml.Drawing.Text(r.Text); //the font family will be inherited from the sheet of the target shape ShapeRunProperties.FontSize = new Int32Value(System.Convert.ToInt32(s.FontSize * 100)); SolidFill textFill = new SolidFill(); SystemColor textColour = new SystemColor(); textColour.Val = new EnumValue <SystemColorValues>(SystemColorValues.WindowText); Int64Value ColourMask = 0xFF000000; Int64Value SourceColour = System.Convert.ToInt64(SourceTextColour.ToString().Replace("#", "0x"), 16); SourceColour = SourceColour % ColourMask; textColour.LastColor = new HexBinaryValue(string.Format("{0,10:X}", SourceColour)); textFill.SystemColor = textColour; ShapeRunProperties.Append(textFill); if (r.FontWeight == System.Windows.FontWeights.Bold) { ShapeRunProperties.Bold = true; } if (r.FontStyle == System.Windows.FontStyles.Italic) { ShapeRunProperties.Italic = true; } if (r.TextDecorations == System.Windows.TextDecorations.Underline) { ShapeRunProperties.Underline = new EnumValue <TextUnderlineValues>(TextUnderlineValues.Single); } ShapeRun.Text = ShapeText; ShapeRun.RunProperties = ShapeRunProperties; ShapeParagraph.Append(ShapeRun); } } } else { //do something else } } targetShape.TextBody.Append(ShapeParagraph); } } catch (System.Exception ex) { throw ex; } return(targetShape); }
public void ToJson(StringBuilder sb) { sb.Append("\n{\n"); // Definition Names sb.Append("\"definitionNameTable\":["); string comma = ""; foreach (uint id in definitionNames.Keys) { sb.Append(comma + "[" + id + ",\"" + definitionNames[id] + "\"]"); comma = ","; } sb.Append("],\n"); // Instance Names sb.Append("\"instanceNameTable\":["); comma = ""; foreach (uint id in instanceNames.Keys) { sb.Append(comma + "[" + id + ",\"" + instanceNames[id] + "\"]"); comma = ","; } sb.Append("],\n"); // strokes sb.Append("\"strokes\":["); //sb.Append("\\\\ strokes\n["); comma = ""; foreach (SolidStroke ss in strokes) { sb.Append(comma + ss.LineWidth.ToString("0.##") + ","); sb.Append(ss.Color.AFlipRGB.ToString()); comma = ","; } sb.Append("],\n"); // solid fills sb.Append("\"fills\":[\n"); //sb.Append("[\n\\\\ solid fills\n"); comma = ""; bool inGradients = false; foreach (FillStyle fs in fills) { if (fs.FillType == FillType.Solid) { SolidFill sf = (SolidFill)fs; sb.Append(comma + sf.Color.AFlipRGB.ToString()); comma = ","; } else { if (!inGradients) { sb.Append(",\n"); //sb.Append(",\n\\\\ gradients\n"); comma = ""; } inGradients = true; GradientFill gf = (GradientFill)fs; sb.Append(comma + "["); sb.Append(gf.GradientType == GradientType.Linear ? "\"L\"," : "\"R\","); sb.Append("[" + GetGradientLineString(gf) + "],"); // new argb colors List <Color> colors = new List <Color>(gf.Fills); List <float> positions = new List <float>(gf.Stops); if (gf.FillType == FillType.Radial) { gf.ReverseStops(colors, positions); } string comma2 = ""; sb.Append("["); for (int i = 0; i < colors.Count; i++) { Color c = colors[i]; sb.Append(comma2 + c.AFlipRGB.ToString() + ","); sb.Append(positions[i].ToString("0.##")); comma2 = ","; } sb.Append("]]"); comma = ",\n"; } } sb.Append("\n],\n"); sb.Append("\"images\":[\n"); comma = ""; foreach (DrawImage image in drawImages) { sb.Append(comma); image.ToJson(sb); comma = ",\n"; } sb.Append("\n],\n"); sb.Append("\"symbols\":[\n"); comma = ""; foreach (DrawSymbol symbol in drawSymbols) { sb.Append(comma); symbol.ToJson(sb); comma = ",\n"; } sb.Append("\n],\n"); sb.Append("\"timelines\":[\n"); comma = ""; foreach (DrawTimeline tl in drawTimelines) { sb.Append(comma); tl.ToJson(sb); comma = ",\n"; } sb.Append("\n]\n"); sb.Append("\n}\n"); }